org-compat.el 37 KB

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