1 ;;; org-macs.el --- Top-level Definitions for Org -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2004-2017 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file contains macro definitions, defsubst definitions, other
28 ;; stuff needed for compilation and top-level forms in Org mode, as
29 ;; well lots of small functions that are not Org mode specific but
30 ;; simply generally useful stuff.
34 (declare-function org-defkey
"org" (keymap key def
))
40 (defmacro org-with-gensyms
(symbols &rest body
)
41 (declare (debug (sexp body
)) (indent 1))
42 `(let ,(mapcar (lambda (s)
43 `(,s
(make-symbol (concat "--" (symbol-name ',s
)))))
47 (defmacro org-preserve-lc
(&rest body
)
48 (declare (debug (body)))
49 (org-with-gensyms (line col
)
50 `(let ((,line
(org-current-line))
51 (,col
(current-column)))
55 (org-move-to-column ,col
)))))
57 ;; Use `org-with-silent-modifications' to ignore cosmetic changes and
58 ;; `org-unmodified' to ignore real text modifications
59 (defmacro org-unmodified
(&rest body
)
60 "Run BODY while preserving the buffer's `buffer-modified-p' state."
61 (declare (debug (body)))
62 (org-with-gensyms (was-modified)
63 `(let ((,was-modified
(buffer-modified-p)))
65 (let ((buffer-undo-list t
)
66 (inhibit-modification-hooks t
))
68 (set-buffer-modified-p ,was-modified
)))))
70 (defmacro org-without-partial-completion
(&rest body
)
71 (declare (debug (body)))
72 `(if (and (boundp 'partial-completion-mode
)
73 partial-completion-mode
74 (fboundp 'partial-completion-mode
))
77 (partial-completion-mode -
1)
79 (partial-completion-mode 1))
82 (defmacro org-with-point-at
(pom &rest body
)
83 "Move to buffer and point of point-or-marker POM for the duration of BODY."
84 (declare (debug (form body
)) (indent 1))
85 (org-with-gensyms (mpom)
88 (if (markerp ,mpom
) (set-buffer (marker-buffer ,mpom
)))
90 (goto-char (or ,mpom
(point)))
93 (defmacro org-with-remote-undo
(buffer &rest body
)
94 "Execute BODY while recording undo information in two buffers."
95 (declare (debug (form body
)) (indent 1))
96 (org-with-gensyms (cline cmd buf1 buf2 undo1 undo2 c1 c2
)
97 `(let ((,cline
(org-current-line))
99 (,buf1
(current-buffer))
101 (,undo1 buffer-undo-list
)
102 (,undo2
(with-current-buffer ,buffer buffer-undo-list
))
105 (when org-agenda-allow-remote-undo
106 (setq ,c1
(org-verify-change-for-undo
107 ,undo1
(with-current-buffer ,buf1 buffer-undo-list
))
108 ,c2
(org-verify-change-for-undo
109 ,undo2
(with-current-buffer ,buf2 buffer-undo-list
)))
111 ;; make sure there are undo boundaries
112 (and ,c1
(with-current-buffer ,buf1
(undo-boundary)))
113 (and ,c2
(with-current-buffer ,buf2
(undo-boundary)))
114 ;; remember which buffer to undo
115 (push (list ,cmd
,cline
,buf1
,c1
,buf2
,c2
)
116 org-agenda-undo-list
))))))
118 (defmacro org-no-read-only
(&rest body
)
119 "Inhibit read-only for BODY."
120 (declare (debug (body)))
121 `(let ((inhibit-read-only t
)) ,@body
))
123 (defmacro org-save-outline-visibility
(use-markers &rest body
)
124 "Save and restore outline visibility around BODY.
125 If USE-MARKERS is non-nil, use markers for the positions.
126 This means that the buffer may change while running BODY,
127 but it also means that the buffer should stay alive
128 during the operation, because otherwise all these markers will
130 (declare (debug (form body
)) (indent 1))
131 (org-with-gensyms (data)
132 `(let ((,data
(org-outline-overlay-data ,use-markers
)))
134 (prog1 (progn ,@body
)
135 (org-set-outline-overlay-data ,data
))
138 (when (markerp (car c
)) (move-marker (car c
) nil
))
139 (when (markerp (cdr c
)) (move-marker (cdr c
) nil
))))))))
141 (defmacro org-with-wide-buffer
(&rest body
)
142 "Execute body while temporarily widening the buffer."
143 (declare (debug (body)))
149 (defmacro org-with-limited-levels
(&rest body
)
150 "Execute BODY with limited number of outline levels."
151 (declare (debug (body)))
153 (defvar org-called-with-limited-levels
)
154 (defvar org-outline-regexp
)
155 (defvar outline-regexp
)
156 (defvar org-outline-regexp-bol
)
157 (let* ((org-called-with-limited-levels t
)
158 (org-outline-regexp (org-get-limited-outline-regexp))
159 (outline-regexp org-outline-regexp
)
160 (org-outline-regexp-bol (concat "^" org-outline-regexp
)))
163 (defmacro org-eval-in-environment
(environment form
)
164 (declare (debug (form form
)) (indent 1))
165 `(eval (list 'let
,environment
',form
)))
168 (defmacro org-load-noerror-mustsuffix
(file)
169 "Load FILE with optional arguments NOERROR and MUSTSUFFIX."
170 `(load ,file
'noerror nil nil
'mustsuffix
))
172 (defmacro org-preserve-local-variables
(&rest body
)
173 "Execute BODY while preserving local variables."
174 (declare (debug (body)))
175 `(let ((local-variables
176 (org-with-wide-buffer
177 (goto-char (point-max))
178 (let ((case-fold-search t
))
179 (and (re-search-backward "^[ \t]*# +Local Variables:"
180 (max (- (point) 3000) 1)
182 (delete-and-extract-region (point) (point-max)))))))
183 (unwind-protect (progn ,@body
)
184 (when local-variables
185 (org-with-wide-buffer
186 (goto-char (point-max))
187 (unless (bolp) (insert "\n"))
188 (insert local-variables
))))))
194 (defun org-base-buffer (buffer)
195 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
198 (or (buffer-base-buffer buffer
)
201 (defun org-find-base-buffer-visiting (file)
202 "Like `find-buffer-visiting' but always return the base buffer and
203 not an indirect buffer."
204 (let ((buf (or (get-file-buffer file
)
205 (find-buffer-visiting file
))))
207 (or (buffer-base-buffer buf
) buf
)
214 (defun org-read-function (prompt &optional allow-empty?
)
215 "Prompt for a function.
216 If ALLOW-EMPTY? is non-nil, return nil rather than raising an
217 error when the user input is empty."
218 (let ((func (completing-read prompt obarray
#'fboundp t
)))
219 (cond ((not (string= func
""))
222 (t (user-error "Empty input is not valid")))))
224 (defun org-completing-read (&rest args
)
225 "Completing-read with SPACE being a normal character."
226 (let ((enable-recursive-minibuffers t
)
227 (minibuffer-local-completion-map
228 (copy-keymap minibuffer-local-completion-map
)))
229 (org-defkey minibuffer-local-completion-map
" " 'self-insert-command
)
230 (org-defkey minibuffer-local-completion-map
"?" 'self-insert-command
)
231 (org-defkey minibuffer-local-completion-map
(kbd "C-c !")
232 'org-time-stamp-inactive
)
233 (apply #'completing-read args
)))
239 (defsubst org-xor
(a b
)
247 (defun org-overlay-display (ovl text
&optional face evap
)
248 "Make overlay OVL display TEXT with face FACE."
249 (overlay-put ovl
'display text
)
250 (if face
(overlay-put ovl
'face face
))
251 (if evap
(overlay-put ovl
'evaporate t
)))
253 (defun org-overlay-before-string (ovl text
&optional face evap
)
254 "Make overlay OVL display TEXT with face FACE."
255 (if face
(org-add-props text nil
'face face
))
256 (overlay-put ovl
'before-string text
)
257 (if evap
(overlay-put ovl
'evaporate t
)))
259 (defun org-find-overlays (prop &optional pos delete
)
260 "Find all overlays specifying PROP at POS or point.
261 If DELETE is non-nil, delete all those overlays."
263 (dolist (ov (overlays-at (or pos
(point))) found
)
264 (cond ((not (overlay-get ov prop
)))
265 (delete (delete-overlay ov
))
266 (t (push ov found
))))))
270 ;;; String manipulation
272 (defsubst org-trim
(s &optional keep-lead
)
273 "Remove whitespace at the beginning and the end of string S.
274 When optional argument KEEP-LEAD is non-nil, removing blank lines
275 at the beginning of the string does not affect leading indentation."
276 (replace-regexp-in-string
277 (if keep-lead
"\\`\\([ \t]*\n\\)+" "\\`[ \t\n\r]+") ""
278 (replace-regexp-in-string "[ \t\n\r]+\\'" "" s
)))
280 (defun org-string-nw-p (s)
281 "Return S if S is a string containing a non-blank character.
282 Otherwise, return nil."
284 (string-match-p "[^ \r\t\n]" s
)
287 (defun org-reverse-string (string)
288 "Return the reverse of STRING."
289 (apply #'string
(nreverse (string-to-list string
))))
291 (defun org-split-string (string &optional separators
)
292 "Splits STRING into substrings at SEPARATORS.
294 SEPARATORS is a regular expression. When nil, it defaults to
297 Unlike `split-string', matching SEPARATORS at the beginning and
298 end of string are ignored."
299 (let ((separators (or separators
"[ \f\t\n\r\v]+")))
300 (when (string-match (concat "\\`" separators
) string
)
301 (setq string
(replace-match "" nil nil string
)))
302 (when (string-match (concat separators
"\\'") string
)
303 (setq string
(replace-match "" nil nil string
)))
304 (split-string string separators
)))
306 (defun org-string-display (string)
307 "Return STRING as it is displayed in the current buffer.
308 This function takes into consideration `invisible' and `display'
310 (let* ((build-from-parts
311 (lambda (s property filter
)
312 ;; Build a new string out of string S. On every group of
313 ;; contiguous characters with the same PROPERTY value,
314 ;; call FILTER on the properties list at the beginning of
315 ;; the group. If it returns a string, replace the
316 ;; characters in the group with it. Otherwise, preserve
318 (let ((len (length s
))
322 (while (setq i
(text-property-not-all i len property nil s
))
323 (let ((end (next-single-property-change i property s len
))
324 (value (funcall filter
(text-properties-at i s
))))
326 (setq new
(concat new
(substring s cursor i
) value
))
329 (concat new
(substring s cursor
)))))
332 (funcall build-from-parts s
'invisible
334 ;; If `invisible' property in PROPS means text
335 ;; is to be invisible, return the empty string.
336 ;; Otherwise return nil so that the part is
338 (and (or (eq t buffer-invisibility-spec
)
339 (assoc-string (plist-get props
'invisible
)
340 buffer-invisibility-spec
))
344 (funcall build-from-parts s
'display
346 ;; If there is any string specification in
347 ;; `display' property return it. Also attach
348 ;; other text properties on the part to that
350 (let* ((display (plist-get props
'display
))
351 (value (if (stringp display
) display
352 (cl-some #'stringp display
))))
355 ;; Displayed string could contain
356 ;; invisible parts, but no nested
358 (funcall prune-invisible value
)
360 (and (not (stringp display
))
361 (cl-remove-if #'stringp display
))
363 ;; `display' property overrides `invisible' one. So we first
364 ;; replace characters with `display' property. Then we remove
365 ;; invisible characters.
366 (funcall prune-invisible
(funcall replace-display string
))))
368 (defun org-string-width (string)
369 "Return width of STRING when displayed in the current buffer.
370 Unlike `string-width', this function takes into consideration
371 `invisible' and `display' text properties."
372 (string-width (org-string-display string
)))
374 (defun org-not-nil (v)
375 "If V not nil, and also not the string \"nil\", then return V.
376 Otherwise return nil."
377 (and v
(not (equal v
"nil")) v
))
379 (defun org-unbracket-string (pre post string
)
380 "Remove PRE/POST from the beginning/end of STRING.
381 Both PRE and POST must be pre-/suffixes of STRING, or neither is
383 (if (and (string-prefix-p pre string
)
384 (string-suffix-p post string
))
385 (substring string
(length pre
) (- (length post
)))
388 (defsubst org-current-line-string
(&optional to-here
)
389 (buffer-substring (point-at-bol) (if to-here
(point) (point-at-eol))))
391 (defun org-shorten-string (s maxlength
)
392 "Shorten string S so that it is no longer than MAXLENGTH characters.
393 If the string is shorter or has length MAXLENGTH, just return the
394 original string. If it is longer, the functions finds a space in the
395 string, breaks this string off at that locations and adds three dots
396 as ellipsis. Including the ellipsis, the string will not be longer
397 than MAXLENGTH. If finding a good breaking point in the string does
398 not work, the string is just chopped off in the middle of a word
400 (if (<= (length s
) maxlength
)
402 (let* ((n (max (- maxlength
4) 1))
403 (re (concat "\\`\\(.\\{1," (int-to-string n
) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
404 (if (string-match re s
)
405 (concat (match-string 1 s
) "...")
406 (concat (substring s
0 (max (- maxlength
3) 0)) "...")))))
408 (defun org-remove-tabs (s &optional width
)
409 "Replace tabulators in S with spaces.
410 Assumes that s is a single line, starting in column 0."
411 (setq width
(or width tab-width
))
412 (while (string-match "\t" s
)
413 (setq s
(replace-match
415 (- (* width
(/ (+ (match-beginning 0) width
) width
))
416 (match-beginning 0)) ?\
)
420 (defun org-wrap (string &optional width lines
)
421 "Wrap string to either a number of lines, or a width in characters.
422 If WIDTH is non-nil, the string is wrapped to that width, however many lines
423 that costs. If there is a word longer than WIDTH, the text is actually
424 wrapped to the length of that word.
425 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
426 many lines, whatever width that takes.
427 The return value is a list of lines, without newlines at the end."
428 (let* ((words (split-string string
))
429 (maxword (apply 'max
(mapcar 'org-string-width words
)))
432 (org--do-wrap words
(max maxword width
)))
435 (setq ll
(org--do-wrap words maxword
))
436 (if (<= (length ll
) lines
)
439 (while (> (length ll
) lines
)
441 (setq ll
(org--do-wrap words w
)))
443 (t (error "Cannot wrap this")))))
445 (defun org--do-wrap (words width
)
446 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
449 (setq line
(pop words
))
450 (while (and words
(< (+ (length line
) (length (car words
))) width
))
451 (setq line
(concat line
" " (pop words
))))
452 (setq lines
(push line lines
)))
455 (defun org-remove-indentation (code &optional n
)
456 "Remove maximum common indentation in string CODE and return it.
457 N may optionally be the number of columns to remove. Return CODE
458 as-is if removal failed."
461 (if (org-do-remove-indentation n
) (buffer-string) code
)))
463 (defun org-do-remove-indentation (&optional n
)
464 "Remove the maximum common indentation from the buffer.
465 When optional argument N is a positive integer, remove exactly
466 that much characters from indentation, if possible. Return nil
469 (goto-char (point-min))
470 ;; Find maximum common indentation, if not specified.
472 (let ((min-ind (point-max)))
474 (while (re-search-forward "^[ \t]*\\S-" nil t
)
475 (let ((ind (1- (current-column))))
476 (if (zerop ind
) (throw :exit nil
)
477 (setq min-ind
(min min-ind ind
))))))
479 (if (zerop n
) (throw :exit nil
)
480 ;; Remove exactly N indentation, but give up if not possible.
482 (let ((ind (progn (skip-chars-forward " \t") (current-column))))
483 (cond ((eolp) (delete-region (line-beginning-position) (point)))
484 ((< ind n
) (throw :exit nil
))
485 (t (indent-line-to (- ind n
))))
492 ;;; List manipulation
494 (defsubst org-get-alist-option
(option key
)
497 ((assoc key option
) (cdr (assoc key option
)))
498 (t (let ((r (cdr (assq 'default option
))))
499 (if (listp r
) (delq nil r
) r
)))))
501 (defsubst org-last
(list)
502 "Return the last element of LIST."
505 (defsubst org-uniquify
(list)
506 "Non-destructively remove duplicate elements from LIST."
507 (let ((res (copy-sequence list
))) (delete-dups res
)))
509 (defun org-uniquify-alist (alist)
510 "Merge elements of ALIST with the same key.
512 For example, in this alist:
514 \(org-uniquify-alist \\='((a 1) (b 2) (a 3)))
515 => \\='((a 1 3) (b 2))
517 merge (a 1) and (a 3) into (a 1 3).
519 The function returns the new ALIST."
521 (dolist (e alist rtn
)
523 (if (not (assoc (car e
) rtn
))
525 (setq n
(cons (car e
) (append (cdr (assoc (car e
) rtn
)) (cdr e
))))
526 (setq rtn
(assq-delete-all (car e
) rtn
))
529 (defun org-delete-all (elts list
)
530 "Remove all elements in ELTS from LIST.
531 Comparison is done with `equal'. It is a destructive operation
532 that may remove elements by altering the list structure."
534 (setq list
(delete (pop elts
) list
)))
537 (defun org-plist-delete (plist property
)
538 "Delete PROPERTY from PLIST.
539 This is in contrast to merely setting it to 0."
542 (if (not (eq property
(car plist
)))
543 (setq p
(plist-put p
(car plist
) (nth 1 plist
))))
544 (setq plist
(cddr plist
)))
547 (defun org-combine-plists (&rest plists
)
548 "Create a single property list from all plists in PLISTS.
549 The process starts by copying the first list, and then setting properties
550 from the other lists. Settings in the last list are the most significant
551 ones and overrule settings in the other lists."
552 (let ((rtn (copy-sequence (pop plists
)))
555 (setq ls
(pop plists
))
557 (setq p
(pop ls
) v
(pop ls
))
558 (setq rtn
(plist-put rtn p v
))))
565 (defsubst org-pos-in-match-range
(pos n
)
566 (and (match-beginning n
)
567 (<= (match-beginning n
) pos
)
568 (>= (match-end n
) pos
)))
570 (defun org-skip-whitespace ()
571 "Skip over space, tabs and newline characters."
572 (skip-chars-forward " \t\n\r"))
574 (defun org-match-line (regexp)
575 "Match REGEXP at the beginning of the current line."
578 (looking-at regexp
)))
580 (defun org-in-regexp (regexp &optional nlines visually
)
581 "Check if point is inside a match of REGEXP.
583 Normally only the current line is checked, but you can include
584 NLINES extra lines around point into the search. If VISUALLY is
585 set, require that the cursor is not after the match but really
586 on, so that the block visually is on the match.
588 Return nil or a cons cell (BEG . END) where BEG and END are,
589 respectively, the positions at the beginning and the end of the
593 (eol (line-end-position (if nlines
(1+ nlines
) 1))))
595 (beginning-of-line (- 1 (or nlines
0)))
596 (while (and (re-search-forward regexp eol t
)
597 (<= (match-beginning 0) pos
))
598 (let ((end (match-end 0)))
599 (when (or (> end pos
) (and (= end pos
) (not visually
)))
600 (throw :exit
(cons (match-beginning 0) (match-end 0))))))))))
602 (defun org-point-in-group (point group
&optional context
)
603 "Check if POINT is in match-group GROUP.
604 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
605 match. If the match group does not exist or point is not inside it,
607 (and (match-beginning group
)
608 (>= point
(match-beginning group
))
609 (<= point
(match-end group
))
611 (list context
(match-beginning group
) (match-end group
))
618 (defsubst org-goto-line
(N)
621 (goto-char (point-min))
622 (forward-line (1- N
))))
624 (defsubst org-current-line
(&optional pos
)
626 (and pos
(goto-char pos
))
627 ;; works also in narrowed buffer, because we start at 1, not point-min
628 (+ (if (bolp) 1 0) (count-lines 1 (point)))))
634 (defconst org-rm-props
'(invisible t face t keymap t intangible t mouse-face t
635 rear-nonsticky t mouse-map t fontified t
637 "Properties to remove when a string without properties is wanted.")
639 (defsubst org-no-properties
(s &optional restricted
)
640 "Remove all text properties from string S.
641 When RESTRICTED is non-nil, only remove the properties listed
643 (if restricted
(remove-text-properties 0 (length s
) org-rm-props s
)
644 (set-text-properties 0 (length s
) nil s
))
646 (defun org-add-props (string plist
&rest props
)
647 "Add text properties to entire string, from beginning to end.
648 PLIST may be a list of properties, PROPS are individual properties and values
649 that will be added to PLIST. Returns the string that was modified."
652 0 (length string
) (if props
(append plist props
) plist
) string
)
655 (defun org-make-parameter-alist (flat)
656 "Return alist based on FLAT.
657 FLAT is a list with alternating symbol names and values. The
658 returned alist is a list of lists with the symbol name in car and
661 (cons (list (car flat
) (cadr flat
))
662 (org-make-parameter-alist (cddr flat
)))))
664 (defsubst org-get-at-bol
(property)
665 "Get text property PROPERTY at the beginning of line."
666 (get-text-property (point-at-bol) property
))
668 (defun org-get-at-eol (property n
)
669 "Get text property PROPERTY at the end of line less N characters."
670 (get-text-property (- (point-at-eol) n
) property
))
672 (defun org-find-text-property-in-string (prop s
)
673 "Return the first non-nil value of property PROP in string S."
674 (or (get-text-property 0 prop s
)
675 (get-text-property (or (next-single-property-change 0 prop s
) 0)
678 (defun org-invisible-p (&optional pos
)
679 "Non-nil if the character after POS is invisible.
680 If POS is nil, use `point' instead."
681 (get-char-property (or pos
(point)) 'invisible
))
683 (defun org-truely-invisible-p ()
684 "Check if point is at a character currently not visible.
685 This version does not only check the character property, but also
687 (unless (bound-and-true-p visible-mode
)
690 (defun org-invisible-p2 ()
691 "Check if point is at a character currently not visible.
692 If the point is at EOL (and not at the beginning of a buffer too),
693 move it back by one char before doing this check."
695 (when (and (eolp) (not (bobp)))
703 (defconst org-unique-local-variables
705 org-element--cache-objects
706 org-element--cache-sync-keys
707 org-element--cache-sync-requests
708 org-element--cache-sync-timer
)
709 "List of local variables that cannot be transferred to another buffer.")
711 (defun org-get-local-variables ()
712 "Return a list of all local variables in an Org mode buffer."
716 (let* ((binding (if (symbolp x
) (list x
) (list (car x
) (cdr x
))))
717 (name (car binding
)))
718 (and (not (get name
'org-state
))
719 (not (memq name org-unique-local-variables
))
721 "\\`\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|\
722 auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)"
727 (buffer-local-variables)))))
729 (defun org-clone-local-variables (from-buffer &optional regexp
)
730 "Clone local variables from FROM-BUFFER.
731 Optional argument REGEXP selects variables to clone."
732 (dolist (pair (buffer-local-variables from-buffer
))
734 (`(,name .
,value
) ;ignore unbound variables
735 (when (and (not (memq name org-unique-local-variables
))
736 (or (null regexp
) (string-match-p regexp
(symbol-name name
))))
737 (ignore-errors (set (make-local-variable name
) value
)))))))
743 (defsubst org-call-with-arg
(command arg
)
744 "Call COMMAND interactively, but pretend prefix arg was ARG."
745 (let ((current-prefix-arg arg
)) (call-interactively command
)))
747 (defsubst org-check-external-command
(cmd &optional use no-error
)
748 "Check if external program CMD for USE exists, error if not.
749 When the program does exist, return its path.
750 When it does not exist and NO-ERROR is set, return nil.
751 Otherwise, throw an error. The optional argument USE can describe what this
752 program is needed for, so that the error message can be more informative."
753 (or (executable-find cmd
)
756 (error "Can't find `%s'%s" cmd
757 (if use
(format " (%s)" use
) "")))))
759 (defun org-display-warning (message)
760 "Display the given MESSAGE as a warning."
761 (display-warning 'org message
:warning
))
763 (defun org-unlogged-message (&rest args
)
764 "Display a message, but avoid logging it in the *Messages* buffer."
765 (let ((message-log-max nil
))
766 (apply #'message args
)))
768 (defun org-let (list &rest body
)
769 (eval (cons 'let
(cons list body
))))
770 (put 'org-let
'lisp-indent-function
1)
772 (defun org-let2 (list1 list2
&rest body
)
773 (eval (cons 'let
(cons list1
(list (cons 'let
(cons list2 body
)))))))
774 (put 'org-let2
'lisp-indent-function
2)
776 (defun org-eval (form)
777 "Eval FORM and return result."
778 (condition-case error
780 (error (format "%%![Error: %s]" error
))))
782 (defvar org-outline-regexp
) ; defined in org.el
783 (defvar org-odd-levels-only
) ; defined in org.el
784 (defvar org-inlinetask-min-level
) ; defined in org-inlinetask.el
785 (defun org-get-limited-outline-regexp ()
786 "Return outline-regexp with limited number of levels.
787 The number of levels is controlled by `org-inlinetask-min-level'"
788 (cond ((not (derived-mode-p 'org-mode
))
790 ((not (featurep 'org-inlinetask
))
793 (let* ((limit-level (1- org-inlinetask-min-level
))
794 (nstars (if org-odd-levels-only
795 (1- (* limit-level
2))
797 (format "\\*\\{1,%d\\} " nstars
)))))
802 ;;; org-macs.el ends here