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