org-compat.el 56 KB

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