org-compat.el 47 KB

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