org-compat.el 60 KB

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