org-compat.el 48 KB

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