org-compat.el 47 KB

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