1 ;;; org-compat.el --- Compatibility Code for Older Emacsen -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2004-2018 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: https://orgmode.org
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file contains code needed for compatibility with older
28 ;; versions of GNU Emacs and integration with other packages.
35 (declare-function org-agenda-diary-entry
"org-agenda")
36 (declare-function org-agenda-maybe-redo
"org-agenda" ())
37 (declare-function org-at-heading-p
"org" (&optional ignored
))
38 (declare-function org-at-table.el-p
"org" ())
39 (declare-function org-element-at-point
"org-element" ())
40 (declare-function org-element-context
"org-element" (&optional element
))
41 (declare-function org-element-lineage
"org-element" (blob &optional types with-self
))
42 (declare-function org-element-type
"org-element" (element))
43 (declare-function org-element-property
"org-element" (property element
))
44 (declare-function org-end-of-subtree
"org" (&optional invisible-ok to-heading
))
45 (declare-function org-invisible-p
"org" (&optional pos
))
46 (declare-function org-link-display-format
"org" (s))
47 (declare-function org-link-set-parameters
"org" (type &rest rest
))
48 (declare-function org-log-into-drawer
"org" ())
49 (declare-function org-reduced-level
"org" (l))
50 (declare-function org-show-context
"org" (&optional key
))
51 (declare-function org-table-end
"org-table" (&optional table-type
))
52 (declare-function outline-next-heading
"outline" ())
53 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
54 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
56 (defvar calendar-mode-map
)
57 (defvar org-complex-heading-regexp
)
58 (defvar org-agenda-diary-file
)
59 (defvar org-table-any-border-regexp
)
60 (defvar org-table-dataline-regexp
)
61 (defvar org-table-tab-recognizes-table.el
)
62 (defvar org-table1-hline-regexp
)
65 ;;; Emacs < 25.1 compatibility
67 (when (< emacs-major-version
25)
68 (defalias 'outline-hide-entry
'hide-entry
)
69 (defalias 'outline-hide-sublevels
'hide-sublevels
)
70 (defalias 'outline-hide-subtree
'hide-subtree
)
71 (defalias 'outline-show-branches
'show-branches
)
72 (defalias 'outline-show-children
'show-children
)
73 (defalias 'outline-show-entry
'show-entry
)
74 (defalias 'outline-show-subtree
'show-subtree
)
75 (defalias 'xref-find-definitions
'find-tag
)
76 (defalias 'format-message
'format
)
77 (defalias 'gui-get-selection
'x-get-selection
))
79 (unless (fboundp 'directory-name-p
)
80 (defun directory-name-p (name)
81 "Return non-nil if NAME ends with a directory separator character."
82 (let ((len (length name
))
85 (setq lastc
(aref name
(1- len
))))
87 (and (memq system-type
'(windows-nt ms-dos
))
91 ;;; Obsolete aliases (remove them after the next major release).
93 ;;;; XEmacs compatibility, now removed.
94 (define-obsolete-function-alias 'org-activate-mark
'activate-mark
)
95 (define-obsolete-function-alias 'org-add-hook
'add-hook
"Org 9.0")
96 (define-obsolete-function-alias 'org-bound-and-true-p
'bound-and-true-p
"Org 9.0")
97 (define-obsolete-function-alias 'org-decompose-region
'decompose-region
"Org 9.0")
98 (define-obsolete-function-alias 'org-defvaralias
'defvaralias
"Org 9.0")
99 (define-obsolete-function-alias 'org-detach-overlay
'delete-overlay
"Org 9.0")
100 (define-obsolete-function-alias 'org-file-equal-p
'file-equal-p
"Org 9.0")
101 (define-obsolete-function-alias 'org-float-time
'float-time
"Org 9.0")
102 (define-obsolete-function-alias 'org-indent-line-to
'indent-line-to
"Org 9.0")
103 (define-obsolete-function-alias 'org-indent-to-column
'indent-to-column
"Org 9.0")
104 (define-obsolete-function-alias 'org-looking-at-p
'looking-at-p
"Org 9.0")
105 (define-obsolete-function-alias 'org-looking-back
'looking-back
"Org 9.0")
106 (define-obsolete-function-alias 'org-match-string-no-properties
'match-string-no-properties
"Org 9.0")
107 (define-obsolete-function-alias 'org-propertize
'propertize
"Org 9.0")
108 (define-obsolete-function-alias 'org-select-frame-set-input-focus
'select-frame-set-input-focus
"Org 9.0")
111 "Replace posix classes in regular expression S."
112 (declare (debug (form))
113 (obsolete "you can safely remove it." "Org 9.0"))
116 ;;;; Functions from cl-lib that Org used to have its own implementation of.
117 (define-obsolete-function-alias 'org-count
'cl-count
"Org 9.0")
118 (define-obsolete-function-alias 'org-every
'cl-every
"Org 9.0")
119 (define-obsolete-function-alias 'org-find-if
'cl-find-if
"Org 9.0")
120 (define-obsolete-function-alias 'org-reduce
'cl-reduce
"Org 9.0")
121 (define-obsolete-function-alias 'org-remove-if
'cl-remove-if
"Org 9.0")
122 (define-obsolete-function-alias 'org-remove-if-not
'cl-remove-if-not
"Org 9.0")
123 (define-obsolete-function-alias 'org-some
'cl-some
"Org 9.0")
124 (define-obsolete-function-alias 'org-floor
* 'cl-floor
"Org 9.0")
126 (defun org-sublist (list start end
)
127 "Return a section of LIST, from START to END.
128 Counting starts at 1."
129 (cl-subseq list
(1- start
) end
))
130 (make-obsolete 'org-sublist
131 "use cl-subseq (note the 0-based counting)."
135 ;;;; Functions available since Emacs 24.3
136 (define-obsolete-function-alias 'org-buffer-narrowed-p
'buffer-narrowed-p
"Org 9.0")
137 (define-obsolete-function-alias 'org-called-interactively-p
'called-interactively-p
"Org 9.0")
138 (define-obsolete-function-alias 'org-char-to-string
'char-to-string
"Org 9.0")
139 (define-obsolete-function-alias 'org-delete-directory
'delete-directory
"Org 9.0")
140 (define-obsolete-function-alias 'org-format-seconds
'format-seconds
"Org 9.0")
141 (define-obsolete-function-alias 'org-link-escape-browser
'url-encode-url
"Org 9.0")
142 (define-obsolete-function-alias 'org-no-warnings
'with-no-warnings
"Org 9.0")
143 (define-obsolete-function-alias 'org-number-sequence
'number-sequence
"Org 9.0")
144 (define-obsolete-function-alias 'org-pop-to-buffer-same-window
'pop-to-buffer-same-window
"Org 9.0")
145 (define-obsolete-function-alias 'org-string-match-p
'string-match-p
"Org 9.0")
147 ;;;; Functions and variables from previous releases now obsolete.
148 (define-obsolete-function-alias 'org-element-remove-indentation
149 'org-remove-indentation
"Org 9.0")
150 (define-obsolete-variable-alias 'org-latex-create-formula-image-program
151 'org-preview-latex-default-process
"Org 9.0")
152 (define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
153 'org-preview-latex-image-directory
"Org 9.0")
154 (define-obsolete-function-alias 'org-table-p
'org-at-table-p
"Org 9.0")
155 (define-obsolete-function-alias 'org-on-heading-p
'org-at-heading-p
"Org 9.0")
156 (define-obsolete-function-alias 'org-at-regexp-p
'org-in-regexp
"Org 8.3")
157 (define-obsolete-function-alias 'org-image-file-name-regexp
158 'image-file-name-regexp
"Org 9.0")
159 (define-obsolete-function-alias 'org-completing-read-no-i
160 'completing-read
"Org 9.0")
161 (define-obsolete-function-alias 'org-icompleting-read
162 'completing-read
"Org 9.0")
163 (define-obsolete-function-alias 'org-iread-file-name
'read-file-name
"Org 9.0")
164 (define-obsolete-function-alias 'org-days-to-time
165 'org-time-stamp-to-now
"Org 8.2")
166 (define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
167 'org-agenda-ignore-properties
"Org 9.0")
168 (define-obsolete-function-alias 'org-preview-latex-fragment
169 'org-toggle-latex-fragment
"Org 8.3")
170 (define-obsolete-function-alias 'org-export-get-genealogy
171 'org-element-lineage
"Org 9.0")
172 (define-obsolete-variable-alias 'org-latex-with-hyperref
173 'org-latex-hyperref-template
"Org 9.0")
174 (define-obsolete-variable-alias 'hfy-optimisations
'hfy-optimizations
"Org 9.0")
175 (define-obsolete-variable-alias 'org-export-htmlized-org-css-url
176 'org-org-htmlized-css-url
"Org 8.2")
177 (define-obsolete-function-alias 'org-list-parse-list
'org-list-to-lisp
"Org 9.0")
178 (define-obsolete-function-alias 'org-agenda-todayp
179 'org-agenda-today-p
"Org 9.0")
180 (define-obsolete-function-alias 'org-babel-examplize-region
181 'org-babel-examplify-region
"Org 9.0")
182 (define-obsolete-variable-alias 'org-babel-capitalize-example-region-markers
183 'org-babel-uppercase-example-markers
"Org 9.1")
185 (define-obsolete-function-alias 'org-babel-trim
'org-trim
"Org 9.0")
186 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
187 (define-obsolete-function-alias 'org-insert-columns-dblock
188 'org-columns-insert-dblock
"Org 9.0")
189 (define-obsolete-variable-alias 'org-export-babel-evaluate
190 'org-export-use-babel
"Org 9.1")
191 (define-obsolete-function-alias 'org-activate-bracket-links
192 'org-activate-links
"Org 9.0")
193 (define-obsolete-function-alias 'org-activate-plain-links
'ignore
"Org 9.0")
194 (define-obsolete-function-alias 'org-activate-angle-links
'ignore
"Org 9.0")
196 (defun org-in-fixed-width-region-p ()
197 "Non-nil if point in a fixed-width region."
199 (eq 'fixed-width
(org-element-type (org-element-at-point)))))
200 (make-obsolete 'org-in-fixed-width-region-p
201 "use `org-element' library"
204 (defun org-compatible-face (inherits specs
)
205 "Make a compatible face specification.
206 If INHERITS is an existing face and if the Emacs version supports
207 it, just inherit the face. If INHERITS is not given and SPECS
208 is, use SPECS to define the face."
211 (list (list t
:inherit inherits
))
213 (make-obsolete 'org-compatible-face
"you can remove it." "Org 9.0")
215 (defun org-add-link-type (type &optional follow export
)
216 "Add a new TYPE link.
217 FOLLOW and EXPORT are two functions.
219 FOLLOW should take the link path as the single argument and do whatever
220 is necessary to follow the link, for example find a file or display
223 EXPORT should format the link path for export to one of the export formats.
224 It should be a function accepting three arguments:
226 path the path of the link, the text after the prefix (like \"http:\")
227 desc the description of the link, if any
228 format the export format, a symbol like `html' or `latex' or `ascii'.
230 The function may use the FORMAT information to return different values
231 depending on the format. The return value will be put literally into
232 the exported file. If the return value is nil, this means Org should
233 do what it normally does with links which do not have EXPORT defined.
235 Org mode has a built-in default for exporting links. If you are happy with
236 this default, there is no need to define an export function for the link
237 type. For a simple example of an export function, see `org-bbdb.el'.
239 If TYPE already exists, update it with the arguments.
240 See `org-link-parameters' for documentation on the other parameters."
241 (org-link-set-parameters type
:follow follow
:export export
)
242 (message "Created %s link." type
))
244 (make-obsolete 'org-add-link-type
"use `org-link-set-parameters' instead." "Org 9.0")
246 (defun org-table-recognize-table.el
()
247 "If there is a table.el table nearby, recognize it and move into it."
248 (when (and org-table-tab-recognizes-table.el
(org-at-table.el-p
))
250 (unless (or (looking-at org-table-dataline-regexp
)
251 (not (looking-at org-table1-hline-regexp
)))
253 (when (looking-at org-table-any-border-regexp
)
255 (if (re-search-forward "|" (org-table-end t
) t
)
258 (if (table--at-cell-p (point)) t
259 (message "recognizing table.el table...")
260 (table-recognize-table)
261 (message "recognizing table.el table...done")))
262 (error "This should not happen"))))
264 ;; Not used by Org core since commit 6d1e3082, Feb 2010.
265 (make-obsolete 'org-table-recognize-table.el
266 "please notify the org mailing list if you use this function."
269 (defun org-remove-angle-brackets (s)
270 (org-unbracket-string "<" ">" s
))
271 (make-obsolete 'org-remove-angle-brackets
'org-unbracket-string
"Org 9.0")
273 (defun org-remove-double-quotes (s)
274 (org-unbracket-string "\"" "\"" s
))
275 (make-obsolete 'org-remove-double-quotes
'org-unbracket-string
"Org 9.0")
277 (defcustom org-publish-sitemap-file-entry-format
"%t"
278 "Format string for site-map file entry.
279 You could use brackets to delimit on what part the link will be.
283 %d is the date formatted using `org-publish-sitemap-date-format'."
284 :group
'org-export-publish
286 (make-obsolete-variable
287 'org-publish-sitemap-file-entry-format
288 "set `:sitemap-format-entry' in `org-publish-project-alist' instead."
291 (defvar org-agenda-skip-regexp
)
292 (defun org-agenda-skip-entry-when-regexp-matches ()
293 "Check if the current entry contains match for `org-agenda-skip-regexp'.
294 If yes, it returns the end position of this entry, causing agenda commands
295 to skip the entry but continuing the search in the subtree. This is a
296 function that can be put into `org-agenda-skip-function' for the duration
298 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
299 (let ((end (save-excursion (org-end-of-subtree t
)))
302 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
305 (defun org-agenda-skip-subtree-when-regexp-matches ()
306 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
307 If yes, it returns the end position of this tree, causing agenda commands
308 to skip this subtree. This is a function that can be put into
309 `org-agenda-skip-function' for the duration of a command."
310 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
311 (let ((end (save-excursion (org-end-of-subtree t
)))
314 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
317 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
318 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
319 If yes, it returns the end position of the current entry (NOT the tree),
320 causing agenda commands to skip the entry but continuing the search in
321 the subtree. This is a function that can be put into
322 `org-agenda-skip-function' for the duration of a command. An important
323 use of this function is for the stuck project list."
324 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
325 (let ((end (save-excursion (org-end-of-subtree t
)))
326 (entry-end (save-excursion (outline-next-heading) (1- (point))))
329 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
330 (and skip entry-end
)))
332 (define-obsolete-function-alias 'org-minutes-to-clocksum-string
333 'org-duration-from-minutes
"Org 9.1")
335 (define-obsolete-function-alias 'org-hh
:mm-string-to-minutes
336 'org-duration-to-minutes
"Org 9.1")
338 (define-obsolete-function-alias 'org-duration-string-to-minutes
339 'org-duration-to-minutes
"Org 9.1")
341 (make-obsolete-variable 'org-time-clocksum-format
342 "set `org-duration-format' instead." "Org 9.1")
344 (make-obsolete-variable 'org-time-clocksum-use-fractional
345 "set `org-duration-format' instead." "Org 9.1")
347 (make-obsolete-variable 'org-time-clocksum-fractional-format
348 "set `org-duration-format' instead." "Org 9.1")
350 (make-obsolete-variable 'org-time-clocksum-use-effort-durations
351 "set `org-duration-units' instead." "Org 9.1")
353 (define-obsolete-function-alias 'org-babel-number-p
354 'org-babel--string-to-number
"Org 9.0")
356 (define-obsolete-variable-alias 'org-usenet-links-prefer-google
357 'org-gnus-prefer-web-links
"Org 9.1")
359 (define-obsolete-variable-alias 'org-texinfo-def-table-markup
360 'org-texinfo-table-default-markup
"Org 9.1")
362 ;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
363 ;; This make-obsolete call was added 2016-09-01.
364 (make-obsolete 'org-capture-import-remember-templates
365 "use the `org-capture-templates' variable instead."
368 (defun org-show-block-all ()
369 "Unfold all blocks in the current buffer."
371 (remove-overlays nil nil
'invisible
'org-hide-block
))
373 (make-obsolete 'org-show-block-all
374 "use `org-show-all' instead."
378 ;;;; Obsolete link types
380 (eval-after-load 'org
382 (org-link-set-parameters "file+emacs") ;since Org 9.0
383 (org-link-set-parameters "file+sys"))) ;since Org 9.0
387 ;;; Miscellaneous functions
389 (defun org-version-check (version feature level
)
390 (let* ((v1 (mapcar 'string-to-number
(split-string version
"[.]")))
391 (v2 (mapcar 'string-to-number
(split-string emacs-version
"[.]")))
392 (rmaj (or (nth 0 v1
) 99))
393 (rmin (or (nth 1 v1
) 99))
394 (rbld (or (nth 2 v1
) 99))
395 (maj (or (nth 0 v2
) 0))
396 (min (or (nth 1 v2
) 0))
397 (bld (or (nth 2 v2
) 0)))
404 (if (eq level
:predicate
)
405 ;; just return if we have the version
407 (let ((msg (format "Emacs %s or greater is recommended for %s"
409 (display-warning 'org msg level
)
413 (defun org-get-x-clipboard (value)
414 "Get the value of the X or Windows clipboard."
415 (cond ((and (eq window-system
'x
)
416 (fboundp 'gui-get-selection
)) ;Silence byte-compiler.
419 (or (gui-get-selection value
'UTF8_STRING
)
420 (gui-get-selection value
'COMPOUND_TEXT
)
421 (gui-get-selection value
'STRING
)
422 (gui-get-selection value
'TEXT
)))))
423 ((and (eq window-system
'w32
) (fboundp 'w32-get-clipboard-data
))
424 (w32-get-clipboard-data))))
426 (defun org-fit-window-to-buffer (&optional window max-height min-height
428 "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
429 WINDOW defaults to the selected window. MAX-HEIGHT and MIN-HEIGHT are
430 passed through to `fit-window-to-buffer'. If SHRINK-ONLY is set, call
431 `shrink-window-if-larger-than-buffer' instead, the height limit is
432 ignored in this case."
433 (cond ((if (fboundp 'window-full-width-p
)
434 (not (window-full-width-p window
))
435 ;; do nothing if another window would suffer
436 (> (frame-width) (window-width window
))))
437 ((and (fboundp 'fit-window-to-buffer
) (not shrink-only
))
438 (fit-window-to-buffer window max-height min-height
))
439 ((fboundp 'shrink-window-if-larger-than-buffer
)
440 (shrink-window-if-larger-than-buffer window
)))
441 (or window
(selected-window)))
443 ;; `set-transient-map' is only in Emacs >= 24.4
444 (defalias 'org-set-transient-map
445 (if (fboundp 'set-transient-map
)
447 'set-temporary-overlay-map
))
450 ;;; Region compatibility
452 (defvar org-ignore-region nil
453 "Non-nil means temporarily disable the active region.")
455 (defun org-region-active-p ()
456 "Non-nil when the region active.
457 Unlike to `use-region-p', this function also checks
458 `org-ignore-region'."
459 (and (not org-ignore-region
) (use-region-p)))
461 (defun org-cursor-to-region-beginning ()
462 (when (and (org-region-active-p)
463 (> (point) (region-beginning)))
464 (exchange-point-and-mark)))
467 ;;; Invisibility compatibility
469 (defun org-remove-from-invisibility-spec (arg)
470 "Remove elements from `buffer-invisibility-spec'."
471 (if (fboundp 'remove-from-invisibility-spec
)
472 (remove-from-invisibility-spec arg
)
473 (if (consp buffer-invisibility-spec
)
474 (setq buffer-invisibility-spec
475 (delete arg buffer-invisibility-spec
)))))
477 (defun org-in-invisibility-spec-p (arg)
478 "Is ARG a member of `buffer-invisibility-spec'?"
479 (if (consp buffer-invisibility-spec
)
480 (member arg buffer-invisibility-spec
)))
482 (defun org-move-to-column (column &optional force _buffer
)
483 "Move to column COLUMN.
484 Pass COLUMN and FORCE to `move-to-column'."
485 (let ((buffer-invisibility-spec
486 (if (listp buffer-invisibility-spec
)
487 (remove '(org-filtered) buffer-invisibility-spec
)
488 buffer-invisibility-spec
)))
489 (move-to-column column force
)))
491 (defmacro org-find-library-dir
(library)
492 `(file-name-directory (or (locate-library ,library
) "")))
494 (defun org-count-lines (s)
495 "How many lines in string S?"
496 (let ((start 0) (n 1))
497 (while (string-match "\n" s start
)
498 (setq start
(match-end 0) n
(1+ n
)))
499 (if (and (> (length s
) 0) (= (aref s
(1- (length s
))) ?
\n))
503 (defun org-kill-new (string &rest args
)
504 (remove-text-properties 0 (length string
) '(line-prefix t wrap-prefix t
)
506 (apply 'kill-new string args
))
508 ;; `font-lock-ensure' is only available from 24.4.50 on
509 (defalias 'org-font-lock-ensure
510 (if (fboundp 'font-lock-ensure
)
512 (lambda (&optional _beg _end
)
513 (with-no-warnings (font-lock-fontify-buffer)))))
515 ;; `file-local-name' was added in Emacs 26.1.
516 (defalias 'org-babel-local-file-name
517 (if (fboundp 'file-local-name
)
520 "Return the local name component of FILE."
521 (or (file-remote-p file
'localname
) file
))))
523 (defmacro org-no-popups
(&rest body
)
524 "Suppress popup windows.
525 Let-bind some variables to nil around BODY to achieve the desired
526 effect, which variables to use depends on the Emacs version."
527 (if (org-version-check "24.2.50" "" :predicate
)
528 `(let (pop-up-frames display-buffer-alist
)
530 `(let (pop-up-frames special-display-buffer-names special-display-regexps special-display-function
)
534 (defmacro org-check-version
()
535 "Try very hard to provide sensible version strings."
536 (let* ((org-dir (org-find-library-dir "org"))
537 (org-version.el
(concat org-dir
"org-version.el"))
538 (org-fixup.el
(concat org-dir
"../mk/org-fixup.el")))
539 (if (require 'org-version org-version.el
'noerror
)
541 (autoload 'org-release
"org-version.el")
542 (autoload 'org-git-version
"org-version.el"))
543 (if (require 'org-fixup org-fixup.el
'noerror
)
545 ;; provide fallback definitions and complain
546 (warn "Could not define org version correctly. Check installation!")
548 (defun org-release () "N/A")
549 (defun org-git-version () "N/A !!check installation!!"))))))
551 (defmacro org-with-silent-modifications
(&rest body
)
552 (if (fboundp 'with-silent-modifications
)
553 `(with-silent-modifications ,@body
)
554 `(org-unmodified ,@body
)))
555 (def-edebug-spec org-with-silent-modifications
(body))
558 ;;; Functions for Emacs < 24.4 compatibility
560 (defun org-define-error (name message
)
561 "Define NAME as a new error signal.
562 MESSAGE is a string that will be output to the echo area if such
563 an error is signaled without being caught by a `condition-case'.
564 Implements `define-error' for older emacsen."
565 (if (fboundp 'define-error
) (define-error name message
)
566 (put name
'error-conditions
567 (copy-sequence (cons name
(get 'error
'error-conditions
))))))
569 (unless (fboundp 'string-suffix-p
)
570 ;; From Emacs subr.el.
571 (defun string-suffix-p (suffix string
&optional ignore-case
)
572 "Return non-nil if SUFFIX is a suffix of STRING.
573 If IGNORE-CASE is non-nil, the comparison is done without paying
574 attention to case differences."
575 (let ((start-pos (- (length string
) (length suffix
))))
576 (and (>= start-pos
0)
577 (eq t
(compare-strings suffix nil nil
578 string start-pos nil ignore-case
))))))
581 ;;; Integration with and fixes for other packages
583 (defgroup org-imenu-and-speedbar nil
584 "Options concerning imenu and speedbar in Org mode."
585 :tag
"Org Imenu and Speedbar"
586 :group
'org-structure
)
588 (defcustom org-imenu-depth
2
589 "The maximum level for Imenu access to Org headlines.
590 This also applied for speedbar access."
591 :group
'org-imenu-and-speedbar
596 (defvar-local org-imenu-markers nil
597 "All markers currently used by Imenu.")
599 (defun org-imenu-new-marker (&optional pos
)
600 "Return a new marker for use by Imenu, and remember the marker."
601 (let ((m (make-marker)))
602 (move-marker m
(or pos
(point)))
603 (push m org-imenu-markers
)
606 (defun org-imenu-get-tree ()
607 "Produce the index for Imenu."
608 (dolist (x org-imenu-markers
) (move-marker x nil
))
609 (setq org-imenu-markers nil
)
610 (let* ((case-fold-search nil
)
612 (re (concat "^" (org-get-limited-outline-regexp)))
613 (subs (make-vector (1+ n
) nil
))
616 (org-with-wide-buffer
617 (goto-char (point-max))
618 (while (re-search-backward re nil t
)
619 (setq level
(org-reduced-level (funcall outline-level
)))
620 (when (and (<= level n
)
621 (looking-at org-complex-heading-regexp
)
622 (setq head0
(match-string-no-properties 4)))
623 (setq head
(org-link-display-format head0
)
624 m
(org-imenu-new-marker))
625 (org-add-props head nil
'org-imenu-marker m
'org-imenu t
)
626 (if (>= level last-level
)
627 (push (cons head m
) (aref subs level
))
628 (push (cons head
(aref subs
(1+ level
))) (aref subs level
))
629 (cl-loop for i from
(1+ level
) to n do
(aset subs i nil
)))
630 (setq last-level level
))))
633 (eval-after-load "imenu"
635 (add-hook 'imenu-after-jump-hook
637 (when (derived-mode-p 'org-mode
)
638 (org-show-context 'org-goto
))))))
642 (defvar org-speedbar-restriction-lock-overlay
(make-overlay 1 1)
643 "Overlay marking the agenda restriction line in speedbar.")
644 (overlay-put org-speedbar-restriction-lock-overlay
645 'face
'org-agenda-restriction-lock
)
646 (overlay-put org-speedbar-restriction-lock-overlay
647 'help-echo
"Agendas are currently limited to this item.")
648 (delete-overlay org-speedbar-restriction-lock-overlay
)
650 (defun org-speedbar-set-agenda-restriction ()
651 "Restrict future agenda commands to the location at point in speedbar.
652 To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
654 (require 'org-agenda
)
655 (let (p m tp np dir txt
)
657 ((setq p
(text-property-any (point-at-bol) (point-at-eol)
659 (setq m
(get-text-property p
'org-imenu-marker
))
660 (with-current-buffer (marker-buffer m
)
662 (org-agenda-set-restriction-lock 'subtree
)))
663 ((setq p
(text-property-any (point-at-bol) (point-at-eol)
664 'speedbar-function
'speedbar-find-file
))
665 (setq tp
(previous-single-property-change
666 (1+ p
) 'speedbar-function
)
667 np
(next-single-property-change
668 tp
'speedbar-function
)
669 dir
(speedbar-line-directory)
670 txt
(buffer-substring-no-properties (or tp
(point-min))
671 (or np
(point-max))))
672 (with-current-buffer (find-file-noselect
673 (let ((default-directory dir
))
674 (expand-file-name txt
)))
675 (unless (derived-mode-p 'org-mode
)
676 (user-error "Cannot restrict to non-Org mode file"))
677 (org-agenda-set-restriction-lock 'file
)))
678 (t (user-error "Don't know how to restrict Org mode agenda")))
679 (move-overlay org-speedbar-restriction-lock-overlay
680 (point-at-bol) (point-at-eol))
681 (setq current-prefix-arg nil
)
682 (org-agenda-maybe-redo)))
684 (defvar speedbar-file-key-map
)
685 (declare-function speedbar-add-supported-extension
"speedbar" (extension))
686 (eval-after-load "speedbar"
688 (speedbar-add-supported-extension ".org")
689 (define-key speedbar-file-key-map
"<" 'org-speedbar-set-agenda-restriction
)
690 (define-key speedbar-file-key-map
"\C-c\C-x<" 'org-speedbar-set-agenda-restriction
)
691 (define-key speedbar-file-key-map
">" 'org-agenda-remove-restriction-lock
)
692 (define-key speedbar-file-key-map
"\C-c\C-x>" 'org-agenda-remove-restriction-lock
)
693 (add-hook 'speedbar-visiting-tag-hook
694 (lambda () (and (derived-mode-p 'org-mode
) (org-show-context 'org-goto
))))))
698 (defun org--flyspell-object-check-p (element)
699 "Non-nil when Flyspell can check object at point.
700 ELEMENT is the element at point."
701 (let ((object (save-excursion
702 (when (looking-at-p "\\>") (backward-char))
703 (org-element-context element
))))
704 (cl-case (org-element-type object
)
705 ;; Prevent checks in links due to keybinding conflict with
707 ((code entity export-snippet inline-babel-call
708 inline-src-block line-break latex-fragment link macro
709 statistics-cookie target timestamp verbatim
)
712 ;; Only in inline footnotes, within the definition.
713 (and (eq (org-element-property :type object
) 'inline
)
715 (goto-char (org-element-property :begin object
))
716 (search-forward ":" nil t
2))
720 (defun org-mode-flyspell-verify ()
721 "Function used for `flyspell-generic-check-word-predicate'."
722 (if (org-at-heading-p)
723 ;; At a headline or an inlinetask, check title only. This is
724 ;; faster than relying on `org-element-at-point'.
725 (and (save-excursion (beginning-of-line)
726 (and (let ((case-fold-search t
))
727 (not (looking-at-p "\\*+ END[ \t]*$")))
728 (let ((case-fold-search nil
))
729 (looking-at org-complex-heading-regexp
))))
731 (>= (point) (match-beginning 4))
732 (or (not (match-beginning 5))
733 (< (point) (match-beginning 5))))
734 (let* ((element (org-element-at-point))
735 (post-affiliated (org-element-property :post-affiliated element
)))
737 ;; Ignore checks in all affiliated keywords but captions.
738 ((< (point) post-affiliated
)
741 (let ((case-fold-search t
)) (looking-at "[ \t]*#\\+CAPTION:")))
742 (> (point) (match-end 0))
743 (org--flyspell-object-check-p element
)))
744 ;; Ignore checks in LOGBOOK (or equivalent) drawer.
745 ((let ((log (org-log-into-drawer)))
747 (let ((drawer (org-element-lineage element
'(drawer))))
751 (org-element-property :drawer-name drawer
) nil nil t
)
755 (cl-case (org-element-type element
)
756 ((comment quote-section
) t
)
758 ;; Allow checks between block markers, not on them.
759 (and (> (line-beginning-position) post-affiliated
)
762 (skip-chars-forward " \r\t\n")
763 (< (point) (org-element-property :end element
)))))
764 ;; Arbitrary list of keywords where checks are meaningful.
765 ;; Make sure point is on the value part of the element.
767 (and (member (org-element-property :key element
)
768 '("DESCRIPTION" "TITLE"))
770 (search-backward ":" (line-beginning-position) t
))))
771 ;; Check is globally allowed in paragraphs verse blocks and
772 ;; table rows (after affiliated keywords) but some objects
773 ;; must not be affected.
774 ((paragraph table-row verse-block
)
775 (let ((cbeg (org-element-property :contents-begin element
))
776 (cend (org-element-property :contents-end element
)))
777 (and cbeg
(>= (point) cbeg
) (< (point) cend
)
778 (org--flyspell-object-check-p element
))))))))))
779 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
781 (defun org-remove-flyspell-overlays-in (beg end
)
782 "Remove flyspell overlays in region."
783 (and (bound-and-true-p flyspell-mode
)
784 (fboundp 'flyspell-delete-region-overlays
)
785 (flyspell-delete-region-overlays beg end
)))
787 (defvar flyspell-delayed-commands
)
788 (eval-after-load "flyspell"
789 '(add-to-list 'flyspell-delayed-commands
'org-self-insert-command
))
793 (defun org-bookmark-jump-unhide ()
794 "Unhide the current position, to show the bookmark location."
795 (and (derived-mode-p 'org-mode
)
796 (or (org-invisible-p)
797 (save-excursion (goto-char (max (point-min) (1- (point))))
799 (org-show-context 'bookmark-jump
)))
801 ;; Make `bookmark-jump' shows the jump location if it was hidden.
802 (eval-after-load "bookmark"
803 '(if (boundp 'bookmark-after-jump-hook
)
804 ;; We can use the hook
805 (add-hook 'bookmark-after-jump-hook
'org-bookmark-jump-unhide
)
806 ;; Hook not available, use advice
807 (defadvice bookmark-jump
(after org-make-visible activate
)
808 "Make the position visible."
809 (org-bookmark-jump-unhide))))
813 (defcustom org-calendar-to-agenda-key
'default
814 "Key to be installed in `calendar-mode-map' for switching to the agenda.
816 The command `org-calendar-goto-agenda' will be bound to this key.
818 When set to `default', bind the function to `c', but only if it is
819 available in the Calendar keymap. This is the default choice because
820 `c' can then be used to switch back and forth between agenda and calendar.
822 When nil, `org-calendar-goto-agenda' is not bound to any key."
825 (const :tag
"Bind to `c' if available" default
)
826 (key-sequence :tag
"Other binding")
827 (const :tag
"No binding" nil
))
828 :safe
(lambda (v) (or (symbolp v
) (stringp v
)))
829 :package-version
'(Org .
"9.2"))
831 (defcustom org-calendar-insert-diary-entry-key
[?i
]
832 "The key to be installed in `calendar-mode-map' for adding diary entries.
833 This option is irrelevant until `org-agenda-diary-file' has been configured
834 to point to an Org file. When that is the case, the command
835 `org-agenda-diary-entry' will be bound to the key given here, by default
836 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
837 if you want to continue doing this, you need to change this to a different
842 (defun org--setup-calendar-bindings ()
843 "Bind Org functions in Calendar keymap."
844 (pcase org-calendar-to-agenda-key
846 ((and key
(pred stringp
))
847 (local-set-key (kbd key
) #'org-calendar-goto-agenda
))
848 ((guard (not (lookup-key calendar-mode-map
"c")))
849 (local-set-key "c" #'org-calendar-goto-agenda
))
851 (unless (eq org-agenda-diary-file
'diary-file
)
852 (local-set-key org-calendar-insert-diary-entry-key
853 #'org-agenda-diary-entry
)))
855 (eval-after-load "calendar"
856 '(add-hook 'calendar-mode-hook
#'org--setup-calendar-bindings
))
860 ;; Make sure saveplace shows the location if it was hidden
861 (eval-after-load "saveplace"
862 '(defadvice save-place-find-file-hook
(after org-make-visible activate
)
863 "Make the position visible."
864 (org-bookmark-jump-unhide)))
868 ;; Make sure ecb shows the location if it was hidden
869 (eval-after-load "ecb"
870 '(defadvice ecb-method-clicked
(after esf
/org-show-context activate
)
871 "Make hierarchy visible when jumping into location from ECB tree buffer."
872 (when (derived-mode-p 'org-mode
)
873 (org-show-context))))
877 (defun org-mark-jump-unhide ()
878 "Make the point visible with `org-show-context' after jumping to the mark."
879 (when (and (derived-mode-p 'org-mode
)
881 (org-show-context 'mark-goto
)))
883 (eval-after-load "simple"
884 '(defadvice pop-to-mark-command
(after org-make-visible activate
)
885 "Make the point visible with `org-show-context'."
886 (org-mark-jump-unhide)))
888 (eval-after-load "simple"
889 '(defadvice exchange-point-and-mark
(after org-make-visible activate
)
890 "Make the point visible with `org-show-context'."
891 (org-mark-jump-unhide)))
893 (eval-after-load "simple"
894 '(defadvice pop-global-mark
(after org-make-visible activate
)
895 "Make the point visible with `org-show-context'."
896 (org-mark-jump-unhide)))
900 ;; Make "session.el" ignore our circular variable.
901 (defvar session-globals-exclude
)
902 (eval-after-load "session"
903 '(add-to-list 'session-globals-exclude
'org-mark-ring
))
905 (provide 'org-compat
)
907 ;;; org-compat.el ends here