org-compat.el 46 KB

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