org-compat.el 59 KB

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