org-compat.el 47 KB

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