org-compat.el 46 KB

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