org-compat.el 48 KB

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