org-compat.el 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. ;;; org-compat.el --- Compatibility Code for Older Emacsen -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains code needed for compatibility with older
  23. ;; versions of GNU Emacs and integration with other packages.
  24. ;;; Code:
  25. (require 'cl-lib)
  26. (require 'seq)
  27. (require 'org-macs)
  28. (declare-function org-agenda-diary-entry "org-agenda")
  29. (declare-function org-agenda-maybe-redo "org-agenda" ())
  30. (declare-function org-agenda-set-restriction-lock "org-agenda" (&optional type))
  31. (declare-function org-agenda-remove-restriction-lock "org-agenda" (&optional noupdate))
  32. (declare-function org-calendar-goto-agenda "org-agenda" ())
  33. (declare-function org-align-tags "org" (&optional all))
  34. (declare-function org-at-heading-p "org" (&optional ignored))
  35. (declare-function org-at-table.el-p "org" ())
  36. (declare-function org-element-at-point "org-element" (&optional pom cached-only))
  37. (declare-function org-element-at-point-no-context "org-element" (&optional pom))
  38. (declare-function org-element-context "org-element" (&optional element))
  39. (declare-function org-element-lineage "org-element" (blob &optional types with-self))
  40. (declare-function org-element-type "org-element" (element))
  41. (declare-function org-element-property "org-element" (property element))
  42. (declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
  43. (declare-function org-get-heading "org" (&optional no-tags no-todo no-priority no-comment))
  44. (declare-function org-get-tags "org" (&optional pos local))
  45. (declare-function org-fold-hide-block-toggle "org-fold" (&optional force no-error element))
  46. (declare-function org-link-display-format "ol" (s))
  47. (declare-function org-link-set-parameters "ol" (type &rest rest))
  48. (declare-function org-log-into-drawer "org" ())
  49. (declare-function org-make-tag-string "org" (tags))
  50. (declare-function org-reduced-level "org" (l))
  51. (declare-function org-return "org" (&optional indent arg interactive))
  52. (declare-function org-fold-show-context "org-fold" (&optional key))
  53. (declare-function org-table-end "org-table" (&optional table-type))
  54. (declare-function outline-next-heading "outline" ())
  55. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  56. (declare-function table--at-cell-p "table" (position &optional object at-column))
  57. (declare-function org-fold-region "org-fold" (from to flag &optional spec))
  58. (declare-function org-fold-show-all "org-fold" (&optional types))
  59. (defvar calendar-mode-map)
  60. (defvar org-complex-heading-regexp)
  61. (defvar org-agenda-diary-file)
  62. (defvar org-agenda-overriding-restriction)
  63. (defvar org-agenda-restriction-lock-overlay)
  64. (defvar org-table-any-border-regexp)
  65. (defvar org-table-dataline-regexp)
  66. (defvar org-table-tab-recognizes-table.el)
  67. (defvar org-table1-hline-regexp)
  68. (defvar org-fold-core-style)
  69. ;;; Emacs < 29 compatibility
  70. (defvar org-file-has-changed-p--hash-table (make-hash-table :test #'equal)
  71. "Internal variable used by `org-file-has-changed-p'.")
  72. (if (fboundp 'file-has-changed-p)
  73. (defalias 'org-file-has-changed-p #'file-has-changed-p)
  74. (defun org-file-has-changed-p (file &optional tag)
  75. "Return non-nil if FILE has changed.
  76. The size and modification time of FILE are compared to the size
  77. and modification time of the same FILE during a previous
  78. invocation of `org-file-has-changed-p'. Thus, the first invocation
  79. of `org-file-has-changed-p' always returns non-nil when FILE exists.
  80. The optional argument TAG, which must be a symbol, can be used to
  81. limit the comparison to invocations with identical tags; it can be
  82. the symbol of the calling function, for example."
  83. (let* ((file (directory-file-name (expand-file-name file)))
  84. (remote-file-name-inhibit-cache t)
  85. (fileattr (file-attributes file 'integer))
  86. (attr (and fileattr
  87. (cons (file-attribute-size fileattr)
  88. (file-attribute-modification-time fileattr))))
  89. (sym (concat (symbol-name tag) "@" file))
  90. (cachedattr (gethash sym org-file-has-changed-p--hash-table)))
  91. (when (not (equal attr cachedattr))
  92. (puthash sym attr org-file-has-changed-p--hash-table)))))
  93. ;;; Emacs < 28.1 compatibility
  94. (if (fboundp 'file-name-concat)
  95. (defalias 'org-file-name-concat #'file-name-concat)
  96. (defun org-file-name-concat (directory &rest components)
  97. "Append COMPONENTS to DIRECTORY and return the resulting string.
  98. Elements in COMPONENTS must be a string or nil.
  99. DIRECTORY or the non-final elements in COMPONENTS may or may not end
  100. with a slash -- if they don't end with a slash, a slash will be
  101. inserted before contatenating."
  102. (save-match-data
  103. (mapconcat
  104. #'identity
  105. (delq nil
  106. (mapcar
  107. (lambda (str)
  108. (when (and str (not (seq-empty-p str))
  109. (string-match "\\(.+\\)/?" str))
  110. (match-string 1 str)))
  111. (cons directory components)))
  112. "/"))))
  113. (if (fboundp 'directory-empty-p)
  114. (defalias 'org-directory-empty-p #'directory-empty-p)
  115. (defun org-directory-empty-p (dir)
  116. "Return t if DIR names an existing directory containing no other files."
  117. (and (file-directory-p dir)
  118. (null (directory-files dir nil directory-files-no-dot-files-regexp t)))))
  119. ;;; Emacs < 27.1 compatibility
  120. (unless (fboundp 'combine-change-calls)
  121. ;; A stub when `combine-change-calls' was not yet there.
  122. (defmacro combine-change-calls (_beg _end &rest body)
  123. (declare (debug (form form def-body)) (indent 2))
  124. `(progn ,@body)))
  125. (if (version< emacs-version "27.1")
  126. (defsubst org-replace-buffer-contents (source &optional _max-secs _max-costs)
  127. (replace-buffer-contents source))
  128. (defalias 'org-replace-buffer-contents #'replace-buffer-contents))
  129. (unless (fboundp 'proper-list-p)
  130. ;; `proper-list-p' was added in Emacs 27.1. The function below is
  131. ;; taken from Emacs subr.el 200195e824b^.
  132. (defun proper-list-p (object)
  133. "Return OBJECT's length if it is a proper list, nil otherwise.
  134. A proper list is neither circular nor dotted (i.e., its last cdr
  135. is nil)."
  136. (and (listp object) (ignore-errors (length object)))))
  137. (if (fboundp 'xor)
  138. ;; `xor' was added in Emacs 27.1.
  139. (defalias 'org-xor #'xor)
  140. (defsubst org-xor (a b)
  141. "Exclusive `or'."
  142. (if a (not b) b)))
  143. (unless (fboundp 'pcomplete-uniquify-list)
  144. ;; The misspelled variant was made obsolete in Emacs 27.1
  145. (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list))
  146. (if (fboundp 'time-convert)
  147. (progn
  148. (defsubst org-time-convert-to-integer (time)
  149. (time-convert time 'integer))
  150. (defsubst org-time-convert-to-list (time)
  151. (time-convert time 'list)))
  152. (defun org-time-convert-to-integer (time)
  153. (floor (float-time time)))
  154. (defun org-time-convert-to-list (time)
  155. (seconds-to-time (float-time time))))
  156. ;; `newline-and-indent' did not take a numeric argument before 27.1.
  157. (if (version< emacs-version "27")
  158. (defsubst org-newline-and-indent (&optional _arg)
  159. (newline-and-indent))
  160. (defalias 'org-newline-and-indent #'newline-and-indent))
  161. (defun org--set-faces-extend (faces extend-p)
  162. "Set the :extend attribute of FACES to EXTEND-P.
  163. This is a no-op for Emacs versions lower than 27, since face
  164. extension beyond end of line was not controllable."
  165. (when (fboundp 'set-face-extend)
  166. (mapc (lambda (f) (set-face-extend f extend-p)) faces)))
  167. (if (fboundp 'string-distance)
  168. (defalias 'org-string-distance 'string-distance)
  169. (defun org-string-distance (s1 s2)
  170. "Return the edit (levenshtein) distance between strings S1 S2."
  171. (let* ((l1 (length s1))
  172. (l2 (length s2))
  173. (dist (vconcat (mapcar (lambda (_) (make-vector (1+ l2) nil))
  174. (number-sequence 1 (1+ l1)))))
  175. (in (lambda (i j) (aref (aref dist i) j))))
  176. (setf (aref (aref dist 0) 0) 0)
  177. (dolist (j (number-sequence 1 l2))
  178. (setf (aref (aref dist 0) j) j))
  179. (dolist (i (number-sequence 1 l1))
  180. (setf (aref (aref dist i) 0) i)
  181. (dolist (j (number-sequence 1 l2))
  182. (setf (aref (aref dist i) j)
  183. (min
  184. (1+ (funcall in (1- i) j))
  185. (1+ (funcall in i (1- j)))
  186. (+ (if (equal (aref s1 (1- i)) (aref s2 (1- j))) 0 1)
  187. (funcall in (1- i) (1- j)))))))
  188. (funcall in l1 l2))))
  189. (define-obsolete-function-alias 'org-babel-edit-distance 'org-string-distance
  190. "9.5")
  191. ;;; Emacs < 26.1 compatibility
  192. (if (fboundp 'line-number-display-width)
  193. (defalias 'org-line-number-display-width 'line-number-display-width)
  194. (defun org-line-number-display-width (&rest _) 0))
  195. (if (fboundp 'buffer-hash)
  196. (defalias 'org-buffer-hash 'buffer-hash)
  197. (defun org-buffer-hash () (md5 (current-buffer))))
  198. (unless (fboundp 'file-attribute-modification-time)
  199. (defsubst file-attribute-modification-time (attributes)
  200. "The modification time in ATTRIBUTES returned by `file-attributes'.
  201. This is the time of the last change to the file's contents, and
  202. is a list of integers (HIGH LOW USEC PSEC) in the same style
  203. as (current-time)."
  204. (nth 5 attributes)))
  205. (unless (fboundp 'file-attribute-size)
  206. (defsubst file-attribute-size (attributes)
  207. "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
  208. This is a floating point number if the size is too large for an integer."
  209. (nth 7 attributes)))
  210. ;;; Obsolete aliases (remove them after the next major release).
  211. ;;;; XEmacs compatibility, now removed.
  212. (define-obsolete-function-alias 'org-activate-mark 'activate-mark "9.0")
  213. (define-obsolete-function-alias 'org-add-hook 'add-hook "9.0")
  214. (define-obsolete-function-alias 'org-bound-and-true-p 'bound-and-true-p "9.0")
  215. (define-obsolete-function-alias 'org-decompose-region 'decompose-region "9.0")
  216. (define-obsolete-function-alias 'org-defvaralias 'defvaralias "9.0")
  217. (define-obsolete-function-alias 'org-detach-overlay 'delete-overlay "9.0")
  218. (define-obsolete-function-alias 'org-file-equal-p 'file-equal-p "9.0")
  219. (define-obsolete-function-alias 'org-float-time 'float-time "9.0")
  220. (define-obsolete-function-alias 'org-indent-line-to 'indent-line-to "9.0")
  221. (define-obsolete-function-alias 'org-indent-to-column 'indent-to-column "9.0")
  222. (define-obsolete-function-alias 'org-looking-at-p 'looking-at-p "9.0")
  223. (define-obsolete-function-alias 'org-looking-back 'looking-back "9.0")
  224. (define-obsolete-function-alias 'org-match-string-no-properties 'match-string-no-properties "9.0")
  225. (define-obsolete-function-alias 'org-propertize 'propertize "9.0")
  226. (define-obsolete-function-alias 'org-select-frame-set-input-focus 'select-frame-set-input-focus "9.0")
  227. (define-obsolete-function-alias 'org-file-remote-p 'file-remote-p "9.2")
  228. (define-obsolete-function-alias 'org-show-context 'org-fold-show-context "9.6")
  229. (define-obsolete-function-alias 'org-show-entry 'org-fold-show-entry "9.6")
  230. (define-obsolete-function-alias 'org-show-children 'org-fold-show-children "9.6")
  231. (defmacro org-re (s)
  232. "Replace posix classes in regular expression S."
  233. (declare (debug (form))
  234. (obsolete "you can safely remove it." "9.0"))
  235. s)
  236. ;;;; Functions from cl-lib that Org used to have its own implementation of.
  237. (define-obsolete-function-alias 'org-count 'cl-count "9.0")
  238. (define-obsolete-function-alias 'org-every 'cl-every "9.0")
  239. (define-obsolete-function-alias 'org-find-if 'cl-find-if "9.0")
  240. (define-obsolete-function-alias 'org-reduce 'cl-reduce "9.0")
  241. (define-obsolete-function-alias 'org-remove-if 'cl-remove-if "9.0")
  242. (define-obsolete-function-alias 'org-remove-if-not 'cl-remove-if-not "9.0")
  243. (define-obsolete-function-alias 'org-some 'cl-some "9.0")
  244. (define-obsolete-function-alias 'org-floor* 'cl-floor "9.0")
  245. (defun org-sublist (list start end)
  246. "Return a section of LIST, from START to END.
  247. Counting starts at 1."
  248. (cl-subseq list (1- start) end))
  249. (make-obsolete 'org-sublist
  250. "use cl-subseq (note the 0-based counting)."
  251. "9.0")
  252. ;;;; Functions available since Emacs 25.1
  253. (define-obsolete-function-alias 'org-string-collate-lessp 'string-collate-lessp "9.6")
  254. (define-obsolete-function-alias 'org-decode-time 'decode-time "9.6")
  255. (define-obsolete-function-alias 'org-format-time-string 'format-time-string "9.6")
  256. (define-obsolete-function-alias 'org-time-add 'time-add "9.6")
  257. (define-obsolete-function-alias 'org-time-subtract 'time-subtract "9.6")
  258. (define-obsolete-function-alias 'org-time-since 'time-since "9.6")
  259. (define-obsolete-function-alias 'org-time-less-p 'time-less-p "9.6")
  260. ;;;; Functions available since Emacs 24.3
  261. (define-obsolete-function-alias 'org-buffer-narrowed-p 'buffer-narrowed-p "9.0")
  262. (define-obsolete-function-alias 'org-called-interactively-p 'called-interactively-p "9.0")
  263. (define-obsolete-function-alias 'org-char-to-string 'char-to-string "9.0")
  264. (define-obsolete-function-alias 'org-delete-directory 'delete-directory "9.0")
  265. (define-obsolete-function-alias 'org-format-seconds 'format-seconds "9.0")
  266. (define-obsolete-function-alias 'org-link-escape-browser 'url-encode-url "9.0")
  267. (define-obsolete-function-alias 'org-no-warnings 'with-no-warnings "9.0")
  268. (define-obsolete-function-alias 'org-number-sequence 'number-sequence "9.0")
  269. (define-obsolete-function-alias 'org-pop-to-buffer-same-window 'pop-to-buffer-same-window "9.0")
  270. (define-obsolete-function-alias 'org-string-match-p 'string-match-p "9.0")
  271. ;;;; Functions and variables from previous releases now obsolete.
  272. (define-obsolete-function-alias 'org-element-remove-indentation
  273. 'org-remove-indentation "9.0")
  274. (define-obsolete-variable-alias 'org-latex-create-formula-image-program
  275. 'org-preview-latex-default-process "9.0")
  276. (define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
  277. 'org-preview-latex-image-directory "9.0")
  278. (define-obsolete-function-alias 'org-table-p 'org-at-table-p "9.0")
  279. (define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "9.0")
  280. (define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "8.3")
  281. (define-obsolete-function-alias 'org-image-file-name-regexp
  282. 'image-file-name-regexp "9.0")
  283. (define-obsolete-function-alias 'org-completing-read-no-i
  284. 'completing-read "9.0")
  285. (define-obsolete-function-alias 'org-icompleting-read
  286. 'completing-read "9.0")
  287. (define-obsolete-function-alias 'org-iread-file-name 'read-file-name "9.0")
  288. (define-obsolete-function-alias 'org-days-to-time
  289. 'org-time-stamp-to-now "8.2")
  290. (define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
  291. 'org-agenda-ignore-properties "9.0")
  292. (define-obsolete-function-alias 'org-preview-latex-fragment
  293. 'org-toggle-latex-fragment "8.3")
  294. (define-obsolete-function-alias 'org-export-get-genealogy
  295. 'org-element-lineage "9.0")
  296. (define-obsolete-variable-alias 'org-latex-with-hyperref
  297. 'org-latex-hyperref-template "9.0")
  298. (define-obsolete-variable-alias 'hfy-optimisations 'hfy-optimizations "9.0")
  299. (define-obsolete-variable-alias 'org-export-htmlized-org-css-url
  300. 'org-org-htmlized-css-url "8.2")
  301. (define-obsolete-function-alias 'org-list-parse-list 'org-list-to-lisp "9.0")
  302. (define-obsolete-function-alias 'org-agenda-todayp
  303. 'org-agenda-today-p "9.0")
  304. (define-obsolete-function-alias 'org-babel-examplize-region
  305. 'org-babel-examplify-region "9.0")
  306. (define-obsolete-variable-alias 'org-babel-capitalize-example-region-markers
  307. 'org-babel-uppercase-example-markers "9.1")
  308. (define-obsolete-function-alias 'org-babel-trim 'org-trim "9.0")
  309. (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
  310. (define-obsolete-function-alias 'org-insert-columns-dblock
  311. 'org-columns-insert-dblock "9.0")
  312. (define-obsolete-variable-alias 'org-export-babel-evaluate
  313. 'org-export-use-babel "9.1")
  314. (define-obsolete-function-alias 'org-activate-bracket-links
  315. 'org-activate-links "9.0")
  316. (define-obsolete-function-alias 'org-activate-plain-links 'ignore "9.0")
  317. (define-obsolete-function-alias 'org-activate-angle-links 'ignore "9.0")
  318. (define-obsolete-function-alias 'org-remove-double-quotes 'org-strip-quotes "9.0")
  319. (define-obsolete-function-alias 'org-get-indentation
  320. 'current-indentation "9.2")
  321. (define-obsolete-function-alias 'org-capture-member 'org-capture-get "9.2")
  322. (define-obsolete-function-alias 'org-remove-from-invisibility-spec
  323. 'remove-from-invisibility-spec "9.2")
  324. (define-obsolete-variable-alias 'org-effort-durations 'org-duration-units
  325. "9.2")
  326. (define-obsolete-function-alias 'org-toggle-latex-fragment 'org-latex-preview
  327. "9.3")
  328. (define-obsolete-function-alias 'org-remove-latex-fragment-image-overlays
  329. 'org-clear-latex-preview "9.3")
  330. (define-obsolete-function-alias 'org-hide-archived-subtrees
  331. 'org-fold-hide-archived-subtrees "9.6")
  332. (define-obsolete-function-alias 'org-flag-region
  333. 'org-fold-region "9.6")
  334. (define-obsolete-function-alias 'org-flag-subtree
  335. 'org-fold-subtree "9.6")
  336. (define-obsolete-function-alias 'org-hide-entry
  337. 'org-fold-hide-entry "9.6")
  338. (define-obsolete-function-alias 'org-show-subtree
  339. 'org-fold-show-subtree "9.6")
  340. (define-obsolete-function-alias 'org--hide-wrapper-toggle
  341. 'org-fold--hide-wrapper-toggle "9.6")
  342. (define-obsolete-function-alias 'org-hide-block-toggle
  343. 'org-fold-hide-block-toggle "9.6")
  344. (define-obsolete-function-alias 'org-hide-drawer-toggle
  345. 'org-fold-hide-drawer-toggle "9.6")
  346. (define-obsolete-function-alias 'org--hide-drawers
  347. 'org-fold--hide-drawers "9.6")
  348. (define-obsolete-function-alias 'org-hide-block-all
  349. 'org-fold-hide-block-all "9.6")
  350. (define-obsolete-function-alias 'org-hide-drawer-all
  351. 'org-fold-hide-drawer-all "9.6")
  352. (define-obsolete-function-alias 'org-show-all
  353. 'org-fold-show-all "9.6")
  354. (define-obsolete-function-alias 'org-set-startup-visibility
  355. 'org-cycle-set-startup-visibility "9.6")
  356. (define-obsolete-function-alias 'org-show-set-visibility
  357. 'org-fold-show-set-visibility "9.6")
  358. (define-obsolete-function-alias 'org-check-before-invisible-edit
  359. 'org-fold-check-before-invisible-edit "9.6")
  360. (define-obsolete-function-alias 'org-flag-above-first-heading
  361. 'org-fold-flag-above-first-heading "9.6")
  362. (define-obsolete-function-alias 'org-show-branches-buffer
  363. 'org-fold-show-branches-buffer "9.6")
  364. (define-obsolete-function-alias 'org-show-siblings
  365. 'org-fold-show-siblings "9.6")
  366. (define-obsolete-function-alias 'org-show-hidden-entry
  367. 'org-fold-show-hidden-entry "9.6")
  368. (define-obsolete-function-alias 'org-flag-heading
  369. 'org-fold-heading "9.6")
  370. (define-obsolete-function-alias 'org-set-startup-visibility
  371. 'org-cycle-set-startup-visibility "9.6")
  372. (define-obsolete-function-alias 'org-set-visibility-according-to-property
  373. 'org-cycle-set-visibility-according-to-property "9.6")
  374. (define-obsolete-variable-alias 'org-scroll-position-to-restore
  375. 'org-cycle-scroll-position-to-restore "9.6")
  376. (define-obsolete-function-alias 'org-optimize-window-after-visibility-change
  377. 'org-cycle-optimize-window-after-visibility-change "9.6")
  378. (define-obsolete-function-alias 'org-force-cycle-archived
  379. 'org-cycle-force-archived "9.6")
  380. (define-obsolete-variable-alias 'org-attach-directory
  381. 'org-attach-id-dir "9.3")
  382. (make-obsolete 'org-attach-store-link "No longer used" "9.4")
  383. (make-obsolete 'org-attach-expand-link "No longer used" "9.4")
  384. (define-obsolete-function-alias 'org-file-url-p 'org-url-p "9.5")
  385. (define-obsolete-variable-alias 'org-show-context-detail
  386. 'org-fold-show-context-detail "9.6")
  387. (define-obsolete-variable-alias 'org-catch-invisible-edits
  388. 'org-fold-catch-invisible-edits "9.6")
  389. (define-obsolete-variable-alias 'org-reveal-start-hook
  390. 'org-fold-reveal-start-hook "9.6")
  391. (define-obsolete-function-alias 'org-file-url-p 'org-url-p "9.6")
  392. (defun org-in-fixed-width-region-p ()
  393. "Non-nil if point in a fixed-width region."
  394. (save-match-data
  395. (eq 'fixed-width (org-element-type (org-element-at-point)))))
  396. (make-obsolete 'org-in-fixed-width-region-p
  397. "use `org-element' library"
  398. "9.0")
  399. (defun org-compatible-face (inherits specs)
  400. "Make a compatible face specification.
  401. If INHERITS is an existing face and if the Emacs version supports
  402. it, just inherit the face. If INHERITS is not given and SPECS
  403. is, use SPECS to define the face."
  404. (declare (indent 1))
  405. (if (facep inherits)
  406. (list (list t :inherit inherits))
  407. specs))
  408. (make-obsolete 'org-compatible-face "you can remove it." "9.0")
  409. (defun org-add-link-type (type &optional follow export)
  410. "Add a new TYPE link.
  411. FOLLOW and EXPORT are two functions.
  412. FOLLOW should take the link path as the single argument and do whatever
  413. is necessary to follow the link, for example find a file or display
  414. a mail message.
  415. EXPORT should format the link path for export to one of the export formats.
  416. It should be a function accepting three arguments:
  417. path the path of the link, the text after the prefix (like \"http:\")
  418. desc the description of the link, if any
  419. format the export format, a symbol like `html' or `latex' or `ascii'.
  420. The function may use the FORMAT information to return different values
  421. depending on the format. The return value will be put literally into
  422. the exported file. If the return value is nil, this means Org should
  423. do what it normally does with links which do not have EXPORT defined.
  424. Org mode has a built-in default for exporting links. If you are happy with
  425. this default, there is no need to define an export function for the link
  426. type. For a simple example of an export function, see `org-bbdb.el'.
  427. If TYPE already exists, update it with the arguments.
  428. See `org-link-parameters' for documentation on the other parameters."
  429. (org-link-set-parameters type :follow follow :export export)
  430. (message "Created %s link." type))
  431. (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." "9.0")
  432. ;;;; Functions unused in Org core.
  433. (defun org-table-recognize-table.el ()
  434. "If there is a table.el table nearby, recognize it and move into it."
  435. (when (org-at-table.el-p)
  436. (beginning-of-line)
  437. (unless (or (looking-at org-table-dataline-regexp)
  438. (not (looking-at org-table1-hline-regexp)))
  439. (forward-line)
  440. (when (looking-at org-table-any-border-regexp)
  441. (forward-line -2)))
  442. (if (re-search-forward "|" (org-table-end t) t)
  443. (progn
  444. (require 'table)
  445. (if (table--at-cell-p (point)) t
  446. (message "recognizing table.el table...")
  447. (table-recognize-table)
  448. (message "recognizing table.el table...done")))
  449. (error "This should not happen"))))
  450. ;; Not used since commit 6d1e3082, Feb 2010.
  451. (make-obsolete 'org-table-recognize-table.el
  452. "please notify Org mailing list if you use this function."
  453. "9.0")
  454. (defmacro org-preserve-lc (&rest body)
  455. (declare (debug (body))
  456. (obsolete "please notify Org mailing list if you use this function."
  457. "9.2"))
  458. (org-with-gensyms (line col)
  459. `(let ((,line (org-current-line))
  460. (,col (current-column)))
  461. (unwind-protect
  462. (progn ,@body)
  463. (org-goto-line ,line)
  464. (org-move-to-column ,col)))))
  465. (defun org-version-check (version &rest _)
  466. "Non-nil if VERSION is lower (older) than `emacs-version'."
  467. (declare (obsolete "use `version<' or `fboundp' instead."
  468. "9.2"))
  469. (version< version emacs-version))
  470. (defun org-remove-angle-brackets (s)
  471. (org-unbracket-string "<" ">" s))
  472. (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "9.0")
  473. (defcustom org-publish-sitemap-file-entry-format "%t"
  474. "Format string for site-map file entry.
  475. You could use brackets to delimit on what part the link will be.
  476. %t is the title.
  477. %a is the author.
  478. %d is the date formatted using `org-publish-sitemap-date-format'."
  479. :group 'org-export-publish
  480. :type 'string)
  481. (make-obsolete-variable
  482. 'org-publish-sitemap-file-entry-format
  483. "set `:sitemap-format-entry' in `org-publish-project-alist' instead."
  484. "9.1")
  485. (defvar org-agenda-skip-regexp)
  486. (defun org-agenda-skip-entry-when-regexp-matches ()
  487. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  488. If yes, it returns the end position of this entry, causing agenda commands
  489. to skip the entry but continuing the search in the subtree. This is a
  490. function that can be put into `org-agenda-skip-function' for the duration
  491. of a command."
  492. (declare (obsolete "use `org-agenda-skip-if' instead." "9.1"))
  493. (let ((end (save-excursion (org-end-of-subtree t)))
  494. skip)
  495. (save-excursion
  496. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  497. (and skip end)))
  498. (defun org-agenda-skip-subtree-when-regexp-matches ()
  499. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  500. If yes, it returns the end position of this tree, causing agenda commands
  501. to skip this subtree. This is a function that can be put into
  502. `org-agenda-skip-function' for the duration of a command."
  503. (declare (obsolete "use `org-agenda-skip-if' instead." "9.1"))
  504. (let ((end (save-excursion (org-end-of-subtree t)))
  505. skip)
  506. (save-excursion
  507. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  508. (and skip end)))
  509. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  510. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  511. If yes, it returns the end position of the current entry (NOT the tree),
  512. causing agenda commands to skip the entry but continuing the search in
  513. the subtree. This is a function that can be put into
  514. `org-agenda-skip-function' for the duration of a command. An important
  515. use of this function is for the stuck project list."
  516. (declare (obsolete "use `org-agenda-skip-if' instead." "9.1"))
  517. (let ((end (save-excursion (org-end-of-subtree t)))
  518. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  519. skip)
  520. (save-excursion
  521. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  522. (and skip entry-end)))
  523. (define-obsolete-function-alias 'org-minutes-to-clocksum-string
  524. 'org-duration-from-minutes "9.1")
  525. (define-obsolete-function-alias 'org-hh:mm-string-to-minutes
  526. 'org-duration-to-minutes "9.1")
  527. (define-obsolete-function-alias 'org-duration-string-to-minutes
  528. 'org-duration-to-minutes "9.1")
  529. (make-obsolete-variable 'org-time-clocksum-format
  530. "set `org-duration-format' instead." "9.1")
  531. (make-obsolete-variable 'org-time-clocksum-use-fractional
  532. "set `org-duration-format' instead." "9.1")
  533. (make-obsolete-variable 'org-time-clocksum-fractional-format
  534. "set `org-duration-format' instead." "9.1")
  535. (make-obsolete-variable 'org-time-clocksum-use-effort-durations
  536. "set `org-duration-units' instead." "9.1")
  537. (define-obsolete-function-alias 'org-babel-number-p
  538. 'org-babel--string-to-number "9.0")
  539. (define-obsolete-variable-alias 'org-usenet-links-prefer-google
  540. 'org-gnus-prefer-web-links "9.1")
  541. (define-obsolete-variable-alias 'org-texinfo-def-table-markup
  542. 'org-texinfo-table-default-markup "9.1")
  543. (define-obsolete-variable-alias 'org-agenda-overriding-columns-format
  544. 'org-overriding-columns-format "9.2.2")
  545. (define-obsolete-variable-alias 'org-doi-server-url
  546. 'org-link-doi-server-url "9.3")
  547. (define-obsolete-variable-alias 'org-email-link-description-format
  548. 'org-link-email-description-format "9.3")
  549. (define-obsolete-variable-alias 'org-make-link-description-function
  550. 'org-link-make-description-function "9.3")
  551. (define-obsolete-variable-alias 'org-from-is-user-regexp
  552. 'org-link-from-user-regexp "9.3")
  553. (define-obsolete-variable-alias 'org-descriptive-links
  554. 'org-link-descriptive "9.3")
  555. (define-obsolete-variable-alias 'org-context-in-file-links
  556. 'org-link-context-for-files "9.3")
  557. (define-obsolete-variable-alias 'org-keep-stored-link-after-insertion
  558. 'org-link-keep-stored-after-insertion "9.3")
  559. (define-obsolete-variable-alias 'org-display-internal-link-with-indirect-buffer
  560. 'org-link-use-indirect-buffer-for-internals "9.3")
  561. (define-obsolete-variable-alias 'org-confirm-shell-link-function
  562. 'org-link-shell-confirm-function "9.3")
  563. (define-obsolete-variable-alias 'org-confirm-shell-link-not-regexp
  564. 'org-link-shell-skip-confirm-regexp "9.3")
  565. (define-obsolete-variable-alias 'org-confirm-elisp-link-function
  566. 'org-link-elisp-confirm-function "9.3")
  567. (define-obsolete-variable-alias 'org-confirm-elisp-link-not-regexp
  568. 'org-link-elisp-skip-confirm-regexp "9.3")
  569. (define-obsolete-function-alias 'org-file-complete-link
  570. 'org-link-complete-file "9.3")
  571. (define-obsolete-function-alias 'org-email-link-description
  572. 'org-link-email-description "9.3")
  573. (define-obsolete-function-alias 'org-make-link-string
  574. 'org-link-make-string "9.3")
  575. (define-obsolete-function-alias 'org-store-link-props
  576. 'org-link-store-props "9.3")
  577. (define-obsolete-function-alias 'org-add-link-props
  578. 'org-link-add-props "9.3")
  579. (define-obsolete-function-alias 'org-make-org-heading-search-string
  580. 'org-link-heading-search-string "9.3")
  581. (define-obsolete-function-alias 'org-make-link-regexps
  582. 'org-link-make-regexps "9.3")
  583. (define-obsolete-function-alias 'org-property-global-value
  584. 'org-property-global-or-keyword-value "9.3")
  585. (make-obsolete-variable 'org-file-properties 'org-keyword-properties "9.3")
  586. (define-obsolete-variable-alias 'org-angle-link-re
  587. 'org-link-angle-re "9.3")
  588. (define-obsolete-variable-alias 'org-plain-link-re
  589. 'org-link-plain-re "9.3")
  590. (define-obsolete-variable-alias 'org-bracket-link-regexp
  591. 'org-link-bracket-re "9.3")
  592. (define-obsolete-variable-alias 'org-bracket-link-analytic-regexp
  593. 'org-link-bracket-re "9.3")
  594. (define-obsolete-variable-alias 'org-any-link-re
  595. 'org-link-any-re "9.3")
  596. (define-obsolete-function-alias 'org-open-link-from-string
  597. 'org-link-open-from-string "9.3")
  598. (define-obsolete-function-alias 'org-add-angle-brackets
  599. 'org-link-add-angle-brackets "9.3")
  600. ;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
  601. ;; This make-obsolete call was added 2016-09-01.
  602. (make-obsolete 'org-capture-import-remember-templates
  603. "use the `org-capture-templates' variable instead."
  604. "9.0")
  605. (defun org-show-block-all ()
  606. "Unfold all blocks in the current buffer."
  607. (interactive)
  608. (org-fold-show-all '(blocks)))
  609. (make-obsolete 'org-show-block-all
  610. "use `org-show-all' instead."
  611. "9.2")
  612. (define-obsolete-function-alias 'org-get-tags-at 'org-get-tags "9.2")
  613. (defun org-get-local-tags ()
  614. "Get a list of tags defined in the current headline."
  615. (declare (obsolete "use `org-get-tags' instead." "9.2"))
  616. (org-get-tags nil 'local))
  617. (defun org-get-local-tags-at (&optional pos)
  618. "Get a list of tags defined in the current headline."
  619. (declare (obsolete "use `org-get-tags' instead." "9.2"))
  620. (org-get-tags pos 'local))
  621. (defun org-get-tags-string ()
  622. "Get the TAGS string in the current headline."
  623. (declare (obsolete "use `org-make-tag-string' instead." "9.2"))
  624. (org-make-tag-string (org-get-tags nil t)))
  625. (define-obsolete-function-alias 'org-set-tags-to 'org-set-tags "9.2")
  626. (defun org-align-all-tags ()
  627. "Align the tags in all headings."
  628. (declare (obsolete "use `org-align-tags' instead." "9.2"))
  629. (org-align-tags t))
  630. (define-obsolete-function-alias
  631. 'org-at-property-block-p 'org-at-property-drawer-p "9.4")
  632. (defun org-flag-drawer (flag &optional element beg end)
  633. "When FLAG is non-nil, hide the drawer we are at.
  634. Otherwise make it visible.
  635. When optional argument ELEMENT is a parsed drawer, as returned by
  636. `org-element-at-point', hide or show that drawer instead.
  637. When buffer positions BEG and END are provided, hide or show that
  638. region as a drawer without further ado."
  639. (declare (obsolete "use `org-hide-drawer-toggle' instead." "9.4"))
  640. (if (and beg end) (org-fold-region beg end flag (if (eq org-fold-core-style 'text-properties) 'drawer 'outline))
  641. (let ((drawer
  642. (or element
  643. (and (save-excursion
  644. (beginning-of-line)
  645. (looking-at-p "^[ \t]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ \t]*$"))
  646. (org-element-at-point)))))
  647. (when (memq (org-element-type drawer) '(drawer property-drawer))
  648. (let ((post (org-element-property :post-affiliated drawer)))
  649. (org-fold-region
  650. (save-excursion (goto-char post) (line-end-position))
  651. (save-excursion (goto-char (org-element-property :end drawer))
  652. (skip-chars-backward " \t\n")
  653. (line-end-position))
  654. flag (if (eq org-fold-core-style 'text-properties) 'drawer 'outline))
  655. ;; When the drawer is hidden away, make sure point lies in
  656. ;; a visible part of the buffer.
  657. (when (invisible-p (max (1- (point)) (point-min)))
  658. (goto-char post)))))))
  659. (defun org-hide-block-toggle-maybe ()
  660. "Toggle visibility of block at point.
  661. Unlike to `org-hide-block-toggle', this function does not throw
  662. an error. Return a non-nil value when toggling is successful."
  663. (declare (obsolete "use `org-hide-block-toggle' instead." "9.4"))
  664. (interactive)
  665. (org-fold-hide-block-toggle nil t))
  666. (defun org-hide-block-toggle-all ()
  667. "Toggle the visibility of all blocks in the current buffer."
  668. (declare (obsolete "please notify Org mailing list if you use this function."
  669. "9.4"))
  670. (let ((start (point-min))
  671. (end (point-max)))
  672. (save-excursion
  673. (goto-char start)
  674. (while (and (< (point) end)
  675. (re-search-forward "^[ \t]*#\\+begin_?\
  676. \\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_?\\1[ \t]*$" end t))
  677. (save-excursion
  678. (save-match-data
  679. (goto-char (match-beginning 0))
  680. (org-fold-hide-block-toggle)))))))
  681. (defun org-return-indent ()
  682. "Goto next table row or insert a newline and indent.
  683. Calls `org-table-next-row' or `newline-and-indent', depending on
  684. context. See the individual commands for more information."
  685. (declare (obsolete "use `org-return' with INDENT set to t instead."
  686. "9.4"))
  687. (interactive)
  688. (org-return t))
  689. (defmacro org-with-silent-modifications (&rest body)
  690. (declare (obsolete "use `with-silent-modifications' instead." "9.2")
  691. (debug (body)))
  692. `(with-silent-modifications ,@body))
  693. (define-obsolete-function-alias 'org-babel-strip-quotes
  694. 'org-strip-quotes "9.2")
  695. (define-obsolete-variable-alias 'org-sort-agenda-notime-is-late
  696. 'org-agenda-sort-notime-is-late "9.4")
  697. (define-obsolete-variable-alias 'org-sort-agenda-noeffort-is-high
  698. 'org-agenda-sort-noeffort-is-high "9.4")
  699. (defconst org-maybe-keyword-time-regexp
  700. (concat "\\(\\<\\(\\(?:CLO\\(?:CK\\|SED\\)\\|DEADLINE\\|SCHEDULED\\):\\)\\)?"
  701. " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*[]>]"
  702. "\\|"
  703. "<%%([^\r\n>]*>\\)")
  704. "Matches a timestamp, possibly preceded by a keyword.")
  705. (make-obsolete-variable
  706. 'org-maybe-keyword-time-regexp
  707. "use `org-planning-line-re', followed by `org-ts-regexp-both' instead."
  708. "9.4")
  709. (define-obsolete-function-alias 'org-copy 'org-refile-copy "9.4")
  710. (define-obsolete-function-alias 'org-get-last-sibling 'org-get-previous-sibling "9.4")
  711. (define-obsolete-function-alias 'org-truely-invisible-p
  712. 'org-truly-invisible-p "9.6"
  713. "Compatibility alias for legacy misspelling of `org-truly-invisible-p'.")
  714. ;;;; Obsolete link types
  715. (eval-after-load 'ol
  716. '(progn
  717. (org-link-set-parameters "file+emacs") ;since Org 9.0
  718. (org-link-set-parameters "file+sys"))) ;since Org 9.0
  719. ;;; Miscellaneous functions
  720. (defun org-get-x-clipboard (value)
  721. "Get the value of the X or Windows clipboard."
  722. (cond ((and (eq window-system 'x)
  723. (fboundp 'gui-get-selection)) ;Silence byte-compiler.
  724. (org-no-properties
  725. (ignore-errors
  726. (or (gui-get-selection value 'UTF8_STRING)
  727. (gui-get-selection value 'COMPOUND_TEXT)
  728. (gui-get-selection value 'STRING)
  729. (gui-get-selection value 'TEXT)))))
  730. ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
  731. (w32-get-clipboard-data))))
  732. ;; `set-transient-map' is only in Emacs >= 24.4
  733. (defalias 'org-set-transient-map
  734. (if (fboundp 'set-transient-map)
  735. 'set-transient-map
  736. 'set-temporary-overlay-map))
  737. ;;; Region compatibility
  738. (defvar org-ignore-region nil
  739. "Non-nil means temporarily disable the active region.")
  740. (defun org-region-active-p ()
  741. "Non-nil when the region active.
  742. Unlike to `use-region-p', this function also checks
  743. `org-ignore-region'."
  744. (and (not org-ignore-region) (use-region-p)))
  745. (defun org-cursor-to-region-beginning ()
  746. (when (and (org-region-active-p)
  747. (> (point) (region-beginning)))
  748. (exchange-point-and-mark)))
  749. ;;; Invisibility compatibility
  750. (defun org-in-invisibility-spec-p (arg)
  751. "Is ARG a member of `buffer-invisibility-spec'?"
  752. (when (consp buffer-invisibility-spec)
  753. (member arg buffer-invisibility-spec)))
  754. (defun org-move-to-column (column &optional force _buffer)
  755. "Move to column COLUMN.
  756. Pass COLUMN and FORCE to `move-to-column'."
  757. (let ((buffer-invisibility-spec
  758. (if (listp buffer-invisibility-spec)
  759. (remove '(org-filtered) buffer-invisibility-spec)
  760. buffer-invisibility-spec)))
  761. (move-to-column column force)))
  762. (defmacro org-find-library-dir (library)
  763. `(file-name-directory (or (locate-library ,library) "")))
  764. (defun org-count-lines (s)
  765. "How many lines in string S?"
  766. (let ((start 0) (n 1))
  767. (while (string-match "\n" s start)
  768. (setq start (match-end 0) n (1+ n)))
  769. (when (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
  770. (setq n (1- n)))
  771. n))
  772. (defun org-kill-new (string &rest args)
  773. (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
  774. string)
  775. (apply 'kill-new string args))
  776. ;; `font-lock-ensure' is only available from 24.4.50 on
  777. (defalias 'org-font-lock-ensure
  778. (if (fboundp 'font-lock-ensure)
  779. #'font-lock-ensure
  780. (lambda (&optional _beg _end)
  781. (with-no-warnings (font-lock-fontify-buffer)))))
  782. ;; `file-local-name' was added in Emacs 26.1.
  783. (defalias 'org-babel-local-file-name
  784. (if (fboundp 'file-local-name)
  785. 'file-local-name
  786. (lambda (file)
  787. "Return the local name component of FILE."
  788. (or (file-remote-p file 'localname) file))))
  789. ;;;###autoload
  790. (defmacro org-check-version ()
  791. "Try very hard to provide sensible version strings."
  792. (let* ((org-dir (org-find-library-dir "org"))
  793. (org-version.el (concat org-dir "org-version.el"))
  794. (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
  795. (if (require 'org-version org-version.el 'noerror)
  796. '(progn
  797. (autoload 'org-release "org-version.el")
  798. (autoload 'org-git-version "org-version.el"))
  799. (if (require 'org-fixup org-fixup.el 'noerror)
  800. '(org-fixup)
  801. ;; provide fallback definitions and complain
  802. (warn "Could not define org version correctly. Check installation!")
  803. '(progn
  804. (defun org-release () "N/A")
  805. (defun org-git-version () "N/A !!check installation!!"))))))
  806. ;;; Functions for Emacs < 24.4 compatibility
  807. (defun org-define-error (name message)
  808. "Define NAME as a new error signal.
  809. MESSAGE is a string that will be output to the echo area if such
  810. an error is signaled without being caught by a `condition-case'.
  811. Implements `define-error' for older emacsen."
  812. (if (fboundp 'define-error) (define-error name message)
  813. (put name 'error-conditions
  814. (copy-sequence (cons name (get 'error 'error-conditions))))))
  815. (unless (fboundp 'string-suffix-p)
  816. ;; From Emacs subr.el.
  817. (defun string-suffix-p (suffix string &optional ignore-case)
  818. "Return non-nil if SUFFIX is a suffix of STRING.
  819. If IGNORE-CASE is non-nil, the comparison is done without paying
  820. attention to case differences."
  821. (let ((start-pos (- (length string) (length suffix))))
  822. (and (>= start-pos 0)
  823. (eq t (compare-strings suffix nil nil
  824. string start-pos nil ignore-case))))))
  825. ;;; Integration with and fixes for other packages
  826. (defgroup org-imenu-and-speedbar nil
  827. "Options concerning imenu and speedbar in Org mode."
  828. :tag "Org Imenu and Speedbar"
  829. :group 'org-structure)
  830. (defcustom org-imenu-depth 2
  831. "The maximum level for Imenu access to Org headlines.
  832. This also applied for speedbar access."
  833. :type 'integer)
  834. ;;;; Imenu
  835. (defvar-local org-imenu-markers nil
  836. "All markers currently used by Imenu.")
  837. (defun org-imenu-get-tree ()
  838. "Produce the index for Imenu."
  839. (dolist (x org-imenu-markers) (move-marker x nil))
  840. (setq org-imenu-markers nil)
  841. (org-with-wide-buffer
  842. (goto-char (point-max))
  843. (let* ((re (concat "^" (org-get-limited-outline-regexp)))
  844. (subs (make-vector (1+ org-imenu-depth) nil))
  845. (last-level 0))
  846. (while (re-search-backward re nil t)
  847. (let ((level (org-reduced-level (funcall outline-level)))
  848. (headline (org-no-properties
  849. (org-link-display-format (org-get-heading t t t t)))))
  850. (when (and (<= level org-imenu-depth) (org-string-nw-p headline))
  851. (let* ((m (point-marker))
  852. (item (propertize headline 'org-imenu-marker m 'org-imenu t)))
  853. (push m org-imenu-markers)
  854. (if (>= level last-level)
  855. (push (cons item m) (aref subs level))
  856. (push (cons item
  857. (cl-mapcan #'identity (cl-subseq subs (1+ level))))
  858. (aref subs level))
  859. (cl-loop for i from (1+ level) to org-imenu-depth
  860. do (aset subs i nil)))
  861. (setq last-level level)))))
  862. (aref subs 1))))
  863. (eval-after-load 'imenu
  864. '(progn
  865. (add-hook 'imenu-after-jump-hook
  866. (lambda ()
  867. (when (derived-mode-p 'org-mode)
  868. (org-fold-show-context 'org-goto))))
  869. (add-hook 'org-mode-hook
  870. (lambda ()
  871. (setq imenu-create-index-function 'org-imenu-get-tree)))))
  872. ;;;; Speedbar
  873. (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
  874. "Overlay marking the agenda restriction line in speedbar.")
  875. (overlay-put org-speedbar-restriction-lock-overlay
  876. 'face 'org-agenda-restriction-lock)
  877. (overlay-put org-speedbar-restriction-lock-overlay
  878. 'help-echo "Agendas are currently limited to this item.")
  879. (delete-overlay org-speedbar-restriction-lock-overlay)
  880. (defun org-speedbar-set-agenda-restriction ()
  881. "Restrict future agenda commands to the location at point in speedbar.
  882. If there is already a restriction lock at the location, remove it.
  883. To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
  884. (interactive)
  885. (require 'org-agenda)
  886. (let (p m tp np dir txt)
  887. (cond
  888. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  889. 'org-imenu t))
  890. (setq m (get-text-property p 'org-imenu-marker))
  891. (with-current-buffer (marker-buffer m)
  892. (goto-char m)
  893. (if (and org-agenda-overriding-restriction
  894. (member org-agenda-restriction-lock-overlay
  895. (overlays-at (point))))
  896. (org-agenda-remove-restriction-lock 'noupdate)
  897. (org-agenda-set-restriction-lock 'subtree))))
  898. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  899. 'speedbar-function 'speedbar-find-file))
  900. (setq tp (previous-single-property-change
  901. (1+ p) 'speedbar-function)
  902. np (next-single-property-change
  903. tp 'speedbar-function)
  904. dir (speedbar-line-directory)
  905. txt (buffer-substring-no-properties (or tp (point-min))
  906. (or np (point-max))))
  907. (with-current-buffer (find-file-noselect
  908. (let ((default-directory dir))
  909. (expand-file-name txt)))
  910. (unless (derived-mode-p 'org-mode)
  911. (user-error "Cannot restrict to non-Org mode file"))
  912. (org-agenda-set-restriction-lock 'file)))
  913. (t (user-error "Don't know how to restrict Org mode agenda")))
  914. (move-overlay org-speedbar-restriction-lock-overlay
  915. (point-at-bol) (point-at-eol))
  916. (setq current-prefix-arg nil)
  917. (org-agenda-maybe-redo)))
  918. (defvar speedbar-file-key-map)
  919. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  920. (eval-after-load 'speedbar
  921. '(progn
  922. (speedbar-add-supported-extension ".org")
  923. (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
  924. (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
  925. (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
  926. (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  927. (add-hook 'speedbar-visiting-tag-hook
  928. (lambda () (and (derived-mode-p 'org-mode) (org-fold-show-context 'org-goto))))))
  929. ;;;; Add Log
  930. (defun org-add-log-current-headline ()
  931. "Return current headline or nil.
  932. This function ignores inlinetasks. It is meant to be used as
  933. `add-log-current-defun-function' value."
  934. (org-with-limited-levels (org-get-heading t t t t)))
  935. ;;;; Flyspell
  936. (defun org--flyspell-object-check-p (element)
  937. "Non-nil when Flyspell can check object at point.
  938. ELEMENT is the element at point."
  939. (let ((object (save-excursion
  940. (when (looking-at-p "\\>") (backward-char))
  941. (org-element-context element))))
  942. (cl-case (org-element-type object)
  943. ;; Prevent checks in links due to keybinding conflict with
  944. ;; Flyspell.
  945. ((citation citation-reference code entity export-snippet inline-babel-call
  946. inline-src-block line-break latex-fragment link macro
  947. statistics-cookie target timestamp verbatim)
  948. nil)
  949. (footnote-reference
  950. ;; Only in inline footnotes, within the definition.
  951. (and (eq (org-element-property :type object) 'inline)
  952. (< (save-excursion
  953. (goto-char (org-element-property :begin object))
  954. (search-forward ":" nil t 2))
  955. (point))))
  956. (otherwise t))))
  957. (defun org-mode-flyspell-verify ()
  958. "Function used for `flyspell-generic-check-word-predicate'."
  959. (if (org-at-heading-p)
  960. ;; At a headline or an inlinetask, check title only.
  961. (and (save-excursion (beginning-of-line)
  962. (and (let ((case-fold-search t))
  963. (not (looking-at-p "\\*+ END[ \t]*$")))
  964. (let ((case-fold-search nil))
  965. (looking-at org-complex-heading-regexp))))
  966. (match-beginning 4)
  967. (>= (point) (match-beginning 4))
  968. (or (not (match-beginning 5))
  969. (< (point) (match-beginning 5)))
  970. ;; Ignore checks in code, verbatim and others.
  971. (org--flyspell-object-check-p (org-element-at-point-no-context)))
  972. (let* ((element (org-element-at-point-no-context))
  973. (post-affiliated (org-element-property :post-affiliated element)))
  974. (cond
  975. ;; Ignore checks in all affiliated keywords but captions.
  976. ((< (point) post-affiliated)
  977. (and (save-excursion
  978. (beginning-of-line)
  979. (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
  980. (> (point) (match-end 0))
  981. (org--flyspell-object-check-p element)))
  982. ;; Ignore checks in LOGBOOK (or equivalent) drawer.
  983. ((let ((log (org-log-into-drawer)))
  984. (and log
  985. (let ((drawer (org-element-lineage element '(drawer))))
  986. (and drawer
  987. (eq (compare-strings
  988. log nil nil
  989. (org-element-property :drawer-name drawer) nil nil t)
  990. t)))))
  991. nil)
  992. (t
  993. (cl-case (org-element-type element)
  994. ((comment quote-section) t)
  995. (comment-block
  996. ;; Allow checks between block markers, not on them.
  997. (and (> (line-beginning-position) post-affiliated)
  998. (save-excursion
  999. (end-of-line)
  1000. (skip-chars-forward " \r\t\n")
  1001. (< (point) (org-element-property :end element)))))
  1002. ;; Arbitrary list of keywords where checks are meaningful.
  1003. ;; Make sure point is on the value part of the element.
  1004. (keyword
  1005. (and (member (org-element-property :key element)
  1006. '("DESCRIPTION" "TITLE"))
  1007. (save-excursion
  1008. (search-backward ":" (line-beginning-position) t))))
  1009. ;; Check is globally allowed in paragraphs verse blocks and
  1010. ;; table rows (after affiliated keywords) but some objects
  1011. ;; must not be affected.
  1012. ((paragraph table-row verse-block)
  1013. (let ((cbeg (org-element-property :contents-begin element))
  1014. (cend (org-element-property :contents-end element)))
  1015. (and cbeg (>= (point) cbeg) (< (point) cend)
  1016. (org--flyspell-object-check-p element))))))))))
  1017. (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
  1018. (defun org-remove-flyspell-overlays-in (beg end)
  1019. "Remove flyspell overlays in region."
  1020. (and (bound-and-true-p flyspell-mode)
  1021. (fboundp 'flyspell-delete-region-overlays)
  1022. (flyspell-delete-region-overlays beg end)))
  1023. (defvar flyspell-delayed-commands)
  1024. (eval-after-load 'flyspell
  1025. '(add-to-list 'flyspell-delayed-commands 'org-self-insert-command))
  1026. ;;;; Bookmark
  1027. (defun org-bookmark-jump-unhide (&rest _)
  1028. "Unhide the current position, to show the bookmark location."
  1029. (and (derived-mode-p 'org-mode)
  1030. (or (org-invisible-p)
  1031. (save-excursion (goto-char (max (point-min) (1- (point))))
  1032. (org-invisible-p)))
  1033. (org-fold-show-context 'bookmark-jump)))
  1034. ;; Make `bookmark-jump' shows the jump location if it was hidden.
  1035. (add-hook 'bookmark-after-jump-hook #'org-bookmark-jump-unhide)
  1036. ;;;; Calendar
  1037. (defcustom org-calendar-to-agenda-key 'default
  1038. "Key to be installed in `calendar-mode-map' for switching to the agenda.
  1039. The command `org-calendar-goto-agenda' will be bound to this key.
  1040. When set to `default', bind the function to `c', but only if it is
  1041. available in the Calendar keymap. This is the default choice because
  1042. `c' can then be used to switch back and forth between agenda and calendar.
  1043. When nil, `org-calendar-goto-agenda' is not bound to any key."
  1044. :group 'org-agenda
  1045. :type '(choice
  1046. (const :tag "Bind to `c' if available" default)
  1047. (key-sequence :tag "Other binding")
  1048. (const :tag "No binding" nil))
  1049. :safe (lambda (v) (or (symbolp v) (stringp v)))
  1050. :package-version '(Org . "9.2"))
  1051. (defcustom org-calendar-insert-diary-entry-key [?i]
  1052. "The key to be installed in `calendar-mode-map' for adding diary entries.
  1053. This option is irrelevant until `org-agenda-diary-file' has been configured
  1054. to point to an Org file. When that is the case, the command
  1055. `org-agenda-diary-entry' will be bound to the key given here, by default
  1056. `i'. In the calendar, `i' normally adds entries to `diary-file'. So
  1057. if you want to continue doing this, you need to change this to a different
  1058. key."
  1059. :group 'org-agenda
  1060. :type 'sexp)
  1061. (defun org--setup-calendar-bindings ()
  1062. "Bind Org functions in Calendar keymap."
  1063. (pcase org-calendar-to-agenda-key
  1064. (`nil nil)
  1065. ((and key (pred stringp))
  1066. (local-set-key (kbd key) #'org-calendar-goto-agenda))
  1067. ((guard (not (lookup-key calendar-mode-map "c")))
  1068. (local-set-key "c" #'org-calendar-goto-agenda))
  1069. (_ nil))
  1070. (when (and (boundp 'org-agenda-diary-file)
  1071. (not (eq org-agenda-diary-file 'diary-file)))
  1072. (local-set-key org-calendar-insert-diary-entry-key
  1073. #'org-agenda-diary-entry)))
  1074. (eval-after-load 'calendar
  1075. '(add-hook 'calendar-mode-hook #'org--setup-calendar-bindings))
  1076. ;;;; Saveplace
  1077. ;; Make sure saveplace shows the location if it was hidden
  1078. (advice-add 'save-place-find-file-hook :after #'org-bookmark-jump-unhide)
  1079. ;;;; Ecb
  1080. ;; Make sure ecb shows the location if it was hidden
  1081. (advice-add 'ecb-method-clicked :after #'org--ecb-show-context)
  1082. (defun org--ecb-show-context (&rest _)
  1083. "Make hierarchy visible when jumping into location from ECB tree buffer."
  1084. (when (derived-mode-p 'org-mode)
  1085. (org-fold-show-context)))
  1086. ;;;; Simple
  1087. (defun org-mark-jump-unhide (&rest _)
  1088. "Make the point visible with `org-show-context' after jumping to the mark."
  1089. (when (and (derived-mode-p 'org-mode)
  1090. (org-invisible-p))
  1091. (org-fold-show-context 'mark-goto)))
  1092. (advice-add 'pop-to-mark-command :after #'org-mark-jump-unhide)
  1093. (advice-add 'exchange-point-and-mark :after #'org-mark-jump-unhide)
  1094. (advice-add 'pop-global-mark :after #'org-mark-jump-unhide)
  1095. ;;;; Session
  1096. ;; Make "session.el" ignore our circular variable.
  1097. (defvar session-globals-exclude)
  1098. (eval-after-load 'session
  1099. '(add-to-list 'session-globals-exclude 'org-mark-ring))
  1100. ;;;; Speed commands
  1101. (make-obsolete-variable 'org-speed-commands-user
  1102. "configure `org-speed-commands' instead." "9.5")
  1103. (provide 'org-compat)
  1104. ;; Local variables:
  1105. ;; generated-autoload-file: "org-loaddefs.el"
  1106. ;; End:
  1107. ;;; org-compat.el ends here