org-compat.el 60 KB

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