org-compat.el 46 KB

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