org-compat.el 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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-link-display-format "ol" (s))
  42. (declare-function org-link-set-parameters "ol" (type &rest rest))
  43. (declare-function org-log-into-drawer "org" ())
  44. (declare-function org-make-tag-string "org" (tags))
  45. (declare-function org-reduced-level "org" (l))
  46. (declare-function org-show-context "org" (&optional key))
  47. (declare-function org-table-end "org-table" (&optional table-type))
  48. (declare-function outline-next-heading "outline" ())
  49. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  50. (declare-function table--at-cell-p "table" (position &optional object at-column))
  51. (defvar calendar-mode-map)
  52. (defvar org-complex-heading-regexp)
  53. (defvar org-agenda-diary-file)
  54. (defvar org-agenda-overriding-restriction)
  55. (defvar org-agenda-restriction-lock-overlay)
  56. (defvar org-table-any-border-regexp)
  57. (defvar org-table-dataline-regexp)
  58. (defvar org-table-tab-recognizes-table.el)
  59. (defvar org-table1-hline-regexp)
  60. ;;; Emacs < 27.1 compatibility
  61. (unless (fboundp 'proper-list-p)
  62. ;; `proper-list-p' was added in Emacs 27.1. The function below is
  63. ;; taken from Emacs subr.el 200195e824b^.
  64. (defun proper-list-p (object)
  65. "Return OBJECT's length if it is a proper list, nil otherwise.
  66. A proper list is neither circular nor dotted (i.e., its last cdr
  67. is nil)."
  68. (and (listp object) (ignore-errors (length object)))))
  69. (if (fboundp 'xor)
  70. ;; `xor' was added in Emacs 27.1.
  71. (defalias 'org-xor #'xor)
  72. (defsubst org-xor (a b)
  73. "Exclusive `or'."
  74. (if a (not b) b)))
  75. (unless (fboundp 'pcomplete-uniquify-list)
  76. ;; The misspelled variant was made obsolete in Emacs 27.1
  77. (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list))
  78. (if (fboundp 'time-convert)
  79. (progn
  80. (defsubst org-time-convert-to-integer (time)
  81. (time-convert time 'integer))
  82. (defsubst org-time-convert-to-list (time)
  83. (time-convert time 'list)))
  84. (defun org-time-convert-to-integer (time)
  85. (floor (float-time time)))
  86. (defun org-time-convert-to-list (time)
  87. (seconds-to-time (float-time time))))
  88. (defun org--set-faces-extend (faces extend-p)
  89. "Set the :extend attribute of FACES to EXTEND-P.
  90. This is a no-op for Emacs versions lower than 27, since face
  91. extension beyond end of line was not controllable."
  92. (when (fboundp 'set-face-extend)
  93. (mapc (lambda (f) (set-face-extend f extend-p)) faces)))
  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. (defun org-in-fixed-width-region-p ()
  283. "Non-nil if point in a fixed-width region."
  284. (save-match-data
  285. (eq 'fixed-width (org-element-type (org-element-at-point)))))
  286. (make-obsolete 'org-in-fixed-width-region-p
  287. "use `org-element' library"
  288. "Org 9.0")
  289. (defun org-compatible-face (inherits specs)
  290. "Make a compatible face specification.
  291. If INHERITS is an existing face and if the Emacs version supports
  292. it, just inherit the face. If INHERITS is not given and SPECS
  293. is, use SPECS to define the face."
  294. (declare (indent 1))
  295. (if (facep inherits)
  296. (list (list t :inherit inherits))
  297. specs))
  298. (make-obsolete 'org-compatible-face "you can remove it." "Org 9.0")
  299. (defun org-add-link-type (type &optional follow export)
  300. "Add a new TYPE link.
  301. FOLLOW and EXPORT are two functions.
  302. FOLLOW should take the link path as the single argument and do whatever
  303. is necessary to follow the link, for example find a file or display
  304. a mail message.
  305. EXPORT should format the link path for export to one of the export formats.
  306. It should be a function accepting three arguments:
  307. path the path of the link, the text after the prefix (like \"http:\")
  308. desc the description of the link, if any
  309. format the export format, a symbol like `html' or `latex' or `ascii'.
  310. The function may use the FORMAT information to return different values
  311. depending on the format. The return value will be put literally into
  312. the exported file. If the return value is nil, this means Org should
  313. do what it normally does with links which do not have EXPORT defined.
  314. Org mode has a built-in default for exporting links. If you are happy with
  315. this default, there is no need to define an export function for the link
  316. type. For a simple example of an export function, see `org-bbdb.el'.
  317. If TYPE already exists, update it with the arguments.
  318. See `org-link-parameters' for documentation on the other parameters."
  319. (org-link-set-parameters type :follow follow :export export)
  320. (message "Created %s link." type))
  321. (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." "Org 9.0")
  322. ;;;; Functions unused in Org core.
  323. (defun org-table-recognize-table.el ()
  324. "If there is a table.el table nearby, recognize it and move into it."
  325. (when (org-at-table.el-p)
  326. (beginning-of-line)
  327. (unless (or (looking-at org-table-dataline-regexp)
  328. (not (looking-at org-table1-hline-regexp)))
  329. (forward-line)
  330. (when (looking-at org-table-any-border-regexp)
  331. (forward-line -2)))
  332. (if (re-search-forward "|" (org-table-end t) t)
  333. (progn
  334. (require 'table)
  335. (if (table--at-cell-p (point)) t
  336. (message "recognizing table.el table...")
  337. (table-recognize-table)
  338. (message "recognizing table.el table...done")))
  339. (error "This should not happen"))))
  340. ;; Not used since commit 6d1e3082, Feb 2010.
  341. (make-obsolete 'org-table-recognize-table.el
  342. "please notify Org mailing list if you use this function."
  343. "Org 9.0")
  344. (defmacro org-preserve-lc (&rest body)
  345. (declare (debug (body))
  346. (obsolete "please notify Org mailing list if you use this function."
  347. "Org 9.2"))
  348. (org-with-gensyms (line col)
  349. `(let ((,line (org-current-line))
  350. (,col (current-column)))
  351. (unwind-protect
  352. (progn ,@body)
  353. (org-goto-line ,line)
  354. (org-move-to-column ,col)))))
  355. (defun org-version-check (version &rest _)
  356. "Non-nil if VERSION is lower (older) than `emacs-version'."
  357. (declare (obsolete "use `version<' or `fboundp' instead."
  358. "Org 9.2"))
  359. (version< version emacs-version))
  360. (defun org-remove-angle-brackets (s)
  361. (org-unbracket-string "<" ">" s))
  362. (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "Org 9.0")
  363. (defcustom org-publish-sitemap-file-entry-format "%t"
  364. "Format string for site-map file entry.
  365. You could use brackets to delimit on what part the link will be.
  366. %t is the title.
  367. %a is the author.
  368. %d is the date formatted using `org-publish-sitemap-date-format'."
  369. :group 'org-export-publish
  370. :type 'string)
  371. (make-obsolete-variable
  372. 'org-publish-sitemap-file-entry-format
  373. "set `:sitemap-format-entry' in `org-publish-project-alist' instead."
  374. "Org 9.1")
  375. (defvar org-agenda-skip-regexp)
  376. (defun org-agenda-skip-entry-when-regexp-matches ()
  377. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  378. If yes, it returns the end position of this entry, causing agenda commands
  379. to skip the entry but continuing the search in the subtree. This is a
  380. function that can be put into `org-agenda-skip-function' for the duration
  381. of a command."
  382. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  383. (let ((end (save-excursion (org-end-of-subtree t)))
  384. skip)
  385. (save-excursion
  386. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  387. (and skip end)))
  388. (defun org-agenda-skip-subtree-when-regexp-matches ()
  389. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  390. If yes, it returns the end position of this tree, causing agenda commands
  391. to skip this subtree. This is a function that can be put into
  392. `org-agenda-skip-function' for the duration of a command."
  393. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  394. (let ((end (save-excursion (org-end-of-subtree t)))
  395. skip)
  396. (save-excursion
  397. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  398. (and skip end)))
  399. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  400. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  401. If yes, it returns the end position of the current entry (NOT the tree),
  402. causing agenda commands to skip the entry but continuing the search in
  403. the subtree. This is a function that can be put into
  404. `org-agenda-skip-function' for the duration of a command. An important
  405. use of this function is for the stuck project list."
  406. (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
  407. (let ((end (save-excursion (org-end-of-subtree t)))
  408. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  409. skip)
  410. (save-excursion
  411. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  412. (and skip entry-end)))
  413. (define-obsolete-function-alias 'org-minutes-to-clocksum-string
  414. 'org-duration-from-minutes "Org 9.1")
  415. (define-obsolete-function-alias 'org-hh:mm-string-to-minutes
  416. 'org-duration-to-minutes "Org 9.1")
  417. (define-obsolete-function-alias 'org-duration-string-to-minutes
  418. 'org-duration-to-minutes "Org 9.1")
  419. (make-obsolete-variable 'org-time-clocksum-format
  420. "set `org-duration-format' instead." "Org 9.1")
  421. (make-obsolete-variable 'org-time-clocksum-use-fractional
  422. "set `org-duration-format' instead." "Org 9.1")
  423. (make-obsolete-variable 'org-time-clocksum-fractional-format
  424. "set `org-duration-format' instead." "Org 9.1")
  425. (make-obsolete-variable 'org-time-clocksum-use-effort-durations
  426. "set `org-duration-units' instead." "Org 9.1")
  427. (define-obsolete-function-alias 'org-babel-number-p
  428. 'org-babel--string-to-number "Org 9.0")
  429. (define-obsolete-variable-alias 'org-usenet-links-prefer-google
  430. 'org-gnus-prefer-web-links "Org 9.1")
  431. (define-obsolete-variable-alias 'org-texinfo-def-table-markup
  432. 'org-texinfo-table-default-markup "Org 9.1")
  433. (define-obsolete-variable-alias 'org-agenda-overriding-columns-format
  434. 'org-overriding-columns-format "Org 9.2.2")
  435. (define-obsolete-variable-alias 'org-doi-server-url
  436. 'org-link-doi-server-url "Org 9.3")
  437. (define-obsolete-variable-alias 'org-email-link-description-format
  438. 'org-link-email-description-format "Org 9.3")
  439. (define-obsolete-variable-alias 'org-make-link-description-function
  440. 'org-link-make-description-function "Org 9.3")
  441. (define-obsolete-variable-alias 'org-from-is-user-regexp
  442. 'org-link-from-user-regexp "Org 9.3")
  443. (define-obsolete-variable-alias 'org-descriptive-links
  444. 'org-link-descriptive "Org 9.3")
  445. (define-obsolete-variable-alias 'org-context-in-file-links
  446. 'org-link-context-for-files "Org 9.3")
  447. (define-obsolete-variable-alias 'org-keep-stored-link-after-insertion
  448. 'org-link-keep-stored-after-insertion "Org 9.3")
  449. (define-obsolete-variable-alias 'org-display-internal-link-with-indirect-buffer
  450. 'org-link-use-indirect-buffer-for-internals "Org 9.3")
  451. (define-obsolete-variable-alias 'org-confirm-shell-link-function
  452. 'org-link-shell-confirm-function "Org 9.3")
  453. (define-obsolete-variable-alias 'org-confirm-shell-link-not-regexp
  454. 'org-link-shell-skip-confirm-regexp "Org 9.3")
  455. (define-obsolete-variable-alias 'org-confirm-elisp-link-function
  456. 'org-link-elisp-confirm-function "Org 9.3")
  457. (define-obsolete-variable-alias 'org-confirm-elisp-link-not-regexp
  458. 'org-link-elisp-skip-confirm-regexp "Org 9.3")
  459. (define-obsolete-function-alias 'org-file-complete-link
  460. 'org-link-complete-file "Org 9.3")
  461. (define-obsolete-function-alias 'org-email-link-description
  462. 'org-link-email-description "Org 9.3")
  463. (define-obsolete-function-alias 'org-make-link-string
  464. 'org-link-make-string "Org 9.3")
  465. (define-obsolete-function-alias 'org-store-link-props
  466. 'org-link-store-props "Org 9.3")
  467. (define-obsolete-function-alias 'org-add-link-props
  468. 'org-link-add-props "Org 9.3")
  469. (define-obsolete-function-alias 'org-make-org-heading-search-string
  470. 'org-link-heading-search-string "Org 9.3")
  471. (define-obsolete-function-alias 'org-make-link-regexps
  472. 'org-link-make-regexps "Org 9.3")
  473. (define-obsolete-variable-alias 'org-angle-link-re
  474. 'org-link-angle-re "Org 9.3")
  475. (define-obsolete-variable-alias 'org-plain-link-re
  476. 'org-link-plain-re "Org 9.3")
  477. (define-obsolete-variable-alias 'org-bracket-link-regexp
  478. 'org-link-bracket-re "Org 9.3")
  479. (define-obsolete-variable-alias 'org-bracket-link-analytic-regexp
  480. 'org-link-bracket-re "Org 9.3")
  481. (define-obsolete-variable-alias 'org-any-link-re
  482. 'org-link-any-re "Org 9.3")
  483. (define-obsolete-function-alias 'org-open-link-from-string
  484. 'org-link-open-from-string "Org 9.3")
  485. (define-obsolete-function-alias 'org-add-angle-brackets
  486. 'org-link-add-angle-brackets "Org 9.3")
  487. ;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
  488. ;; This make-obsolete call was added 2016-09-01.
  489. (make-obsolete 'org-capture-import-remember-templates
  490. "use the `org-capture-templates' variable instead."
  491. "Org 9.0")
  492. (defun org-show-block-all ()
  493. "Unfold all blocks in the current buffer."
  494. (interactive)
  495. (remove-overlays nil nil 'invisible 'org-hide-block))
  496. (make-obsolete 'org-show-block-all
  497. "use `org-show-all' instead."
  498. "Org 9.2")
  499. (define-obsolete-function-alias 'org-get-tags-at 'org-get-tags "Org 9.2")
  500. (defun org-get-local-tags ()
  501. "Get a list of tags defined in the current headline."
  502. (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
  503. (org-get-tags nil 'local))
  504. (defun org-get-local-tags-at (&optional pos)
  505. "Get a list of tags defined in the current headline."
  506. (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
  507. (org-get-tags pos 'local))
  508. (defun org-get-tags-string ()
  509. "Get the TAGS string in the current headline."
  510. (declare (obsolete "use `org-make-tag-string' instead." "Org 9.2"))
  511. (org-make-tag-string (org-get-tags nil t)))
  512. (define-obsolete-function-alias 'org-set-tags-to 'org-set-tags "Org 9.2")
  513. (defun org-align-all-tags ()
  514. "Align the tags in all headings."
  515. (declare (obsolete "use `org-align-tags' instead." "Org 9.2"))
  516. (org-align-tags t))
  517. (defmacro org-with-silent-modifications (&rest body)
  518. (declare (obsolete "use `with-silent-modifications' instead." "Org 9.2")
  519. (debug (body)))
  520. `(with-silent-modifications ,@body))
  521. (define-obsolete-function-alias 'org-babel-strip-quotes
  522. 'org-strip-quotes "Org 9.2")
  523. ;;;; Obsolete link types
  524. (eval-after-load 'ol
  525. '(progn
  526. (org-link-set-parameters "file+emacs") ;since Org 9.0
  527. (org-link-set-parameters "file+sys"))) ;since Org 9.0
  528. ;;; Miscellaneous functions
  529. (defun org-get-x-clipboard (value)
  530. "Get the value of the X or Windows clipboard."
  531. (cond ((and (eq window-system 'x)
  532. (fboundp 'gui-get-selection)) ;Silence byte-compiler.
  533. (org-no-properties
  534. (ignore-errors
  535. (or (gui-get-selection value 'UTF8_STRING)
  536. (gui-get-selection value 'COMPOUND_TEXT)
  537. (gui-get-selection value 'STRING)
  538. (gui-get-selection value 'TEXT)))))
  539. ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
  540. (w32-get-clipboard-data))))
  541. ;; `set-transient-map' is only in Emacs >= 24.4
  542. (defalias 'org-set-transient-map
  543. (if (fboundp 'set-transient-map)
  544. 'set-transient-map
  545. 'set-temporary-overlay-map))
  546. ;;; Region compatibility
  547. (defvar org-ignore-region nil
  548. "Non-nil means temporarily disable the active region.")
  549. (defun org-region-active-p ()
  550. "Non-nil when the region active.
  551. Unlike to `use-region-p', this function also checks
  552. `org-ignore-region'."
  553. (and (not org-ignore-region) (use-region-p)))
  554. (defun org-cursor-to-region-beginning ()
  555. (when (and (org-region-active-p)
  556. (> (point) (region-beginning)))
  557. (exchange-point-and-mark)))
  558. ;;; Invisibility compatibility
  559. (defun org-in-invisibility-spec-p (arg)
  560. "Is ARG a member of `buffer-invisibility-spec'?"
  561. (when (consp buffer-invisibility-spec)
  562. (member arg buffer-invisibility-spec)))
  563. (defun org-move-to-column (column &optional force _buffer)
  564. "Move to column COLUMN.
  565. Pass COLUMN and FORCE to `move-to-column'."
  566. (let ((buffer-invisibility-spec
  567. (if (listp buffer-invisibility-spec)
  568. (remove '(org-filtered) buffer-invisibility-spec)
  569. buffer-invisibility-spec)))
  570. (move-to-column column force)))
  571. (defmacro org-find-library-dir (library)
  572. `(file-name-directory (or (locate-library ,library) "")))
  573. (defun org-count-lines (s)
  574. "How many lines in string S?"
  575. (let ((start 0) (n 1))
  576. (while (string-match "\n" s start)
  577. (setq start (match-end 0) n (1+ n)))
  578. (when (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
  579. (setq n (1- n)))
  580. n))
  581. (defun org-kill-new (string &rest args)
  582. (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
  583. string)
  584. (apply 'kill-new string args))
  585. ;; `font-lock-ensure' is only available from 24.4.50 on
  586. (defalias 'org-font-lock-ensure
  587. (if (fboundp 'font-lock-ensure)
  588. #'font-lock-ensure
  589. (lambda (&optional _beg _end)
  590. (with-no-warnings (font-lock-fontify-buffer)))))
  591. ;; `file-local-name' was added in Emacs 26.1.
  592. (defalias 'org-babel-local-file-name
  593. (if (fboundp 'file-local-name)
  594. 'file-local-name
  595. (lambda (file)
  596. "Return the local name component of FILE."
  597. (or (file-remote-p file 'localname) file))))
  598. ;;;###autoload
  599. (defmacro org-check-version ()
  600. "Try very hard to provide sensible version strings."
  601. (let* ((org-dir (org-find-library-dir "org"))
  602. (org-version.el (concat org-dir "org-version.el"))
  603. (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
  604. (if (require 'org-version org-version.el 'noerror)
  605. '(progn
  606. (autoload 'org-release "org-version.el")
  607. (autoload 'org-git-version "org-version.el"))
  608. (if (require 'org-fixup org-fixup.el 'noerror)
  609. '(org-fixup)
  610. ;; provide fallback definitions and complain
  611. (warn "Could not define org version correctly. Check installation!")
  612. '(progn
  613. (defun org-release () "N/A")
  614. (defun org-git-version () "N/A !!check installation!!"))))))
  615. ;;; Functions for Emacs < 24.4 compatibility
  616. (defun org-define-error (name message)
  617. "Define NAME as a new error signal.
  618. MESSAGE is a string that will be output to the echo area if such
  619. an error is signaled without being caught by a `condition-case'.
  620. Implements `define-error' for older emacsen."
  621. (if (fboundp 'define-error) (define-error name message)
  622. (put name 'error-conditions
  623. (copy-sequence (cons name (get 'error 'error-conditions))))))
  624. (unless (fboundp 'string-suffix-p)
  625. ;; From Emacs subr.el.
  626. (defun string-suffix-p (suffix string &optional ignore-case)
  627. "Return non-nil if SUFFIX is a suffix of STRING.
  628. If IGNORE-CASE is non-nil, the comparison is done without paying
  629. attention to case differences."
  630. (let ((start-pos (- (length string) (length suffix))))
  631. (and (>= start-pos 0)
  632. (eq t (compare-strings suffix nil nil
  633. string start-pos nil ignore-case))))))
  634. ;;; Integration with and fixes for other packages
  635. (defgroup org-imenu-and-speedbar nil
  636. "Options concerning imenu and speedbar in Org mode."
  637. :tag "Org Imenu and Speedbar"
  638. :group 'org-structure)
  639. (defcustom org-imenu-depth 2
  640. "The maximum level for Imenu access to Org headlines.
  641. This also applied for speedbar access."
  642. :group 'org-imenu-and-speedbar
  643. :type 'integer)
  644. ;;;; Imenu
  645. (defvar-local org-imenu-markers nil
  646. "All markers currently used by Imenu.")
  647. (defun org-imenu-get-tree ()
  648. "Produce the index for Imenu."
  649. (dolist (x org-imenu-markers) (move-marker x nil))
  650. (setq org-imenu-markers nil)
  651. (org-with-wide-buffer
  652. (goto-char (point-max))
  653. (let* ((re (concat "^" (org-get-limited-outline-regexp)))
  654. (subs (make-vector (1+ org-imenu-depth) nil))
  655. (last-level 0))
  656. (while (re-search-backward re nil t)
  657. (let ((level (org-reduced-level (funcall outline-level)))
  658. (headline (org-no-properties
  659. (org-link-display-format (org-get-heading t t t t)))))
  660. (when (and (<= level org-imenu-depth) (org-string-nw-p headline))
  661. (let* ((m (point-marker))
  662. (item (propertize headline 'org-imenu-marker m 'org-imenu t)))
  663. (push m org-imenu-markers)
  664. (if (>= level last-level)
  665. (push (cons item m) (aref subs level))
  666. (push (cons item
  667. (cl-mapcan #'identity (cl-subseq subs (1+ level))))
  668. (aref subs level))
  669. (cl-loop for i from (1+ level) to org-imenu-depth
  670. do (aset subs i nil)))
  671. (setq last-level level)))))
  672. (aref subs 1))))
  673. (eval-after-load "imenu"
  674. '(progn
  675. (add-hook 'imenu-after-jump-hook
  676. (lambda ()
  677. (when (derived-mode-p 'org-mode)
  678. (org-show-context 'org-goto))))
  679. (add-hook 'org-mode-hook
  680. (lambda ()
  681. (setq imenu-create-index-function 'org-imenu-get-tree)))))
  682. ;;;; Speedbar
  683. (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
  684. "Overlay marking the agenda restriction line in speedbar.")
  685. (overlay-put org-speedbar-restriction-lock-overlay
  686. 'face 'org-agenda-restriction-lock)
  687. (overlay-put org-speedbar-restriction-lock-overlay
  688. 'help-echo "Agendas are currently limited to this item.")
  689. (delete-overlay org-speedbar-restriction-lock-overlay)
  690. (defun org-speedbar-set-agenda-restriction ()
  691. "Restrict future agenda commands to the location at point in speedbar.
  692. If there is already a restriction lock at the location, remove it.
  693. To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
  694. (interactive)
  695. (require 'org-agenda)
  696. (let (p m tp np dir txt)
  697. (cond
  698. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  699. 'org-imenu t))
  700. (setq m (get-text-property p 'org-imenu-marker))
  701. (with-current-buffer (marker-buffer m)
  702. (goto-char m)
  703. (if (and org-agenda-overriding-restriction
  704. (member org-agenda-restriction-lock-overlay
  705. (overlays-at (point))))
  706. (org-agenda-remove-restriction-lock 'noupdate)
  707. (org-agenda-set-restriction-lock 'subtree))))
  708. ((setq p (text-property-any (point-at-bol) (point-at-eol)
  709. 'speedbar-function 'speedbar-find-file))
  710. (setq tp (previous-single-property-change
  711. (1+ p) 'speedbar-function)
  712. np (next-single-property-change
  713. tp 'speedbar-function)
  714. dir (speedbar-line-directory)
  715. txt (buffer-substring-no-properties (or tp (point-min))
  716. (or np (point-max))))
  717. (with-current-buffer (find-file-noselect
  718. (let ((default-directory dir))
  719. (expand-file-name txt)))
  720. (unless (derived-mode-p 'org-mode)
  721. (user-error "Cannot restrict to non-Org mode file"))
  722. (org-agenda-set-restriction-lock 'file)))
  723. (t (user-error "Don't know how to restrict Org mode agenda")))
  724. (move-overlay org-speedbar-restriction-lock-overlay
  725. (point-at-bol) (point-at-eol))
  726. (setq current-prefix-arg nil)
  727. (org-agenda-maybe-redo)))
  728. (defvar speedbar-file-key-map)
  729. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  730. (eval-after-load "speedbar"
  731. '(progn
  732. (speedbar-add-supported-extension ".org")
  733. (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
  734. (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
  735. (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
  736. (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  737. (add-hook 'speedbar-visiting-tag-hook
  738. (lambda () (and (derived-mode-p 'org-mode) (org-show-context 'org-goto))))))
  739. ;;;; Add Log
  740. (defun org-add-log-current-headline ()
  741. "Return current headline or nil.
  742. This function ignores inlinetasks. It is meant to be used as
  743. `add-log-current-defun-function' value."
  744. (org-with-limited-levels (org-get-heading t t t t)))
  745. ;;;; Flyspell
  746. (defun org--flyspell-object-check-p (element)
  747. "Non-nil when Flyspell can check object at point.
  748. ELEMENT is the element at point."
  749. (let ((object (save-excursion
  750. (when (looking-at-p "\\>") (backward-char))
  751. (org-element-context element))))
  752. (cl-case (org-element-type object)
  753. ;; Prevent checks in links due to keybinding conflict with
  754. ;; Flyspell.
  755. ((code entity export-snippet inline-babel-call
  756. inline-src-block line-break latex-fragment link macro
  757. statistics-cookie target timestamp verbatim)
  758. nil)
  759. (footnote-reference
  760. ;; Only in inline footnotes, within the definition.
  761. (and (eq (org-element-property :type object) 'inline)
  762. (< (save-excursion
  763. (goto-char (org-element-property :begin object))
  764. (search-forward ":" nil t 2))
  765. (point))))
  766. (otherwise t))))
  767. (defun org-mode-flyspell-verify ()
  768. "Function used for `flyspell-generic-check-word-predicate'."
  769. (if (org-at-heading-p)
  770. ;; At a headline or an inlinetask, check title only. This is
  771. ;; faster than relying on `org-element-at-point'.
  772. (and (save-excursion (beginning-of-line)
  773. (and (let ((case-fold-search t))
  774. (not (looking-at-p "\\*+ END[ \t]*$")))
  775. (let ((case-fold-search nil))
  776. (looking-at org-complex-heading-regexp))))
  777. (match-beginning 4)
  778. (>= (point) (match-beginning 4))
  779. (or (not (match-beginning 5))
  780. (< (point) (match-beginning 5))))
  781. (let* ((element (org-element-at-point))
  782. (post-affiliated (org-element-property :post-affiliated element)))
  783. (cond
  784. ;; Ignore checks in all affiliated keywords but captions.
  785. ((< (point) post-affiliated)
  786. (and (save-excursion
  787. (beginning-of-line)
  788. (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
  789. (> (point) (match-end 0))
  790. (org--flyspell-object-check-p element)))
  791. ;; Ignore checks in LOGBOOK (or equivalent) drawer.
  792. ((let ((log (org-log-into-drawer)))
  793. (and log
  794. (let ((drawer (org-element-lineage element '(drawer))))
  795. (and drawer
  796. (eq (compare-strings
  797. log nil nil
  798. (org-element-property :drawer-name drawer) nil nil t)
  799. t)))))
  800. nil)
  801. (t
  802. (cl-case (org-element-type element)
  803. ((comment quote-section) t)
  804. (comment-block
  805. ;; Allow checks between block markers, not on them.
  806. (and (> (line-beginning-position) post-affiliated)
  807. (save-excursion
  808. (end-of-line)
  809. (skip-chars-forward " \r\t\n")
  810. (< (point) (org-element-property :end element)))))
  811. ;; Arbitrary list of keywords where checks are meaningful.
  812. ;; Make sure point is on the value part of the element.
  813. (keyword
  814. (and (member (org-element-property :key element)
  815. '("DESCRIPTION" "TITLE"))
  816. (save-excursion
  817. (search-backward ":" (line-beginning-position) t))))
  818. ;; Check is globally allowed in paragraphs verse blocks and
  819. ;; table rows (after affiliated keywords) but some objects
  820. ;; must not be affected.
  821. ((paragraph table-row verse-block)
  822. (let ((cbeg (org-element-property :contents-begin element))
  823. (cend (org-element-property :contents-end element)))
  824. (and cbeg (>= (point) cbeg) (< (point) cend)
  825. (org--flyspell-object-check-p element))))))))))
  826. (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
  827. (defun org-remove-flyspell-overlays-in (beg end)
  828. "Remove flyspell overlays in region."
  829. (and (bound-and-true-p flyspell-mode)
  830. (fboundp 'flyspell-delete-region-overlays)
  831. (flyspell-delete-region-overlays beg end)))
  832. (defvar flyspell-delayed-commands)
  833. (eval-after-load "flyspell"
  834. '(add-to-list 'flyspell-delayed-commands 'org-self-insert-command))
  835. ;;;; Bookmark
  836. (defun org-bookmark-jump-unhide ()
  837. "Unhide the current position, to show the bookmark location."
  838. (and (derived-mode-p 'org-mode)
  839. (or (org-invisible-p)
  840. (save-excursion (goto-char (max (point-min) (1- (point))))
  841. (org-invisible-p)))
  842. (org-show-context 'bookmark-jump)))
  843. ;; Make `bookmark-jump' shows the jump location if it was hidden.
  844. (eval-after-load "bookmark"
  845. '(if (boundp 'bookmark-after-jump-hook)
  846. ;; We can use the hook
  847. (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
  848. ;; Hook not available, use advice
  849. (defadvice bookmark-jump (after org-make-visible activate)
  850. "Make the position visible."
  851. (org-bookmark-jump-unhide))))
  852. ;;;; Calendar
  853. (defcustom org-calendar-to-agenda-key 'default
  854. "Key to be installed in `calendar-mode-map' for switching to the agenda.
  855. The command `org-calendar-goto-agenda' will be bound to this key.
  856. When set to `default', bind the function to `c', but only if it is
  857. available in the Calendar keymap. This is the default choice because
  858. `c' can then be used to switch back and forth between agenda and calendar.
  859. When nil, `org-calendar-goto-agenda' is not bound to any key."
  860. :group 'org-agenda
  861. :type '(choice
  862. (const :tag "Bind to `c' if available" default)
  863. (key-sequence :tag "Other binding")
  864. (const :tag "No binding" nil))
  865. :safe (lambda (v) (or (symbolp v) (stringp v)))
  866. :package-version '(Org . "9.2"))
  867. (defcustom org-calendar-insert-diary-entry-key [?i]
  868. "The key to be installed in `calendar-mode-map' for adding diary entries.
  869. This option is irrelevant until `org-agenda-diary-file' has been configured
  870. to point to an Org file. When that is the case, the command
  871. `org-agenda-diary-entry' will be bound to the key given here, by default
  872. `i'. In the calendar, `i' normally adds entries to `diary-file'. So
  873. if you want to continue doing this, you need to change this to a different
  874. key."
  875. :group 'org-agenda
  876. :type 'sexp)
  877. (defun org--setup-calendar-bindings ()
  878. "Bind Org functions in Calendar keymap."
  879. (pcase org-calendar-to-agenda-key
  880. (`nil nil)
  881. ((and key (pred stringp))
  882. (local-set-key (kbd key) #'org-calendar-goto-agenda))
  883. ((guard (not (lookup-key calendar-mode-map "c")))
  884. (local-set-key "c" #'org-calendar-goto-agenda))
  885. (_ nil))
  886. (unless (and (boundp 'org-agenda-diary-file)
  887. (eq org-agenda-diary-file 'diary-file))
  888. (local-set-key org-calendar-insert-diary-entry-key
  889. #'org-agenda-diary-entry)))
  890. (eval-after-load "calendar"
  891. '(add-hook 'calendar-mode-hook #'org--setup-calendar-bindings))
  892. ;;;; Saveplace
  893. ;; Make sure saveplace shows the location if it was hidden
  894. (eval-after-load "saveplace"
  895. '(defadvice save-place-find-file-hook (after org-make-visible activate)
  896. "Make the position visible."
  897. (org-bookmark-jump-unhide)))
  898. ;;;; Ecb
  899. ;; Make sure ecb shows the location if it was hidden
  900. (eval-after-load "ecb"
  901. '(defadvice ecb-method-clicked (after esf/org-show-context activate)
  902. "Make hierarchy visible when jumping into location from ECB tree buffer."
  903. (when (derived-mode-p 'org-mode)
  904. (org-show-context))))
  905. ;;;; Simple
  906. (defun org-mark-jump-unhide ()
  907. "Make the point visible with `org-show-context' after jumping to the mark."
  908. (when (and (derived-mode-p 'org-mode)
  909. (org-invisible-p))
  910. (org-show-context 'mark-goto)))
  911. (eval-after-load "simple"
  912. '(defadvice pop-to-mark-command (after org-make-visible activate)
  913. "Make the point visible with `org-show-context'."
  914. (org-mark-jump-unhide)))
  915. (eval-after-load "simple"
  916. '(defadvice exchange-point-and-mark (after org-make-visible activate)
  917. "Make the point visible with `org-show-context'."
  918. (org-mark-jump-unhide)))
  919. (eval-after-load "simple"
  920. '(defadvice pop-global-mark (after org-make-visible activate)
  921. "Make the point visible with `org-show-context'."
  922. (org-mark-jump-unhide)))
  923. ;;;; Session
  924. ;; Make "session.el" ignore our circular variable.
  925. (defvar session-globals-exclude)
  926. (eval-after-load "session"
  927. '(add-to-list 'session-globals-exclude 'org-mark-ring))
  928. (provide 'org-compat)
  929. ;;; org-compat.el ends here