2016-06-21 16:56:46 -04:00
|
|
|
;;; org-macs.el --- Top-level Definitions for Org -*- lexical-binding: t; -*-
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2018-01-07 00:27:54 -05:00
|
|
|
;; Copyright (C) 2004-2018 Free Software Foundation, Inc.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
2018-01-16 11:22:00 -05:00
|
|
|
;; Homepage: https://orgmode.org
|
2008-03-22 11:52:18 -04:00
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 08:45:52 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-03-22 11:52:18 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:45:52 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 18:52:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2008-03-22 11:52:18 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-04-04 17:44:48 -04:00
|
|
|
;; This file contains macro definitions, defsubst definitions, other
|
2016-06-21 16:56:46 -04:00
|
|
|
;; stuff needed for compilation and top-level forms in Org mode, as
|
|
|
|
;; well lots of small functions that are not Org mode specific but
|
|
|
|
;; simply generally useful stuff.
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2011-08-10 01:28:41 -04:00
|
|
|
(defmacro org-with-gensyms (symbols &rest body)
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (sexp body)) (indent 1))
|
2011-08-10 01:28:41 -04:00
|
|
|
`(let ,(mapcar (lambda (s)
|
2015-05-04 11:32:43 -04:00
|
|
|
`(,s (make-symbol (concat "--" (symbol-name ',s)))))
|
|
|
|
symbols)
|
2011-08-10 01:28:41 -04:00
|
|
|
,@body))
|
|
|
|
|
2010-07-20 01:54:11 -04:00
|
|
|
(defun org-string-nw-p (s)
|
2015-02-26 09:14:40 -05:00
|
|
|
"Return S if S is a string containing a non-blank character.
|
|
|
|
Otherwise, return nil."
|
2010-07-20 01:54:11 -04:00
|
|
|
(and (stringp s)
|
2016-06-23 04:00:00 -04:00
|
|
|
(string-match-p "[^ \r\t\n]" s)
|
2010-07-20 01:54:11 -04:00
|
|
|
s))
|
|
|
|
|
2017-07-27 07:39:52 -04:00
|
|
|
(defun org-split-string (string &optional separators)
|
|
|
|
"Splits STRING into substrings at SEPARATORS.
|
|
|
|
|
|
|
|
SEPARATORS is a regular expression. When nil, it defaults to
|
|
|
|
\"[ \f\t\n\r\v]+\".
|
|
|
|
|
2017-11-15 12:58:44 -05:00
|
|
|
Unlike `split-string', matching SEPARATORS at the beginning and
|
|
|
|
end of string are ignored."
|
2017-07-27 07:39:52 -04:00
|
|
|
(let ((separators (or separators "[ \f\t\n\r\v]+")))
|
|
|
|
(when (string-match (concat "\\`" separators) string)
|
|
|
|
(setq string (replace-match "" nil nil string)))
|
|
|
|
(when (string-match (concat separators "\\'") string)
|
|
|
|
(setq string (replace-match "" nil nil string)))
|
|
|
|
(split-string string separators)))
|
|
|
|
|
2017-07-28 06:15:47 -04:00
|
|
|
(defun org-string-display (string)
|
|
|
|
"Return STRING as it is displayed in the current buffer.
|
|
|
|
This function takes into consideration `invisible' and `display'
|
|
|
|
text properties."
|
|
|
|
(let* ((build-from-parts
|
|
|
|
(lambda (s property filter)
|
|
|
|
;; Build a new string out of string S. On every group of
|
|
|
|
;; contiguous characters with the same PROPERTY value,
|
|
|
|
;; call FILTER on the properties list at the beginning of
|
|
|
|
;; the group. If it returns a string, replace the
|
|
|
|
;; characters in the group with it. Otherwise, preserve
|
|
|
|
;; those characters.
|
|
|
|
(let ((len (length s))
|
|
|
|
(new "")
|
|
|
|
(i 0)
|
|
|
|
(cursor 0))
|
|
|
|
(while (setq i (text-property-not-all i len property nil s))
|
|
|
|
(let ((end (next-single-property-change i property s len))
|
|
|
|
(value (funcall filter (text-properties-at i s))))
|
|
|
|
(when value
|
|
|
|
(setq new (concat new (substring s cursor i) value))
|
|
|
|
(setq cursor end))
|
|
|
|
(setq i end)))
|
|
|
|
(concat new (substring s cursor)))))
|
|
|
|
(prune-invisible
|
|
|
|
(lambda (s)
|
|
|
|
(funcall build-from-parts s 'invisible
|
|
|
|
(lambda (props)
|
|
|
|
;; If `invisible' property in PROPS means text
|
|
|
|
;; is to be invisible, return the empty string.
|
|
|
|
;; Otherwise return nil so that the part is
|
|
|
|
;; skipped.
|
|
|
|
(and (or (eq t buffer-invisibility-spec)
|
|
|
|
(assoc-string (plist-get props 'invisible)
|
|
|
|
buffer-invisibility-spec))
|
|
|
|
"")))))
|
|
|
|
(replace-display
|
|
|
|
(lambda (s)
|
|
|
|
(funcall build-from-parts s 'display
|
|
|
|
(lambda (props)
|
|
|
|
;; If there is any string specification in
|
|
|
|
;; `display' property return it. Also attach
|
|
|
|
;; other text properties on the part to that
|
|
|
|
;; string (face...).
|
|
|
|
(let* ((display (plist-get props 'display))
|
|
|
|
(value (if (stringp display) display
|
|
|
|
(cl-some #'stringp display))))
|
|
|
|
(when value
|
2017-11-15 12:13:34 -05:00
|
|
|
(apply #'propertize
|
|
|
|
;; Displayed string could contain
|
|
|
|
;; invisible parts, but no nested
|
|
|
|
;; display.
|
|
|
|
(funcall prune-invisible value)
|
|
|
|
'display
|
|
|
|
(and (not (stringp display))
|
|
|
|
(cl-remove-if #'stringp display))
|
|
|
|
props))))))))
|
2017-07-28 06:15:47 -04:00
|
|
|
;; `display' property overrides `invisible' one. So we first
|
|
|
|
;; replace characters with `display' property. Then we remove
|
|
|
|
;; invisible characters.
|
|
|
|
(funcall prune-invisible (funcall replace-display string))))
|
|
|
|
|
|
|
|
(defun org-string-width (string)
|
|
|
|
"Return width of STRING when displayed in the current buffer.
|
2017-11-15 12:58:44 -05:00
|
|
|
Unlike `string-width', this function takes into consideration
|
2017-07-28 06:15:47 -04:00
|
|
|
`invisible' and `display' text properties."
|
|
|
|
(string-width (org-string-display string)))
|
2017-07-27 09:23:31 -04:00
|
|
|
|
2010-06-25 03:00:19 -04:00
|
|
|
(defun org-not-nil (v)
|
2010-06-26 01:54:07 -04:00
|
|
|
"If V not nil, and also not the string \"nil\", then return V.
|
|
|
|
Otherwise return nil."
|
|
|
|
(and v (not (equal v "nil")) v))
|
2010-06-25 03:00:19 -04:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defmacro org-preserve-lc (&rest body)
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
2011-08-10 01:33:43 -04:00
|
|
|
(org-with-gensyms (line col)
|
|
|
|
`(let ((,line (org-current-line))
|
|
|
|
(,col (current-column)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn ,@body)
|
|
|
|
(org-goto-line ,line)
|
|
|
|
(org-move-to-column ,col)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2013-02-25 05:47:01 -05:00
|
|
|
;; Use `org-with-silent-modifications' to ignore cosmetic changes and
|
|
|
|
;; `org-unmodified' to ignore real text modifications
|
2013-02-23 05:44:24 -05:00
|
|
|
(defmacro org-unmodified (&rest body)
|
2012-12-29 19:21:27 -05:00
|
|
|
"Run BODY while preserving the buffer's `buffer-modified-p' state."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
2012-12-29 19:21:27 -05:00
|
|
|
(org-with-gensyms (was-modified)
|
|
|
|
`(let ((,was-modified (buffer-modified-p)))
|
|
|
|
(unwind-protect
|
2013-02-23 05:44:24 -05:00
|
|
|
(let ((buffer-undo-list t)
|
|
|
|
(inhibit-modification-hooks t))
|
|
|
|
,@body)
|
|
|
|
(set-buffer-modified-p ,was-modified)))))
|
2012-12-29 19:21:27 -05:00
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defmacro org-without-partial-completion (&rest body)
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
2011-07-02 06:15:20 -04:00
|
|
|
`(if (and (boundp 'partial-completion-mode)
|
2011-07-02 10:51:55 -04:00
|
|
|
partial-completion-mode
|
2011-07-02 06:15:20 -04:00
|
|
|
(fboundp 'partial-completion-mode))
|
2012-08-11 13:10:44 -04:00
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(partial-completion-mode -1)
|
|
|
|
,@body)
|
|
|
|
(partial-completion-mode 1))
|
2011-07-02 06:15:20 -04:00
|
|
|
,@body))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defmacro org-with-point-at (pom &rest body)
|
|
|
|
"Move to buffer and point of point-or-marker POM for the duration of BODY."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (form body)) (indent 1))
|
2011-08-10 01:33:43 -04:00
|
|
|
(org-with-gensyms (mpom)
|
|
|
|
`(let ((,mpom ,pom))
|
2011-02-25 13:30:33 -05:00
|
|
|
(save-excursion
|
2011-08-10 01:33:43 -04:00
|
|
|
(if (markerp ,mpom) (set-buffer (marker-buffer ,mpom)))
|
2014-06-14 22:50:07 -04:00
|
|
|
(org-with-wide-buffer
|
|
|
|
(goto-char (or ,mpom (point)))
|
|
|
|
,@body)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2013-04-10 08:32:55 -04:00
|
|
|
(defmacro org-with-remote-undo (buffer &rest body)
|
2008-03-22 11:52:18 -04:00
|
|
|
"Execute BODY while recording undo information in two buffers."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (form body)) (indent 1))
|
2011-08-10 01:33:43 -04:00
|
|
|
(org-with-gensyms (cline cmd buf1 buf2 undo1 undo2 c1 c2)
|
|
|
|
`(let ((,cline (org-current-line))
|
|
|
|
(,cmd this-command)
|
|
|
|
(,buf1 (current-buffer))
|
2013-04-10 08:32:55 -04:00
|
|
|
(,buf2 ,buffer)
|
2011-08-10 01:33:43 -04:00
|
|
|
(,undo1 buffer-undo-list)
|
2013-04-10 08:32:55 -04:00
|
|
|
(,undo2 (with-current-buffer ,buffer buffer-undo-list))
|
2011-08-10 01:33:43 -04:00
|
|
|
,c1 ,c2)
|
2013-04-10 08:32:55 -04:00
|
|
|
,@body
|
2011-08-10 01:33:43 -04:00
|
|
|
(when org-agenda-allow-remote-undo
|
|
|
|
(setq ,c1 (org-verify-change-for-undo
|
|
|
|
,undo1 (with-current-buffer ,buf1 buffer-undo-list))
|
|
|
|
,c2 (org-verify-change-for-undo
|
|
|
|
,undo2 (with-current-buffer ,buf2 buffer-undo-list)))
|
|
|
|
(when (or ,c1 ,c2)
|
|
|
|
;; make sure there are undo boundaries
|
|
|
|
(and ,c1 (with-current-buffer ,buf1 (undo-boundary)))
|
|
|
|
(and ,c2 (with-current-buffer ,buf2 (undo-boundary)))
|
|
|
|
;; remember which buffer to undo
|
|
|
|
(push (list ,cmd ,cline ,buf1 ,c1 ,buf2 ,c2)
|
|
|
|
org-agenda-undo-list))))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
|
|
|
(defmacro org-no-read-only (&rest body)
|
|
|
|
"Inhibit read-only for BODY."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
2008-03-22 11:52:18 -04:00
|
|
|
`(let ((inhibit-read-only t)) ,@body))
|
|
|
|
|
|
|
|
(defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
|
2010-06-03 18:13:19 -04:00
|
|
|
rear-nonsticky t mouse-map t fontified t
|
|
|
|
org-emphasis t)
|
2008-03-22 11:52:18 -04:00
|
|
|
"Properties to remove when a string without properties is wanted.")
|
|
|
|
|
2012-08-15 03:35:21 -04:00
|
|
|
(defsubst org-no-properties (s &optional restricted)
|
|
|
|
"Remove all text properties from string S.
|
|
|
|
When RESTRICTED is non-nil, only remove the properties listed
|
|
|
|
in `org-rm-props'."
|
2016-06-23 09:55:39 -04:00
|
|
|
(if restricted (remove-text-properties 0 (length s) org-rm-props s)
|
|
|
|
(set-text-properties 0 (length s) nil s))
|
2008-03-22 11:52:18 -04:00
|
|
|
s)
|
|
|
|
|
|
|
|
(defsubst org-get-alist-option (option key)
|
|
|
|
(cond ((eq key t) t)
|
|
|
|
((eq option t) t)
|
|
|
|
((assoc key option) (cdr (assoc key option)))
|
2013-02-27 02:46:26 -05:00
|
|
|
(t (let ((r (cdr (assq 'default option))))
|
|
|
|
(if (listp r) (delq nil r) r)))))
|
2008-03-22 11:52:18 -04:00
|
|
|
|
2009-04-30 16:50:47 -04:00
|
|
|
(defsubst org-check-external-command (cmd &optional use no-error)
|
2009-11-12 07:39:29 -05:00
|
|
|
"Check if external program CMD for USE exists, error if not.
|
2009-08-15 02:16:38 -04:00
|
|
|
When the program does exist, return its path.
|
2009-04-30 16:50:47 -04:00
|
|
|
When it does not exist and NO-ERROR is set, return nil.
|
|
|
|
Otherwise, throw an error. The optional argument USE can describe what this
|
|
|
|
program is needed for, so that the error message can be more informative."
|
|
|
|
(or (executable-find cmd)
|
|
|
|
(if no-error
|
|
|
|
nil
|
|
|
|
(error "Can't find `%s'%s" cmd
|
|
|
|
(if use (format " (%s)" use) "")))))
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defsubst org-last (list)
|
|
|
|
"Return the last element of LIST."
|
|
|
|
(car (last list)))
|
|
|
|
|
|
|
|
(defun org-let (list &rest body)
|
|
|
|
(eval (cons 'let (cons list body))))
|
|
|
|
(put 'org-let 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
(defun org-let2 (list1 list2 &rest body)
|
|
|
|
(eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
|
|
|
|
(put 'org-let2 'lisp-indent-function 2)
|
|
|
|
|
|
|
|
(defsubst org-call-with-arg (command arg)
|
2008-05-09 00:08:45 -04:00
|
|
|
"Call COMMAND interactively, but pretend prefix arg was ARG."
|
2008-03-22 11:52:18 -04:00
|
|
|
(let ((current-prefix-arg arg)) (call-interactively command)))
|
|
|
|
|
|
|
|
(defsubst org-current-line (&optional pos)
|
|
|
|
(save-excursion
|
|
|
|
(and pos (goto-char pos))
|
|
|
|
;; works also in narrowed buffer, because we start at 1, not point-min
|
|
|
|
(+ (if (bolp) 1 0) (count-lines 1 (point)))))
|
|
|
|
|
2009-08-27 04:24:09 -04:00
|
|
|
(defsubst org-goto-line (N)
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (1- N))))
|
|
|
|
|
2009-01-21 07:14:07 -05:00
|
|
|
(defsubst org-current-line-string (&optional to-here)
|
|
|
|
(buffer-substring (point-at-bol) (if to-here (point) (point-at-eol))))
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(defsubst org-pos-in-match-range (pos n)
|
|
|
|
(and (match-beginning n)
|
|
|
|
(<= (match-beginning n) pos)
|
|
|
|
(>= (match-end n) pos)))
|
|
|
|
|
2016-12-14 18:02:58 -05:00
|
|
|
(defun org-match-line (regexp)
|
|
|
|
"Match REGEXP at the beginning of the current line."
|
2008-04-03 11:58:13 -04:00
|
|
|
(save-excursion
|
2016-12-14 18:02:58 -05:00
|
|
|
(beginning-of-line)
|
|
|
|
(looking-at regexp)))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2008-04-04 17:44:48 -04:00
|
|
|
(defun org-plist-delete (plist property)
|
|
|
|
"Delete PROPERTY from PLIST.
|
|
|
|
This is in contrast to merely setting it to 0."
|
|
|
|
(let (p)
|
|
|
|
(while plist
|
|
|
|
(if (not (eq property (car plist)))
|
|
|
|
(setq p (plist-put p (car plist) (nth 1 plist))))
|
|
|
|
(setq plist (cddr plist)))
|
|
|
|
p))
|
|
|
|
|
2010-08-27 10:18:32 -04:00
|
|
|
(defmacro org-save-outline-visibility (use-markers &rest body)
|
|
|
|
"Save and restore outline visibility around BODY.
|
|
|
|
If USE-MARKERS is non-nil, use markers for the positions.
|
|
|
|
This means that the buffer may change while running BODY,
|
|
|
|
but it also means that the buffer should stay alive
|
|
|
|
during the operation, because otherwise all these markers will
|
|
|
|
point nowhere."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (form body)) (indent 1))
|
2016-06-21 17:02:35 -04:00
|
|
|
(org-with-gensyms (data)
|
2016-06-21 16:56:46 -04:00
|
|
|
`(let ((,data (org-outline-overlay-data ,use-markers)))
|
2011-08-10 01:33:43 -04:00
|
|
|
(unwind-protect
|
2016-06-21 16:56:46 -04:00
|
|
|
(prog1 (progn ,@body)
|
2011-08-10 01:33:43 -04:00
|
|
|
(org-set-outline-overlay-data ,data))
|
|
|
|
(when ,use-markers
|
2016-06-21 16:56:46 -04:00
|
|
|
(dolist (c ,data)
|
|
|
|
(when (markerp (car c)) (move-marker (car c) nil))
|
|
|
|
(when (markerp (cdr c)) (move-marker (cdr c) nil))))))))
|
2010-08-27 10:18:32 -04:00
|
|
|
|
2011-03-05 05:01:28 -05:00
|
|
|
(defmacro org-with-wide-buffer (&rest body)
|
2012-08-11 13:10:44 -04:00
|
|
|
"Execute body while temporarily widening the buffer."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
2012-08-11 13:10:44 -04:00
|
|
|
`(save-excursion
|
|
|
|
(save-restriction
|
2011-03-09 04:56:47 -05:00
|
|
|
(widen)
|
|
|
|
,@body)))
|
2011-03-05 05:01:28 -05:00
|
|
|
|
2009-07-19 03:42:22 -04:00
|
|
|
(defmacro org-with-limited-levels (&rest body)
|
|
|
|
"Execute BODY with limited number of outline levels."
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (body)))
|
|
|
|
`(progn
|
|
|
|
(defvar org-called-with-limited-levels)
|
|
|
|
(defvar org-outline-regexp)
|
|
|
|
(defvar outline-regexp)
|
|
|
|
(defvar org-outline-regexp-bol)
|
|
|
|
(let* ((org-called-with-limited-levels t)
|
|
|
|
(org-outline-regexp (org-get-limited-outline-regexp))
|
|
|
|
(outline-regexp org-outline-regexp)
|
|
|
|
(org-outline-regexp-bol (concat "^" org-outline-regexp)))
|
|
|
|
,@body)))
|
2009-07-19 03:42:22 -04:00
|
|
|
|
2011-07-18 13:25:10 -04:00
|
|
|
(defvar org-outline-regexp) ; defined in org.el
|
2009-07-20 03:16:28 -04:00
|
|
|
(defvar org-odd-levels-only) ; defined in org.el
|
|
|
|
(defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
|
2009-07-19 03:42:22 -04:00
|
|
|
(defun org-get-limited-outline-regexp ()
|
|
|
|
"Return outline-regexp with limited number of levels.
|
2010-07-16 17:23:01 -04:00
|
|
|
The number of levels is controlled by `org-inlinetask-min-level'"
|
2014-07-22 12:29:00 -04:00
|
|
|
(cond ((not (derived-mode-p 'org-mode))
|
|
|
|
outline-regexp)
|
|
|
|
((not (featurep 'org-inlinetask))
|
|
|
|
org-outline-regexp)
|
|
|
|
(t
|
|
|
|
(let* ((limit-level (1- org-inlinetask-min-level))
|
|
|
|
(nstars (if org-odd-levels-only
|
|
|
|
(1- (* limit-level 2))
|
|
|
|
limit-level)))
|
|
|
|
(format "\\*\\{1,%d\\} " nstars)))))
|
2009-08-03 11:30:30 -04:00
|
|
|
|
2011-08-10 01:43:10 -04:00
|
|
|
(defmacro org-eval-in-environment (environment form)
|
2015-05-04 11:32:43 -04:00
|
|
|
(declare (debug (form form)) (indent 1))
|
2011-08-10 01:43:10 -04:00
|
|
|
`(eval (list 'let ,environment ',form)))
|
|
|
|
|
2011-08-10 02:14:26 -04:00
|
|
|
(defun org-make-parameter-alist (flat)
|
|
|
|
"Return alist based on FLAT.
|
2012-08-11 13:10:44 -04:00
|
|
|
FLAT is a list with alternating symbol names and values. The
|
2011-08-10 02:14:26 -04:00
|
|
|
returned alist is a list of lists with the symbol name in car and
|
|
|
|
the value in cdr."
|
|
|
|
(when flat
|
|
|
|
(cons (list (car flat) (cadr flat))
|
2012-08-11 13:10:44 -04:00
|
|
|
(org-make-parameter-alist (cddr flat)))))
|
2011-08-10 02:14:26 -04:00
|
|
|
|
2013-01-10 18:43:26 -05:00
|
|
|
;;;###autoload
|
2013-01-06 12:24:56 -05:00
|
|
|
(defmacro org-load-noerror-mustsuffix (file)
|
2016-05-26 05:30:11 -04:00
|
|
|
"Load FILE with optional arguments NOERROR and MUSTSUFFIX."
|
|
|
|
`(load ,file 'noerror nil nil 'mustsuffix))
|
2013-01-06 12:24:56 -05:00
|
|
|
|
2016-09-02 20:55:45 -04:00
|
|
|
(defun org-unbracket-string (pre post string)
|
|
|
|
"Remove PRE/POST from the beginning/end of STRING.
|
|
|
|
Both PRE and POST must be pre-/suffixes of STRING, or neither is
|
|
|
|
removed."
|
|
|
|
(if (and (string-prefix-p pre string)
|
|
|
|
(string-suffix-p post string))
|
2016-09-05 18:08:32 -04:00
|
|
|
(substring string (length pre) (- (length post)))
|
2016-09-02 20:55:45 -04:00
|
|
|
string))
|
|
|
|
|
2017-05-09 14:57:40 -04:00
|
|
|
(defun org-read-function (prompt &optional allow-empty?)
|
|
|
|
"Prompt for a function.
|
|
|
|
If ALLOW-EMPTY? is non-nil, return nil rather than raising an
|
|
|
|
error when the user input is empty."
|
|
|
|
(let ((func (completing-read prompt obarray #'fboundp t)))
|
|
|
|
(cond ((not (string= func ""))
|
|
|
|
(intern func))
|
|
|
|
(allow-empty? nil)
|
|
|
|
(t (user-error "Empty input is not valid")))))
|
|
|
|
|
2017-08-07 04:52:37 -04:00
|
|
|
(defconst org-unique-local-variables
|
|
|
|
'(org-element--cache
|
|
|
|
org-element--cache-objects
|
|
|
|
org-element--cache-sync-keys
|
|
|
|
org-element--cache-sync-requests
|
|
|
|
org-element--cache-sync-timer)
|
|
|
|
"List of local variables that cannot be transferred to another buffer.")
|
|
|
|
|
|
|
|
(defun org-get-local-variables ()
|
|
|
|
"Return a list of all local variables in an Org mode buffer."
|
|
|
|
(delq nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (x)
|
|
|
|
(let* ((binding (if (symbolp x) (list x) (list (car x) (cdr x))))
|
|
|
|
(name (car binding)))
|
|
|
|
(and (not (get name 'org-state))
|
|
|
|
(not (memq name org-unique-local-variables))
|
|
|
|
(string-match-p
|
|
|
|
"\\`\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|\
|
|
|
|
auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)"
|
|
|
|
(symbol-name name))
|
|
|
|
binding)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(org-mode)
|
|
|
|
(buffer-local-variables)))))
|
|
|
|
|
|
|
|
(defun org-clone-local-variables (from-buffer &optional regexp)
|
|
|
|
"Clone local variables from FROM-BUFFER.
|
|
|
|
Optional argument REGEXP selects variables to clone."
|
|
|
|
(dolist (pair (buffer-local-variables from-buffer))
|
|
|
|
(pcase pair
|
|
|
|
(`(,name . ,value) ;ignore unbound variables
|
|
|
|
(when (and (not (memq name org-unique-local-variables))
|
|
|
|
(or (null regexp) (string-match-p regexp (symbol-name name))))
|
|
|
|
(ignore-errors (set (make-local-variable name) value)))))))
|
|
|
|
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(provide 'org-macs)
|
|
|
|
|
|
|
|
;;; org-macs.el ends here
|