org-compat.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. ;;; org-compat.el --- Compatibility code for Org-mode
  2. ;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains code needed for compatibility with XEmacs and older
  23. ;; versions of GNU Emacs.
  24. ;;; Code:
  25. (eval-when-compile
  26. (require 'cl))
  27. (require 'org-macs)
  28. (declare-function w32-focus-frame "term/w32-win" (frame))
  29. ;; The following constant is for backward compatibility. We do not use
  30. ;; it in org-mode, because the Byte compiler evaluates (featurep 'xemacs)
  31. ;; at compilation time and can therefore optimize code better.
  32. (defconst org-xemacs-p (featurep 'xemacs))
  33. (defun org-compatible-face (inherits specs)
  34. "Make a compatible face specification.
  35. If INHERITS is an existing face and if the Emacs version supports it,
  36. just inherit the face. If INHERITS is set and the Emacs version does
  37. not support it, copy the face specification from the inheritance face.
  38. If INHERITS is not given and SPECS is, use SPECS to define the face.
  39. XEmacs and Emacs 21 do not know about the `min-colors' attribute.
  40. For them we convert a (min-colors 8) entry to a `tty' entry and move it
  41. to the top of the list. The `min-colors' attribute will be removed from
  42. any other entries, and any resulting duplicates will be removed entirely."
  43. (when (and inherits (facep inherits) (not specs))
  44. (setq specs (or specs
  45. (get inherits 'saved-face)
  46. (get inherits 'face-defface-spec))))
  47. (cond
  48. ((and inherits (facep inherits)
  49. (not (featurep 'xemacs))
  50. (>= emacs-major-version 22)
  51. ;; do not inherit outline faces before Emacs 23
  52. (or (>= emacs-major-version 23)
  53. (not (string-match "\\`outline-[0-9]+"
  54. (symbol-name inherits)))))
  55. (list (list t :inherit inherits)))
  56. ((or (featurep 'xemacs) (< emacs-major-version 22))
  57. ;; These do not understand the `min-colors' attribute.
  58. (let (r e a)
  59. (while (setq e (pop specs))
  60. (cond
  61. ((memq (car e) '(t default)) (push e r))
  62. ((setq a (member '(min-colors 8) (car e)))
  63. (nconc r (list (cons (cons '(type tty) (delq (car a) (car e)))
  64. (cdr e)))))
  65. ((setq a (assq 'min-colors (car e)))
  66. (setq e (cons (delq a (car e)) (cdr e)))
  67. (or (assoc (car e) r) (push e r)))
  68. (t (or (assoc (car e) r) (push e r)))))
  69. (nreverse r)))
  70. (t specs)))
  71. (put 'org-compatible-face 'lisp-indent-function 1)
  72. (defun org-version-check (version feature level)
  73. (let* ((v1 (mapcar 'string-to-number (split-string version "[.]")))
  74. (v2 (mapcar 'string-to-number (split-string emacs-version "[.]")))
  75. (rmaj (or (nth 0 v1) 99))
  76. (rmin (or (nth 1 v1) 99))
  77. (rbld (or (nth 2 v1) 99))
  78. (maj (or (nth 0 v2) 0))
  79. (min (or (nth 1 v2) 0))
  80. (bld (or (nth 2 v2) 0)))
  81. (if (or (< maj rmaj)
  82. (and (= maj rmaj)
  83. (< min rmin))
  84. (and (= maj rmaj)
  85. (= min rmin)
  86. (< bld rbld)))
  87. (if (eq level :predicate)
  88. ;; just return if we have the version
  89. nil
  90. (let ((msg (format "Emacs %s or greater is recommended for %s"
  91. version feature)))
  92. (display-warning 'org msg level)
  93. t))
  94. t)))
  95. ;;;; Emacs/XEmacs compatibility
  96. (eval-and-compile
  97. (defun org-defvaralias (new-alias base-variable &optional docstring)
  98. "Compatibility function for defvaralias.
  99. Don't do the aliasing when `defvaralias' is not bound."
  100. (declare (indent 1))
  101. (when (fboundp 'defvaralias)
  102. (defvaralias new-alias base-variable docstring)))
  103. (when (and (not (boundp 'user-emacs-directory))
  104. (boundp 'user-init-directory))
  105. (org-defvaralias 'user-emacs-directory 'user-init-directory)))
  106. (when (featurep 'xemacs)
  107. (defadvice custom-handle-keyword
  108. (around org-custom-handle-keyword
  109. activate preactivate)
  110. "Remove custom keywords not recognized to avoid producing an error."
  111. (cond
  112. ((eq (ad-get-arg 1) :package-version))
  113. (t ad-do-it)))
  114. (defadvice define-obsolete-variable-alias
  115. (around org-define-obsolete-variable-alias
  116. (obsolete-name current-name &optional when docstring)
  117. activate preactivate)
  118. "Declare arguments defined in later versions of Emacs."
  119. ad-do-it)
  120. (defadvice define-obsolete-function-alias
  121. (around org-define-obsolete-function-alias
  122. (obsolete-name current-name &optional when docstring)
  123. activate preactivate)
  124. "Declare arguments defined in later versions of Emacs."
  125. ad-do-it)
  126. (defvar customize-package-emacs-version-alist nil)
  127. (defvar temporary-file-directory (temp-directory)))
  128. ;; Keys
  129. (defconst org-xemacs-key-equivalents
  130. '(([mouse-1] . [button1])
  131. ([mouse-2] . [button2])
  132. ([mouse-3] . [button3])
  133. ([C-mouse-4] . [(control mouse-4)])
  134. ([C-mouse-5] . [(control mouse-5)]))
  135. "Translation alist for a couple of keys.")
  136. ;; Overlay compatibility functions
  137. (defun org-detach-overlay (ovl)
  138. (if (featurep 'xemacs) (detach-extent ovl) (delete-overlay ovl)))
  139. (defun org-overlay-display (ovl text &optional face evap)
  140. "Make overlay OVL display TEXT with face FACE."
  141. (if (featurep 'xemacs)
  142. (let ((gl (make-glyph text)))
  143. (and face (set-glyph-face gl face))
  144. (set-extent-property ovl 'invisible t)
  145. (set-extent-property ovl 'end-glyph gl))
  146. (overlay-put ovl 'display text)
  147. (if face (overlay-put ovl 'face face))
  148. (if evap (overlay-put ovl 'evaporate t))))
  149. (defun org-overlay-before-string (ovl text &optional face evap)
  150. "Make overlay OVL display TEXT with face FACE."
  151. (if (featurep 'xemacs)
  152. (let ((gl (make-glyph text)))
  153. (and face (set-glyph-face gl face))
  154. (set-extent-property ovl 'begin-glyph gl))
  155. (if face (org-add-props text nil 'face face))
  156. (overlay-put ovl 'before-string text)
  157. (if evap (overlay-put ovl 'evaporate t))))
  158. (defun org-find-overlays (prop &optional pos delete)
  159. "Find all overlays specifying PROP at POS or point.
  160. If DELETE is non-nil, delete all those overlays."
  161. (let ((overlays (overlays-at (or pos (point))))
  162. ov found)
  163. (while (setq ov (pop overlays))
  164. (if (overlay-get ov prop)
  165. (if delete (delete-overlay ov) (push ov found))))
  166. found))
  167. (defun org-get-x-clipboard (value)
  168. "Get the value of the x or Windows clipboard, compatible with XEmacs, and GNU Emacs 21."
  169. (cond ((eq window-system 'x)
  170. (let ((x (org-get-x-clipboard-compat value)))
  171. (if x (org-no-properties x))))
  172. ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
  173. (w32-get-clipboard-data))))
  174. (defsubst org-decompose-region (beg end)
  175. "Decompose from BEG to END."
  176. (if (featurep 'xemacs)
  177. (let ((modified-p (buffer-modified-p))
  178. (buffer-read-only nil))
  179. (remove-text-properties beg end '(composition nil))
  180. (set-buffer-modified-p modified-p))
  181. (decompose-region beg end)))
  182. ;; Miscellaneous functions
  183. (defun org-add-hook (hook function &optional append local)
  184. "Add-hook, compatible with both Emacsen."
  185. (if (and local (featurep 'xemacs))
  186. (add-local-hook hook function append)
  187. (add-hook hook function append local)))
  188. (defun org-add-props (string plist &rest props)
  189. "Add text properties to entire string, from beginning to end.
  190. PLIST may be a list of properties, PROPS are individual properties and values
  191. that will be added to PLIST. Returns the string that was modified."
  192. (add-text-properties
  193. 0 (length string) (if props (append plist props) plist) string)
  194. string)
  195. (put 'org-add-props 'lisp-indent-function 2)
  196. (defun org-fit-window-to-buffer (&optional window max-height min-height
  197. shrink-only)
  198. "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
  199. WINDOW defaults to the selected window. MAX-HEIGHT and MIN-HEIGHT are
  200. passed through to `fit-window-to-buffer'. If SHRINK-ONLY is set, call
  201. `shrink-window-if-larger-than-buffer' instead, the height limit is
  202. ignored in this case."
  203. (cond ((if (fboundp 'window-full-width-p)
  204. (not (window-full-width-p window))
  205. ;; do nothing if another window would suffer
  206. (> (frame-width) (window-width window))))
  207. ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
  208. (fit-window-to-buffer window max-height min-height))
  209. ((fboundp 'shrink-window-if-larger-than-buffer)
  210. (shrink-window-if-larger-than-buffer window)))
  211. (or window (selected-window)))
  212. (defun org-number-sequence (from &optional to inc)
  213. "Call `number-sequence' or emulate it."
  214. (if (fboundp 'number-sequence)
  215. (number-sequence from to inc)
  216. (if (or (not to) (= from to))
  217. (list from)
  218. (or inc (setq inc 1))
  219. (when (zerop inc) (error "The increment can not be zero"))
  220. (let (seq (n 0) (next from))
  221. (if (> inc 0)
  222. (while (<= next to)
  223. (setq seq (cons next seq)
  224. n (1+ n)
  225. next (+ from (* n inc))))
  226. (while (>= next to)
  227. (setq seq (cons next seq)
  228. n (1+ n)
  229. next (+ from (* n inc)))))
  230. (nreverse seq)))))
  231. ;; `set-transient-map' is only in Emacs >= 24.4
  232. (defalias 'org-set-transient-map
  233. (if (fboundp 'set-transient-map)
  234. 'set-transient-map
  235. 'set-temporary-overlay-map))
  236. ;; Region compatibility
  237. (defvar org-ignore-region nil
  238. "Non-nil means temporarily disable the active region.")
  239. (defun org-region-active-p ()
  240. "Is `transient-mark-mode' on and the region active?
  241. Works on both Emacs and XEmacs."
  242. (if org-ignore-region
  243. nil
  244. (if (featurep 'xemacs)
  245. (and zmacs-regions (region-active-p))
  246. (if (fboundp 'use-region-p)
  247. (use-region-p)
  248. (and transient-mark-mode mark-active))))) ; Emacs 22 and before
  249. (defun org-cursor-to-region-beginning ()
  250. (when (and (org-region-active-p)
  251. (> (point) (region-beginning)))
  252. (exchange-point-and-mark)))
  253. ;; Old alias for emacs 22 compatibility, now dropped
  254. (define-obsolete-function-alias 'org-activate-mark 'activate-mark)
  255. ;; Invisibility compatibility
  256. (defun org-remove-from-invisibility-spec (arg)
  257. "Remove elements from `buffer-invisibility-spec'."
  258. (if (fboundp 'remove-from-invisibility-spec)
  259. (remove-from-invisibility-spec arg)
  260. (if (consp buffer-invisibility-spec)
  261. (setq buffer-invisibility-spec
  262. (delete arg buffer-invisibility-spec)))))
  263. (defun org-in-invisibility-spec-p (arg)
  264. "Is ARG a member of `buffer-invisibility-spec'?"
  265. (if (consp buffer-invisibility-spec)
  266. (member arg buffer-invisibility-spec)))
  267. (defmacro org-xemacs-without-invisibility (&rest body)
  268. "Turn off extents with invisibility while executing BODY."
  269. `(let ((ext-inv (extent-list nil (point-at-bol) (point-at-eol)
  270. 'all-extents-closed-open 'invisible))
  271. ext-inv-specs)
  272. (dolist (ext ext-inv)
  273. (when (extent-property ext 'invisible)
  274. (add-to-list 'ext-inv-specs (list ext (extent-property
  275. ext 'invisible)))
  276. (set-extent-property ext 'invisible nil)))
  277. ,@body
  278. (dolist (ext-inv-spec ext-inv-specs)
  279. (set-extent-property (car ext-inv-spec) 'invisible
  280. (cadr ext-inv-spec)))))
  281. (def-edebug-spec org-xemacs-without-invisibility (body))
  282. (defun org-indent-to-column (column &optional minimum buffer)
  283. "Work around a bug with extents with invisibility in XEmacs."
  284. (if (featurep 'xemacs)
  285. (org-xemacs-without-invisibility (indent-to-column column minimum buffer))
  286. (indent-to-column column minimum)))
  287. (defun org-indent-line-to (column)
  288. "Work around a bug with extents with invisibility in XEmacs."
  289. (if (featurep 'xemacs)
  290. (org-xemacs-without-invisibility (indent-line-to column))
  291. (indent-line-to column)))
  292. (defun org-move-to-column (column &optional force buffer)
  293. "Move to column COLUMN.
  294. Pass COLUMN and FORCE to `move-to-column'.
  295. Pass BUFFER to the XEmacs version of `move-to-column'."
  296. (let ((buffer-invisibility-spec
  297. (remove '(org-filtered) buffer-invisibility-spec)))
  298. (if (featurep 'xemacs)
  299. (org-xemacs-without-invisibility
  300. (move-to-column column force buffer))
  301. (move-to-column column force))))
  302. (defun org-get-x-clipboard-compat (value)
  303. "Get the clipboard value on XEmacs or Emacs 21."
  304. (cond ((featurep 'xemacs)
  305. (org-no-warnings (get-selection-no-error value)))
  306. ((fboundp 'x-get-selection)
  307. (condition-case nil
  308. (or (x-get-selection value 'UTF8_STRING)
  309. (x-get-selection value 'COMPOUND_TEXT)
  310. (x-get-selection value 'STRING)
  311. (x-get-selection value 'TEXT))
  312. (error nil)))))
  313. (defun org-propertize (string &rest properties)
  314. (if (featurep 'xemacs)
  315. (progn
  316. (add-text-properties 0 (length string) properties string)
  317. string)
  318. (apply 'propertize string properties)))
  319. (defmacro org-find-library-dir (library)
  320. `(file-name-directory (or (locate-library ,library) "")))
  321. (defun org-count-lines (s)
  322. "How many lines in string S?"
  323. (let ((start 0) (n 1))
  324. (while (string-match "\n" s start)
  325. (setq start (match-end 0) n (1+ n)))
  326. (if (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
  327. (setq n (1- n)))
  328. n))
  329. (defun org-kill-new (string &rest args)
  330. (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
  331. string)
  332. (apply 'kill-new string args))
  333. (defun org-select-frame-set-input-focus (frame)
  334. "Select FRAME, raise it, and set input focus, if possible."
  335. (cond ((featurep 'xemacs)
  336. (if (fboundp 'select-frame-set-input-focus)
  337. (select-frame-set-input-focus frame)
  338. (raise-frame frame)
  339. (select-frame frame)
  340. (focus-frame frame)))
  341. ;; `select-frame-set-input-focus' defined in Emacs 21 will not
  342. ;; set the input focus.
  343. ((>= emacs-major-version 22)
  344. (select-frame-set-input-focus frame))
  345. (t
  346. (raise-frame frame)
  347. (select-frame frame)
  348. (cond ((memq window-system '(x ns mac))
  349. (x-focus-frame frame))
  350. ((eq window-system 'w32)
  351. (w32-focus-frame frame)))
  352. (when focus-follows-mouse
  353. (set-mouse-position frame (1- (frame-width frame)) 0)))))
  354. (defalias 'org-float-time
  355. (if (featurep 'xemacs) 'time-to-seconds 'float-time))
  356. ;; `user-error' is only available from 24.2.50 on
  357. (unless (fboundp 'user-error)
  358. (defalias 'user-error 'error))
  359. ;; ‘format-message’ is available only from 25 on
  360. (unless (fboundp 'format-message)
  361. (defalias 'format-message 'format))
  362. ;; `font-lock-ensure' is only available from 24.4.50 on
  363. (unless (fboundp 'font-lock-ensure)
  364. (defalias 'font-lock-ensure 'font-lock-fontify-buffer))
  365. (defmacro org-no-popups (&rest body)
  366. "Suppress popup windows.
  367. Let-bind some variables to nil around BODY to achieve the desired
  368. effect, which variables to use depends on the Emacs version."
  369. (if (org-version-check "24.2.50" "" :predicate)
  370. `(let (pop-up-frames display-buffer-alist)
  371. ,@body)
  372. `(let (pop-up-frames special-display-buffer-names special-display-regexps special-display-function)
  373. ,@body)))
  374. (if (fboundp 'string-match-p)
  375. (defalias 'org-string-match-p 'string-match-p)
  376. (defun org-string-match-p (regexp string &optional start)
  377. (save-match-data
  378. (funcall 'string-match regexp string start))))
  379. (if (fboundp 'looking-at-p)
  380. (defalias 'org-looking-at-p 'looking-at-p)
  381. (defun org-looking-at-p (&rest args)
  382. (save-match-data
  383. (apply 'looking-at args))))
  384. ;; XEmacs does not have `looking-back'.
  385. (if (fboundp 'looking-back)
  386. (defalias 'org-looking-back 'looking-back)
  387. (defun org-looking-back (regexp &optional limit greedy)
  388. "Return non-nil if text before point matches regular expression REGEXP.
  389. Like `looking-at' except matches before point, and is slower.
  390. LIMIT if non-nil speeds up the search by specifying a minimum
  391. starting position, to avoid checking matches that would start
  392. before LIMIT.
  393. If GREEDY is non-nil, extend the match backwards as far as
  394. possible, stopping when a single additional previous character
  395. cannot be part of a match for REGEXP. When the match is
  396. extended, its starting position is allowed to occur before
  397. LIMIT."
  398. (let ((start (point))
  399. (pos
  400. (save-excursion
  401. (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)
  402. (point)))))
  403. (if (and greedy pos)
  404. (save-restriction
  405. (narrow-to-region (point-min) start)
  406. (while (and (> pos (point-min))
  407. (save-excursion
  408. (goto-char pos)
  409. (backward-char 1)
  410. (looking-at (concat "\\(?:" regexp "\\)\\'"))))
  411. (setq pos (1- pos)))
  412. (save-excursion
  413. (goto-char pos)
  414. (looking-at (concat "\\(?:" regexp "\\)\\'")))))
  415. (not (null pos)))))
  416. (defun org-floor* (x &optional y)
  417. "Return a list of the floor of X and the fractional part of X.
  418. With two arguments, return floor and remainder of their quotient."
  419. (let ((q (floor x y)))
  420. (list q (- x (if y (* y q) q)))))
  421. ;; `pop-to-buffer-same-window' has been introduced in Emacs 24.1.
  422. (defun org-pop-to-buffer-same-window
  423. (&optional buffer-or-name norecord label)
  424. "Pop to buffer specified by BUFFER-OR-NAME in the selected window."
  425. (if (fboundp 'pop-to-buffer-same-window)
  426. (funcall
  427. 'pop-to-buffer-same-window buffer-or-name norecord)
  428. (funcall 'switch-to-buffer buffer-or-name norecord)))
  429. ;; RECURSIVE has been introduced with Emacs 23.2.
  430. ;; This is copying and adapted from `tramp-compat-delete-directory'
  431. (defun org-delete-directory (directory &optional recursive)
  432. "Compatibility function for `delete-directory'."
  433. (if (null recursive)
  434. (delete-directory directory)
  435. (condition-case nil
  436. (funcall 'delete-directory directory recursive)
  437. ;; This Emacs version does not support the RECURSIVE flag. We
  438. ;; use the implementation from Emacs 23.2.
  439. (wrong-number-of-arguments
  440. (setq directory (directory-file-name (expand-file-name directory)))
  441. (if (not (file-symlink-p directory))
  442. (mapc (lambda (file)
  443. (if (eq t (car (file-attributes file)))
  444. (org-delete-directory file recursive)
  445. (delete-file file)))
  446. (directory-files
  447. directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
  448. (delete-directory directory)))))
  449. ;;;###autoload
  450. (defmacro org-check-version ()
  451. "Try very hard to provide sensible version strings."
  452. (let* ((org-dir (org-find-library-dir "org"))
  453. (org-version.el (concat org-dir "org-version.el"))
  454. (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
  455. (if (require 'org-version org-version.el 'noerror)
  456. '(progn
  457. (autoload 'org-release "org-version.el")
  458. (autoload 'org-git-version "org-version.el"))
  459. (if (require 'org-fixup org-fixup.el 'noerror)
  460. '(org-fixup)
  461. ;; provide fallback definitions and complain
  462. (warn "Could not define org version correctly. Check installation!")
  463. '(progn
  464. (defun org-release () "N/A")
  465. (defun org-git-version () "N/A !!check installation!!"))))))
  466. (defun org-file-equal-p (f1 f2)
  467. "Return t if files F1 and F2 are the same.
  468. Implements `file-equal-p' for older emacsen and XEmacs."
  469. (if (fboundp 'file-equal-p)
  470. (file-equal-p f1 f2)
  471. (let (f1-attr f2-attr)
  472. (and (setq f1-attr (file-attributes (file-truename f1)))
  473. (setq f2-attr (file-attributes (file-truename f2)))
  474. (equal f1-attr f2-attr)))))
  475. ;; `buffer-narrowed-p' is available for Emacs >=24.3
  476. (defun org-buffer-narrowed-p ()
  477. "Compatibility function for `buffer-narrowed-p'."
  478. (if (fboundp 'buffer-narrowed-p)
  479. (buffer-narrowed-p)
  480. (/= (- (point-max) (point-min)) (buffer-size))))
  481. ;; As of Emacs 25.1, `outline-mode` functions are under the 'outline-'
  482. ;; prefix and `find-tag` is replaced with `xref-find-definition`.
  483. (when (< emacs-major-version 25)
  484. (defalias 'outline-hide-entry 'hide-entry)
  485. (defalias 'outline-hide-sublevels 'hide-sublevels)
  486. (defalias 'outline-hide-subtree 'hide-subtree)
  487. (defalias 'outline-show-all 'show-all)
  488. (defalias 'outline-show-branches 'show-branches)
  489. (defalias 'outline-show-children 'show-children)
  490. (defalias 'outline-show-entry 'show-entry)
  491. (defalias 'outline-show-subtree 'show-subtree)
  492. (defalias 'xref-find-definitions 'find-tag))
  493. (defmacro org-with-silent-modifications (&rest body)
  494. (if (fboundp 'with-silent-modifications)
  495. `(with-silent-modifications ,@body)
  496. `(org-unmodified ,@body)))
  497. (def-edebug-spec org-with-silent-modifications (body))
  498. ;; Remove this when support for Emacs < 24.4 is dropped.
  499. (defun org-define-error (name message)
  500. "Define NAME as a new error signal.
  501. MESSAGE is a string that will be output to the echo area if such
  502. an error is signaled without being caught by a `condition-case'.
  503. Implements `define-error' for older emacsen."
  504. (if (fboundp 'define-error) (define-error name message)
  505. (put name 'error-conditions
  506. (copy-sequence (cons name (get 'error 'error-conditions))))))
  507. ;;; Functions from cl-lib that Org used to have its own implementation of
  508. (define-obsolete-function-alias 'org-count 'cl-count "Org 9.0")
  509. (define-obsolete-function-alias 'org-remove-if 'cl-remove-if "Org 9.0")
  510. (define-obsolete-function-alias 'org-remove-if-not 'cl-remove-if-not "Org 9.0")
  511. (define-obsolete-function-alias 'org-reduce 'cl-reduce "Org 9.0")
  512. (define-obsolete-function-alias 'org-every 'cl-every "Org 9.0")
  513. (define-obsolete-function-alias 'org-some 'cl-some "Org 9.0")
  514. (provide 'org-compat)
  515. ;;; org-compat.el ends here