org-compat.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. ;;; org-compat.el --- Compatibility Code for Older Emacsen -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2016 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 older
  23. ;; versions of GNU Emacs.
  24. ;;; Code:
  25. (require 'cl-lib)
  26. (require 'org-macs)
  27. (declare-function org-at-table.el-p "org" (&optional table-type))
  28. (declare-function org-link-set-parameters "org" (type &rest rest))
  29. (declare-function org-table-end (&optional table-type))
  30. (declare-function table--at-cell-p "table" (position &optional object at-column))
  31. (defvar org-table-any-border-regexp)
  32. (defvar org-table-dataline-regexp)
  33. (defvar org-table-tab-recognizes-table.el)
  34. (defvar org-table1-hline-regexp)
  35. ;; As of Emacs 25.1, `outline-mode' functions are under the 'outline-'
  36. ;; prefix, `find-tag' is replaced with `xref-find-definition' and
  37. ;; `x-get-selection' with `gui-get-selection'.
  38. (when (< emacs-major-version 25)
  39. (defalias 'outline-hide-entry 'hide-entry)
  40. (defalias 'outline-hide-sublevels 'hide-sublevels)
  41. (defalias 'outline-hide-subtree 'hide-subtree)
  42. (defalias 'outline-show-all 'show-all)
  43. (defalias 'outline-show-branches 'show-branches)
  44. (defalias 'outline-show-children 'show-children)
  45. (defalias 'outline-show-entry 'show-entry)
  46. (defalias 'outline-show-subtree 'show-subtree)
  47. (defalias 'xref-find-definitions 'find-tag)
  48. (defalias 'format-message 'format)
  49. (defalias 'gui-get-selection 'x-get-selection))
  50. ;;; Obsolete aliases (remove them once the next major release is released).
  51. ;;;; XEmacs compatibility, now removed.
  52. (define-obsolete-function-alias 'org-activate-mark 'activate-mark)
  53. (define-obsolete-function-alias 'org-add-hook 'add-hook "Org 9.0")
  54. (define-obsolete-function-alias 'org-bound-and-true-p 'bound-and-true-p "Org 9.0")
  55. (define-obsolete-function-alias 'org-decompose-region 'decompose-region "Org 9.0")
  56. (define-obsolete-function-alias 'org-defvaralias 'defvaralias "Org 9.0")
  57. (define-obsolete-function-alias 'org-detach-overlay 'delete-overlay "Org 9.0")
  58. (define-obsolete-function-alias 'org-file-equal-p 'file-equal-p "Org 9.0")
  59. (define-obsolete-function-alias 'org-float-time 'float-time "Org 9.0")
  60. (define-obsolete-function-alias 'org-indent-line-to 'indent-line-to "Org 9.0")
  61. (define-obsolete-function-alias 'org-indent-to-column 'indent-to-column "Org 9.0")
  62. (define-obsolete-function-alias 'org-looking-at-p 'looking-at-p "Org 9.0")
  63. (define-obsolete-function-alias 'org-looking-back 'looking-back "Org 9.0")
  64. (define-obsolete-function-alias 'org-match-string-no-properties 'match-string-no-properties "Org 9.0")
  65. (define-obsolete-function-alias 'org-propertize 'propertize "Org 9.0")
  66. (define-obsolete-function-alias 'org-select-frame-set-input-focus 'select-frame-set-input-focus "Org 9.0")
  67. (defmacro org-re (s)
  68. "Replace posix classes in regular expression S."
  69. (declare (debug (form))
  70. (obsolete "you can safely remove it." "Org 9.0"))
  71. s)
  72. ;;;; Functions from cl-lib that Org used to have its own implementation of.
  73. (define-obsolete-function-alias 'org-count 'cl-count "Org 9.0")
  74. (define-obsolete-function-alias 'org-every 'cl-every "Org 9.0")
  75. (define-obsolete-function-alias 'org-find-if 'cl-find-if "Org 9.0")
  76. (define-obsolete-function-alias 'org-reduce 'cl-reduce "Org 9.0")
  77. (define-obsolete-function-alias 'org-remove-if 'cl-remove-if "Org 9.0")
  78. (define-obsolete-function-alias 'org-remove-if-not 'cl-remove-if-not "Org 9.0")
  79. (define-obsolete-function-alias 'org-some 'cl-some "Org 9.0")
  80. (define-obsolete-function-alias 'org-floor* 'cl-floor "Org 9.0")
  81. (defun org-sublist (list start end)
  82. "Return a section of LIST, from START to END.
  83. Counting starts at 1."
  84. (cl-subseq list (1- start) end))
  85. (make-obsolete 'org-sublist "cl-subseq (note the 0-based counting)." "Org 9.0")
  86. ;;;; Functions available since Emacs 24.3
  87. (define-obsolete-function-alias 'org-buffer-narrowed-p 'buffer-narrowed-p "Org 9.0")
  88. (define-obsolete-function-alias 'org-called-interactively-p 'called-interactively-p "Org 9.0")
  89. (define-obsolete-function-alias 'org-char-to-string 'char-to-string "Org 9.0")
  90. (define-obsolete-function-alias 'org-delete-directory 'delete-directory "Org 9.0")
  91. (define-obsolete-function-alias 'org-format-seconds 'format-seconds "Org 9.0")
  92. (define-obsolete-function-alias 'org-link-escape-browser 'url-encode-url "Org 9.0")
  93. (define-obsolete-function-alias 'org-no-warnings 'with-no-warnings "Org 9.0")
  94. (define-obsolete-function-alias 'org-number-sequence 'number-sequence "Org 9.0")
  95. (define-obsolete-function-alias 'org-pop-to-buffer-same-window 'pop-to-buffer-same-window "Org 9.0")
  96. (define-obsolete-function-alias 'org-string-match-p 'string-match-p "Org 9.0")
  97. ;;;; Functions and variables from previous releases now obsolete.
  98. (define-obsolete-function-alias 'org-element-remove-indentation
  99. 'org-remove-indentation "Org 9.0")
  100. (define-obsolete-variable-alias 'org-hierarchical-checkbox-statistics
  101. 'org-checkbox-hierarchical-statistics "Org 8.0")
  102. (define-obsolete-variable-alias 'org-description-max-indent
  103. 'org-list-description-max-indent "Org 8.0")
  104. (define-obsolete-variable-alias 'org-latex-create-formula-image-program
  105. 'org-preview-latex-default-process "Org 9.0")
  106. (define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
  107. 'org-preview-latex-image-directory "Org 9.0")
  108. (define-obsolete-function-alias 'org-table-p 'org-at-table-p "Org 9.0")
  109. (define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "Org 9.0")
  110. (define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "Org 8.3")
  111. (define-obsolete-function-alias 'org-speed-command-default-hook
  112. 'org-speed-command-activate "Org 8.0")
  113. (define-obsolete-function-alias 'org-babel-speed-command-hook
  114. 'org-babel-speed-command-activate "Org 8.0")
  115. (define-obsolete-function-alias 'org-image-file-name-regexp
  116. 'image-file-name-regexp "Org 9.0")
  117. (define-obsolete-function-alias 'org-get-legal-level
  118. 'org-get-valid-level "Org 7.8")
  119. (define-obsolete-function-alias 'org-completing-read-no-i
  120. 'completing-read "Org 9.0")
  121. (define-obsolete-function-alias 'org-icompleting-read
  122. 'completing-read "Org 9.0")
  123. (define-obsolete-function-alias 'org-iread-file-name 'read-file-name "Org 9.0")
  124. (define-obsolete-function-alias 'org-days-to-time
  125. 'org-time-stamp-to-now "Org 8.2")
  126. (define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
  127. 'org-agenda-ignore-properties "Org 9.0")
  128. (define-obsolete-function-alias 'org-preview-latex-fragment
  129. 'org-toggle-latex-fragment "Org 8.3")
  130. (define-obsolete-function-alias 'org-display-inline-modification-hook
  131. 'org-display-inline-remove-overlay "Org 8.0")
  132. (define-obsolete-function-alias 'org-export-get-genealogy
  133. 'org-element-lineage "Org 9.0")
  134. (define-obsolete-variable-alias 'org-latex-with-hyperref
  135. 'org-latex-hyperref-template "Org 9.0")
  136. (define-obsolete-variable-alias 'org-link-to-org-use-id
  137. 'org-id-link-to-org-use-id "Org 8.0")
  138. (define-obsolete-variable-alias 'hfy-optimisations 'hfy-optimizations "Org 9.0")
  139. (define-obsolete-variable-alias 'org-clock-modeline-total
  140. 'org-clock-mode-line-total "Org 8.0")
  141. (define-obsolete-function-alias 'org-protocol-unhex-compound
  142. 'org-link-unescape-compound "Org 7.8")
  143. (define-obsolete-function-alias 'org-protocol-unhex-string
  144. 'org-link-unescape "Org 7.8")
  145. (define-obsolete-function-alias 'org-protocol-unhex-single-byte-sequence
  146. 'org-link-unescape-single-byte-sequence "Org 7.8")
  147. (define-obsolete-variable-alias 'org-export-htmlized-org-css-url
  148. 'org-org-htmlized-css-url "Org 8.2")
  149. (define-obsolete-variable-alias 'org-alphabetical-lists
  150. 'org-list-allow-alphabetical "Org 8.0")
  151. (define-obsolete-function-alias 'org-list-parse-list 'org-list-to-lisp "Org 9.0")
  152. (define-obsolete-variable-alias 'org-agenda-menu-two-column
  153. 'org-agenda-menu-two-columns "Org 8.0")
  154. (define-obsolete-variable-alias 'org-finalize-agenda-hook
  155. 'org-agenda-finalize-hook "Org 8.0")
  156. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "Org 7.8")
  157. (define-obsolete-function-alias 'org-agenda-post-command-hook
  158. 'org-agenda-update-agenda-type "Org 8.0")
  159. (define-obsolete-function-alias 'org-agenda-todayp
  160. 'org-agenda-today-p "Org 9.0")
  161. (define-obsolete-function-alias 'org-babel-examplize-region
  162. 'org-babel-examplify-region "Org 9.0")
  163. (define-obsolete-function-alias 'org-babel-trim 'org-trim "Org 9.0")
  164. (define-obsolete-variable-alias 'org-html-style-include-scripts
  165. 'org-html-head-include-scripts "Org 8.0")
  166. (define-obsolete-variable-alias 'org-html-style-include-default
  167. 'org-html-head-include-default-style "Org 8.0")
  168. (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
  169. (define-obsolete-function-alias 'org-insert-columns-dblock
  170. 'org-columns-insert-dblock "Org 9.0")
  171. (defcustom org-read-date-minibuffer-setup-hook nil
  172. "Hook to be used to set up keys for the date/time interface.
  173. Add key definitions to `minibuffer-local-map', which will be a
  174. temporary copy."
  175. :group 'org-time
  176. :type 'hook)
  177. (make-obsolete-variable
  178. 'org-read-date-minibuffer-setup-hook
  179. "set `org-read-date-minibuffer-local-map' instead." "Org 8.0")
  180. (defun org-compatible-face (inherits specs)
  181. "Make a compatible face specification.
  182. If INHERITS is an existing face and if the Emacs version supports
  183. it, just inherit the face. If INHERITS is not given and SPECS
  184. is, use SPECS to define the face."
  185. (declare (indent 1))
  186. (if (facep inherits)
  187. (list (list t :inherit inherits))
  188. specs))
  189. (make-obsolete 'org-compatible-face "you can remove it." "Org 9.0")
  190. (defun org-add-link-type (type &optional follow export)
  191. "Add a new TYPE link.
  192. FOLLOW and EXPORT are two functions.
  193. FOLLOW should take the link path as the single argument and do whatever
  194. is necessary to follow the link, for example find a file or display
  195. a mail message.
  196. EXPORT should format the link path for export to one of the export formats.
  197. It should be a function accepting three arguments:
  198. path the path of the link, the text after the prefix (like \"http:\")
  199. desc the description of the link, if any
  200. format the export format, a symbol like `html' or `latex' or `ascii'.
  201. The function may use the FORMAT information to return different values
  202. depending on the format. The return value will be put literally into
  203. the exported file. If the return value is nil, this means Org should
  204. do what it normally does with links which do not have EXPORT defined.
  205. Org mode has a built-in default for exporting links. If you are happy with
  206. this default, there is no need to define an export function for the link
  207. type. For a simple example of an export function, see `org-bbdb.el'.
  208. If TYPE already exists, update it with the arguments.
  209. See `org-link-parameters' for documentation on the other parameters."
  210. (org-link-set-parameters type :follow follow :export export)
  211. (message "Created %s link." type))
  212. (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." "Org 9.0")
  213. (defun org-table-recognize-table.el ()
  214. "If there is a table.el table nearby, recognize it and move into it."
  215. (when (and org-table-tab-recognizes-table.el (org-at-table.el-p))
  216. (beginning-of-line)
  217. (unless (or (looking-at org-table-dataline-regexp)
  218. (not (looking-at org-table1-hline-regexp)))
  219. (forward-line)
  220. (when (looking-at org-table-any-border-regexp)
  221. (forward-line -2)))
  222. (if (re-search-forward "|" (org-table-end t) t)
  223. (progn
  224. (require 'table)
  225. (if (table--at-cell-p (point)) t
  226. (message "recognizing table.el table...")
  227. (table-recognize-table)
  228. (message "recognizing table.el table...done")))
  229. (error "This should not happen"))))
  230. ;; Not used by Org core since commit 6d1e3082, Feb 2010.
  231. (make-obsolete 'org-table-recognize-table.el
  232. "please notify the org mailing list if you use this function."
  233. "Org 9.0")
  234. (define-obsolete-function-alias
  235. 'org-minutes-to-hh:mm-string 'org-minutes-to-clocksum-string "Org 8.0")
  236. (defun org-remove-angle-brackets (s)
  237. (org-unbracket-string "<" ">" s))
  238. (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "Org 9.0")
  239. (defun org-remove-double-quotes (s)
  240. (org-unbracket-string "\"" "\"" s))
  241. (make-obsolete 'org-remove-double-quotes 'org-unbracket-string "Org 9.0")
  242. ;;;; Obsolete link types
  243. (eval-after-load 'org
  244. '(progn
  245. (org-link-set-parameters "file+emacs") ;since Org 9.0
  246. (org-link-set-parameters "file+sys"))) ;since Org 9.0
  247. ;;; Miscellaneous functions
  248. (defun org-version-check (version feature level)
  249. (let* ((v1 (mapcar 'string-to-number (split-string version "[.]")))
  250. (v2 (mapcar 'string-to-number (split-string emacs-version "[.]")))
  251. (rmaj (or (nth 0 v1) 99))
  252. (rmin (or (nth 1 v1) 99))
  253. (rbld (or (nth 2 v1) 99))
  254. (maj (or (nth 0 v2) 0))
  255. (min (or (nth 1 v2) 0))
  256. (bld (or (nth 2 v2) 0)))
  257. (if (or (< maj rmaj)
  258. (and (= maj rmaj)
  259. (< min rmin))
  260. (and (= maj rmaj)
  261. (= min rmin)
  262. (< bld rbld)))
  263. (if (eq level :predicate)
  264. ;; just return if we have the version
  265. nil
  266. (let ((msg (format "Emacs %s or greater is recommended for %s"
  267. version feature)))
  268. (display-warning 'org msg level)
  269. t))
  270. t)))
  271. (defun org-get-x-clipboard (value)
  272. "Get the value of the X or Windows clipboard."
  273. (cond ((and (eq window-system 'x)
  274. (fboundp 'gui-get-selection)) ;Silence byte-compiler.
  275. (org-no-properties
  276. (ignore-errors
  277. (or (gui-get-selection value 'UTF8_STRING)
  278. (gui-get-selection value 'COMPOUND_TEXT)
  279. (gui-get-selection value 'STRING)
  280. (gui-get-selection value 'TEXT)))))
  281. ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
  282. (w32-get-clipboard-data))))
  283. (defun org-add-props (string plist &rest props)
  284. "Add text properties to entire string, from beginning to end.
  285. PLIST may be a list of properties, PROPS are individual properties and values
  286. that will be added to PLIST. Returns the string that was modified."
  287. (add-text-properties
  288. 0 (length string) (if props (append plist props) plist) string)
  289. string)
  290. (put 'org-add-props 'lisp-indent-function 2)
  291. (defun org-fit-window-to-buffer (&optional window max-height min-height
  292. shrink-only)
  293. "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
  294. WINDOW defaults to the selected window. MAX-HEIGHT and MIN-HEIGHT are
  295. passed through to `fit-window-to-buffer'. If SHRINK-ONLY is set, call
  296. `shrink-window-if-larger-than-buffer' instead, the height limit is
  297. ignored in this case."
  298. (cond ((if (fboundp 'window-full-width-p)
  299. (not (window-full-width-p window))
  300. ;; do nothing if another window would suffer
  301. (> (frame-width) (window-width window))))
  302. ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
  303. (fit-window-to-buffer window max-height min-height))
  304. ((fboundp 'shrink-window-if-larger-than-buffer)
  305. (shrink-window-if-larger-than-buffer window)))
  306. (or window (selected-window)))
  307. ;; `set-transient-map' is only in Emacs >= 24.4
  308. (defalias 'org-set-transient-map
  309. (if (fboundp 'set-transient-map)
  310. 'set-transient-map
  311. 'set-temporary-overlay-map))
  312. ;;; Region compatibility
  313. (defvar org-ignore-region nil
  314. "Non-nil means temporarily disable the active region.")
  315. (defun org-region-active-p ()
  316. "Non-nil when the region active.
  317. Unlike to `use-region-p', this function also checks
  318. `org-ignore-region'."
  319. (and (not org-ignore-region) (use-region-p)))
  320. (defun org-cursor-to-region-beginning ()
  321. (when (and (org-region-active-p)
  322. (> (point) (region-beginning)))
  323. (exchange-point-and-mark)))
  324. ;;; Invisibility compatibility
  325. (defun org-remove-from-invisibility-spec (arg)
  326. "Remove elements from `buffer-invisibility-spec'."
  327. (if (fboundp 'remove-from-invisibility-spec)
  328. (remove-from-invisibility-spec arg)
  329. (if (consp buffer-invisibility-spec)
  330. (setq buffer-invisibility-spec
  331. (delete arg buffer-invisibility-spec)))))
  332. (defun org-in-invisibility-spec-p (arg)
  333. "Is ARG a member of `buffer-invisibility-spec'?"
  334. (if (consp buffer-invisibility-spec)
  335. (member arg buffer-invisibility-spec)))
  336. (defun org-move-to-column (column &optional force _buffer)
  337. "Move to column COLUMN.
  338. Pass COLUMN and FORCE to `move-to-column'."
  339. (let ((buffer-invisibility-spec
  340. (if (listp buffer-invisibility-spec)
  341. (remove '(org-filtered) buffer-invisibility-spec)
  342. buffer-invisibility-spec)))
  343. (move-to-column column force)))
  344. (defmacro org-find-library-dir (library)
  345. `(file-name-directory (or (locate-library ,library) "")))
  346. (defun org-count-lines (s)
  347. "How many lines in string S?"
  348. (let ((start 0) (n 1))
  349. (while (string-match "\n" s start)
  350. (setq start (match-end 0) n (1+ n)))
  351. (if (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
  352. (setq n (1- n)))
  353. n))
  354. (defun org-kill-new (string &rest args)
  355. (remove-text-properties 0 (length string) '(line-prefix t wrap-prefix t)
  356. string)
  357. (apply 'kill-new string args))
  358. ;; `font-lock-ensure' is only available from 24.4.50 on
  359. (defalias 'org-font-lock-ensure
  360. (if (fboundp 'font-lock-ensure)
  361. #'font-lock-ensure
  362. (lambda (&optional _beg _end)
  363. (with-no-warnings (font-lock-fontify-buffer)))))
  364. (defmacro org-no-popups (&rest body)
  365. "Suppress popup windows.
  366. Let-bind some variables to nil around BODY to achieve the desired
  367. effect, which variables to use depends on the Emacs version."
  368. (if (org-version-check "24.2.50" "" :predicate)
  369. `(let (pop-up-frames display-buffer-alist)
  370. ,@body)
  371. `(let (pop-up-frames special-display-buffer-names special-display-regexps special-display-function)
  372. ,@body)))
  373. ;;;###autoload
  374. (defmacro org-check-version ()
  375. "Try very hard to provide sensible version strings."
  376. (let* ((org-dir (org-find-library-dir "org"))
  377. (org-version.el (concat org-dir "org-version.el"))
  378. (org-fixup.el (concat org-dir "../mk/org-fixup.el")))
  379. (if (require 'org-version org-version.el 'noerror)
  380. '(progn
  381. (autoload 'org-release "org-version.el")
  382. (autoload 'org-git-version "org-version.el"))
  383. (if (require 'org-fixup org-fixup.el 'noerror)
  384. '(org-fixup)
  385. ;; provide fallback definitions and complain
  386. (warn "Could not define org version correctly. Check installation!")
  387. '(progn
  388. (defun org-release () "N/A")
  389. (defun org-git-version () "N/A !!check installation!!"))))))
  390. (defmacro org-with-silent-modifications (&rest body)
  391. (if (fboundp 'with-silent-modifications)
  392. `(with-silent-modifications ,@body)
  393. `(org-unmodified ,@body)))
  394. (def-edebug-spec org-with-silent-modifications (body))
  395. ;; Functions for Emacs < 24.4 compatibility
  396. (defun org-define-error (name message)
  397. "Define NAME as a new error signal.
  398. MESSAGE is a string that will be output to the echo area if such
  399. an error is signaled without being caught by a `condition-case'.
  400. Implements `define-error' for older emacsen."
  401. (if (fboundp 'define-error) (define-error name message)
  402. (put name 'error-conditions
  403. (copy-sequence (cons name (get 'error 'error-conditions))))))
  404. (unless (fboundp 'string-suffix-p)
  405. ;; From Emacs subr.el.
  406. (defun string-prefix-p (prefix string &optional ignore-case)
  407. "Return non-nil if PREFIX is a prefix of STRING.
  408. If IGNORE-CASE is non-nil, the comparison is done without paying attention
  409. to case differences."
  410. (let ((prefix-length (length prefix)))
  411. (if (> prefix-length (length string)) nil
  412. (eq t (compare-strings prefix 0 prefix-length string
  413. 0 prefix-length ignore-case)))))
  414. (defun string-suffix-p (suffix string &optional ignore-case)
  415. "Return non-nil if SUFFIX is a suffix of STRING.
  416. If IGNORE-CASE is non-nil, the comparison is done without paying
  417. attention to case differences."
  418. (let ((start-pos (- (length string) (length suffix))))
  419. (and (>= start-pos 0)
  420. (eq t (compare-strings suffix nil nil
  421. string start-pos nil ignore-case))))))
  422. (provide 'org-compat)
  423. ;;; org-compat.el ends here