2008-03-22 11:52:18 -04:00
|
|
|
;;; org-macs.el --- Top-level definitions for Org-mode
|
|
|
|
|
2009-01-26 03:42:33 -05:00
|
|
|
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
|
|
|
|
;; 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
|
|
|
|
;; Homepage: http://orgmode.org
|
2009-06-26 11:26:50 -04:00
|
|
|
;; Version: 6.28trans
|
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
|
2008-05-06 08:45:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://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
|
|
|
|
;; 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:
|
|
|
|
|
2009-06-07 16:14:33 -04:00
|
|
|
(eval-and-compile
|
|
|
|
(unless (fboundp 'declare-function)
|
|
|
|
(defmacro declare-function (fn file &optional arglist fileonly))))
|
|
|
|
|
2009-06-07 11:07:07 -04:00
|
|
|
(declare-function org-add-props "org-compat" (string plist &rest props))
|
|
|
|
|
2008-03-22 11:52:18 -04: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)
|
|
|
|
"Execute body without changing `buffer-modified-p'."
|
|
|
|
`(set-buffer-modified-p
|
|
|
|
(prog1 (buffer-modified-p) ,@body)))
|
|
|
|
|
|
|
|
(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 04:59:11 -05:00
|
|
|
(while (string-match "\\[:word:\\]" ss)
|
|
|
|
(setq ss (replace-match "a-zA-Z0-9" t t ss)))
|
2008-03-22 11:52:18 -04: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)
|
|
|
|
(goto-line _line)
|
2008-04-24 10:44:12 -04:00
|
|
|
(org-move-to-column _col))))
|
2008-03-22 11:52:18 -04: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 11:23:08 -05:00
|
|
|
"Add '(intangible t) to PROPS if Emacs version is earlier than Emacs 22.
|
2008-03-22 11:52:18 -04: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 06:35:32 -04:00
|
|
|
(if (< emacs-major-version 22)
|
2008-03-22 11:52:18 -04: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 06:46:52 -04:00
|
|
|
(if (markerp ,pom) (set-buffer (marker-buffer ,pom)))
|
2008-03-22 11:52:18 -04:00
|
|
|
(save-excursion
|
2008-06-12 06:46:52 -04:00
|
|
|
(goto-char (or ,pom (point)))
|
2008-03-22 11:52:18 -04:00
|
|
|
,@body)))
|
|
|
|
|
|
|
|
(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 02:26:44 -05: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 16:23:50 -05:00
|
|
|
(defmacro org-if-unprotected-at (pos &rest body)
|
|
|
|
"Execute BODY if there is no `org-protected' text property at point-1."
|
|
|
|
`(unless (get-text-property ,pos 'org-protected)
|
|
|
|
,@body))
|
|
|
|
|
2008-03-22 11:52:18 -04: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 02:10:18 -04:00
|
|
|
(and s (remove-text-properties 0 (length s) org-rm-props s))
|
2008-03-22 11:52:18 -04: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 16:50:47 -04:00
|
|
|
(defsubst org-check-external-command (cmd &optional use no-error)
|
|
|
|
"Check if external progam CMD for USE exists, error if not.
|
|
|
|
When the program does exist, return it's path.
|
|
|
|
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-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 11:00:03 -04:00
|
|
|
(set (make-local-variable var) value))
|
2008-03-22 11:52:18 -04: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 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-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)))
|
|
|
|
|
|
|
|
(defun org-autoload (file functions)
|
2008-05-09 00:08:45 -04:00
|
|
|
"Establish autoload for all FUNCTIONS in FILE, if not bound already."
|
2008-03-22 11:52:18 -04: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 08:48:59 -04:00
|
|
|
(defun org-match-line (re)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Looking-at at the beginning of the current line."
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-at-bol))
|
|
|
|
(looking-at re)))
|
|
|
|
|
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))
|
|
|
|
|
2009-06-07 10:11:14 -04: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))
|
|
|
|
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
(provide 'org-macs)
|
|
|
|
|
2008-04-29 01:15:41 -04:00
|
|
|
;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668
|
|
|
|
|
2008-03-22 11:52:18 -04:00
|
|
|
;;; org-macs.el ends here
|