org-compat.el 42 KB

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