org-macs.el 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. ;;; org-macs.el --- Top-level Definitions for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: https://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 <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains macro definitions, defsubst definitions, other
  23. ;; stuff needed for compilation and top-level forms in Org mode, as
  24. ;; well lots of small functions that are not Org mode specific but
  25. ;; simply generally useful stuff.
  26. ;;; Code:
  27. (require 'cl-lib)
  28. (require 'format-spec)
  29. (declare-function org-string-collate-lessp "org-compat" (s1 s2 &optional locale ignore-case))
  30. (defvar org-ts-regexp0)
  31. ;;; Macros
  32. (defmacro org-with-gensyms (symbols &rest body)
  33. (declare (debug (sexp body)) (indent 1))
  34. `(let ,(mapcar (lambda (s)
  35. `(,s (make-symbol (concat "--" (symbol-name ',s)))))
  36. symbols)
  37. ,@body))
  38. ;; Use `with-silent-modifications' to ignore cosmetic changes and
  39. ;; `org-unmodified' to ignore real text modifications.
  40. (defmacro org-unmodified (&rest body)
  41. "Run BODY while preserving the buffer's `buffer-modified-p' state."
  42. (declare (debug (body)))
  43. (org-with-gensyms (was-modified)
  44. `(let ((,was-modified (buffer-modified-p)))
  45. (unwind-protect
  46. (let ((buffer-undo-list t)
  47. (inhibit-modification-hooks t))
  48. ,@body)
  49. (set-buffer-modified-p ,was-modified)))))
  50. (defmacro org-without-partial-completion (&rest body)
  51. (declare (debug (body)))
  52. `(if (and (boundp 'partial-completion-mode)
  53. partial-completion-mode
  54. (fboundp 'partial-completion-mode))
  55. (unwind-protect
  56. (progn
  57. (partial-completion-mode -1)
  58. ,@body)
  59. (partial-completion-mode 1))
  60. ,@body))
  61. (defmacro org-with-point-at (pom &rest body)
  62. "Move to buffer and point of point-or-marker POM for the duration of BODY."
  63. (declare (debug (form body)) (indent 1))
  64. (org-with-gensyms (mpom)
  65. `(let ((,mpom ,pom))
  66. (save-excursion
  67. (when (markerp ,mpom) (set-buffer (marker-buffer ,mpom)))
  68. (org-with-wide-buffer
  69. (goto-char (or ,mpom (point)))
  70. ,@body)))))
  71. (defmacro org-with-remote-undo (buffer &rest body)
  72. "Execute BODY while recording undo information in two buffers."
  73. (declare (debug (form body)) (indent 1))
  74. (org-with-gensyms (cline cmd buf1 buf2 undo1 undo2 c1 c2)
  75. `(let ((,cline (org-current-line))
  76. (,cmd this-command)
  77. (,buf1 (current-buffer))
  78. (,buf2 ,buffer)
  79. (,undo1 buffer-undo-list)
  80. (,undo2 (with-current-buffer ,buffer buffer-undo-list))
  81. ,c1 ,c2)
  82. ,@body
  83. (when org-agenda-allow-remote-undo
  84. (setq ,c1 (org-verify-change-for-undo
  85. ,undo1 (with-current-buffer ,buf1 buffer-undo-list))
  86. ,c2 (org-verify-change-for-undo
  87. ,undo2 (with-current-buffer ,buf2 buffer-undo-list)))
  88. (when (or ,c1 ,c2)
  89. ;; make sure there are undo boundaries
  90. (and ,c1 (with-current-buffer ,buf1 (undo-boundary)))
  91. (and ,c2 (with-current-buffer ,buf2 (undo-boundary)))
  92. ;; remember which buffer to undo
  93. (push (list ,cmd ,cline ,buf1 ,c1 ,buf2 ,c2)
  94. org-agenda-undo-list))))))
  95. (defmacro org-no-read-only (&rest body)
  96. "Inhibit read-only for BODY."
  97. (declare (debug (body)))
  98. `(let ((inhibit-read-only t)) ,@body))
  99. (defmacro org-save-outline-visibility (use-markers &rest body)
  100. "Save and restore outline visibility around BODY.
  101. If USE-MARKERS is non-nil, use markers for the positions. This
  102. means that the buffer may change while running BODY, but it also
  103. means that the buffer should stay alive during the operation,
  104. because otherwise all these markers will point to nowhere."
  105. (declare (debug (form body)) (indent 1))
  106. (org-with-gensyms (data invisible-types markers?)
  107. `(let* ((,invisible-types '(org-hide-block org-hide-drawer outline))
  108. (,markers? ,use-markers)
  109. (,data
  110. (mapcar (lambda (o)
  111. (let ((beg (overlay-start o))
  112. (end (overlay-end o))
  113. (type (overlay-get o 'invisible)))
  114. (and beg end
  115. (> end beg)
  116. (memq type ,invisible-types)
  117. (list (if ,markers? (copy-marker beg) beg)
  118. (if ,markers? (copy-marker end t) end)
  119. type))))
  120. (org-with-wide-buffer
  121. (overlays-in (point-min) (point-max))))))
  122. (unwind-protect (progn ,@body)
  123. (org-with-wide-buffer
  124. (dolist (type ,invisible-types)
  125. (remove-overlays (point-min) (point-max) 'invisible type))
  126. (pcase-dolist (`(,beg ,end ,type) (delq nil ,data))
  127. (org-flag-region beg end t type)
  128. (when ,markers?
  129. (set-marker beg nil)
  130. (set-marker end nil))))))))
  131. (defmacro org-with-wide-buffer (&rest body)
  132. "Execute body while temporarily widening the buffer."
  133. (declare (debug (body)))
  134. `(save-excursion
  135. (save-restriction
  136. (widen)
  137. ,@body)))
  138. (defmacro org-with-limited-levels (&rest body)
  139. "Execute BODY with limited number of outline levels."
  140. (declare (debug (body)))
  141. `(progn
  142. (defvar org-called-with-limited-levels)
  143. (defvar org-outline-regexp)
  144. (defvar outline-regexp)
  145. (defvar org-outline-regexp-bol)
  146. (let* ((org-called-with-limited-levels t)
  147. (org-outline-regexp (org-get-limited-outline-regexp))
  148. (outline-regexp org-outline-regexp)
  149. (org-outline-regexp-bol (concat "^" org-outline-regexp)))
  150. ,@body)))
  151. (defmacro org-eval-in-environment (environment form)
  152. (declare (debug (form form)) (indent 1))
  153. `(eval (list 'let ,environment ',form)))
  154. ;;;###autoload
  155. (defmacro org-load-noerror-mustsuffix (file)
  156. "Load FILE with optional arguments NOERROR and MUSTSUFFIX."
  157. `(load ,file 'noerror nil nil 'mustsuffix))
  158. (defmacro org-preserve-local-variables (&rest body)
  159. "Execute BODY while preserving local variables."
  160. (declare (debug (body)))
  161. `(let ((local-variables
  162. (org-with-wide-buffer
  163. (goto-char (point-max))
  164. (let ((case-fold-search t))
  165. (and (re-search-backward "^[ \t]*# +Local Variables:"
  166. (max (- (point) 3000) 1)
  167. t)
  168. (delete-and-extract-region (point) (point-max)))))))
  169. (unwind-protect (progn ,@body)
  170. (when local-variables
  171. (org-with-wide-buffer
  172. (goto-char (point-max))
  173. ;; If last section is folded, make sure to also hide file
  174. ;; local variables after inserting them back.
  175. (let ((overlay
  176. (cl-find-if (lambda (o)
  177. (eq 'outline (overlay-get o 'invisible)))
  178. (overlays-at (1- (point))))))
  179. (unless (bolp) (insert "\n"))
  180. (insert local-variables)
  181. (when overlay
  182. (move-overlay overlay (overlay-start overlay) (point-max)))))))))
  183. (defmacro org-no-popups (&rest body)
  184. "Suppress popup windows and evaluate BODY."
  185. `(let (pop-up-frames display-buffer-alist)
  186. ,@body))
  187. (defmacro org-table-with-shrunk-field (&rest body)
  188. "Save field shrunk state, execute BODY and restore state."
  189. (declare (debug (body)))
  190. (org-with-gensyms (end shrunk size)
  191. `(let* ((,shrunk (save-match-data (org-table--shrunk-field)))
  192. (,end (and ,shrunk (copy-marker (overlay-end ,shrunk) t)))
  193. (,size (and ,shrunk (- ,end (overlay-start ,shrunk)))))
  194. (when ,shrunk (delete-overlay ,shrunk))
  195. (unwind-protect (progn ,@body)
  196. (when ,shrunk (move-overlay ,shrunk (- ,end ,size) ,end))))))
  197. ;;; Buffer and windows
  198. (defun org-base-buffer (buffer)
  199. "Return the base buffer of BUFFER, if it has one. Else return the buffer."
  200. (when buffer
  201. (or (buffer-base-buffer buffer)
  202. buffer)))
  203. (defun org-find-base-buffer-visiting (file)
  204. "Like `find-buffer-visiting' but always return the base buffer and
  205. not an indirect buffer."
  206. (let ((buf (or (get-file-buffer file)
  207. (find-buffer-visiting file))))
  208. (org-base-buffer buf)))
  209. (defun org-switch-to-buffer-other-window (&rest args)
  210. "Switch to buffer in a second window on the current frame.
  211. In particular, do not allow pop-up frames.
  212. Returns the newly created buffer."
  213. (org-no-popups (apply #'switch-to-buffer-other-window args)))
  214. (defun org-fit-window-to-buffer (&optional window max-height min-height
  215. shrink-only)
  216. "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
  217. WINDOW defaults to the selected window. MAX-HEIGHT and MIN-HEIGHT are
  218. passed through to `fit-window-to-buffer'. If SHRINK-ONLY is set, call
  219. `shrink-window-if-larger-than-buffer' instead, the height limit is
  220. ignored in this case."
  221. (cond ((if (fboundp 'window-full-width-p)
  222. (not (window-full-width-p window))
  223. ;; Do nothing if another window would suffer.
  224. (> (frame-width) (window-width window))))
  225. ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
  226. (fit-window-to-buffer window max-height min-height))
  227. ((fboundp 'shrink-window-if-larger-than-buffer)
  228. (shrink-window-if-larger-than-buffer window)))
  229. (or window (selected-window)))
  230. ;;; File
  231. (defun org-file-newer-than-p (file time)
  232. "Non-nil if FILE is newer than TIME.
  233. FILE is a filename, as a string, TIME is a list of integers, as
  234. returned by, e.g., `current-time'."
  235. (and (file-exists-p file)
  236. ;; Only compare times up to whole seconds as some file-systems
  237. ;; (e.g. HFS+) do not retain any finer granularity. As
  238. ;; a consequence, make sure we return non-nil when the two
  239. ;; times are equal.
  240. (not (time-less-p (cl-subseq (nth 5 (file-attributes file)) 0 2)
  241. (cl-subseq time 0 2)))))
  242. (defun org-compile-file (source process ext &optional err-msg log-buf spec)
  243. "Compile a SOURCE file using PROCESS.
  244. PROCESS is either a function or a list of shell commands, as
  245. strings. EXT is a file extension, without the leading dot, as
  246. a string. It is used to check if the process actually succeeded.
  247. PROCESS must create a file with the same base name and directory
  248. as SOURCE, but ending with EXT. The function then returns its
  249. filename. Otherwise, it raises an error. The error message can
  250. then be refined by providing string ERR-MSG, which is appended to
  251. the standard message.
  252. If PROCESS is a function, it is called with a single argument:
  253. the SOURCE file.
  254. If it is a list of commands, each of them is called using
  255. `shell-command'. By default, in each command, %b, %f, %F, %o and
  256. %O are replaced with, respectively, SOURCE base name, name, full
  257. name, directory and absolute output file name. It is possible,
  258. however, to use more place-holders by specifying them in optional
  259. argument SPEC, as an alist following the pattern
  260. (CHARACTER . REPLACEMENT-STRING).
  261. When PROCESS is a list of commands, optional argument LOG-BUF can
  262. be set to a buffer or a buffer name. `shell-command' then uses
  263. it for output."
  264. (let* ((base-name (file-name-base source))
  265. (full-name (file-truename source))
  266. (out-dir (or (file-name-directory source) "./"))
  267. (output (expand-file-name (concat base-name "." ext) out-dir))
  268. (time (current-time))
  269. (err-msg (if (stringp err-msg) (concat ". " err-msg) "")))
  270. (save-window-excursion
  271. (pcase process
  272. ((pred functionp) (funcall process (shell-quote-argument source)))
  273. ((pred consp)
  274. (let ((log-buf (and log-buf (get-buffer-create log-buf)))
  275. (spec (append spec
  276. `((?b . ,(shell-quote-argument base-name))
  277. (?f . ,(shell-quote-argument source))
  278. (?F . ,(shell-quote-argument full-name))
  279. (?o . ,(shell-quote-argument out-dir))
  280. (?O . ,(shell-quote-argument output))))))
  281. (dolist (command process)
  282. (shell-command (format-spec command spec) log-buf))
  283. (when log-buf (with-current-buffer log-buf (compilation-mode)))))
  284. (_ (error "No valid command to process %S%s" source err-msg))))
  285. ;; Check for process failure. Output file is expected to be
  286. ;; located in the same directory as SOURCE.
  287. (unless (org-file-newer-than-p output time)
  288. (error (format "File %S wasn't produced%s" output err-msg)))
  289. output))
  290. ;;; Indentation
  291. (defun org-do-remove-indentation (&optional n)
  292. "Remove the maximum common indentation from the buffer.
  293. When optional argument N is a positive integer, remove exactly
  294. that much characters from indentation, if possible. Return nil
  295. if it fails."
  296. (catch :exit
  297. (goto-char (point-min))
  298. ;; Find maximum common indentation, if not specified.
  299. (let ((n (or n
  300. (let ((min-ind (point-max)))
  301. (save-excursion
  302. (while (re-search-forward "^[ \t]*\\S-" nil t)
  303. (let ((ind (1- (current-column))))
  304. (if (zerop ind) (throw :exit nil)
  305. (setq min-ind (min min-ind ind))))))
  306. min-ind))))
  307. (if (zerop n) (throw :exit nil)
  308. ;; Remove exactly N indentation, but give up if not possible.
  309. (while (not (eobp))
  310. (let ((ind (progn (skip-chars-forward " \t") (current-column))))
  311. (cond ((eolp) (delete-region (line-beginning-position) (point)))
  312. ((< ind n) (throw :exit nil))
  313. (t (indent-line-to (- ind n))))
  314. (forward-line)))
  315. ;; Signal success.
  316. t))))
  317. ;;; Input
  318. (defun org-read-function (prompt &optional allow-empty?)
  319. "Prompt for a function.
  320. If ALLOW-EMPTY? is non-nil, return nil rather than raising an
  321. error when the user input is empty."
  322. (let ((func (completing-read prompt obarray #'fboundp t)))
  323. (cond ((not (string= func ""))
  324. (intern func))
  325. (allow-empty? nil)
  326. (t (user-error "Empty input is not valid")))))
  327. (defun org-completing-read (&rest args)
  328. "Completing-read with SPACE being a normal character."
  329. (let ((enable-recursive-minibuffers t)
  330. (minibuffer-local-completion-map
  331. (copy-keymap minibuffer-local-completion-map)))
  332. (define-key minibuffer-local-completion-map " " 'self-insert-command)
  333. (define-key minibuffer-local-completion-map "?" 'self-insert-command)
  334. (define-key minibuffer-local-completion-map (kbd "C-c !")
  335. 'org-time-stamp-inactive)
  336. (apply #'completing-read args)))
  337. (defun org--mks-read-key (allowed-keys prompt)
  338. "Read a key and ensure it is a member of ALLOWED-KEYS.
  339. TAB, SPC and RET are treated equivalently."
  340. (let* ((key (char-to-string
  341. (pcase (read-char-exclusive prompt)
  342. ((or ?\s ?\t ?\r) ?\t)
  343. (char char)))))
  344. (if (member key allowed-keys)
  345. key
  346. (message "Invalid key: `%s'" key)
  347. (sit-for 1)
  348. (org--mks-read-key allowed-keys prompt))))
  349. (defun org-mks (table title &optional prompt specials)
  350. "Select a member of an alist with multiple keys.
  351. TABLE is the alist which should contain entries where the car is a string.
  352. There should be two types of entries.
  353. 1. prefix descriptions like (\"a\" \"Description\")
  354. This indicates that `a' is a prefix key for multi-letter selection, and
  355. that there are entries following with keys like \"ab\", \"ax\"...
  356. 2. Select-able members must have more than two elements, with the first
  357. being the string of keys that lead to selecting it, and the second a
  358. short description string of the item.
  359. The command will then make a temporary buffer listing all entries
  360. that can be selected with a single key, and all the single key
  361. prefixes. When you press the key for a single-letter entry, it is selected.
  362. When you press a prefix key, the commands (and maybe further prefixes)
  363. under this key will be shown and offered for selection.
  364. TITLE will be placed over the selection in the temporary buffer,
  365. PROMPT will be used when prompting for a key. SPECIALS is an
  366. alist with (\"key\" \"description\") entries. When one of these
  367. is selected, only the bare key is returned."
  368. (save-window-excursion
  369. (let ((inhibit-quit t)
  370. (buffer (org-switch-to-buffer-other-window "*Org Select*"))
  371. (prompt (or prompt "Select: "))
  372. current)
  373. (unwind-protect
  374. (catch 'exit
  375. (while t
  376. (erase-buffer)
  377. (insert title "\n\n")
  378. (let ((des-keys nil)
  379. (allowed-keys '("\C-g"))
  380. (tab-alternatives '("\s" "\t" "\r"))
  381. (cursor-type nil))
  382. ;; Populate allowed keys and descriptions keys
  383. ;; available with CURRENT selector.
  384. (let ((re (format "\\`%s\\(.\\)\\'"
  385. (if current (regexp-quote current) "")))
  386. (prefix (if current (concat current " ") "")))
  387. (dolist (entry table)
  388. (pcase entry
  389. ;; Description.
  390. (`(,(and key (pred (string-match re))) ,desc)
  391. (let ((k (match-string 1 key)))
  392. (push k des-keys)
  393. ;; Keys ending in tab, space or RET are equivalent.
  394. (if (member k tab-alternatives)
  395. (push "\t" allowed-keys)
  396. (push k allowed-keys))
  397. (insert prefix "[" k "]" "..." " " desc "..." "\n")))
  398. ;; Usable entry.
  399. (`(,(and key (pred (string-match re))) ,desc . ,_)
  400. (let ((k (match-string 1 key)))
  401. (insert prefix "[" k "]" " " desc "\n")
  402. (push k allowed-keys)))
  403. (_ nil))))
  404. ;; Insert special entries, if any.
  405. (when specials
  406. (insert "----------------------------------------------------\
  407. ---------------------------\n")
  408. (pcase-dolist (`(,key ,description) specials)
  409. (insert (format "[%s] %s\n" key description))
  410. (push key allowed-keys)))
  411. ;; Display UI and let user select an entry or
  412. ;; a sub-level prefix.
  413. (goto-char (point-min))
  414. (unless (pos-visible-in-window-p (point-max))
  415. (org-fit-window-to-buffer))
  416. (let ((pressed (org--mks-read-key allowed-keys prompt)))
  417. (setq current (concat current pressed))
  418. (cond
  419. ((equal pressed "\C-g") (user-error "Abort"))
  420. ;; Selection is a prefix: open a new menu.
  421. ((member pressed des-keys))
  422. ;; Selection matches an association: return it.
  423. ((let ((entry (assoc current table)))
  424. (and entry (throw 'exit entry))))
  425. ;; Selection matches a special entry: return the
  426. ;; selection prefix.
  427. ((assoc current specials) (throw 'exit current))
  428. (t (error "No entry available")))))))
  429. (when buffer (kill-buffer buffer))))))
  430. ;;; List manipulation
  431. (defsubst org-get-alist-option (option key)
  432. (cond ((eq key t) t)
  433. ((eq option t) t)
  434. ((assoc key option) (cdr (assoc key option)))
  435. (t (let ((r (cdr (assq 'default option))))
  436. (if (listp r) (delq nil r) r)))))
  437. (defsubst org-last (list)
  438. "Return the last element of LIST."
  439. (car (last list)))
  440. (defsubst org-uniquify (list)
  441. "Non-destructively remove duplicate elements from LIST."
  442. (let ((res (copy-sequence list))) (delete-dups res)))
  443. (defun org-uniquify-alist (alist)
  444. "Merge elements of ALIST with the same key.
  445. For example, in this alist:
  446. \(org-uniquify-alist \\='((a 1) (b 2) (a 3)))
  447. => \\='((a 1 3) (b 2))
  448. merge (a 1) and (a 3) into (a 1 3).
  449. The function returns the new ALIST."
  450. (let (rtn)
  451. (dolist (e alist rtn)
  452. (let (n)
  453. (if (not (assoc (car e) rtn))
  454. (push e rtn)
  455. (setq n (cons (car e) (append (cdr (assoc (car e) rtn)) (cdr e))))
  456. (setq rtn (assq-delete-all (car e) rtn))
  457. (push n rtn))))))
  458. (defun org-delete-all (elts list)
  459. "Remove all elements in ELTS from LIST.
  460. Comparison is done with `equal'. It is a destructive operation
  461. that may remove elements by altering the list structure."
  462. (while elts
  463. (setq list (delete (pop elts) list)))
  464. list)
  465. (defun org-plist-delete (plist property)
  466. "Delete PROPERTY from PLIST.
  467. This is in contrast to merely setting it to 0."
  468. (let (p)
  469. (while plist
  470. (if (not (eq property (car plist)))
  471. (setq p (plist-put p (car plist) (nth 1 plist))))
  472. (setq plist (cddr plist)))
  473. p))
  474. (defun org-combine-plists (&rest plists)
  475. "Create a single property list from all plists in PLISTS.
  476. The process starts by copying the first list, and then setting properties
  477. from the other lists. Settings in the last list are the most significant
  478. ones and overrule settings in the other lists."
  479. (let ((rtn (copy-sequence (pop plists)))
  480. p v ls)
  481. (while plists
  482. (setq ls (pop plists))
  483. (while ls
  484. (setq p (pop ls) v (pop ls))
  485. (setq rtn (plist-put rtn p v))))
  486. rtn))
  487. ;;; Local variables
  488. (defconst org-unique-local-variables
  489. '(org-element--cache
  490. org-element--cache-objects
  491. org-element--cache-sync-keys
  492. org-element--cache-sync-requests
  493. org-element--cache-sync-timer)
  494. "List of local variables that cannot be transferred to another buffer.")
  495. (defun org-get-local-variables ()
  496. "Return a list of all local variables in an Org mode buffer."
  497. (delq nil
  498. (mapcar
  499. (lambda (x)
  500. (let* ((binding (if (symbolp x) (list x) (list (car x) (cdr x))))
  501. (name (car binding)))
  502. (and (not (get name 'org-state))
  503. (not (memq name org-unique-local-variables))
  504. (string-match-p
  505. "\\`\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|\
  506. auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)"
  507. (symbol-name name))
  508. binding)))
  509. (with-temp-buffer
  510. (org-mode)
  511. (buffer-local-variables)))))
  512. (defun org-clone-local-variables (from-buffer &optional regexp)
  513. "Clone local variables from FROM-BUFFER.
  514. Optional argument REGEXP selects variables to clone."
  515. (dolist (pair (buffer-local-variables from-buffer))
  516. (pcase pair
  517. (`(,name . ,value) ;ignore unbound variables
  518. (when (and (not (memq name org-unique-local-variables))
  519. (or (null regexp) (string-match-p regexp (symbol-name name))))
  520. (ignore-errors (set (make-local-variable name) value)))))))
  521. ;;; Logic
  522. (defsubst org-xor (a b)
  523. "Exclusive `or'."
  524. (if a (not b) b))
  525. ;;; Miscellaneous
  526. (defsubst org-call-with-arg (command arg)
  527. "Call COMMAND interactively, but pretend prefix arg was ARG."
  528. (let ((current-prefix-arg arg)) (call-interactively command)))
  529. (defsubst org-check-external-command (cmd &optional use no-error)
  530. "Check if external program CMD for USE exists, error if not.
  531. When the program does exist, return its path.
  532. When it does not exist and NO-ERROR is set, return nil.
  533. Otherwise, throw an error. The optional argument USE can describe what this
  534. program is needed for, so that the error message can be more informative."
  535. (or (executable-find cmd)
  536. (if no-error
  537. nil
  538. (error "Can't find `%s'%s" cmd
  539. (if use (format " (%s)" use) "")))))
  540. (defun org-display-warning (message)
  541. "Display the given MESSAGE as a warning."
  542. (display-warning 'org message :warning))
  543. (defun org-unlogged-message (&rest args)
  544. "Display a message, but avoid logging it in the *Messages* buffer."
  545. (let ((message-log-max nil))
  546. (apply #'message args)))
  547. (defun org-let (list &rest body)
  548. (eval (cons 'let (cons list body))))
  549. (put 'org-let 'lisp-indent-function 1)
  550. (defun org-let2 (list1 list2 &rest body)
  551. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  552. (put 'org-let2 'lisp-indent-function 2)
  553. (defun org-eval (form)
  554. "Eval FORM and return result."
  555. (condition-case error
  556. (eval form)
  557. (error (format "%%![Error: %s]" error))))
  558. (defvar org-outline-regexp) ; defined in org.el
  559. (defvar org-odd-levels-only) ; defined in org.el
  560. (defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
  561. (defun org-get-limited-outline-regexp ()
  562. "Return outline-regexp with limited number of levels.
  563. The number of levels is controlled by `org-inlinetask-min-level'"
  564. (cond ((not (derived-mode-p 'org-mode))
  565. outline-regexp)
  566. ((not (featurep 'org-inlinetask))
  567. org-outline-regexp)
  568. (t
  569. (let* ((limit-level (1- org-inlinetask-min-level))
  570. (nstars (if org-odd-levels-only
  571. (1- (* limit-level 2))
  572. limit-level)))
  573. (format "\\*\\{1,%d\\} " nstars)))))
  574. ;;; Motion
  575. (defsubst org-goto-line (N)
  576. (save-restriction
  577. (widen)
  578. (goto-char (point-min))
  579. (forward-line (1- N))))
  580. (defsubst org-current-line (&optional pos)
  581. (save-excursion
  582. (and pos (goto-char pos))
  583. ;; works also in narrowed buffer, because we start at 1, not point-min
  584. (+ (if (bolp) 1 0) (count-lines 1 (point)))))
  585. ;;; Overlays
  586. (defun org-overlay-display (ovl text &optional face evap)
  587. "Make overlay OVL display TEXT with face FACE."
  588. (overlay-put ovl 'display text)
  589. (when face (overlay-put ovl 'face face))
  590. (when evap (overlay-put ovl 'evaporate t)))
  591. (defun org-overlay-before-string (ovl text &optional face evap)
  592. "Make overlay OVL display TEXT with face FACE."
  593. (when face (org-add-props text nil 'face face))
  594. (overlay-put ovl 'before-string text)
  595. (when evap (overlay-put ovl 'evaporate t)))
  596. (defun org-find-overlays (prop &optional pos delete)
  597. "Find all overlays specifying PROP at POS or point.
  598. If DELETE is non-nil, delete all those overlays."
  599. (let (found)
  600. (dolist (ov (overlays-at (or pos (point))) found)
  601. (cond ((not (overlay-get ov prop)))
  602. (delete (delete-overlay ov))
  603. (t (push ov found))))))
  604. (defun org-flag-region (from to flag spec)
  605. "Hide or show lines from FROM to TO, according to FLAG.
  606. SPEC is the invisibility spec, as a symbol."
  607. (remove-overlays from to 'invisible spec)
  608. ;; Use `front-advance' since text right before to the beginning of
  609. ;; the overlay belongs to the visible line than to the contents.
  610. (when flag
  611. (let ((o (make-overlay from to nil 'front-advance)))
  612. (overlay-put o 'evaporate t)
  613. (overlay-put o 'invisible spec)
  614. (overlay-put o 'isearch-open-invisible #'delete-overlay))))
  615. ;;; Regexp matching
  616. (defsubst org-pos-in-match-range (pos n)
  617. (and (match-beginning n)
  618. (<= (match-beginning n) pos)
  619. (>= (match-end n) pos)))
  620. (defun org-skip-whitespace ()
  621. "Skip over space, tabs and newline characters."
  622. (skip-chars-forward " \t\n\r"))
  623. (defun org-match-line (regexp)
  624. "Match REGEXP at the beginning of the current line."
  625. (save-excursion
  626. (beginning-of-line)
  627. (looking-at regexp)))
  628. (defun org-match-any-p (re list)
  629. "Non-nil if regexp RE matches an element in LIST."
  630. (cl-some (lambda (x) (string-match-p re x)) list))
  631. (defun org-in-regexp (regexp &optional nlines visually)
  632. "Check if point is inside a match of REGEXP.
  633. Normally only the current line is checked, but you can include
  634. NLINES extra lines around point into the search. If VISUALLY is
  635. set, require that the cursor is not after the match but really
  636. on, so that the block visually is on the match.
  637. Return nil or a cons cell (BEG . END) where BEG and END are,
  638. respectively, the positions at the beginning and the end of the
  639. match."
  640. (catch :exit
  641. (let ((pos (point))
  642. (eol (line-end-position (if nlines (1+ nlines) 1))))
  643. (save-excursion
  644. (beginning-of-line (- 1 (or nlines 0)))
  645. (while (and (re-search-forward regexp eol t)
  646. (<= (match-beginning 0) pos))
  647. (let ((end (match-end 0)))
  648. (when (or (> end pos) (and (= end pos) (not visually)))
  649. (throw :exit (cons (match-beginning 0) (match-end 0))))))))))
  650. (defun org-point-in-group (point group &optional context)
  651. "Check if POINT is in match-group GROUP.
  652. If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
  653. match. If the match group does not exist or point is not inside it,
  654. return nil."
  655. (and (match-beginning group)
  656. (>= point (match-beginning group))
  657. (<= point (match-end group))
  658. (if context
  659. (list context (match-beginning group) (match-end group))
  660. t)))
  661. ;;; String manipulation
  662. (defun org-string< (a b)
  663. (org-string-collate-lessp a b))
  664. (defun org-string<= (a b)
  665. (or (string= a b) (org-string-collate-lessp a b)))
  666. (defun org-string>= (a b)
  667. (not (org-string-collate-lessp a b)))
  668. (defun org-string> (a b)
  669. (and (not (string= a b))
  670. (not (org-string-collate-lessp a b))))
  671. (defun org-string<> (a b)
  672. (not (string= a b)))
  673. (defsubst org-trim (s &optional keep-lead)
  674. "Remove whitespace at the beginning and the end of string S.
  675. When optional argument KEEP-LEAD is non-nil, removing blank lines
  676. at the beginning of the string does not affect leading indentation."
  677. (replace-regexp-in-string
  678. (if keep-lead "\\`\\([ \t]*\n\\)+" "\\`[ \t\n\r]+") ""
  679. (replace-regexp-in-string "[ \t\n\r]+\\'" "" s)))
  680. (defun org-string-nw-p (s)
  681. "Return S if S is a string containing a non-blank character.
  682. Otherwise, return nil."
  683. (and (stringp s)
  684. (string-match-p "[^ \r\t\n]" s)
  685. s))
  686. (defun org-reverse-string (string)
  687. "Return the reverse of STRING."
  688. (apply #'string (nreverse (string-to-list string))))
  689. (defun org-split-string (string &optional separators)
  690. "Splits STRING into substrings at SEPARATORS.
  691. SEPARATORS is a regular expression. When nil, it defaults to
  692. \"[ \f\t\n\r\v]+\".
  693. Unlike `split-string', matching SEPARATORS at the beginning and
  694. end of string are ignored."
  695. (let ((separators (or separators "[ \f\t\n\r\v]+")))
  696. (if (not (string-match separators string)) (list string)
  697. (let ((i (match-end 0))
  698. (results
  699. (and (/= 0 (match-beginning 0)) ;skip leading separator
  700. (list (substring string 0 (match-beginning 0))))))
  701. (while (string-match separators string i)
  702. (push (substring string i (match-beginning 0))
  703. results)
  704. (setq i (match-end 0)))
  705. (nreverse (if (= i (length string))
  706. results ;skip trailing separator
  707. (cons (substring string i) results)))))))
  708. (defun org--string-from-props (s property beg end)
  709. "Return the visible part of string S.
  710. Visible part is determined according to text PROPERTY, which is
  711. either `invisible' or `display'. BEG and END are 0-indices
  712. delimiting S."
  713. (let ((width 0)
  714. (cursor beg))
  715. (while (setq beg (text-property-not-all beg end property nil s))
  716. (let* ((next (next-single-property-change beg property s end))
  717. (props (text-properties-at beg s))
  718. (spec (plist-get props property))
  719. (value
  720. (pcase property
  721. (`invisible
  722. ;; If `invisible' property in PROPS means text is to
  723. ;; be invisible, return 0. Otherwise return nil so
  724. ;; as to resume search.
  725. (and (or (eq t buffer-invisibility-spec)
  726. (assoc-string spec buffer-invisibility-spec))
  727. 0))
  728. (`display
  729. (pcase spec
  730. (`nil nil)
  731. (`(space . ,props)
  732. (let ((width (plist-get props :width)))
  733. (and (wholenump width) width)))
  734. (`(image . ,_)
  735. (ceiling (car (image-size spec))))
  736. ((pred stringp)
  737. ;; Displayed string could contain invisible parts,
  738. ;; but no nested display.
  739. (org--string-from-props spec 'invisible 0 (length spec)))
  740. (_
  741. ;; Un-handled `display' value. Ignore it.
  742. ;; Consider the original string instead.
  743. nil)))
  744. (_ (error "Unknown property: %S" property)))))
  745. (when value
  746. (cl-incf width
  747. ;; When looking for `display' parts, we still need
  748. ;; to look for `invisible' property elsewhere.
  749. (+ (cond ((eq property 'display)
  750. (org--string-from-props s 'invisible cursor beg))
  751. ((= cursor beg) 0)
  752. (t (string-width (substring s cursor beg))))
  753. value))
  754. (setq cursor next))
  755. (setq beg next)))
  756. (+ width
  757. ;; Look for `invisible' property in the last part of the
  758. ;; string. See above.
  759. (cond ((eq property 'display)
  760. (org--string-from-props s 'invisible cursor end))
  761. ((= cursor end) 0)
  762. (t (string-width (substring s cursor end)))))))
  763. (defun org-string-width (string)
  764. "Return width of STRING when displayed in the current buffer.
  765. Unlike `string-width', this function takes into consideration
  766. `invisible' and `display' text properties. It supports the
  767. latter in a limited way, mostly for combinations used in Org.
  768. Results may be off sometimes if it cannot handle a given
  769. `display' value."
  770. (org--string-from-props string 'display 0 (length string)))
  771. (defun org-not-nil (v)
  772. "If V not nil, and also not the string \"nil\", then return V.
  773. Otherwise return nil."
  774. (and v (not (equal v "nil")) v))
  775. (defun org-unbracket-string (pre post string)
  776. "Remove PRE/POST from the beginning/end of STRING.
  777. Both PRE and POST must be pre-/suffixes of STRING, or neither is
  778. removed. Return the new string. If STRING is nil, return nil."
  779. (declare (indent 2))
  780. (and string
  781. (if (and (string-prefix-p pre string)
  782. (string-suffix-p post string))
  783. (substring string (length pre) (- (length post)))
  784. string)))
  785. (defun org-strip-quotes (string)
  786. "Strip double quotes from around STRING, if applicable.
  787. If STRING is nil, return nil."
  788. (org-unbracket-string "\"" "\"" string))
  789. (defsubst org-current-line-string (&optional to-here)
  790. "Return current line, as a string.
  791. If optional argument TO-HERE is non-nil, return string from
  792. beginning of line up to point."
  793. (buffer-substring (line-beginning-position)
  794. (if to-here (point) (line-end-position))))
  795. (defun org-shorten-string (s maxlength)
  796. "Shorten string S so that it is no longer than MAXLENGTH characters.
  797. If the string is shorter or has length MAXLENGTH, just return the
  798. original string. If it is longer, the functions finds a space in the
  799. string, breaks this string off at that locations and adds three dots
  800. as ellipsis. Including the ellipsis, the string will not be longer
  801. than MAXLENGTH. If finding a good breaking point in the string does
  802. not work, the string is just chopped off in the middle of a word
  803. if necessary."
  804. (if (<= (length s) maxlength)
  805. s
  806. (let* ((n (max (- maxlength 4) 1))
  807. (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
  808. (if (string-match re s)
  809. (concat (match-string 1 s) "...")
  810. (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
  811. (defun org-remove-tabs (s &optional width)
  812. "Replace tabulators in S with spaces.
  813. Assumes that s is a single line, starting in column 0."
  814. (setq width (or width tab-width))
  815. (while (string-match "\t" s)
  816. (setq s (replace-match
  817. (make-string
  818. (- (* width (/ (+ (match-beginning 0) width) width))
  819. (match-beginning 0)) ?\ )
  820. t t s)))
  821. s)
  822. (defun org-wrap (string &optional width lines)
  823. "Wrap string to either a number of lines, or a width in characters.
  824. If WIDTH is non-nil, the string is wrapped to that width, however many lines
  825. that costs. If there is a word longer than WIDTH, the text is actually
  826. wrapped to the length of that word.
  827. IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
  828. many lines, whatever width that takes.
  829. The return value is a list of lines, without newlines at the end."
  830. (let* ((words (split-string string))
  831. (maxword (apply 'max (mapcar 'org-string-width words)))
  832. w ll)
  833. (cond (width
  834. (org--do-wrap words (max maxword width)))
  835. (lines
  836. (setq w maxword)
  837. (setq ll (org--do-wrap words maxword))
  838. (if (<= (length ll) lines)
  839. ll
  840. (setq ll words)
  841. (while (> (length ll) lines)
  842. (setq w (1+ w))
  843. (setq ll (org--do-wrap words w)))
  844. ll))
  845. (t (error "Cannot wrap this")))))
  846. (defun org--do-wrap (words width)
  847. "Create lines of maximum width WIDTH (in characters) from word list WORDS."
  848. (let (lines line)
  849. (while words
  850. (setq line (pop words))
  851. (while (and words (< (+ (length line) (length (car words))) width))
  852. (setq line (concat line " " (pop words))))
  853. (setq lines (push line lines)))
  854. (nreverse lines)))
  855. (defun org-remove-indentation (code &optional n)
  856. "Remove maximum common indentation in string CODE and return it.
  857. N may optionally be the number of columns to remove. Return CODE
  858. as-is if removal failed."
  859. (with-temp-buffer
  860. (insert code)
  861. (if (org-do-remove-indentation n) (buffer-string) code)))
  862. ;;; Text properties
  863. (defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
  864. rear-nonsticky t mouse-map t fontified t
  865. org-emphasis t)
  866. "Properties to remove when a string without properties is wanted.")
  867. (defsubst org-no-properties (s &optional restricted)
  868. "Remove all text properties from string S.
  869. When RESTRICTED is non-nil, only remove the properties listed
  870. in `org-rm-props'."
  871. (if restricted (remove-text-properties 0 (length s) org-rm-props s)
  872. (set-text-properties 0 (length s) nil s))
  873. s)
  874. (defun org-add-props (string plist &rest props)
  875. "Add text properties to entire string, from beginning to end.
  876. PLIST may be a list of properties, PROPS are individual properties and values
  877. that will be added to PLIST. Returns the string that was modified."
  878. (declare (indent 2))
  879. (add-text-properties
  880. 0 (length string) (if props (append plist props) plist) string)
  881. string)
  882. (defun org-make-parameter-alist (flat)
  883. "Return alist based on FLAT.
  884. FLAT is a list with alternating symbol names and values. The
  885. returned alist is a list of lists with the symbol name in car and
  886. the value in cdr."
  887. (when flat
  888. (cons (list (car flat) (cadr flat))
  889. (org-make-parameter-alist (cddr flat)))))
  890. (defsubst org-get-at-bol (property)
  891. "Get text property PROPERTY at the beginning of line."
  892. (get-text-property (point-at-bol) property))
  893. (defun org-get-at-eol (property n)
  894. "Get text property PROPERTY at the end of line less N characters."
  895. (get-text-property (- (point-at-eol) n) property))
  896. (defun org-find-text-property-in-string (prop s)
  897. "Return the first non-nil value of property PROP in string S."
  898. (or (get-text-property 0 prop s)
  899. (get-text-property (or (next-single-property-change 0 prop s) 0)
  900. prop s)))
  901. (defun org-invisible-p (&optional pos)
  902. "Non-nil if the character after POS is invisible.
  903. If POS is nil, use `point' instead."
  904. (get-char-property (or pos (point)) 'invisible))
  905. (defun org-truely-invisible-p ()
  906. "Check if point is at a character currently not visible.
  907. This version does not only check the character property, but also
  908. `visible-mode'."
  909. (unless (bound-and-true-p visible-mode)
  910. (org-invisible-p)))
  911. (defun org-invisible-p2 ()
  912. "Check if point is at a character currently not visible.
  913. If the point is at EOL (and not at the beginning of a buffer too),
  914. move it back by one char before doing this check."
  915. (save-excursion
  916. (when (and (eolp) (not (bobp)))
  917. (backward-char 1))
  918. (org-invisible-p)))
  919. ;;; Time
  920. (defun org-2ft (s)
  921. "Convert S to a floating point time.
  922. If S is already a number, just return it. If it is a string,
  923. parse it as a time string and apply `float-time' to it. If S is
  924. nil, just return 0."
  925. (cond
  926. ((numberp s) s)
  927. ((stringp s)
  928. (condition-case nil
  929. (float-time (apply #'encode-time (org-parse-time-string s)))
  930. (error 0.)))
  931. (t 0.)))
  932. (defun org-time= (a b)
  933. (let ((a (org-2ft a))
  934. (b (org-2ft b)))
  935. (and (> a 0) (> b 0) (= a b))))
  936. (defun org-time< (a b)
  937. (let ((a (org-2ft a))
  938. (b (org-2ft b)))
  939. (and (> a 0) (> b 0) (< a b))))
  940. (defun org-time<= (a b)
  941. (let ((a (org-2ft a))
  942. (b (org-2ft b)))
  943. (and (> a 0) (> b 0) (<= a b))))
  944. (defun org-time> (a b)
  945. (let ((a (org-2ft a))
  946. (b (org-2ft b)))
  947. (and (> a 0) (> b 0) (> a b))))
  948. (defun org-time>= (a b)
  949. (let ((a (org-2ft a))
  950. (b (org-2ft b)))
  951. (and (> a 0) (> b 0) (>= a b))))
  952. (defun org-time<> (a b)
  953. (let ((a (org-2ft a))
  954. (b (org-2ft b)))
  955. (and (> a 0) (> b 0) (\= a b))))
  956. (defun org-parse-time-string (s &optional nodefault)
  957. "Parse Org time string S.
  958. If time is not given, defaults to 0:00. However, with optional
  959. NODEFAULT, hour and minute fields are nil if not given.
  960. Throw an error if S does not contain a valid Org time string.
  961. Note that the first match for YYYY-MM-DD will be used (e.g.,
  962. \"-52000-02-03\" will be taken as \"2000-02-03\").
  963. This should be a lot faster than the `parse-time-string'."
  964. (unless (string-match org-ts-regexp0 s)
  965. (error "Not an Org time string: %s" s))
  966. (list 0
  967. (cond ((match-beginning 8) (string-to-number (match-string 8 s)))
  968. (nodefault nil)
  969. (t 0))
  970. (cond ((match-beginning 7) (string-to-number (match-string 7 s)))
  971. (nodefault nil)
  972. (t 0))
  973. (string-to-number (match-string 4 s))
  974. (string-to-number (match-string 3 s))
  975. (string-to-number (match-string 2 s))
  976. nil nil nil))
  977. (defun org-matcher-time (s)
  978. "Interpret a time comparison value S as a floating point time.
  979. S can be an Org time stamp, a modifier, e.g., \"<+2d>\", or the
  980. following special strings: \"<now>\", \"<today>\",
  981. \"<tomorrow>\", and \"<yesterday>\".
  982. Return 0. if S is not recognized as a valid value."
  983. (let ((today (float-time (apply #'encode-time
  984. (append '(0 0 0) (nthcdr 3 (decode-time)))))))
  985. (save-match-data
  986. (cond
  987. ((string= s "<now>") (float-time))
  988. ((string= s "<today>") today)
  989. ((string= s "<tomorrow>") (+ 86400.0 today))
  990. ((string= s "<yesterday>") (- today 86400.0))
  991. ((string-match "\\`<\\([-+][0-9]+\\)\\([hdwmy]\\)>\\'" s)
  992. (+ today
  993. (* (string-to-number (match-string 1 s))
  994. (cdr (assoc (match-string 2 s)
  995. '(("d" . 86400.0) ("w" . 604800.0)
  996. ("m" . 2678400.0) ("y" . 31557600.0)))))))
  997. ((string-match org-ts-regexp0 s) (org-2ft s))
  998. (t 0.)))))
  999. (provide 'org-macs)
  1000. ;;; org-macs.el ends here