org-compat.el 57 KB

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