org-compat.el 45 KB

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