2008-03-22 15:52:18 +00:00
|
|
|
;;; org-macs.el --- Top-level definitions for Org-mode
|
|
|
|
|
2009-01-26 08:42:33 +00:00
|
|
|
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
|
|
|
|
;; Free Software Foundation, Inc.
|
2008-03-22 15:52:18 +00:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
2009-10-01 09:57:17 +00:00
|
|
|
;; Version: 6.31trans
|
2008-03-22 15:52:18 +00:00
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 12:45:52 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-03-22 15:52:18 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 12:45:52 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-03-22 15:52:18 +00: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
|
2008-05-06 12:45:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-22 15:52:18 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-04-04 21:44:48 +00:00
|
|
|
;; This file contains macro definitions, defsubst definitions, other
|
|
|
|
;; 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 15:52:18 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2009-06-07 20:14:33 +00:00
|
|
|
(eval-and-compile
|
|
|
|
(unless (fboundp 'declare-function)
|
|
|
|
(defmacro declare-function (fn file &optional arglist fileonly))))
|
|
|
|
|
2009-06-07 15:07:07 +00:00
|
|
|
(declare-function org-add-props "org-compat" (string plist &rest props))
|
|
|
|
|
2008-03-22 15:52:18 +00:00
|
|
|
(defmacro org-bound-and-true-p (var)
|
|
|
|
"Return the value of symbol VAR if it is bound, else nil."
|
|
|
|
`(and (boundp (quote ,var)) ,var))
|
|
|
|
|
|
|
|
(defmacro org-unmodified (&rest body)
|
2009-08-03 09:03:37 +00:00
|
|
|
"Execute body without changing `buffer-modified-p'.
|
|
|
|
Also, do not record undo information."
|
2008-03-22 15:52:18 +00:00
|
|
|
`(set-buffer-modified-p
|
2009-07-18 06:14:03 +00:00
|
|
|
(prog1 (buffer-modified-p)
|
2009-08-03 09:03:37 +00:00
|
|
|
(let ((buffer-undo-list t)
|
|
|
|
before-change-functions after-change-functions)
|
2009-07-18 06:14:03 +00:00
|
|
|
,@body))))
|
2008-03-22 15:52:18 +00:00
|
|
|
|
|
|
|
(defmacro org-re (s)
|
|
|
|
"Replace posix classes in regular expression."
|
|
|
|
(if (featurep 'xemacs)
|
|
|
|
(let ((ss s))
|
|
|
|
(save-match-data
|
|
|
|
(while (string-match "\\[:alnum:\\]" ss)
|
|
|
|
(setq ss (replace-match "a-zA-Z0-9" t t ss)))
|
2009-01-01 09:59:11 +00:00
|
|
|
(while (string-match "\\[:word:\\]" ss)
|
|
|
|
(setq ss (replace-match "a-zA-Z0-9" t t ss)))
|
2008-03-22 15:52:18 +00:00
|
|
|
(while (string-match "\\[:alpha:\\]" ss)
|
|
|
|
(setq ss (replace-match "a-zA-Z" t t ss)))
|
|
|
|
ss))
|
|
|
|
s))
|
|
|
|
|
|
|
|
(defmacro org-preserve-lc (&rest body)
|
|
|
|
`(let ((_line (org-current-line))
|
|
|
|
(_col (current-column)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn ,@body)
|
2009-08-27 08:24:09 +00:00
|
|
|
(org-goto-line _line)
|
2008-04-24 14:44:12 +00:00
|
|
|
(org-move-to-column _col))))
|
2008-03-22 15:52:18 +00:00
|
|
|
|
|
|
|
(defmacro org-without-partial-completion (&rest body)
|
|
|
|
`(let ((pc-mode (and (boundp 'partial-completion-mode)
|
|
|
|
partial-completion-mode)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(if pc-mode (partial-completion-mode -1))
|
|
|
|
,@body)
|
|
|
|
(if pc-mode (partial-completion-mode 1)))))
|
|
|
|
|
|
|
|
(defmacro org-maybe-intangible (props)
|
2008-12-16 16:23:08 +00:00
|
|
|
"Add '(intangible t) to PROPS if Emacs version is earlier than Emacs 22.
|
2008-03-22 15:52:18 +00:00
|
|
|
In emacs 21, invisible text is not avoided by the command loop, so the
|
|
|
|
intangible property is needed to make sure point skips this text.
|
|
|
|
In Emacs 22, this is not necessary. The intangible text property has
|
|
|
|
led to problems with flyspell. These problems are fixed in flyspell.el,
|
|
|
|
but we still avoid setting the property in Emacs 22 and later.
|
|
|
|
We use a macro so that the test can happen at compilation time."
|
2009-04-14 10:35:32 +00:00
|
|
|
(if (< emacs-major-version 22)
|
2008-03-22 15:52:18 +00:00
|
|
|
`(append '(intangible t) ,props)
|
|
|
|
props))
|
|
|
|
|
|
|
|
(defmacro org-with-point-at (pom &rest body)
|
|
|
|
"Move to buffer and point of point-or-marker POM for the duration of BODY."
|
|
|
|
`(save-excursion
|
2008-06-12 10:46:52 +00:00
|
|
|
(if (markerp ,pom) (set-buffer (marker-buffer ,pom)))
|
2008-03-22 15:52:18 +00:00
|
|
|
(save-excursion
|
2008-06-12 10:46:52 +00:00
|
|
|
(goto-char (or ,pom (point)))
|
2008-03-22 15:52:18 +00:00
|
|
|
,@body)))
|
2009-09-12 05:05:21 +00:00
|
|
|
(put 'org-with-point-at 'lisp-indent-function 1)
|
2008-03-22 15:52:18 +00:00
|
|
|
|
|
|
|
(defmacro org-no-warnings (&rest body)
|
|
|
|
(cons (if (fboundp 'with-no-warnings) 'with-no-warnings 'progn) body))
|
|
|
|
|
|
|
|
(defmacro org-if-unprotected (&rest body)
|
|
|
|
"Execute BODY if there is no `org-protected' text property at point."
|
|
|
|
`(unless (get-text-property (point) 'org-protected)
|
|
|
|
,@body))
|
|
|
|
|
LaTeX export: Make quotes exported right before a footnote reference.
Matt Lundin writes:
I'm have a *minor* issue to report. It occurs when I export
an org file with footnotes to LaTeX. Specifically, it has to
do with the combination of American style quotation marks
and footnotes.
According to many American manuals of style, quotation marks
are to be placed after a sentence ending period if the
quoted passage is at the end of the sentence. E.g.
,----
| Here is "a quote."
|
| not
|
| Here is "a quote".
`----
When I use American style quotation in conjuction with a
footnote, the exporter does not convert the closing quote
marks into a two single quotation marks (i.e., LaTeX smart
quotes).
Thus, the following source snippet:
,----
| This is a footnote "with a quote."[fn:sample] And here
| is another footnote "with a quote".[fn:another]
|
| [fn:sample] Here is the sample footnote.
|
| [fn:another] Another footnote.
`----
Becomes
,----
| This is a footnote ``with a quote."\footnote{Here is
| the sample footnote. } And here is another footnote ``with
| a quote''.\footnote{Another footnote. }
`----
Notice the double quotation mark (rather than two single
apostrophes) at the end of the first sentence. Notice also
the correct quotation mark format appears in the second
sentence, where the period comes after the quotation mark.
This commit addresses this issue by checking of text
protection is off not after the quotation mark, but before.
2009-01-20 07:26:44 +00:00
|
|
|
(defmacro org-if-unprotected-1 (&rest body)
|
|
|
|
"Execute BODY if there is no `org-protected' text property at point-1."
|
|
|
|
`(unless (get-text-property (1- (point)) 'org-protected)
|
|
|
|
,@body))
|
|
|
|
|
2009-02-17 21:23:50 +00:00
|
|
|
(defmacro org-if-unprotected-at (pos &rest body)
|
2009-09-28 19:35:49 +00:00
|
|
|
"Execute BODY if there is no `org-protected' text property at POS."
|
2009-02-17 21:23:50 +00:00
|
|
|
`(unless (get-text-property ,pos 'org-protected)
|
|
|
|
,@body))
|
|
|
|
|
2008-03-22 15:52:18 +00:00
|
|
|
(defmacro org-with-remote-undo (_buffer &rest _body)
|
|
|
|
"Execute BODY while recording undo information in two buffers."
|
|
|
|
`(let ((_cline (org-current-line))
|
|
|
|
(_cmd this-command)
|
|
|
|
(_buf1 (current-buffer))
|
|
|
|
(_buf2 ,_buffer)
|
|
|
|
(_undo1 buffer-undo-list)
|
|
|
|
(_undo2 (with-current-buffer ,_buffer buffer-undo-list))
|
|
|
|
_c1 _c2)
|
|
|
|
,@_body
|
|
|
|
(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)))))
|
|
|
|
|
|
|
|
(defmacro org-no-read-only (&rest body)
|
|
|
|
"Inhibit read-only for BODY."
|
|
|
|
`(let ((inhibit-read-only t)) ,@body))
|
|
|
|
|
|
|
|
(defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
|
|
|
|
rear-nonsticky t mouse-map t fontified t)
|
|
|
|
"Properties to remove when a string without properties is wanted.")
|
|
|
|
|
|
|
|
(defsubst org-match-string-no-properties (num &optional string)
|
|
|
|
(if (featurep 'xemacs)
|
|
|
|
(let ((s (match-string num string)))
|
2008-04-20 06:10:18 +00:00
|
|
|
(and s (remove-text-properties 0 (length s) org-rm-props s))
|
2008-03-22 15:52:18 +00:00
|
|
|
s)
|
|
|
|
(match-string-no-properties num string)))
|
|
|
|
|
|
|
|
(defsubst org-no-properties (s)
|
|
|
|
(if (fboundp 'set-text-properties)
|
|
|
|
(set-text-properties 0 (length s) nil s)
|
|
|
|
(remove-text-properties 0 (length s) org-rm-props s))
|
|
|
|
s)
|
|
|
|
|
|
|
|
(defsubst org-get-alist-option (option key)
|
|
|
|
(cond ((eq key t) t)
|
|
|
|
((eq option t) t)
|
|
|
|
((assoc key option) (cdr (assoc key option)))
|
|
|
|
(t (cdr (assq 'default option)))))
|
|
|
|
|
2009-04-30 20:50:47 +00:00
|
|
|
(defsubst org-check-external-command (cmd &optional use no-error)
|
|
|
|
"Check if external progam CMD for USE exists, error if not.
|
2009-08-15 06:16:38 +00:00
|
|
|
When the program does exist, return its path.
|
2009-04-30 20:50:47 +00: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 15:52:18 +00:00
|
|
|
(defsubst org-inhibit-invisibility ()
|
|
|
|
"Modified `buffer-invisibility-spec' for Emacs 21.
|
|
|
|
Some ops with invisible text do not work correctly on Emacs 21. For these
|
|
|
|
we turn off invisibility temporarily. Use this in a `let' form."
|
|
|
|
(if (< emacs-major-version 22) nil buffer-invisibility-spec))
|
|
|
|
|
|
|
|
(defsubst org-set-local (var value)
|
|
|
|
"Make VAR local in current buffer and set it to VALUE."
|
2009-07-06 15:00:03 +00:00
|
|
|
(set (make-local-variable var) value))
|
2008-03-22 15:52:18 +00:00
|
|
|
|
|
|
|
(defsubst org-mode-p ()
|
|
|
|
"Check if the current buffer is in Org-mode."
|
|
|
|
(eq major-mode 'org-mode))
|
|
|
|
|
|
|
|
(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 04:08:45 +00:00
|
|
|
"Call COMMAND interactively, but pretend prefix arg was ARG."
|
2008-03-22 15:52:18 +00: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 08:24:09 +00:00
|
|
|
(defsubst org-goto-line (N)
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (1- N))))
|
|
|
|
|
2009-01-21 12:14:07 +00:00
|
|
|
(defsubst org-current-line-string (&optional to-here)
|
|
|
|
(buffer-substring (point-at-bol) (if to-here (point) (point-at-eol))))
|
|
|
|
|
2008-03-22 15:52:18 +00:00
|
|
|
(defsubst org-pos-in-match-range (pos n)
|
|
|
|
(and (match-beginning n)
|
|
|
|
(<= (match-beginning n) pos)
|
|
|
|
(>= (match-end n) pos)))
|
|
|
|
|
|
|
|
(defun org-autoload (file functions)
|
2008-05-09 04:08:45 +00:00
|
|
|
"Establish autoload for all FUNCTIONS in FILE, if not bound already."
|
2008-03-22 15:52:18 +00:00
|
|
|
(let ((d (format "Documentation will be available after `%s.el' is loaded."
|
|
|
|
file))
|
|
|
|
f)
|
|
|
|
(while (setq f (pop functions))
|
|
|
|
(or (fboundp f) (autoload f file d t)))))
|
|
|
|
|
2008-04-10 12:48:59 +00:00
|
|
|
(defun org-match-line (re)
|
2008-04-03 15:58:13 +00:00
|
|
|
"Looking-at at the beginning of the current line."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-at-bol))
|
|
|
|
(looking-at re)))
|
|
|
|
|
2008-04-04 21:44:48 +00: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))
|
|
|
|
|
2009-06-07 14:11:14 +00:00
|
|
|
|
|
|
|
(defun org-replace-match-keep-properties (newtext &optional fixedcase
|
|
|
|
literal string)
|
|
|
|
"Like `replace-match', but add the text properties found original text."
|
|
|
|
(setq newtext (org-add-props newtext (text-properties-at
|
|
|
|
(match-beginning 0) string)))
|
|
|
|
(replace-match newtext fixedcase literal string))
|
|
|
|
|
2009-07-19 07:42:22 +00:00
|
|
|
(defmacro org-with-limited-levels (&rest body)
|
|
|
|
"Execute BODY with limited number of outline levels."
|
|
|
|
`(let* ((outline-regexp (org-get-limited-outline-regexp)))
|
|
|
|
,@body))
|
|
|
|
|
2009-07-20 07:16:28 +00:00
|
|
|
(defvar org-odd-levels-only) ; defined in org.el
|
|
|
|
(defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
|
2009-07-19 07:42:22 +00:00
|
|
|
(defun org-get-limited-outline-regexp ()
|
|
|
|
"Return outline-regexp with limited number of levels.
|
|
|
|
The number of levels is controlled by "
|
|
|
|
(if (or (not (org-mode-p)) (not (featurep 'org-inlinetask)))
|
2009-06-07 14:11:14 +00:00
|
|
|
|
2009-07-19 07:42:22 +00:00
|
|
|
outline-regexp
|
|
|
|
(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 15:30:30 +00:00
|
|
|
|
2008-03-22 15:52:18 +00:00
|
|
|
(provide 'org-macs)
|
|
|
|
|
2008-04-29 05:15:41 +00:00
|
|
|
;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668
|
|
|
|
|
2008-03-22 15:52:18 +00:00
|
|
|
;;; org-macs.el ends here
|