Document reserved keys
[emacs.git] / lisp / org / org-compat.el
blobf32fcd1783ea99ff6b880a99bf5cd286c3fb8939
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: http://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.
30 ;;; Code:
32 (require 'cl-lib)
33 (require 'org-macs)
35 (declare-function org-at-table.el-p "org" ())
36 (declare-function org-element-at-point "org-element" ())
37 (declare-function org-element-type "org-element" (element))
38 (declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
39 (declare-function org-link-set-parameters "org" (type &rest rest))
40 (declare-function org-table-end "org-table" (&optional table-type))
41 (declare-function outline-next-heading "outline" ())
42 (declare-function table--at-cell-p "table" (position &optional object at-column))
44 (defvar org-table-any-border-regexp)
45 (defvar org-table-dataline-regexp)
46 (defvar org-table-tab-recognizes-table.el)
47 (defvar org-table1-hline-regexp)
49 ;;; Emacs < 25.1 compatibility
51 (when (< emacs-major-version 25)
52 (defalias 'outline-hide-entry 'hide-entry)
53 (defalias 'outline-hide-sublevels 'hide-sublevels)
54 (defalias 'outline-hide-subtree 'hide-subtree)
55 (defalias 'outline-show-all 'show-all)
56 (defalias 'outline-show-branches 'show-branches)
57 (defalias 'outline-show-children 'show-children)
58 (defalias 'outline-show-entry 'show-entry)
59 (defalias 'outline-show-subtree 'show-subtree)
60 (defalias 'xref-find-definitions 'find-tag)
61 (defalias 'format-message 'format)
62 (defalias 'gui-get-selection 'x-get-selection))
64 (defun org-decode-time (&optional time zone)
65 "Backward-compatible function for `decode-time'."
66 (if (< emacs-major-version 25)
67 (decode-time time)
68 (decode-time time zone)))
70 (unless (fboundp 'directory-name-p)
71 (defun directory-name-p (name)
72 "Return non-nil if NAME ends with a directory separator character."
73 (let ((len (length name))
74 (lastc ?.))
75 (if (> len 0)
76 (setq lastc (aref name (1- len))))
77 (or (= lastc ?/)
78 (and (memq system-type '(windows-nt ms-dos))
79 (= lastc ?\\))))))
81 (unless (fboundp 'directory-files-recursively)
82 (defun directory-files-recursively (dir regexp &optional include-directories)
83 "Return list of all files under DIR that have file names matching REGEXP.
84 This function works recursively. Files are returned in \"depth first\"
85 order, and files from each directory are sorted in alphabetical order.
86 Each file name appears in the returned list in its absolute form.
87 Optional argument INCLUDE-DIRECTORIES non-nil means also include in the
88 output directories whose names match REGEXP."
89 (let ((result nil)
90 (files nil)
91 ;; When DIR is "/", remote file names like "/method:" could
92 ;; also be offered. We shall suppress them.
93 (tramp-mode (and tramp-mode (file-remote-p (expand-file-name dir)))))
94 (dolist (file (sort (file-name-all-completions "" dir)
95 'string<))
96 (unless (member file '("./" "../"))
97 (if (directory-name-p file)
98 (let* ((leaf (substring file 0 (1- (length file))))
99 (full-file (expand-file-name leaf dir)))
100 ;; Don't follow symlinks to other directories.
101 (unless (file-symlink-p full-file)
102 (setq result
103 (nconc result (directory-files-recursively
104 full-file regexp include-directories))))
105 (when (and include-directories
106 (string-match regexp leaf))
107 (setq result (nconc result (list full-file)))))
108 (when (string-match regexp file)
109 (push (expand-file-name file dir) files)))))
110 (nconc result (nreverse files)))))
113 ;;; Obsolete aliases (remove them after the next major release).
115 ;;;; XEmacs compatibility, now removed.
116 (define-obsolete-function-alias 'org-activate-mark 'activate-mark)
117 (define-obsolete-function-alias 'org-add-hook 'add-hook "Org 9.0")
118 (define-obsolete-function-alias 'org-bound-and-true-p 'bound-and-true-p "Org 9.0")
119 (define-obsolete-function-alias 'org-decompose-region 'decompose-region "Org 9.0")
120 (define-obsolete-function-alias 'org-defvaralias 'defvaralias "Org 9.0")
121 (define-obsolete-function-alias 'org-detach-overlay 'delete-overlay "Org 9.0")
122 (define-obsolete-function-alias 'org-file-equal-p 'file-equal-p "Org 9.0")
123 (define-obsolete-function-alias 'org-float-time 'float-time "Org 9.0")
124 (define-obsolete-function-alias 'org-indent-line-to 'indent-line-to "Org 9.0")
125 (define-obsolete-function-alias 'org-indent-to-column 'indent-to-column "Org 9.0")
126 (define-obsolete-function-alias 'org-looking-at-p 'looking-at-p "Org 9.0")
127 (define-obsolete-function-alias 'org-looking-back 'looking-back "Org 9.0")
128 (define-obsolete-function-alias 'org-match-string-no-properties 'match-string-no-properties "Org 9.0")
129 (define-obsolete-function-alias 'org-propertize 'propertize "Org 9.0")
130 (define-obsolete-function-alias 'org-select-frame-set-input-focus 'select-frame-set-input-focus "Org 9.0")
132 (defmacro org-re (s)
133 "Replace posix classes in regular expression S."
134 (declare (debug (form))
135 (obsolete "you can safely remove it." "Org 9.0"))
138 ;;;; Functions from cl-lib that Org used to have its own implementation of.
139 (define-obsolete-function-alias 'org-count 'cl-count "Org 9.0")
140 (define-obsolete-function-alias 'org-every 'cl-every "Org 9.0")
141 (define-obsolete-function-alias 'org-find-if 'cl-find-if "Org 9.0")
142 (define-obsolete-function-alias 'org-reduce 'cl-reduce "Org 9.0")
143 (define-obsolete-function-alias 'org-remove-if 'cl-remove-if "Org 9.0")
144 (define-obsolete-function-alias 'org-remove-if-not 'cl-remove-if-not "Org 9.0")
145 (define-obsolete-function-alias 'org-some 'cl-some "Org 9.0")
146 (define-obsolete-function-alias 'org-floor* 'cl-floor "Org 9.0")
148 (defun org-sublist (list start end)
149 "Return a section of LIST, from START to END.
150 Counting starts at 1."
151 (cl-subseq list (1- start) end))
152 (make-obsolete 'org-sublist
153 "use cl-subseq (note the 0-based counting)."
154 "Org 9.0")
157 ;;;; Functions available since Emacs 24.3
158 (define-obsolete-function-alias 'org-buffer-narrowed-p 'buffer-narrowed-p "Org 9.0")
159 (define-obsolete-function-alias 'org-called-interactively-p 'called-interactively-p "Org 9.0")
160 (define-obsolete-function-alias 'org-char-to-string 'char-to-string "Org 9.0")
161 (define-obsolete-function-alias 'org-delete-directory 'delete-directory "Org 9.0")
162 (define-obsolete-function-alias 'org-format-seconds 'format-seconds "Org 9.0")
163 (define-obsolete-function-alias 'org-link-escape-browser 'url-encode-url "Org 9.0")
164 (define-obsolete-function-alias 'org-no-warnings 'with-no-warnings "Org 9.0")
165 (define-obsolete-function-alias 'org-number-sequence 'number-sequence "Org 9.0")
166 (define-obsolete-function-alias 'org-pop-to-buffer-same-window 'pop-to-buffer-same-window "Org 9.0")
167 (define-obsolete-function-alias 'org-string-match-p 'string-match-p "Org 9.0")
169 ;;;; Functions and variables from previous releases now obsolete.
170 (define-obsolete-function-alias 'org-element-remove-indentation
171 'org-remove-indentation "Org 9.0")
172 (define-obsolete-variable-alias 'org-latex-create-formula-image-program
173 'org-preview-latex-default-process "Org 9.0")
174 (define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
175 'org-preview-latex-image-directory "Org 9.0")
176 (define-obsolete-function-alias 'org-table-p 'org-at-table-p "Org 9.0")
177 (define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "Org 9.0")
178 (define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "Org 8.3")
179 (define-obsolete-function-alias 'org-image-file-name-regexp
180 'image-file-name-regexp "Org 9.0")
181 (define-obsolete-function-alias 'org-completing-read-no-i
182 'completing-read "Org 9.0")
183 (define-obsolete-function-alias 'org-icompleting-read
184 'completing-read "Org 9.0")
185 (define-obsolete-function-alias 'org-iread-file-name 'read-file-name "Org 9.0")
186 (define-obsolete-function-alias 'org-days-to-time
187 'org-time-stamp-to-now "Org 8.2")
188 (define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
189 'org-agenda-ignore-properties "Org 9.0")
190 (define-obsolete-function-alias 'org-preview-latex-fragment
191 'org-toggle-latex-fragment "Org 8.3")
192 (define-obsolete-function-alias 'org-export-get-genealogy
193 'org-element-lineage "Org 9.0")
194 (define-obsolete-variable-alias 'org-latex-with-hyperref
195 'org-latex-hyperref-template "Org 9.0")
196 (define-obsolete-variable-alias 'hfy-optimisations 'hfy-optimizations "Org 9.0")
197 (define-obsolete-variable-alias 'org-export-htmlized-org-css-url
198 'org-org-htmlized-css-url "Org 8.2")
199 (define-obsolete-function-alias 'org-list-parse-list 'org-list-to-lisp "Org 9.0")
200 (define-obsolete-function-alias 'org-agenda-todayp
201 'org-agenda-today-p "Org 9.0")
202 (define-obsolete-function-alias 'org-babel-examplize-region
203 'org-babel-examplify-region "Org 9.0")
204 (define-obsolete-variable-alias 'org-babel-capitalize-example-region-markers
205 'org-babel-uppercase-example-markers "Org 9.1")
207 (define-obsolete-function-alias 'org-babel-trim 'org-trim "Org 9.0")
208 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
209 (define-obsolete-function-alias 'org-insert-columns-dblock
210 'org-columns-insert-dblock "Org 9.0")
211 (define-obsolete-variable-alias 'org-export-babel-evaluate
212 'org-export-use-babel "Org 9.1")
213 (define-obsolete-function-alias 'org-activate-bracket-links
214 'org-activate-links "Org 9.0")
215 (define-obsolete-function-alias 'org-activate-plain-links 'ignore "Org 9.0")
216 (define-obsolete-function-alias 'org-activate-angle-links 'ignore "Org 9.0")
218 (defun org-in-fixed-width-region-p ()
219 "Non-nil if point in a fixed-width region."
220 (save-match-data
221 (eq 'fixed-width (org-element-type (org-element-at-point)))))
222 (make-obsolete 'org-in-fixed-width-region-p
223 "use `org-element' library"
224 "Org 9.0")
226 (defun org-compatible-face (inherits specs)
227 "Make a compatible face specification.
228 If INHERITS is an existing face and if the Emacs version supports
229 it, just inherit the face. If INHERITS is not given and SPECS
230 is, use SPECS to define the face."
231 (declare (indent 1))
232 (if (facep inherits)
233 (list (list t :inherit inherits))
234 specs))
235 (make-obsolete 'org-compatible-face "you can remove it." "Org 9.0")
237 (defun org-add-link-type (type &optional follow export)
238 "Add a new TYPE link.
239 FOLLOW and EXPORT are two functions.
241 FOLLOW should take the link path as the single argument and do whatever
242 is necessary to follow the link, for example find a file or display
243 a mail message.
245 EXPORT should format the link path for export to one of the export formats.
246 It should be a function accepting three arguments:
248 path the path of the link, the text after the prefix (like \"http:\")
249 desc the description of the link, if any
250 format the export format, a symbol like `html' or `latex' or `ascii'.
252 The function may use the FORMAT information to return different values
253 depending on the format. The return value will be put literally into
254 the exported file. If the return value is nil, this means Org should
255 do what it normally does with links which do not have EXPORT defined.
257 Org mode has a built-in default for exporting links. If you are happy with
258 this default, there is no need to define an export function for the link
259 type. For a simple example of an export function, see `org-bbdb.el'.
261 If TYPE already exists, update it with the arguments.
262 See `org-link-parameters' for documentation on the other parameters."
263 (org-link-set-parameters type :follow follow :export export)
264 (message "Created %s link." type))
266 (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." "Org 9.0")
268 (defun org-table-recognize-table.el ()
269 "If there is a table.el table nearby, recognize it and move into it."
270 (when (and org-table-tab-recognizes-table.el (org-at-table.el-p))
271 (beginning-of-line)
272 (unless (or (looking-at org-table-dataline-regexp)
273 (not (looking-at org-table1-hline-regexp)))
274 (forward-line)
275 (when (looking-at org-table-any-border-regexp)
276 (forward-line -2)))
277 (if (re-search-forward "|" (org-table-end t) t)
278 (progn
279 (require 'table)
280 (if (table--at-cell-p (point)) t
281 (message "recognizing table.el table...")
282 (table-recognize-table)
283 (message "recognizing table.el table...done")))
284 (error "This should not happen"))))
286 ;; Not used by Org core since commit 6d1e3082, Feb 2010.
287 (make-obsolete 'org-table-recognize-table.el
288 "please notify the org mailing list if you use this function."
289 "Org 9.0")
291 (defun org-remove-angle-brackets (s)
292 (org-unbracket-string "<" ">" s))
293 (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "Org 9.0")
295 (defun org-remove-double-quotes (s)
296 (org-unbracket-string "\"" "\"" s))
297 (make-obsolete 'org-remove-double-quotes 'org-unbracket-string "Org 9.0")
299 (defcustom org-publish-sitemap-file-entry-format "%t"
300 "Format string for site-map file entry.
301 You could use brackets to delimit on what part the link will be.
303 %t is the title.
304 %a is the author.
305 %d is the date formatted using `org-publish-sitemap-date-format'."
306 :group 'org-export-publish
307 :type 'string)
308 (make-obsolete-variable
309 'org-publish-sitemap-file-entry-format
310 "set `:sitemap-format-entry' in `org-publish-project-alist' instead."
311 "Org 9.1")
313 (defvar org-agenda-skip-regexp)
314 (defun org-agenda-skip-entry-when-regexp-matches ()
315 "Check if the current entry contains match for `org-agenda-skip-regexp'.
316 If yes, it returns the end position of this entry, causing agenda commands
317 to skip the entry but continuing the search in the subtree. This is a
318 function that can be put into `org-agenda-skip-function' for the duration
319 of a command."
320 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
321 (let ((end (save-excursion (org-end-of-subtree t)))
322 skip)
323 (save-excursion
324 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
325 (and skip end)))
327 (defun org-agenda-skip-subtree-when-regexp-matches ()
328 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
329 If yes, it returns the end position of this tree, causing agenda commands
330 to skip this subtree. This is a function that can be put into
331 `org-agenda-skip-function' for the duration of a command."
332 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
333 (let ((end (save-excursion (org-end-of-subtree t)))
334 skip)
335 (save-excursion
336 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
337 (and skip end)))
339 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
340 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
341 If yes, it returns the end position of the current entry (NOT the tree),
342 causing agenda commands to skip the entry but continuing the search in
343 the subtree. This is a function that can be put into
344 `org-agenda-skip-function' for the duration of a command. An important
345 use of this function is for the stuck project list."
346 (declare (obsolete "use `org-agenda-skip-if' instead." "Org 9.1"))
347 (let ((end (save-excursion (org-end-of-subtree t)))
348 (entry-end (save-excursion (outline-next-heading) (1- (point))))
349 skip)
350 (save-excursion
351 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
352 (and skip entry-end)))
354 (define-obsolete-function-alias 'org-minutes-to-clocksum-string
355 'org-duration-from-minutes "Org 9.1")
357 (define-obsolete-function-alias 'org-hh:mm-string-to-minutes
358 'org-duration-to-minutes "Org 9.1")
360 (define-obsolete-function-alias 'org-duration-string-to-minutes
361 'org-duration-to-minutes "Org 9.1")
363 (make-obsolete-variable 'org-time-clocksum-format
364 "set `org-duration-format' instead." "Org 9.1")
366 (make-obsolete-variable 'org-time-clocksum-use-fractional
367 "set `org-duration-format' instead." "Org 9.1")
369 (make-obsolete-variable 'org-time-clocksum-fractional-format
370 "set `org-duration-format' instead." "Org 9.1")
372 (make-obsolete-variable 'org-time-clocksum-use-effort-durations
373 "set `org-duration-units' instead." "Org 9.1")
375 (define-obsolete-function-alias 'org-babel-number-p
376 'org-babel--string-to-number "Org 9.0")
378 (define-obsolete-variable-alias 'org-usenet-links-prefer-google
379 'org-gnus-prefer-web-links "Org 9.1")
381 (define-obsolete-variable-alias 'org-texinfo-def-table-markup
382 'org-texinfo-table-default-markup "Org 9.1")
384 ;;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
385 ;;; This make-obsolete call was added 2016-09-01.
386 (make-obsolete 'org-capture-import-remember-templates
387 "use the `org-capture-templates' variable instead."
388 "Org 9.0")
391 ;;;; Obsolete link types
393 (eval-after-load 'org
394 '(progn
395 (org-link-set-parameters "file+emacs") ;since Org 9.0
396 (org-link-set-parameters "file+sys"))) ;since Org 9.0
400 ;;; Miscellaneous functions
402 (defun org-version-check (version feature level)
403 (let* ((v1 (mapcar 'string-to-number (split-string version "[.]")))
404 (v2 (mapcar 'string-to-number (split-string emacs-version "[.]")))
405 (rmaj (or (nth 0 v1) 99))
406 (rmin (or (nth 1 v1) 99))
407 (rbld (or (nth 2 v1) 99))
408 (maj (or (nth 0 v2) 0))
409 (min (or (nth 1 v2) 0))
410 (bld (or (nth 2 v2) 0)))
411 (if (or (< maj rmaj)
412 (and (= maj rmaj)
413 (< min rmin))
414 (and (= maj rmaj)
415 (= min rmin)
416 (< bld rbld)))
417 (if (eq level :predicate)
418 ;; just return if we have the version
420 (let ((msg (format "Emacs %s or greater is recommended for %s"
421 version feature)))
422 (display-warning 'org msg level)
424 t)))
426 (defun org-get-x-clipboard (value)
427 "Get the value of the X or Windows clipboard."
428 (cond ((and (eq window-system 'x)
429 (fboundp 'gui-get-selection)) ;Silence byte-compiler.
430 (org-no-properties
431 (ignore-errors
432 (or (gui-get-selection value 'UTF8_STRING)
433 (gui-get-selection value 'COMPOUND_TEXT)
434 (gui-get-selection value 'STRING)
435 (gui-get-selection value 'TEXT)))))
436 ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
437 (w32-get-clipboard-data))))
439 (defun org-add-props (string plist &rest props)
440 "Add text properties to entire string, from beginning to end.
441 PLIST may be a list of properties, PROPS are individual properties and values
442 that will be added to PLIST. Returns the string that was modified."
443 (add-text-properties
444 0 (length string) (if props (append plist props) plist) string)
445 string)
446 (put 'org-add-props 'lisp-indent-function 2)
448 (defun org-fit-window-to-buffer (&optional window max-height min-height
449 shrink-only)
450 "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
451 WINDOW defaults to the selected window. MAX-HEIGHT and MIN-HEIGHT are
452 passed through to `fit-window-to-buffer'. If SHRINK-ONLY is set, call
453 `shrink-window-if-larger-than-buffer' instead, the height limit is
454 ignored in this case."
455 (cond ((if (fboundp 'window-full-width-p)
456 (not (window-full-width-p window))
457 ;; do nothing if another window would suffer
458 (> (frame-width) (window-width window))))
459 ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
460 (fit-window-to-buffer window max-height min-height))
461 ((fboundp 'shrink-window-if-larger-than-buffer)
462 (shrink-window-if-larger-than-buffer window)))
463 (or window (selected-window)))
465 ;; `set-transient-map' is only in Emacs >= 24.4
466 (defalias 'org-set-transient-map
467 (if (fboundp 'set-transient-map)
468 'set-transient-map
469 'set-temporary-overlay-map))
471 ;;; Region compatibility
473 (defvar org-ignore-region nil
474 "Non-nil means temporarily disable the active region.")
476 (defun org-region-active-p ()
477 "Non-nil when the region active.
478 Unlike to `use-region-p', this function also checks
479 `org-ignore-region'."
480 (and (not org-ignore-region) (use-region-p)))
482 (defun org-cursor-to-region-beginning ()
483 (when (and (org-region-active-p)
484 (> (point) (region-beginning)))
485 (exchange-point-and-mark)))
487 ;;; Invisibility compatibility
489 (defun org-remove-from-invisibility-spec (arg)
490 "Remove elements from `buffer-invisibility-spec'."
491 (if (fboundp 'remove-from-invisibility-spec)
492 (remove-from-invisibility-spec arg)
493 (if (consp buffer-invisibility-spec)
494 (setq buffer-invisibility-spec
495 (delete arg buffer-invisibility-spec)))))
497 (defun org-in-invisibility-spec-p (arg)
498 "Is ARG a member of `buffer-invisibility-spec'?"
499 (if (consp buffer-invisibility-spec)
500 (member arg buffer-invisibility-spec)))
502 (defun org-move-to-column (column &optional force _buffer)
503 "Move to column COLUMN.
504 Pass COLUMN and FORCE to `move-to-column'."
505 (let ((buffer-invisibility-spec
506 (if (listp buffer-invisibility-spec)
507 (remove '(org-filtered) buffer-invisibility-spec)
508 buffer-invisibility-spec)))
509 (move-to-column column force)))
511 (defmacro org-find-library-dir (library)
512 `(file-name-directory (or (locate-library ,library) "")))
514 (defun org-count-lines (s)
515 "How many lines in string S?"
516 (let ((start 0) (n 1))
517 (while (string-match "\n" s start)
518 (setq start (match-end 0) n (1+ n)))
519 (if (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
520 (setq n (1- n)))
523 (defun org-kill-new (string &rest args)
524 (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
525 string)
526 (apply 'kill-new string args))
528 ;; `font-lock-ensure' is only available from 24.4.50 on
529 (defalias 'org-font-lock-ensure
530 (if (fboundp 'font-lock-ensure)
531 #'font-lock-ensure
532 (lambda (&optional _beg _end)
533 (with-no-warnings (font-lock-fontify-buffer)))))
535 ;; `file-local-name' was added in Emacs 26.1.
536 (defalias 'org-babel-local-file-name
537 (if (fboundp 'file-local-name)
538 'file-local-name
539 (lambda (file)
540 "Return the local name component of FILE."
541 (or (file-remote-p file 'localname) file))))
543 (defmacro org-no-popups (&rest body)
544 "Suppress popup windows.
545 Let-bind some variables to nil around BODY to achieve the desired
546 effect, which variables to use depends on the Emacs version."
547 (if (org-version-check "24.2.50" "" :predicate)
548 `(let (pop-up-frames display-buffer-alist)
549 ,@body)
550 `(let (pop-up-frames special-display-buffer-names special-display-regexps special-display-function)
551 ,@body)))
553 ;;;###autoload
554 (defmacro org-check-version ()
555 "Try very hard to provide sensible version strings."
556 (let* ((org-dir (org-find-library-dir "org"))
557 (org-version.el (concat org-dir "org-version.el"))
558 (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
559 (if (require 'org-version org-version.el 'noerror)
560 '(progn
561 (autoload 'org-release "org-version.el")
562 (autoload 'org-git-version "org-version.el"))
563 (if (require 'org-fixup org-fixup.el 'noerror)
564 '(org-fixup)
565 ;; provide fallback definitions and complain
566 (warn "Could not define org version correctly. Check installation!")
567 '(progn
568 (defun org-release () "N/A")
569 (defun org-git-version () "N/A !!check installation!!"))))))
571 (defmacro org-with-silent-modifications (&rest body)
572 (if (fboundp 'with-silent-modifications)
573 `(with-silent-modifications ,@body)
574 `(org-unmodified ,@body)))
575 (def-edebug-spec org-with-silent-modifications (body))
577 ;; Functions for Emacs < 24.4 compatibility
578 (defun org-define-error (name message)
579 "Define NAME as a new error signal.
580 MESSAGE is a string that will be output to the echo area if such
581 an error is signaled without being caught by a `condition-case'.
582 Implements `define-error' for older emacsen."
583 (if (fboundp 'define-error) (define-error name message)
584 (put name 'error-conditions
585 (copy-sequence (cons name (get 'error 'error-conditions))))))
587 (unless (fboundp 'string-suffix-p)
588 ;; From Emacs subr.el.
589 (defun string-suffix-p (suffix string &optional ignore-case)
590 "Return non-nil if SUFFIX is a suffix of STRING.
591 If IGNORE-CASE is non-nil, the comparison is done without paying
592 attention to case differences."
593 (let ((start-pos (- (length string) (length suffix))))
594 (and (>= start-pos 0)
595 (eq t (compare-strings suffix nil nil
596 string start-pos nil ignore-case))))))
598 (provide 'org-compat)
600 ;;; org-compat.el ends here