org-compat.el 49 KB

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