1 ;;; org-macs.el --- Top-level definitions for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This file contains macro definitions, defsubst definitions, other
31 ;; stuff needed for compilation and top-level forms in Org-mode, as well
32 ;; lots of small functions that are not org-mode specific but simply
33 ;; generally useful stuff.
37 (defmacro org-bound-and-true-p
(var)
38 "Return the value of symbol VAR if it is bound, else nil."
39 `(and (boundp (quote ,var
)) ,var
))
41 (defmacro org-unmodified
(&rest body
)
42 "Execute body without changing `buffer-modified-p'."
43 `(set-buffer-modified-p
44 (prog1 (buffer-modified-p) ,@body
)))
47 "Replace posix classes in regular expression."
48 (if (featurep 'xemacs
)
51 (while (string-match "\\[:alnum:\\]" ss
)
52 (setq ss
(replace-match "a-zA-Z0-9" t t ss
)))
53 (while (string-match "\\[:alpha:\\]" ss
)
54 (setq ss
(replace-match "a-zA-Z" t t ss
)))
58 (defmacro org-preserve-lc
(&rest body
)
59 `(let ((_line (org-current-line))
60 (_col (current-column)))
64 (move-to-column _col
))))
66 (defmacro org-without-partial-completion
(&rest body
)
67 `(let ((pc-mode (and (boundp 'partial-completion-mode
)
68 partial-completion-mode
)))
71 (if pc-mode
(partial-completion-mode -
1))
73 (if pc-mode
(partial-completion-mode 1)))))
76 (unless (fboundp 'declare-function
)
77 (defmacro declare-function
(fn file
&optional arglist fileonly
))))
79 (defmacro org-maybe-intangible
(props)
80 "Add '(intangigble t) to PROPS if Emacs version is earlier than Emacs 22.
81 In emacs 21, invisible text is not avoided by the command loop, so the
82 intangible property is needed to make sure point skips this text.
83 In Emacs 22, this is not necessary. The intangible text property has
84 led to problems with flyspell. These problems are fixed in flyspell.el,
85 but we still avoid setting the property in Emacs 22 and later.
86 We use a macro so that the test can happen at compilation time."
87 (if (< emacs-major-version
22)
88 `(append '(intangible t
) ,props
)
91 (defmacro org-with-point-at
(pom &rest body
)
92 "Move to buffer and point of point-or-marker POM for the duration of BODY."
94 (if (markerp pom
) (set-buffer (marker-buffer pom
)))
96 (goto-char (or pom
(point)))
99 (defmacro org-no-warnings
(&rest body
)
100 (cons (if (fboundp 'with-no-warnings
) 'with-no-warnings
'progn
) body
))
102 (defmacro org-if-unprotected
(&rest body
)
103 "Execute BODY if there is no `org-protected' text property at point."
104 `(unless (get-text-property (point) 'org-protected
)
107 (defmacro org-with-remote-undo
(_buffer &rest _body
)
108 "Execute BODY while recording undo information in two buffers."
109 `(let ((_cline (org-current-line))
111 (_buf1 (current-buffer))
113 (_undo1 buffer-undo-list
)
114 (_undo2 (with-current-buffer ,_buffer buffer-undo-list
))
117 (when org-agenda-allow-remote-undo
118 (setq _c1
(org-verify-change-for-undo
119 _undo1
(with-current-buffer _buf1 buffer-undo-list
))
120 _c2
(org-verify-change-for-undo
121 _undo2
(with-current-buffer _buf2 buffer-undo-list
)))
123 ;; make sure there are undo boundaries
124 (and _c1
(with-current-buffer _buf1
(undo-boundary)))
125 (and _c2
(with-current-buffer _buf2
(undo-boundary)))
126 ;; remember which buffer to undo
127 (push (list _cmd _cline _buf1 _c1 _buf2 _c2
)
128 org-agenda-undo-list
)))))
130 (defmacro org-no-read-only
(&rest body
)
131 "Inhibit read-only for BODY."
132 `(let ((inhibit-read-only t
)) ,@body
))
134 (defconst org-rm-props
'(invisible t face t keymap t intangible t mouse-face t
135 rear-nonsticky t mouse-map t fontified t
)
136 "Properties to remove when a string without properties is wanted.")
138 (defsubst org-match-string-no-properties
(num &optional string
)
139 (if (featurep 'xemacs
)
140 (let ((s (match-string num string
)))
141 (and s
(remove-text-properties 0 (length s
) org-rm-props s
))
143 (match-string-no-properties num string
)))
145 (defsubst org-no-properties
(s)
146 (if (fboundp 'set-text-properties
)
147 (set-text-properties 0 (length s
) nil s
)
148 (remove-text-properties 0 (length s
) org-rm-props s
))
151 (defsubst org-get-alist-option
(option key
)
154 ((assoc key option
) (cdr (assoc key option
)))
155 (t (cdr (assq 'default option
)))))
157 (defsubst org-inhibit-invisibility
()
158 "Modified `buffer-invisibility-spec' for Emacs 21.
159 Some ops with invisible text do not work correctly on Emacs 21. For these
160 we turn off invisibility temporarily. Use this in a `let' form."
161 (if (< emacs-major-version
22) nil buffer-invisibility-spec
))
163 (defsubst org-set-local
(var value
)
164 "Make VAR local in current buffer and set it to VALUE."
165 (set (make-variable-buffer-local var
) value
))
167 (defsubst org-mode-p
()
168 "Check if the current buffer is in Org-mode."
169 (eq major-mode
'org-mode
))
171 (defsubst org-last
(list)
172 "Return the last element of LIST."
175 (defun org-let (list &rest body
)
176 (eval (cons 'let
(cons list body
))))
177 (put 'org-let
'lisp-indent-function
1)
179 (defun org-let2 (list1 list2
&rest body
)
180 (eval (cons 'let
(cons list1
(list (cons 'let
(cons list2 body
)))))))
181 (put 'org-let2
'lisp-indent-function
2)
183 (defsubst org-call-with-arg
(command arg
)
184 "Call COMMAND interactively, but pretend prefix are was ARG."
185 (let ((current-prefix-arg arg
)) (call-interactively command
)))
187 (defsubst org-current-line
(&optional pos
)
189 (and pos
(goto-char pos
))
190 ;; works also in narrowed buffer, because we start at 1, not point-min
191 (+ (if (bolp) 1 0) (count-lines 1 (point)))))
193 (defsubst org-pos-in-match-range
(pos n
)
194 (and (match-beginning n
)
195 (<= (match-beginning n
) pos
)
196 (>= (match-end n
) pos
)))
198 (defun org-autoload (file functions
)
199 "Establish autoload for all FUNCTIONS in FILE, if not boutd already."
200 (let ((d (format "Documentation will be available after `%s.el' is loaded."
203 (while (setq f
(pop functions
))
204 (or (fboundp f
) (autoload f file d t
)))))
206 (defun org-match-line (re)
207 "Looking-at at the beginning of the current line."
209 (goto-char (point-at-bol))
212 (defun org-plist-delete (plist property
)
213 "Delete PROPERTY from PLIST.
214 This is in contrast to merely setting it to 0."
217 (if (not (eq property
(car plist
)))
218 (setq p
(plist-put p
(car plist
) (nth 1 plist
))))
219 (setq plist
(cddr plist
)))
224 ;;; org-macs.el ends here