org-compat.el 46 KB

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