org-compat.el 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. ;;; org-compat.el --- Compatibility Code for Older Emacsen -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: 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 'org-macs)
  27. (declare-function org-agenda-diary-entry "org-agenda")
  28. (declare-function org-agenda-maybe-redo "org-agenda" ())
  29. (declare-function org-agenda-remove-restriction-lock "org-agenda" (&optional noupdate))
  30. (declare-function org-align-tags "org" (&optional all))
  31. (declare-function org-at-heading-p "org" (&optional ignored))
  32. (declare-function org-at-table.el-p "org" ())
  33. (declare-function org-element-at-point "org-element" ())
  34. (declare-function org-element-context "org-element" (&optional element))
  35. (declare-function org-element-lineage "org-element" (blob &optional types with-self))
  36. (declare-function org-element-type "org-element" (element))
  37. (declare-function org-element-property "org-element" (property element))
  38. (declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
  39. (declare-function org-get-heading "org" (&optional no-tags no-todo no-priority no-comment))
  40. (declare-function org-get-tags "org" (&optional pos local))
  41. (declare-function org-link-display-format "org" (s))
  42. (declare-function org-link-set-parameters "org" (type &rest rest))
  43. (declare-function org-log-into-drawer "org" ())
  44. (declare-function org-make-tag-string "org" (tags))
  45. (declare-function org-reduced-level "org" (l))
  46. (declare-function org-show-context "org" (&optional key))
  47. (declare-function org-table-end "org-table" (&optional table-type))
  48. (declare-function outline-next-heading "outline" ())
  49. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  50. (declare-function table--at-cell-p "table" (position &optional object at-column))
  51. (defvar calendar-mode-map)
  52. (defvar org-complex-heading-regexp)
  53. (defvar org-agenda-diary-file)
  54. (defvar org-agenda-overriding-restriction)
  55. (defvar org-agenda-restriction-lock-overlay)
  56. (defvar org-table-any-border-regexp)
  57. (defvar org-table-dataline-regexp)
  58. (defvar org-table-tab-recognizes-table.el)
  59. (defvar org-table1-hline-regexp)
  60. ;;; Emacs < 27.1 compatibility
  61. (unless (fboundp 'pcomplete-uniquify-list)
  62. ;; The misspelled variant was made obsolete in Emacs 27.1
  63. (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list))
  64. (defun org-current-time-as-list ()
  65. "Compatibility wrapper for `current-time'.
  66. As of Emacs 27.1, `current-time' callers should not assume a list
  67. return value."
  68. (or (ignore-errors (encode-time nil 'list))
  69. (current-time)))
  70. ;;; Emacs < 26.1 compatibility
  71. (if (fboundp 'line-number-display-width)
  72. (defalias 'org-line-number-display-width 'line-number-display-width)
  73. (defun org-line-number-display-width (&rest _) 0))
  74. (unless (fboundp 'file-attribute-modification-time)
  75. (defsubst file-attribute-modification-time (attributes)
  76. "The modification time in ATTRIBUTES returned by `file-attributes'.
  77. This is the time of the last change to the file's contents, and
  78. is a list of integers (HIGH LOW USEC PSEC) in the same style
  79. as (current-time)."
  80. (nth 5 attributes)))
  81. (unless (fboundp 'file-attribute-size)
  82. (defsubst file-attribute-size (attributes)
  83. "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
  84. This is a floating point number if the size is too large for an integer."
  85. (nth 7 attributes)))
  86. ;;; Emacs < 25.1 compatibility
  87. (when (< emacs-major-version 25)
  88. (defalias 'outline-hide-entry 'hide-entry)
  89. (defalias 'outline-hide-sublevels 'hide-sublevels)
  90. (defalias 'outline-hide-subtree 'hide-subtree)
  91. (defalias 'outline-show-branches 'show-branches)
  92. (defalias 'outline-show-children 'show-children)
  93. (defalias 'outline-show-entry 'show-entry)
  94. (defalias 'outline-show-subtree 'show-subtree)
  95. (defalias 'xref-find-definitions 'find-tag)
  96. (defalias 'format-message 'format)
  97. (defalias 'gui-get-selection 'x-get-selection))
  98. (unless (fboundp 'directory-name-p)
  99. (defun directory-name-p (name)
  100. "Return non-nil if NAME ends with a directory separator character."
  101. (let ((len (length name))
  102. (lastc ?.))
  103. (if (> len 0)
  104. (setq lastc (aref name (1- len))))
  105. (or (= lastc ?/)
  106. (and (memq system-type '(windows-nt ms-dos))
  107. (= lastc ?\\))))))
  108. ;; `string-collate-lessp' is new in Emacs 25.
  109. (if (fboundp 'string-collate-lessp)
  110. (defalias 'org-string-collate-lessp
  111. 'string-collate-lessp)
  112. (defun org-string-collate-lessp (s1 s2 &rest _)
  113. "Return non-nil if STRING1 is less than STRING2 in lexicographic order.
  114. Case is significant."
  115. (string< s1 s2)))
  116. ;;; Obsolete aliases (remove them after the next major release).
  117. ;;;; XEmacs compatibility, now removed.
  118. (define-obsolete-function-alias 'org-activate-mark 'activate-mark "Org 9.0")
  119. (define-obsolete-function-alias 'org-add-hook 'add-hook "Org 9.0")
  120. (define-obsolete-function-alias 'org-bound-and-true-p 'bound-and-true-p "Org 9.0")
  121. (define-obsolete-function-alias 'org-decompose-region 'decompose-region "Org 9.0")
  122. (define-obsolete-function-alias 'org-defvaralias 'defvaralias "Org 9.0")
  123. (define-obsolete-function-alias 'org-detach-overlay 'delete-overlay "Org 9.0")
  124. (define-obsolete-function-alias 'org-file-equal-p 'file-equal-p "Org 9.0")
  125. (define-obsolete-function-alias 'org-float-time 'float-time "Org 9.0")
  126. (define-obsolete-function-alias 'org-indent-line-to 'indent-line-to "Org 9.0")
  127. (define-obsolete-function-alias 'org-indent-to-column 'indent-to-column "Org 9.0")
  128. (define-obsolete-function-alias 'org-looking-at-p 'looking-at-p "Org 9.0")
  129. (define-obsolete-function-alias 'org-looking-back 'looking-back "Org 9.0")
  130. (define-obsolete-function-alias 'org-match-string-no-properties 'match-string-no-properties "Org 9.0")
  131. (define-obsolete-function-alias 'org-propertize 'propertize "Org 9.0")
  132. (define-obsolete-function-alias 'org-select-frame-set-input-focus 'select-frame-set-input-focus "Org 9.0")
  133. (define-obsolete-function-alias 'org-file-remote-p 'file-remote-p "Org 9.2")
  134. (defmacro org-re (s)
  135. "Replace posix classes in regular expression S."
  136. (declare (debug (form))
  137. (obsolete "you can safely remove it." "Org 9.0"))
  138. s)
  139. ;;;; Functions from cl-lib that Org used to have its own implementation of.
  140. (define-obsolete-function-alias 'org-count 'cl-count "Org 9.0")
  141. (define-obsolete-function-alias 'org-every 'cl-every "Org 9.0")
  142. (define-obsolete-function-alias 'org-find-if 'cl-find-if "Org 9.0")
  143. (define-obsolete-function-alias 'org-reduce 'cl-reduce "Org 9.0")
  144. (define-obsolete-function-alias 'org-remove-if 'cl-remove-if "Org 9.0")
  145. (define-obsolete-function-alias 'org-remove-if-not 'cl-remove-if-not "Org 9.0")
  146. (define-obsolete-function-alias 'org-some 'cl-some "Org 9.0")
  147. (define-obsolete-function-alias 'org-floor* 'cl-floor "Org 9.0")
  148. (defun org-sublist (list start end)
  149. "Return a section of LIST, from START to END.
  150. Counting starts at 1."
  151. (cl-subseq list (1- start) end))
  152. (make-obsolete 'org-sublist
  153. "use cl-subseq (note the 0-based counting)."
  154. "Org 9.0")
  155. ;;;; Functions available since Emacs 24.3
  156. (define-obsolete-function-alias 'org-buffer-narrowed-p 'buffer-narrowed-p "Org 9.0")
  157. (define-obsolete-function-alias 'org-called-interactively-p 'called-interactively-p "Org 9.0")
  158. (define-obsolete-function-alias 'org-char-to-string 'char-to-string "Org 9.0")
  159. (define-obsolete-function-alias 'org-delete-directory 'delete-directory "Org 9.0")
  160. (define-obsolete-function-alias 'org-format-seconds 'format-seconds "Org 9.0")
  161. (define-obsolete-function-alias 'org-link-escape-browser 'url-encode-url "Org 9.0")
  162. (define-obsolete-function-alias 'org-no-warnings 'with-no-warnings "Org 9.0")
  163. (define-obsolete-function-alias 'org-number-sequence 'number-sequence "Org 9.0")
  164. (define-obsolete-function-alias 'org-pop-to-buffer-same-window 'pop-to-buffer-same-window "Org 9.0")
  165. (define-obsolete-function-alias 'org-string-match-p 'string-match-p "Org 9.0")
  166. ;;;; Functions and variables from previous releases now obsolete.
  167. (define-obsolete-function-alias 'org-element-remove-indentation
  168. 'org-remove-indentation "Org 9.0")
  169. (define-obsolete-variable-alias 'org-latex-create-formula-image-program
  170. 'org-preview-latex-default-process "Org 9.0")
  171. (define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
  172. 'org-preview-latex-image-directory "Org 9.0")
  173. (define-obsolete-function-alias 'org-table-p 'org-at-table-p "Org 9.0")
  174. (define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "Org 9.0")
  175. (define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "Org 8.3")
  176. (define-obsolete-function-alias 'org-image-file-name-regexp
  177. 'image-file-name-regexp "Org 9.0")
  178. (define-obsolete-function-alias 'org-completing-read-no-i
  179. 'completing-read "Org 9.0")
  180. (define-obsolete-function-alias 'org-icompleting-read
  181. 'completing-read "Org 9.0")
  182. (define-obsolete-function-alias 'org-iread-file-name 'read-file-name "Org 9.0")
  183. (define-obsolete-function-alias 'org-days-to-time
  184. 'org-time-stamp-to-now "Org 8.2")
  185. (define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
  186. 'org-agenda-ignore-properties "Org 9.0")
  187. (define-obsolete-function-alias 'org-preview-latex-fragment
  188. 'org-toggle-latex-fragment "Org 8.3")
  189. (define-obsolete-function-alias 'org-export-get-genealogy
  190. 'org-element-lineage "Org 9.0")
  191. (define-obsolete-variable-alias 'org-latex-with-hyperref
  192. 'org-latex-hyperref-template "Org 9.0")
  193. (define-obsolete-variable-alias 'hfy-optimisations 'hfy-optimizations "Org 9.0")
  194. (define-obsolete-variable-alias 'org-export-htmlized-org-css-url
  195. 'org-org-htmlized-css-url "Org 8.2")
  196. (define-obsolete-function-alias 'org-list-parse-list 'org-list-to-lisp "Org 9.0")
  197. (define-obsolete-function-alias 'org-agenda-todayp
  198. 'org-agenda-today-p "Org 9.0")
  199. (define-obsolete-function-alias 'org-babel-examplize-region
  200. 'org-babel-examplify-region "Org 9.0")
  201. (define-obsolete-variable-alias 'org-babel-capitalize-example-region-markers
  202. 'org-babel-uppercase-example-markers "Org 9.1")
  203. (define-obsolete-function-alias 'org-babel-trim 'org-trim "Org 9.0")
  204. (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
  205. (define-obsolete-function-alias 'org-insert-columns-dblock
  206. 'org-columns-insert-dblock "Org 9.0")
  207. (define-obsolete-variable-alias 'org-export-babel-evaluate
  208. 'org-export-use-babel "Org 9.1")
  209. (define-obsolete-function-alias 'org-activate-bracket-links
  210. 'org-activate-links "Org 9.0")
  211. (define-obsolete-function-alias 'org-activate-plain-links 'ignore "Org 9.0")
  212. (define-obsolete-function-alias 'org-activate-angle-links 'ignore "Org 9.0")
  213. (define-obsolete-function-alias 'org-remove-double-quotes 'org-strip-quotes "Org 9.0")
  214. (define-obsolete-function-alias 'org-get-indentation
  215. 'current-indentation "Org 9.2")
  216. (define-obsolete-function-alias 'org-capture-member 'org-capture-get "Org 9.2")
  217. (define-obsolete-function-alias 'org-remove-from-invisibility-spec
  218. 'remove-from-invisibility-spec "Org 9.2")
  219. (define-obsolete-variable-alias 'org-effort-durations 'org-duration-units
  220. "Org 9.2")
  221. (defun org-in-fixed-width-region-p ()
  222. "Non-nil if point in a fixed-width region."
  223. (save-match-data
  224. (eq 'fixed-width (org-element-type (org-element-at-point)))))
  225. (make-obsolete 'org-in-fixed-width-region-p
  226. "use `org-element' library"
  227. "Org 9.0")
  228. (defun org-compatible-face (inherits specs)
  229. "Make a compatible face specification.
  230. If INHERITS is an existing face and if the Emacs version supports
  231. it, just inherit the face. If INHERITS is not given and SPECS
  232. is, use SPECS to define the face."
  233. (declare (indent 1))
  234. (if (facep inherits)
  235. (list (list t :inherit inherits))
  236. specs))
  237. (make-obsolete 'org-compatible-face "you can remove it." "Org 9.0")
  238. (defun org-add-link-type (type &optional follow export)
  239. "Add a new TYPE link.
  240. FOLLOW and EXPORT are two functions.
  241. FOLLOW should take the link path as the single argument and do whatever
  242. is necessary to follow the link, for example find a file or display
  243. a mail message.
  244. EXPORT should format the link path for export to one of the export formats.
  245. It should be a function accepting three arguments:
  246. path the path of the link, the text after the prefix (like \"http:\")
  247. desc the description of the link, if any
  248. format the export format, a symbol like `html' or `latex' or `ascii'.
  249. The function may use the FORMAT information to return different values
  250. depending on the format. The return value will be put literally into
  251. the exported file. If the return value is nil, this means Org should
  252. do what it normally does with links which do not have EXPORT defined.
  253. Org mode has a built-in default for exporting links. If you are happy with
  254. this default, there is no need to define an export function for the link
  255. type. For a simple example of an export function, see `org-bbdb.el'.
  256. If TYPE already exists, update it with the arguments.
  257. See `org-link-parameters' for documentation on the other parameters."
  258. (org-link-set-parameters type :follow follow :export export)
  259. (message "Created %s link." type))
  260. (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." "Org 9.0")
  261. ;;;; Functions unused in Org core.
  262. (defun org-table-recognize-table.el ()
  263. "If there is a table.el table nearby, recognize it and move into it."
  264. (when (and org-table-tab-recognizes-table.el (org-at-table.el-p))
  265. (beginning-of-line)
  266. (unless (or (looking-at org-table-dataline-regexp)
  267. (not (looking-at org-table1-hline-regexp)))
  268. (forward-line)
  269. (when (looking-at org-table-any-border-regexp)
  270. (forward-line -2)))
  271. (if (re-search-forward "|" (org-table-end t) t)
  272. (progn
  273. (require 'table)
  274. (if (table--at-cell-p (point)) t
  275. (message "recognizing table.el table...")
  276. (table-recognize-table)
  277. (message "recognizing table.el table...done")))
  278. (error "This should not happen"))))
  279. ;; Not used since commit 6d1e3082, Feb 2010.
  280. (make-obsolete 'org-table-recognize-table.el
  281. "please notify Org mailing list if you use this function."
  282. "Org 9.0")
  283. (defmacro org-preserve-lc (&rest body)
  284. (declare (debug (body))
  285. (obsolete "please notify Org mailing list if you use this function."
  286. "Org 9.2"))
  287. (org-with-gensyms (line col)
  288. `(let ((,line (org-current-line))
  289. (,col (current-column)))
  290. (unwind-protect
  291. (progn ,@body)
  292. (org-goto-line ,line)
  293. (org-move-to-column ,col)))))
  294. (defun org-version-check (version &rest _)
  295. "Non-nil if VERSION is lower (older) than `emacs-version'."
  296. (declare (obsolete "use `version<' or `fboundp' instead."
  297. "Org 9.2"))
  298. (version< version emacs-version))
  299. (defun org-remove-angle-brackets (s)
  300. (org-unbracket-string "<" ">" s))
  301. (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "Org 9.0")
  302. (defcustom org-publish-sitemap-file-entry-format "%t"
  303. "Format string for site-map file entry.
  304. You could use brackets to delimit on what part the link will be.
  305. %t is the title.
  306. %a is the author.
  307. %d is the date formatted using `org-publish-sitemap-date-format'."
  308. :group 'org-export-publish
  309. :type 'string)
  310. (make-obsolete-variable
  311. 'org-publish-sitemap-file-entry-format
  312. "set `:sitemap-format-entry' in `org-publish-project-alist' instead."
  313. "Org 9.1")
  314. (defvar org-agenda-skip-regexp)
  315. (defun org-agenda-skip-entry-when-regexp-matches ()
  316. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  317. If yes, it returns the end position of this entry, causing agenda commands
  318. to skip the entry but continuing the search in the subtree. This is a
  319. function that can be put into `org-agenda-skip-function' for the duration
  320. of a command."
  321. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  322. (let ((end (save-excursion (org-end-of-subtree t)))
  323. skip)
  324. (save-excursion
  325. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  326. (and skip end)))
  327. (defun org-agenda-skip-subtree-when-regexp-matches ()
  328. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  329. If yes, it returns the end position of this tree, causing agenda commands
  330. to skip this subtree. This is a function that can be put into
  331. `org-agenda-skip-function' for the duration of a command."
  332. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  333. (let ((end (save-excursion (org-end-of-subtree t)))
  334. skip)
  335. (save-excursion
  336. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  337. (and skip end)))
  338. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  339. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  340. If yes, it returns the end position of the current entry (NOT the tree),
  341. causing agenda commands to skip the entry but continuing the search in
  342. the subtree. This is a function that can be put into
  343. `org-agenda-skip-function' for the duration of a command. An important
  344. use of this function is for the stuck project list."
  345. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  346. (let ((end (save-excursion (org-end-of-subtree t)))
  347. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  348. skip)
  349. (save-excursion
  350. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  351. (and skip entry-end)))
  352. (define-obsolete-function-alias 'org-minutes-to-clocksum-string
  353. 'org-duration-from-minutes "Org 9.1")
  354. (define-obsolete-function-alias 'org-hh:mm-string-to-minutes
  355. 'org-duration-to-minutes "Org 9.1")
  356. (define-obsolete-function-alias 'org-duration-string-to-minutes
  357. 'org-duration-to-minutes "Org 9.1")
  358. (make-obsolete-variable 'org-time-clocksum-format
  359. "set `org-duration-format' instead." "Org 9.1")
  360. (make-obsolete-variable 'org-time-clocksum-use-fractional
  361. "set `org-duration-format' instead." "Org 9.1")
  362. (make-obsolete-variable 'org-time-clocksum-fractional-format
  363. "set `org-duration-format' instead." "Org 9.1")
  364. (make-obsolete-variable 'org-time-clocksum-use-effort-durations
  365. "set `org-duration-units' instead." "Org 9.1")
  366. (define-obsolete-function-alias 'org-babel-number-p
  367. 'org-babel--string-to-number "Org 9.0")
  368. (define-obsolete-variable-alias 'org-usenet-links-prefer-google
  369. 'org-gnus-prefer-web-links "Org 9.1")
  370. (define-obsolete-variable-alias 'org-texinfo-def-table-markup
  371. 'org-texinfo-table-default-markup "Org 9.1")
  372. ;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
  373. ;; This make-obsolete call was added 2016-09-01.
  374. (make-obsolete 'org-capture-import-remember-templates
  375. "use the `org-capture-templates' variable instead."
  376. "Org 9.0")
  377. (defun org-show-block-all ()
  378. "Unfold all blocks in the current buffer."
  379. (interactive)
  380. (remove-overlays nil nil 'invisible 'org-hide-block))
  381. (make-obsolete 'org-show-block-all
  382. "use `org-show-all' instead."
  383. "Org 9.2")
  384. (define-obsolete-function-alias 'org-get-tags-at 'org-get-tags "Org 9.2")
  385. (defun org-get-local-tags ()
  386. "Get a list of tags defined in the current headline."
  387. (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
  388. (org-get-tags nil 'local))
  389. (defun org-get-local-tags-at (&optional pos)
  390. "Get a list of tags defined in the current headline."
  391. (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
  392. (org-get-tags pos 'local))
  393. (defun org-get-tags-string ()
  394. "Get the TAGS string in the current headline."
  395. (declare (obsolete "use `org-make-tag-string' instead." "Org 9.2"))
  396. (org-make-tag-string (org-get-tags nil t)))
  397. (define-obsolete-function-alias 'org-set-tags-to 'org-set-tags "Org 9.2")
  398. (defun org-align-all-tags ()
  399. "Align the tags in all headings."
  400. (declare (obsolete "use `org-align-tags' instead." "Org 9.2"))
  401. (org-align-tags t))
  402. (defmacro org-with-silent-modifications (&rest body)
  403. (declare (obsolete "use `with-silent-modifications' instead." "Org 9.2")
  404. (debug (body)))
  405. `(with-silent-modifications ,@body))
  406. (define-obsolete-function-alias 'org-babel-strip-quotes
  407. 'org-strip-quotes "Org 9.2")
  408. ;;;; Obsolete link types
  409. (eval-after-load 'org
  410. '(progn
  411. (org-link-set-parameters "file+emacs") ;since Org 9.0
  412. (org-link-set-parameters "file+sys"))) ;since Org 9.0
  413. ;;; Miscellaneous functions
  414. (defun org-get-x-clipboard (value)
  415. "Get the value of the X or Windows clipboard."
  416. (cond ((and (eq window-system 'x)
  417. (fboundp 'gui-get-selection)) ;Silence byte-compiler.
  418. (org-no-properties
  419. (ignore-errors
  420. (or (gui-get-selection value 'UTF8_STRING)
  421. (gui-get-selection value 'COMPOUND_TEXT)
  422. (gui-get-selection value 'STRING)
  423. (gui-get-selection value 'TEXT)))))
  424. ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
  425. (w32-get-clipboard-data))))
  426. ;; `set-transient-map' is only in Emacs >= 24.4
  427. (defalias 'org-set-transient-map
  428. (if (fboundp 'set-transient-map)
  429. 'set-transient-map
  430. 'set-temporary-overlay-map))
  431. ;;; Region compatibility
  432. (defvar org-ignore-region nil
  433. "Non-nil means temporarily disable the active region.")
  434. (defun org-region-active-p ()
  435. "Non-nil when the region active.
  436. Unlike to `use-region-p', this function also checks
  437. `org-ignore-region'."
  438. (and (not org-ignore-region) (use-region-p)))
  439. (defun org-cursor-to-region-beginning ()
  440. (when (and (org-region-active-p)
  441. (> (point) (region-beginning)))
  442. (exchange-point-and-mark)))
  443. ;;; Invisibility compatibility
  444. (defun org-in-invisibility-spec-p (arg)
  445. "Is ARG a member of `buffer-invisibility-spec'?"
  446. (when (consp buffer-invisibility-spec)
  447. (member arg buffer-invisibility-spec)))
  448. (defun org-move-to-column (column &optional force _buffer)
  449. "Move to column COLUMN.
  450. Pass COLUMN and FORCE to `move-to-column'."
  451. (let ((buffer-invisibility-spec
  452. (if (listp buffer-invisibility-spec)
  453. (remove '(org-filtered) buffer-invisibility-spec)
  454. buffer-invisibility-spec)))
  455. (move-to-column column force)))
  456. (defmacro org-find-library-dir (library)
  457. `(file-name-directory (or (locate-library ,library) "")))
  458. (defun org-count-lines (s)
  459. "How many lines in string S?"
  460. (let ((start 0) (n 1))
  461. (while (string-match "\n" s start)
  462. (setq start (match-end 0) n (1+ n)))
  463. (when (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
  464. (setq n (1- n)))
  465. n))
  466. (defun org-kill-new (string &rest args)
  467. (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
  468. string)
  469. (apply 'kill-new string args))
  470. ;; `font-lock-ensure' is only available from 24.4.50 on
  471. (defalias 'org-font-lock-ensure
  472. (if (fboundp 'font-lock-ensure)
  473. #'font-lock-ensure
  474. (lambda (&optional _beg _end)
  475. (with-no-warnings (font-lock-fontify-buffer)))))
  476. ;; `file-local-name' was added in Emacs 26.1.
  477. (defalias 'org-babel-local-file-name
  478. (if (fboundp 'file-local-name)
  479. 'file-local-name
  480. (lambda (file)
  481. "Return the local name component of FILE."
  482. (or (file-remote-p file 'localname) file))))
  483. ;;;###autoload
  484. (defmacro org-check-version ()
  485. "Try very hard to provide sensible version strings."
  486. (let* ((org-dir (org-find-library-dir "org"))
  487. (org-version.el (concat org-dir "org-version.el"))
  488. (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
  489. (if (require 'org-version org-version.el 'noerror)
  490. '(progn
  491. (autoload 'org-release "org-version.el")
  492. (autoload 'org-git-version "org-version.el"))
  493. (if (require 'org-fixup org-fixup.el 'noerror)
  494. '(org-fixup)
  495. ;; provide fallback definitions and complain
  496. (warn "Could not define org version correctly. Check installation!")
  497. '(progn
  498. (defun org-release () "N/A")
  499. (defun org-git-version () "N/A !!check installation!!"))))))
  500. ;;; Functions for Emacs < 24.4 compatibility
  501. (defun org-define-error (name message)
  502. "Define NAME as a new error signal.
  503. MESSAGE is a string that will be output to the echo area if such
  504. an error is signaled without being caught by a `condition-case'.
  505. Implements `define-error' for older emacsen."
  506. (if (fboundp 'define-error) (define-error name message)
  507. (put name 'error-conditions
  508. (copy-sequence (cons name (get 'error 'error-conditions))))))
  509. (unless (fboundp 'string-suffix-p)
  510. ;; From Emacs subr.el.
  511. (defun string-suffix-p (suffix string &optional ignore-case)
  512. "Return non-nil if SUFFIX is a suffix of STRING.
  513. If IGNORE-CASE is non-nil, the comparison is done without paying
  514. attention to case differences."
  515. (let ((start-pos (- (length string) (length suffix))))
  516. (and (>= start-pos 0)
  517. (eq t (compare-strings suffix nil nil
  518. string start-pos nil ignore-case))))))
  519. (unless (fboundp 'proper-list-p)
  520. ;; `proper-list-p' was added in Emacs 27.1. The function below is
  521. ;; taken from Emacs subr.el 200195e824b^.
  522. (defun proper-list-p (object)
  523. "Return OBJECT's length if it is a proper list, nil otherwise.
  524. A proper list is neither circular nor dotted (i.e., its last cdr
  525. is nil)."
  526. (and (listp object) (ignore-errors (length object)))))
  527. ;;; Integration with and fixes for other packages
  528. (defgroup org-imenu-and-speedbar nil
  529. "Options concerning imenu and speedbar in Org mode."
  530. :tag "Org Imenu and Speedbar"
  531. :group 'org-structure)
  532. (defcustom org-imenu-depth 2
  533. "The maximum level for Imenu access to Org headlines.
  534. This also applied for speedbar access."
  535. :group 'org-imenu-and-speedbar
  536. :type 'integer)
  537. ;;;; Imenu
  538. (defvar-local org-imenu-markers nil
  539. "All markers currently used by Imenu.")
  540. (defun org-imenu-get-tree ()
  541. "Produce the index for Imenu."
  542. (dolist (x org-imenu-markers) (move-marker x nil))
  543. (setq org-imenu-markers nil)
  544. (org-with-wide-buffer
  545. (goto-char (point-max))
  546. (let* ((re (concat "^" (org-get-limited-outline-regexp)))
  547. (subs (make-vector (1+ org-imenu-depth) nil))
  548. (last-level 0))
  549. (while (re-search-backward re nil t)
  550. (let ((level (org-reduced-level (funcall outline-level)))
  551. (headline (org-no-properties
  552. (org-link-display-format (org-get-heading t t t t)))))
  553. (when (and (<= level org-imenu-depth) (org-string-nw-p headline))
  554. (let* ((m (point-marker))
  555. (item (propertize headline 'org-imenu-marker m 'org-imenu t)))
  556. (push m org-imenu-markers)
  557. (if (>= level last-level)
  558. (push (cons item m) (aref subs level))
  559. (push (cons item
  560. (cl-mapcan #'identity (cl-subseq subs (1+ level))))
  561. (aref subs level))
  562. (cl-loop for i from (1+ level) to org-imenu-depth
  563. do (aset subs i nil)))
  564. (setq last-level level)))))
  565. (aref subs 1))))
  566. (eval-after-load "imenu"
  567. '(progn
  568. (add-hook 'imenu-after-jump-hook
  569. (lambda ()
  570. (when (derived-mode-p 'org-mode)
  571. (org-show-context 'org-goto))))
  572. (add-hook 'org-mode-hook
  573. (lambda ()
  574. (setq imenu-create-index-function 'org-imenu-get-tree)))))
  575. ;;;; Speedbar
  576. (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
  577. "Overlay marking the agenda restriction line in speedbar.")
  578. (overlay-put org-speedbar-restriction-lock-overlay
  579. 'face 'org-agenda-restriction-lock)
  580. (overlay-put org-speedbar-restriction-lock-overlay
  581. 'help-echo "Agendas are currently limited to this item.")
  582. (delete-overlay org-speedbar-restriction-lock-overlay)
  583. (defun org-speedbar-set-agenda-restriction ()
  584. "Restrict future agenda commands to the location at point in speedbar.
  585. If there is already a restriction lock at the location, remove it.
  586. To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
  587. (interactive)
  588. (require 'org-agenda)
  589. (let (p m tp np dir txt)
  590. (cond
  591. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  592. 'org-imenu t))
  593. (setq m (get-text-property p 'org-imenu-marker))
  594. (with-current-buffer (marker-buffer m)
  595. (goto-char m)
  596. (if (and org-agenda-overriding-restriction
  597. (member org-agenda-restriction-lock-overlay
  598. (overlays-at (point))))
  599. (org-agenda-remove-restriction-lock 'noupdate)
  600. (org-agenda-set-restriction-lock 'subtree))))
  601. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  602. 'speedbar-function 'speedbar-find-file))
  603. (setq tp (previous-single-property-change
  604. (1+ p) 'speedbar-function)
  605. np (next-single-property-change
  606. tp 'speedbar-function)
  607. dir (speedbar-line-directory)
  608. txt (buffer-substring-no-properties (or tp (point-min))
  609. (or np (point-max))))
  610. (with-current-buffer (find-file-noselect
  611. (let ((default-directory dir))
  612. (expand-file-name txt)))
  613. (unless (derived-mode-p 'org-mode)
  614. (user-error "Cannot restrict to non-Org mode file"))
  615. (org-agenda-set-restriction-lock 'file)))
  616. (t (user-error "Don't know how to restrict Org mode agenda")))
  617. (move-overlay org-speedbar-restriction-lock-overlay
  618. (point-at-bol) (point-at-eol))
  619. (setq current-prefix-arg nil)
  620. (org-agenda-maybe-redo)))
  621. (defvar speedbar-file-key-map)
  622. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  623. (eval-after-load "speedbar"
  624. '(progn
  625. (speedbar-add-supported-extension ".org")
  626. (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
  627. (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
  628. (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
  629. (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  630. (add-hook 'speedbar-visiting-tag-hook
  631. (lambda () (and (derived-mode-p 'org-mode) (org-show-context 'org-goto))))))
  632. ;;;; Add Log
  633. (defun org-add-log-current-headline ()
  634. "Return current headline or nil.
  635. This function ignores inlinetasks. It is meant to be used as
  636. `add-log-current-defun-function' value."
  637. (org-with-limited-levels (org-get-heading t t t t)))
  638. ;;;; Flyspell
  639. (defun org--flyspell-object-check-p (element)
  640. "Non-nil when Flyspell can check object at point.
  641. ELEMENT is the element at point."
  642. (let ((object (save-excursion
  643. (when (looking-at-p "\\>") (backward-char))
  644. (org-element-context element))))
  645. (cl-case (org-element-type object)
  646. ;; Prevent checks in links due to keybinding conflict with
  647. ;; Flyspell.
  648. ((code entity export-snippet inline-babel-call
  649. inline-src-block line-break latex-fragment link macro
  650. statistics-cookie target timestamp verbatim)
  651. nil)
  652. (footnote-reference
  653. ;; Only in inline footnotes, within the definition.
  654. (and (eq (org-element-property :type object) 'inline)
  655. (< (save-excursion
  656. (goto-char (org-element-property :begin object))
  657. (search-forward ":" nil t 2))
  658. (point))))
  659. (otherwise t))))
  660. (defun org-mode-flyspell-verify ()
  661. "Function used for `flyspell-generic-check-word-predicate'."
  662. (if (org-at-heading-p)
  663. ;; At a headline or an inlinetask, check title only. This is
  664. ;; faster than relying on `org-element-at-point'.
  665. (and (save-excursion (beginning-of-line)
  666. (and (let ((case-fold-search t))
  667. (not (looking-at-p "\\*+ END[ \t]*$")))
  668. (let ((case-fold-search nil))
  669. (looking-at org-complex-heading-regexp))))
  670. (match-beginning 4)
  671. (>= (point) (match-beginning 4))
  672. (or (not (match-beginning 5))
  673. (< (point) (match-beginning 5))))
  674. (let* ((element (org-element-at-point))
  675. (post-affiliated (org-element-property :post-affiliated element)))
  676. (cond
  677. ;; Ignore checks in all affiliated keywords but captions.
  678. ((< (point) post-affiliated)
  679. (and (save-excursion
  680. (beginning-of-line)
  681. (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
  682. (> (point) (match-end 0))
  683. (org--flyspell-object-check-p element)))
  684. ;; Ignore checks in LOGBOOK (or equivalent) drawer.
  685. ((let ((log (org-log-into-drawer)))
  686. (and log
  687. (let ((drawer (org-element-lineage element '(drawer))))
  688. (and drawer
  689. (eq (compare-strings
  690. log nil nil
  691. (org-element-property :drawer-name drawer) nil nil t)
  692. t)))))
  693. nil)
  694. (t
  695. (cl-case (org-element-type element)
  696. ((comment quote-section) t)
  697. (comment-block
  698. ;; Allow checks between block markers, not on them.
  699. (and (> (line-beginning-position) post-affiliated)
  700. (save-excursion
  701. (end-of-line)
  702. (skip-chars-forward " \r\t\n")
  703. (< (point) (org-element-property :end element)))))
  704. ;; Arbitrary list of keywords where checks are meaningful.
  705. ;; Make sure point is on the value part of the element.
  706. (keyword
  707. (and (member (org-element-property :key element)
  708. '("DESCRIPTION" "TITLE"))
  709. (save-excursion
  710. (search-backward ":" (line-beginning-position) t))))
  711. ;; Check is globally allowed in paragraphs verse blocks and
  712. ;; table rows (after affiliated keywords) but some objects
  713. ;; must not be affected.
  714. ((paragraph table-row verse-block)
  715. (let ((cbeg (org-element-property :contents-begin element))
  716. (cend (org-element-property :contents-end element)))
  717. (and cbeg (>= (point) cbeg) (< (point) cend)
  718. (org--flyspell-object-check-p element))))))))))
  719. (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
  720. (defun org-remove-flyspell-overlays-in (beg end)
  721. "Remove flyspell overlays in region."
  722. (and (bound-and-true-p flyspell-mode)
  723. (fboundp 'flyspell-delete-region-overlays)
  724. (flyspell-delete-region-overlays beg end)))
  725. (defvar flyspell-delayed-commands)
  726. (eval-after-load "flyspell"
  727. '(add-to-list 'flyspell-delayed-commands 'org-self-insert-command))
  728. ;;;; Bookmark
  729. (defun org-bookmark-jump-unhide ()
  730. "Unhide the current position, to show the bookmark location."
  731. (and (derived-mode-p 'org-mode)
  732. (or (org-invisible-p)
  733. (save-excursion (goto-char (max (point-min) (1- (point))))
  734. (org-invisible-p)))
  735. (org-show-context 'bookmark-jump)))
  736. ;; Make `bookmark-jump' shows the jump location if it was hidden.
  737. (eval-after-load "bookmark"
  738. '(if (boundp 'bookmark-after-jump-hook)
  739. ;; We can use the hook
  740. (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
  741. ;; Hook not available, use advice
  742. (defadvice bookmark-jump (after org-make-visible activate)
  743. "Make the position visible."
  744. (org-bookmark-jump-unhide))))
  745. ;;;; Calendar
  746. (defcustom org-calendar-to-agenda-key 'default
  747. "Key to be installed in `calendar-mode-map' for switching to the agenda.
  748. The command `org-calendar-goto-agenda' will be bound to this key.
  749. When set to `default', bind the function to `c', but only if it is
  750. available in the Calendar keymap. This is the default choice because
  751. `c' can then be used to switch back and forth between agenda and calendar.
  752. When nil, `org-calendar-goto-agenda' is not bound to any key."
  753. :group 'org-agenda
  754. :type '(choice
  755. (const :tag "Bind to `c' if available" default)
  756. (key-sequence :tag "Other binding")
  757. (const :tag "No binding" nil))
  758. :safe (lambda (v) (or (symbolp v) (stringp v)))
  759. :package-version '(Org . "9.2"))
  760. (defcustom org-calendar-insert-diary-entry-key [?i]
  761. "The key to be installed in `calendar-mode-map' for adding diary entries.
  762. This option is irrelevant until `org-agenda-diary-file' has been configured
  763. to point to an Org file. When that is the case, the command
  764. `org-agenda-diary-entry' will be bound to the key given here, by default
  765. `i'. In the calendar, `i' normally adds entries to `diary-file'. So
  766. if you want to continue doing this, you need to change this to a different
  767. key."
  768. :group 'org-agenda
  769. :type 'sexp)
  770. (defun org--setup-calendar-bindings ()
  771. "Bind Org functions in Calendar keymap."
  772. (pcase org-calendar-to-agenda-key
  773. (`nil nil)
  774. ((and key (pred stringp))
  775. (local-set-key (kbd key) #'org-calendar-goto-agenda))
  776. ((guard (not (lookup-key calendar-mode-map "c")))
  777. (local-set-key "c" #'org-calendar-goto-agenda))
  778. (_ nil))
  779. (unless (eq org-agenda-diary-file 'diary-file)
  780. (local-set-key org-calendar-insert-diary-entry-key
  781. #'org-agenda-diary-entry)))
  782. (eval-after-load "calendar"
  783. '(add-hook 'calendar-mode-hook #'org--setup-calendar-bindings))
  784. ;;;; Saveplace
  785. ;; Make sure saveplace shows the location if it was hidden
  786. (eval-after-load "saveplace"
  787. '(defadvice save-place-find-file-hook (after org-make-visible activate)
  788. "Make the position visible."
  789. (org-bookmark-jump-unhide)))
  790. ;;;; Ecb
  791. ;; Make sure ecb shows the location if it was hidden
  792. (eval-after-load "ecb"
  793. '(defadvice ecb-method-clicked (after esf/org-show-context activate)
  794. "Make hierarchy visible when jumping into location from ECB tree buffer."
  795. (when (derived-mode-p 'org-mode)
  796. (org-show-context))))
  797. ;;;; Simple
  798. (defun org-mark-jump-unhide ()
  799. "Make the point visible with `org-show-context' after jumping to the mark."
  800. (when (and (derived-mode-p 'org-mode)
  801. (org-invisible-p))
  802. (org-show-context 'mark-goto)))
  803. (eval-after-load "simple"
  804. '(defadvice pop-to-mark-command (after org-make-visible activate)
  805. "Make the point visible with `org-show-context'."
  806. (org-mark-jump-unhide)))
  807. (eval-after-load "simple"
  808. '(defadvice exchange-point-and-mark (after org-make-visible activate)
  809. "Make the point visible with `org-show-context'."
  810. (org-mark-jump-unhide)))
  811. (eval-after-load "simple"
  812. '(defadvice pop-global-mark (after org-make-visible activate)
  813. "Make the point visible with `org-show-context'."
  814. (org-mark-jump-unhide)))
  815. ;;;; Session
  816. ;; Make "session.el" ignore our circular variable.
  817. (defvar session-globals-exclude)
  818. (eval-after-load "session"
  819. '(add-to-list 'session-globals-exclude 'org-mark-ring))
  820. (provide 'org-compat)
  821. ;;; org-compat.el ends here