1 ;;; org.el --- Outline-based notes management and organizer
2 ;; Carstens outline-mode for keeping track of everything.
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
30 ;; project planning with a fast and effective plain-text system.
32 ;; Org-mode develops organizational tasks around NOTES files that contain
33 ;; information about projects as plain text. Org-mode is implemented on
34 ;; top of outline-mode, which makes it possible to keep the content of
35 ;; large files well structured. Visibility cycling and structure editing
36 ;; help to work with the tree. Tables are easily created with a built-in
37 ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
38 ;; and scheduling. It dynamically compiles entries into an agenda that
39 ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
40 ;; Plain text URL-like links connect to websites, emails, Usenet
41 ;; messages, BBDB entries, and any files related to the projects. For
42 ;; printing and sharing of notes, an Org-mode file can be exported as a
43 ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
44 ;; iCalendar file. It can also serve as a publishing tool for a set of
47 ;; Installation and Activation
48 ;; ---------------------------
49 ;; See the corresponding sections in the manual at
51 ;; http://orgmode.org/org.html#Installation
55 ;; The documentation of Org-mode can be found in the TeXInfo file. The
56 ;; distribution also contains a PDF version of it. At the homepage of
57 ;; Org-mode, you can read the same text online as HTML. There is also an
58 ;; excellent reference card made by Philip Rooke. This card can be found
59 ;; in the etc/ directory of Emacs 22.
61 ;; A list of recent changes can be found at
62 ;; http://orgmode.org/Changes.html
66 (defvar org-inhibit-highlight-removal nil
) ; dynamically scoped param
67 (defvar org-table-formula-constants-local nil
68 "Local version of `org-table-formula-constants'.")
69 (make-variable-buffer-local 'org-table-formula-constants-local
)
71 ;;;; Require other packages
78 ;; Emacs 22 calendar compatibility: Make sure the new variables are available
79 (unless (boundp 'calendar-view-holidays-initially-flag
)
80 (defvaralias 'calendar-view-holidays-initially-flag
81 'view-calendar-holidays-initially
))
82 (unless (boundp 'calendar-view-diary-initially-flag
)
83 (defvaralias 'calendar-view-diary-initially-flag
84 'view-diary-entries-initially
))
85 (unless (boundp 'diary-fancy-buffer
)
86 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
))
88 ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
89 ;; the file noutline.el being loaded.
90 (if (featurep 'xemacs
) (condition-case nil
(require 'noutline
)))
91 ;; We require noutline, which might be provided in outline.el
92 (require 'outline
) (require 'noutline
)
93 ;; Other stuff we need.
95 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
100 (require 'org-entities
)
101 (require 'org-compat
)
105 (require 'org-footnote
)
107 ;;;; Customization variables
111 (defconst org-version
"6.36trans"
112 "The version number of the file org.el.")
114 (defun org-version (&optional here
)
115 "Show the org-mode version in the echo area.
116 With prefix arg HERE, insert it at point."
118 (let* ((origin default-directory
)
119 (version org-version
)
121 (dir (concat (file-name-directory (locate-library "org")) "../" )))
122 (when (and (file-exists-p (expand-file-name ".git" dir
))
123 (executable-find "git"))
127 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
128 (with-current-buffer "*Shell Command Output*"
129 (goto-char (point-min))
130 (setq git-version
(buffer-substring (point) (point-at-eol))))
131 (subst-char-in-string ?- ?. git-version t
)
132 (when (string-match "\\S-"
133 (shell-command-to-string
134 "git diff-index --name-only HEAD --"))
135 (setq git-version
(concat git-version
".dirty")))
136 (setq version
(concat version
" (" git-version
")"))))
138 (setq version
(format "Org-mode version %s" version
))
139 (if here
(insert version
))
142 ;;; Compatibility constants
144 ;;; The custom variables
147 "Outline-based notes management and organizer."
152 (defcustom org-mode-hook nil
153 "Mode hook for Org-mode, run after the mode was turned on."
157 (defcustom org-load-hook nil
158 "Hook that is run after org.el has been loaded."
162 (defvar org-modules
) ; defined below
163 (defvar org-modules-loaded nil
164 "Have the modules been loaded already?")
166 (defun org-load-modules-maybe (&optional force
)
167 "Load all extensions listed in `org-modules'."
168 (when (or force
(not org-modules-loaded
))
170 (condition-case nil
(require ext
)
171 (error (message "Problems while trying to load feature `%s'" ext
))))
173 (setq org-modules-loaded t
)))
175 (defun org-set-modules (var value
)
176 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
178 (when (featurep 'org
)
179 (org-load-modules-maybe 'force
)))
181 (when (org-bound-and-true-p org-modules
)
182 (let ((a (member 'org-infojs org-modules
)))
183 (and a
(setcar a
'org-jsinfo
))))
185 (defcustom org-modules
'(org-bbdb org-bibtex org-docview org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-w3m org-wl
)
186 "Modules that should always be loaded together with org.el.
187 If a description starts with <C>, the file is not part of Emacs
188 and loading it will require that you have downloaded and properly installed
189 the org-mode distribution.
191 You can also use this system to load external packages (i.e. neither Org
192 core modules, nor modules from the CONTRIB directory). Just add symbols
193 to the end of the list. If the package is called org-xyz.el, then you need
194 to add the symbol `xyz', and the package must have a call to
198 :set
'org-set-modules
201 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
202 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
203 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
204 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
205 (const :tag
" docview: Links to doc-view buffers" org-docview
)
206 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
207 (const :tag
" id: Global IDs for identifying entries" org-id
)
208 (const :tag
" info: Links to Info nodes" org-info
)
209 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
210 (const :tag
" habit: Track your consistency with habits" org-habit
)
211 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
212 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
213 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
214 (const :tag
" mew Links to Mew folders/messages" org-mew
)
215 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
216 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
217 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
218 (const :tag
" vm: Links to VM folders/messages" org-vm
)
219 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
220 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
221 (const :tag
" mouse: Additional mouse support" org-mouse
)
223 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
224 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
225 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
226 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
227 (const :tag
"C collector: Collect properties into tables" org-collector
)
228 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
229 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
230 (const :tag
"C eval: Include command output as text" org-eval
)
231 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
232 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
233 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
234 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
235 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
237 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
239 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
240 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
241 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
242 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
243 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
244 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
245 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
246 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
247 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
248 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
249 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
250 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
251 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
252 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
253 (const :tag
"C track: Keep up with Org-mode development" org-track
)
254 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
256 (defcustom org-support-shift-select nil
257 "Non-nil means make shift-cursor commands select text when possible.
259 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
260 selecting a region, or enlarge thusly regions started in this way.
261 In Org-mode, in special contexts, these same keys are used for other
262 purposes, important enough to compete with shift selection. Org tries
263 to balance these needs by supporting `shift-select-mode' outside these
264 special contexts, under control of this variable.
266 The default of this variable is nil, to avoid confusing behavior. Shifted
267 cursor keys will then execute Org commands in the following contexts:
268 - on a headline, changing TODO state (left/right) and priority (up/down)
269 - on a time stamp, changing the time
270 - in a plain list item, changing the bullet type
271 - in a property definition line, switching between allowed values
272 - in the BEGIN line of a clock table (changing the time block).
273 Outside these contexts, the commands will throw an error.
275 When this variable is t and the cursor is not in a special context,
276 Org-mode will support shift-selection for making and enlarging regions.
277 To make this more effective, the bullet cycling will no longer happen
278 anywhere in an item line, but only if the cursor is exactly on the bullet.
280 If you set this variable to the symbol `always', then the keys
281 will not be special in headlines, property lines, and item lines, to make
282 shift selection work there as well. If this is what you want, you can
283 use the following alternative commands: `C-c C-t' and `C-c ,' to
284 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
285 TODO sets, `C-c -' to cycle item bullet types, and properties can be
286 edited by hand or in column view.
288 However, when the cursor is on a timestamp, shift-cursor commands
289 will still edit the time stamp - this is just too good to give up.
291 XEmacs user should have this variable set to nil, because shift-select-mode
295 (const :tag
"Never" nil
)
296 (const :tag
"When outside special context" t
)
297 (const :tag
"Everywhere except timestamps" always
)))
299 (defgroup org-startup nil
300 "Options concerning startup of Org-mode."
304 (defcustom org-startup-folded t
305 "Non-nil means entering Org-mode will switch to OVERVIEW.
306 This can also be configured on a per-file basis by adding one of
307 the following lines anywhere in the buffer:
309 #+STARTUP: fold (or `overview', this is equivalent)
310 #+STARTUP: nofold (or `showall', this is equivalent)
312 #+STARTUP: showeverything"
315 (const :tag
"nofold: show all" nil
)
316 (const :tag
"fold: overview" t
)
317 (const :tag
"content: all headlines" content
)
318 (const :tag
"show everything, even drawers" showeverything
)))
320 (defcustom org-startup-truncated t
321 "Non-nil means entering Org-mode will set `truncate-lines'.
322 This is useful since some lines containing links can be very long and
323 uninteresting. Also tables look terrible when wrapped."
327 (defcustom org-startup-indented nil
328 "Non-nil means turn on `org-indent-mode' on startup.
329 This can also be configured on a per-file basis by adding one of
330 the following lines anywhere in the buffer:
334 :group
'org-structure
336 (const :tag
"Not" nil
)
337 (const :tag
"Globally (slow on startup in large files)" t
)))
339 (defcustom org-startup-with-beamer-mode nil
340 "Non-nil means turn on `org-beamer-mode' on startup.
341 This can also be configured on a per-file basis by adding one of
342 the following lines anywhere in the buffer:
348 (defcustom org-startup-align-all-tables nil
349 "Non-nil means align all tables when visiting a file.
350 This is useful when the column width in tables is forced with <N> cookies
351 in table fields. Such tables will look correct only after the first re-align.
352 This can also be configured on a per-file basis by adding one of
353 the following lines anywhere in the buffer:
359 (defcustom org-insert-mode-line-in-empty-file nil
360 "Non-nil means insert the first line setting Org-mode in empty files.
361 When the function `org-mode' is called interactively in an empty file, this
362 normally means that the file name does not automatically trigger Org-mode.
363 To ensure that the file will always be in Org-mode in the future, a
364 line enforcing Org-mode will be inserted into the buffer, if this option
369 (defcustom org-replace-disputed-keys nil
370 "Non-nil means use alternative key bindings for some keys.
371 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
372 These keys are also used by other packages like shift-selection-mode'
373 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
374 If you want to use Org-mode together with one of these other modes,
375 or more generally if you would like to move some Org-mode commands to
376 other keys, set this variable and configure the keys with the variable
379 This option is only relevant at load-time of Org-mode, and must be set
380 *before* org.el is loaded. Changing it requires a restart of Emacs to
385 (defcustom org-use-extra-keys nil
386 "Non-nil means use extra key sequence definitions for certain
387 commands. This happens automatically if you run XEmacs or if
388 window-system is nil. This variable lets you do the same
389 manually. You must set it before loading org.
391 Example: on Carbon Emacs 22 running graphically, with an external
392 keyboard on a Powerbook, the default way of setting M-left might
393 not work for either Alt or ESC. Setting this variable will make
398 (if (fboundp 'defvaralias
)
399 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
401 (defcustom org-disputed-keys
402 '(([(shift up
)] .
[(meta p
)])
403 ([(shift down
)] .
[(meta n
)])
404 ([(shift left
)] .
[(meta -
)])
405 ([(shift right
)] .
[(meta +)])
406 ([(control shift right
)] .
[(meta shift
+)])
407 ([(control shift left
)] .
[(meta shift -
)]))
408 "Keys for which Org-mode and other modes compete.
409 This is an alist, cars are the default keys, second element specifies
410 the alternative to use when `org-replace-disputed-keys' is t.
412 Keys can be specified in any syntax supported by `define-key'.
413 The value of this option takes effect only at Org-mode's startup,
414 therefore you'll have to restart Emacs to apply it after changing."
419 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
420 Or return the original if not disputed.
421 Also apply the trnaslations defined in `org-xemacs-key-equivalents'."
422 (when org-replace-disputed-keys
423 (let* ((nkey (key-description key
))
424 (x (org-find-if (lambda (x)
425 (equal (key-description (car x
)) nkey
))
427 (setq key
(if x
(cdr x
) key
))))
428 (when (featurep 'xemacs
)
429 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
432 (defun org-find-if (predicate seq
)
435 (if (funcall predicate
(car seq
))
436 (throw 'exit
(car seq
))
439 (defun org-defkey (keymap key def
)
440 "Define a key, possibly translated, as returned by `org-key'."
441 (define-key keymap
(org-key key
) def
))
443 (defcustom org-ellipsis nil
444 "The ellipsis to use in the Org-mode outline.
445 When nil, just use the standard three dots. When a string, use that instead,
446 When a face, use the standard 3 dots, but with the specified face.
447 The change affects only Org-mode (which will then use its own display table).
448 Changing this requires executing `M-x org-mode' in a buffer to become
451 :type
'(choice (const :tag
"Default" nil
)
452 (face :tag
"Face" :value org-warning
)
453 (string :tag
"String" :value
"...#")))
455 (defvar org-display-table nil
456 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
458 (defgroup org-keywords nil
459 "Keywords in Org-mode."
463 (defcustom org-deadline-string
"DEADLINE:"
464 "String to mark deadline entries.
465 A deadline is this string, followed by a time stamp. Should be a word,
466 terminated by a colon. You can insert a schedule keyword and
467 a timestamp with \\[org-deadline].
468 Changes become only effective after restarting Emacs."
472 (defcustom org-scheduled-string
"SCHEDULED:"
473 "String to mark scheduled TODO entries.
474 A schedule is this string, followed by a time stamp. Should be a word,
475 terminated by a colon. You can insert a schedule keyword and
476 a timestamp with \\[org-schedule].
477 Changes become only effective after restarting Emacs."
481 (defcustom org-closed-string
"CLOSED:"
482 "String used as the prefix for timestamps logging closing a TODO entry."
486 (defcustom org-clock-string
"CLOCK:"
487 "String used as prefix for timestamps clocking work hours on an item."
491 (defcustom org-comment-string
"COMMENT"
492 "Entries starting with this keyword will never be exported.
493 An entry can be toggled between COMMENT and normal with
494 \\[org-toggle-comment].
495 Changes become only effective after restarting Emacs."
499 (defcustom org-quote-string
"QUOTE"
500 "Entries starting with this keyword will be exported in fixed-width font.
501 Quoting applies only to the text in the entry following the headline, and does
502 not extend beyond the next headline, even if that is lower level.
503 An entry can be toggled between QUOTE and normal with
504 \\[org-toggle-fixed-width-section]."
508 (defconst org-repeat-re
509 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
510 "Regular expression for specifying repeated events.
511 After a match, group 1 contains the repeat expression.")
513 (defgroup org-structure nil
514 "Options concerning the general structure of Org-mode files."
518 (defgroup org-reveal-location nil
519 "Options about how to make context of a location visible."
520 :tag
"Org Reveal Location"
521 :group
'org-structure
)
523 (defconst org-context-choice
525 (const :tag
"Always" t
)
526 (const :tag
"Never" nil
)
527 (repeat :greedy t
:tag
"Individual contexts"
529 (choice :tag
"Context"
536 (const bookmark-jump
)
540 "Contexts for the reveal options.")
542 (defcustom org-show-hierarchy-above
'((default . t
))
543 "Non-nil means show full hierarchy when revealing a location.
544 Org-mode often shows locations in an org-mode file which might have
545 been invisible before. When this is set, the hierarchy of headings
546 above the exposed location is shown.
547 Turning this off for example for sparse trees makes them very compact.
548 Instead of t, this can also be an alist specifying this option for different
549 contexts. Valid contexts are
550 agenda when exposing an entry from the agenda
551 org-goto when using the command `org-goto' on key C-c C-j
552 occur-tree when using the command `org-occur' on key C-c /
553 tags-tree when constructing a sparse tree based on tags matches
554 link-search when exposing search matches associated with a link
555 mark-goto when exposing the jump goal of a mark
556 bookmark-jump when exposing a bookmark location
557 isearch when exiting from an incremental search
558 default default for all contexts not set explicitly"
559 :group
'org-reveal-location
560 :type org-context-choice
)
562 (defcustom org-show-following-heading
'((default . nil
))
563 "Non-nil means show following heading when revealing a location.
564 Org-mode often shows locations in an org-mode file which might have
565 been invisible before. When this is set, the heading following the
567 Turning this off for example for sparse trees makes them very compact,
568 but makes it harder to edit the location of the match. In such a case,
569 use the command \\[org-reveal] to show more context.
570 Instead of t, this can also be an alist specifying this option for different
571 contexts. See `org-show-hierarchy-above' for valid contexts."
572 :group
'org-reveal-location
573 :type org-context-choice
)
575 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
576 "Non-nil means show all sibling heading when revealing a location.
577 Org-mode often shows locations in an org-mode file which might have
578 been invisible before. When this is set, the sibling of the current entry
579 heading are all made visible. If `org-show-hierarchy-above' is t,
580 the same happens on each level of the hierarchy above the current entry.
582 By default this is on for the isearch context, off for all other contexts.
583 Turning this off for example for sparse trees makes them very compact,
584 but makes it harder to edit the location of the match. In such a case,
585 use the command \\[org-reveal] to show more context.
586 Instead of t, this can also be an alist specifying this option for different
587 contexts. See `org-show-hierarchy-above' for valid contexts."
588 :group
'org-reveal-location
589 :type org-context-choice
)
591 (defcustom org-show-entry-below
'((default . nil
))
592 "Non-nil means show the entry below a headline when revealing a location.
593 Org-mode often shows locations in an org-mode file which might have
594 been invisible before. When this is set, the text below the headline that is
595 exposed is also shown.
597 By default this is off for all contexts.
598 Instead of t, this can also be an alist specifying this option for different
599 contexts. See `org-show-hierarchy-above' for valid contexts."
600 :group
'org-reveal-location
601 :type org-context-choice
)
603 (defcustom org-indirect-buffer-display
'other-window
604 "How should indirect tree buffers be displayed?
605 This applies to indirect buffers created with the commands
606 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
608 current-window Display in the current window
609 other-window Just display in another window.
610 dedicated-frame Create one new frame, and re-use it each time.
611 new-frame Make a new frame each time. Note that in this case
612 previously-made indirect buffers are kept, and you need to
613 kill these buffers yourself."
614 :group
'org-structure
615 :group
'org-agenda-windows
617 (const :tag
"In current window" current-window
)
618 (const :tag
"In current frame, other window" other-window
)
619 (const :tag
"Each time a new frame" new-frame
)
620 (const :tag
"One dedicated frame" dedicated-frame
)))
622 (defcustom org-use-speed-commands nil
623 "Non-nil means activate single letter commands at beginning of a headline.
624 This may also be a function to test for appropriate locations where speed
625 commands should be active."
626 :group
'org-structure
628 (const :tag
"Never" nil
)
629 (const :tag
"At beginning of headline stars" t
)
632 (defcustom org-speed-commands-user nil
633 "Alist of additional speed commands.
634 This list will be checked before `org-speed-commands-default'
635 when the variable `org-use-speed-commands' is non-nil
636 and when the cursor is at the beginning of a headline.
637 The car if each entry is a string with a single letter, which must
638 be assigned to `self-insert-command' in the global map.
639 The cdr is either a command to be called interactively, a function
640 to be called, or a form to be evaluated.
641 An entry that is just a list with a single string will be interpreted
642 as a descriptive headline that will be added when listing the speed
643 copmmands in the Help buffer using the `?' speed command."
644 :group
'org-structure
645 :type
'(repeat :value
("k" . ignore
)
646 (choice :value
("k" . ignore
)
647 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
648 (cons :tag
"Letter and Command"
649 (string :tag
"Command letter")
654 (defgroup org-cycle nil
655 "Options concerning visibility cycling in Org-mode."
657 :group
'org-structure
)
659 (defcustom org-cycle-skip-children-state-if-no-children t
660 "Non-nil means skip CHILDREN state in entries that don't have any."
664 (defcustom org-cycle-max-level nil
665 "Maximum level which should still be subject to visibility cycling.
666 Levels higher than this will, for cycling, be treated as text, not a headline.
667 When `org-odd-levels-only' is set, a value of N in this variable actually
668 means 2N-1 stars as the limiting headline.
669 When nil, cycle all levels.
670 Note that the limiting level of cycling is also influenced by
671 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
672 `org-inlinetask-min-level' is, cycling will be limited to levels one less
676 (const :tag
"No limit" nil
)
677 (integer :tag
"Maximum level")))
679 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
680 "Names of drawers. Drawers are not opened by cycling on the headline above.
681 Drawers only open with a TAB on the drawer line itself. A drawer looks like
686 The drawer \"PROPERTIES\" is special for capturing properties through
689 Drawers can be defined on the per-file basis with a line like:
691 #+DRAWERS: HIDDEN STATE PROPERTIES"
692 :group
'org-structure
694 :type
'(repeat (string :tag
"Drawer Name")))
696 (defcustom org-hide-block-startup nil
697 "Non-nil means entering Org-mode will fold all blocks.
698 This can also be set in on a per-file basis with
700 #+STARTUP: hideblocks
701 #+STARTUP: showblocks"
706 (defcustom org-cycle-global-at-bob nil
707 "Cycle globally if cursor is at beginning of buffer and not at a headline.
708 This makes it possible to do global cycling without having to use S-TAB or
709 C-u TAB. For this special case to work, the first line of the buffer
710 must not be a headline - it may be empty or some other text. When used in
711 this way, `org-cycle-hook' is disables temporarily, to make sure the
712 cursor stays at the beginning of the buffer.
713 When this option is nil, don't do anything special at the beginning
718 (defcustom org-cycle-level-after-item
/entry-creation t
719 "Non-nil means cycle entry level or item indentation in new empty entries.
721 When the cursor is at the end of an empty headline, i.e with only stars
722 and maybe a TODO keyword, TAB will then switch the entry to become a child,
723 and then all possible anchestor states, before returning to the original state.
724 This makes data entry extremely fast: M-RET to create a new headline,
725 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
727 When the cursor is at the end of an empty plain list item, one TAB will
728 make it a subitem, two or more tabs will back up to make this an item
729 higher up in the item hierarchy."
733 (defcustom org-cycle-emulate-tab t
734 "Where should `org-cycle' emulate TAB.
736 white Only in completely white lines
737 whitestart Only at the beginning of lines, before the first non-white char
738 t Everywhere except in headlines
739 exc-hl-bol Everywhere except at the start of a headline
740 If TAB is used in a place where it does not emulate TAB, the current subtree
741 visibility is cycled."
743 :type
'(choice (const :tag
"Never" nil
)
744 (const :tag
"Only in completely white lines" white
)
745 (const :tag
"Before first char in a line" whitestart
)
746 (const :tag
"Everywhere except in headlines" t
)
747 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
750 (defcustom org-cycle-separator-lines
2
751 "Number of empty lines needed to keep an empty line between collapsed trees.
752 If you leave an empty line between the end of a subtree and the following
753 headline, this empty line is hidden when the subtree is folded.
754 Org-mode will leave (exactly) one empty line visible if the number of
755 empty lines is equal or larger to the number given in this variable.
756 So the default 2 means at least 2 empty lines after the end of a subtree
757 are needed to produce free space between a collapsed subtree and the
760 If the number is negative, and the number of empty lines is at least -N,
761 all empty lines are shown.
763 Special case: when 0, never leave empty lines in collapsed view."
766 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
768 (defcustom org-pre-cycle-hook nil
769 "Hook that is run before visibility cycling is happening.
770 The function(s) in this hook must accept a single argument which indicates
771 the new state that will be set right after running this hook. The
772 argument is a symbol. Before a global state change, it can have the values
773 `overview', `content', or `all'. Before a local state change, it can have
774 the values `folded', `children', or `subtree'."
778 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
779 org-cycle-hide-drawers
780 org-cycle-show-empty-lines
781 org-optimize-window-after-visibility-change
)
782 "Hook that is run after `org-cycle' has changed the buffer visibility.
783 The function(s) in this hook must accept a single argument which indicates
784 the new state that was set by the most recent `org-cycle' command. The
785 argument is a symbol. After a global state change, it can have the values
786 `overview', `content', or `all'. After a local state change, it can have
787 the values `folded', `children', or `subtree'."
791 (defgroup org-edit-structure nil
792 "Options concerning structure editing in Org-mode."
793 :tag
"Org Edit Structure"
794 :group
'org-structure
)
796 (defcustom org-odd-levels-only nil
797 "Non-nil means skip even levels and only use odd levels for the outline.
798 This has the effect that two stars are being added/taken away in
799 promotion/demotion commands. It also influences how levels are
800 handled by the exporters.
801 Changing it requires restart of `font-lock-mode' to become effective
802 for fontification also in regions already fontified.
803 You may also set this on a per-file basis by adding one of the following
808 :group
'org-edit-structure
809 :group
'org-appearance
812 (defcustom org-adapt-indentation t
813 "Non-nil means adapt indentation to outline node level.
815 When this variable is set, Org assumes that you write outlines by
816 indenting text in each node to align with the headline (after the stars).
817 The following issues are influenced by this variable:
819 - When this is set and the *entire* text in an entry is indented, the
820 indentation is increased by one space in a demotion command, and
821 decreased by one in a promotion command. If any line in the entry
822 body starts with text at column 0, indentation is not changed at all.
824 - Property drawers and planning information is inserted indented when
825 this variable s set. When nil, they will not be indented.
827 - TAB indents a line relative to context. The lines below a headline
828 will be indented when this variable is set.
830 Note that this is all about true indentation, by adding and removing
831 space characters. See also `org-indent.el' which does level-dependent
832 indentation in a virtual way, i.e. at display time in Emacs."
833 :group
'org-edit-structure
836 (defcustom org-special-ctrl-a
/e nil
837 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
839 When t, `C-a' will bring back the cursor to the beginning of the
840 headline text, i.e. after the stars and after a possible TODO keyword.
841 In an item, this will be the position after the bullet.
842 When the cursor is already at that position, another `C-a' will bring
843 it to the beginning of the line.
845 `C-e' will jump to the end of the headline, ignoring the presence of tags
846 in the headline. A second `C-e' will then jump to the true end of the
847 line, after any tags. This also means that, when this variable is
848 non-nil, `C-e' also will never jump beyond the end of the heading of a
849 folded section, i.e. not after the ellipses.
851 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
852 going to the true line boundary first. Only a directly following, identical
853 keypress will bring the cursor to the special positions.
855 This may also be a cons cell where the behavior for `C-a' and `C-e' is
857 :group
'org-edit-structure
859 (const :tag
"off" nil
)
860 (const :tag
"on: after stars/bullet and before tags first" t
)
861 (const :tag
"reversed: true line boundary first" reversed
)
862 (cons :tag
"Set C-a and C-e separately"
863 (choice :tag
"Special C-a"
864 (const :tag
"off" nil
)
865 (const :tag
"on: after stars/bullet first" t
)
866 (const :tag
"reversed: before stars/bullet first" reversed
))
867 (choice :tag
"Special C-e"
868 (const :tag
"off" nil
)
869 (const :tag
"on: before tags first" t
)
870 (const :tag
"reversed: after tags first" reversed
)))))
871 (if (fboundp 'defvaralias
)
872 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
874 (defcustom org-special-ctrl-k nil
875 "Non-nil means `C-k' will behave specially in headlines.
876 When nil, `C-k' will call the default `kill-line' command.
877 When t, the following will happen while the cursor is in the headline:
879 - When the cursor is at the beginning of a headline, kill the entire
880 line and possible the folded subtree below the line.
881 - When in the middle of the headline text, kill the headline up to the tags.
882 - When after the headline text, kill the tags."
883 :group
'org-edit-structure
886 (defcustom org-yank-folded-subtrees t
887 "Non-nil means when yanking subtrees, fold them.
888 If the kill is a single subtree, or a sequence of subtrees, i.e. if
889 it starts with a heading and all other headings in it are either children
890 or siblings, then fold all the subtrees. However, do this only if no
891 text after the yank would be swallowed into a folded tree by this action."
892 :group
'org-edit-structure
895 (defcustom org-yank-adjusted-subtrees nil
896 "Non-nil means when yanking subtrees, adjust the level.
897 With this setting, `org-paste-subtree' is used to insert the subtree, see
898 this function for details."
899 :group
'org-edit-structure
902 (defcustom org-M-RET-may-split-line
'((default . t
))
903 "Non-nil means M-RET will split the line at the cursor position.
904 When nil, it will go to the end of the line before making a
906 You may also set this option in a different way for different
907 contexts. Valid contexts are:
909 headline when creating a new headline
910 item when creating a new item
911 table in a table field
912 default the value to be used for all contexts not explicitly
914 :group
'org-structure
917 (const :tag
"Always" t
)
918 (const :tag
"Never" nil
)
919 (repeat :greedy t
:tag
"Individual contexts"
921 (choice :tag
"Context"
929 (defcustom org-insert-heading-respect-content nil
930 "Non-nil means insert new headings after the current subtree.
931 When nil, the new heading is created directly after the current line.
932 The commands \\[org-insert-heading-respect-content] and
933 \\[org-insert-todo-heading-respect-content] turn this variable on
934 for the duration of the command."
935 :group
'org-structure
938 (defcustom org-blank-before-new-entry
'((heading . auto
)
939 (plain-list-item . auto
))
940 "Should `org-insert-heading' leave a blank line before new heading/item?
941 The value is an alist, with `heading' and `plain-list-item' as car,
942 and a boolean flag as cdr. For plain lists, if the variable
943 `org-empty-line-terminates-plain-lists' is set, the setting here
944 is ignored and no empty line is inserted, to keep the list in tact."
945 :group
'org-edit-structure
947 (cons (const heading
)
948 (choice (const :tag
"Never" nil
)
949 (const :tag
"Always" t
)
950 (const :tag
"Auto" auto
)))
951 (cons (const plain-list-item
)
952 (choice (const :tag
"Never" nil
)
953 (const :tag
"Always" t
)
954 (const :tag
"Auto" auto
)))))
956 (defcustom org-insert-heading-hook nil
957 "Hook being run after inserting a new heading."
958 :group
'org-edit-structure
961 (defcustom org-enable-fixed-width-editor t
962 "Non-nil means lines starting with \":\" are treated as fixed-width.
963 This currently only means they are never auto-wrapped.
964 When nil, such lines will be treated like ordinary lines.
965 See also the QUOTE keyword."
966 :group
'org-edit-structure
970 (defcustom org-goto-auto-isearch t
971 "Non-nil means typing characters in org-goto starts incremental search."
972 :group
'org-edit-structure
975 (defgroup org-sparse-trees nil
976 "Options concerning sparse trees in Org-mode."
977 :tag
"Org Sparse Trees"
978 :group
'org-structure
)
980 (defcustom org-highlight-sparse-tree-matches t
981 "Non-nil means highlight all matches that define a sparse tree.
982 The highlights will automatically disappear the next time the buffer is
983 changed by an edit command."
984 :group
'org-sparse-trees
987 (defcustom org-remove-highlights-with-change t
988 "Non-nil means any change to the buffer will remove temporary highlights.
989 Such highlights are created by `org-occur' and `org-clock-display'.
990 When nil, `C-c C-c needs to be used to get rid of the highlights.
991 The highlights created by `org-preview-latex-fragment' always need
992 `C-c C-c' to be removed."
993 :group
'org-sparse-trees
998 (defcustom org-occur-hook
'(org-first-headline-recenter)
999 "Hook that is run after `org-occur' has constructed a sparse tree.
1000 This can be used to recenter the window to show as much of the structure
1002 :group
'org-sparse-trees
1005 (defgroup org-imenu-and-speedbar nil
1006 "Options concerning imenu and speedbar in Org-mode."
1007 :tag
"Org Imenu and Speedbar"
1008 :group
'org-structure
)
1010 (defcustom org-imenu-depth
2
1011 "The maximum level for Imenu access to Org-mode headlines.
1012 This also applied for speedbar access."
1013 :group
'org-imenu-and-speedbar
1016 (defgroup org-table nil
1017 "Options concerning tables in Org-mode."
1021 (defcustom org-enable-table-editor
'optimized
1022 "Non-nil means lines starting with \"|\" are handled by the table editor.
1023 When nil, such lines will be treated like ordinary lines.
1025 When equal to the symbol `optimized', the table editor will be optimized to
1027 - Automatic overwrite mode in front of whitespace in table fields.
1028 This makes the structure of the table stay in tact as long as the edited
1029 field does not exceed the column width.
1030 - Minimize the number of realigns. Normally, the table is aligned each time
1031 TAB or RET are pressed to move to another field. With optimization this
1032 happens only if changes to a field might have changed the column width.
1033 Optimization requires replacing the functions `self-insert-command',
1034 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1035 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1036 very good at guessing when a re-align will be necessary, but you can always
1037 force one with \\[org-ctrl-c-ctrl-c].
1039 If you would like to use the optimized version in Org-mode, but the
1040 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1042 This variable can be used to turn on and off the table editor during a session,
1043 but in order to toggle optimization, a restart is required.
1045 See also the variable `org-table-auto-blank-field'."
1048 (const :tag
"off" nil
)
1050 (const :tag
"on, optimized" optimized
)))
1052 (defcustom org-self-insert-cluster-for-undo t
1053 "Non-nil means cluster self-insert commands for undo when possible.
1054 If this is set, then, like in the Emacs command loop, 20 consecutive
1055 characters will be undone together.
1056 This is configurable, because there is some impact on typing performance."
1060 (defcustom org-table-tab-recognizes-table.el t
1061 "Non-nil means TAB will automatically notice a table.el table.
1062 When it sees such a table, it moves point into it and - if necessary -
1063 calls `table-recognize-table'."
1064 :group
'org-table-editing
1067 (defgroup org-link nil
1068 "Options concerning links in Org-mode."
1072 (defvar org-link-abbrev-alist-local nil
1073 "Buffer-local version of `org-link-abbrev-alist', which see.
1074 The value of this is taken from the #+LINK lines.")
1075 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1077 (defcustom org-link-abbrev-alist nil
1078 "Alist of link abbreviations.
1079 The car of each element is a string, to be replaced at the start of a link.
1080 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1081 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1083 [[linkkey:tag][description]]
1085 The 'linkkey' must be a word word, starting with a letter, followed
1086 by letters, numbers, '-' or '_'.
1088 If REPLACE is a string, the tag will simply be appended to create the link.
1089 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1090 the placeholder \"%h\" will cause a url-encoded version of the tag to
1091 be inserted at that point (see the function `url-hexify-string').
1093 REPLACE may also be a function that will be called with the tag as the
1094 only argument to create the link, which should be returned as a string.
1096 See the manual for examples."
1100 (string :tag
"Protocol")
1102 (string :tag
"Format")
1105 (defcustom org-descriptive-links t
1106 "Non-nil means hide link part and only show description of bracket links.
1107 Bracket links are like [[link][description]]. This variable sets the initial
1108 state in new org-mode buffers. The setting can then be toggled on a
1109 per-buffer basis from the Org->Hyperlinks menu."
1113 (defcustom org-link-file-path-type
'adaptive
1114 "How the path name in file links should be stored.
1117 relative Relative to the current directory, i.e. the directory of the file
1118 into which the link is being inserted.
1119 absolute Absolute path, if possible with ~ for home directory.
1120 noabbrev Absolute path, no abbreviation of home directory.
1121 adaptive Use relative path for files in the current directory and sub-
1122 directories of it. For other files, use an absolute path."
1130 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1131 "Types of links that should be activated in Org-mode files.
1132 This is a list of symbols, each leading to the activation of a certain link
1133 type. In principle, it does not hurt to turn on most link types - there may
1134 be a small gain when turning off unused link types. The types are:
1136 bracket The recommended [[link][description]] or [[link]] links with hiding.
1137 angular Links in angular brackets that may contain whitespace like
1138 <bbdb:Carsten Dominik>.
1139 plain Plain links in normal text, no whitespace, like http://google.com.
1140 radio Text that is matched by a radio target, see manual for details.
1141 tag Tag settings in a headline (link to tag search).
1142 date Time stamps (link to calendar).
1143 footnote Footnote labels.
1145 Changing this variable requires a restart of Emacs to become effective."
1147 :type
'(set :greedy t
1148 (const :tag
"Double bracket links (new style)" bracket
)
1149 (const :tag
"Angular bracket links (old style)" angular
)
1150 (const :tag
"Plain text links" plain
)
1151 (const :tag
"Radio target matches" radio
)
1152 (const :tag
"Tags" tag
)
1153 (const :tag
"Timestamps" date
)
1154 (const :tag
"Footnotes" footnote
)))
1156 (defcustom org-make-link-description-function nil
1157 "Function to use to generate link descriptions from links. If
1158 nil the link location will be used. This function must take two
1159 parameters; the first is the link and the second the description
1160 org-insert-link has generated, and should return the description
1165 (defgroup org-link-store nil
1166 "Options concerning storing links in Org-mode."
1167 :tag
"Org Store Link"
1170 (defcustom org-email-link-description-format
"Email %c: %.30s"
1171 "Format of the description part of a link to an email or usenet message.
1172 The following %-escapes will be replaced by corresponding information:
1174 %F full \"From\" field
1175 %f name, taken from \"From\" field, address if no name
1176 %T full \"To\" field
1177 %t first name in \"To\" field, address if no name
1178 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1179 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1183 You may use normal field width specification between the % and the letter.
1184 This is for example useful to limit the length of the subject.
1186 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1187 :group
'org-link-store
1190 (defcustom org-from-is-user-regexp
1192 (when (and user-mail-address
(not (string= user-mail-address
"")))
1193 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1194 (when (and user-full-name
(not (string= user-full-name
"")))
1195 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1196 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1197 "Regexp matched against the \"From:\" header of an email or usenet message.
1198 It should match if the message is from the user him/herself."
1199 :group
'org-link-store
1202 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1203 "Non-nil means storing a link to an Org file will use entry IDs.
1205 Note that before this variable is even considered, org-id must be loaded,
1206 so please customize `org-modules' and turn it on.
1208 The variable can have the following values:
1210 t Create an ID if needed to make a link to the current entry.
1212 create-if-interactive
1213 If `org-store-link' is called directly (interactively, as a user
1214 command), do create an ID to support the link. But when doing the
1215 job for remember, only use the ID if it already exists. The
1216 purpose of this setting is to avoid proliferation of unwanted
1217 IDs, just because you happen to be in an Org file when you
1218 call `org-remember' that automatically and preemptively
1219 creates a link. If you do want to get an ID link in a remember
1220 template to an entry not having an ID, create it first by
1221 explicitly creating a link to it, using `C-c C-l' first.
1223 create-if-interactive-and-no-custom-id
1224 Like create-if-interactive, but do not create an ID if there is
1225 a CUSTOM_ID property defined in the entry. This is the default.
1228 Use existing ID, do not create one.
1230 nil Never use an ID to make a link, instead link using a text search for
1232 :group
'org-link-store
1234 (const :tag
"Create ID to make link" t
)
1235 (const :tag
"Create if storing link interactively"
1236 create-if-interactive
)
1237 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1238 create-if-interactive-and-no-custom-id
)
1239 (const :tag
"Only use existing" use-existing
)
1240 (const :tag
"Do not use ID to create link" nil
)))
1242 (defcustom org-context-in-file-links t
1243 "Non-nil means file links from `org-store-link' contain context.
1244 A search string will be added to the file name with :: as separator and
1245 used to find the context when the link is activated by the command
1246 `org-open-at-point'.
1247 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1248 negates this setting for the duration of the command."
1249 :group
'org-link-store
1252 (defcustom org-keep-stored-link-after-insertion nil
1253 "Non-nil means keep link in list for entire session.
1255 The command `org-store-link' adds a link pointing to the current
1256 location to an internal list. These links accumulate during a session.
1257 The command `org-insert-link' can be used to insert links into any
1258 Org-mode file (offering completion for all stored links). When this
1259 option is nil, every link which has been inserted once using \\[org-insert-link]
1260 will be removed from the list, to make completing the unused links
1262 :group
'org-link-store
1265 (defgroup org-link-follow nil
1266 "Options concerning following links in Org-mode."
1267 :tag
"Org Follow Link"
1270 (defcustom org-link-translation-function nil
1271 "Function to translate links with different syntax to Org syntax.
1272 This can be used to translate links created for example by the Planner
1273 or emacs-wiki packages to Org syntax.
1274 The function must accept two parameters, a TYPE containing the link
1275 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1276 which is everything after the link protocol. It should return a cons
1277 with possibly modified values of type and path.
1278 Org contains a function for this, so if you set this variable to
1279 `org-translate-link-from-planner', you should be able follow many
1280 links created by planner."
1281 :group
'org-link-follow
1284 (defcustom org-follow-link-hook nil
1285 "Hook that is run after a link has been followed."
1286 :group
'org-link-follow
1289 (defcustom org-tab-follows-link nil
1290 "Non-nil means on links TAB will follow the link.
1291 Needs to be set before org.el is loaded.
1292 This really should not be used, it does not make sense, and the
1293 implementation is bad."
1294 :group
'org-link-follow
1297 (defcustom org-return-follows-link nil
1298 "Non-nil means on links RET will follow the link."
1299 :group
'org-link-follow
1302 (defcustom org-mouse-1-follows-link
1303 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1304 "Non-nil means mouse-1 on a link will follow the link.
1305 A longer mouse click will still set point. Does not work on XEmacs.
1306 Needs to be set before org.el is loaded."
1307 :group
'org-link-follow
1310 (defcustom org-mark-ring-length
4
1311 "Number of different positions to be recorded in the ring
1312 Changing this requires a restart of Emacs to work correctly."
1313 :group
'org-link-follow
1316 (defcustom org-link-frame-setup
1317 '((vm . vm-visit-folder-other-frame
)
1318 (gnus . gnus-other-frame
)
1319 (file . find-file-other-window
))
1320 "Setup the frame configuration for following links.
1321 When following a link with Emacs, it may often be useful to display
1322 this link in another window or frame. This variable can be used to
1323 set this up for the different types of links.
1326 `vm-visit-folder-other-frame'
1327 For Gnus, use any of
1330 `org-gnus-no-new-news'
1331 For FILE, use any of
1333 `find-file-other-window'
1334 `find-file-other-frame'
1335 For the calendar, use the variable `calendar-setup'.
1336 For BBDB, it is currently only possible to display the matches in
1338 :group
'org-link-follow
1342 (const vm-visit-folder
)
1343 (const vm-visit-folder-other-window
)
1344 (const vm-visit-folder-other-frame
)))
1348 (const gnus-other-frame
)
1349 (const org-gnus-no-new-news
)))
1353 (const find-file-other-window
)
1354 (const find-file-other-frame
)))))
1356 (defcustom org-display-internal-link-with-indirect-buffer nil
1357 "Non-nil means use indirect buffer to display infile links.
1358 Activating internal links (from one location in a file to another location
1359 in the same file) normally just jumps to the location. When the link is
1360 activated with a C-u prefix (or with mouse-3), the link is displayed in
1361 another window. When this option is set, the other window actually displays
1362 an indirect buffer clone of the current buffer, to avoid any visibility
1363 changes to the current buffer."
1364 :group
'org-link-follow
1367 (defcustom org-open-non-existing-files nil
1368 "Non-nil means `org-open-file' will open non-existing files.
1369 When nil, an error will be generated.
1370 This variable applies only to external applications because they
1371 might choke on non-existing files. If the link is to a file that
1372 will be opened in Emacs, the variable is ignored."
1373 :group
'org-link-follow
1376 (defcustom org-open-directory-means-index-dot-org nil
1377 "Non-nil means a link to a directory really means to index.org.
1378 When nil, following a directory link will run dired or open a finder/explorer
1379 window on that directory."
1380 :group
'org-link-follow
1383 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1384 "Function and arguments to call for following mailto links.
1385 This is a list with the first element being a lisp function, and the
1386 remaining elements being arguments to the function. In string arguments,
1387 %a will be replaced by the address, and %s will be replaced by the subject
1388 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1389 :group
'org-link-follow
1391 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1392 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1393 (const :tag
"message-mail" (message-mail "%a" "%s"))
1394 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1396 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1397 "Non-nil means ask for confirmation before executing shell links.
1398 Shell links can be dangerous: just think about a link
1400 [[shell:rm -rf ~/*][Google Search]]
1402 This link would show up in your Org-mode document as \"Google Search\",
1403 but really it would remove your entire home directory.
1404 Therefore we advise against setting this variable to nil.
1405 Just change it to `y-or-n-p' if you want to confirm with a
1406 single keystroke rather than having to type \"yes\"."
1407 :group
'org-link-follow
1409 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1410 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1411 (const :tag
"no confirmation (dangerous)" nil
)))
1413 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1414 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1415 Elisp links can be dangerous: just think about a link
1417 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1419 This link would show up in your Org-mode document as \"Google Search\",
1420 but really it would remove your entire home directory.
1421 Therefore we advise against setting this variable to nil.
1422 Just change it to `y-or-n-p' if you want to confirm with a
1423 single keystroke rather than having to type \"yes\"."
1424 :group
'org-link-follow
1426 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1427 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1428 (const :tag
"no confirmation (dangerous)" nil
)))
1430 (defconst org-file-apps-defaults-gnu
1434 "Default file applications on a UNIX or GNU/Linux system.
1435 See `org-file-apps'.")
1437 (defconst org-file-apps-defaults-macosx
1440 (system .
"open %s")
1442 ("eps.gz" .
"gv %s")
1444 ("fig" .
"xfig %s"))
1445 "Default file applications on a MacOS X system.
1446 The system \"open\" is known as a default, but we use X11 applications
1447 for some files for which the OS does not have a good default.
1448 See `org-file-apps'.")
1450 (defconst org-file-apps-defaults-windowsnt
1454 (list (if (featurep 'xemacs
)
1455 'mswindows-shell-execute
1459 (list (if (featurep 'xemacs
)
1460 'mswindows-shell-execute
1463 "Default file applications on a Windows NT system.
1464 The system \"open\" is used for most files.
1465 See `org-file-apps'.")
1467 (defcustom org-file-apps
1470 ("\\.mm\\'" . default
)
1471 ("\\.x?html?\\'" . default
)
1472 ("\\.pdf\\'" . default
)
1474 "External applications for opening `file:path' items in a document.
1475 Org-mode uses system defaults for different file types, but
1476 you can use this variable to set the application for a given file
1477 extension. The entries in this list are cons cells where the car identifies
1478 files and the cdr the corresponding command. Possible values for the
1480 \"regex\" Regular expression matched against the file name. For backward
1481 compatibility, this can also be a string with only alphanumeric
1482 characters, which is then interpreted as an extension.
1483 `directory' Matches a directory
1484 `remote' Matches a remote file, accessible through tramp or efs.
1485 Remote files most likely should be visited through Emacs
1486 because external applications cannot handle such paths.
1487 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1488 so all files Emacs knows how to handle. Using this with
1489 command `emacs' will open most files in Emacs. Beware that this
1490 will also open html files inside Emacs, unless you add
1491 (\"html\" . default) to the list as well.
1492 t Default for files not matched by any of the other options.
1493 `system' The system command to open files, like `open' on Windows
1494 and Mac OS X, and mailcap under GNU/Linux. This is the command
1495 that will be selected if you call `C-c C-o' with a double
1498 Possible values for the command are:
1499 `emacs' The file will be visited by the current Emacs process.
1500 `default' Use the default application for this file type, which is the
1501 association for t in the list, most likely in the system-specific
1503 This can be used to overrule an unwanted setting in the
1504 system-specific variable.
1505 `system' Use the system command for opening files, like \"open\".
1506 This command is specified by the entry whose car is `system'.
1507 Most likely, the system-specific version of this variable
1508 does define this command, but you can overrule/replace it
1510 string A command to be executed by a shell; %s will be replaced
1511 by the path to the file.
1512 sexp A Lisp form which will be evaluated. The file path will
1513 be available in the Lisp variable `file'.
1514 For more examples, see the system specific constants
1515 `org-file-apps-defaults-macosx'
1516 `org-file-apps-defaults-windowsnt'
1517 `org-file-apps-defaults-gnu'."
1518 :group
'org-link-follow
1520 (cons (choice :value
""
1521 (string :tag
"Extension")
1522 (const :tag
"System command to open files" system
)
1523 (const :tag
"Default for unrecognized files" t
)
1524 (const :tag
"Remote file" remote
)
1525 (const :tag
"Links to a directory" directory
)
1526 (const :tag
"Any files that have Emacs modes"
1529 (const :tag
"Visit with Emacs" emacs
)
1530 (const :tag
"Use default" default
)
1531 (const :tag
"Use the system command" system
)
1532 (string :tag
"Command")
1533 (sexp :tag
"Lisp form")))))
1537 (defgroup org-refile nil
1538 "Options concerning refiling entries in Org-mode."
1542 (defcustom org-directory
"~/org"
1543 "Directory with org files.
1544 This is just a default location to look for Org files. There is no need
1545 at all to put your files into this directory. It is only used in the
1546 following situations:
1548 1. When a remember template specifies a target file that is not an
1549 absolute path. The path will then be interpreted relative to
1551 2. When a remember note is filed away in an interactive way (when exiting the
1552 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1553 with `org-directory' as the default path."
1555 :group
'org-remember
1558 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1559 "Default target for storing notes.
1560 Used by the hooks for remember.el. This can be a string, or nil to mean
1561 the value of `remember-data-file'.
1562 You can set this on a per-template basis with the variable
1563 `org-remember-templates'."
1565 :group
'org-remember
1567 (const :tag
"Default from remember-data-file" nil
)
1570 (defcustom org-goto-interface
'outline
1571 "The default interface to be used for `org-goto'.
1573 outline The interface shows an outline of the relevant file
1574 and the correct heading is found by moving through
1575 the outline or by searching with incremental search.
1576 outline-path-completion Headlines in the current buffer are offered via
1577 completion. This is the interface also used by
1578 the refile command."
1581 (const :tag
"Outline" outline
)
1582 (const :tag
"Outline-path-completion" outline-path-completion
)))
1584 (defcustom org-goto-max-level
5
1585 "Maximum level to be considered when running org-goto with refile interface."
1589 (defcustom org-reverse-note-order nil
1590 "Non-nil means store new notes at the beginning of a file or entry.
1591 When nil, new notes will be filed to the end of a file or entry.
1592 This can also be a list with cons cells of regular expressions that
1593 are matched against file names, and values."
1594 :group
'org-remember
1597 (const :tag
"Reverse always" t
)
1598 (const :tag
"Reverse never" nil
)
1599 (repeat :tag
"By file name regexp"
1600 (cons regexp boolean
))))
1602 (defcustom org-log-refile nil
1603 "Information to record when a task is refiled.
1605 Possible values are:
1607 nil Don't add anything
1608 time Add a time stamp to the task
1609 note Prompt for a note and add it with template `org-log-note-headings'
1611 This option can also be set with on a per-file-basis with
1613 #+STARTUP: nologrefile
1614 #+STARTUP: logrefile
1615 #+STARTUP: lognoterefile
1617 You can have local logging settings for a subtree by setting the LOGGING
1618 property to one or more of these keywords.
1620 When bulk-refiling from the agenda, the value `note' is forbidden and
1621 will temporarily be changed to `time'."
1623 :group
'org-progress
1625 (const :tag
"No logging" nil
)
1626 (const :tag
"Record timestamp" time
)
1627 (const :tag
"Record timestamp with note." note
)))
1629 (defcustom org-refile-targets nil
1630 "Targets for refiling entries with \\[org-refile].
1631 This is list of cons cells. Each cell contains:
1632 - a specification of the files to be considered, either a list of files,
1633 or a symbol whose function or variable value will be used to retrieve
1634 a file name or a list of file names. If you use `org-agenda-files' for
1635 that, all agenda files will be scanned for targets. Nil means consider
1636 headings in the current buffer.
1637 - A specification of how to find candidate refile targets. This may be
1639 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1640 This tag has to be present in all target headlines, inheritance will
1642 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1644 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1645 headlines that are refiling targets.
1646 - a cons cell (:level . N). Any headline of level N is considered a target.
1647 Note that, when `org-odd-levels-only' is set, level corresponds to
1648 order in hierarchy, not to the number of stars.
1649 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1650 Note that, when `org-odd-levels-only' is set, level corresponds to
1651 order in hierarchy, not to the number of stars.
1653 You can set the variable `org-refile-target-verify-function' to a function
1654 to verify each headline found by the simple critery above.
1656 When this variable is nil, all top-level headlines in the current buffer
1657 are used, equivalent to the value `((nil . (:level . 1))'."
1661 (choice :value org-agenda-files
1662 (const :tag
"All agenda files" org-agenda-files
)
1663 (const :tag
"Current buffer" nil
)
1664 (function) (variable) (file))
1665 (choice :tag
"Identify target headline by"
1666 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1667 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1668 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1669 (cons :tag
"Level number" (const :value
:level
) (integer))
1670 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1672 (defcustom org-refile-target-verify-function nil
1673 "Function to verify if the headline at point should be a refile target.
1674 The function will be called without arguments, with point at the
1675 beginning of the headline. It should return t and leave point
1676 where it is if the headline is a valid target for refiling.
1678 If the target should not be selected, the function must return nil.
1679 In addition to this, it may move point to a place from where the search
1680 should be continued. For example, the function may decide that the entire
1681 subtree of the current entry should be excluded and move point to the end
1686 (defcustom org-refile-use-outline-path nil
1687 "Non-nil means provide refile targets as paths.
1688 So a level 3 headline will be available as level1/level2/level3.
1690 When the value is `file', also include the file name (without directory)
1691 into the path. In this case, you can also stop the completion after
1692 the file name, to get entries inserted as top level in the file.
1694 When `full-file-path', include the full file path."
1697 (const :tag
"Not" nil
)
1698 (const :tag
"Yes" t
)
1699 (const :tag
"Start with file name" file
)
1700 (const :tag
"Start with full file path" full-file-path
)))
1702 (defcustom org-outline-path-complete-in-steps t
1703 "Non-nil means complete the outline path in hierarchical steps.
1704 When Org-mode uses the refile interface to select an outline path
1705 \(see variable `org-refile-use-outline-path'), the completion of
1706 the path can be done is a single go, or if can be done in steps down
1707 the headline hierarchy. Going in steps is probably the best if you
1708 do not use a special completion package like `ido' or `icicles'.
1709 However, when using these packages, going in one step can be very
1710 fast, while still showing the whole path to the entry."
1714 (defcustom org-refile-allow-creating-parent-nodes nil
1715 "Non-nil means allow to create new nodes as refile targets.
1716 New nodes are then created by adding \"/new node name\" to the completion
1717 of an existing node. When the value of this variable is `confirm',
1718 new node creation must be confirmed by the user (recommended)
1719 When nil, the completion must match an existing entry.
1721 Note that, if the new heading is not seen by the criteria
1722 listed in `org-refile-targets', multiple instances of the same
1723 heading would be created by trying again to file under the new
1727 (const :tag
"Never" nil
)
1728 (const :tag
"Always" t
)
1729 (const :tag
"Prompt for confirmation" confirm
)))
1731 (defgroup org-todo nil
1732 "Options concerning TODO items in Org-mode."
1736 (defgroup org-progress nil
1737 "Options concerning Progress logging in Org-mode."
1741 (defvar org-todo-interpretation-widgets
1743 (:tag
"Sequence (cycling hits every state)" sequence
)
1744 (:tag
"Type (cycling directly to DONE)" type
))
1745 "The available interpretation symbols for customizing
1746 `org-todo-keywords'.
1747 Interested libraries should add to this list.")
1749 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1750 "List of TODO entry keyword sequences and their interpretation.
1751 \\<org-mode-map>This is a list of sequences.
1753 Each sequence starts with a symbol, either `sequence' or `type',
1754 indicating if the keywords should be interpreted as a sequence of
1755 action steps, or as different types of TODO items. The first
1756 keywords are states requiring action - these states will select a headline
1757 for inclusion into the global TODO list Org-mode produces. If one of
1758 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1759 signify that no further action is necessary. If \"|\" is not found,
1760 the last keyword is treated as the only DONE state of the sequence.
1762 The command \\[org-todo] cycles an entry through these states, and one
1763 additional state where no keyword is present. For details about this
1764 cycling, see the manual.
1766 TODO keywords and interpretation can also be set on a per-file basis with
1767 the special #+SEQ_TODO and #+TYP_TODO lines.
1769 Each keyword can optionally specify a character for fast state selection
1770 \(in combination with the variable `org-use-fast-todo-selection')
1771 and specifiers for state change logging, using the same syntax
1772 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1773 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1774 indicates to record a time stamp each time this state is selected.
1776 Each keyword may also specify if a timestamp or a note should be
1777 recorded when entering or leaving the state, by adding additional
1778 characters in the parenthesis after the keyword. This looks like this:
1779 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1780 record only the time of the state change. With X and Y being either
1781 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1782 Y when leaving the state if and only if the *target* state does not
1783 define X. You may omit any of the fast-selection key or X or /Y,
1784 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1786 For backward compatibility, this variable may also be just a list
1787 of keywords - in this case the interpretation (sequence or type) will be
1788 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1790 :group
'org-keywords
1792 (repeat :tag
"Old syntax, just keywords"
1793 (string :tag
"Keyword"))
1794 (repeat :tag
"New syntax"
1797 :tag
"Interpretation"
1798 ;;Quick and dirty way to see
1799 ;;`org-todo-interpretations'. This takes the
1800 ;;place of item arguments
1808 org-todo-interpretation-widgets
))
1811 (string :tag
"Keyword"))))))
1813 (defvar org-todo-keywords-1 nil
1814 "All TODO and DONE keywords active in a buffer.")
1815 (make-variable-buffer-local 'org-todo-keywords-1
)
1816 (defvar org-todo-keywords-for-agenda nil
)
1817 (defvar org-done-keywords-for-agenda nil
)
1818 (defvar org-drawers-for-agenda nil
)
1819 (defvar org-todo-keyword-alist-for-agenda nil
)
1820 (defvar org-tag-alist-for-agenda nil
)
1821 (defvar org-agenda-contributing-files nil
)
1822 (defvar org-not-done-keywords nil
)
1823 (make-variable-buffer-local 'org-not-done-keywords
)
1824 (defvar org-done-keywords nil
)
1825 (make-variable-buffer-local 'org-done-keywords
)
1826 (defvar org-todo-heads nil
)
1827 (make-variable-buffer-local 'org-todo-heads
)
1828 (defvar org-todo-sets nil
)
1829 (make-variable-buffer-local 'org-todo-sets
)
1830 (defvar org-todo-log-states nil
)
1831 (make-variable-buffer-local 'org-todo-log-states
)
1832 (defvar org-todo-kwd-alist nil
)
1833 (make-variable-buffer-local 'org-todo-kwd-alist
)
1834 (defvar org-todo-key-alist nil
)
1835 (make-variable-buffer-local 'org-todo-key-alist
)
1836 (defvar org-todo-key-trigger nil
)
1837 (make-variable-buffer-local 'org-todo-key-trigger
)
1839 (defcustom org-todo-interpretation
'sequence
1840 "Controls how TODO keywords are interpreted.
1841 This variable is in principle obsolete and is only used for
1842 backward compatibility, if the interpretation of todo keywords is
1843 not given already in `org-todo-keywords'. See that variable for
1846 :group
'org-keywords
1847 :type
'(choice (const sequence
)
1850 (defcustom org-use-fast-todo-selection t
1851 "Non-nil means use the fast todo selection scheme with C-c C-t.
1852 This variable describes if and under what circumstances the cycling
1853 mechanism for TODO keywords will be replaced by a single-key, direct
1856 When nil, fast selection is never used.
1858 When the symbol `prefix', it will be used when `org-todo' is called with
1859 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1860 in an agenda buffer.
1862 When t, fast selection is used by default. In this case, the prefix
1863 argument forces cycling instead.
1865 In all cases, the special interface is only used if access keys have actually
1866 been assigned by the user, i.e. if keywords in the configuration are followed
1867 by a letter in parenthesis, like TODO(t)."
1870 (const :tag
"Never" nil
)
1871 (const :tag
"By default" t
)
1872 (const :tag
"Only with C-u C-c C-t" prefix
)))
1874 (defcustom org-provide-todo-statistics t
1875 "Non-nil means update todo statistics after insert and toggle.
1876 ALL-HEADLINES means update todo statistics by including headlines
1877 with no TODO keyword as well, counting them as not done.
1878 A list of TODO keywords means the same, but skip keywords that are
1881 When this is set, todo statistics is updated in the parent of the
1882 current entry each time a todo state is changed."
1885 (const :tag
"Yes, only for TODO entries" t
)
1886 (const :tag
"Yes, including all entries" 'all-headlines
)
1887 (repeat :tag
"Yes, for TODOs in this list"
1888 (string :tag
"TODO keyword"))
1889 (other :tag
"No TODO statistics" nil
)))
1891 (defcustom org-hierarchical-todo-statistics t
1892 "Non-nil means TODO statistics covers just direct children.
1893 When nil, all entries in the subtree are considered.
1894 This has only an effect if `org-provide-todo-statistics' is set.
1895 To set this to nil for only a single subtree, use a COOKIE_DATA
1896 property and include the word \"recursive\" into the value."
1900 (defcustom org-after-todo-state-change-hook nil
1901 "Hook which is run after the state of a TODO item was changed.
1902 The new state (a string with a TODO keyword, or nil) is available in the
1903 Lisp variable `state'."
1907 (defvar org-blocker-hook nil
1908 "Hook for functions that are allowed to block a state change.
1910 Each function gets as its single argument a property list, see
1911 `org-trigger-hook' for more information about this list.
1913 If any of the functions in this hook returns nil, the state change
1916 (defvar org-trigger-hook nil
1917 "Hook for functions that are triggered by a state change.
1919 Each function gets as its single argument a property list with at least
1920 the following elements:
1922 (:type type-of-change :position pos-at-entry-start
1923 :from old-state :to new-state)
1925 Depending on the type, more properties may be present.
1927 This mechanism is currently implemented for:
1931 :type todo-state-change
1932 :from previous state (keyword as a string), or nil, or a symbol
1933 'todo' or 'done', to indicate the general type of state.
1934 :to new state, like in :from")
1936 (defcustom org-enforce-todo-dependencies nil
1937 "Non-nil means undone TODO entries will block switching the parent to DONE.
1938 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1939 be blocked if any prior sibling is not yet done.
1940 Finally, if the parent is blocked because of ordered siblings of its own,
1941 the child will also be blocked.
1942 This variable needs to be set before org.el is loaded, and you need to
1943 restart Emacs after a change to make the change effective. The only way
1944 to change is while Emacs is running is through the customize interface."
1945 :set
(lambda (var val
)
1948 (add-hook 'org-blocker-hook
1949 'org-block-todo-from-children-or-siblings-or-parent
)
1950 (remove-hook 'org-blocker-hook
1951 'org-block-todo-from-children-or-siblings-or-parent
)))
1955 (defcustom org-enforce-todo-checkbox-dependencies nil
1956 "Non-nil means unchecked boxes will block switching the parent to DONE.
1957 When this is nil, checkboxes have no influence on switching TODO states.
1958 When non-nil, you first need to check off all check boxes before the TODO
1959 entry can be switched to DONE.
1960 This variable needs to be set before org.el is loaded, and you need to
1961 restart Emacs after a change to make the change effective. The only way
1962 to change is while Emacs is running is through the customize interface."
1963 :set
(lambda (var val
)
1966 (add-hook 'org-blocker-hook
1967 'org-block-todo-from-checkboxes
)
1968 (remove-hook 'org-blocker-hook
1969 'org-block-todo-from-checkboxes
)))
1973 (defcustom org-treat-insert-todo-heading-as-state-change nil
1974 "Non-nil means inserting a TODO heading is treated as state change.
1975 So when the command \\[org-insert-todo-heading] is used, state change
1976 logging will apply if appropriate. When nil, the new TODO item will
1977 be inserted directly, and no logging will take place."
1981 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
1982 "Non-nil means switching TODO states with S-cursor counts as state change.
1983 This is the default behavior. However, setting this to nil allows a
1984 convenient way to select a TODO state and bypass any logging associated
1989 (defcustom org-todo-state-tags-triggers nil
1990 "Tag changes that should be triggered by TODO state changes.
1991 This is a list. Each entry is
1993 (state-change (tag . flag) .......)
1995 State-change can be a string with a state, and empty string to indicate the
1996 state that has no TODO keyword, or it can be one of the symbols `todo'
1997 or `done', meaning any not-done or done state, respectively."
2001 (cons (choice :tag
"When changing to"
2002 (const :tag
"Not-done state" todo
)
2003 (const :tag
"Done state" done
)
2004 (string :tag
"State"))
2006 (cons :tag
"Tag action"
2008 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2010 (defcustom org-log-done nil
2011 "Information to record when a task moves to the DONE state.
2013 Possible values are:
2015 nil Don't add anything, just change the keyword
2016 time Add a time stamp to the task
2017 note Prompt for a note and add it with template `org-log-note-headings'
2019 This option can also be set with on a per-file-basis with
2021 #+STARTUP: nologdone
2023 #+STARTUP: lognotedone
2025 You can have local logging settings for a subtree by setting the LOGGING
2026 property to one or more of these keywords."
2028 :group
'org-progress
2030 (const :tag
"No logging" nil
)
2031 (const :tag
"Record CLOSED timestamp" time
)
2032 (const :tag
"Record CLOSED timestamp with note." note
)))
2034 ;; Normalize old uses of org-log-done.
2036 ((eq org-log-done t
) (setq org-log-done
'time
))
2037 ((and (listp org-log-done
) (memq 'done org-log-done
))
2038 (setq org-log-done
'note
)))
2040 (defcustom org-log-reschedule nil
2041 "Information to record when the scheduling date of a tasks is modified.
2043 Possible values are:
2045 nil Don't add anything, just change the date
2046 time Add a time stamp to the task
2047 note Prompt for a note and add it with template `org-log-note-headings'
2049 This option can also be set with on a per-file-basis with
2051 #+STARTUP: nologreschedule
2052 #+STARTUP: logreschedule
2053 #+STARTUP: lognotereschedule"
2055 :group
'org-progress
2057 (const :tag
"No logging" nil
)
2058 (const :tag
"Record timestamp" time
)
2059 (const :tag
"Record timestamp with note." note
)))
2061 (defcustom org-log-redeadline nil
2062 "Information to record when the deadline date of a tasks is modified.
2064 Possible values are:
2066 nil Don't add anything, just change the date
2067 time Add a time stamp to the task
2068 note Prompt for a note and add it with template `org-log-note-headings'
2070 This option can also be set with on a per-file-basis with
2072 #+STARTUP: nologredeadline
2073 #+STARTUP: logredeadline
2074 #+STARTUP: lognoteredeadline
2076 You can have local logging settings for a subtree by setting the LOGGING
2077 property to one or more of these keywords."
2079 :group
'org-progress
2081 (const :tag
"No logging" nil
)
2082 (const :tag
"Record timestamp" time
)
2083 (const :tag
"Record timestamp with note." note
)))
2085 (defcustom org-log-note-clock-out nil
2086 "Non-nil means record a note when clocking out of an item.
2087 This can also be configured on a per-file basis by adding one of
2088 the following lines anywhere in the buffer:
2090 #+STARTUP: lognoteclock-out
2091 #+STARTUP: nolognoteclock-out"
2093 :group
'org-progress
2096 (defcustom org-log-done-with-time t
2097 "Non-nil means the CLOSED time stamp will contain date and time.
2098 When nil, only the date will be recorded."
2099 :group
'org-progress
2102 (defcustom org-log-note-headings
2103 '((done .
"CLOSING NOTE %t")
2104 (state .
"State %-12s from %-12S %t")
2105 (note .
"Note taken on %t")
2106 (reschedule .
"Rescheduled from %S on %t")
2107 (delschedule .
"Not scheduled, was %S on %t")
2108 (redeadline .
"New deadline from %S on %t")
2109 (deldeadline .
"Removed deadline, was %S on %t")
2110 (refile .
"Refiled on %t")
2112 "Headings for notes added to entries.
2113 The value is an alist, with the car being a symbol indicating the note
2114 context, and the cdr is the heading to be used. The heading may also be the
2116 %t in the heading will be replaced by a time stamp.
2117 %s will be replaced by the new TODO state, in double quotes.
2118 %S will be replaced by the old TODO state, in double quotes.
2119 %u will be replaced by the user name.
2120 %U will be replaced by the full user name.
2122 In fact, it is not a good idea to change the `state' entry, because
2123 agenda log mode depends on the format of these entries."
2125 :group
'org-progress
2126 :type
'(list :greedy t
2127 (cons (const :tag
"Heading when closing an item" done
) string
)
2129 "Heading when changing todo state (todo sequence only)"
2131 (cons (const :tag
"Heading when just taking a note" note
) string
)
2132 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2133 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2134 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2135 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2136 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2137 (cons (const :tag
"Heading when refiling" refile
) string
)))
2139 (unless (assq 'note org-log-note-headings
)
2140 (push '(note .
"%t") org-log-note-headings
))
2142 (defcustom org-log-into-drawer nil
2143 "Non-nil means insert state change notes and time stamps into a drawer.
2144 When nil, state changes notes will be inserted after the headline and
2145 any scheduling and clock lines, but not inside a drawer.
2147 The value of this variable should be the name of the drawer to use.
2148 LOGBOOK is proposed at the default drawer for this purpose, you can
2149 also set this to a string to define the drawer of your choice.
2151 A value of t is also allowed, representing \"LOGBOOK\".
2153 If this variable is set, `org-log-state-notes-insert-after-drawers'
2156 You can set the property LOG_INTO_DRAWER to overrule this setting for
2159 :group
'org-progress
2161 (const :tag
"Not into a drawer" nil
)
2162 (const :tag
"LOGBOOK" t
)
2163 (string :tag
"Other")))
2165 (if (fboundp 'defvaralias
)
2166 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2168 (defun org-log-into-drawer ()
2169 "Return the value of `org-log-into-drawer', but let properties overrule.
2170 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2171 used instead of the default value."
2172 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2174 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2175 ((equal p
"t") "LOGBOOK")
2178 (defcustom org-log-state-notes-insert-after-drawers nil
2179 "Non-nil means insert state change notes after any drawers in entry.
2180 Only the drawers that *immediately* follow the headline and the
2181 deadline/scheduled line are skipped.
2182 When nil, insert notes right after the heading and perhaps the line
2183 with deadline/scheduling if present.
2185 This variable will have no effect if `org-log-into-drawer' is
2188 :group
'org-progress
2191 (defcustom org-log-states-order-reversed t
2192 "Non-nil means the latest state note will be directly after heading.
2193 When nil, the state change notes will be ordered according to time."
2195 :group
'org-progress
2198 (defcustom org-todo-repeat-to-state nil
2199 "The TODO state to which a repeater should return the repeating task.
2200 By default this is the first task in a TODO sequence, or the previous state
2201 in a TODO_TYP set. But you can specify another task here.
2202 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2204 :type
'(choice (const :tag
"Head of sequence" nil
)
2205 (string :tag
"Specific state")))
2207 (defcustom org-log-repeat
'time
2208 "Non-nil means record moving through the DONE state when triggering repeat.
2209 An auto-repeating task is immediately switched back to TODO when
2210 marked DONE. If you are not logging state changes (by adding \"@\"
2211 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2212 record a closing note, there will be no record of the task moving
2213 through DONE. This variable forces taking a note anyway.
2215 nil Don't force a record
2216 time Record a time stamp
2219 This option can also be set with on a per-file-basis with
2221 #+STARTUP: logrepeat
2222 #+STARTUP: lognoterepeat
2223 #+STARTUP: nologrepeat
2225 You can have local logging settings for a subtree by setting the LOGGING
2226 property to one or more of these keywords."
2228 :group
'org-progress
2230 (const :tag
"Don't force a record" nil
)
2231 (const :tag
"Force recording the DONE state" time
)
2232 (const :tag
"Force recording a note with the DONE state" note
)))
2235 (defgroup org-priorities nil
2236 "Priorities in Org-mode."
2237 :tag
"Org Priorities"
2240 (defcustom org-enable-priority-commands t
2241 "Non-nil means priority commands are active.
2242 When nil, these commands will be disabled, so that you never accidentally
2244 :group
'org-priorities
2247 (defcustom org-highest-priority ?A
2248 "The highest priority of TODO items. A character like ?A, ?B etc.
2249 Must have a smaller ASCII number than `org-lowest-priority'."
2250 :group
'org-priorities
2253 (defcustom org-lowest-priority ?C
2254 "The lowest priority of TODO items. A character like ?A, ?B etc.
2255 Must have a larger ASCII number than `org-highest-priority'."
2256 :group
'org-priorities
2259 (defcustom org-default-priority ?B
2260 "The default priority of TODO items.
2261 This is the priority an item get if no explicit priority is given."
2262 :group
'org-priorities
2265 (defcustom org-priority-start-cycle-with-default t
2266 "Non-nil means start with default priority when starting to cycle.
2267 When this is nil, the first step in the cycle will be (depending on the
2268 command used) one higher or lower that the default priority."
2269 :group
'org-priorities
2272 (defgroup org-time nil
2273 "Options concerning time stamps and deadlines in Org-mode."
2277 (defcustom org-insert-labeled-timestamps-at-point nil
2278 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2279 When nil, these labeled time stamps are forces into the second line of an
2280 entry, just after the headline. When scheduling from the global TODO list,
2281 the time stamp will always be forced into the second line."
2285 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2286 "Formats for `format-time-string' which are used for time stamps.
2287 It is not recommended to change this constant.")
2289 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2290 "Number of minutes to round time stamps to.
2291 These are two values, the first applies when first creating a time stamp.
2292 The second applies when changing it with the commands `S-up' and `S-down'.
2293 When changing the time stamp, this means that it will change in steps
2294 of N minutes, as given by the second value.
2296 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2297 numbers should be factors of 60, so for example 5, 10, 15.
2299 When this is larger than 1, you can still force an exact time-stamp by using
2300 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2301 and by using a prefix arg to `S-up/down' to specify the exact number
2302 of minutes to shift."
2304 :get
'(lambda (var) ; Make sure both elements are there
2305 (if (integerp (default-value var
))
2306 (list (default-value var
) 5)
2307 (default-value var
)))
2309 (integer :tag
"when inserting times")
2310 (integer :tag
"when modifying times")))
2312 ;; Normalize old customizations of this variable.
2313 (when (integerp org-time-stamp-rounding-minutes
)
2314 (setq org-time-stamp-rounding-minutes
2315 (list org-time-stamp-rounding-minutes
2316 org-time-stamp-rounding-minutes
)))
2318 (defcustom org-display-custom-times nil
2319 "Non-nil means overlay custom formats over all time stamps.
2320 The formats are defined through the variable `org-time-stamp-custom-formats'.
2321 To turn this on on a per-file basis, insert anywhere in the file:
2322 #+STARTUP: customtime"
2326 (make-variable-buffer-local 'org-display-custom-times
)
2328 (defcustom org-time-stamp-custom-formats
2329 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2330 "Custom formats for time stamps. See `format-time-string' for the syntax.
2331 These are overlayed over the default ISO format if the variable
2332 `org-display-custom-times' is set. Time like %H:%M should be at the
2333 end of the second format. The custom formats are also honored by export
2334 commands, if custom time display is turned on at the time of export."
2338 (defun org-time-stamp-format (&optional long inactive
)
2339 "Get the right format for a time string."
2340 (let ((f (if long
(cdr org-time-stamp-formats
)
2341 (car org-time-stamp-formats
))))
2343 (concat "[" (substring f
1 -
1) "]")
2346 (defcustom org-time-clocksum-format
"%d:%02d"
2347 "The format string used when creating CLOCKSUM lines, or when
2348 org-mode generates a time duration."
2352 (defcustom org-time-clocksum-use-fractional nil
2353 "If non-nil, \\[org-clock-display] uses fractional times.
2354 org-mode generates a time duration."
2358 (defcustom org-time-clocksum-fractional-format
"%.2f"
2359 "The format string used when creating CLOCKSUM lines, or when
2360 org-mode generates a time duration."
2364 (defcustom org-deadline-warning-days
14
2365 "No. of days before expiration during which a deadline becomes active.
2366 This variable governs the display in sparse trees and in the agenda.
2367 When 0 or negative, it means use this number (the absolute value of it)
2368 even if a deadline has a different individual lead time specified.
2370 Custom commands can set this variable in the options section."
2372 :group
'org-agenda-daily
/weekly
2375 (defcustom org-read-date-prefer-future t
2376 "Non-nil means assume future for incomplete date input from user.
2377 This affects the following situations:
2378 1. The user gives a month but not a year.
2379 For example, if it is april and you enter \"feb 2\", this will be read
2380 as feb 2, *next* year. \"May 5\", however, will be this year.
2381 2. The user gives a day, but no month.
2382 For example, if today is the 15th, and you enter \"3\", Org-mode will
2383 read this as the third of *next* month. However, if you enter \"17\",
2384 it will be considered as *this* month.
2386 If you set this variable to the symbol `time', then also the following
2389 3. If the user gives a time, but no day. If the time is before now,
2390 to will be interpreted as tomorrow.
2392 Currently none of this works for ISO week specifications.
2394 When this option is nil, the current day, month and year will always be
2398 (const :tag
"Never" nil
)
2399 (const :tag
"Check month and day" t
)
2400 (const :tag
"Check month, day, and time" time
)))
2402 (defcustom org-read-date-display-live t
2403 "Non-nil means display current interpretation of date prompt live.
2404 This display will be in an overlay, in the minibuffer."
2408 (defcustom org-read-date-popup-calendar t
2409 "Non-nil means pop up a calendar when prompting for a date.
2410 In the calendar, the date can be selected with mouse-1. However, the
2411 minibuffer will also be active, and you can simply enter the date as well.
2412 When nil, only the minibuffer will be available."
2415 (if (fboundp 'defvaralias
)
2416 (defvaralias 'org-popup-calendar-for-date-prompt
2417 'org-read-date-popup-calendar
))
2419 (defcustom org-read-date-minibuffer-setup-hook nil
2420 "Hook to be used to set up keys for the date/time interface.
2421 Add key definitions to `minibuffer-local-map', which will be a temporary
2426 (defcustom org-extend-today-until
0
2427 "The hour when your day really ends. Must be an integer.
2428 This has influence for the following applications:
2429 - When switching the agenda to \"today\". It it is still earlier than
2430 the time given here, the day recognized as TODAY is actually yesterday.
2431 - When a date is read from the user and it is still before the time given
2432 here, the current date and time will be assumed to be yesterday, 23:59.
2433 Also, timestamps inserted in remember templates follow this rule.
2435 IMPORTANT: This is a feature whose implementation is and likely will
2436 remain incomplete. Really, it is only here because past midnight seems to
2437 be the favorite working time of John Wiegley :-)"
2441 (defcustom org-edit-timestamp-down-means-later nil
2442 "Non-nil means S-down will increase the time in a time stamp.
2443 When nil, S-up will increase."
2447 (defcustom org-calendar-follow-timestamp-change t
2448 "Non-nil means make the calendar window follow timestamp changes.
2449 When a timestamp is modified and the calendar window is visible, it will be
2450 moved to the new date."
2454 (defgroup org-tags nil
2455 "Options concerning tags in Org-mode."
2459 (defcustom org-tag-alist nil
2460 "List of tags allowed in Org-mode files.
2461 When this list is nil, Org-mode will base TAG input on what is already in the
2463 The value of this variable is an alist, the car of each entry must be a
2464 keyword as a string, the cdr may be a character that is used to select
2465 that tag through the fast-tag-selection interface.
2466 See the manual for details."
2470 (cons (string :tag
"Tag name")
2471 (character :tag
"Access char"))
2472 (list :tag
"Start radio group"
2474 (option (string :tag
"Group description")))
2475 (list :tag
"End radio group"
2477 (option (string :tag
"Group description")))
2478 (const :tag
"New line" (:newline
)))))
2480 (defcustom org-tag-persistent-alist nil
2481 "List of tags that will always appear in all Org-mode files.
2482 This is in addition to any in buffer settings or customizations
2484 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2485 The value of this variable is an alist, the car of each entry must be a
2486 keyword as a string, the cdr may be a character that is used to select
2487 that tag through the fast-tag-selection interface.
2488 See the manual for details.
2489 To disable these tags on a per-file basis, insert anywhere in the file:
2494 (cons (string :tag
"Tag name")
2495 (character :tag
"Access char"))
2496 (const :tag
"Start radio group" (:startgroup
))
2497 (const :tag
"End radio group" (:endgroup
))
2498 (const :tag
"New line" (:newline
)))))
2500 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2501 "If non-nil, always offer completion for all tags of all agenda files.
2502 Instead of customizing this variable directly, you might want to
2503 set it locally for remember buffers, because there no list of
2504 tags in that file can be created dynamically (there are none).
2506 (add-hook 'org-remember-mode-hook
2508 (set (make-local-variable
2509 'org-complete-tags-always-offer-all-agenda-tags)
2514 (defvar org-file-tags nil
2515 "List of tags that can be inherited by all entries in the file.
2516 The tags will be inherited if the variable `org-use-tag-inheritance'
2517 says they should be.
2518 This variable is populated from #+FILETAGS lines.")
2520 (defcustom org-use-fast-tag-selection
'auto
2521 "Non-nil means use fast tag selection scheme.
2522 This is a special interface to select and deselect tags with single keys.
2523 When nil, fast selection is never used.
2524 When the symbol `auto', fast selection is used if and only if selection
2525 characters for tags have been configured, either through the variable
2526 `org-tag-alist' or through a #+TAGS line in the buffer.
2527 When t, fast selection is always used and selection keys are assigned
2528 automatically if necessary."
2531 (const :tag
"Always" t
)
2532 (const :tag
"Never" nil
)
2533 (const :tag
"When selection characters are configured" 'auto
)))
2535 (defcustom org-fast-tag-selection-single-key nil
2536 "Non-nil means fast tag selection exits after first change.
2537 When nil, you have to press RET to exit it.
2538 During fast tag selection, you can toggle this flag with `C-c'.
2539 This variable can also have the value `expert'. In this case, the window
2540 displaying the tags menu is not even shown, until you press C-c again."
2543 (const :tag
"No" nil
)
2544 (const :tag
"Yes" t
)
2545 (const :tag
"Expert" expert
)))
2547 (defvar org-fast-tag-selection-include-todo nil
2548 "Non-nil means fast tags selection interface will also offer TODO states.
2549 This is an undocumented feature, you should not rely on it.")
2551 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2552 "The column to which tags should be indented in a headline.
2553 If this number is positive, it specifies the column. If it is negative,
2554 it means that the tags should be flushright to that column. For example,
2555 -80 works well for a normal 80 character screen."
2559 (defcustom org-auto-align-tags t
2560 "Non-nil means realign tags after pro/demotion of TODO state change.
2561 These operations change the length of a headline and therefore shift
2562 the tags around. With this options turned on, after each such operation
2563 the tags are again aligned to `org-tags-column'."
2567 (defcustom org-use-tag-inheritance t
2568 "Non-nil means tags in levels apply also for sublevels.
2569 When nil, only the tags directly given in a specific line apply there.
2570 This may also be a list of tags that should be inherited, or a regexp that
2571 matches tags that should be inherited. Additional control is possible
2572 with the variable `org-tags-exclude-from-inheritance' which gives an
2573 explicit list of tags to be excluded from inheritance., even if the value of
2574 `org-use-tag-inheritance' would select it for inheritance.
2576 If this option is t, a match early-on in a tree can lead to a large
2577 number of matches in the subtree when constructing the agenda or creating
2578 a sparse tree. If you only want to see the first match in a tree during
2579 a search, check out the variable `org-tags-match-list-sublevels'."
2582 (const :tag
"Not" nil
)
2583 (const :tag
"Always" t
)
2584 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2585 (regexp :tag
"Tags matched by regexp")))
2587 (defcustom org-tags-exclude-from-inheritance nil
2588 "List of tags that should never be inherited.
2589 This is a way to exclude a few tags from inheritance. For way to do
2590 the opposite, to actively allow inheritance for selected tags,
2591 see the variable `org-use-tag-inheritance'."
2593 :type
'(repeat (string :tag
"Tag")))
2595 (defun org-tag-inherit-p (tag)
2596 "Check if TAG is one that should be inherited."
2598 ((member tag org-tags-exclude-from-inheritance
) nil
)
2599 ((eq org-use-tag-inheritance t
) t
)
2600 ((not org-use-tag-inheritance
) nil
)
2601 ((stringp org-use-tag-inheritance
)
2602 (string-match org-use-tag-inheritance tag
))
2603 ((listp org-use-tag-inheritance
)
2604 (member tag org-use-tag-inheritance
))
2605 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2607 (defcustom org-tags-match-list-sublevels t
2608 "Non-nil means list also sublevels of headlines matching a search.
2609 This variable applies to tags/property searches, and also to stuck
2610 projects because this search is based on a tags match as well.
2612 When set to the symbol `indented', sublevels are indented with
2615 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2616 the sublevels of a headline matching a tag search often also match
2617 the same search. Listing all of them can create very long lists.
2618 Setting this variable to nil causes subtrees of a match to be skipped.
2620 This variable is semi-obsolete and probably should always be true. It
2621 is better to limit inheritance to certain tags using the variables
2622 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2625 (const :tag
"No, don't list them" nil
)
2626 (const :tag
"Yes, do list them" t
)
2627 (const :tag
"List them, indented with leading dots" indented
)))
2629 (defcustom org-tags-sort-function nil
2630 "When set, tags are sorted using this function as a comparator"
2633 (const :tag
"No sorting" nil
)
2634 (const :tag
"Alphabetical" string
<)
2635 (const :tag
"Reverse alphabetical" string
>)
2636 (function :tag
"Custom function" nil
)))
2638 (defvar org-tags-history nil
2639 "History of minibuffer reads for tags.")
2640 (defvar org-last-tags-completion-table nil
2641 "The last used completion table for tags.")
2642 (defvar org-after-tags-change-hook nil
2643 "Hook that is run after the tags in a line have changed.")
2645 (defgroup org-properties nil
2646 "Options concerning properties in Org-mode."
2647 :tag
"Org Properties"
2650 (defcustom org-property-format
"%-10s %s"
2651 "How property key/value pairs should be formatted by `indent-line'.
2652 When `indent-line' hits a property definition, it will format the line
2653 according to this format, mainly to make sure that the values are
2654 lined-up with respect to each other."
2655 :group
'org-properties
2658 (defcustom org-use-property-inheritance nil
2659 "Non-nil means properties apply also for sublevels.
2661 This setting is chiefly used during property searches. Turning it on can
2662 cause significant overhead when doing a search, which is why it is not
2665 When nil, only the properties directly given in the current entry count.
2666 When t, every property is inherited. The value may also be a list of
2667 properties that should have inheritance, or a regular expression matching
2668 properties that should be inherited.
2670 However, note that some special properties use inheritance under special
2671 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2672 and the properties ending in \"_ALL\" when they are used as descriptor
2673 for valid values of a property.
2675 Note for programmers:
2676 When querying an entry with `org-entry-get', you can control if inheritance
2677 should be used. By default, `org-entry-get' looks only at the local
2678 properties. You can request inheritance by setting the inherit argument
2679 to t (to force inheritance) or to `selective' (to respect the setting
2681 :group
'org-properties
2683 (const :tag
"Not" nil
)
2684 (const :tag
"Always" t
)
2685 (repeat :tag
"Specific properties" (string :tag
"Property"))
2686 (regexp :tag
"Properties matched by regexp")))
2688 (defun org-property-inherit-p (property)
2689 "Check if PROPERTY is one that should be inherited."
2691 ((eq org-use-property-inheritance t
) t
)
2692 ((not org-use-property-inheritance
) nil
)
2693 ((stringp org-use-property-inheritance
)
2694 (string-match org-use-property-inheritance property
))
2695 ((listp org-use-property-inheritance
)
2696 (member property org-use-property-inheritance
))
2697 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2699 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2700 "The default column format, if no other format has been defined.
2701 This variable can be set on the per-file basis by inserting a line
2703 #+COLUMNS: %25ITEM ....."
2704 :group
'org-properties
2707 (defcustom org-columns-ellipses
".."
2708 "The ellipses to be used when a field in column view is truncated.
2709 When this is the empty string, as many characters as possible are shown,
2710 but then there will be no visual indication that the field has been truncated.
2711 When this is a string of length N, the last N characters of a truncated
2712 field are replaced by this string. If the column is narrower than the
2713 ellipses string, only part of the ellipses string will be shown."
2714 :group
'org-properties
2717 (defcustom org-columns-modify-value-for-display-function nil
2718 "Function that modifies values for display in column view.
2719 For example, it can be used to cut out a certain part from a time stamp.
2720 The function must take 2 arguments:
2722 column-title The title of the column (*not* the property name)
2723 value The value that should be modified.
2725 The function should return the value that should be displayed,
2726 or nil if the normal value should be used."
2727 :group
'org-properties
2730 (defcustom org-effort-property
"Effort"
2731 "The property that is being used to keep track of effort estimates.
2732 Effort estimates given in this property need to have the format H:MM."
2733 :group
'org-properties
2734 :group
'org-progress
2735 :type
'(string :tag
"Property"))
2737 (defconst org-global-properties-fixed
2738 '(("VISIBILITY_ALL" .
"folded children content all")
2739 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2740 "List of property/value pairs that can be inherited by any entry.
2742 These are fixed values, for the preset properties. The user variable
2743 that can be used to add to this list is `org-global-properties'.
2745 The entries in this list are cons cells where the car is a property
2746 name and cdr is a string with the value. If the value represents
2747 multiple items like an \"_ALL\" property, separate the items by
2750 (defcustom org-global-properties nil
2751 "List of property/value pairs that can be inherited by any entry.
2753 This list will be combined with the constant `org-global-properties-fixed'.
2755 The entries in this list are cons cells where the car is a property
2756 name and cdr is a string with the value.
2758 You can set buffer-local values for the same purpose in the variable
2759 `org-file-properties' this by adding lines like
2761 #+PROPERTY: NAME VALUE"
2762 :group
'org-properties
2764 (cons (string :tag
"Property")
2765 (string :tag
"Value"))))
2767 (defvar org-file-properties nil
2768 "List of property/value pairs that can be inherited by any entry.
2769 Valid for the current buffer.
2770 This variable is populated from #+PROPERTY lines.")
2771 (make-variable-buffer-local 'org-file-properties
)
2773 (defgroup org-agenda nil
2774 "Options concerning agenda views in Org-mode."
2778 (defvar org-category nil
2779 "Variable used by org files to set a category for agenda display.
2780 Such files should use a file variable to set it, for example
2782 # -*- mode: org; org-category: \"ELisp\"
2784 or contain a special line
2788 If the file does not specify a category, then file's base name
2790 (make-variable-buffer-local 'org-category
)
2791 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2793 (defcustom org-agenda-files nil
2794 "The files to be used for agenda display.
2795 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2796 \\[org-remove-file]. You can also use customize to edit the list.
2798 If an entry is a directory, all files in that directory that are matched by
2799 `org-agenda-file-regexp' will be part of the file list.
2801 If the value of the variable is not a list but a single file name, then
2802 the list of agenda files is actually stored and maintained in that file, one
2803 agenda file per line. In this file paths can be given relative to
2804 `org-directory'. Tilde expansion and environment variable substitution
2808 (repeat :tag
"List of files and directories" file
)
2809 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2811 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2812 "Regular expression to match files for `org-agenda-files'.
2813 If any element in the list in that variable contains a directory instead
2814 of a normal file, all files in that directory that are matched by this
2815 regular expression will be included."
2819 (defcustom org-agenda-text-search-extra-files nil
2820 "List of extra files to be searched by text search commands.
2821 These files will be search in addition to the agenda files by the
2822 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2823 Note that these files will only be searched for text search commands,
2824 not for the other agenda views like todo lists, tag searches or the weekly
2825 agenda. This variable is intended to list notes and possibly archive files
2826 that should also be searched by these two commands.
2827 In fact, if the first element in the list is the symbol `agenda-archives',
2828 than all archive files of all agenda files will be added to the search
2831 :type
'(set :greedy t
2832 (const :tag
"Agenda Archives" agenda-archives
)
2833 (repeat :inline t
(file))))
2835 (if (fboundp 'defvaralias
)
2836 (defvaralias 'org-agenda-multi-occur-extra-files
2837 'org-agenda-text-search-extra-files
))
2839 (defcustom org-agenda-skip-unavailable-files nil
2840 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2841 A nil value means to remove them, after a query, from the list."
2845 (defcustom org-calendar-to-agenda-key
[?c
]
2846 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2847 The command `org-calendar-goto-agenda' will be bound to this key. The
2848 default is the character `c' because then `c' can be used to switch back and
2849 forth between agenda and calendar."
2853 (defcustom org-calendar-agenda-action-key
[?k
]
2854 "The key to be installed in `calendar-mode-map' for agenda-action.
2855 The command `org-agenda-action' will be bound to this key. The
2856 default is the character `k' because we use the same key in the agenda."
2860 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2861 "The key to be installed in `calendar-mode-map' for adding diary entries.
2862 This option is irrelevant until `org-agenda-diary-file' has been configured
2863 to point to an Org-mode file. When that is the case, the command
2864 `org-agenda-diary-entry' will be bound to the key given here, by default
2865 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2866 if you want to continue doing this, you need to change this to a different
2871 (defcustom org-agenda-diary-file
'diary-file
2872 "File to which to add new entries with the `i' key in agenda and calendar.
2873 When this is the symbol `diary-file', the functionality in the Emacs
2874 calendar will be used to add entries to the `diary-file'. But when this
2875 points to a file, `org-agenda-diary-entry' will be used instead."
2878 (const :tag
"The standard Emacs diary file" diary-file
)
2879 (file :tag
"Special Org file diary entries")))
2881 (eval-after-load "calendar"
2883 (org-defkey calendar-mode-map org-calendar-to-agenda-key
2884 'org-calendar-goto-agenda
)
2885 (org-defkey calendar-mode-map org-calendar-agenda-action-key
2887 (add-hook 'calendar-mode-hook
2889 (unless (eq org-agenda-diary-file
'diary-file
)
2890 (define-key calendar-mode-map
2891 org-calendar-insert-diary-entry-key
2892 'org-agenda-diary-entry
))))))
2894 (defgroup org-latex nil
2895 "Options for embedding LaTeX code into Org-mode."
2899 (defcustom org-format-latex-options
2900 '(:foreground default
:background default
:scale
1.0
2901 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
2902 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
2903 "Options for creating images from LaTeX fragments.
2904 This is a property list with the following properties:
2905 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
2906 `default' means use the foreground of the default face.
2907 :background the background color, or \"Transparent\".
2908 `default' means use the background of the default face.
2909 :scale a scaling factor for the size of the images.
2910 :html-foreground, :html-background, :html-scale
2911 the same numbers for HTML export.
2912 :matchers a list indicating which matchers should be used to
2913 find LaTeX fragments. Valid members of this list are:
2914 \"begin\" find environments
2915 \"$1\" find single characters surrounded by $.$
2916 \"$\" find math expressions surrounded by $...$
2917 \"$$\" find math expressions surrounded by $$....$$
2918 \"\\(\" find math expressions surrounded by \\(...\\)
2919 \"\\ [\" find math expressions surrounded by \\ [...\\]"
2923 (defcustom org-format-latex-signal-error t
2924 "Non-nil means signal an error when image creation of LaTeX snippets fails.
2925 When nil, just push out a message."
2929 (defcustom org-format-latex-header
"\\documentclass{article}
2930 \\usepackage[usenames]{color}
2931 \\usepackage{amsmath}
2932 \\usepackage[mathscr]{eucal}
2933 \\pagestyle{empty} % do not remove
2936 % The settings below are copied from fullpage.sty
2937 \\setlength{\\textwidth}{\\paperwidth}
2938 \\addtolength{\\textwidth}{-3cm}
2939 \\setlength{\\oddsidemargin}{1.5cm}
2940 \\addtolength{\\oddsidemargin}{-2.54cm}
2941 \\setlength{\\evensidemargin}{\\oddsidemargin}
2942 \\setlength{\\textheight}{\\paperheight}
2943 \\addtolength{\\textheight}{-\\headheight}
2944 \\addtolength{\\textheight}{-\\headsep}
2945 \\addtolength{\\textheight}{-\\footskip}
2946 \\addtolength{\\textheight}{-3cm}
2947 \\setlength{\\topmargin}{1.5cm}
2948 \\addtolength{\\topmargin}{-2.54cm}"
2949 "The document header used for processing LaTeX fragments.
2950 It is imperative that this header make sure that no page number
2951 appears on the page. The package defined in the variables
2952 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
2953 will either replace the placeholder \"[PACKAGES]\" in this header, or they
2958 (defvar org-format-latex-header-extra nil
)
2960 (defun org-set-packages-alist (var val
)
2961 "Set the packages alist and make sure it has 3 elements per entry."
2962 (set var
(mapcar (lambda (x)
2963 (if (and (consp x
) (= (length x
) 2))
2964 (list (car x
) (nth 1 x
) t
)
2968 (defun org-get-packages-alist (var)
2970 "Get the packages alist and make sure it has 3 elements per entry."
2972 (if (and (consp x
) (= (length x
) 2))
2973 (list (car x
) (nth 1 x
) t
)
2975 (default-value var
)))
2977 ;; The following variables are defined here because is it also used
2978 ;; when formatting latex fragments. Originally it was part of the
2979 ;; LaTeX exporter, which is why the name includes "export".
2980 (defcustom org-export-latex-default-packages-alist
2981 '(("AUTO" "inputenc" t
)
2985 ("" "longtable" nil
)
2998 "Alist of default packages to be inserted in the header.
2999 Change this only if one of the packages here causes an incompatibility
3000 with another package you are using.
3001 The packages in this list are needed by one part or another of Org-mode
3002 to function properly.
3004 - inputenc, fontenc, t1enc: for basic font and character selection
3005 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3006 for interpreting the entities in `org-entities'. You can skip some of these
3007 packages if you don't use any of the symbols in it.
3008 - graphicx: for including images
3009 - float, wrapfig: for figure placement
3010 - longtable: for long tables
3011 - hyperref: for cross references
3013 Therefore you should not modify this variable unless you know what you
3014 are doing. The one reason to change it anyway is that you might be loading
3015 some other package that conflicts with one of the default packages.
3016 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3017 If SNIPPET-FLAG is t, the package also needs to be included when
3018 compiling LaTeX snippets into images for inclusion into HTML."
3019 :group
'org-export-latex
3020 :set
'org-set-packages-alist
3021 :get
'org-get-packages-alist
3024 (list :tag
"options/package pair"
3025 (string :tag
"options")
3026 (string :tag
"package")
3027 (boolean :tag
"Snippet"))
3028 (string :tag
"A line of LaTeX"))))
3030 (defcustom org-export-latex-packages-alist nil
3031 "Alist of packages to be inserted in every LaTeX header.
3032 These will be inserted after `org-export-latex-default-packages-alist'.
3033 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3034 SNIPPET-FLAG, when t, indicates that this package is also needed when
3035 turning LaTeX snippets into images for inclusion into HTML.
3036 Make sure that you only list packages here which:
3037 - you want in every file
3038 - do not conflict with the default packages in
3039 `org-export-latex-default-packages-alist'
3040 - do not conflict with the setup in `org-format-latex-header'."
3041 :group
'org-export-latex
3042 :set
'org-set-packages-alist
3043 :get
'org-get-packages-alist
3046 (list :tag
"options/package pair"
3047 (string :tag
"options")
3048 (string :tag
"package")
3049 (boolean :tag
"Snippet"))
3050 (string :tag
"A line of LaTeX"))))
3053 (defgroup org-appearance nil
3054 "Settings for Org-mode appearance."
3055 :tag
"Org Appearance"
3058 (defcustom org-level-color-stars-only nil
3059 "Non-nil means fontify only the stars in each headline.
3060 When nil, the entire headline is fontified.
3061 Changing it requires restart of `font-lock-mode' to become effective
3062 also in regions already fontified."
3063 :group
'org-appearance
3066 (defcustom org-hide-leading-stars nil
3067 "Non-nil means hide the first N-1 stars in a headline.
3068 This works by using the face `org-hide' for these stars. This
3069 face is white for a light background, and black for a dark
3070 background. You may have to customize the face `org-hide' to
3072 Changing it requires restart of `font-lock-mode' to become effective
3073 also in regions already fontified.
3074 You may also set this on a per-file basis by adding one of the following
3075 lines to the buffer:
3077 #+STARTUP: hidestars
3078 #+STARTUP: showstars"
3079 :group
'org-appearance
3082 (defcustom org-hidden-keywords nil
3083 "List of keywords that should be hidden when typed in the org buffer.
3084 For example, add #+TITLE to this list in order to make the
3085 document title appear in the buffer without the initial #+TITLE:
3087 :group
'org-appearance
3088 :type
'(set (const :tag
"#+AUTHOR" author
)
3089 (const :tag
"#+DATE" date
)
3090 (const :tag
"#+EMAIL" email
)
3091 (const :tag
"#+TITLE" title
)))
3093 (defcustom org-fontify-done-headline nil
3094 "Non-nil means change the face of a headline if it is marked DONE.
3095 Normally, only the TODO/DONE keyword indicates the state of a headline.
3096 When this is non-nil, the headline after the keyword is set to the
3097 `org-headline-done' as an additional indication."
3098 :group
'org-appearance
3101 (defcustom org-fontify-emphasized-text t
3102 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3103 Changing this variable requires a restart of Emacs to take effect."
3104 :group
'org-appearance
3107 (defcustom org-fontify-whole-heading-line nil
3108 "Non-nil means fontify the whole line for headings.
3109 This is useful when setting a background color for the
3111 :group
'org-appearance
3114 (defcustom org-highlight-latex-fragments-and-specials nil
3115 "Non-nil means fontify what is treated specially by the exporters."
3116 :group
'org-appearance
3119 (defcustom org-hide-emphasis-markers nil
3120 "Non-nil mean font-lock should hide the emphasis marker characters."
3121 :group
'org-appearance
3124 (defvar org-emph-re nil
3125 "Regular expression for matching emphasis.")
3126 (defvar org-verbatim-re nil
3127 "Regular expression for matching verbatim text.")
3128 (defvar org-emphasis-regexp-components
) ; defined just below
3129 (defvar org-emphasis-alist
) ; defined just below
3130 (defun org-set-emph-re (var val
)
3131 "Set variable and compute the emphasis regular expression."
3133 (when (and (boundp 'org-emphasis-alist
)
3134 (boundp 'org-emphasis-regexp-components
)
3135 org-emphasis-alist org-emphasis-regexp-components
)
3136 (let* ((e org-emphasis-regexp-components
)
3142 (body1 (concat body
"*?"))
3143 (markers (mapconcat 'car org-emphasis-alist
""))
3144 (vmarkers (mapconcat
3145 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3146 org-emphasis-alist
"")))
3147 ;; make sure special characters appear at the right position in the class
3148 (if (string-match "\\^" markers
)
3149 (setq markers
(concat (replace-match "" t t markers
) "^")))
3150 (if (string-match "-" markers
)
3151 (setq markers
(concat (replace-match "" t t markers
) "-")))
3152 (if (string-match "\\^" vmarkers
)
3153 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3154 (if (string-match "-" vmarkers
)
3155 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3157 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3158 (int-to-string nl
) "\\}")))
3161 (concat "\\([" pre
"]\\|^\\)"
3163 "\\([" markers
"]\\)"
3171 "\\([" post
"]\\|$\\)"))
3172 (setq org-verbatim-re
3173 (concat "\\([" pre
"]\\|^\\)"
3175 "\\([" vmarkers
"]\\)"
3183 "\\([" post
"]\\|$\\)")))))
3185 (defcustom org-emphasis-regexp-components
3186 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3187 "Components used to build the regular expression for emphasis.
3188 This is a list with 6 entries. Terminology: In an emphasis string
3189 like \" *strong word* \", we call the initial space PREMATCH, the final
3190 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3191 and \"trong wor\" is the body. The different components in this variable
3192 specify what is allowed/forbidden in each part:
3194 pre Chars allowed as prematch. Beginning of line will be allowed too.
3195 post Chars allowed as postmatch. End of line will be allowed too.
3196 border The chars *forbidden* as border characters.
3197 body-regexp A regexp like \".\" to match a body character. Don't use
3198 non-shy groups here, and don't allow newline here.
3199 newline The maximum number of newlines allowed in an emphasis exp.
3201 Use customize to modify this, or restart Emacs after changing it."
3202 :group
'org-appearance
3203 :set
'org-set-emph-re
3205 (sexp :tag
"Allowed chars in pre ")
3206 (sexp :tag
"Allowed chars in post ")
3207 (sexp :tag
"Forbidden chars in border ")
3208 (sexp :tag
"Regexp for body ")
3209 (integer :tag
"number of newlines allowed")
3210 (option (boolean :tag
"Please ignore this button"))))
3212 (defcustom org-emphasis-alist
3213 `(("*" bold
"<b>" "</b>")
3214 ("/" italic
"<i>" "</i>")
3215 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3216 ("=" org-code
"<code>" "</code>" verbatim
)
3217 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3218 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3221 "Special syntax for emphasized text.
3222 Text starting and ending with a special character will be emphasized, for
3223 example *bold*, _underlined_ and /italic/. This variable sets the marker
3224 characters, the face to be used by font-lock for highlighting in Org-mode
3225 Emacs buffers, and the HTML tags to be used for this.
3226 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3227 Use customize to modify this, or restart Emacs after changing it."
3228 :group
'org-appearance
3229 :set
'org-set-emph-re
3232 (string :tag
"Marker character")
3234 (face :tag
"Font-lock-face")
3235 (plist :tag
"Face property list"))
3236 (string :tag
"HTML start tag")
3237 (string :tag
"HTML end tag")
3238 (option (const verbatim
)))))
3240 (defvar org-protecting-blocks
3241 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3242 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3243 This is needed for font-lock setup.")
3245 ;;; Miscellaneous options
3247 (defgroup org-completion nil
3248 "Completion in Org-mode."
3249 :tag
"Org Completion"
3252 (defcustom org-completion-use-ido nil
3253 "Non-nil means use ido completion wherever possible.
3254 Note that `ido-mode' must be active for this variable to be relevant.
3255 If you decide to turn this variable on, you might well want to turn off
3256 `org-outline-path-complete-in-steps'.
3257 See also `org-completion-use-iswitchb'."
3258 :group
'org-completion
3261 (defcustom org-completion-use-iswitchb nil
3262 "Non-nil means use iswitchb completion wherever possible.
3263 Note that `iswitchb-mode' must be active for this variable to be relevant.
3264 If you decide to turn this variable on, you might well want to turn off
3265 `org-outline-path-complete-in-steps'.
3266 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3267 :group
'org-completion
3270 (defcustom org-completion-fallback-command
'hippie-expand
3271 "The expansion command called by \\[org-complete] in normal context.
3272 Normal means no org-mode-specific context."
3273 :group
'org-completion
3276 ;;; Functions and variables from their packages
3277 ;; Declared here to avoid compiler warnings
3280 (defvar outline-mode-menu-heading
)
3281 (defvar outline-mode-menu-show
)
3282 (defvar outline-mode-menu-hide
)
3283 (defvar zmacs-regions
) ; XEmacs regions
3286 (defvar mark-active
)
3289 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3290 (declare-function calendar-forward-day
"cal-move" (arg))
3291 (declare-function calendar-goto-date
"cal-move" (date))
3292 (declare-function calendar-goto-today
"cal-move" ())
3293 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3294 (defvar calc-embedded-close-formula
)
3295 (defvar calc-embedded-open-formula
)
3296 (declare-function cdlatex-tab
"ext:cdlatex" ())
3297 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3298 (defvar font-lock-unfontify-region-function
)
3299 (declare-function iswitchb-read-buffer
"iswitchb"
3300 (prompt &optional default require-match start matches-set
))
3301 (defvar iswitchb-temp-buflist
)
3302 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3303 (defvar org-agenda-tags-todo-honor-ignore-options
)
3304 (declare-function org-agenda-skip
"org-agenda" ())
3306 org-format-agenda-item
"org-agenda"
3307 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3308 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3309 (declare-function org-agenda-change-all-lines
"org-agenda"
3310 (newhead hdmarker
&optional fixface just-this
))
3311 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3312 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3313 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3315 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3316 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3317 "org-agenda" (&optional end
))
3318 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3319 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3320 (declare-function parse-time-string
"parse-time" (string))
3321 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3322 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3323 (defvar remember-data-file
)
3324 (defvar texmathp-why
)
3325 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3326 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3328 (defvar w3m-current-url
)
3329 (defvar w3m-current-title
)
3331 (defvar org-latex-regexps
)
3333 ;;; Autoload and prepare some org modules
3335 ;; Some table stuff that needs to be defined here, because it is used
3336 ;; by the functions setting up org-mode or checking for table context.
3338 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3339 "Detects an org-type or table-type table.")
3340 (defconst org-table-line-regexp
"^[ \t]*|"
3341 "Detects an org-type table line.")
3342 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3343 "Detects an org-type table line.")
3344 (defconst org-table-hline-regexp
"^[ \t]*|-"
3345 "Detects an org-type table hline.")
3346 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3347 "Detects a table-type table hline.")
3348 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3349 "Searching from within a table (any type) this finds the first line
3350 outside the table.")
3352 ;; Autoload the functions in org-table.el that are needed by functions here.
3355 (org-autoload "org-table"
3356 '(org-table-align org-table-begin org-table-blank-field
3357 org-table-convert org-table-convert-region org-table-copy-down
3358 org-table-copy-region org-table-create
3359 org-table-create-or-convert-from-region
3360 org-table-create-with-table.el org-table-current-dline
3361 org-table-cut-region org-table-delete-column org-table-edit-field
3362 org-table-edit-formulas org-table-end org-table-eval-formula
3363 org-table-export org-table-field-info
3364 org-table-get-stored-formulas org-table-goto-column
3365 org-table-hline-and-move org-table-import org-table-insert-column
3366 org-table-insert-hline org-table-insert-row org-table-iterate
3367 org-table-justify-field-maybe org-table-kill-row
3368 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3369 org-table-move-column org-table-move-column-left
3370 org-table-move-column-right org-table-move-row
3371 org-table-move-row-down org-table-move-row-up
3372 org-table-next-field org-table-next-row org-table-paste-rectangle
3373 org-table-previous-field org-table-recalculate
3374 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3375 org-table-toggle-coordinate-overlays
3376 org-table-toggle-formula-debugger org-table-wrap-region
3377 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3379 (defun org-at-table-p (&optional table-type
)
3380 "Return t if the cursor is inside an org-type table.
3381 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3382 (if org-enable-table-editor
3384 (beginning-of-line 1)
3385 (looking-at (if table-type org-table-any-line-regexp
3386 org-table-line-regexp
)))
3388 (defsubst org-table-p
() (org-at-table-p))
3390 (defun org-at-table.el-p
()
3391 "Return t if and only if we are at a table.el table."
3392 (and (org-at-table-p 'any
)
3394 (goto-char (org-table-begin 'any
))
3395 (looking-at org-table1-hline-regexp
))))
3396 (defun org-table-recognize-table.el
()
3397 "If there is a table.el table nearby, recognize it and move into it."
3398 (if org-table-tab-recognizes-table.el
3399 (if (org-at-table.el-p
)
3401 (beginning-of-line 1)
3402 (if (looking-at org-table-dataline-regexp
)
3404 (if (looking-at org-table1-hline-regexp
)
3406 (beginning-of-line 2)
3407 (if (looking-at org-table-any-border-regexp
)
3408 (beginning-of-line -
1)))))
3409 (if (re-search-forward "|" (org-table-end t
) t
)
3412 (if (table--at-cell-p (point))
3414 (message "recognizing table.el table...")
3415 (table-recognize-table)
3416 (message "recognizing table.el table...done")))
3417 (error "This should not happen..."))
3422 (defun org-at-table-hline-p ()
3423 "Return t if the cursor is inside a hline in a table."
3424 (if org-enable-table-editor
3426 (beginning-of-line 1)
3427 (looking-at org-table-hline-regexp
))
3430 (defvar org-table-clean-did-remove-column nil
)
3432 (defun org-table-map-tables (function &optional quietly
)
3433 "Apply FUNCTION to the start of all tables in the buffer."
3437 (goto-char (point-min))
3438 (while (re-search-forward org-table-any-line-regexp nil t
)
3440 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3441 (beginning-of-line 1)
3442 (when (looking-at org-table-line-regexp
)
3443 (save-excursion (funcall function
))
3444 (or (looking-at org-table-line-regexp
)
3446 (re-search-forward org-table-any-border-regexp nil
1))))
3447 (unless quietly
(message "Mapping tables: done")))
3449 ;; Declare and autoload functions from org-exp.el & Co
3451 (declare-function org-default-export-plist
"org-exp")
3452 (declare-function org-infile-export-plist
"org-exp")
3453 (declare-function org-get-current-options
"org-exp")
3455 (org-autoload "org-exp"
3456 '(org-export org-export-visible
3457 org-insert-export-options-template
3458 org-table-clean-before-export
))
3459 (org-autoload "org-ascii"
3460 '(org-export-as-ascii org-export-ascii-preprocess
3461 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3462 org-export-region-as-ascii
))
3463 (org-autoload "org-latex"
3464 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3465 org-replace-region-by-latex org-export-region-as-latex
3466 org-export-as-latex org-export-as-pdf
3467 org-export-as-pdf-and-open
))
3468 (org-autoload "org-html"
3469 '(org-export-as-html-and-open
3470 org-export-as-html-batch org-export-as-html-to-buffer
3471 org-replace-region-by-html org-export-region-as-html
3472 org-export-as-html
))
3473 (org-autoload "org-docbook"
3474 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3475 org-replace-region-by-docbook org-export-region-as-docbook
3476 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3477 org-export-as-docbook
))
3478 (org-autoload "org-icalendar"
3479 '(org-export-icalendar-this-file
3480 org-export-icalendar-all-agenda-files
3481 org-export-icalendar-combine-agenda-files
))
3482 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3483 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3485 ;; Declare and autoload functions from org-agenda.el
3488 (org-autoload "org-agenda"
3489 '(org-agenda org-agenda-list org-search-view
3490 org-todo-list org-tags-view org-agenda-list-stuck-projects
3491 org-diary org-agenda-to-appt
3492 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3494 ;; Autoload org-remember
3497 (org-autoload "org-remember"
3498 '(org-remember-insinuate org-remember-annotation
3499 org-remember-apply-template org-remember org-remember-handler
)))
3501 ;; Autoload org-clock.el
3504 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3506 (declare-function org-clock-update-mode-line
"org-clock" ())
3507 (declare-function org-resolve-clocks
"org-clock"
3508 (&optional also-non-dangling-p prompt last-valid
))
3509 (defvar org-clock-start-time
)
3510 (defvar org-clock-marker
(make-marker)
3511 "Marker recording the last clock-in.")
3512 (defvar org-clock-hd-marker
(make-marker)
3513 "Marker recording the last clock-in, but the headline position.")
3514 (defvar org-clock-heading
""
3515 "The heading of the current clock entry.")
3516 (defun org-clock-is-active ()
3517 "Return non-nil if clock is currently running.
3518 The return value is actually the clock marker."
3519 (marker-buffer org-clock-marker
))
3524 '(org-clock-in org-clock-out org-clock-cancel
3525 org-clock-goto org-clock-sum org-clock-display
3526 org-clock-remove-overlays org-clock-report
3527 org-clocktable-shift org-dblock-write
:clocktable
3528 org-get-clocktable org-resolve-clocks
)))
3530 (defun org-clock-update-time-maybe ()
3531 "If this is a CLOCK line, update it and return t.
3532 Otherwise, return nil."
3535 (beginning-of-line 1)
3536 (skip-chars-forward " \t")
3537 (when (looking-at org-clock-string
)
3538 (let ((re (concat "[ \t]*" org-clock-string
3539 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3540 "\\([ \t]*=>.*\\)?\\)?"))
3543 ((not (looking-at re
))
3545 ((not (match-end 2))
3546 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3547 (> org-clock-marker
(point))
3548 (<= org-clock-marker
(point-at-eol)))
3549 ;; The clock is running here
3550 (setq org-clock-start-time
3552 (org-parse-time-string (match-string 1))))
3553 (org-clock-update-mode-line)))
3555 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3557 (setq ts
(match-string 1)
3558 te
(match-string 3))
3559 (setq s
(- (org-float-time
3560 (apply 'encode-time
(org-parse-time-string te
)))
3562 (apply 'encode-time
(org-parse-time-string ts
))))
3565 h
(floor (/ s
3600))
3569 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3572 (defun org-check-running-clock ()
3573 "Check if the current buffer contains the running clock.
3574 If yes, offer to stop it and to save the buffer with the changes."
3575 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3576 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3579 (when (y-or-n-p "Save changed buffer?")
3582 (defun org-clocktable-try-shift (dir n
)
3583 "Check if this line starts a clock table, if yes, shift the time block."
3584 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3585 (org-clocktable-shift dir n
)))
3587 ;; Autoload org-timer.el
3592 '(org-timer-start org-timer org-timer-item
3593 org-timer-change-times-in-region
3595 org-timer-reset-timers
3596 org-timer-show-remaining-time
)))
3598 ;; Autoload org-feed.el
3603 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3606 ;; Autoload org-indent.el
3608 ;; Define the variable already here, to make sure we have it.
3609 (defvar org-indent-mode nil
3610 "Non-nil if Org-Indent mode is enabled.
3611 Use the command `org-indent-mode' to change this variable.")
3616 '(org-indent-mode)))
3618 ;; Autoload org-mobile.el
3623 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3625 ;; Autoload archiving code
3626 ;; The stuff that is needed for cycling and tags has to be defined here.
3628 (defgroup org-archive nil
3629 "Options concerning archiving in Org-mode."
3631 :group
'org-structure
)
3633 (defcustom org-archive-location
"%s_archive::"
3634 "The location where subtrees should be archived.
3636 The value of this variable is a string, consisting of two parts,
3637 separated by a double-colon. The first part is a filename and
3638 the second part is a headline.
3640 When the filename is omitted, archiving happens in the same file.
3641 %s in the filename will be replaced by the current file
3642 name (without the directory part). Archiving to a different file
3643 is useful to keep archived entries from contributing to the
3646 The archived entries will be filed as subtrees of the specified
3647 headline. When the headline is omitted, the subtrees are simply
3648 filed away at the end of the file, as top-level entries. Also in
3649 the heading you can use %s to represent the file name, this can be
3650 useful when using the same archive for a number of different files.
3652 Here are a few examples:
3654 If the current file is Projects.org, archive in file
3655 Projects.org_archive, as top-level trees. This is the default.
3657 \"::* Archived Tasks\"
3658 Archive in the current file, under the top-level headline
3659 \"* Archived Tasks\".
3661 \"~/org/archive.org::\"
3662 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3664 \"~/org/archive.org::From %s\"
3665 Archive in file ~/org/archive.org (absolute path), under headlines
3666 \"From FILENAME\" where file name is the current file name.
3668 \"basement::** Finished Tasks\"
3669 Archive in file ./basement (relative path), as level 3 trees
3670 below the level 2 heading \"** Finished Tasks\".
3672 You may set this option on a per-file basis by adding to the buffer a
3675 #+ARCHIVE: basement::** Finished Tasks
3677 You may also define it locally for a subtree by setting an ARCHIVE property
3678 in the entry. If such a property is found in an entry, or anywhere up
3679 the hierarchy, it will be used."
3683 (defcustom org-archive-tag
"ARCHIVE"
3684 "The tag that marks a subtree as archived.
3685 An archived subtree does not open during visibility cycling, and does
3686 not contribute to the agenda listings.
3687 After changing this, font-lock must be restarted in the relevant buffers to
3688 get the proper fontification."
3690 :group
'org-keywords
3693 (defcustom org-agenda-skip-archived-trees t
3694 "Non-nil means the agenda will skip any items located in archived trees.
3695 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3696 variable is no longer recommended, you should leave it at the value t.
3697 Instead, use the key `v' to cycle the archives-mode in the agenda."
3699 :group
'org-agenda-skip
3702 (defcustom org-columns-skip-archived-trees t
3703 "Non-nil means ignore archived trees when creating column view."
3705 :group
'org-properties
3708 (defcustom org-cycle-open-archived-trees nil
3709 "Non-nil means `org-cycle' will open archived trees.
3710 An archived tree is a tree marked with the tag ARCHIVE.
3711 When nil, archived trees will stay folded. You can still open them with
3712 normal outline commands like `show-all', but not with the cycling commands."
3717 (defcustom org-sparse-tree-open-archived-trees nil
3718 "Non-nil means sparse tree construction shows matches in archived trees.
3719 When nil, matches in these trees are highlighted, but the trees are kept in
3722 :group
'org-sparse-trees
3725 (defun org-cycle-hide-archived-subtrees (state)
3726 "Re-hide all archived subtrees after a visibility state change."
3727 (when (and (not org-cycle-open-archived-trees
)
3728 (not (memq state
'(overview folded
))))
3730 (let* ((globalp (memq state
'(contents all
)))
3731 (beg (if globalp
(point-min) (point)))
3732 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3733 (org-hide-archived-subtrees beg end
)
3735 (if (looking-at (concat ".*:" org-archive-tag
":"))
3736 (message "%s" (substitute-command-keys
3737 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3739 (defun org-force-cycle-archived ()
3740 "Cycle subtree even if it is archived."
3742 (setq this-command
'org-cycle
)
3743 (let ((org-cycle-open-archived-trees t
))
3744 (call-interactively 'org-cycle
)))
3746 (defun org-hide-archived-subtrees (beg end
)
3747 "Re-hide all archived subtrees after a visibility state change."
3749 (let* ((re (concat ":" org-archive-tag
":")))
3751 (while (re-search-forward re end t
)
3752 (when (org-on-heading-p)
3753 (org-flag-subtree t
)
3754 (org-end-of-subtree t
))))))
3756 (defun org-flag-subtree (flag)
3758 (org-back-to-heading t
)
3759 (outline-end-of-heading)
3760 (outline-flag-region (point)
3761 (progn (org-end-of-subtree t
) (point))
3764 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3767 (org-autoload "org-archive"
3768 '(org-add-archive-files org-archive-subtree
3769 org-archive-to-archive-sibling org-toggle-archive-tag
3770 org-archive-subtree-default
3771 org-archive-subtree-default-with-confirmation
)))
3773 ;; Autoload Column View Code
3775 (declare-function org-columns-number-to-string
"org-colview")
3776 (declare-function org-columns-get-format-and-top-level
"org-colview")
3777 (declare-function org-columns-compute
"org-colview")
3779 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3780 '(org-columns-number-to-string org-columns-get-format-and-top-level
3781 org-columns-compute org-agenda-columns org-columns-remove-overlays
3782 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3786 (declare-function org-id-store-link
"org-id")
3787 (declare-function org-id-locations-load
"org-id")
3788 (declare-function org-id-locations-save
"org-id")
3789 (defvar org-id-track-globally
)
3790 (org-autoload "org-id"
3791 '(org-id-get-create org-id-new org-id-copy org-id-get
3792 org-id-get-with-outline-path-completion
3793 org-id-get-with-outline-drilling
3794 org-id-goto org-id-find org-id-store-link
))
3796 ;; Autoload Plotting Code
3798 (org-autoload "org-plot"
3799 '(org-plot/gnuplot
))
3801 ;;; Variables for pre-computed regular expressions, all buffer local
3803 (defvar org-drawer-regexp nil
3804 "Matches first line of a hidden block.")
3805 (make-variable-buffer-local 'org-drawer-regexp
)
3806 (defvar org-todo-regexp nil
3807 "Matches any of the TODO state keywords.")
3808 (make-variable-buffer-local 'org-todo-regexp
)
3809 (defvar org-not-done-regexp nil
3810 "Matches any of the TODO state keywords except the last one.")
3811 (make-variable-buffer-local 'org-not-done-regexp
)
3812 (defvar org-not-done-heading-regexp nil
3813 "Matches a TODO headline that is not done.")
3814 (make-variable-buffer-local 'org-not-done-regexp
)
3815 (defvar org-todo-line-regexp nil
3816 "Matches a headline and puts TODO state into group 2 if present.")
3817 (make-variable-buffer-local 'org-todo-line-regexp
)
3818 (defvar org-complex-heading-regexp nil
3819 "Matches a headline and puts everything into groups:
3821 group 2: The todo keyword, maybe
3822 group 3: Priority cookie
3823 group 4: True headline
3825 (make-variable-buffer-local 'org-complex-heading-regexp
)
3826 (defvar org-complex-heading-regexp-format nil
)
3827 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3828 (defvar org-todo-line-tags-regexp nil
3829 "Matches a headline and puts TODO state into group 2 if present.
3830 Also put tags into group 4 if tags are present.")
3831 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3832 (defvar org-nl-done-regexp nil
3833 "Matches newline followed by a headline with the DONE keyword.")
3834 (make-variable-buffer-local 'org-nl-done-regexp
)
3835 (defvar org-looking-at-done-regexp nil
3836 "Matches the DONE keyword a point.")
3837 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3838 (defvar org-ds-keyword-length
12
3839 "Maximum length of the Deadline and SCHEDULED keywords.")
3840 (make-variable-buffer-local 'org-ds-keyword-length
)
3841 (defvar org-deadline-regexp nil
3842 "Matches the DEADLINE keyword.")
3843 (make-variable-buffer-local 'org-deadline-regexp
)
3844 (defvar org-deadline-time-regexp nil
3845 "Matches the DEADLINE keyword together with a time stamp.")
3846 (make-variable-buffer-local 'org-deadline-time-regexp
)
3847 (defvar org-deadline-line-regexp nil
3848 "Matches the DEADLINE keyword and the rest of the line.")
3849 (make-variable-buffer-local 'org-deadline-line-regexp
)
3850 (defvar org-scheduled-regexp nil
3851 "Matches the SCHEDULED keyword.")
3852 (make-variable-buffer-local 'org-scheduled-regexp
)
3853 (defvar org-scheduled-time-regexp nil
3854 "Matches the SCHEDULED keyword together with a time stamp.")
3855 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3856 (defvar org-closed-time-regexp nil
3857 "Matches the CLOSED keyword together with a time stamp.")
3858 (make-variable-buffer-local 'org-closed-time-regexp
)
3860 (defvar org-keyword-time-regexp nil
3861 "Matches any of the 4 keywords, together with the time stamp.")
3862 (make-variable-buffer-local 'org-keyword-time-regexp
)
3863 (defvar org-keyword-time-not-clock-regexp nil
3864 "Matches any of the 3 keywords, together with the time stamp.")
3865 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
3866 (defvar org-maybe-keyword-time-regexp nil
3867 "Matches a timestamp, possibly preceeded by a keyword.")
3868 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
3869 (defvar org-planning-or-clock-line-re nil
3870 "Matches a line with planning or clock info.")
3871 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
3872 (defvar org-all-time-keywords nil
3873 "List of time keywords.")
3874 (make-variable-buffer-local 'org-all-time-keywords
)
3876 (defconst org-plain-time-of-day-regexp
3879 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3882 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3884 "Regular expression to match a plain time or time range.
3885 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3886 groups carry important information:
3888 1 the first time, range or not
3889 8 the second time, if it is a range.")
3891 (defconst org-plain-time-extension-regexp
3894 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3895 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3896 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3897 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3898 groups carry important information:
3901 9 minutes of duration")
3903 (defconst org-stamp-time-of-day-regexp
3905 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3906 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3908 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3909 "Regular expression to match a timestamp time or time range.
3910 After a match, the following groups carry important information:
3912 1 date plus weekday, for back referencing to make sure both times are on the same day
3913 2 the first time, range or not
3914 4 the second time, if it is a range.")
3916 (defconst org-startup-options
3917 '(("fold" org-startup-folded t
)
3918 ("overview" org-startup-folded t
)
3919 ("nofold" org-startup-folded nil
)
3920 ("showall" org-startup-folded nil
)
3921 ("showeverything" org-startup-folded showeverything
)
3922 ("content" org-startup-folded content
)
3923 ("indent" org-startup-indented t
)
3924 ("noindent" org-startup-indented nil
)
3925 ("hidestars" org-hide-leading-stars t
)
3926 ("showstars" org-hide-leading-stars nil
)
3927 ("odd" org-odd-levels-only t
)
3928 ("oddeven" org-odd-levels-only nil
)
3929 ("align" org-startup-align-all-tables t
)
3930 ("noalign" org-startup-align-all-tables nil
)
3931 ("customtime" org-display-custom-times t
)
3932 ("logdone" org-log-done time
)
3933 ("lognotedone" org-log-done note
)
3934 ("nologdone" org-log-done nil
)
3935 ("lognoteclock-out" org-log-note-clock-out t
)
3936 ("nolognoteclock-out" org-log-note-clock-out nil
)
3937 ("logrepeat" org-log-repeat state
)
3938 ("lognoterepeat" org-log-repeat note
)
3939 ("nologrepeat" org-log-repeat nil
)
3940 ("logreschedule" org-log-reschedule time
)
3941 ("lognotereschedule" org-log-reschedule note
)
3942 ("nologreschedule" org-log-reschedule nil
)
3943 ("logredeadline" org-log-redeadline time
)
3944 ("lognoteredeadline" org-log-redeadline note
)
3945 ("nologredeadline" org-log-redeadline nil
)
3946 ("logrefile" org-log-refile time
)
3947 ("lognoterefile" org-log-refile note
)
3948 ("nologrefile" org-log-refile nil
)
3949 ("fninline" org-footnote-define-inline t
)
3950 ("nofninline" org-footnote-define-inline nil
)
3951 ("fnlocal" org-footnote-section nil
)
3952 ("fnauto" org-footnote-auto-label t
)
3953 ("fnprompt" org-footnote-auto-label nil
)
3954 ("fnconfirm" org-footnote-auto-label confirm
)
3955 ("fnplain" org-footnote-auto-label plain
)
3956 ("fnadjust" org-footnote-auto-adjust t
)
3957 ("nofnadjust" org-footnote-auto-adjust nil
)
3958 ("constcgs" constants-unit-system cgs
)
3959 ("constSI" constants-unit-system SI
)
3960 ("noptag" org-tag-persistent-alist nil
)
3961 ("hideblocks" org-hide-block-startup t
)
3962 ("nohideblocks" org-hide-block-startup nil
)
3963 ("beamer" org-startup-with-beamer-mode t
))
3964 "Variable associated with STARTUP options for org-mode.
3965 Each element is a list of three items: The startup options as written
3966 in the #+STARTUP line, the corresponding variable, and the value to
3967 set this variable to if the option is found. An optional forth element PUSH
3968 means to push this value onto the list in the variable.")
3970 (defun org-set-regexps-and-options ()
3971 "Precompute regular expressions for current buffer."
3973 (org-set-local 'org-todo-kwd-alist nil
)
3974 (org-set-local 'org-todo-key-alist nil
)
3975 (org-set-local 'org-todo-key-trigger nil
)
3976 (org-set-local 'org-todo-keywords-1 nil
)
3977 (org-set-local 'org-done-keywords nil
)
3978 (org-set-local 'org-todo-heads nil
)
3979 (org-set-local 'org-todo-sets nil
)
3980 (org-set-local 'org-todo-log-states nil
)
3981 (org-set-local 'org-file-properties nil
)
3982 (org-set-local 'org-file-tags nil
)
3983 (let ((re (org-make-options-regexp
3984 '("CATEGORY" "TODO" "COLUMNS"
3985 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
3986 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS")
3987 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
3989 kwds kws0 kwsa key log value cat arch tags const links hw dws
3990 tail sep kws1 prio props ftags drawers beamer-p
3991 ext-setup-or-nil setup-contents
(start 0))
3995 (goto-char (point-min))
3996 (while (or (and ext-setup-or-nil
3997 (string-match re ext-setup-or-nil start
)
3998 (setq start
(match-end 0)))
3999 (and (setq ext-setup-or-nil nil start
0)
4000 (re-search-forward re nil t
)))
4001 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4002 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4004 ((equal key
"CATEGORY")
4005 (if (string-match "[ \t]+$" value
)
4006 (setq value
(replace-match "" t t value
)))
4008 ((member key
'("SEQ_TODO" "TODO"))
4009 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4010 ((equal key
"TYP_TODO")
4011 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4012 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4013 ;; general TODO-like setup
4014 (push (cons (intern (downcase (match-string 1 key
)))
4015 (org-split-string value splitre
)) kwds
))
4017 (setq tags
(append tags
(if tags
'("\\n") nil
)
4018 (org-split-string value splitre
))))
4019 ((equal key
"COLUMNS")
4020 (org-set-local 'org-columns-default-format value
))
4022 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4023 (push (cons (match-string 1 value
)
4024 (org-trim (match-string 2 value
)))
4026 ((equal key
"PRIORITIES")
4027 (setq prio
(org-split-string value
" +")))
4028 ((equal key
"PROPERTY")
4029 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4030 (push (cons (match-string 1 value
) (match-string 2 value
))
4032 ((equal key
"FILETAGS")
4033 (when (string-match "\\S-" value
)
4038 (mapcar (lambda (x) (org-split-string x
":"))
4039 (org-split-string value
)))))))
4040 ((equal key
"DRAWERS")
4041 (setq drawers
(org-split-string value splitre
)))
4042 ((equal key
"CONSTANTS")
4043 (setq const
(append const
(org-split-string value splitre
))))
4044 ((equal key
"STARTUP")
4045 (let ((opts (org-split-string value splitre
))
4047 (while (setq l
(pop opts
))
4048 (when (setq l
(assoc l org-startup-options
))
4049 (setq var
(nth 1 l
) val
(nth 2 l
))
4051 (set (make-local-variable var
) val
)
4052 (if (not (listp (symbol-value var
)))
4053 (set (make-local-variable var
) nil
))
4054 (set (make-local-variable var
) (symbol-value var
))
4055 (add-to-list var val
))))))
4056 ((equal key
"ARCHIVE")
4057 (string-match " *$" value
)
4058 (setq arch
(replace-match "" t t value
))
4059 (remove-text-properties 0 (length arch
)
4060 '(face t fontified t
) arch
))
4061 ((equal key
"LATEX_CLASS")
4062 (setq beamer-p
(equal value
"beamer")))
4063 ((equal key
"SETUPFILE")
4064 (setq setup-contents
(org-file-contents
4066 (org-remove-double-quotes value
))
4068 (if (not ext-setup-or-nil
)
4069 (setq ext-setup-or-nil setup-contents start
0)
4070 (setq ext-setup-or-nil
4071 (concat (substring ext-setup-or-nil
0 start
)
4072 "\n" setup-contents
"\n"
4073 (substring ext-setup-or-nil start
)))))
4076 (org-set-local 'org-category
(intern cat
))
4077 (push (cons "CATEGORY" cat
) props
))
4079 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4080 (setq prio
(mapcar 'string-to-char prio
))
4081 (org-set-local 'org-highest-priority
(nth 0 prio
))
4082 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4083 (org-set-local 'org-default-priority
(nth 2 prio
)))
4084 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4085 (and ftags
(org-set-local 'org-file-tags
4086 (mapcar 'org-add-prop-inherited ftags
)))
4087 (and drawers
(org-set-local 'org-drawers drawers
))
4088 (and arch
(org-set-local 'org-archive-location arch
))
4089 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4090 ;; Process the TODO keywords
4092 ;; Use the global values as if they had been given locally.
4093 (setq kwds
(default-value 'org-todo-keywords
))
4094 (if (stringp (car kwds
))
4095 (setq kwds
(list (cons org-todo-interpretation
4096 (default-value 'org-todo-keywords
)))))
4097 (setq kwds
(reverse kwds
)))
4098 (setq kwds
(nreverse kwds
))
4100 (while (setq kws
(pop kwds
))
4102 (run-hook-with-args-until-success
4103 'org-todo-setup-filter-hook kws
)
4105 (setq inter
(pop kws
) sep
(member "|" kws
)
4106 kws0
(delete "|" (copy-sequence kws
))
4111 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4113 (setq kw
(match-string 1 x
)
4114 key
(and (match-end 2) (match-string 2 x
))
4115 log
(org-extract-log-state-settings x
))
4116 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4117 (and log
(push log org-todo-log-states
))
4119 (error "Invalid TODO keyword %s" x
)))
4121 kwsa
(if kwsa
(append '((:startgroup
))
4125 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4126 tail
(list inter hw
(car dws
) (org-last dws
))))
4127 (add-to-list 'org-todo-heads hw
'append
)
4128 (push kws1 org-todo-sets
)
4129 (setq org-done-keywords
(append org-done-keywords dws nil
))
4130 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4131 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4132 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4133 (setq org-todo-sets
(nreverse org-todo-sets
)
4134 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4135 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4136 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4137 ;; Process the constants
4140 (while (setq e
(pop const
))
4141 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4142 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4143 (setq org-table-formula-constants-local cst
)))
4145 ;; Process the tags.
4148 (while (setq e
(pop tags
))
4150 ((equal e
"{") (push '(:startgroup
) tgs
))
4151 ((equal e
"}") (push '(:endgroup
) tgs
))
4152 ((equal e
"\\n") (push '(:newline
) tgs
))
4153 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4154 (push (cons (match-string 1 e
)
4155 (string-to-char (match-string 2 e
)))
4157 (t (push (list e
) tgs
))))
4158 (org-set-local 'org-tag-alist nil
)
4159 (while (setq e
(pop tgs
))
4160 (or (and (stringp (car e
))
4161 (assoc (car e
) org-tag-alist
))
4162 (push e org-tag-alist
)))))
4164 ;; Compute the regular expressions and other local variables
4165 (if (not org-done-keywords
)
4166 (setq org-done-keywords
(and org-todo-keywords-1
4167 (list (org-last org-todo-keywords-1
)))))
4168 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4169 (length org-scheduled-string
)
4170 (length org-clock-string
)
4171 (length org-closed-string
)))
4173 (concat "^[ \t]*:\\("
4174 (mapconcat 'regexp-quote org-drawers
"\\|")
4176 org-not-done-keywords
4177 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4179 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4183 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4185 org-not-done-heading-regexp
4186 (concat "^\\(\\*+\\)[ \t]+\\("
4187 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4189 org-todo-line-regexp
4190 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4191 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4192 "\\)\\>\\)?[ \t]*\\(.*\\)")
4193 org-complex-heading-regexp
4194 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4195 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4196 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4197 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4198 org-complex-heading-regexp-format
4199 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4200 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4201 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(%s\\)"
4202 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4204 (concat "\n\\*+[ \t]+"
4205 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4207 org-todo-line-tags-regexp
4208 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4209 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4211 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4212 org-looking-at-done-regexp
4214 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4216 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4217 org-deadline-time-regexp
4218 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4219 org-deadline-line-regexp
4220 (concat "\\<\\(" org-deadline-string
"\\).*")
4221 org-scheduled-regexp
4222 (concat "\\<" org-scheduled-string
)
4223 org-scheduled-time-regexp
4224 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4225 org-closed-time-regexp
4226 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4227 org-keyword-time-regexp
4228 (concat "\\<\\(" org-scheduled-string
4229 "\\|" org-deadline-string
4230 "\\|" org-closed-string
4231 "\\|" org-clock-string
"\\)"
4232 " *[[<]\\([^]>]+\\)[]>]")
4233 org-keyword-time-not-clock-regexp
4234 (concat "\\<\\(" org-scheduled-string
4235 "\\|" org-deadline-string
4236 "\\|" org-closed-string
4238 " *[[<]\\([^]>]+\\)[]>]")
4239 org-maybe-keyword-time-regexp
4240 (concat "\\(\\<\\(" org-scheduled-string
4241 "\\|" org-deadline-string
4242 "\\|" org-closed-string
4243 "\\|" org-clock-string
"\\)\\)?"
4244 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4245 org-planning-or-clock-line-re
4246 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4247 "\\|" org-deadline-string
4248 "\\|" org-closed-string
"\\|" org-clock-string
4250 org-all-time-keywords
4251 (mapcar (lambda (w) (substring w
0 -
1))
4252 (list org-scheduled-string org-deadline-string
4253 org-clock-string org-closed-string
))
4255 (org-compute-latex-and-specials-regexp)
4256 (org-set-font-lock-defaults))))
4258 (defun org-file-contents (file &optional noerror
)
4259 "Return the contents of FILE, as a string."
4261 (not (file-readable-p file
)))
4264 (message "Cannot read file %s" file
)
4267 (error "Cannot read file %s" file
))
4269 (insert-file-contents file
)
4272 (defun org-extract-log-state-settings (x)
4273 "Extract the log state setting from a TODO keyword string.
4274 This will extract info from a string like \"WAIT(w@/!)\"."
4275 (let (kw key log1 log2
)
4276 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4277 (setq kw
(match-string 1 x
)
4278 key
(and (match-end 2) (match-string 2 x
))
4279 log1
(and (match-end 3) (match-string 3 x
))
4280 log2
(and (match-end 4) (match-string 4 x
)))
4283 (and log1
(if (equal log1
"!") 'time
'note
))
4284 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4286 (defun org-remove-keyword-keys (list)
4287 "Remove a pair of parenthesis at the end of each string in LIST."
4289 (if (string-match "(.*)$" x
)
4290 (substring x
0 (match-beginning 0))
4294 (defun org-assign-fast-keys (alist)
4295 "Assign fast keys to a keyword-key alist.
4296 Respect keys that are already there."
4297 (let (new e
(alt ?
0))
4298 (while (setq e
(pop alist
))
4299 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4300 (cdr e
)) ;; Key already assigned.
4302 (let ((clist (string-to-list (downcase (car e
))))
4303 (used (append new alist
)))
4304 (when (= (car clist
) ?
@)
4306 (while (and clist
(rassoc (car clist
) used
))
4309 (while (rassoc alt used
)
4311 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4314 ;;; Some variables used in various places
4316 (defvar org-window-configuration nil
4317 "Used in various places to store a window configuration.")
4318 (defvar org-selected-window nil
4319 "Used in various places to store a window configuration.")
4320 (defvar org-finish-function nil
4321 "Function to be called when `C-c C-c' is used.
4322 This is for getting out of special buffers like remember.")
4325 ;; FIXME: Occasionally check by commenting these, to make sure
4326 ;; no other functions uses these, forgetting to let-bind them.
4331 ;; Defined somewhere in this file, but used before definition.
4332 (defvar org-entities
) ;; defined in org-entities.el
4333 (defvar org-struct-menu
)
4334 (defvar org-org-menu
)
4335 (defvar org-tbl-menu
)
4337 ;;;; Define the Org-mode
4339 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4340 (error "Conflict with outdated version of allout.el. Load org.el before allout.el, or upgrade to newer allout, for example by switching to Emacs 22."))
4343 ;; We use a before-change function to check if a table might need
4345 (defvar org-table-may-need-update t
4346 "Indicates that a table might need an update.
4347 This variable is set by `org-before-change-function'.
4348 `org-table-align' sets it back to nil.")
4349 (defun org-before-change-function (beg end
)
4350 "Every change indicates that a table might need an update."
4351 (setq org-table-may-need-update t
))
4352 (defvar org-mode-map
)
4353 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4354 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4355 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4356 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4357 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4358 (defvar org-table-buffer-is-an nil
)
4359 (defconst org-outline-regexp
"\\*+ ")
4362 (define-derived-mode org-mode outline-mode
"Org"
4363 "Outline-based notes management and organizer, alias
4364 \"Carsten's outline-mode for keeping track of everything.\"
4366 Org-mode develops organizational tasks around a NOTES file which
4367 contains information about projects as plain text. Org-mode is
4368 implemented on top of outline-mode, which is ideal to keep the content
4369 of large files well structured. It supports ToDo items, deadlines and
4370 time stamps, which magically appear in the diary listing of the Emacs
4371 calendar. Tables are easily created with a built-in table editor.
4372 Plain text URL-like links connect to websites, emails (VM), Usenet
4373 messages (Gnus), BBDB entries, and any files related to the project.
4374 For printing and sharing of notes, an Org-mode file (or a part of it)
4375 can be exported as a structured ASCII or HTML file.
4377 The following commands are available:
4381 ;; Get rid of Outline menus, they are not needed
4382 ;; Need to do this here because define-derived-mode sets up
4383 ;; the keymap so late. Still, it is a waste to call this each time
4384 ;; we switch another buffer into org-mode.
4385 (if (featurep 'xemacs
)
4386 (when (boundp 'outline-mode-menu-heading
)
4387 ;; Assume this is Greg's port, it uses easymenu
4388 (easy-menu-remove outline-mode-menu-heading
)
4389 (easy-menu-remove outline-mode-menu-show
)
4390 (easy-menu-remove outline-mode-menu-hide
))
4391 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4392 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4393 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4395 (org-load-modules-maybe)
4396 (easy-menu-add org-org-menu
)
4397 (easy-menu-add org-tbl-menu
)
4398 (org-install-agenda-files-menu)
4399 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4400 (add-to-invisibility-spec '(org-cwidth))
4401 (add-to-invisibility-spec '(org-hide-block . t
))
4402 (when (featurep 'xemacs
)
4403 (org-set-local 'line-move-ignore-invisible t
))
4404 (org-set-local 'outline-regexp org-outline-regexp
)
4405 (org-set-local 'outline-level
'org-outline-level
)
4406 (when (and org-ellipsis
4407 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4408 (fboundp 'make-glyph-code
))
4409 (unless org-display-table
4410 (setq org-display-table
(make-display-table)))
4411 (set-display-table-slot
4414 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4416 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4417 (setq buffer-display-table org-display-table
))
4418 (org-set-regexps-and-options)
4419 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4420 ;; tag faces set outside customize.... force initialization.
4421 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4423 (org-set-local 'calc-embedded-open-mode
"# ")
4424 (modify-syntax-entry ?
@ "w")
4425 (if org-startup-truncated
(setq truncate-lines t
))
4426 (org-set-local 'font-lock-unfontify-region-function
4427 'org-unfontify-region
)
4428 ;; Activate before-change-function
4429 (org-set-local 'org-table-may-need-update t
)
4430 (org-add-hook 'before-change-functions
'org-before-change-function nil
4432 ;; Check for running clock before killing a buffer
4433 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4434 ;; Paragraphs and auto-filling
4435 (org-set-autofill-regexps)
4436 (setq indent-line-function
'org-indent-line-function
)
4437 (org-update-radio-target-regexp)
4438 ;; Make sure dependence stuff works reliably, even for users who set it
4440 (if org-enforce-todo-dependencies
4441 (add-hook 'org-blocker-hook
4442 'org-block-todo-from-children-or-siblings-or-parent
)
4443 (remove-hook 'org-blocker-hook
4444 'org-block-todo-from-children-or-siblings-or-parent
))
4445 (if org-enforce-todo-checkbox-dependencies
4446 (add-hook 'org-blocker-hook
4447 'org-block-todo-from-checkboxes
)
4448 (remove-hook 'org-blocker-hook
4449 'org-block-todo-from-checkboxes
))
4451 ;; Comment characters
4452 ;; (org-set-local 'comment-start "#")
4453 (org-set-local 'comment-padding
" ")
4454 (modify-syntax-entry ?
# "<")
4455 ;; (modify-syntax-entry ?\n ">")
4457 ;; Align options lines
4459 'align-mode-rules-list
4460 '((org-in-buffer-settings
4461 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4462 (modes .
'(org-mode)))))
4465 (org-set-local 'imenu-create-index-function
4466 'org-imenu-get-tree
)
4468 ;; Make isearch reveal context
4469 (if (or (featurep 'xemacs
)
4470 (not (boundp 'outline-isearch-open-invisible-function
)))
4471 ;; Emacs 21 and XEmacs make use of the hook
4472 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4473 ;; Emacs 22 deals with this through a special variable
4474 (org-set-local 'outline-isearch-open-invisible-function
4475 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4477 ;; Turn on org-beamer-mode?
4478 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4480 ;; If empty file that did not turn on org-mode automatically, make it to.
4481 (if (and org-insert-mode-line-in-empty-file
4483 (= (point-min) (point-max)))
4484 (insert "# -*- mode: org -*-\n\n"))
4485 (unless org-inhibit-startup
4486 (when org-startup-align-all-tables
4487 (let ((bmp (buffer-modified-p)))
4488 (org-table-map-tables 'org-table-align
'quietly
)
4489 (set-buffer-modified-p bmp
)))
4490 (when org-startup-indented
4491 (require 'org-indent
)
4492 (org-indent-mode 1))
4493 (unless org-inhibit-startup-visibility-stuff
4494 (org-set-startup-visibility))))
4496 (when (fboundp 'abbrev-table-put
)
4497 (abbrev-table-put org-mode-abbrev-table
4498 :parents
(list text-mode-abbrev-table
)))
4500 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4502 (defun org-current-time ()
4503 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4504 (if (> (car org-time-stamp-rounding-minutes
) 1)
4505 (let ((r (car org-time-stamp-rounding-minutes
))
4506 (time (decode-time)))
4508 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4512 ;;;; Font-Lock stuff, including the activators
4514 (defvar org-mouse-map
(make-sparse-keymap))
4515 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
4516 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
4517 (when org-mouse-1-follows-link
4518 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
4519 (when org-tab-follows-link
4520 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
4521 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
4523 (require 'font-lock
)
4525 (defconst org-non-link-chars
"]\t\n\r<>")
4526 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
4527 "shell" "elisp" "doi"))
4528 (defvar org-link-types-re nil
4529 "Matches a link that has a url-like prefix like \"http:\"")
4530 (defvar org-link-re-with-space nil
4531 "Matches a link with spaces, optional angular brackets around it.")
4532 (defvar org-link-re-with-space2 nil
4533 "Matches a link with spaces, optional angular brackets around it.")
4534 (defvar org-link-re-with-space3 nil
4535 "Matches a link with spaces, only for internal part in bracket links.")
4536 (defvar org-angle-link-re nil
4537 "Matches link with angular brackets, spaces are allowed.")
4538 (defvar org-plain-link-re nil
4539 "Matches plain link, without spaces.")
4540 (defvar org-bracket-link-regexp nil
4541 "Matches a link in double brackets.")
4542 (defvar org-bracket-link-analytic-regexp nil
4543 "Regular expression used to analyze links.
4544 Here is what the match groups contain after a match:
4550 (defvar org-bracket-link-analytic-regexp
++ nil
4551 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4552 (defvar org-any-link-re nil
4553 "Regular expression matching any link.")
4555 (defun org-make-link-regexps ()
4556 "Update the link regular expressions.
4557 This should be called after the variable `org-link-types' has changed."
4558 (setq org-link-types-re
4560 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
4561 org-link-re-with-space
4563 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4564 "\\([^" org-non-link-chars
" ]"
4565 "[^" org-non-link-chars
"]*"
4566 "[^" org-non-link-chars
" ]\\)>?")
4567 org-link-re-with-space2
4569 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4570 "\\([^" org-non-link-chars
" ]"
4572 "[^" org-non-link-chars
" ]\\)>?")
4573 org-link-re-with-space3
4575 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4576 "\\([^" org-non-link-chars
" ]"
4580 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4581 "\\([^" org-non-link-chars
" ]"
4582 "[^" org-non-link-chars
"]*"
4586 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4587 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4588 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4589 org-bracket-link-regexp
4590 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4591 org-bracket-link-analytic-regexp
4594 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
4597 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4599 org-bracket-link-analytic-regexp
++
4602 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
4605 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4608 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
4609 org-angle-link-re
"\\)\\|\\("
4610 org-plain-link-re
"\\)")))
4612 (org-make-link-regexps)
4614 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4615 "Regular expression for fast time stamp matching.")
4616 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4617 "Regular expression for fast time stamp matching.")
4618 (defconst org-ts-regexp0
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4619 "Regular expression matching time strings for analysis.
4620 This one does not require the space after the date, so it can be used
4621 on a string that terminates immediately after the date.")
4622 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4623 "Regular expression matching time strings for analysis.")
4624 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
4625 "Regular expression matching time stamps, with groups.")
4626 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
4627 "Regular expression matching time stamps (also [..]), with groups.")
4628 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
4629 "Regular expression matching a time stamp range.")
4630 (defconst org-tr-regexp-both
4631 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
4632 "Regular expression matching a time stamp range.")
4633 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
4634 org-ts-regexp
"\\)?")
4635 "Regular expression matching a time stamp or time stamp range.")
4636 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
4637 org-ts-regexp-both
"\\)?")
4638 "Regular expression matching a time stamp or time stamp range.
4639 The time stamps may be either active or inactive.")
4641 (defvar org-emph-face nil
)
4643 (defun org-do-emphasis-faces (limit)
4644 "Run through the buffer and add overlays to links."
4646 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
4647 (if (not (= (char-after (match-beginning 3))
4648 (char-after (match-beginning 4))))
4651 (setq a
(assoc (match-string 3) org-emphasis-alist
))
4652 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4656 (org-remove-flyspell-overlays-in
4657 (match-beginning 0) (match-end 0)))
4658 (add-text-properties (match-beginning 2) (match-end 2)
4659 '(font-lock-multiline t
))
4660 (when org-hide-emphasis-markers
4661 (add-text-properties (match-end 4) (match-beginning 5)
4662 '(invisible org-link
))
4663 (add-text-properties (match-beginning 3) (match-end 3)
4664 '(invisible org-link
)))))
4668 (defun org-emphasize (&optional char
)
4669 "Insert or change an emphasis, i.e. a font like bold or italic.
4670 If there is an active region, change that region to a new emphasis.
4671 If there is no region, just insert the marker characters and position
4672 the cursor between them.
4673 CHAR should be either the marker character, or the first character of the
4674 HTML tag associated with that emphasis. If CHAR is a space, the means
4675 to remove the emphasis of the selected region.
4676 If char is not given (for example in an interactive call) it
4677 will be prompted for."
4679 (let ((eal org-emphasis-alist
) e det
4680 (erc org-emphasis-regexp-components
)
4682 (string "") beg end move tag c s
)
4683 (if (org-region-active-p)
4684 (setq beg
(region-beginning) end
(region-end)
4685 string
(buffer-substring beg end
))
4688 (while (setq e
(pop eal
))
4689 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
4691 (push (cons c
(string-to-char (car e
))) det
)
4692 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
4693 (substring tag
1)))))
4694 (setq det
(nreverse det
))
4696 (message "%s" (concat "Emphasis marker or tag:" prompt
))
4697 (setq char
(read-char-exclusive)))
4698 (setq char
(or (cdr (assoc char det
)) char
))
4699 (if (equal char ?\
)
4700 (setq s
"" move nil
)
4701 (unless (assoc (char-to-string char
) org-emphasis-alist
)
4702 (error "No such emphasis marker: \"%c\"" char
))
4703 (setq s
(char-to-string char
)))
4704 (while (and (> (length string
) 1)
4705 (equal (substring string
0 1) (substring string -
1))
4706 (assoc (substring string
0 1) org-emphasis-alist
))
4707 (setq string
(substring string
1 -
1)))
4708 (setq string
(concat s string s
))
4709 (if beg
(delete-region beg end
))
4711 (string-match (concat "[" (nth 0 erc
) "\n]")
4712 (char-to-string (char-before (point)))))
4715 (string-match (concat "[" (nth 1 erc
) "\n]")
4716 (char-to-string (char-after (point)))))
4717 (insert " ") (backward-char 1))
4719 (and move
(backward-char 1))))
4721 (defconst org-nonsticky-props
4722 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
4724 (defsubst org-rear-nonsticky-at
(pos)
4725 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
4727 (defun org-activate-plain-links (limit)
4728 "Run through the buffer and add overlays to links."
4731 (if (re-search-forward org-plain-link-re limit t
)
4733 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4734 (setq f
(get-text-property (match-beginning 0) 'face
))
4735 (if (or (eq f
'org-tag
)
4736 (and (listp f
) (memq 'org-tag f
)))
4738 (add-text-properties (match-beginning 0) (match-end 0)
4739 (list 'mouse-face
'highlight
4741 'keymap org-mouse-map
))
4742 (org-rear-nonsticky-at (match-end 0)))
4745 (defun org-activate-code (limit)
4746 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t
)
4748 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4749 (remove-text-properties (match-beginning 0) (match-end 0)
4750 '(display t invisible t intangible t
))
4753 (defun org-fontify-meta-lines-and-blocks (limit)
4754 "Fontify #+ lines and blocks, in the correct ways."
4755 (let ((case-fold-search t
))
4756 (if (re-search-forward
4757 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4759 (let ((beg (match-beginning 0))
4760 (beg1 (line-beginning-position 2))
4761 (dc1 (downcase (match-string 2)))
4762 (dc3 (downcase (match-string 3)))
4763 end end1 quoting block-type
)
4765 ((member dc1
'("html:" "ascii:" "latex:" "docbook:"))
4766 ;; a single line of backend-specific content
4767 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4768 (remove-text-properties (match-beginning 0) (match-end 0)
4769 '(display t invisible t intangible t
))
4770 (add-text-properties (match-beginning 1) (match-end 3)
4771 '(font-lock-fontified t face org-meta-line
))
4772 (add-text-properties (match-beginning 6) (match-end 6)
4773 '(font-lock-fontified t face org-block
))
4775 ((and (match-end 4) (equal dc3
"begin"))
4777 (setq block-type
(downcase (match-string 5))
4778 quoting
(member block-type org-protecting-blocks
))
4779 (when (re-search-forward
4780 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4781 nil t
) ;; on purpose, we look further than LIMIT
4782 (setq end
(match-end 0) end1
(1- (match-beginning 0)))
4784 (remove-text-properties beg end
4785 '(display t invisible t intangible t
)))
4786 (add-text-properties
4788 '(font-lock-fontified t font-lock-multiline t
))
4789 (add-text-properties beg beg1
'(face org-meta-line
))
4790 (add-text-properties end1 end
'(face org-meta-line
))
4793 (add-text-properties beg1 end1
'(face org-block
)))
4794 ((not org-fontify-quote-and-verse-blocks
))
4795 ((string= block-type
"quote")
4796 (add-text-properties beg1 end1
'(face org-quote
)))
4797 ((string= block-type
"verse")
4798 (add-text-properties beg1 end1
'(face org-verse
))))
4800 ((member dc1
'("title:" "author:" "email:" "date:"))
4801 (add-text-properties
4803 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
4804 '(font-lock-fontified t invisible t
)
4805 '(font-lock-fontified t face org-document-info-keyword
)))
4806 (add-text-properties
4807 (match-beginning 6) (match-end 6)
4808 (if (string-equal dc1
"title:")
4809 '(font-lock-fontified t face org-document-title
)
4810 '(font-lock-fontified t face org-document-info
))))
4811 ((not (member (char-after beg
) '(?\ ?
\t)))
4812 ;; just any other in-buffer setting, but not indented
4813 (add-text-properties
4815 '(font-lock-fontified t face org-meta-line
))
4817 ((or (member dc1
'("begin:" "end:" "caption:" "label:"
4818 "orgtbl:" "tblfm:" "tblname:"))
4819 (and (match-end 4) (equal dc3
"attr")))
4820 (add-text-properties
4822 '(font-lock-fontified t face org-meta-line
))
4824 ((member dc3
'(" " ""))
4825 (add-text-properties
4827 '(font-lock-fontified t face font-lock-comment-face
)))
4830 (defun org-activate-angle-links (limit)
4831 "Run through the buffer and add overlays to links."
4832 (if (re-search-forward org-angle-link-re limit t
)
4834 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4835 (add-text-properties (match-beginning 0) (match-end 0)
4836 (list 'mouse-face
'highlight
4837 'keymap org-mouse-map
))
4838 (org-rear-nonsticky-at (match-end 0))
4841 (defun org-activate-footnote-links (limit)
4842 "Run through the buffer and add overlays to links."
4843 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
4846 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4847 (add-text-properties (match-beginning 2) (match-end 2)
4848 (list 'mouse-face
'highlight
4849 'keymap org-mouse-map
4851 (if (= (point-at-bol) (match-beginning 2))
4852 "Footnote definition"
4853 "Footnote reference")
4855 (org-rear-nonsticky-at (match-end 2))
4858 (defun org-activate-bracket-links (limit)
4859 "Run through the buffer and add overlays to bracketed links."
4860 (if (re-search-forward org-bracket-link-regexp limit t
)
4861 (let* ((help (concat "LINK: "
4862 (org-match-string-no-properties 1)))
4863 ;; FIXME: above we should remove the escapes.
4864 ;; but that requires another match, protecting match data,
4865 ;; a lot of overhead for font-lock.
4866 (ip (org-maybe-intangible
4867 (list 'invisible
'org-link
4868 'keymap org-mouse-map
'mouse-face
'highlight
4869 'font-lock-multiline t
'help-echo help
)))
4870 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
4871 'font-lock-multiline t
'help-echo help
)))
4872 ;; We need to remove the invisible property here. Table narrowing
4873 ;; may have made some of this invisible.
4874 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4875 (remove-text-properties (match-beginning 0) (match-end 0)
4879 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
4880 (org-rear-nonsticky-at (match-beginning 3))
4881 (add-text-properties (match-beginning 3) (match-end 3) vp
)
4882 (org-rear-nonsticky-at (match-end 3))
4883 (add-text-properties (match-end 3) (match-end 0) ip
)
4884 (org-rear-nonsticky-at (match-end 0)))
4885 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
4886 (org-rear-nonsticky-at (match-beginning 1))
4887 (add-text-properties (match-beginning 1) (match-end 1) vp
)
4888 (org-rear-nonsticky-at (match-end 1))
4889 (add-text-properties (match-end 1) (match-end 0) ip
)
4890 (org-rear-nonsticky-at (match-end 0)))
4893 (defun org-activate-dates (limit)
4894 "Run through the buffer and add overlays to dates."
4895 (if (re-search-forward org-tsr-regexp-both limit t
)
4897 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4898 (add-text-properties (match-beginning 0) (match-end 0)
4899 (list 'mouse-face
'highlight
4900 'keymap org-mouse-map
))
4901 (org-rear-nonsticky-at (match-end 0))
4902 (when org-display-custom-times
4904 (org-display-custom-time (match-beginning 3) (match-end 3)))
4905 (org-display-custom-time (match-beginning 1) (match-end 1)))
4908 (defvar org-target-link-regexp nil
4909 "Regular expression matching radio targets in plain text.")
4910 (make-variable-buffer-local 'org-target-link-regexp
)
4911 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
4912 "Regular expression matching a link target.")
4913 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
4914 "Regular expression matching a radio target.")
4915 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
4916 "Regular expression matching any target.")
4918 (defun org-activate-target-links (limit)
4919 "Run through the buffer and add overlays to target matches."
4920 (when org-target-link-regexp
4921 (let ((case-fold-search t
))
4922 (if (re-search-forward org-target-link-regexp limit t
)
4924 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4925 (add-text-properties (match-beginning 0) (match-end 0)
4926 (list 'mouse-face
'highlight
4927 'keymap org-mouse-map
4928 'help-echo
"Radio target link"
4929 'org-linked-text t
))
4930 (org-rear-nonsticky-at (match-end 0))
4933 (defun org-update-radio-target-regexp ()
4934 "Find all radio targets in this file and update the regular expression."
4936 (when (memq 'radio org-activate-links
)
4937 (setq org-target-link-regexp
4938 (org-make-target-link-regexp (org-all-targets 'radio
)))
4939 (org-restart-font-lock)))
4941 (defun org-hide-wide-columns (limit)
4943 (setq s
(text-property-any (point) (or limit
(point-max))
4946 (setq e
(next-single-property-change s
'org-cwidth
))
4947 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
4951 (defvar org-latex-and-specials-regexp nil
4952 "Regular expression for highlighting export special stuff.")
4953 (defvar org-match-substring-regexp
)
4954 (defvar org-match-substring-with-braces-regexp
)
4956 ;; This should be with the exporter code, but we also use if for font-locking
4957 (defconst org-export-html-special-string-regexps
4958 '(("\\\\-" .
"­")
4959 ("---\\([^-]\\)" .
"—\\1")
4960 ("--\\([^-]\\)" .
"–\\1")
4961 ("\\.\\.\\." .
"…"))
4962 "Regular expressions for special string conversion.")
4965 (defun org-compute-latex-and-specials-regexp ()
4966 "Compute regular expression for stuff treated specially by exporters."
4967 (if (not org-highlight-latex-fragments-and-specials
)
4968 (org-set-local 'org-latex-and-specials-regexp nil
)
4971 ((matchers (plist-get org-format-latex-options
:matchers
))
4972 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
4973 org-latex-regexps
)))
4974 (org-export-allow-BIND nil
)
4975 (options (org-combine-plists (org-default-export-plist)
4976 (org-infile-export-plist)))
4977 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
4978 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
4979 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
4980 (org-export-html-expand (plist-get options
:expand-quoted-html
))
4981 (org-export-with-special-strings (plist-get options
:special-strings
))
4984 ((equal org-export-with-sub-superscripts
'{})
4985 (list org-match-substring-with-braces-regexp
))
4986 (org-export-with-sub-superscripts
4987 (list org-match-substring-regexp
))
4990 (if org-export-with-LaTeX-fragments
4991 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
4993 (if org-export-with-TeX-macros
4994 (list (concat "\\\\"
4996 (append (mapcar 'car
(append org-entities-user
4998 (if (boundp 'org-latex-entities
)
5000 (or (car-safe x
) x
))
5005 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5006 (re-special (if org-export-with-special-strings
5007 (mapcar (lambda (x) (car x
))
5008 org-export-html-special-string-regexps
)))
5012 (if org-export-html-expand
"@<[^>\n]+>")
5015 'org-latex-and-specials-regexp
5016 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5019 (defun org-do-latex-and-special-faces (limit)
5020 "Run through the buffer and add overlays to links."
5021 (when org-latex-and-specials-regexp
5023 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5025 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5027 '(org-code org-verbatim underline
)))
5030 d
(cond ((member (char-after (1+ (match-beginning 0)))
5033 (font-lock-prepend-text-property
5034 (+ d
(match-beginning 0)) (match-end 0)
5035 'face
'org-latex-and-export-specials
)
5036 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5037 '(font-lock-multiline t
)))))
5040 (defun org-restart-font-lock ()
5041 "Restart font-lock-mode, to force refontification."
5042 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5044 (font-lock-mode 1)))
5046 (defun org-all-targets (&optional radio
)
5047 "Return a list of all targets in this file.
5048 With optional argument RADIO, only find radio targets."
5049 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5052 (goto-char (point-min))
5053 (while (re-search-forward re nil t
)
5054 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5057 (defun org-make-target-link-regexp (targets)
5058 "Make regular expression matching all strings in TARGETS.
5059 The regular expression finds the targets also if there is a line break
5066 (while (string-match " +" x
)
5067 (setq x
(replace-match "\\s-+" t t x
)))
5073 (defun org-activate-tags (limit)
5074 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t
)
5076 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5077 (add-text-properties (match-beginning 1) (match-end 1)
5078 (list 'mouse-face
'highlight
5079 'keymap org-mouse-map
))
5080 (org-rear-nonsticky-at (match-end 1))
5083 (defun org-outline-level ()
5084 "Compute the outline level of the heading at point.
5085 This function assumes that the cursor is at the beginning of a line matched
5086 by outline-regexp. Otherwise it returns garbage.
5087 If this is called at a normal headline, the level is the number of stars.
5088 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5089 For plain list items, if they are matched by `outline-regexp', this returns
5090 1000 plus the line indentation."
5092 (looking-at outline-regexp
)
5093 (if (match-beginning 1)
5094 (+ (org-get-string-indentation (match-string 1)) 1000)
5095 (1- (- (match-end 0) (match-beginning 0))))))
5097 (defvar org-font-lock-keywords nil
)
5099 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5100 "Regular expression matching a property line.")
5102 (defvar org-font-lock-hook nil
5103 "Functions to be called for special font lock stuff.")
5105 (defun org-font-lock-hook (limit)
5106 (run-hook-with-args 'org-font-lock-hook limit
))
5108 (defun org-set-font-lock-defaults ()
5109 (let* ((em org-fontify-emphasized-text
)
5110 (lk org-activate-links
)
5111 (org-font-lock-extra-keywords
5114 '(org-font-lock-hook)
5116 `(,(if org-fontify-whole-heading-line
5117 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5118 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5119 (1 (org-get-level-face 1))
5120 (2 (org-get-level-face 2))
5121 (3 (org-get-level-face 3)))
5123 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5126 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5127 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5128 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5129 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t
))
5131 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5132 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5134 (list org-property-re
5135 '(1 'org-special-keyword t
)
5136 '(3 'org-property-value t
))
5138 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5139 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5140 (if (memq 'plain lk
) '(org-activate-plain-links))
5141 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5142 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5143 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5144 (if (memq 'footnote lk
) '(org-activate-footnote-links
5145 (2 'org-footnote t
)))
5146 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5147 '(org-hide-wide-columns (0 nil append
))
5149 (list (concat "^\\*+[ \t]+" org-todo-regexp
"\\([ \t]\\|$\\)")
5150 '(1 (org-get-todo-face 1) t
))
5152 (if org-fontify-done-headline
5153 (list (concat "^[*]+ +\\<\\("
5154 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5156 '(2 'org-headline-done t
))
5159 '(org-font-lock-add-priority-faces)
5161 '(org-font-lock-add-tag-faces)
5163 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5164 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5165 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5166 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5169 (if (featurep 'xemacs
)
5170 '(org-do-emphasis-faces (0 nil append
))
5171 '(org-do-emphasis-faces)))
5173 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5174 2 'org-checkbox prepend
)
5175 (if org-provide-checkbox-statistics
5176 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5177 (0 (org-get-checkbox-statistics-face) t
)))
5178 ;; Description list items
5179 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5181 ;; ARCHIVEd headings
5182 (list (concat "^\\*+ \\(.*:" org-archive-tag
":.*\\)")
5183 '(1 'org-archived prepend
))
5185 '(org-do-latex-and-special-faces)
5187 '(org-activate-code (1 'org-code t
))
5189 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5190 "\\|" org-quote-string
"\\)\\>")
5191 '(1 'org-special-keyword t
))
5192 '("^#.*" (0 'font-lock-comment-face t
))
5193 ;; Blocks and meta lines
5194 '(org-fontify-meta-lines-and-blocks)
5196 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5197 ;; Now set the full font-lock-keywords
5198 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5199 (org-set-local 'font-lock-defaults
5200 '(org-font-lock-keywords t nil nil backward-paragraph
))
5201 (kill-local-variable 'font-lock-keywords
) nil
))
5203 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
5204 "Fontify string S like in Org-mode"
5207 (let ((org-odd-levels-only odd-levels
))
5209 (font-lock-fontify-buffer)
5215 (defun org-get-level-face (n)
5216 "Get the right face for match N in font-lock matching of headlines."
5217 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
5218 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
5219 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
5221 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
5223 (t (if org-level-color-stars-only nil org-f
))))
5225 (defun org-get-todo-face (kwd)
5226 "Get the right face for a TODO keyword KWD.
5227 If KWD is a number, get the corresponding match group."
5228 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5229 (or (org-face-from-face-or-color
5230 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
5231 (and (member kwd org-done-keywords
) 'org-done
)
5234 (defun org-face-from-face-or-color (context inherit face-or-color
)
5235 "Create a face list that inherits INHERIT, but sets the foreground color.
5236 When FACE-OR-COLOR is not a string, just return it."
5237 (if (stringp face-or-color
)
5238 (list :inherit inherit
5239 (cdr (assoc context org-faces-easy-properties
))
5243 (defun org-font-lock-add-tag-faces (limit)
5244 "Add the special tag faces."
5245 (when (and org-tag-faces org-tags-special-faces-re
)
5246 (while (re-search-forward org-tags-special-faces-re limit t
)
5247 (add-text-properties (match-beginning 1) (match-end 1)
5248 (list 'face
(org-get-tag-face 1)
5249 'font-lock-fontified t
))
5250 (backward-char 1))))
5252 (defun org-font-lock-add-priority-faces (limit)
5253 "Add the special priority faces."
5254 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
5255 (add-text-properties
5256 (match-beginning 0) (match-end 0)
5257 (list 'face
(or (org-face-from-face-or-color
5258 'priority
'org-special-keyword
5259 (cdr (assoc (char-after (match-beginning 1))
5260 org-priority-faces
)))
5261 'org-special-keyword
)
5262 'font-lock-fontified t
))))
5264 (defun org-get-tag-face (kwd)
5265 "Get the right face for a TODO keyword KWD.
5266 If KWD is a number, get the corresponding match group."
5267 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5268 (or (org-face-from-face-or-color
5269 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
5272 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
5273 "Remove fontification and activation overlays from links."
5274 (font-lock-default-unfontify-region beg end
)
5275 (let* ((buffer-undo-list t
)
5276 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
5277 (inhibit-modification-hooks t
)
5278 deactivate-mark buffer-file-name buffer-file-truename
)
5279 (remove-text-properties
5282 ;; also remove line-prefix and wrap-prefix properties
5283 '(mouse-face t keymap t org-linked-text t
5284 invisible t intangible t
5285 line-prefix t wrap-prefix t
5287 '(mouse-face t keymap t org-linked-text t
5288 invisible t intangible t
5289 org-no-flyspell t
)))))
5291 ;;;; Visibility cycling, including org-goto and indirect buffer
5295 (defvar org-cycle-global-status nil
)
5296 (make-variable-buffer-local 'org-cycle-global-status
)
5297 (defvar org-cycle-subtree-status nil
)
5298 (make-variable-buffer-local 'org-cycle-subtree-status
)
5302 (defvar org-inlinetask-min-level
)
5304 (defun org-cycle (&optional arg
)
5305 "TAB-action and visibility cycling for Org-mode.
5307 This is the command invoked in Org-mode by the TAB key. Its main purpose
5308 is outline visibility cycling, but it also invokes other actions
5309 in special contexts.
5311 - When this function is called with a prefix argument, rotate the entire
5312 buffer through 3 states (global cycling)
5313 1. OVERVIEW: Show only top-level headlines.
5314 2. CONTENTS: Show all headlines of all levels, but no body text.
5315 3. SHOW ALL: Show everything.
5316 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5317 determined by the variable `org-startup-folded', and by any VISIBILITY
5318 properties in the buffer.
5319 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5320 including any drawers.
5322 - When inside a table, re-align the table and move to the next field.
5324 - When point is at the beginning of a headline, rotate the subtree started
5325 by this line through 3 different states (local cycling)
5326 1. FOLDED: Only the main headline is shown.
5327 2. CHILDREN: The main headline and the direct children are shown.
5328 From this state, you can move to one of the children
5329 and zoom in further.
5330 3. SUBTREE: Show the entire subtree, including body text.
5331 If there is no subtree, switch directly from CHILDREN to FOLDED.
5333 - When point is at the beginning of an empty headline and the variable
5334 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5335 of the headline by demoting and promoting it to likely levels. This
5336 speeds up creation document structure by presing TAB once or several
5337 times right after creating a new headline.
5339 - When there is a numeric prefix, go up to a heading with level ARG, do
5340 a `show-subtree' and return to the previous cursor position. If ARG
5341 is negative, go up that many levels.
5343 - When point is not at the beginning of a headline, execute the global
5344 binding for TAB, which is re-indenting the line. See the option
5345 `org-cycle-emulate-tab' for details.
5347 - Special case: if point is at the beginning of the buffer and there is
5348 no headline in line 1, this function will act as if called with prefix arg.
5349 But only if also the variable `org-cycle-global-at-bob' is t."
5351 (org-load-modules-maybe)
5352 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
5353 (and org-cycle-level-after-item
/entry-creation
5354 (or (org-cycle-level)
5355 (org-cycle-item-indentation))))
5357 (or org-cycle-max-level
5358 (and (boundp 'org-inlinetask-min-level
)
5359 org-inlinetask-min-level
5360 (1- org-inlinetask-min-level
))))
5361 (nstars (and limit-level
5362 (if org-odd-levels-only
5363 (and limit-level
(1- (* limit-level
2)))
5367 ((not (org-mode-p)) outline-regexp
)
5368 ((or (eq org-cycle-include-plain-lists
'integrate
)
5369 (and org-cycle-include-plain-lists
(org-at-item-p)))
5371 (if nstars
(format "\\{1,%d\\}" nstars
) "+")
5372 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5373 (t (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ ")))))
5374 (bob-special (and org-cycle-global-at-bob
(bobp)
5375 (not (looking-at outline-regexp
))))
5378 (delq 'org-optimize-window-after-visibility-change
5379 (copy-sequence org-cycle-hook
))
5383 (if (or bob-special
(equal arg
'(4)))
5384 ;; special case: use global cycling
5390 (org-set-startup-visibility)
5391 (message "Startup visibility, plus VISIBILITY properties"))
5395 (message "Entire buffer visible, including drawers"))
5397 ((org-at-table-p 'any
)
5398 ;; Enter the table or move to the next field in the table
5399 (if (org-at-table.el-p
)
5400 (message "Use C-c ' to edit table.el tables")
5401 (if arg
(org-table-edit-field t
)
5402 (org-table-justify-field-maybe)
5403 (call-interactively 'org-table-next-field
))))
5405 ((run-hook-with-args-until-success
5406 'org-tab-after-check-for-table-hook
))
5408 ((eq arg t
) ;; Global cycling
5409 (org-cycle-internal-global))
5411 ((and org-drawers org-drawer-regexp
5413 (beginning-of-line 1)
5414 (looking-at org-drawer-regexp
)))
5415 ;; Toggle block visibility
5417 (not (get-char-property (match-end 0) 'invisible
))))
5420 ;; Show-subtree, ARG levels up from here.
5422 (org-back-to-heading)
5423 (outline-up-heading (if (< arg
0) (- arg
)
5424 (- (funcall outline-level
) arg
)))
5425 (org-show-subtree)))
5427 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp
))
5428 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
5430 (org-cycle-internal-local))
5432 ;; TAB emulation and template completion
5433 (buffer-read-only (org-back-to-heading))
5435 ((run-hook-with-args-until-success
5436 'org-tab-after-check-for-cycling-hook
))
5438 ((org-try-structure-completion))
5440 ((org-try-cdlatex-tab))
5442 ((run-hook-with-args-until-success
5443 'org-tab-before-tab-emulation-hook
))
5445 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
5447 (not (looking-at outline-regexp
))))
5448 (call-interactively (global-key-binding "\t")))
5450 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
5451 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5452 (or (and (eq org-cycle-emulate-tab
'white
)
5453 (= (match-end 0) (point-at-eol)))
5454 (and (eq org-cycle-emulate-tab
'whitestart
)
5455 (>= (match-end 0) pos
))))
5457 (eq org-cycle-emulate-tab t
))
5458 (call-interactively (global-key-binding "\t")))
5461 (org-back-to-heading)
5464 (defun org-cycle-internal-global ()
5465 "Do the global cycling action."
5467 ((and (eq last-command this-command
)
5468 (eq org-cycle-global-status
'overview
))
5469 ;; We just created the overview - now do table of contents
5470 ;; This can be slow in very large buffers, so indicate action
5471 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
5472 (message "CONTENTS...")
5474 (message "CONTENTS...done")
5475 (setq org-cycle-global-status
'contents
)
5476 (run-hook-with-args 'org-cycle-hook
'contents
))
5478 ((and (eq last-command this-command
)
5479 (eq org-cycle-global-status
'contents
))
5480 ;; We just showed the table of contents - now show everything
5481 (run-hook-with-args 'org-pre-cycle-hook
'all
)
5483 (message "SHOW ALL")
5484 (setq org-cycle-global-status
'all
)
5485 (run-hook-with-args 'org-cycle-hook
'all
))
5488 ;; Default action: go to overview
5489 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
5491 (message "OVERVIEW")
5492 (setq org-cycle-global-status
'overview
)
5493 (run-hook-with-args 'org-cycle-hook
'overview
))))
5495 (defun org-cycle-internal-local ()
5496 "Do the local cycling action."
5497 (org-back-to-heading)
5498 (let ((goal-column 0) eoh eol eos level has-children children-skipped
)
5499 ;; First, some boundaries
5501 (org-back-to-heading)
5502 (setq level
(funcall outline-level
))
5504 (beginning-of-line 2)
5505 (if (or (featurep 'xemacs
) (<= emacs-major-version
21))
5506 ; XEmacs does not have `next-single-char-property-change'
5507 ; I'm not sure about Emacs 21.
5508 (while (and (not (eobp)) ;; this is like `next-line'
5509 (get-char-property (1- (point)) 'invisible
))
5510 (beginning-of-line 2))
5511 (while (and (not (eobp)) ;; this is like `next-line'
5512 (get-char-property (1- (point)) 'invisible
))
5513 (goto-char (next-single-char-property-change (point) 'invisible
))
5514 (and (eolp) (beginning-of-line 2))))
5516 (outline-end-of-heading) (setq eoh
(point))
5518 (outline-next-heading)
5519 (setq has-children
(and (org-at-heading-p t
)
5520 (> (funcall outline-level
) level
))))
5521 (org-end-of-subtree t
)
5523 (skip-chars-forward " \t\n")
5524 (beginning-of-line 1) ; in case this is an item
5526 (setq eos
(if (eobp) (point) (1- (point)))))
5527 ;; Find out what to do next and set `this-command'
5530 ;; Nothing is hidden behind this heading
5531 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
5532 (message "EMPTY ENTRY")
5533 (setq org-cycle-subtree-status nil
)
5536 (outline-next-heading)
5537 (if (org-invisible-p) (org-flag-heading nil
))))
5538 ((and (or (>= eol eos
)
5539 (not (string-match "\\S-" (buffer-substring eol eos
))))
5541 (not (setq children-skipped
5542 org-cycle-skip-children-state-if-no-children
))))
5543 ;; Entire subtree is hidden in one line: children view
5544 (run-hook-with-args 'org-pre-cycle-hook
'children
)
5547 (message "CHILDREN")
5550 (outline-next-heading)
5551 (if (org-invisible-p) (org-flag-heading nil
)))
5552 (setq org-cycle-subtree-status
'children
)
5553 (run-hook-with-args 'org-cycle-hook
'children
))
5554 ((or children-skipped
5555 (and (eq last-command this-command
)
5556 (eq org-cycle-subtree-status
'children
)))
5557 ;; We just showed the children, or no children are there,
5558 ;; now show everything.
5559 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
5561 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
5562 (setq org-cycle-subtree-status
'subtree
)
5563 (run-hook-with-args 'org-cycle-hook
'subtree
))
5565 ;; Default action: hide the subtree.
5566 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
5569 (setq org-cycle-subtree-status
'folded
)
5570 (run-hook-with-args 'org-cycle-hook
'folded
)))))
5573 (defun org-global-cycle (&optional arg
)
5574 "Cycle the global visibility. For details see `org-cycle'.
5575 With C-u prefix arg, switch to startup visibility.
5576 With a numeric prefix, show all headlines up to that level."
5578 (let ((org-cycle-include-plain-lists
5579 (if (org-mode-p) org-cycle-include-plain-lists nil
)))
5583 (hide-sublevels arg
)
5584 (setq org-cycle-global-status
'contents
))
5586 (org-set-startup-visibility)
5587 (message "Startup visibility, plus VISIBILITY properties."))
5589 (org-cycle '(4))))))
5591 (defun org-set-startup-visibility ()
5592 "Set the visibility required by startup options and properties."
5594 ((eq org-startup-folded t
)
5596 ((eq org-startup-folded
'content
)
5597 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
5598 (org-cycle '(4)) (org-cycle '(4)))))
5599 (unless (eq org-startup-folded
'showeverything
)
5600 (if org-hide-block-startup
(org-hide-block-all))
5601 (org-set-visibility-according-to-property 'no-cleanup
)
5602 (org-cycle-hide-archived-subtrees 'all
)
5603 (org-cycle-hide-drawers 'all
)
5604 (org-cycle-show-empty-lines 'all
)))
5606 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
5607 "Switch subtree visibilities according to :VISIBILITY: property."
5609 (let (org-show-entry-below state
)
5611 (goto-char (point-min))
5612 (while (re-search-forward
5613 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5615 (setq state
(match-string 1))
5617 (org-back-to-heading t
)
5621 ((equal state
'("fold" "folded"))
5623 ((equal state
"children")
5624 (org-show-hidden-entry)
5626 ((equal state
"content")
5629 (org-narrow-to-subtree)
5631 ((member state
'("all" "showall"))
5634 (org-cycle-hide-archived-subtrees 'all
)
5635 (org-cycle-hide-drawers 'all
)
5636 (org-cycle-show-empty-lines 'all
)))))
5638 (defun org-overview ()
5639 "Switch to overview mode, showing only top-level headlines.
5640 Really, this shows all headlines with level equal or greater than the level
5641 of the first headline in the buffer. This is important, because if the
5642 first headline is not level one, then (hide-sublevels 1) gives confusing
5645 (let ((level (save-excursion
5646 (goto-char (point-min))
5647 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
5649 (goto-char (match-beginning 0))
5650 (funcall outline-level
))))))
5651 (and level
(hide-sublevels level
))))
5653 (defun org-content (&optional arg
)
5654 "Show all headlines in the buffer, like a table of contents.
5655 With numerical argument N, show content up to level N."
5658 ;; Visit all headings and show their offspring
5659 (and (integerp arg
) (org-overview))
5660 (goto-char (point-max))
5662 (while (and (progn (condition-case nil
5663 (outline-previous-visible-heading 1)
5664 (error (goto-char (point-min))))
5666 (looking-at outline-regexp
))
5668 (show-children (1- arg
))
5670 (if (bobp) (throw 'exit nil
))))))
5673 (defun org-optimize-window-after-visibility-change (state)
5674 "Adjust the window after a change in outline visibility.
5675 This function is the default value of the hook `org-cycle-hook'."
5676 (when (get-buffer-window (current-buffer))
5678 ((eq state
'content
) nil
)
5679 ((eq state
'all
) nil
)
5680 ((eq state
'folded
) nil
)
5681 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
5682 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
5684 (defun org-remove-empty-overlays-at (pos)
5685 "Remove outline overlays that do not contain non-white stuff."
5688 (and (eq 'outline
(overlay-get o
'invisible
))
5689 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
5691 (delete-overlay o
)))
5694 (defun org-clean-visibility-after-subtree-move ()
5695 "Fix visibility issues after moving a subtree."
5696 ;; First, find a reasonable region to look at:
5697 ;; Start two siblings above, end three below
5698 (let* ((beg (save-excursion
5699 (and (org-get-last-sibling)
5700 (org-get-last-sibling))
5702 (end (save-excursion
5703 (and (org-get-next-sibling)
5704 (org-get-next-sibling)
5705 (org-get-next-sibling))
5706 (if (org-at-heading-p)
5709 (level (looking-at "\\*+"))
5710 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
5713 (narrow-to-region beg end
)
5715 ;; Properly fold already folded siblings
5716 (goto-char (point-min))
5717 (while (re-search-forward re nil t
)
5718 (if (and (not (org-invisible-p))
5720 (goto-char (point-at-eol)) (org-invisible-p)))
5722 (org-cycle-show-empty-lines 'overview
)
5723 (org-cycle-hide-drawers 'overview
)))))
5725 (defun org-cycle-show-empty-lines (state)
5726 "Show empty lines above all visible headlines.
5727 The region to be covered depends on STATE when called through
5728 `org-cycle-hook'. Lisp program can use t for STATE to get the
5729 entire buffer covered. Note that an empty line is only shown if there
5730 are at least `org-cycle-separator-lines' empty lines before the headline."
5731 (when (not (= org-cycle-separator-lines
0))
5733 (let* ((n (abs org-cycle-separator-lines
))
5735 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
5736 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
5737 (t (let ((ns (number-to-string (- n
2))))
5738 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
5739 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
5742 ((memq state
'(overview contents t
))
5743 (setq beg
(point-min) end
(point-max)))
5744 ((memq state
'(children folded
))
5745 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
5746 (beginning-of-line 2)
5750 (while (re-search-forward re end t
)
5751 (unless (get-char-property (match-end 1) 'invisible
)
5752 (setq e
(match-end 1))
5753 (if (< org-cycle-separator-lines
0)
5754 (setq b
(save-excursion
5755 (goto-char (match-beginning 0))
5756 (org-back-over-empty-lines)
5758 (goto-char (max (point-min) (1- (point))))
5762 (setq b
(match-beginning 1)))
5763 (outline-flag-region b e nil
)))))))
5764 ;; Never hide empty lines at the end of the file.
5766 (goto-char (point-max))
5767 (outline-previous-heading)
5768 (outline-end-of-heading)
5769 (if (and (looking-at "[ \t\n]+")
5770 (= (match-end 0) (point-max)))
5771 (outline-flag-region (point) (match-end 0) nil
))))
5773 (defun org-show-empty-lines-in-parent ()
5774 "Move to the parent and re-show empty lines before visible headlines."
5776 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
5777 (org-cycle-show-empty-lines context
))))
5779 (defun org-files-list ()
5780 "Return `org-agenda-files' list, plus all open org-mode files.
5781 This is useful for operations that need to scan all of a user's
5782 open and agenda-wise Org files."
5783 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
5784 (dolist (buf (buffer-list))
5785 (with-current-buffer buf
5786 (if (and (eq major-mode
'org-mode
) (buffer-file-name))
5787 (let ((file (expand-file-name (buffer-file-name))))
5788 (unless (member file files
)
5789 (push file files
))))))
5792 (defsubst org-entry-beginning-position
()
5793 "Return the beginning position of the current entry."
5794 (save-excursion (outline-back-to-heading t
) (point)))
5796 (defsubst org-entry-end-position
()
5797 "Return the end position of the current entry."
5798 (save-excursion (outline-next-heading) (point)))
5800 (defun org-cycle-hide-drawers (state)
5801 "Re-hide all drawers after a visibility state change."
5802 (when (and (org-mode-p)
5803 (not (memq state
'(overview folded contents
))))
5805 (let* ((globalp (memq state
'(contents all
)))
5806 (beg (if globalp
(point-min) (point)))
5807 (end (if globalp
(point-max)
5808 (if (eq state
'children
)
5809 (save-excursion (outline-next-heading) (point))
5810 (org-end-of-subtree t
)))))
5812 (while (re-search-forward org-drawer-regexp end t
)
5813 (org-flag-drawer t
))))))
5815 (defun org-flag-drawer (flag)
5817 (beginning-of-line 1)
5818 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
5819 (let ((b (match-end 0))
5820 (outline-regexp org-outline-regexp
))
5821 (if (re-search-forward
5823 (save-excursion (outline-next-heading) (point)) t
)
5824 (outline-flag-region b
(point-at-eol) flag
)
5825 (error ":END: line missing at position %s" b
))))))
5827 (defun org-subtree-end-visible-p ()
5828 "Is the end of the current subtree visible?"
5829 (pos-visible-in-window-p
5830 (save-excursion (org-end-of-subtree t
) (point))))
5832 (defun org-first-headline-recenter (&optional N
)
5833 "Move cursor to the first headline and recenter the headline.
5834 Optional argument N means put the headline into the Nth line of the window."
5835 (goto-char (point-min))
5836 (when (re-search-forward (concat "^\\(" outline-regexp
"\\)") nil t
)
5838 (recenter (prefix-numeric-value N
))))
5840 ;;; Saving and restoring visibility
5842 (defun org-outline-overlay-data (&optional use-markers
)
5843 "Return a list of the locations of all outline overlays.
5844 The are overlays with the `invisible' property value `outline'.
5845 The return valus is a list of cons cells, with start and stop
5846 positions for each overlay.
5847 If USE-MARKERS is set, return the positions as markers."
5854 (when (eq (overlay-get o
'invisible
) 'outline
)
5855 (setq beg
(overlay-start o
)
5856 end
(overlay-end o
))
5857 (and beg end
(> end beg
)
5859 (cons (move-marker (make-marker) beg
)
5860 (move-marker (make-marker) end
))
5862 (overlays-in (point-min) (point-max))))))))
5864 (defun org-set-outline-overlay-data (data)
5865 "Create visibility overlays for all positions in DATA.
5866 DATA should have been made by `org-outline-overlay-data'."
5873 (setq o
(make-overlay (car c
) (cdr c
)))
5874 (overlay-put o
'invisible
'outline
))
5877 (defmacro org-save-outline-visibility
(use-markers &rest body
)
5878 "Save and restore outline visibility around BODY.
5879 If USE-MARKERS is non-nil, use markers for the positions.
5880 This means that the buffer may change while running BODY,
5881 but it also means that the buffer should stay alive
5882 during the operation, because otherwise all these markers will
5884 `(let ((data (org-outline-overlay-data ,use-markers
)))
5888 (org-set-outline-overlay-data data
))
5891 (and (markerp (car c
)) (move-marker (car c
) nil
))
5892 (and (markerp (cdr c
)) (move-marker (cdr c
) nil
)))
5896 ;;; Folding of blocks
5898 (defconst org-block-regexp
5900 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
5901 "Regular expression for hiding blocks.")
5903 (defvar org-hide-block-overlays nil
5904 "Overlays hiding blocks.")
5905 (make-variable-buffer-local 'org-hide-block-overlays
)
5907 (defun org-block-map (function &optional start end
)
5908 "Call func at the head of all source blocks in the current
5909 buffer. Optional arguments START and END can be used to limit
5911 (let ((start (or start
(point-min)))
5912 (end (or end
(point-max))))
5915 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
5918 (goto-char (match-beginning 0))
5919 (funcall function
)))))))
5921 (defun org-hide-block-toggle-all ()
5922 "Toggle the visibility of all blocks in the current buffer."
5923 (org-block-map #'org-hide-block-toggle
))
5925 (defun org-hide-block-all ()
5926 "Fold all blocks in the current buffer."
5928 (org-show-block-all)
5929 (org-block-map #'org-hide-block-toggle-maybe
))
5931 (defun org-show-block-all ()
5932 "Unfold all blocks in the current buffer."
5933 (mapc 'delete-overlay org-hide-block-overlays
)
5934 (setq org-hide-block-overlays nil
))
5936 (defun org-hide-block-toggle-maybe ()
5937 "Toggle visibility of block at point."
5939 (let ((case-fold-search t
))
5941 (beginning-of-line 1)
5942 (looking-at org-block-regexp
))
5943 (progn (org-hide-block-toggle)
5944 t
) ;; to signal that we took action
5945 nil
))) ;; to signal that we did not
5947 (defun org-hide-block-toggle (&optional force
)
5948 "Toggle the visibility of the current block."
5952 (if (re-search-forward org-block-regexp nil t
)
5953 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
5954 (end (match-end 0)) ;; end of entire body
5956 (if (memq t
(mapcar (lambda (overlay)
5957 (eq (overlay-get overlay
'invisible
)
5959 (overlays-at start
)))
5960 (if (or (not force
) (eq force
'off
))
5962 (when (member ov org-hide-block-overlays
)
5963 (setq org-hide-block-overlays
5964 (delq ov org-hide-block-overlays
)))
5965 (when (eq (overlay-get ov
'invisible
)
5967 (delete-overlay ov
)))
5968 (overlays-at start
)))
5969 (setq ov
(make-overlay start end
))
5970 (overlay-put ov
'invisible
'org-hide-block
)
5971 ;; make the block accessible to isearch
5973 ov
'isearch-open-invisible
5975 (when (member ov org-hide-block-overlays
)
5976 (setq org-hide-block-overlays
5977 (delq ov org-hide-block-overlays
)))
5978 (when (eq (overlay-get ov
'invisible
)
5980 (delete-overlay ov
))))
5981 (push ov org-hide-block-overlays
)))
5982 (error "Not looking at a source block"))))
5984 ;; org-tab-after-check-for-cycling-hook
5985 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
5986 ;; Remove overlays when changing major mode
5987 (add-hook 'org-mode-hook
5988 (lambda () (org-add-hook 'change-major-mode-hook
5989 'org-show-block-all
'append
'local
)))
5993 (defvar org-goto-window-configuration nil
)
5994 (defvar org-goto-marker nil
)
5995 (defvar org-goto-map
5996 (let ((map (make-sparse-keymap)))
5997 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
5998 (while (setq cmd
(pop cmds
))
5999 (substitute-key-definition cmd cmd map global-map
)))
6000 (suppress-keymap map
)
6001 (org-defkey map
"\C-m" 'org-goto-ret
)
6002 (org-defkey map
[(return)] 'org-goto-ret
)
6003 (org-defkey map
[(left)] 'org-goto-left
)
6004 (org-defkey map
[(right)] 'org-goto-right
)
6005 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6006 (org-defkey map
"\C-i" 'org-cycle
)
6007 (org-defkey map
[(tab)] 'org-cycle
)
6008 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6009 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6010 (if org-goto-auto-isearch
6011 (if (fboundp 'define-key-after
)
6012 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6014 (org-defkey map "q" 'org-goto-quit)
6015 (org-defkey map "n" 'outline-next-visible-heading)
6016 (org-defkey map "p" 'outline-previous-visible-heading)
6017 (org-defkey map "f" 'outline-forward-same-level)
6018 (org-defkey map "b" 'outline-backward-same-level)
6019 (org-defkey map "u" 'outline-up-heading))
6020 (org-defkey map "/" 'org-occur)
6021 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6022 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6023 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6024 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6025 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6028 (defconst org-goto-help
6029 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6030 RET=jump to location [Q]uit and return to previous location
6031 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6033 (defvar org-goto-start-pos) ; dynamically scoped parameter
6035 ;; FIXME: Docstring does not mention both interfaces
6036 (defun org-goto (&optional alternative-interface)
6037 "Look up a different location in the current file, keeping current visibility.
6039 When you want look-up or go to a different location in a document, the
6040 fastest way is often to fold the entire buffer and then dive into the tree.
6041 This method has the disadvantage, that the previous location will be folded,
6042 which may not be what you want.
6044 This command works around this by showing a copy of the current buffer
6045 in an indirect buffer, in overview mode. You can dive into the tree in
6046 that copy, use org-occur and incremental search to find a location.
6047 When pressing RET or `Q', the command returns to the original buffer in
6048 which the visibility is still unchanged. After RET is will also jump to
6049 the location selected in the indirect buffer and expose the
6050 the headline hierarchy above."
6052 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6053 (org-refile-use-outline-path t)
6054 (org-refile-target-verify-function nil)
6056 (if (not alternative-interface)
6058 (if (eq org-goto-interface 'outline)
6059 'outline-path-completion
6061 (org-goto-start-pos (point))
6063 (if (eq interface 'outline)
6064 (car (org-get-location (current-buffer) org-goto-help))
6065 (nth 3 (org-refile-get-location "Goto: ")))))
6068 (org-mark-ring-push org-goto-start-pos)
6069 (goto-char selected-point)
6070 (if (or (org-invisible-p) (org-invisible-p2))
6071 (org-show-context 'org-goto)))
6074 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6075 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6076 (defvar org-goto-local-auto-isearch-map) ; defined below
6078 (defun org-get-location (buf help)
6079 "Let the user select a location in the Org-mode buffer BUF.
6080 This function uses a recursive edit. It returns the selected position
6082 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6083 (isearch-hide-immediately nil)
6084 (isearch-search-fun-function
6085 (lambda () 'org-goto-local-search-headings))
6086 (org-goto-selected-point org-goto-exit-command)
6088 (special-display-buffer-names nil)
6089 (special-display-regexps nil)
6090 (special-display-function nil))
6092 (save-window-excursion
6093 (delete-other-windows)
6094 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6097 (make-indirect-buffer (current-buffer) "*org-goto*")
6098 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6099 (with-output-to-temp-buffer "*Help*"
6101 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6102 (setq buffer-read-only nil)
6103 (let ((org-startup-truncated t)
6104 (org-startup-folded nil)
6105 (org-startup-align-all-tables nil))
6108 (setq buffer-read-only t)
6109 (if (and (boundp 'org-goto-start-pos)
6110 (integer-or-marker-p org-goto-start-pos))
6111 (let ((org-show-hierarchy-above t)
6112 (org-show-siblings t)
6113 (org-show-following-heading t))
6114 (goto-char org-goto-start-pos)
6115 (and (org-invisible-p) (org-show-context)))
6116 (goto-char (point-min)))
6117 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6118 (message "Select location and press RET")
6119 (use-local-map org-goto-map)
6122 (kill-buffer "*org-goto*")
6123 (cons org-goto-selected-point org-goto-exit-command)))
6125 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6126 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6127 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6128 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6130 (defun org-goto-local-search-headings (string bound noerror)
6131 "Search and make sure that any matches are in headlines."
6133 (while (if isearch-forward
6134 (search-forward string bound noerror)
6135 (search-backward string bound noerror))
6136 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6137 (and (member :headline context)
6138 (not (member :tags context))))
6139 (throw 'return (point))))))
6141 (defun org-goto-local-auto-isearch ()
6144 (goto-char (point-min))
6145 (let ((keys (this-command-keys)))
6146 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6148 (isearch-process-search-char (string-to-char keys)))))
6150 (defun org-goto-ret (&optional arg)
6151 "Finish `org-goto' by going to the new location."
6153 (setq org-goto-selected-point (point)
6154 org-goto-exit-command 'return)
6157 (defun org-goto-left ()
6158 "Finish `org-goto' by going to the new location."
6160 (if (org-on-heading-p)
6162 (beginning-of-line 1)
6163 (setq org-goto-selected-point (point)
6164 org-goto-exit-command 'left)
6166 (error "Not on a heading")))
6168 (defun org-goto-right ()
6169 "Finish `org-goto' by going to the new location."
6171 (if (org-on-heading-p)
6173 (setq org-goto-selected-point (point)
6174 org-goto-exit-command 'right)
6176 (error "Not on a heading")))
6178 (defun org-goto-quit ()
6179 "Finish `org-goto' without cursor motion."
6181 (setq org-goto-selected-point nil)
6182 (setq org-goto-exit-command 'quit)
6185 ;;; Indirect buffer display of subtrees
6187 (defvar org-indirect-dedicated-frame nil
6188 "This is the frame being used for indirect tree display.")
6189 (defvar org-last-indirect-buffer nil)
6191 (defun org-tree-to-indirect-buffer (&optional arg)
6192 "Create indirect buffer and narrow it to current subtree.
6193 With numerical prefix ARG, go up to this level and then take that tree.
6194 If ARG is negative, go up that many levels.
6195 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6196 indirect buffer previously made with this command, to avoid proliferation of
6197 indirect buffers. However, when you call the command with a `C-u' prefix, or
6198 when `org-indirect-buffer-display' is `new-frame', the last buffer
6199 is kept so that you can work with several indirect buffers at the same time.
6200 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6201 requests that a new frame be made for the new buffer, so that the dedicated
6202 frame is not changed."
6204 (let ((cbuf (current-buffer))
6205 (cwin (selected-window))
6207 beg end level heading ibuf)
6209 (org-back-to-heading t)
6211 (setq level (org-outline-level))
6212 (if (< arg 0) (setq arg (+ level arg)))
6213 (while (> (setq level (org-outline-level)) arg)
6214 (outline-up-heading 1 t)))
6216 heading (org-get-heading))
6217 (org-end-of-subtree t t)
6218 (if (org-on-heading-p) (backward-char 1))
6220 (if (and (buffer-live-p org-last-indirect-buffer)
6221 (not (eq org-indirect-buffer-display 'new-frame))
6223 (kill-buffer org-last-indirect-buffer))
6224 (setq ibuf (org-get-indirect-buffer cbuf)
6225 org-last-indirect-buffer ibuf)
6227 ((or (eq org-indirect-buffer-display 'new-frame)
6228 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6229 (select-frame (make-frame))
6230 (delete-other-windows)
6231 (switch-to-buffer ibuf)
6232 (org-set-frame-title heading))
6233 ((eq org-indirect-buffer-display 'dedicated-frame)
6235 (select-frame (or (and org-indirect-dedicated-frame
6236 (frame-live-p org-indirect-dedicated-frame)
6237 org-indirect-dedicated-frame)
6238 (setq org-indirect-dedicated-frame (make-frame)))))
6239 (delete-other-windows)
6240 (switch-to-buffer ibuf)
6241 (org-set-frame-title (concat "Indirect: " heading)))
6242 ((eq org-indirect-buffer-display 'current-window)
6243 (switch-to-buffer ibuf))
6244 ((eq org-indirect-buffer-display 'other-window)
6245 (pop-to-buffer ibuf))
6246 (t (error "Invalid value")))
6247 (if (featurep 'xemacs)
6248 (save-excursion (org-mode) (turn-on-font-lock)))
6249 (narrow-to-region beg end)
6252 (and (window-live-p cwin) (select-window cwin))))
6254 (defun org-get-indirect-buffer (&optional buffer)
6255 (setq buffer (or buffer (current-buffer)))
6256 (let ((n 1) (base (buffer-name buffer)) bname)
6257 (while (buffer-live-p
6258 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6261 (make-indirect-buffer buffer bname 'clone)
6262 (error (make-indirect-buffer buffer bname)))))
6264 (defun org-set-frame-title (title)
6265 "Set the title of the current frame to the string TITLE."
6266 ;; FIXME: how to name a single frame in XEmacs???
6267 (unless (featurep 'xemacs)
6268 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6270 ;;;; Structure editing
6272 ;;; Inserting headlines
6274 (defun org-previous-line-empty-p ()
6277 (or (beginning-of-line 0) t)
6279 (looking-at "[ \t]*$")))))
6281 (defun org-insert-heading (&optional force-heading invisible-ok)
6282 "Insert a new heading or item with same depth at point.
6283 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6284 If point is at the beginning of a headline, insert a sibling before the
6285 current headline. If point is not at the beginning, do not split the line,
6286 but create the new headline after the current line.
6287 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6288 This is important for non-interactive uses of the command."
6290 (if (or (= (buffer-size) 0)
6291 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6292 (org-on-heading-p))))
6293 (not (org-in-item-p))))
6295 (when (or force-heading (not (org-insert-item)))
6296 (let* ((empty-line-p nil)
6297 (head (save-excursion
6300 (org-back-to-heading invisible-ok)
6301 (setq empty-line-p (org-previous-line-empty-p))
6304 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6305 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6306 pos hide-previous previous-pos)
6308 ((and (org-on-heading-p) (bolp)
6310 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6311 ;; insert before the current line
6312 (open-line (if blank 2 1)))
6314 (not org-insert-heading-respect-content)
6317 (backward-char 1) (not (org-invisible-p)))))
6318 ;; insert right here
6321 ;; somewhere in the line
6323 (setq previous-pos (point-at-bol))
6325 (setq hide-previous (org-invisible-p)))
6326 (and org-insert-heading-respect-content (org-show-subtree))
6328 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6331 (goto-char (point-at-bol))
6332 (and (looking-at org-complex-heading-regexp)
6333 (> p (match-beginning 4)))))))
6336 (org-insert-heading-respect-content
6337 (org-end-of-subtree nil t)
6338 (or (bolp) (newline))
6339 (or (org-previous-line-empty-p)
6340 (and blank (newline)))
6346 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6347 (setq tags (and (match-end 2) (match-string 2)))
6349 (delete-region (match-beginning 1) (match-end 1)))
6350 (setq pos (point-at-bol))
6351 (or split (end-of-line 1))
6352 (delete-horizontal-space)
6353 (if (string-match "\\`\\*+\\'"
6354 (buffer-substring (point-at-bol) (point)))
6356 (newline (if blank 2 1))
6362 (org-set-tags nil 'align))))
6364 (or split (end-of-line 1))
6365 (newline (if blank 2 1)))))))
6366 (insert head) (just-one-space)
6369 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6370 (when (and org-insert-heading-respect-content hide-previous)
6372 (goto-char previous-pos)
6374 (run-hooks 'org-insert-heading-hook)))))
6376 (defun org-get-heading (&optional no-tags)
6377 "Return the heading of the current entry, without the stars."
6379 (org-back-to-heading t)
6382 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6383 "\\*+[ \t]+\\([^\r\n]*\\)"))
6384 (match-string 1) "")))
6386 (defun org-heading-components ()
6387 "Return the components of the current heading.
6388 This is a list with the following elements:
6389 - the level as an integer
6390 - the reduced level, different if `org-odd-levels-only' is set.
6391 - the TODO keyword, or nil
6392 - the priority character, like ?A, or nil if no priority is given
6393 - the headline text itself, or the tags string if no headline text
6394 - the tags string, or nil."
6396 (org-back-to-heading t)
6397 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6398 (list (length (match-string 1))
6399 (org-reduced-level (length (match-string 1)))
6400 (org-match-string-no-properties 2)
6401 (and (match-end 3) (aref (match-string 3) 2))
6402 (org-match-string-no-properties 4)
6403 (org-match-string-no-properties 5)))))
6405 (defun org-get-entry ()
6406 "Get the entry text, after heading, entire subtree."
6408 (org-back-to-heading t)
6409 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6411 (defun org-insert-heading-after-current ()
6412 "Insert a new heading with same level as current, after current subtree."
6414 (org-back-to-heading)
6415 (org-insert-heading)
6416 (org-move-subtree-down)
6419 (defun org-insert-heading-respect-content ()
6421 (let ((org-insert-heading-respect-content t))
6422 (org-insert-heading t)))
6424 (defun org-insert-todo-heading-respect-content (&optional force-state)
6426 (let ((org-insert-heading-respect-content t))
6427 (org-insert-todo-heading force-state t)))
6429 (defun org-insert-todo-heading (arg &optional force-heading)
6430 "Insert a new heading with the same level and TODO state as current heading.
6431 If the heading has no TODO state, or if the state is DONE, use the first
6432 state (TODO by default). Also with prefix arg, force first state."
6434 (when (or force-heading (not (org-insert-item 'checkbox)))
6435 (org-insert-heading force-heading)
6437 (org-back-to-heading)
6438 (outline-previous-heading)
6439 (looking-at org-todo-line-regexp))
6443 (not (match-beginning 2))
6444 (member (match-string 2) org-done-keywords))
6445 (car org-todo-keywords-1)
6449 (run-hook-with-args-until-success
6450 'org-todo-get-default-hook new-mark-x nil)
6452 (beginning-of-line 1)
6453 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6454 (if org-treat-insert-todo-heading-as-state-change
6456 (insert new-mark " "))))
6457 (when org-provide-todo-statistics
6458 (org-update-parent-todo-statistics))))
6460 (defun org-insert-subheading (arg)
6461 "Insert a new subheading and demote it.
6462 Works for outline headings and for plain lists alike."
6464 (org-insert-heading arg)
6466 ((org-on-heading-p) (org-do-demote))
6467 ((org-at-item-p) (org-indent-item 1))))
6469 (defun org-insert-todo-subheading (arg)
6470 "Insert a new subheading with TODO keyword or checkbox and demote it.
6471 Works for outline headings and for plain lists alike."
6473 (org-insert-todo-heading arg)
6475 ((org-on-heading-p) (org-do-demote))
6476 ((org-at-item-p) (org-indent-item 1))))
6478 ;;; Promotion and Demotion
6480 (defvar org-after-demote-entry-hook nil
6481 "Hook run after an entry has been demoted.
6482 The cursor will be at the beginning of the entry.
6483 When a subtree is being demoted, the hook will be called for each node.")
6485 (defvar org-after-promote-entry-hook nil
6486 "Hook run after an entry has been promoted.
6487 The cursor will be at the beginning of the entry.
6488 When a subtree is being promoted, the hook will be called for each node.")
6490 (defun org-promote-subtree ()
6491 "Promote the entire subtree.
6492 See also `org-promote'."
6495 (org-map-tree 'org-promote))
6496 (org-fix-position-after-promote))
6498 (defun org-demote-subtree ()
6499 "Demote the entire subtree. See `org-demote'.
6500 See also `org-promote'."
6503 (org-map-tree 'org-demote))
6504 (org-fix-position-after-promote))
6507 (defun org-do-promote ()
6508 "Promote the current heading higher up the tree.
6509 If the region is active in `transient-mark-mode', promote all headings
6513 (if (org-region-active-p)
6514 (org-map-region 'org-promote (region-beginning) (region-end))
6516 (org-fix-position-after-promote))
6518 (defun org-do-demote ()
6519 "Demote the current heading lower down the tree.
6520 If the region is active in `transient-mark-mode', demote all headings
6524 (if (org-region-active-p)
6525 (org-map-region 'org-demote (region-beginning) (region-end))
6527 (org-fix-position-after-promote))
6529 (defun org-fix-position-after-promote ()
6530 "Make sure that after pro/demotion cursor position is right."
6531 (let ((pos (point)))
6532 (when (save-excursion
6533 (beginning-of-line 1)
6534 (looking-at org-todo-line-regexp)
6535 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6536 (cond ((eobp) (insert " "))
6537 ((eolp) (insert " "))
6538 ((equal (char-after) ?\ ) (forward-char 1))))))
6540 (defun org-current-level ()
6541 "Return the level of the current entry, or nil if before the first headline.
6542 The level is the number of stars at the beginning of the headline."
6546 (org-back-to-heading t)
6547 (funcall outline-level))
6550 (defun org-get-previous-line-level ()
6551 "Return the outline depth of the last headline before the current line.
6552 Returns 0 for the first headline in the buffer, and nil if before the
6554 (let ((current-level (org-current-level))
6555 (prev-level (when (> (line-number-at-pos) 1)
6557 (beginning-of-line 0)
6558 (org-current-level)))))
6559 (cond ((null current-level) nil) ; Before first headline
6560 ((null prev-level) 0) ; At first headline
6563 (defun org-reduced-level (l)
6564 "Compute the effective level of a heading.
6565 This takes into account the setting of `org-odd-levels-only'."
6566 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6568 (defun org-level-increment ()
6569 "Return the number of stars that will be added or removed at a
6570 time to headlines when structure editing, based on the value of
6571 `org-odd-levels-only'."
6572 (if org-odd-levels-only 2 1))
6574 (defun org-get-valid-level (level &optional change)
6575 "Rectify a level change under the influence of `org-odd-levels-only'
6576 LEVEL is a current level, CHANGE is by how much the level should be
6577 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6578 even level numbers will become the next higher odd number."
6579 (if org-odd-levels-only
6580 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6581 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6582 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6583 (max 1 (+ level (or change 0)))))
6585 (if (boundp 'define-obsolete-function-alias)
6586 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6587 (define-obsolete-function-alias 'org-get-legal-level
6588 'org-get-valid-level)
6589 (define-obsolete-function-alias 'org-get-legal-level
6590 'org-get-valid-level "23.1")))
6592 (defun org-promote ()
6593 "Promote the current heading higher up the tree.
6594 If the region is active in `transient-mark-mode', promote all headings
6596 (org-back-to-heading t)
6597 (let* ((level (save-match-data (funcall outline-level)))
6598 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6599 (diff (abs (- level (length up-head) -1))))
6600 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6601 (replace-match up-head nil t)
6602 ;; Fixup tag positioning
6603 (and org-auto-align-tags (org-set-tags nil t))
6604 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6605 (run-hooks 'org-after-promote-entry-hook)))
6607 (defun org-demote ()
6608 "Demote the current heading lower down the tree.
6609 If the region is active in `transient-mark-mode', demote all headings
6611 (org-back-to-heading t)
6612 (let* ((level (save-match-data (funcall outline-level)))
6613 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6614 (diff (abs (- level (length down-head) -1))))
6615 (replace-match down-head nil t)
6616 ;; Fixup tag positioning
6617 (and org-auto-align-tags (org-set-tags nil t))
6618 (if org-adapt-indentation (org-fixup-indentation diff))
6619 (run-hooks 'org-after-demote-entry-hook)))
6621 (defun org-cycle-level ()
6622 "Cycle the level of an empty headline through possible states.
6623 This goes first to child, then to parent, level, then up the hierarchy.
6624 After top level, it switches back to sibling level."
6626 (let ((org-adapt-indentation nil))
6627 (when (org-point-at-end-of-empty-headline)
6628 (setq this-command 'org-cycle-level) ; Only needed for caching
6629 (let ((cur-level (org-current-level))
6630 (prev-level (org-get-previous-line-level)))
6632 ;; If first headline in file, promote to top-level.
6634 (loop repeat (/ (- cur-level 1) (org-level-increment))
6635 do (org-do-promote)))
6636 ;; If same level as prev, demote one.
6637 ((= prev-level cur-level)
6639 ;; If parent is top-level, promote to top level if not already.
6641 (loop repeat (/ (- cur-level 1) (org-level-increment))
6642 do (org-do-promote)))
6643 ;; If top-level, return to prev-level.
6645 (loop repeat (/ (- prev-level 1) (org-level-increment))
6646 do (org-do-demote)))
6647 ;; If less than prev-level, promote one.
6648 ((< cur-level prev-level)
6650 ;; If deeper than prev-level, promote until higher than
6652 ((> cur-level prev-level)
6653 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6654 do (org-do-promote))))
6657 (defun org-map-tree (fun)
6658 "Call FUN for every heading underneath the current one."
6659 (org-back-to-heading)
6660 (let ((level (funcall outline-level)))
6664 (outline-next-heading)
6665 (> (funcall outline-level) level))
6669 (defun org-map-region (fun beg end)
6670 "Call FUN for every heading between BEG and END."
6671 (let ((org-ignore-region t))
6673 (setq end (copy-marker end))
6675 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6679 (outline-next-heading)
6684 (defun org-fixup-indentation (diff)
6685 "Change the indentation in the current entry by DIFF
6686 However, if any line in the current entry has no indentation, or if it
6687 would end up with no indentation after the change, nothing at all is done."
6689 (let ((end (save-excursion (outline-next-heading)
6691 (prohibit (if (> diff 0)
6693 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6695 (unless (save-excursion (end-of-line 1)
6696 (re-search-forward prohibit end t))
6697 (while (and (< (point) end)
6698 (re-search-forward "^[ \t]+" end t))
6699 (goto-char (match-end 0))
6700 (setq col (current-column))
6701 (if (< diff 0) (replace-match ""))
6702 (org-indent-to-column (+ diff col))))
6703 (move-marker end nil))))
6705 (defun org-convert-to-odd-levels ()
6706 "Convert an org-mode file with all levels allowed to one with odd levels.
6707 This will leave level 1 alone, convert level 2 to level 3, level 3 to
6710 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
6711 (let ((outline-regexp org-outline-regexp)
6712 (outline-level 'org-outline-level)
6713 (org-odd-levels-only nil) n)
6715 (goto-char (point-min))
6716 (while (re-search-forward "^\\*\\*+ " nil t)
6717 (setq n (- (length (match-string 0)) 2))
6718 (while (>= (setq n (1- n)) 0)
6720 (end-of-line 1))))))
6722 (defun org-convert-to-oddeven-levels ()
6723 "Convert an org-mode file with only odd levels to one with odd and even levels.
6724 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
6725 section with an even level, conversion would destroy the structure of the file. An error
6726 is signaled in this case."
6728 (goto-char (point-min))
6729 ;; First check if there are no even levels
6730 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
6731 (org-show-context t)
6732 (error "Not all levels are odd in this file. Conversion not possible"))
6733 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
6734 (let ((outline-regexp org-outline-regexp)
6735 (outline-level 'org-outline-level)
6736 (org-odd-levels-only nil) n)
6738 (goto-char (point-min))
6739 (while (re-search-forward "^\\*\\*+ " nil t)
6740 (setq n (/ (1- (length (match-string 0))) 2))
6741 (while (>= (setq n (1- n)) 0)
6743 (end-of-line 1))))))
6745 (defun org-tr-level (n)
6746 "Make N odd if required."
6747 (if org-odd-levels-only (1+ (/ n 2)) n))
6749 ;;; Vertical tree motion, cutting and pasting of subtrees
6751 (defun org-move-subtree-up (&optional arg)
6752 "Move the current subtree up past ARG headlines of the same level."
6754 (org-move-subtree-down (- (prefix-numeric-value arg))))
6756 (defun org-move-subtree-down (&optional arg)
6757 "Move the current subtree down past ARG headlines of the same level."
6759 (setq arg (prefix-numeric-value arg))
6760 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
6761 'org-get-last-sibling))
6762 (ins-point (make-marker))
6764 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
6766 (org-back-to-heading)
6769 (setq ne-beg (org-back-over-empty-lines))
6772 (save-excursion (outline-end-of-heading)
6773 (setq folded (org-invisible-p)))
6774 (outline-end-of-subtree))
6775 (outline-next-heading)
6776 (setq ne-end (org-back-over-empty-lines))
6779 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
6780 ;; include less whitespace
6783 (forward-line (- ne-beg ne-end))
6784 (setq beg (point))))
6785 ;; Find insertion point, with error handling
6787 (or (and (funcall movfunc) (looking-at outline-regexp))
6788 (progn (goto-char beg0)
6789 (error "Cannot move past superior level or buffer limit")))
6790 (setq cnt (1- cnt)))
6792 ;; Moving forward - still need to move over subtree
6793 (progn (org-end-of-subtree t t)
6795 (org-back-over-empty-lines)
6796 (or (bolp) (newline)))))
6797 (setq ne-ins (org-back-over-empty-lines))
6798 (move-marker ins-point (point))
6799 (setq txt (buffer-substring beg end))
6800 (org-save-markers-in-region beg end)
6801 (delete-region beg end)
6802 (org-remove-empty-overlays-at beg)
6803 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
6804 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
6805 (and (not (bolp)) (looking-at "\n") (forward-char 1))
6806 (let ((bbb (point)))
6807 (insert-before-markers txt)
6808 (org-reinstall-markers-in-region bbb)
6809 (move-marker ins-point bbb))
6810 (or (bolp) (insert "\n"))
6811 (setq ins-end (point))
6812 (goto-char ins-point)
6813 (org-skip-whitespace)
6814 (when (and (< arg 0)
6815 (org-first-sibling-p)
6817 ;; Move whitespace back to beginning
6820 (let ((kill-whole-line t))
6821 (kill-line (- ne-ins ne-beg)) (point)))
6822 (insert (make-string (- ne-ins ne-beg) ?\n)))
6823 (move-marker ins-point nil)
6828 (org-cycle-hide-drawers 'children))
6829 (org-clean-visibility-after-subtree-move)))
6831 (defvar org-subtree-clip ""
6832 "Clipboard for cut and paste of subtrees.
6833 This is actually only a copy of the kill, because we use the normal kill
6834 ring. We need it to check if the kill was created by `org-copy-subtree'.")
6836 (defvar org-subtree-clip-folded nil
6837 "Was the last copied subtree folded?
6838 This is used to fold the tree back after pasting.")
6840 (defun org-cut-subtree (&optional n)
6841 "Cut the current subtree into the clipboard.
6842 With prefix arg N, cut this many sequential subtrees.
6843 This is a short-hand for marking the subtree and then cutting it."
6845 (org-copy-subtree n 'cut))
6847 (defun org-copy-subtree (&optional n cut force-store-markers)
6848 "Cut the current subtree into the clipboard.
6849 With prefix arg N, cut this many sequential subtrees.
6850 This is a short-hand for marking the subtree and then copying it.
6851 If CUT is non-nil, actually cut the subtree.
6852 If FORCE-STORE-MARKERS is non-nil, store the relative locations
6853 of some markers in the region, even if CUT is non-nil. This is
6854 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
6856 (let (beg end folded (beg0 (point)))
6858 (org-back-to-heading nil) ; take what looks like a subtree
6859 (org-back-to-heading t)) ; take what is really there
6860 (org-back-over-empty-lines)
6862 (skip-chars-forward " \t\r\n")
6864 (save-excursion (outline-end-of-heading)
6865 (setq folded (org-invisible-p)))
6867 (org-forward-same-level (1- n) t)
6869 (org-end-of-subtree t t))
6870 (org-back-over-empty-lines)
6874 (setq org-subtree-clip-folded folded)
6875 (when (or cut force-store-markers)
6876 (org-save-markers-in-region beg end))
6877 (if cut (kill-region beg end) (copy-region-as-kill beg end))
6878 (setq org-subtree-clip (current-kill 0))
6879 (message "%s: Subtree(s) with %d characters"
6880 (if cut "Cut" "Copied")
6881 (length org-subtree-clip)))))
6883 (defun org-paste-subtree (&optional level tree for-yank)
6884 "Paste the clipboard as a subtree, with modification of headline level.
6885 The entire subtree is promoted or demoted in order to match a new headline
6888 If the cursor is at the beginning of a headline, the same level as
6889 that headline is used to paste the tree
6891 If not, the new level is derived from the *visible* headings
6892 before and after the insertion point, and taken to be the inferior headline
6893 level of the two. So if the previous visible heading is level 3 and the
6894 next is level 4 (or vice versa), level 4 will be used for insertion.
6895 This makes sure that the subtree remains an independent subtree and does
6896 not swallow low level entries.
6898 You can also force a different level, either by using a numeric prefix
6899 argument, or by inserting the heading marker by hand. For example, if the
6900 cursor is after \"*****\", then the tree will be shifted to level 5.
6902 If optional TREE is given, use this text instead of the kill ring.
6904 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
6905 move back over whitespace before inserting, and move point to the end of
6906 the inserted text when done."
6908 (setq tree (or tree (and kill-ring (current-kill 0))))
6909 (unless (org-kill-is-subtree-p tree)
6911 (substitute-command-keys
6912 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
6913 (let* ((visp (not (org-invisible-p)))
6915 (^re (concat "^\\(" outline-regexp "\\)"))
6916 (re (concat "\\(" outline-regexp "\\)"))
6917 (^re_ (concat "\\(\\*+\\)[ \t]*"))
6919 (old-level (if (string-match ^re txt)
6920 (- (match-end 0) (match-beginning 0) 1)
6922 (force-level (cond (level (prefix-numeric-value level))
6923 ((and (looking-at "[ \t]*$")
6925 ^re_ (buffer-substring
6926 (point-at-bol) (point))))
6927 (- (match-end 1) (match-beginning 1)))
6929 (looking-at org-outline-regexp))
6930 (- (match-end 0) (point) 1))
6932 (previous-level (save-excursion
6935 (outline-previous-visible-heading 1)
6937 (- (match-end 0) (match-beginning 0) 1)
6940 (next-level (save-excursion
6943 (or (looking-at outline-regexp)
6944 (outline-next-visible-heading 1))
6946 (- (match-end 0) (match-beginning 0) 1)
6949 (new-level (or force-level (max previous-level next-level)))
6950 (shift (if (or (= old-level -1)
6952 (= old-level new-level))
6954 (- new-level old-level)))
6955 (delta (if (> shift 0) -1 1))
6956 (func (if (> shift 0) 'org-demote 'org-promote))
6957 (org-odd-levels-only nil)
6959 ;; Remove the forced level indicator
6961 (delete-region (point-at-bol) (point)))
6963 (beginning-of-line 1)
6964 (unless for-yank (org-back-over-empty-lines))
6966 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
6967 (insert-before-markers txt)
6968 (unless (string-match "\n\\'" txt) (insert "\n"))
6969 (setq newend (point))
6970 (org-reinstall-markers-in-region beg)
6973 (skip-chars-forward " \t\n\r")
6975 (if (and (org-invisible-p) visp)
6976 (save-excursion (outline-show-heading)))
6977 ;; Shift if necessary
6980 (narrow-to-region beg end)
6981 (while (not (= shift 0))
6982 (org-map-region func (point-min) (point-max))
6983 (setq shift (+ delta shift)))
6984 (goto-char (point-min))
6985 (setq newend (point-max))))
6986 (when (or (interactive-p) for-yank)
6987 (message "Clipboard pasted as level %d subtree" new-level))
6988 (if (and (not for-yank) ; in this case, org-yank will decide about folding
6990 (eq org-subtree-clip (current-kill 0))
6991 org-subtree-clip-folded)
6992 ;; The tree was folded before it was killed/copied
6994 (and for-yank (goto-char newend))))
6996 (defun org-kill-is-subtree-p (&optional txt)
6997 "Check if the current kill is an outline subtree, or a set of trees.
6998 Returns nil if kill does not start with a headline, or if the first
6999 headline level is not the largest headline level in the tree.
7000 So this will actually accept several entries of equal levels as well,
7001 which is OK for `org-paste-subtree'.
7002 If optional TXT is given, check this string instead of the current kill."
7003 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7004 (start-level (and kill
7005 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
7006 org-outline-regexp "\\)")
7008 (- (match-end 2) (match-beginning 2) 1)))
7009 (re (concat "^" org-outline-regexp))
7010 (start (1+ (or (match-beginning 2) -1))))
7011 (if (not start-level)
7013 nil) ;; does not even start with a heading
7015 (while (setq start (string-match re kill (1+ start)))
7016 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7020 (defvar org-markers-to-move nil
7021 "Markers that should be moved with a cut-and-paste operation.
7022 Those markers are stored together with their positions relative to
7023 the start of the region.")
7025 (defun org-save-markers-in-region (beg end)
7026 "Check markers in region.
7027 If these markers are between BEG and END, record their position relative
7028 to BEG, so that after moving the block of text, we can put the markers back
7030 This function gets called just before an entry or tree gets cut from the
7031 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7032 called immediately, to move the markers with the entries."
7033 (setq org-markers-to-move nil)
7034 (when (featurep 'org-clock)
7035 (org-clock-save-markers-for-cut-and-paste beg end))
7036 (when (featurep 'org-agenda)
7037 (org-agenda-save-markers-for-cut-and-paste beg end)))
7039 (defun org-check-and-save-marker (marker beg end)
7040 "Check if MARKER is between BEG and END.
7041 If yes, remember the marker and the distance to BEG."
7042 (when (and (marker-buffer marker)
7043 (equal (marker-buffer marker) (current-buffer)))
7044 (if (and (>= marker beg) (< marker end))
7045 (push (cons marker (- marker beg)) org-markers-to-move))))
7047 (defun org-reinstall-markers-in-region (beg)
7048 "Move all remembered markers to their position relative to BEG."
7050 (move-marker (car x) (+ beg (cdr x))))
7051 org-markers-to-move)
7052 (setq org-markers-to-move nil))
7054 (defun org-narrow-to-subtree ()
7055 "Narrow buffer to the current subtree."
7060 (progn (org-back-to-heading t) (point))
7061 (progn (org-end-of-subtree t t)
7062 (if (org-on-heading-p) (backward-char 1))
7065 (defun org-clone-subtree-with-time-shift (n &optional shift)
7066 "Clone the task (subtree) at point N times.
7067 The clones will be inserted as siblings.
7069 In interactive use, the user will be prompted for the number of clones
7070 to be produced, and for a time SHIFT, which may be a repeater as used
7071 in time stamps, for example `+3d'.
7073 When a valid repeater is given and the entry contains any time stamps,
7074 the clones will become a sequence in time, with time stamps in the
7075 subtree shifted for each clone produced. If SHIFT is nil or the
7076 empty string, time stamps will be left alone.
7078 If the original subtree did contain time stamps with a repeater,
7079 the following will happen:
7080 - the repeater will be removed in each clone
7081 - an additional clone will be produced, with the current, unshifted
7082 date(s) in the entry.
7083 - the original entry will be placed *after* all the clones, with
7085 - the start days in the repeater in the original entry will be shifted
7086 to past the last clone.
7087 I this way you can spell out a number of instances of a repeating task,
7088 and still retain the repeater to cover future instances of the task."
7089 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7090 (let (beg end template task
7091 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7092 (if (not (and (integerp n) (> n 0)))
7093 (error "Invalid number of replications %s" n))
7094 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7095 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7097 (error "Invalid shift specification %s" shift))
7099 (setq shift-n (string-to-number (match-string 1 shift))
7100 shift-what (cdr (assoc (match-string 2 shift)
7101 '(("d" . day) ("w" . week)
7102 ("m" . month) ("y" . year))))))
7103 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7104 (setq nmin 1 nmax n)
7105 (org-back-to-heading t)
7107 (org-end-of-subtree t t)
7108 (or (bolp) (insert "\n"))
7110 (setq template (buffer-substring beg end))
7112 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7113 (delete-region beg end)
7115 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7117 (loop for n from nmin to nmax do
7119 (setq task template)
7123 (goto-char (point-min))
7124 (while (re-search-forward org-ts-regexp-both nil t)
7125 (org-timestamp-change (* n shift-n) shift-what))
7126 (unless (= n n-no-remove)
7127 (goto-char (point-min))
7128 (while (re-search-forward org-ts-regexp nil t)
7130 (goto-char (match-beginning 0))
7131 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7132 (delete-region (match-beginning 1) (match-end 1))))))
7133 (setq task (buffer-string))))
7139 (defun org-sort (with-case)
7140 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7141 Optional argument WITH-CASE means sort case-sensitively.
7142 With a double prefix argument, also remove duplicate entries."
7144 (if (org-at-table-p)
7145 (org-call-with-arg 'org-table-sort-lines with-case)
7146 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7148 (defun org-sort-remove-invisible (s)
7149 (remove-text-properties 0 (length s) org-rm-props s)
7150 (while (string-match org-bracket-link-regexp s)
7151 (setq s (replace-match (if (match-end 2)
7153 (match-string 1 s)) t t s)))
7156 (defvar org-priority-regexp) ; defined later in the file
7158 (defvar org-after-sorting-entries-or-items-hook nil
7159 "Hook that is run after a bunch of entries or items have been sorted.
7160 When children are sorted, the cursor is in the parent line when this
7161 hook gets called. When a region or a plain list is sorted, the cursor
7162 will be in the first entry of the sorted region/list.")
7164 (defun org-sort-entries-or-items
7165 (&optional with-case sorting-type getkey-func compare-func property)
7166 "Sort entries on a certain level of an outline tree, or plain list items.
7167 If there is an active region, the entries in the region are sorted.
7168 Else, if the cursor is before the first entry, sort the top-level items.
7169 Else, the children of the entry at point are sorted.
7170 If the cursor is at the first item in a plain list, the list items will be
7173 Sorting can be alphabetically, numerically, by date/time as given by
7174 a time stamp, by a property or by priority.
7176 The command prompts for the sorting type unless it has been given to the
7177 function through the SORTING-TYPE argument, which needs to be a character,
7178 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7179 precise meaning of each character:
7181 n Numerically, by converting the beginning of the entry/item to a number.
7182 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7183 t By date/time, either the first active time stamp in the entry, or, if
7184 none exist, by the first inactive one.
7185 In items, only the first line will be checked.
7186 s By the scheduled date/time.
7187 d By deadline date/time.
7188 c By creation time, which is assumed to be the first inactive time stamp
7189 at the beginning of a line.
7190 p By priority according to the cookie.
7191 r By the value of a property.
7193 Capital letters will reverse the sort order.
7195 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7196 called with point at the beginning of the record. It must return either
7197 a string or a number that should serve as the sorting key for that record.
7199 Comparing entries ignores case by default. However, with an optional argument
7200 WITH-CASE, the sorting considers case as well."
7202 (let ((case-func (if with-case 'identity 'downcase))
7203 start beg end stars re re2
7204 txt what tmp plain-list-p)
7205 ;; Find beginning and end of region to sort
7207 ((org-region-active-p)
7208 ;; we will sort the region
7209 (setq end (region-end)
7211 (goto-char (region-beginning))
7212 (if (not (org-on-heading-p)) (outline-next-heading))
7213 (setq start (point)))
7215 ;; we will sort this plain list
7216 (org-beginning-of-item-list) (setq start (point))
7217 (org-end-of-item-list)
7218 (or (bolp) (insert "\n"))
7221 (setq plain-list-p t
7223 ((or (org-on-heading-p)
7224 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7225 ;; we will sort the children of the current headline
7226 (org-back-to-heading)
7228 end (progn (org-end-of-subtree t t)
7229 (or (bolp) (insert "\n"))
7230 (org-back-over-empty-lines)
7235 (outline-next-heading))
7237 ;; we will sort the top-level entries in this file
7238 (goto-char (point-min))
7239 (or (org-on-heading-p) (outline-next-heading))
7240 (setq start (point))
7241 (goto-char (point-max))
7242 (beginning-of-line 1)
7243 (when (looking-at ".*?\\S-")
7244 ;; File ends in a non-white line
7247 (setq end (point-max))
7248 (setq what "top-level")
7253 (if (>= beg end) (error "Nothing to sort"))
7255 (unless plain-list-p
7256 (looking-at "\\(\\*+\\)")
7257 (setq stars (match-string 1)
7258 re (concat "^" (regexp-quote stars) " +")
7259 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7260 txt (buffer-substring beg end))
7261 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7262 (if (and (not (equal stars "*")) (string-match re2 txt))
7263 (error "Region to sort contains a level above the first entry")))
7265 (unless sorting-type
7268 "Sort %s: [a]lpha [n]umeric [t]ime
[f]unc A/N/T/F means reversed:"
7269 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7270 [t]ime [s]cheduled [d]eadline [c]reated
7271 A/N/T/S/D/C/P/O/F means reversed:")
7273 (setq sorting-type (read-char-exclusive))
7275 (and (= (downcase sorting-type) ?f)
7277 (org-icompleting-read "Sort using function: "
7278 obarray 'fboundp t nil nil))
7279 (setq getkey-func (intern getkey-func)))
7281 (and (= (downcase sorting-type) ?r)
7283 (org-icompleting-read "Property: "
7284 (mapcar 'list (org-buffer-property-keys t))
7287 (message "Sorting entries...")
7290 (narrow-to-region start end)
7292 (let ((dcst (downcase sorting-type))
7293 (case-fold-search nil)
7294 (now (current-time)))
7296 (/= dcst sorting-type)
7297 ;; This function moves to the beginning character of the "record" to
7301 (if (org-at-item-p) t (goto-char (point-max))))
7303 (if (re-search-forward re nil t)
7304 (goto-char (match-beginning 0))
7305 (goto-char (point-max)))))
7306 ;; This function moves to the last character of the "record" being
7313 (outline-forward-same-level 1)
7315 (goto-char (point-max)))))))
7317 ;; This function returns the value that gets sorted against.
7320 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7323 (string-to-number (buffer-substring (match-end 0)
7326 (buffer-substring (match-end 0) (point-at-eol)))
7328 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7329 (re-search-forward org-ts-regexp-both
7331 (org-time-string-to-seconds (match-string 0))
7332 (org-float-time now)))
7336 (setq tmp (funcall getkey-func))
7337 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7339 (error "Invalid key function `%s'" getkey-func)))
7340 (t (error "Invalid sorting type `%c'" sorting-type)))))
7344 (if (looking-at org-complex-heading-regexp)
7345 (string-to-number (match-string 4))
7348 (if (looking-at org-complex-heading-regexp)
7349 (funcall case-func (match-string 4))
7352 (let ((end (save-excursion (outline-next-heading) (point))))
7353 (if (or (re-search-forward org-ts-regexp end t)
7354 (re-search-forward org-ts-regexp-both end t))
7355 (org-time-string-to-seconds (match-string 0))
7356 (org-float-time now))))
7358 (let ((end (save-excursion (outline-next-heading) (point))))
7359 (if (re-search-forward
7360 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7362 (org-time-string-to-seconds (match-string 0))
7363 (org-float-time now))))
7365 (let ((end (save-excursion (outline-next-heading) (point))))
7366 (if (re-search-forward org-scheduled-time-regexp end t)
7367 (org-time-string-to-seconds (match-string 1))
7368 (org-float-time now))))
7370 (let ((end (save-excursion (outline-next-heading) (point))))
7371 (if (re-search-forward org-deadline-time-regexp end t)
7372 (org-time-string-to-seconds (match-string 1))
7373 (org-float-time now))))
7375 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7376 (string-to-char (match-string 2))
7377 org-default-priority))
7379 (or (org-entry-get nil property) ""))
7381 (if (looking-at org-complex-heading-regexp)
7382 (- 9999 (length (member (match-string 2)
7383 org-todo-keywords-1)))))
7387 (setq tmp (funcall getkey-func))
7388 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7390 (error "Invalid key function `%s'" getkey-func)))
7391 (t (error "Invalid sorting type `%c'" sorting-type)))))
7394 ((= dcst ?a) 'string<)
7395 ((= dcst ?f) compare-func)
7396 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7398 (run-hooks 'org-after-sorting-entries-or-items-hook)
7399 (message "Sorting entries...done")))
7401 (defun org-do-sort (table what &optional with-case sorting-type)
7402 "Sort TABLE of WHAT according to SORTING-TYPE.
7403 The user will be prompted for the SORTING-TYPE if the call to this
7404 function does not specify it. WHAT is only for the prompt, to indicate
7405 what is being sorted. The sorting key will be extracted from
7406 the car of the elements of the table.
7407 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7408 (unless sorting-type
7410 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A
/N
/T means reversed
:"
7412 (setq sorting-type (read-char-exclusive)))
7413 (let ((dcst (downcase sorting-type))
7414 extractfun comparefun)
7415 ;; Define the appropriate functions
7418 (setq extractfun 'string-to-number
7419 comparefun (if (= dcst sorting-type) '< '>)))
7421 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7422 (lambda(x) (downcase (org-sort-remove-invisible x))))
7423 comparefun (if (= dcst sorting-type)
7425 (lambda (a b) (and (not (string< a b))
7426 (not (string= a b)))))))
7430 (if (or (string-match org-ts-regexp x)
7431 (string-match org-ts-regexp-both x))
7433 (org-time-string-to-time (match-string 0 x)))
7435 comparefun (if (= dcst sorting-type) '< '>)))
7436 (t (error "Invalid sorting type
`%c
'" sorting-type)))
7438 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7440 (lambda (a b) (funcall comparefun (car a) (car b))))))
7443 ;;; The orgstruct minor mode
7445 ;; Define a minor mode which can be used in other modes in order to
7446 ;; integrate the org-mode structure editing commands.
7448 ;; This is really a hack, because the org-mode structure commands use
7449 ;; keys which normally belong to the major mode. Here is how it
7450 ;; works: The minor mode defines all the keys necessary to operate the
7451 ;; structure commands, but wraps the commands into a function which
7452 ;; tests if the cursor is currently at a headline or a plain list
7453 ;; item. If that is the case, the structure command is used,
7454 ;; temporarily setting many Org-mode variables like regular
7455 ;; expressions for filling etc. However, when any of those keys is
7456 ;; used at a different location, function uses `key-binding' to look
7457 ;; up if the key has an associated command in another currently active
7458 ;; keymap (minor modes, major mode, global), and executes that
7459 ;; command. There might be problems if any of the keys is otherwise
7460 ;; used as a prefix key.
7462 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7463 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7464 ;; addresses this by checking explicitly for both bindings.
7466 (defvar orgstruct-mode-map (make-sparse-keymap)
7467 "Keymap for the minor
`orgstruct-mode
'.
")
7469 (defvar org-local-vars nil
7470 "List of local variables
, for use by
`orgstruct-mode
'")
7473 (define-minor-mode orgstruct-mode
7474 "Toggle the minor mode
`orgstruct-mode
'.
7475 This mode is for using Org-mode structure commands in other
7476 modes. The following keys behave as if Org-mode were active
, if
7477 the cursor is on a headline
, or on a plain list item
(both as
7478 defined by Org-mode
).
7480 M-up Move entry
/item up
7481 M-down Move entry
/item down
7484 M-S-up Move entry
/item up
7485 M-S-down Move entry
/item down
7486 M-S-left Promote subtree
7487 M-S-right Demote subtree
7488 M-q Fill paragraph and items like in Org-mode
7490 C-c - Cycle list bullet
7491 TAB Cycle item visibility
7492 M-RET Insert new heading
/item
7493 S-M-RET Insert new TODO heading
/ Checkbox item
7494 C-c C-c Set tags
/ toggle checkbox
"
7495 nil " OrgStruct
" nil
7496 (org-load-modules-maybe)
7497 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7500 (defun turn-on-orgstruct ()
7501 "Unconditionally turn on
`orgstruct-mode
'.
"
7504 (defun orgstruct++-mode (&optional arg)
7505 "Toggle
`orgstruct-mode
', the enhanced version of it.
7506 In addition to setting orgstruct-mode
, this also exports all indentation
7507 and autofilling variables from org-mode into the buffer. It will also
7508 recognize item context in multiline items.
7509 Note that turning off orgstruct-mode will
*not
* remove the
7510 indentation
/paragraph settings. This can only be done by refreshing the
7511 major mode
, for example with
\\[normal-mode
].
"
7513 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7521 "^
\\(paragraph-\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7522 (symbol-name (car x)))
7523 (setq var (car x) val (nth 1 x))
7524 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7526 (org-set-local 'orgstruct-is-++ t))))
7528 (defvar orgstruct-is-++ nil
7529 "Is orgstruct-mode in
++ version in the current-buffer?
")
7530 (make-variable-buffer-local 'orgstruct-is-++)
7533 (defun turn-on-orgstruct++ ()
7534 "Unconditionally turn on
`orgstruct
++-mode
'.
"
7535 (orgstruct++-mode 1))
7537 (defun orgstruct-error ()
7538 "Error when there is no default binding for a structure key.
"
7540 (error "This key has no function outside structure elements
"))
7542 (defun orgstruct-setup ()
7543 "Setup orgstruct keymaps.
"
7547 '([(meta up)] org-metaup)
7548 '([(meta down)] org-metadown)
7549 '([(meta left)] org-metaleft)
7550 '([(meta right)] org-metaright)
7551 '([(meta shift up)] org-shiftmetaup)
7552 '([(meta shift down)] org-shiftmetadown)
7553 '([(meta shift left)] org-shiftmetaleft)
7554 '([(meta shift right)] org-shiftmetaright)
7555 '([?\e (up)] org-metaup)
7556 '([?\e (down)] org-metadown)
7557 '([?\e (left)] org-metaleft)
7558 '([?\e (right)] org-metaright)
7559 '([?\e (shift up)] org-shiftmetaup)
7560 '([?\e (shift down)] org-shiftmetadown)
7561 '([?\e (shift left)] org-shiftmetaleft)
7562 '([?\e (shift right)] org-shiftmetaright)
7563 '([(shift up)] org-shiftup)
7564 '([(shift down)] org-shiftdown)
7565 '([(shift left)] org-shiftleft)
7566 '([(shift right)] org-shiftright)
7567 '("\C-c\C-c
" org-ctrl-c-ctrl-c)
7568 '("\M-q
" fill-paragraph)
7570 '("\C-c-
" org-cycle-list-bullet)))
7572 (while (setq elt (pop bindings))
7573 (setq nfunc (1+ nfunc))
7574 (setq key (org-key (car elt))
7576 cmd (orgstruct-make-binding fun nfunc key))
7577 (org-defkey orgstruct-mode-map key cmd))
7579 ;; Special treatment needed for TAB and RET
7580 (org-defkey orgstruct-mode-map [(tab)]
7581 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i
"))
7582 (org-defkey orgstruct-mode-map "\C-i
"
7583 (orgstruct-make-binding 'org-cycle 103 "\C-i
" [(tab)]))
7585 (org-defkey orgstruct-mode-map "\M-\C-m
"
7586 (orgstruct-make-binding 'org-insert-heading 105
7587 "\M-\C-m
" [(meta return)]))
7588 (org-defkey orgstruct-mode-map [(meta return)]
7589 (orgstruct-make-binding 'org-insert-heading 106
7590 [(meta return)] "\M-\C-m
"))
7592 (org-defkey orgstruct-mode-map [(shift meta return)]
7593 (orgstruct-make-binding 'org-insert-todo-heading 107
7594 [(meta return)] "\M-\C-m
"))
7596 (org-defkey orgstruct-mode-map "\e\C-m
"
7597 (orgstruct-make-binding 'org-insert-heading 108
7598 "\e\C-m
" [?\e (return)]))
7599 (org-defkey orgstruct-mode-map [?\e (return)]
7600 (orgstruct-make-binding 'org-insert-heading 109
7601 [?\e (return)] "\e\C-m
"))
7602 (org-defkey orgstruct-mode-map [?\e (shift return)]
7603 (orgstruct-make-binding 'org-insert-todo-heading 110
7604 [?\e (return)] "\e\C-m
"))
7606 (unless org-local-vars
7607 (setq org-local-vars (org-get-local-variables)))
7611 (defun orgstruct-make-binding (fun n &rest keys)
7612 "Create a function for binding in the structure minor mode.
7613 FUN is the command to call inside a table. N is used to create a unique
7614 command name. KEYS are keys that should be checked in for a command
7615 to execute outside of tables.
"
7618 (intern (concat "orgstruct-hijacker-command-
" (int-to-string n)))
7620 (concat "In Structure
, run
`" (symbol-name fun) "'.
\n"
7621 "Outside of structure
, run the binding of
`"
7622 (mapconcat (lambda (x) (format "%s
" x)) keys "' or
`")
7626 `(org-context-p 'headline 'item
7627 (and orgstruct-is-++
7628 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7630 (list 'org-run-like-in-org-mode (list 'quote fun))
7631 (list 'let '(orgstruct-mode)
7632 (list 'call-interactively
7635 (list 'key-binding k))
7637 '('orgstruct-error))))))))
7639 (defun org-context-p (&rest contexts)
7640 "Check if local context is any of CONTEXTS.
7641 Possible values in the list of contexts are
`table
', `headline
', and
`item
'.
"
7642 (let ((pos (point)))
7643 (goto-char (point-at-bol))
7644 (prog1 (or (and (memq 'table contexts)
7645 (looking-at "[ \t]*|
"))
7646 (and (memq 'headline contexts)
7647 ;;????????? (looking-at "\\*+"))
7648 (looking-at outline-regexp))
7649 (and (memq 'item contexts)
7650 (looking-at "[ \t]*\\([-
+*] \\|
[0-
9]+[.
)] \\)"))
7651 (and (memq 'item-body contexts)
7655 (defun org-get-local-variables ()
7656 "Return a list of all local variables in an org-mode buffer.
"
7658 (with-current-buffer (get-buffer-create "*Org tmp
*")
7661 (setq varlist (buffer-local-variables)))
7662 (kill-buffer "*Org tmp
*")
7669 (list (car x) (list 'quote (cdr x)))))
7671 "^
\\(org-\\|orgtbl-
\\|outline-
\\|comment-
\\|paragraph-
\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7672 (symbol-name (car x)))
7677 (defun org-run-like-in-org-mode (cmd)
7678 "Run a command
, pretending that the current buffer is in Org-mode.
7679 This will temporarily bind local variables that are typically bound in
7680 Org-mode to the values they have in Org-mode
, and then interactively
7682 (org-load-modules-maybe)
7683 (unless org-local-vars
7684 (setq org-local-vars (org-get-local-variables)))
7685 (eval (list 'let org-local-vars
7686 (list 'call-interactively (list 'quote cmd)))))
7690 (defun org-get-category (&optional pos)
7691 "Get the category applying to position POS.
"
7692 (get-text-property (or pos (point)) 'org-category))
7694 (defun org-refresh-category-properties ()
7695 "Refresh category text properties in the buffer.
"
7696 (let ((def-cat (cond
7697 ((null org-category)
7698 (if buffer-file-name
7699 (file-name-sans-extension
7700 (file-name-nondirectory buffer-file-name))
7702 ((symbolp org-category) (symbol-name org-category))
7704 beg end cat pos optionp)
7709 (goto-char (point-min))
7710 (put-text-property (point) (point-max) 'org-category def-cat)
7711 (while (re-search-forward
7712 "^
\\(#\\+CATEGORY
:\\|
[ \t]*:CATEGORY
:\\)\\(.
*\\)" nil t)
7713 (setq pos (match-end 0)
7714 optionp (equal (char-after (match-beginning 0)) ?#)
7715 cat (org-trim (match-string 2)))
7717 (setq beg (point-at-bol) end (point-max))
7718 (org-back-to-heading t)
7719 (setq beg (point) end (org-end-of-subtree t t)))
7720 (put-text-property beg end 'org-category cat)
7721 (goto-char pos)))))))
7726 ;;; Link abbreviations
7728 (defun org-link-expand-abbrev (link)
7729 "Apply replacements as defined in
`org-link-abbrev-alist.
"
7730 (if (string-match "^
\\([a-zA-Z
][-_a-zA-Z0-9
]*\\)\\(::?
\\(.
*\\)\\)?$
" link)
7731 (let* ((key (match-string 1 link))
7732 (as (or (assoc key org-link-abbrev-alist-local)
7733 (assoc key org-link-abbrev-alist)))
7734 (tag (and (match-end 2) (match-string 3 link)))
7740 ((symbolp rpl) (funcall rpl tag))
7741 ((string-match "%s
" rpl) (replace-match (or tag "") t t rpl))
7742 ((string-match "%h
" rpl)
7743 (replace-match (url-hexify-string (or tag "")) t t rpl))
7744 (t (concat rpl tag)))))
7747 ;;; Storing and inserting links
7749 (defvar org-insert-link-history nil
7750 "Minibuffer history for links inserted with
`org-insert-link
'.
")
7752 (defvar org-stored-links nil
7753 "Contains the links stored with
`org-store-link
'.
")
7755 (defvar org-store-link-plist nil
7756 "Plist with info about the most recently link created with
`org-store-link
'.
")
7758 (defvar org-link-protocols nil
7759 "Link protocols added to Org-mode using
`org-add-link-type
'.
")
7761 (defvar org-store-link-functions nil
7762 "List of functions that are called to create and store a link.
7763 Each function will be called in turn until one returns a non-nil
7764 value. Each function should check if it is responsible for creating
7765 this link
(for example by looking at the major mode
).
7766 If not
, it must exit and return nil.
7767 If yes
, it should return a non-nil value after a calling
7768 `org-store-link-props
' with a list of properties and values.
7769 Special properties are
:
7771 :type The link prefix. like
\"http
\". This must be given.
7772 :link The link
, like
\"http
://www.astro.uva.nl
/~dominik
\".
7773 This is obligatory as well.
7774 :description Optional default description for the second pair
7775 of brackets in an Org-mode link. The user can still change
7776 this when inserting this link into an Org-mode buffer.
7778 In addition to these
, any additional properties can be specified
7779 and then used in remember templates.
")
7781 (defun org-add-link-type (type &optional follow export)
7782 "Add TYPE to the list of
`org-link-types
'.
7783 Re-compute all regular expressions depending on
`org-link-types
'
7785 FOLLOW and EXPORT are two functions.
7787 FOLLOW should take the link path as the single argument and do whatever
7788 is necessary to follow the link
, for example find a file or display
7791 EXPORT should format the link path for export to one of the export formats.
7792 It should be a function accepting three arguments
:
7794 path the path of the link
, the text after the prefix
(like \"http
:\")
7795 desc the description of the link
, if any
, nil if there was no description
7796 format the export format
, a symbol like
`html
' or
`latex
'.
7798 The function may use the FORMAT information to return different values
7799 depending on the format. The return value will be put literally into
7801 Org-mode has a built-in default for exporting links. If you are happy with
7802 this default
, there is no need to define an export function for the link
7803 type. For a simple example of an export function
, see
`org-bbdb.el
'.
"
7804 (add-to-list 'org-link-types type t)
7805 (org-make-link-regexps)
7806 (if (assoc type org-link-protocols)
7807 (setcdr (assoc type org-link-protocols) (list follow export))
7808 (push (list type follow export) org-link-protocols)))
7810 (defvar org-agenda-buffer-name)
7813 (defun org-store-link (arg)
7814 "\\<org-mode-map
>Store an org-link to the current location.
7815 This link is added to
`org-stored-links
' and can later be inserted
7816 into an org-buffer with
\\[org-insert-link
].
7818 For some link types
, a prefix arg is interpreted
:
7819 For links to usenet articles
, arg negates
`org-gnus-prefer-web-links
'.
7820 For file links
, arg negates
`org-context-in-file-links
'.
"
7822 (org-load-modules-maybe)
7823 (setq org-store-link-plist nil) ; reset
7824 (let ((outline-regexp (org-get-limited-outline-regexp))
7825 link cpltxt desc description search txt custom-id)
7828 ((run-hook-with-args-until-success 'org-store-link-functions)
7829 (setq link (plist-get org-store-link-plist :link)
7830 desc (or (plist-get org-store-link-plist :description) link)))
7832 ((equal (buffer-name) "*Org Edit Src Example
*")
7834 (while (or (not label)
7838 (goto-char (point-min))
7840 (regexp-quote (format org-coderef-label-format label))
7842 (when label (message "Label exists already
") (sit-for 2))
7843 (setq label (read-string "Code line label
: " label)))
7845 (setq link (format org-coderef-label-format label))
7846 (setq gc (- 79 (length link)))
7847 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
7849 (setq link (concat "(" label ")") desc nil)))
7851 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
7852 ;; We are in the agenda, link to referenced location
7853 (let ((m (or (get-text-property (point) 'org-hd-marker)
7854 (get-text-property (point) 'org-marker))))
7856 (org-with-point-at m
7857 (call-interactively 'org-store-link)))))
7859 ((eq major-mode 'calendar-mode)
7860 (let ((cd (calendar-cursor-to-date)))
7863 (car org-time-stamp-formats)
7865 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
7867 (org-store-link-props :type "calendar
" :date cd)))
7869 ((eq major-mode 'w3-mode)
7870 (setq cpltxt (if (and (buffer-name)
7871 (not (string-match "Untitled
" (buffer-name))))
7874 link (org-make-link (url-view-url t)))
7875 (org-store-link-props :type "w3
" :url (url-view-url t)))
7877 ((eq major-mode 'w3m-mode)
7878 (setq cpltxt (or w3m-current-title w3m-current-url)
7879 link (org-make-link w3m-current-url))
7880 (org-store-link-props :type "w3m
" :url (url-view-url t)))
7882 ((setq search (run-hook-with-args-until-success
7883 'org-create-file-search-functions))
7884 (setq link (concat "file
:" (abbreviate-file-name buffer-file-name)
7886 (setq cpltxt (or description link)))
7888 ((eq major-mode 'image-mode)
7889 (setq cpltxt (concat "file
:"
7890 (abbreviate-file-name buffer-file-name))
7891 link (org-make-link cpltxt))
7892 (org-store-link-props :type "image
" :file buffer-file-name))
7894 ((eq major-mode 'dired-mode)
7895 ;; link to the file in the current line
7896 (let ((file (dired-get-filename nil t)))
7898 (abbreviate-file-name
7899 (expand-file-name (dired-get-filename nil t)))
7900 ;; otherwise, no file so use current directory.
7902 (setq cpltxt (concat "file
:" file)
7903 link (org-make-link cpltxt))))
7905 ((and buffer-file-name (org-mode-p))
7906 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID
")))
7908 ((org-in-regexp "<<\\(.
*?
\\)>>")
7911 (abbreviate-file-name buffer-file-name)
7912 "::" (match-string 1))
7913 link (org-make-link cpltxt)))
7914 ((and (featurep 'org-id)
7915 (or (eq org-link-to-org-use-id t)
7916 (and (eq org-link-to-org-use-id 'create-if-interactive)
7918 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
7921 (and org-link-to-org-use-id
7923 (org-entry-get nil "ID
")
7925 ;; We can make a link using the ID.
7926 (setq link (condition-case nil
7927 (prog1 (org-id-store-link)
7928 (setq desc (plist-get org-store-link-plist
7931 ;; probably before first headline, link to file only
7933 (abbreviate-file-name buffer-file-name))))))
7935 ;; Just link to current headline
7936 (setq cpltxt (concat "file
:"
7937 (abbreviate-file-name buffer-file-name)))
7938 ;; Add a context search string
7939 (when (org-xor org-context-in-file-links arg)
7941 ((org-on-heading-p) nil)
7942 ((org-region-active-p)
7943 (buffer-substring (region-beginning) (region-end)))
7945 (when (or (null txt) (string-match "\\S-
" txt))
7949 (org-make-org-heading-search-string txt)
7951 desc (or (nth 4 (ignore-errors
7952 (org-heading-components))) "NONE
"))))
7953 (if (string-match "::\\'" cpltxt)
7954 (setq cpltxt (substring cpltxt 0 -2)))
7955 (setq link (org-make-link cpltxt)))))
7957 ((buffer-file-name (buffer-base-buffer))
7958 ;; Just link to this file here.
7959 (setq cpltxt (concat "file
:"
7960 (abbreviate-file-name
7961 (buffer-file-name (buffer-base-buffer)))))
7962 ;; Add a context string
7963 (when (org-xor org-context-in-file-links arg)
7964 (setq txt (if (org-region-active-p)
7965 (buffer-substring (region-beginning) (region-end))
7966 (buffer-substring (point-at-bol) (point-at-eol))))
7967 ;; Only use search option if there is some text.
7968 (when (string-match "\\S-
" txt)
7970 (concat cpltxt "::" (org-make-org-heading-search-string txt))
7972 (setq link (org-make-link cpltxt)))
7975 (error "Cannot link to a buffer which is not visiting a file
"))
7977 (t (setq link nil)))
7979 (if (consp link) (setq cpltxt (car link) link (cdr link)))
7980 (setq link (or link cpltxt)
7981 desc (or desc cpltxt))
7982 (if (equal desc "NONE
") (setq desc nil))
7984 (if (and (or (interactive-p) executing-kbd-macro) link)
7986 (setq org-stored-links
7987 (cons (list link desc) org-stored-links))
7988 (message "Stored
: %s
" (or desc link))
7990 (setq link (concat "file
:" (abbreviate-file-name (buffer-file-name))
7992 (setq org-stored-links
7993 (cons (list link desc) org-stored-links))))
7994 (and link (org-make-link-string link desc)))))
7996 (defun org-store-link-props (&rest plist)
7997 "Store link properties
, extract names and addresses.
"
7999 (when (setq x (plist-get plist :from))
8000 (setq adr (mail-extract-address-components x))
8001 (setq plist (plist-put plist :fromname (car adr)))
8002 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8003 (when (setq x (plist-get plist :to))
8004 (setq adr (mail-extract-address-components x))
8005 (setq plist (plist-put plist :toname (car adr)))
8006 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8007 (let ((from (plist-get plist :from))
8008 (to (plist-get plist :to)))
8009 (when (and from to org-from-is-user-regexp)
8011 (plist-put plist :fromto
8012 (if (string-match org-from-is-user-regexp from)
8014 (concat "from %f
"))))))
8015 (setq org-store-link-plist plist))
8017 (defun org-add-link-props (&rest plist)
8018 "Add these properties to the link property list.
"
8021 (setq key (pop plist) value (pop plist))
8022 (setq org-store-link-plist
8023 (plist-put org-store-link-plist key value)))))
8025 (defun org-email-link-description (&optional fmt)
8026 "Return the description part of an email link.
8027 This takes information from
`org-store-link-plist
' and formats it
8028 according to FMT
(default from
`org-email-link-description-format
').
"
8029 (setq fmt (or fmt org-email-link-description-format))
8030 (let* ((p org-store-link-plist)
8031 (to (plist-get p :toaddress))
8032 (from (plist-get p :fromaddress))
8035 (cons "%c
" (plist-get p :fromto))
8036 (cons "%F
" (plist-get p :from))
8037 (cons "%f
" (or (plist-get p :fromname) (plist-get p :fromaddress) "?
"))
8038 (cons "%T
" (plist-get p :to))
8039 (cons "%t
" (or (plist-get p :toname) (plist-get p :toaddress) "?
"))
8040 (cons "%s
" (plist-get p :subject))
8041 (cons "%m
" (plist-get p :message-id)))))
8042 (when (string-match "%c
" fmt)
8043 ;; Check if the user wrote this message
8044 (if (and org-from-is-user-regexp from to
8045 (save-match-data (string-match org-from-is-user-regexp from)))
8046 (setq fmt (replace-match "to %t
" t t fmt))
8047 (setq fmt (replace-match "from %f
" t t fmt))))
8048 (org-replace-escapes fmt table)))
8050 (defun org-make-org-heading-search-string (&optional string heading)
8051 "Make search string for STRING or current headline.
"
8053 (let ((s (or string (org-get-heading))))
8054 (unless (and string (not heading))
8055 ;; We are using a headline, clean up garbage in there.
8056 (if (string-match org-todo-regexp s)
8057 (setq s (replace-match "" t t s)))
8058 (if (string-match (org-re ":[[:alnum
:]_
@:]+:[ \t]*$
") s)
8059 (setq s (replace-match "" t t s)))
8060 (setq s (org-trim s))
8061 (if (string-match (concat "^
\\(" org-quote-string "\\|
"
8062 org-comment-string "\\)") s)
8063 (setq s (replace-match "" t t s)))
8064 (while (string-match org-ts-regexp s)
8065 (setq s (replace-match "" t t s))))
8066 (while (string-match "[^a-zA-Z_0-9
\t]+" s)
8067 (setq s (replace-match " " t t s)))
8068 (or string (setq s (concat "*" s))) ; Add * for headlines
8069 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8071 (defun org-make-link (&rest strings)
8072 "Concatenate STRINGS.
"
8073 (apply 'concat strings))
8075 (defun org-make-link-string (link &optional description)
8076 "Make a link with brackets
, consisting of LINK and DESCRIPTION.
"
8077 (unless (string-match "\\S-
" link)
8078 (error "Empty link
"))
8079 (when (and description
8080 (stringp description)
8081 (not (string-match "\\S-
" description)))
8082 (setq description nil))
8083 (when (stringp description)
8084 ;; Remove brackets from the description, they are fatal.
8085 (while (string-match "\\[" description)
8086 (setq description (replace-match "{" t t description)))
8087 (while (string-match "\\]" description)
8088 (setq description (replace-match "}" t t description))))
8089 (when (equal (org-link-escape link) description)
8090 ;; No description needed, it is identical
8091 (setq description nil))
8092 (when (and (not description)
8093 (not (equal link (org-link-escape link))))
8094 (setq description (org-extract-attributes link)))
8095 (concat "[[" (org-link-escape link) "]"
8096 (if description (concat "[" description "]") "")
8099 (defconst org-link-escape-chars
8103 (?\340 . "%E0
") ; `a
8104 (?\342 . "%E2
") ; ^a
8105 (?\347 . "%E7
") ; ,c
8106 (?\350 . "%E8
") ; `e
8107 (?\351 . "%E9
") ; 'e
8108 (?\352 . "%EA
") ; ^e
8109 (?\356 . "%EE
") ; ^i
8110 (?\364 . "%F4
") ; ^o
8111 (?\371 . "%F9
") ; `u
8112 (?\373 . "%FB
") ; ^u
8118 "Association list of escapes for some characters problematic in links.
8119 This is the list that is used for internal purposes.
")
8121 (defvar org-url-encoding-use-url-hexify nil)
8123 (defconst org-link-escape-chars-browser
8124 '((?\ . "%
20")) ; 32 for the SPC char
8125 "Association list of escapes for some characters problematic in links.
8126 This is the list that is used before handing over to the browser.
")
8128 (defun org-link-escape (text &optional table)
8129 "Escape characters in TEXT that are problematic for links.
"
8130 (if (and org-url-encoding-use-url-hexify (not table))
8131 (url-hexify-string text)
8132 (setq table (or table org-link-escape-chars))
8134 (let ((re (mapconcat (lambda (x) (regexp-quote
8135 (char-to-string (car x))))
8137 (while (string-match re text)
8140 (cdr (assoc (string-to-char (match-string 0 text))
8145 (defun org-link-unescape (text &optional table)
8146 "Reverse the action of
`org-link-escape
'.
"
8147 (if (and org-url-encoding-use-url-hexify (not table))
8148 (url-unhex-string text)
8149 (setq table (or table org-link-escape-chars))
8151 (let ((case-fold-search t)
8152 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8154 (while (string-match re text)
8157 (char-to-string (car (rassoc (upcase (match-string 0 text))
8162 (defun org-xor (a b)
8166 (defun org-fixup-message-id-for-http (s)
8167 "Replace special characters in a message id
, so it can be used in an http query.
"
8168 (while (string-match "<" s)
8169 (setq s (replace-match "%
3C
" t t s)))
8170 (while (string-match ">" s)
8171 (setq s (replace-match "%
3E
" t t s)))
8172 (while (string-match "@" s)
8173 (setq s (replace-match "%
40" t t s)))
8177 (defun org-insert-link-global ()
8178 "Insert a link like Org-mode does.
8179 This command can be called in any mode to insert a link in Org-mode syntax.
"
8181 (org-load-modules-maybe)
8182 (org-run-like-in-org-mode 'org-insert-link))
8184 (defun org-insert-link (&optional complete-file link-location)
8185 "Insert a link. At the prompt
, enter the link.
8187 Completion can be used to insert any of the link protocol prefixes like
8190 The history can be used to select a link previously stored with
8191 `org-store-link
'. When the empty string is entered
(i.e. if you just
8192 press RET at the prompt
), the link defaults to the most recently
8193 stored link. As SPC triggers completion in the minibuffer
, you need to
8194 use M-SPC or C-q SPC to force the insertion of a space character.
8196 You will also be prompted for a description
, and if one is given
, it will
8197 be displayed in the buffer instead of the link.
8199 If there is already a link at point
, this command will allow you to edit link
8200 and description parts.
8202 With a
\\[universal-argument
] prefix
, prompts for a file to link to. The file name can
8203 be selected using completion. The path to the file will be relative to the
8204 current directory if the file is in the current directory or a subdirectory.
8205 Otherwise
, the link will be the absolute path as completed in the minibuffer
8206 \
(i.e. normally ~
/path
/to
/file
). You can configure this behavior using the
8207 option
`org-link-file-path-type
'.
8209 With two
\\[universal-argument
] prefixes
, enforce an absolute path even if the file is in
8210 the current directory or below.
8212 With three
\\[universal-argument
] prefixes
, negate the meaning of
8213 `org-keep-stored-link-after-insertion
'.
8215 If
`org-make-link-description-function
' is non-nil
, this function will be
8216 called with the link target
, and the result will be the default
8219 If the LINK-LOCATION parameter is non-nil
, this value will be
8220 used as the link location instead of reading one interactively.
"
8222 (let* ((wcf (current-window-configuration))
8223 (region (if (org-region-active-p)
8224 (buffer-substring (region-beginning) (region-end))))
8225 (remove (and region (list (region-beginning) (region-end))))
8227 tmphist ; byte-compile incorrectly complains about this
8228 (link link-location)
8229 entry file all-prefixes)
8231 (link-location) ; specified by arg, just use it.
8232 ((org-in-regexp org-bracket-link-regexp 1)
8233 ;; We do have a link at point, and we are going to edit it.
8234 (setq remove (list (match-beginning 0) (match-end 0)))
8235 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8236 (setq link (read-string "Link
: "
8238 (org-match-string-no-properties 1)))))
8239 ((or (org-in-regexp org-angle-link-re)
8240 (org-in-regexp org-plain-link-re))
8241 ;; Convert to bracket link
8242 (setq remove (list (match-beginning 0) (match-end 0))
8243 link (read-string "Link
: "
8244 (org-remove-angle-brackets (match-string 0)))))
8245 ((member complete-file '((4) (16)))
8246 ;; Completing read for file names.
8247 (setq link (org-file-complete-link complete-file)))
8249 ;; Read link, with completion for stored links.
8250 (with-output-to-temp-buffer "*Org Links
*"
8251 (princ "Insert a link.
8252 Use TAB to complete link prefixes
, then RET for type-specific completion support
\n")
8253 (when org-stored-links
8254 (princ "\nStored links are available with
<up
>/<down
> or M-p
/n
(most recent with RET
):\n\n")
8257 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8258 (reverse org-stored-links) "\n"))))
8259 (let ((cw (selected-window)))
8260 (select-window (get-buffer-window "*Org Links
*" 'visible))
8261 (setq truncate-lines t)
8262 (unless (pos-visible-in-window-p (point-max))
8263 (org-fit-window-to-buffer))
8264 (and (window-live-p cw) (select-window cw)))
8265 ;; Fake a link history, containing the stored links.
8266 (setq tmphist (append (mapcar 'car org-stored-links)
8267 org-insert-link-history))
8268 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8269 (mapcar 'car org-link-abbrev-alist)
8274 (let ((org-completion-use-ido nil)
8275 (org-completion-use-iswitchb nil))
8276 (org-completing-read
8279 (mapcar (lambda (x) (list (concat x ":")))
8281 (mapcar 'car org-stored-links))
8284 (car (car org-stored-links)))))
8285 (if (not (string-match "\\S-
" link))
8286 (error "No link selected
"))
8287 (if (or (member link all-prefixes)
8288 (and (equal ":" (substring link -1))
8289 (member (substring link 0 -1) all-prefixes)
8290 (setq link (substring link 0 -1))))
8291 (setq link (org-link-try-special-completion link))))
8292 (set-window-configuration wcf)
8293 (kill-buffer "*Org Links
*"))
8294 (setq entry (assoc link org-stored-links))
8295 (or entry (push link org-insert-link-history))
8296 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8297 (not org-keep-stored-link-after-insertion))
8298 (setq org-stored-links (delq (assoc link org-stored-links)
8300 (setq desc (or desc (nth 1 entry)))))
8302 (if (string-match org-plain-link-re link)
8303 ;; URL-like link, normalize the use of angular brackets.
8304 (setq link (org-make-link (org-remove-angle-brackets link))))
8306 ;; Check if we are linking to the current file with a search option
8307 ;; If yes, simplify the link by using only the search option.
8308 (when (and buffer-file-name
8309 (string-match "^file
:\\(.
+?
\\)::\\([^
>]+\\)" link))
8310 (let* ((path (match-string 1 link))
8311 (case-fold-search nil)
8312 (search (match-string 2 link)))
8314 (if (equal (file-truename buffer-file-name) (file-truename path))
8315 ;; We are linking to this same file, with a search option
8316 (setq link search)))))
8318 ;; Check if we can/should use a relative path. If yes, simplify the link
8319 (when (string-match "^
\\(file:\\|docview
:\\)\\(.
*\\)" link)
8320 (let* ((type (match-string 1 link))
8321 (path (match-string 2 link))
8323 (case-fold-search nil))
8325 ((or (eq org-link-file-path-type 'absolute)
8326 (equal complete-file '(16)))
8327 (setq path (abbreviate-file-name (expand-file-name path))))
8328 ((eq org-link-file-path-type 'noabbrev)
8329 (setq path (expand-file-name path)))
8330 ((eq org-link-file-path-type 'relative)
8331 (setq path (file-relative-name path)))
8334 (if (string-match (concat "^
" (regexp-quote
8335 (file-name-as-directory
8336 (expand-file-name ".
"))))
8337 (expand-file-name path))
8338 ;; We are linking a file with relative path name.
8339 (setq path (substring (expand-file-name path)
8341 (setq path (abbreviate-file-name (expand-file-name path)))))))
8342 (setq link (concat type path))
8343 (if (equal desc origpath)
8346 (if org-make-link-description-function
8347 (setq desc (funcall org-make-link-description-function link desc)))
8349 (setq desc (read-string "Description
: " desc))
8350 (unless (string-match "\\S-
" desc) (setq desc nil))
8351 (if remove (apply 'delete-region remove))
8352 (insert (org-make-link-string link desc))))
8354 (defun org-link-try-special-completion (type)
8355 "If there is completion support for link type TYPE
, offer it.
"
8356 (let ((fun (intern (concat "org-
" type "-complete-link
"))))
8359 (read-string "Link
(no completion support
): " (concat type ":")))))
8361 (defun org-file-complete-link (&optional arg)
8362 "Create a file link using completion.
"
8364 (setq file (read-file-name "File
: "))
8365 (let ((pwd (file-name-as-directory (expand-file-name ".
")))
8366 (pwd1 (file-name-as-directory (abbreviate-file-name
8367 (expand-file-name ".
")))))
8370 (setq link (org-make-link
8372 (abbreviate-file-name (expand-file-name file)))))
8373 ((string-match (concat "^
" (regexp-quote pwd1) "\\(.
+\\)") file)
8374 (setq link (org-make-link "file
:" (match-string 1 file))))
8375 ((string-match (concat "^
" (regexp-quote pwd) "\\(.
+\\)")
8376 (expand-file-name file))
8377 (setq link (org-make-link
8378 "file
:" (match-string 1 (expand-file-name file)))))
8379 (t (setq link (org-make-link "file
:" file)))))
8382 (defun org-completing-read (&rest args)
8383 "Completing-read with SPACE being a normal character.
"
8384 (let ((minibuffer-local-completion-map
8385 (copy-keymap minibuffer-local-completion-map)))
8386 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8387 (org-defkey minibuffer-local-completion-map "?
" 'self-insert-command)
8388 (apply 'org-icompleting-read args)))
8390 (defun org-completing-read-no-i (&rest args)
8391 (let (org-completion-use-ido org-completion-use-iswitchb)
8392 (apply 'org-completing-read args)))
8394 (defun org-iswitchb-completing-read (prompt choices &rest args)
8395 "Use iswitch as a completing-read replacement to choose from choices.
8396 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8398 (let* ((iswitchb-use-virtual-buffers nil)
8399 (iswitchb-make-buflist-hook
8401 (setq iswitchb-temp-buflist choices))))
8402 (iswitchb-read-buffer prompt)))
8404 (defun org-icompleting-read (&rest args)
8405 "Completing-read using
`ido-mode
' or
`iswitchb
' speedups if available.
"
8406 (org-without-partial-completion
8407 (if (and org-completion-use-ido
8408 (fboundp 'ido-completing-read)
8409 (boundp 'ido-mode) ido-mode
8410 (listp (second args)))
8411 (let ((ido-enter-matching-directory nil))
8412 (apply 'ido-completing-read (concat (car args))
8413 (if (consp (car (nth 1 args)))
8414 (mapcar (lambda (x) (car x)) (nth 1 args))
8417 (if (and org-completion-use-iswitchb
8418 (boundp 'iswitchb-mode) iswitchb-mode
8419 (listp (second args)))
8420 (apply 'org-iswitchb-completing-read (concat (car args))
8421 (if (consp (car (nth 1 args)))
8422 (mapcar (lambda (x) (car x)) (nth 1 args))
8425 (apply 'completing-read args)))))
8427 (defun org-extract-attributes (s)
8428 "Extract the attributes cookie from a string and set as text property.
"
8429 (let (a attr (start 0) key value)
8431 (when (string-match "{{\\([^
}]+\\)}}$
" s)
8432 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8433 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"" a start)
8434 (setq key (match-string 1 a) value (match-string 2 a)
8436 attr (plist-put attr (intern key) value))))
8437 (org-add-props s nil 'org-attr attr))
8440 (defun org-extract-attributes-from-string (tag)
8441 (let (key value attr)
8442 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"\\s-?
" tag)
8443 (setq key (match-string 1 tag) value (match-string 2 tag)
8444 tag (replace-match "" t t tag)
8445 attr (plist-put attr (intern key) value)))
8448 (defun org-attributes-to-string (plist)
8449 "Format a property list into an HTML attribute list.
"
8450 (let ((s "") key value)
8452 (setq key (pop plist) value (pop plist))
8454 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8457 ;;; Opening/following a link
8459 (defvar org-link-search-failed nil)
8461 (defvar org-open-link-functions nil
8462 "Hook for functions finding a plain text link.
8463 These functions must take a single argument
, the link content.
8464 They will be called for links that look like
[[link text
][description]]
8465 when LINK TEXT does not have a protocol like \"http:\" and does not look
8466 like a filename (e.g. \"./blue.png\").
8468 These functions will be called *before* Org attempts to resolve the
8469 link by doing text searches in the current buffer - so if you want a
8470 link \"[[target]]\" to still find \"<<target>>\", your function should
8471 handle this as a special case.
8473 When the function does handle the link, it must return a non-nil value.
8474 If it decides that it is not responsible for this link, it must return
8475 nil to indicate that that Org-mode can continue with other options
8476 like exact and fuzzy text search.")
8478 (defun org-next-link ()
8479 "Move forward to the next link.
8480 If the link is in hidden text, expose it."
8482 (when (and org-link-search-failed (eq this-command last-command))
8483 (goto-char (point-min))
8484 (message "Link search wrapped back to beginning of buffer"))
8485 (setq org-link-search-failed nil)
8486 (let* ((pos (point))
8488 (a (assoc :link ct)))
8489 (if a (goto-char (nth 2 a)))
8490 (if (re-search-forward org-any-link-re nil t)
8492 (goto-char (match-beginning 0))
8493 (if (org-invisible-p) (org-show-context)))
8495 (setq org-link-search-failed t)
8496 (error "No further link found"))))
8498 (defun org-previous-link ()
8499 "Move backward to the previous link.
8500 If the link is in hidden text, expose it."
8502 (when (and org-link-search-failed (eq this-command last-command))
8503 (goto-char (point-max))
8504 (message "Link search wrapped back to end of buffer"))
8505 (setq org-link-search-failed nil)
8506 (let* ((pos (point))
8508 (a (assoc :link ct)))
8509 (if a (goto-char (nth 1 a)))
8510 (if (re-search-backward org-any-link-re nil t)
8512 (goto-char (match-beginning 0))
8513 (if (org-invisible-p) (org-show-context)))
8515 (setq org-link-search-failed t)
8516 (error "No further link found"))))
8518 (defun org-translate-link (s)
8519 "Translate a link string if a translation function has been defined."
8520 (if (and org-link-translation-function
8521 (fboundp org-link-translation-function)
8522 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8524 (setq s (funcall org-link-translation-function
8525 (match-string 1) (match-string 2)))
8526 (concat (car s) ":" (cdr s)))
8529 (defun org-translate-link-from-planner (type path)
8530 "Translate a link from Emacs Planner syntax so that Org can follow it.
8531 This is still an experimental function, your mileage may vary."
8533 ((member type '("http" "https" "news" "ftp"))
8534 ;; standard Internet links are the same.
8536 ((and (equal type "irc") (string-match "^//" path))
8537 ;; Planner has two / at the beginning of an irc link, we have 1.
8538 ;; We should have zero, actually....
8539 (setq path (substring path 1)))
8540 ((and (equal type "lisp") (string-match "^/" path))
8541 ;; Planner has a slash, we do not.
8542 (setq type "elisp" path (substring path 1)))
8543 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8544 ;; A typical message link. Planner has the id after the final slash,
8545 ;; we separate it with a hash mark
8546 (setq path (concat (match-string 1 path) "#"
8547 (org-remove-angle-brackets (match-string 2 path)))))
8551 (defun org-find-file-at-mouse (ev)
8552 "Open file link or URL at mouse."
8554 (mouse-set-point ev)
8555 (org-open-at-point 'in-emacs))
8557 (defun org-open-at-mouse (ev)
8558 "Open file link or URL at mouse."
8560 (mouse-set-point ev)
8561 (if (eq major-mode 'org-agenda-mode)
8562 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8563 (org-open-at-point))
8565 (defvar org-window-config-before-follow-link nil
8566 "The window configuration before following a link.
8567 This is saved in case the need arises to restore it.")
8569 (defvar org-open-link-marker (make-marker)
8570 "Marker pointing to the location where `org-open-at-point; was called.")
8573 (defun org-open-at-point-global ()
8574 "Follow a link like Org-mode does.
8575 This command can be called in any mode to follow a link that has
8578 (org-run-like-in-org-mode 'org-open-at-point))
8581 (defun org-open-link-from-string (s &optional arg reference-buffer)
8582 "Open a link in the string S, as if it was in Org-mode."
8583 (interactive "sLink: \nP")
8584 (let ((reference-buffer (or reference-buffer (current-buffer))))
8586 (let ((org-inhibit-startup t))
8589 (goto-char (point-min))
8590 (when reference-buffer
8591 (setq org-link-abbrev-alist-local
8592 (with-current-buffer reference-buffer
8593 org-link-abbrev-alist-local)))
8594 (org-open-at-point arg reference-buffer)))))
8596 (defun org-open-at-point (&optional in-emacs reference-buffer)
8597 "Open link at or after point.
8598 If there is no link at point, this function will search forward up to
8599 the end of the current line.
8600 Normally, files will be opened by an appropriate application. If the
8601 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8602 With a double prefix argument, try to open outside of Emacs, in the
8603 application the system uses for this file type."
8605 (org-load-modules-maybe)
8606 (move-marker org-open-link-marker (point))
8607 (setq org-window-config-before-follow-link (current-window-configuration))
8608 (org-remove-occur-highlights nil nil t)
8610 ((and (org-on-heading-p)
8612 (concat org-plain-link-re "\\|"
8613 org-bracket-link-regexp "\\|"
8614 org-angle-link-re "\\|"
8615 "[ \t]:[^ \t\n]+:[ \t]*$")))
8616 (not (get-text-property (point) 'org-linked-text)))
8617 (or (org-offer-links-in-entry in-emacs)
8618 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8619 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8620 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8621 (org-footnote-action))
8623 (let (type path link line search (pos (point)))
8626 (skip-chars-forward "^]\n\r")
8627 (when (org-in-regexp org-bracket-link-regexp 1)
8628 (setq link (org-extract-attributes
8629 (org-link-unescape (org-match-string-no-properties 1))))
8630 (while (string-match " *\n *" link)
8631 (setq link (replace-match " " t t link)))
8632 (setq link (org-link-expand-abbrev link))
8634 ((or (file-name-absolute-p link)
8635 (string-match "^\\.\\.?/" link))
8636 (setq type "file" path link))
8637 ((string-match org-link-re-with-space3 link)
8638 (setq type (match-string 1 link) path (match-string 2 link)))
8639 (t (setq type "thisfile" path link)))
8642 (when (get-text-property (point) 'org-linked-text)
8643 (setq type "thisfile"
8644 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8645 (1+ (point)) (point))
8646 path (buffer-substring
8647 (previous-single-property-change pos 'org-linked-text)
8648 (next-single-property-change pos 'org-linked-text)))
8652 (when (or (org-in-regexp org-angle-link-re)
8653 (org-in-regexp org-plain-link-re))
8654 (setq type (match-string 1) path (match-string 2))
8657 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8659 path (match-string 1))
8660 (while (string-match ":" path)
8661 (setq path (replace-match "+" t t path)))
8663 (when (org-in-regexp "<\\([^><\n]+\\)>")
8664 (setq type "tree-match"
8665 path (match-string 1))
8668 (error "No link found"))
8670 ;; switch back to reference buffer
8671 ;; needed when if called in a temporary buffer through
8672 ;; org-open-link-from-string
8673 (with-current-buffer (or reference-buffer (current-buffer))
8675 ;; Remove any trailing spaces in path
8676 (if (string-match " +\\'" path)
8677 (setq path (replace-match "" t t path)))
8678 (if (and org-link-translation-function
8679 (fboundp org-link-translation-function))
8680 ;; Check if we need to translate the link
8681 (let ((tmp (funcall org-link-translation-function type path)))
8682 (setq type (car tmp) path (cdr tmp))))
8686 ((assoc type org-link-protocols)
8687 (funcall (nth 1 (assoc type org-link-protocols)) path))
8689 ((equal type "mailto")
8690 (let ((cmd (car org-link-mailto-program))
8691 (args (cdr org-link-mailto-program)) args1
8692 (address path) (subject "") a)
8693 (if (string-match "\\(.*\\)::\\(.*\\)" path)
8694 (setq address (match-string 1 path)
8695 subject (org-link-escape (match-string 2 path))))
8698 ((not (stringp (car args))) (push (pop args) args1))
8699 (t (setq a (pop args))
8700 (if (string-match "%a" a)
8701 (setq a (replace-match address t t a)))
8702 (if (string-match "%s" a)
8703 (setq a (replace-match subject t t a)))
8705 (apply cmd (nreverse args1))))
8707 ((member type '("http" "https" "ftp" "news"))
8708 (browse-url (concat type ":" (org-link-escape
8709 path org-link-escape-chars-browser))))
8711 ((string= type "doi")
8712 (browse-url (concat "http://dx.doi.org/"
8714 path org-link-escape-chars-browser))))
8716 ((member type '("message"))
8717 (browse-url (concat type ":" path)))
8719 ((string= type "tags")
8720 (org-tags-view in-emacs path))
8722 ((string= type "tree-match")
8723 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
8725 ((string= type "file")
8726 (if (string-match "::\\([0-9]+\\)\\'" path)
8727 (setq line (string-to-number (match-string 1 path))
8728 path (substring path 0 (match-beginning 0)))
8729 (if (string-match "::\\(.+\\)\\'" path)
8730 (setq search (match-string 1 path)
8731 path (substring path 0 (match-beginning 0)))))
8732 (if (string-match "[*?{]" (file-name-nondirectory path))
8734 (org-open-file path in-emacs line search)))
8736 ((string= type "news")
8738 (org-gnus-follow-link path))
8740 ((string= type "shell")
8742 (if (or (not org-confirm-shell-link-function)
8743 (funcall org-confirm-shell-link-function
8744 (format "Execute \"%s\" in shell? "
8745 (org-add-props cmd nil
8746 'face 'org-warning))))
8748 (message "Executing %s" cmd)
8749 (shell-command cmd))
8752 ((string= type "elisp")
8754 (if (or (not org-confirm-elisp-link-function)
8755 (funcall org-confirm-elisp-link-function
8756 (format "Execute \"%s\" as elisp? "
8757 (org-add-props cmd nil
8758 'face 'org-warning))))
8759 (message "%s => %s" cmd
8760 (if (equal (string-to-char cmd) ?\()
8762 (call-interactively (read cmd))))
8765 ((and (string= type "thisfile")
8766 (run-hook-with-args-until-success
8767 'org-open-link-functions path)))
8769 ((string= type "thisfile")
8771 (switch-to-buffer-other-window
8772 (org-get-buffer-for-internal-link (current-buffer)))
8773 (org-mark-ring-push))
8774 (let ((cmd `(org-link-search
8776 ,(cond ((equal in-emacs '(4)) 'occur)
8777 ((equal in-emacs '(16)) 'org-occur)
8780 (condition-case nil (eval cmd)
8781 (error (progn (widen) (eval cmd))))))
8784 (browse-url-at-point)))))))
8785 (move-marker org-open-link-marker nil)
8786 (run-hook-with-args 'org-follow-link-hook))
8788 (defun org-offer-links-in-entry (&optional nth zero)
8789 "Offer links in the current entry and follow the selected link.
8790 If there is only one link, follow it immediately as well.
8791 If NTH is an integer, immediately pick the NTH link found.
8792 If ZERO is a string, check also this string for a link, and if
8793 there is one, offer it as link number zero."
8794 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
8795 "\\(" org-angle-link-re "\\)\\|"
8796 "\\(" org-plain-link-re "\\)"))
8798 (in-emacs (if (integerp nth) nil nth))
8799 have-zero end links link c)
8800 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
8801 (push (match-string 0 zero) links)
8802 (setq cnt (1- cnt) have-zero t))
8804 (org-back-to-heading t)
8805 (setq end (save-excursion (outline-next-heading) (point)))
8806 (while (re-search-forward re end t)
8807 (push (match-string 0) links))
8808 (setq links (org-uniquify (reverse links))))
8812 (message "No links"))
8813 ((equal (length links) 1)
8814 (setq link (list (car links))))
8815 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
8816 (setq link (nth (if have-zero nth (1- nth)) links)))
8817 (t ; we have to select a link
8819 (save-window-excursion
8820 (delete-other-windows)
8821 (with-output-to-temp-buffer "*Select Link*"
8823 (if (not (string-match org-bracket-link-regexp l))
8824 (princ (format "[%c] %s\n" (incf cnt)
8825 (org-remove-angle-brackets l)))
8827 (princ (format "[%c] %s (%s)\n" (incf cnt)
8828 (match-string 3 l) (match-string 1 l)))
8829 (princ (format "[%c] %s\n" (incf cnt)
8830 (match-string 1 l))))))
8832 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
8833 (message "Select link to open, RET to open all:")
8834 (setq c (read-char-exclusive))
8835 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
8836 (when (equal c ?q) (error "Abort"))
8840 (if have-zero (setq nth (1+ nth)))
8841 (unless (and (integerp nth) (>= (length links) nth))
8842 (error "Invalid link selection"))
8843 (setq link (list (nth (1- nth) links))))))
8845 (let ((buf (current-buffer)))
8847 (org-open-link-from-string l in-emacs buf))
8851 ;; Add special file links that specify the way of opening
8853 (org-add-link-type "file+sys" 'org-open-file-with-system)
8854 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
8855 (defun org-open-file-with-system (path)
8856 "Open file at PATH using the system way of opeing it."
8857 (org-open-file path 'system))
8858 (defun org-open-file-with-emacs (path)
8859 "Open file at PATH in emacs."
8860 (org-open-file path 'emacs))
8861 (defun org-remove-file-link-modifiers ()
8862 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
8863 (goto-char (point-min))
8864 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
8866 (replace-match "file:" t t))))
8867 (eval-after-load "org-exp"
8868 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
8869 'org-remove-file-link-modifiers))
8873 (defun org-get-effort (&optional pom)
8874 "Get the effort estimate for the current entry."
8875 (org-entry-get pom org-effort-property))
8879 (defvar org-create-file-search-functions nil
8880 "List of functions to construct the right search string for a file link.
8881 These functions are called in turn with point at the location to
8882 which the link should point.
8884 A function in the hook should first test if it would like to
8885 handle this file type, for example by checking the major-mode or
8886 the file extension. If it decides not to handle this file, it
8887 should just return nil to give other functions a chance. If it
8888 does handle the file, it must return the search string to be used
8889 when following the link. The search string will be part of the
8890 file link, given after a double colon, and `org-open-at-point'
8891 will automatically search for it. If special measures must be
8892 taken to make the search successful, another function should be
8893 added to the companion hook `org-execute-file-search-functions',
8896 A function in this hook may also use `setq' to set the variable
8897 `description' to provide a suggestion for the descriptive text to
8898 be used for this link when it gets inserted into an Org-mode
8899 buffer with \\[org-insert-link].")
8901 (defvar org-execute-file-search-functions nil
8902 "List of functions to execute a file search triggered by a link.
8904 Functions added to this hook must accept a single argument, the
8905 search string that was part of the file link, the part after the
8906 double colon. The function must first check if it would like to
8907 handle this search, for example by checking the major-mode or the
8908 file extension. If it decides not to handle this search, it
8909 should just return nil to give other functions a chance. If it
8910 does handle the search, it must return a non-nil value to keep
8911 other functions from trying.
8913 Each function can access the current prefix argument through the
8914 variable `current-prefix-argument'. Note that a single prefix is
8915 used to force opening a link in Emacs, so it may be good to only
8916 use a numeric or double prefix to guide the search function.
8918 In case this is needed, a function in this hook can also restore
8919 the window configuration before `org-open-at-point' was called using:
8921 (set-window-configuration org-window-config-before-follow-link)")
8923 (defun org-link-search (s &optional type avoid-pos)
8924 "Search for a link search option.
8925 If S is surrounded by forward slashes, it is interpreted as a
8926 regular expression. In org-mode files, this will create an `org-occur'
8927 sparse tree. In ordinary files, `occur' will be used to list matches.
8928 If the current buffer is in `dired-mode', grep will be used to search
8929 in all files. If AVOID-POS is given, ignore matches near that position."
8930 (let ((case-fold-search t)
8931 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
8932 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
8933 (append '(("") (" ") ("\t") ("\n"))
8937 (pre nil) (post nil)
8938 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
8940 ;; First check if there are any special
8941 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
8942 ;; Now try the builtin stuff
8943 ((and (equal (string-to-char s0) ?#)
8946 (goto-char (point-min))
8949 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
8950 (setq type 'dedicated
8951 pos (match-beginning 0))))
8952 ;; There is an exact target for this
8954 (org-back-to-heading t)))
8956 (goto-char (point-min))
8959 (concat "<<" (regexp-quote s0) ">>") nil t)
8960 (setq type 'dedicated
8961 pos (match-beginning 0))))
8962 ;; There is an exact target for this
8964 ((and (string-match "^(\\(.*\\))$" s0)
8966 (goto-char (point-min))
8969 (concat "[^[]" (regexp-quote
8970 (format org-coderef-label-format
8971 (match-string 1 s0))))
8973 (setq type 'dedicated
8974 pos (1+ (match-beginning 0))))))
8975 ;; There is a coderef target for this
8977 ((string-match "^/\\(.*\\)/$" s)
8978 ;; A regular expression
8981 (org-occur (match-string 1 s)))
8982 ;;((eq major-mode 'dired-mode)
8983 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
8984 (t (org-do-occur (match-string 1 s)))))
8986 ;; A normal search strings
8987 (when (equal (string-to-char s) ?*)
8988 ;; Anchor on headlines, post may include tags.
8989 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
8990 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
8992 (remove-text-properties
8994 '(face nil mouse-face nil keymap nil fontified nil) s)
8995 ;; Make a series of regular expressions to find a match
8996 (setq words (org-split-string s "[ \n\r\t]+")
8998 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
8999 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9001 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9002 re2a (concat "[ \t\r\n]" re2a_)
9003 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9004 re4 (concat "[^a-zA-Z_]" re4_)
9006 re1 (concat pre re2 post)
9007 re3 (concat pre (if pre re4_ re4) post)
9008 re5 (concat pre ".*" re4)
9009 re2 (concat pre re2)
9010 re2a (concat pre (if pre re2a_ re2a))
9011 re4 (concat pre (if pre re4_ re4))
9012 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9013 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9017 ((eq type 'org-occur) (org-occur reall))
9018 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9019 (t (goto-char (point-min))
9021 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9022 (org-search-not-self 1 re1 nil t)
9023 (org-search-not-self 1 re2 nil t)
9024 (org-search-not-self 1 re2a nil t)
9025 (org-search-not-self 1 re3 nil t)
9026 (org-search-not-self 1 re4 nil t)
9027 (org-search-not-self 1 re5 nil t)
9029 (goto-char (match-beginning 1))
9031 (error "No match")))))
9033 ;; Normal string-search
9034 (goto-char (point-min))
9035 (if (search-forward s nil t)
9036 (goto-char (match-beginning 0))
9037 (error "No match"))))
9038 (and (org-mode-p) (org-show-context 'link-search))
9041 (defun org-search-not-self (group &rest args)
9042 "Execute `re-search-forward', but only accept matches that do not
9043 enclose the position of `org-open-link-marker'."
9044 (let ((m org-open-link-marker))
9046 (while (apply 're-search-forward args)
9047 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9048 (goto-char (match-end group))
9049 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9050 (> (match-beginning 0) (marker-position m))
9051 (< (match-end 0) (marker-position m)))
9053 (or (not (org-in-regexp
9054 org-bracket-link-analytic-regexp 1))
9055 (not (match-end 4)) ; no description
9056 (and (<= (match-beginning 4) (point))
9057 (>= (match-end 4) (point))))))
9058 (throw 'exit (point))))))))
9060 (defun org-get-buffer-for-internal-link (buffer)
9061 "Return a buffer to be used for displaying the link target of internal links."
9063 ((not org-display-internal-link-with-indirect-buffer)
9065 ((string-match "(Clone)$" (buffer-name buffer))
9066 (message "Buffer is already a clone, not making another one")
9067 ;; we also do not modify visibility in this case
9069 (t ; make a new indirect buffer for displaying the link
9070 (let* ((bn (buffer-name buffer))
9071 (ibn (concat bn "(Clone)"))
9072 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9073 (with-current-buffer ib (org-overview))
9076 (defun org-do-occur (regexp &optional cleanup)
9077 "Call the Emacs command `occur'.
9078 If CLEANUP is non-nil, remove the printout of the regular expression
9079 in the *Occur* buffer. This is useful if the regex is long and not useful
9083 (let ((cwin (selected-window)) win beg end)
9084 (when (setq win (get-buffer-window "*Occur*"))
9085 (select-window win))
9086 (goto-char (point-min))
9087 (when (re-search-forward "match[a-z]+" nil t)
9088 (setq beg (match-end 0))
9089 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9090 (setq end (1- (match-beginning 0)))))
9091 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9092 (goto-char (point-min))
9093 (select-window cwin))))
9095 ;;; The mark ring for links jumps
9097 (defvar org-mark-ring nil
9098 "Mark ring for positions before jumps in Org-mode.")
9099 (defvar org-mark-ring-last-goto nil
9100 "Last position in the mark ring used to go back.")
9101 ;; Fill and close the ring
9102 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9103 (loop for i from 1 to org-mark-ring-length do
9104 (push (make-marker) org-mark-ring))
9105 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9108 (defun org-mark-ring-push (&optional pos buffer)
9109 "Put the current position or POS into the mark ring and rotate it."
9111 (setq pos (or pos (point)))
9112 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9113 (move-marker (car org-mark-ring)
9115 (or buffer (current-buffer)))
9117 (substitute-command-keys
9118 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9120 (defun org-mark-ring-goto (&optional n)
9121 "Jump to the previous position in the mark ring.
9122 With prefix arg N, jump back that many stored positions. When
9123 called several times in succession, walk through the entire ring.
9124 Org-mode commands jumping to a different position in the current file,
9125 or to another Org-mode file, automatically push the old position
9129 (if (eq last-command this-command)
9130 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9131 (setq p org-mark-ring))
9132 (setq org-mark-ring-last-goto p)
9134 (switch-to-buffer (marker-buffer m))
9136 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9138 (defun org-remove-angle-brackets (s)
9139 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9140 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9142 (defun org-add-angle-brackets (s)
9143 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9144 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9146 (defun org-remove-double-quotes (s)
9147 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9148 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9151 ;;; Following specific links
9153 (defun org-follow-timestamp-link ()
9155 ((org-at-date-range-p t)
9156 (let ((org-agenda-start-on-weekday)
9157 (t1 (match-string 1))
9158 (t2 (match-string 2)))
9159 (setq t1 (time-to-days (org-time-string-to-time t1))
9160 t2 (time-to-days (org-time-string-to-time t2)))
9161 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9162 ((org-at-timestamp-p t)
9163 (org-agenda-list nil (time-to-days (org-time-string-to-time
9164 (substring (match-string 1) 0 10)))
9166 (t (error "This should not happen"))))
9169 ;;; Following file links
9170 (defvar org-wait nil)
9171 (defun org-open-file (path &optional in-emacs line search)
9172 "Open the file at PATH.
9173 First, this expands any special file name abbreviations. Then the
9174 configuration variable `org-file-apps' is checked if it contains an
9175 entry for this file type, and if yes, the corresponding command is launched.
9177 If no application is found, Emacs simply visits the file.
9179 With optional prefix argument IN-EMACS, Emacs will visit the file.
9180 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9181 and to use an external application to visit the file.
9183 Optional LINE specifies a line to go to, optional SEARCH a string
9184 to search for. If LINE or SEARCH is given, the file will be
9185 opened in Emacs, unless an entry from org-file-apps that makes
9186 use of groups in a regexp matches.
9187 If the file does not exist, an error is thrown."
9188 (let* ((file (if (equal path "")
9190 (substitute-in-file-name (expand-file-name path))))
9191 (file-apps (append org-file-apps (org-default-apps)))
9192 (apps (org-remove-if
9193 'org-file-apps-entry-match-against-dlink-p file-apps))
9194 (apps-dlink (org-remove-if-not
9195 'org-file-apps-entry-match-against-dlink-p file-apps))
9196 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9197 (dirp (if remp nil (file-directory-p file)))
9198 (file (if (and dirp org-open-directory-means-index-dot-org)
9199 (concat (file-name-as-directory file) "index.org")
9201 (a-m-a-p (assq 'auto-mode apps))
9202 (dfile (downcase file))
9203 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9204 (link (cond ((and (eq line nil)
9208 (concat file "::" (number-to-string line)))
9210 (concat file "::" search))))
9211 (dlink (downcase link))
9212 (old-buffer (current-buffer))
9214 (old-mode major-mode)
9215 ext cmd link-match-data)
9216 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9217 (setq ext (match-string 1 dfile))
9218 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9219 (setq ext (match-string 1 dfile))))
9221 ((member in-emacs '((16) system))
9222 (setq cmd (cdr (assoc 'system apps))))
9223 (in-emacs (setq cmd 'emacs))
9225 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9226 (and dirp (cdr (assoc 'directory apps)))
9227 ; first, try matching against apps-dlink
9228 ; if we get a match here, store the match data for later
9229 (let ((match (assoc-default dlink apps-dlink
9232 (progn (setq link-match-data (match-data))
9234 (progn (setq in-emacs (or in-emacs line search))
9235 nil))) ; if we have no match in apps-dlink,
9236 ; always open the file in emacs if line or search
9237 ; is given (for backwards compatibility)
9238 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9240 (cdr (assoc ext apps))
9241 (cdr (assoc t apps))))))
9242 (when (eq cmd 'system)
9243 (setq cmd (cdr (assoc 'system apps))))
9244 (when (eq cmd 'default)
9245 (setq cmd (cdr (assoc t apps))))
9246 (when (eq cmd 'mailcap)
9248 (mailcap-parse-mailcaps)
9249 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9250 (command (mailcap-mime-info mime-type)))
9251 (if (stringp command)
9253 (setq cmd 'emacs))))
9254 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9255 (not (file-exists-p file))
9256 (not org-open-non-existing-files))
9257 (error "No such file: %s" file))
9259 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9260 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9261 (while (string-match "['\"]%s['\"]" cmd)
9262 (setq cmd (replace-match "%s" t t cmd)))
9263 (while (string-match "%s" cmd)
9264 (setq cmd (replace-match
9266 (shell-quote-argument
9267 (convert-standard-filename file)))
9270 ;; Replace "%1", "%2" etc. in command with group matches from regex
9272 (let ((match-index 1)
9273 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9274 (set-match-data link-match-data)
9275 (while (<= match-index number-of-groups)
9276 (let ((regex (concat "%" (number-to-string match-index)))
9277 (replace-with (match-string match-index dlink)))
9278 (while (string-match regex cmd)
9279 (setq cmd (replace-match replace-with t t cmd))))
9280 (setq match-index (+ match-index 1)))))
9282 (save-window-excursion
9283 (start-process-shell-command cmd nil cmd)
9284 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9288 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9290 (if line (org-goto-line line)
9291 (if search (org-link-search search))))
9293 (let ((file (convert-standard-filename file)))
9295 (set-match-data link-match-data)
9297 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9298 (and (org-mode-p) (eq old-mode 'org-mode)
9299 (or (not (equal old-buffer (current-buffer)))
9300 (not (equal old-pos (point))))
9301 (org-mark-ring-push old-pos old-buffer))))
9303 (defun org-file-apps-entry-match-against-dlink-p (entry)
9304 "This function returns non-nil if `entry' uses a regular
9305 expression which should be matched against the whole link by
9308 It assumes that is the case when the entry uses a regular
9309 expression which has at least one grouping construct and the
9310 action is either a lisp form or a command string containing
9311 '%1', i.e. using at least one subexpression match as a
9313 (let ((selector (car entry))
9314 (action (cdr entry)))
9315 (if (stringp selector)
9316 (and (> (regexp-opt-depth selector) 0)
9317 (or (and (stringp action)
9318 (string-match "%[0-9]" action))
9322 (defun org-default-apps ()
9323 "Return the default applications for this operating system."
9325 ((eq system-type 'darwin)
9326 org-file-apps-defaults-macosx)
9327 ((eq system-type 'windows-nt)
9328 org-file-apps-defaults-windowsnt)
9329 (t org-file-apps-defaults-gnu)))
9331 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9332 "Convert extensions to regular expressions in the cars of LIST.
9333 Also, weed out any non-string entries, because the return value is used
9334 only for regexp matching.
9335 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9336 point to the symbol `emacs', indicating that the file should
9337 be opened in Emacs."
9341 (if (not (stringp (car x)))
9343 (if (string-match "\\W" (car x))
9345 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9348 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9350 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9351 (defun org-file-remote-p (file)
9352 "Test whether FILE specifies a location on a remote system.
9353 Return non-nil if the location is indeed remote.
9355 For example, the filename \"/user@host:/foo\" specifies a location
9356 on the system \"/user@host:\"."
9357 (cond ((fboundp 'file-remote-p)
9358 (file-remote-p file))
9359 ((fboundp 'tramp-handle-file-remote-p)
9360 (tramp-handle-file-remote-p file))
9361 ((and (boundp 'ange-ftp-name-format)
9362 (string-match (car ange-ftp-name-format) file))
9369 (defun org-get-org-file ()
9370 "Read a filename, with default directory `org-directory'."
9371 (let ((default (or org-default-notes-file remember-data-file)))
9372 (read-file-name (format "File name [%s]: " default)
9373 (file-name-as-directory org-directory)
9376 (defun org-notes-order-reversed-p ()
9377 "Check if the current file should receive notes in reversed order."
9379 ((not org-reverse-note-order) nil)
9380 ((eq t org-reverse-note-order) t)
9381 ((not (listp org-reverse-note-order)) nil)
9383 (let ((all org-reverse-note-order)
9385 (while (setq entry (pop all))
9386 (if (string-match (car entry) buffer-file-name)
9387 (throw 'exit (cdr entry))))
9390 (defvar org-refile-target-table nil
9391 "The list of refile targets, created by `org-refile'.")
9393 (defvar org-agenda-new-buffers nil
9394 "Buffers created to visit agenda files.")
9396 (defun org-get-refile-targets (&optional default-buffer)
9397 "Produce a table with refile targets."
9398 (let ((case-fold-search nil)
9399 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9400 (entries (or org-refile-targets '((nil . (:level . 1)))))
9401 targets txt re files f desc descre fast-path-p level pos0)
9402 (message "Getting targets...")
9403 (with-current-buffer (or default-buffer (current-buffer))
9404 (while (setq entry (pop entries))
9405 (setq files (car entry) desc (cdr entry))
9406 (setq fast-path-p nil)
9408 ((null files) (setq files (list (current-buffer))))
9409 ((eq files 'org-agenda-files)
9410 (setq files (org-agenda-files 'unrestricted)))
9411 ((and (symbolp files) (fboundp files))
9412 (setq files (funcall files)))
9413 ((and (symbolp files) (boundp files))
9414 (setq files (symbol-value files))))
9415 (if (stringp files) (setq files (list files)))
9417 ((eq (car desc) :tag)
9418 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9419 ((eq (car desc) :todo)
9420 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9421 ((eq (car desc) :regexp)
9422 (setq descre (cdr desc)))
9423 ((eq (car desc) :level)
9424 (setq descre (concat "^\\*\\{" (number-to-string
9425 (if org-odd-levels-only
9426 (1- (* 2 (cdr desc)))
9429 ((eq (car desc) :maxlevel)
9430 (setq fast-path-p t)
9431 (setq descre (concat "^\\*\\{1," (number-to-string
9432 (if org-odd-levels-only
9433 (1- (* 2 (cdr desc)))
9436 (t (error "Bad refiling target description %s" desc)))
9437 (while (setq f (pop files))
9438 (with-current-buffer
9439 (if (bufferp f) f (org-get-agenda-file-buffer f))
9440 (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
9441 (setq f (and f (expand-file-name f)))
9442 (if (eq org-refile-use-outline-path 'file)
9443 (push (list (file-name-nondirectory f) f nil nil) targets))
9447 (goto-char (point-min))
9448 (while (re-search-forward descre nil t)
9449 (goto-char (setq pos0 (point-at-bol)))
9451 (when org-refile-target-verify-function
9453 (or (funcall org-refile-target-verify-function)
9455 (when (looking-at org-complex-heading-regexp)
9456 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
9457 txt (org-link-display-format (match-string 4))
9458 re (concat "^" (regexp-quote
9459 (buffer-substring (match-beginning 1)
9461 (if (match-end 5) (setq re (concat re "[ \t]+"
9463 (match-string 5)))))
9464 (setq re (concat re "[ \t]*$"))
9465 (when org-refile-use-outline-path
9466 (setq txt (mapconcat 'org-protect-slash
9468 (if (eq org-refile-use-outline-path 'file)
9469 (list (file-name-nondirectory
9470 (buffer-file-name (buffer-base-buffer))))
9471 (if (eq org-refile-use-outline-path 'full-file-path)
9472 (list (buffer-file-name (buffer-base-buffer)))))
9473 (org-get-outline-path fast-path-p level txt)
9476 (push (list txt f re (point)) targets)))
9477 (when (= (point) pos0)
9478 ;; verification function has not moved point
9479 (goto-char (point-at-eol))))))))))
9480 (message "Getting targets...done")
9481 (nreverse targets)))
9483 (defun org-protect-slash (s)
9484 (while (string-match "/" s)
9485 (setq s (replace-match "\\" t t s)))
9488 (defvar org-olpa (make-vector 20 nil))
9490 (defun org-get-outline-path (&optional fastp level heading)
9491 "Return the outline path to the current entry, as a list.
9492 The parameters FASTP, LEVEL, and HEADING are for use be a scanner
9493 routine which makes outline path derivations for an entire file,
9494 avoiding backtracing."
9498 (error "Outline path failure, more than 19 levels."))
9499 (loop for i from level upto 19 do
9500 (aset org-olpa i nil))
9502 (delq nil (append org-olpa nil))
9503 (aset org-olpa level heading)))
9504 (let (rtn case-fold-search)
9508 (while (org-up-heading-safe)
9509 (when (looking-at org-complex-heading-regexp)
9510 (push (org-match-string-no-properties 4) rtn)))
9513 (defun org-format-outline-path (path &optional width prefix)
9514 "Format the outlie path PATH for display.
9515 Width is the maximum number of characters that is available.
9516 Prefix is a prefix to be included in the returned string,
9517 such as the file name."
9518 (setq width (or width 79))
9519 (if prefix (setq width (- width (length prefix))))
9522 (let* ((nsteps (length path))
9523 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9524 (maxwidth (if (<= total-width width)
9525 10000 ;; everything fits
9526 ;; we need to shorten the level headings
9527 (/ (- width nsteps) nsteps)))
9528 (org-odd-levels-only nil)
9530 (total (1+ (length prefix))))
9531 (setq maxwidth (max maxwidth 10))
9536 (if (and (= n nsteps) (< maxwidth 10000))
9537 (setq maxwidth (- total-width total)))
9538 (if (< (length h) maxwidth)
9539 (progn (setq total (+ total (length h) 1)) h)
9540 (setq h (substring h 0 (- maxwidth 2))
9541 total (+ total maxwidth 1))
9542 (if (string-match "[ \t]+\\'" h)
9543 (setq h (substring h 0 (match-beginning 0))))
9544 (setq h (concat h "..")))
9545 (org-add-props h nil 'face
9546 (nth (% (1- n) org-n-level-faces)
9551 (defun org-display-outline-path (&optional file current)
9552 "Display the current outline path in the echo area."
9554 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9555 (case-fold-search nil)
9556 (path (and (org-mode-p) (org-get-outline-path))))
9557 (if current (setq path (append path
9559 (org-back-to-heading t)
9560 (if (looking-at org-complex-heading-regexp)
9561 (list (match-string 4)))))))
9563 (org-format-outline-path
9566 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9568 (defvar org-refile-history nil
9569 "History for refiling operations.")
9571 (defvar org-after-refile-insert-hook nil
9572 "Hook run after `org-refile' has inserted its stuff at the new location.
9573 Note that this is still *before* the stuff will be removed from
9574 the *old* location.")
9576 (defun org-refile (&optional goto default-buffer rfloc)
9577 "Move the entry at point to another heading.
9578 The list of target headings is compiled using the information in
9579 `org-refile-targets', which see. This list is created before each use
9580 and will therefore always be up-to-date.
9582 At the target location, the entry is filed as a subitem of the target heading.
9583 Depending on `org-reverse-note-order', the new subitem will either be the
9584 first or the last subitem.
9586 If there is an active region, all entries in that region will be moved.
9587 However, the region must fulfil the requirement that the first heading
9588 is the first one sets the top-level of the moved text - at most siblings
9589 below it are allowed.
9591 With prefix arg GOTO, the command will only visit the target location,
9592 not actually move anything.
9593 With a double prefix `C-u C-u', go to the location where the last refiling
9594 operation has put the subtree.
9595 With a prefix argument of `2', refile to the running clock.
9597 RFLOC can be a refile location obtained in a different way.
9599 See also `org-refile-use-outline-path' and `org-completion-use-ido'"
9601 (let* ((cbuf (current-buffer))
9602 (regionp (org-region-active-p))
9603 (region-start (and regionp (region-beginning)))
9604 (region-end (and regionp (region-end)))
9605 (region-length (and regionp (- region-end region-start)))
9606 (filename (buffer-file-name (buffer-base-buffer cbuf)))
9607 pos it nbuf file re level reversed)
9608 (setq last-command nil)
9610 (goto-char region-start)
9611 (or (bolp) (goto-char (point-at-bol)))
9612 (setq region-start (point))
9613 (unless (org-kill-is-subtree-p
9614 (buffer-substring region-start region-end))
9615 (error "The region is not a (sequence of) subtree(s)")))
9616 (if (equal goto '(16))
9617 (org-refile-goto-last-stored)
9620 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
9622 (setq it (list (or org-clock-heading "running clock")
9624 (marker-buffer org-clock-hd-marker))
9626 (marker-position org-clock-hd-marker)))
9630 (org-refile-get-location
9631 (if goto "Goto: " "Refile to: ") default-buffer
9632 org-refile-allow-creating-parent-nodes)))))
9633 (setq file (nth 1 it)
9638 (equal (buffer-file-name) file)
9640 (and (>= pos region-start)
9641 (<= pos region-end))
9642 (and (>= pos (point))
9643 (< pos (save-excursion
9644 (org-end-of-subtree t t))))))
9645 (error "Cannot refile to position inside the tree or region"))
9647 (setq nbuf (or (find-buffer-visiting file)
9648 (find-file-noselect file)))
9651 (switch-to-buffer nbuf)
9653 (org-show-context 'org-goto))
9656 (org-kill-new (buffer-substring region-start region-end))
9657 (org-save-markers-in-region region-start region-end))
9658 (org-copy-subtree 1 nil t))
9659 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
9660 (find-file-noselect file)))
9661 (setq reversed (org-notes-order-reversed-p))
9668 (looking-at outline-regexp)
9669 (setq level (org-get-valid-level (funcall outline-level) 1))
9672 (or (outline-next-heading) (point-max))
9673 (or (save-excursion (org-get-next-sibling))
9674 (org-end-of-subtree t t)
9678 (goto-char (point-max))
9679 (goto-char (point-min))
9680 (or (outline-next-heading) (goto-char (point-max)))))
9681 (if (not (bolp)) (newline))
9682 (org-paste-subtree level)
9683 (when org-log-refile
9684 (org-add-log-setup 'refile nil nil 'findpos
9686 (unless (eq org-log-refile 'note)
9687 (save-excursion (org-add-log-note))))
9688 (and org-auto-align-tags (org-set-tags nil t))
9689 (bookmark-set "org-refile-last-stored")
9690 (if (fboundp 'deactivate-mark) (deactivate-mark))
9691 (run-hooks 'org-after-refile-insert-hook))))
9693 (delete-region (point) (+ (point) region-length))
9695 (when (featurep 'org-inlinetask)
9696 (org-inlinetask-remove-END-maybe))
9697 (setq org-markers-to-move nil)
9698 (message "Refiled to \"%s\"" (car it)))))))
9700 (defun org-refile-goto-last-stored ()
9701 "Go to the location where the last refile was stored."
9703 (bookmark-jump "org-refile-last-stored")
9704 (message "This is the location of the last refile"))
9706 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
9707 "Prompt the user for a refile location, using PROMPT."
9708 (let ((org-refile-targets org-refile-targets)
9709 (org-refile-use-outline-path org-refile-use-outline-path))
9710 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
9711 (unless org-refile-target-table
9712 (error "No refile targets"))
9713 (let* ((cbuf (current-buffer))
9714 (partial-completion-mode nil)
9715 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
9716 (cfunc (if (and org-refile-use-outline-path
9717 org-outline-path-complete-in-steps)
9718 'org-olpath-completing-read
9719 'org-icompleting-read))
9720 (extra (if org-refile-use-outline-path "/" ""))
9721 (filename (and cfn (expand-file-name cfn)))
9724 (if (and (not (member org-refile-use-outline-path
9725 '(file full-file-path)))
9726 (not (equal filename (nth 1 x))))
9727 (cons (concat (car x) extra " ("
9728 (file-name-nondirectory (nth 1 x)) ")")
9730 (cons (concat (car x) extra) (cdr x))))
9731 org-refile-target-table))
9732 (completion-ignore-case t)
9733 pa answ parent-target child parent old-hist)
9734 (setq old-hist org-refile-history)
9735 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
9736 nil 'org-refile-history))
9737 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
9740 (when (or (not org-refile-history)
9741 (not (eq old-hist org-refile-history))
9742 (not (equal (car pa) (car org-refile-history))))
9743 (setq org-refile-history
9744 (cons (car pa) (if (assoc (car org-refile-history) tbl)
9746 (cdr org-refile-history))))
9747 (if (equal (car org-refile-history) (nth 1 org-refile-history))
9748 (pop org-refile-history)))
9750 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
9752 (setq parent (match-string 1 answ)
9753 child (match-string 2 answ))
9754 (setq parent-target (or (assoc parent tbl)
9755 (assoc (concat parent "/") tbl)))
9756 (when (and parent-target
9757 (or (eq new-nodes t)
9758 (and (eq new-nodes 'confirm)
9759 (y-or-n-p (format "Create new node \"%s\"? "
9761 (org-refile-new-child parent-target child)))
9762 (error "Invalid target location")))))
9764 (defun org-refile-new-child (parent-target child)
9765 "Use refile target PARENT-TARGET to add new CHILD below it."
9766 (unless parent-target
9767 (error "Cannot find parent for new node"))
9768 (let ((file (nth 1 parent-target))
9769 (pos (nth 3 parent-target))
9771 (with-current-buffer (or (find-buffer-visiting file)
9772 (find-file-noselect file))
9778 (goto-char (point-max))
9779 (if (not (bolp)) (newline)))
9780 (when (looking-at outline-regexp)
9781 (setq level (funcall outline-level))
9782 (org-end-of-subtree t t))
9783 (org-back-over-empty-lines)
9784 (insert "\n" (make-string
9785 (if pos (org-get-valid-level level 1) 1) ?*)
9787 (beginning-of-line 0)
9788 (list (concat (car parent-target) "/" child) file "" (point)))))))
9790 (defun org-olpath-completing-read (prompt collection &rest args)
9791 "Read an outline path like a file name."
9792 (let ((thetable collection)
9793 (org-completion-use-ido nil) ; does not work with ido.
9794 (org-completion-use-iswitchb nil)) ; or iswitchb
9796 'org-icompleting-read prompt
9797 (lambda (string predicate &optional flag)
9798 (let (rtn r f (l (length string)))
9802 (try-completion string thetable))
9805 (setq rtn (all-completions string thetable predicate))
9808 (setq r (substring x l))
9809 (if (string-match " ([^)]*)$" x)
9810 (setq f (match-string 0 x))
9812 (if (string-match "/" r)
9813 (concat string (substring r 0 (match-end 0)) f)
9818 (assoc string thetable)))
9824 (defun org-find-dblock (name)
9825 "Find the first dynamic block with name NAME in the buffer.
9826 If not found, stay at current position and return nil."
9829 (goto-char (point-min))
9830 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
9832 (match-beginning 0))))
9833 (if pos (goto-char pos))
9836 (defconst org-dblock-start-re
9837 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
9838 "Matches the start line of a dynamic block, with parameters.")
9840 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
9841 "Matches the end of a dynamic block.")
9843 (defun org-create-dblock (plist)
9844 "Create a dynamic block section, with parameters taken from PLIST.
9845 PLIST must contain a :name entry which is used as name of the block."
9846 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
9849 (let ((col (current-column))
9850 (name (plist-get plist :name)))
9851 (insert "#+BEGIN: " name)
9853 (if (eq (car plist) :name)
9854 (setq plist (cddr plist))
9855 (insert " " (prin1-to-string (pop plist)))))
9856 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
9857 (beginning-of-line -2)))
9859 (defun org-prepare-dblock ()
9860 "Prepare dynamic block for refresh.
9861 This empties the block, puts the cursor at the insert position and returns
9862 the property list including an extra property :name with the block name."
9863 (unless (looking-at org-dblock-start-re)
9864 (error "Not at a dynamic block"))
9865 (let* ((begdel (1+ (match-end 0)))
9866 (name (org-no-properties (match-string 1)))
9867 (params (append (list :name name)
9868 (read (concat "(" (match-string 3) ")")))))
9870 (beginning-of-line 1)
9871 (skip-chars-forward " \t")
9872 (setq params (plist-put params :indentation-column (current-column))))
9873 (unless (re-search-forward org-dblock-end-re nil t)
9874 (error "Dynamic block not terminated"))
9877 (list :content (buffer-substring
9878 begdel (match-beginning 0)))))
9879 (delete-region begdel (match-beginning 0))
9884 (defun org-map-dblocks (&optional command)
9885 "Apply COMMAND to all dynamic blocks in the current buffer.
9886 If COMMAND is not given, use `org-update-dblock'."
9887 (let ((cmd (or command 'org-update-dblock)))
9889 (goto-char (point-min))
9890 (while (re-search-forward org-dblock-start-re nil t)
9891 (goto-char (match-beginning 0))
9895 (error (message "Error during update of dynamic block"))))
9896 (unless (re-search-forward org-dblock-end-re nil t)
9897 (error "Dynamic block not terminated"))))))
9899 (defun org-dblock-update (&optional arg)
9900 "User command for updating dynamic blocks.
9901 Update the dynamic block at point. With prefix ARG, update all dynamic
9902 blocks in the buffer."
9905 (org-update-all-dblocks)
9906 (or (looking-at org-dblock-start-re)
9907 (org-beginning-of-dblock))
9908 (org-update-dblock)))
9910 (defun org-update-dblock ()
9911 "Update the dynamic block at point
9912 This means to empty the block, parse for parameters and then call
9913 the correct writing function."
9914 (save-window-excursion
9915 (let* ((pos (point))
9916 (line (org-current-line))
9917 (params (org-prepare-dblock))
9918 (name (plist-get params :name))
9919 (indent (plist-get params :indentation-column))
9920 (cmd (intern (concat "org-dblock-write:" name))))
9921 (message "Updating dynamic block `%s' at line %d..." name line)
9922 (funcall cmd params)
9923 (message "Updating dynamic block `%s' at line %d...done" name line)
9925 (when (and indent (> indent 0))
9926 (setq indent (make-string indent ?\ ))
9928 (org-beginning-of-dblock)
9930 (while (not (looking-at org-dblock-end-re))
9932 (beginning-of-line 2))
9933 (when (looking-at org-dblock-end-re)
9934 (and (looking-at "[ \t]+")
9936 (insert indent)))))))
9938 (defun org-beginning-of-dblock ()
9939 "Find the beginning of the dynamic block at point.
9940 Error if there is no such block at point."
9944 (if (and (re-search-backward org-dblock-start-re nil t)
9945 (setq beg (match-beginning 0))
9946 (re-search-forward org-dblock-end-re nil t)
9947 (> (match-end 0) pos))
9950 (error "Not in a dynamic block"))))
9952 (defun org-update-all-dblocks ()
9953 "Update all dynamic blocks in the buffer.
9954 This function can be used in a hook."
9956 (org-map-dblocks 'org-update-dblock)))
9961 (defconst org-additional-option-like-keywords
9962 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
9963 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
9964 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
9965 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
9967 "ORGTBL" "TBLFM:" "TBLNAME:"
9968 "BEGIN_EXAMPLE" "END_EXAMPLE"
9969 "BEGIN_QUOTE" "END_QUOTE"
9970 "BEGIN_VERSE" "END_VERSE"
9971 "BEGIN_CENTER" "END_CENTER"
9972 "BEGIN_SRC" "END_SRC"
9973 "CATEGORY" "COLUMNS"
9979 (defcustom org-structure-template-alist
9981 ("s" "#+begin_src ?\n\n#+end_src"
9982 "<src lang=\"?\">\n\n</src>")
9983 ("e" "#+begin_example\n?\n#+end_example"
9984 "<example>\n?\n</example>")
9985 ("q" "#+begin_quote\n?\n#+end_quote"
9986 "<quote>\n?\n</quote>")
9987 ("v" "#+begin_verse\n?\n#+end_verse"
9988 "<verse>\n?\n/verse>")
9989 ("c" "#+begin_center\n?\n#+end_center"
9990 "<center>\n?\n/center>")
9991 ("l" "#+begin_latex\n?\n#+end_latex"
9992 "<literal style=\"latex\">\n?\n</literal>")
9994 "<literal style=\"latex\">?</literal>")
9995 ("h" "#+begin_html\n?\n#+end_html"
9996 "<literal style=\"html\">\n?\n</literal>")
9998 "<literal style=\"html\">?</literal>")
9999 ("a" "#+begin_ascii\n?\n#+end_ascii")
10001 ("i" "#+include %file ?"
10002 "<include file=%file markup=\"?\">")
10004 "Structure completion elements.
10005 This is a list of abbreviation keys and values. The value gets inserted
10006 if you type `<' followed by the key and then press the completion key,
10007 usually `M-TAB'. %file will be replaced by a file name after prompting
10008 for the file using completion.
10009 There are two templates for each key, the first uses the original Org syntax,
10010 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
10011 the default when the /org-mtags.el/ module has been loaded. See also the
10012 variable `org-mtags-prefer-muse-templates'.
10013 This is an experimental feature, it is undecided if it is going to stay in."
10014 :group 'org-completion
10016 (string :tag "Key")
10017 (string :tag "Template")
10018 (string :tag "Muse Template")))
10020 (defun org-try-structure-completion ()
10021 "Try to complete a structure template before point.
10022 This looks for strings like \"<e\" on an otherwise empty line and
10024 (let ((l (buffer-substring (point-at-bol) (point)))
10026 (when (and (looking-at "[ \t]*$")
10027 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
10028 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
10029 (org-complete-expand-structure-template (+ -1 (point-at-bol)
10030 (match-beginning 1)) a)
10033 (defun org-complete-expand-structure-template (start cell)
10034 "Expand a structure template."
10035 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10036 (rpl (nth (if musep 2 1) cell))
10038 (delete-region start (point))
10039 (when (string-match "\\`#\\+" rpl)
10042 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10043 (setq ind (buffer-substring (point-at-bol) (point))))
10045 (setq start (point))
10046 (if (string-match "%file" rpl)
10047 (setq rpl (replace-match
10051 (abbreviate-file-name (read-file-name "Include file: ")))
10054 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10055 (concat "\n" ind)))
10057 (if (re-search-backward "\\?" start t) (delete-char 1))))
10060 (defun org-complete (&optional arg)
10061 "Perform completion on word at point.
10062 At the beginning of a headline, this completes TODO keywords as given in
10063 `org-todo-keywords'.
10064 If the current word is preceded by a backslash, completes the TeX symbols
10065 that are supported for HTML support.
10066 If the current word is preceded by \"#+\", completes special words for
10067 setting file options.
10068 In the line after \"#+STARTUP:, complete valid keywords.\"
10069 At all other locations, this simply calls the value of
10070 `org-completion-fallback-command'."
10072 (org-without-partial-completion
10076 (beg1 (save-excursion
10077 (skip-chars-backward (org-re "[:alnum:]_@"))
10079 (beg (save-excursion
10080 (skip-chars-backward "a-zA-Z0-9_:$")
10082 (confirm (lambda (x) (stringp (car x))))
10083 (searchhead (equal (char-before beg) ?*))
10085 (when (and (member (char-before beg1) '(?. ?<))
10086 (setq a (assoc (buffer-substring beg1 (point))
10087 org-structure-template-alist)))
10088 (org-complete-expand-structure-template (1- beg1) a)
10090 (tag (and (equal (char-before beg1) ?:)
10091 (equal (char-after (point-at-bol)) ?*)))
10092 (prop (and (equal (char-before beg1) ?:)
10093 (not (equal (char-after (point-at-bol)) ?*))))
10094 (texp (equal (char-before beg) ?\\))
10095 (link (equal (char-before beg) ?\[))
10096 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10099 (startup (string-match "^#\\+STARTUP:.*"
10100 (buffer-substring (point-at-bol) (point))))
10101 (completion-ignore-case opt)
10113 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10114 (cons (match-string 2 x)
10115 (match-string 1 x))))
10116 (org-split-string (org-get-current-options) "\n")))
10117 (mapcar 'list org-additional-option-like-keywords)))
10119 (setq type :startup)
10120 org-startup-options)
10121 (link (append org-link-abbrev-alist-local
10122 org-link-abbrev-alist))
10125 (append org-entities-user org-entities))
10126 ((string-match "\\`\\*+[ \t]+\\'"
10127 (buffer-substring (point-at-bol) beg))
10129 (mapcar 'list org-todo-keywords-1))
10131 (setq type :searchhead)
10133 (goto-char (point-min))
10134 (while (re-search-forward org-todo-line-regexp nil t)
10136 (org-make-org-heading-search-string
10137 (match-string 3) t))
10140 (tag (setq type :tag beg beg1)
10141 (or org-tag-alist (org-get-buffer-tags)))
10142 (prop (setq type :prop beg beg1)
10143 (mapcar 'list (org-buffer-property-keys nil t t)))
10145 (call-interactively org-completion-fallback-command)
10146 (throw 'exit nil)))))
10147 (pattern (buffer-substring-no-properties beg end))
10148 (completion (try-completion pattern table confirm)))
10149 (cond ((eq completion t)
10150 (if (not (assoc (upcase pattern) table))
10151 (message "Already complete")
10152 (if (and (equal type :opt)
10153 (not (member (car (assoc (upcase pattern) table))
10154 org-additional-option-like-keywords)))
10155 (insert (substring (cdr (assoc (upcase pattern) table))
10157 (if (memq type '(:tag :prop)) (insert ":")))))
10159 (message "Can't find completion for \"%s\"" pattern)
10161 ((not (string= pattern completion))
10162 (delete-region beg end)
10163 (if (string-match " +$" completion)
10164 (setq completion (replace-match "" t t completion)))
10165 (insert completion)
10166 (if (get-buffer-window "*Completions*")
10167 (delete-window (get-buffer-window "*Completions*")))
10168 (if (assoc completion table)
10169 (if (eq type :todo) (insert " ")
10170 (if (memq type '(:tag :prop)) (insert ":"))))
10171 (if (and (equal type :opt) (assoc completion table))
10172 (message "%s" (substitute-command-keys
10173 "Press \\[org-complete] again to insert example settings"))))
10175 (message "Making completion list...")
10176 (let ((list (sort (all-completions pattern table confirm)
10178 (with-output-to-temp-buffer "*Completions*"
10179 (condition-case nil
10180 ;; Protection needed for XEmacs and emacs 21
10181 (display-completion-list list pattern)
10182 (error (display-completion-list list)))))
10183 (message "Making completion list...%s" "done")))))))
10185 ;;;; TODO, DEADLINE, Comments
10187 (defun org-toggle-comment ()
10188 "Change the COMMENT state of an entry."
10191 (org-back-to-heading)
10192 (let (case-fold-search)
10193 (if (looking-at (concat outline-regexp
10194 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10195 (replace-match "" t t nil 1)
10196 (if (looking-at outline-regexp)
10198 (goto-char (match-end 0))
10199 (insert org-comment-string " ")))))))
10201 (defvar org-last-todo-state-is-todo nil
10202 "This is non-nil when the last TODO state change led to a TODO state.
10203 If the last change removed the TODO tag or switched to DONE, then
10206 (defvar org-setting-tags nil) ; dynamically skipped
10208 (defun org-parse-local-options (string var)
10209 "Parse STRING for startup setting relevant for variable VAR."
10210 (let ((rtn (symbol-value var))
10213 (if (or (not string) (not (string-match "\\S-" string)))
10215 (setq opts (delq nil (mapcar (lambda (x)
10216 (setq e (assoc x org-startup-options))
10217 (if (eq (nth 1 e) var) e nil))
10218 (org-split-string string "[ \t]+"))))
10222 (while (setq e (pop opts))
10223 (if (not (nth 3 e))
10224 (setq rtn (nth 2 e))
10225 (if (not (listp rtn)) (setq rtn nil))
10226 (push (nth 2 e) rtn)))
10229 (defvar org-todo-setup-filter-hook nil
10230 "Hook for functions that pre-filter todo specs.
10232 Each function takes a todo spec and returns either `nil' or the spec
10233 transformed into canonical form." )
10235 (defvar org-todo-get-default-hook nil
10236 "Hook for functions that get a default item for todo.
10238 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10239 `nil' or a string to be used for the todo mark." )
10241 (defvar org-agenda-headline-snapshot-before-repeat)
10243 (defun org-todo (&optional arg)
10244 "Change the TODO state of an item.
10245 The state of an item is given by a keyword at the start of the heading,
10247 *** TODO Write paper
10250 The different keywords are specified in the variable `org-todo-keywords'.
10251 By default the available states are \"TODO\" and \"DONE\".
10252 So for this example: when the item starts with TODO, it is changed to DONE.
10253 When it starts with DONE, the DONE is removed. And when neither TODO nor
10254 DONE are present, add TODO at the beginning of the heading.
10256 With C-u prefix arg, use completion to determine the new state.
10257 With numeric prefix arg, switch to that state.
10258 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10259 With a triple C-u prefix, circumvent any state blocking.
10261 For calling through lisp, arg is also interpreted in the following way:
10262 'none -> empty state
10263 \"\"(empty string) -> switch to empty state
10264 'done -> switch to DONE
10265 'nextset -> switch to the next set of keywords
10266 'previousset -> switch to the previous set of keywords
10267 \"WAITING\" -> switch to the specified keyword, but only if it
10268 really is a member of `org-todo-keywords'."
10270 (if (equal arg '(16)) (setq arg 'nextset))
10271 (let ((org-blocker-hook org-blocker-hook)
10272 (case-fold-search nil))
10273 (when (equal arg '(64))
10274 (setq arg nil org-blocker-hook nil))
10275 (when (and org-blocker-hook
10276 (or org-inhibit-blocking
10277 (org-entry-get nil "NOBLOCKING")))
10278 (setq org-blocker-hook nil))
10281 (org-back-to-heading t)
10282 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10283 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10285 (let* ((match-data (match-data))
10286 (startpos (point-at-bol))
10287 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
10288 (org-log-done org-log-done)
10289 (org-log-repeat org-log-repeat)
10290 (org-todo-log-states org-todo-log-states)
10291 (this (match-string 1))
10292 (hl-pos (match-beginning 0))
10293 (head (org-get-todo-sequence-head this))
10294 (ass (assoc head org-todo-kwd-alist))
10295 (interpret (nth 1 ass))
10296 (done-word (nth 3 ass))
10297 (final-done-word (nth 4 ass))
10298 (last-state (or this ""))
10299 (completion-ignore-case t)
10300 (member (member this org-todo-keywords-1))
10301 (tail (cdr member))
10303 ((and org-todo-key-trigger
10304 (or (and (equal arg '(4))
10305 (eq org-use-fast-todo-selection 'prefix))
10306 (and (not arg) org-use-fast-todo-selection
10307 (not (eq org-use-fast-todo-selection
10309 ;; Use fast selection
10310 (org-fast-todo-selection))
10311 ((and (equal arg '(4))
10312 (or (not org-use-fast-todo-selection)
10313 (not org-todo-key-trigger)))
10314 ;; Read a state with completion
10315 (org-icompleting-read
10316 "State: " (mapcar (lambda(x) (list x))
10317 org-todo-keywords-1)
10321 (if tail (car tail) nil)
10322 (car org-todo-keywords-1)))
10324 (if (equal member org-todo-keywords-1)
10327 (nth (- (length org-todo-keywords-1)
10329 org-todo-keywords-1)
10330 (org-last org-todo-keywords-1))))
10331 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10332 (setq arg nil))) ; hack to fall back to cycling
10334 ;; user or caller requests a specific state
10336 ((equal arg "") nil)
10337 ((eq arg 'none) nil)
10338 ((eq arg 'done) (or done-word (car org-done-keywords)))
10340 (or (car (cdr (member head org-todo-heads)))
10341 (car org-todo-heads)))
10342 ((eq arg 'previousset)
10343 (let ((org-todo-heads (reverse org-todo-heads)))
10344 (or (car (cdr (member head org-todo-heads)))
10345 (car org-todo-heads))))
10346 ((car (member arg org-todo-keywords-1)))
10348 (error "State `%s' not valid in this file" arg))
10349 ((nth (1- (prefix-numeric-value arg))
10350 org-todo-keywords-1))))
10351 ((null member) (or head (car org-todo-keywords-1)))
10352 ((equal this final-done-word) nil) ;; -> make empty
10353 ((null tail) nil) ;; -> first entry
10354 ((memq interpret '(type priority))
10355 (if (eq this-command last-command)
10357 (if (> (length tail) 0)
10358 (or done-word (car org-done-keywords))
10363 (run-hook-with-args-until-success
10364 'org-todo-get-default-hook state last-state)
10366 (next (if state (concat " " state " ") " "))
10367 (change-plist (list :type 'todo-state-change :from this :to state
10368 :position startpos))
10370 (when org-blocker-hook
10371 (setq org-last-todo-state-is-todo
10372 (not (member this org-done-keywords)))
10373 (unless (save-excursion
10375 (run-hook-with-args-until-failure
10376 'org-blocker-hook change-plist)))
10377 (if (interactive-p)
10378 (error "TODO state change from %s to %s blocked" this state)
10380 (message "TODO state change from %s to %s blocked" this state)
10381 (throw 'exit nil))))
10382 (store-match-data match-data)
10383 (replace-match next t t)
10384 (unless (pos-visible-in-window-p hl-pos)
10385 (message "TODO state changed to %s" (org-trim next)))
10387 (setq head (org-get-todo-sequence-head state)
10388 ass (assoc head org-todo-kwd-alist)
10389 interpret (nth 1 ass)
10390 done-word (nth 3 ass)
10391 final-done-word (nth 4 ass)))
10392 (when (memq arg '(nextset previousset))
10393 (message "Keyword-Set %d/%d: %s"
10394 (- (length org-todo-sets) -1
10395 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10396 (length org-todo-sets)
10397 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10398 (setq org-last-todo-state-is-todo
10399 (not (member state org-done-keywords)))
10400 (setq now-done-p (and (member state org-done-keywords)
10401 (not (member this org-done-keywords))))
10402 (and logging (org-local-logging logging))
10403 (when (and (or org-todo-log-states org-log-done)
10404 (not (eq org-inhibit-logging t))
10405 (not (memq arg '(nextset previousset))))
10406 ;; we need to look at recording a time and note
10407 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10408 (nth 2 (assoc this org-todo-log-states))))
10409 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10410 (setq dolog 'time))
10412 (member state org-not-done-keywords)
10413 (not (member this org-not-done-keywords)))
10414 ;; This is now a todo state and was not one before
10415 ;; If there was a CLOSED time stamp, get rid of it.
10416 (org-add-planning-info nil nil 'closed))
10417 (when (and now-done-p org-log-done)
10418 ;; It is now done, and it was not done before
10419 (org-add-planning-info 'closed (org-current-time))
10420 (if (and (not dolog) (eq 'note org-log-done))
10421 (org-add-log-setup 'done state this 'findpos 'note)))
10422 (when (and state dolog)
10423 ;; This is a non-nil state, and we need to log it
10424 (org-add-log-setup 'state state this 'findpos dolog)))
10425 ;; Fixup tag positioning
10426 (org-todo-trigger-tag-changes state)
10427 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10428 (when org-provide-todo-statistics
10429 (org-update-parent-todo-statistics))
10430 (run-hooks 'org-after-todo-state-change-hook)
10431 (if (and arg (not (member state org-done-keywords)))
10432 (setq head (org-get-todo-sequence-head state)))
10433 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10434 ;; Do we need to trigger a repeat?
10436 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10437 ;; This is for the agenda, take a snapshot of the headline.
10439 (setq org-agenda-headline-snapshot-before-repeat
10440 (org-get-heading))))
10441 (org-auto-repeat-maybe state))
10442 ;; Fixup cursor location if close to the keyword
10443 (if (and (outline-on-heading-p)
10445 (save-excursion (beginning-of-line 1)
10446 (looking-at org-todo-line-regexp))
10447 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10449 (goto-char (or (match-end 2) (match-end 1)))
10450 (and (looking-at " ") (just-one-space))))
10451 (when org-trigger-hook
10453 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10455 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10456 "Block turning an entry into a TODO, using the hierarchy.
10457 This checks whether the current task should be blocked from state
10458 changes. Such blocking occurs when:
10460 1. The task has children which are not all in a completed state.
10462 2. A task has a parent with the property :ORDERED:, and there
10463 are siblings prior to the current task with incomplete
10466 3. The parent of the task is blocked because it has siblings that should
10467 be done first, or is child of a block grandparent TODO entry."
10469 (if (not org-enforce-todo-dependencies)
10470 t ; if locally turned off don't block
10472 ;; If this is not a todo state change, or if this entry is already DONE,
10474 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10475 (member (plist-get change-plist :from)
10476 (cons 'done org-done-keywords))
10477 (member (plist-get change-plist :to)
10478 (cons 'todo org-not-done-keywords))
10479 (not (plist-get change-plist :to)))
10480 (throw 'dont-block t))
10481 ;; If this task has children, and any are undone, it's blocked
10483 (org-back-to-heading t)
10484 (let ((this-level (funcall outline-level)))
10485 (outline-next-heading)
10486 (let ((child-level (funcall outline-level)))
10487 (while (and (not (eobp))
10488 (> child-level this-level))
10489 ;; this todo has children, check whether they are all
10491 (if (and (not (org-entry-is-done-p))
10492 (org-entry-is-todo-p))
10493 (throw 'dont-block nil))
10494 (outline-next-heading)
10495 (setq child-level (funcall outline-level))))))
10496 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10497 ;; any previous siblings are undone, it's blocked
10499 (org-back-to-heading t)
10500 (let* ((pos (point))
10501 (parent-pos (and (org-up-heading-safe) (point))))
10502 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10503 (when (and (org-entry-get (point) "ORDERED")
10505 (re-search-forward org-not-done-heading-regexp pos t))
10506 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10507 ;; Search further up the hierarchy, to see if an anchestor is blocked
10509 (goto-char parent-pos)
10510 (if (not (looking-at org-not-done-heading-regexp))
10511 (throw 'dont-block t)) ; do not block, parent is not a TODO
10513 (setq parent-pos (and (org-up-heading-safe) (point)))
10514 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10515 (when (and (org-entry-get (point) "ORDERED")
10517 (re-search-forward org-not-done-heading-regexp pos t))
10518 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10520 (defcustom org-track-ordered-property-with-tag nil
10521 "Should the ORDERED property also be shown as a tag?
10522 The ORDERED property decides if an entry should require subtasks to be
10523 completed in sequence. Since a property is not very visible, setting
10524 this option means that toggling the ORDERED property with the command
10525 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10526 not relevant for the behavior, but it makes things more visible.
10528 Note that toggling the tag with tags commands will not change the property
10529 and therefore not influence behavior!
10531 This can be t, meaning the tag ORDERED should be used, It can also be a
10532 string to select a different tag for this task."
10535 (const :tag "No tracking" nil)
10536 (const :tag "Track with ORDERED tag" t)
10537 (string :tag "Use other tag")))
10539 (defun org-toggle-ordered-property ()
10540 "Toggle the ORDERED property of the current entry.
10541 For better visibility, you can track the value of this property with a tag.
10542 See variable `org-track-ordered-property-with-tag'."
10544 (let* ((t1 org-track-ordered-property-with-tag)
10545 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10547 (org-back-to-heading)
10548 (if (org-entry-get nil "ORDERED")
10550 (org-delete-property "ORDERED")
10551 (and tag (org-toggle-tag tag 'off))
10552 (message "Subtasks can be completed in arbitrary order"))
10553 (org-entry-put nil "ORDERED" "t")
10554 (and tag (org-toggle-tag tag 'on))
10555 (message "Subtasks must be completed in sequence")))))
10557 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10558 (defun org-block-todo-from-checkboxes (change-plist)
10559 "Block turning an entry into a TODO, using checkboxes.
10560 This checks whether the current task should be blocked from state
10561 changes because there are unchecked boxes in this entry."
10562 (if (not org-enforce-todo-checkbox-dependencies)
10563 t ; if locally turned off don't block
10565 ;; If this is not a todo state change, or if this entry is already DONE,
10567 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10568 (member (plist-get change-plist :from)
10569 (cons 'done org-done-keywords))
10570 (member (plist-get change-plist :to)
10571 (cons 'todo org-not-done-keywords))
10572 (not (plist-get change-plist :to)))
10573 (throw 'dont-block t))
10574 ;; If this task has checkboxes that are not checked, it's blocked
10576 (org-back-to-heading t)
10577 (let ((beg (point)) end)
10578 (outline-next-heading)
10581 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10584 (if (boundp 'org-blocked-by-checkboxes)
10585 (setq org-blocked-by-checkboxes t))
10586 (throw 'dont-block nil)))))
10587 t))) ; do not block
10589 (defun org-entry-blocked-p ()
10590 "Is the current entry blocked?"
10591 (if (org-entry-get nil "NOBLOCKING")
10592 nil ;; Never block this entry
10594 (run-hook-with-args-until-failure
10596 (list :type 'todo-state-change
10601 (defun org-update-statistics-cookies (all)
10602 "Update the statistics cookie, either from TODO or from checkboxes.
10603 This should be called with the cursor in a line with a statistics cookie."
10607 (org-update-checkbox-count 'all)
10608 (org-map-entries 'org-update-parent-todo-statistics))
10609 (if (not (org-on-heading-p))
10610 (org-update-checkbox-count)
10611 (let ((pos (move-marker (make-marker) (point)))
10613 (ignore-errors (org-back-to-heading t))
10614 (if (not (org-on-heading-p))
10615 (org-update-checkbox-count)
10616 (setq l1 (org-outline-level))
10617 (setq end (save-excursion
10618 (outline-next-heading)
10619 (if (org-on-heading-p) (setq l2 (org-outline-level)))
10621 (if (and (save-excursion
10623 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
10624 (not (save-excursion (re-search-forward
10625 ":COOKIE_DATA:.*\\<todo\\>" end t))))
10626 (org-update-checkbox-count)
10627 (if (and l2 (> l2 l1))
10630 (org-update-parent-todo-statistics))
10632 (beginning-of-line 1)
10633 (while (re-search-forward
10634 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
10636 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
10638 (move-marker pos nil)))))
10640 (defvar org-entry-property-inherited-from) ;; defined below
10641 (defun org-update-parent-todo-statistics ()
10642 "Update any statistics cookie in the parent of the current headline.
10643 When `org-hierarchical-todo-statistics' is nil, statistics will cover
10644 the entire subtree and this will travel up the hierarchy and update
10645 statistics everywhere."
10647 (let* ((lim 0) prop
10648 (recursive (or (not org-hierarchical-todo-statistics)
10651 (or (setq prop (org-entry-get
10652 nil "COOKIE_DATA" 'inherit)) ""))))
10653 (lim (or (and prop (marker-position
10654 org-entry-property-inherited-from))
10657 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
10658 level ltoggle l1 new ndel
10659 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
10662 (beginning-of-line 1)
10663 (if (org-at-heading-p)
10664 (setq ltoggle (funcall outline-level))
10665 (error "This should not happen"))
10666 (while (and (setq level (org-up-heading-safe))
10667 (or recursive first)
10669 (setq first nil cookie-present nil)
10678 (while (re-search-forward box-re (point-at-eol) t)
10679 (setq cnt-all 0 cnt-done 0 cookie-present t)
10680 (setq is-percent (match-end 2))
10682 (unless (outline-next-heading) (throw 'exit nil))
10683 (while (and (looking-at org-complex-heading-regexp)
10684 (> (setq l1 (length (match-string 1))) level))
10685 (setq kwd (and (or recursive (= l1 ltoggle))
10687 (if (or (eq org-provide-todo-statistics 'all-headlines)
10688 (and (listp org-provide-todo-statistics)
10689 (or (member kwd org-provide-todo-statistics)
10690 (member kwd org-done-keywords))))
10691 (setq cnt-all (1+ cnt-all))
10692 (if (eq org-provide-todo-statistics t)
10693 (and kwd (setq cnt-all (1+ cnt-all)))))
10694 (and (member kwd org-done-keywords)
10695 (setq cnt-done (1+ cnt-done)))
10696 (outline-next-heading)))
10699 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
10700 (format "[%d/%d]" cnt-done cnt-all))
10701 ndel (- (match-end 0) (match-beginning 0)))
10702 (goto-char (match-beginning 0))
10704 (delete-region (point) (+ (point) ndel)))
10705 (when cookie-present
10706 (run-hook-with-args 'org-after-todo-statistics-hook
10707 cnt-done (- cnt-all cnt-done))))))
10708 (run-hooks 'org-todo-statistics-hook)))
10710 (defvar org-after-todo-statistics-hook nil
10711 "Hook that is called after a TODO statistics cookie has been updated.
10712 Each function is called with two arguments: the number of not-done entries
10713 and the number of done entries.
10715 For example, the following function, when added to this hook, will switch
10716 an entry to DONE when all children are done, and back to TODO when new
10717 entries are set to a TODO status. Note that this hook is only called
10718 when there is a statistics cookie in the headline!
10720 (defun org-summary-todo (n-done n-not-done)
10721 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
10722 (let (org-log-done org-log-states) ; turn off logging
10723 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
10726 (defvar org-todo-statistics-hook nil
10727 "Hook that is run whenever Org thinks TODO statistics should be updated.
10728 This hook runs even if there is no statistics cookie present, in which case
10729 `org-after-todo-statistics-hook' would not run.")
10731 (defun org-todo-trigger-tag-changes (state)
10732 "Apply the changes defined in `org-todo-state-tags-triggers'."
10733 (let ((l org-todo-state-tags-triggers)
10735 (when (or (not state) (equal state ""))
10736 (setq changes (append changes (cdr (assoc "" l)))))
10737 (when (and (stringp state) (> (length state) 0))
10738 (setq changes (append changes (cdr (assoc state l)))))
10739 (when (member state org-not-done-keywords)
10740 (setq changes (append changes (cdr (assoc 'todo l)))))
10741 (when (member state org-done-keywords)
10742 (setq changes (append changes (cdr (assoc 'done l)))))
10743 (dolist (c changes)
10744 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
10746 (defun org-local-logging (value)
10747 "Get logging settings from a property VALUE."
10749 ;; directly set the variables, they are already local.
10750 (setq org-log-done nil
10752 org-todo-log-states nil)
10753 (setq words (org-split-string value))
10754 (while (setq w (pop words))
10756 ((setq a (assoc w org-startup-options))
10757 (and (member (nth 1 a) '(org-log-done org-log-repeat))
10758 (set (nth 1 a) (nth 2 a))))
10759 ((setq a (org-extract-log-state-settings w))
10760 (and (member (car a) org-todo-keywords-1)
10761 (push a org-todo-log-states)))))))
10763 (defun org-get-todo-sequence-head (kwd)
10764 "Return the head of the TODO sequence to which KWD belongs.
10765 If KWD is not set, check if there is a text property remembering the
10770 (or (get-text-property (point-at-bol) 'org-todo-head)
10772 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
10773 nil (point-at-eol)))
10774 (get-text-property p 'org-todo-head))))
10775 ((not (member kwd org-todo-keywords-1))
10776 (car org-todo-keywords-1))
10777 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
10779 (defun org-fast-todo-selection ()
10780 "Fast TODO keyword selection with single keys.
10781 Returns the new TODO keyword, or nil if no state change should occur."
10782 (let* ((fulltable org-todo-key-alist)
10783 (done-keywords org-done-keywords) ;; needed for the faces.
10784 (maxlen (apply 'max (mapcar
10786 (if (stringp (car x)) (string-width (car x)) 0))
10789 (fwidth (+ maxlen 3 1 3))
10790 (ncol (/ (- (window-width) 4) fwidth))
10794 (save-window-excursion
10796 (set-buffer (get-buffer-create " *Org todo*"))
10797 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
10799 (org-set-local 'org-done-keywords done-keywords)
10800 (setq tbl fulltable cnt 0)
10801 (while (setq e (pop tbl))
10803 ((equal e '(:startgroup))
10804 (push '() groups) (setq ingroup t)
10805 (when (not (= cnt 0))
10809 ((equal e '(:endgroup))
10810 (setq ingroup nil cnt 0)
10812 ((equal e '(:newline))
10813 (when (not (= cnt 0))
10817 (while (equal (car tbl) '(:newline))
10819 (setq tbl (cdr tbl)))))
10821 (setq tg (car e) c (cdr e))
10822 (if ingroup (push tg (car groups)))
10823 (setq tg (org-add-props tg nil 'face
10824 (org-get-todo-face tg)))
10825 (if (and (= cnt 0) (not ingroup)) (insert " "))
10826 (insert "[" c "] " tg (make-string
10827 (- fwidth 4 (length tg)) ?\ ))
10828 (when (= (setq cnt (1+ cnt)) ncol)
10830 (if ingroup (insert " "))
10833 (goto-char (point-min))
10834 (if (not expert) (org-fit-window-to-buffer))
10835 (message "[a-z..]:Set [SPC]:clear")
10836 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
10839 (and (= c ?q) (not (rassoc c fulltable))))
10840 (setq quit-flag t))
10842 ((setq e (rassoc c fulltable) tg (car e))
10844 (t (setq quit-flag t)))))))
10846 (defun org-entry-is-todo-p ()
10847 (member (org-get-todo-state) org-not-done-keywords))
10849 (defun org-entry-is-done-p ()
10850 (member (org-get-todo-state) org-done-keywords))
10852 (defun org-get-todo-state ()
10854 (org-back-to-heading t)
10855 (and (looking-at org-todo-line-regexp)
10857 (match-string 2))))
10859 (defun org-at-date-range-p (&optional inactive-ok)
10860 "Is the cursor inside a date range?"
10864 (let ((pos (point)))
10865 (skip-chars-backward "^[<\r\n")
10866 (skip-chars-backward "<[")
10867 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10868 (>= (match-end 0) pos)
10870 (skip-chars-backward "^<[\r\n")
10871 (skip-chars-backward "<[")
10872 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10873 (>= (match-end 0) pos)
10877 (defun org-get-repeat (&optional tagline)
10878 "Check if there is a deadline/schedule with repeater in this entry."
10881 (org-back-to-heading t)
10882 (and (re-search-forward (if tagline
10883 (concat tagline "\\s-*" org-repeat-re)
10885 (org-entry-end-position) t)
10886 (match-string-no-properties 1)))))
10888 (defvar org-last-changed-timestamp)
10889 (defvar org-last-inserted-timestamp)
10890 (defvar org-log-post-message)
10891 (defvar org-log-note-purpose)
10892 (defvar org-log-note-how)
10893 (defvar org-log-note-extra)
10894 (defun org-auto-repeat-maybe (done-word)
10895 "Check if the current headline contains a repeated deadline/schedule.
10896 If yes, set TODO state back to what it was and change the base date
10897 of repeating deadline/scheduled time stamps to new date.
10898 This function is run automatically after each state change to a DONE state."
10899 ;; last-state is dynamically scoped into this function
10900 (let* ((repeat (org-get-repeat))
10901 (aa (assoc last-state org-todo-kwd-alist))
10902 (interpret (nth 1 aa))
10904 (whata '(("d" . day) ("m" . month) ("y" . year)))
10905 (msg "Entry repeats: ")
10907 (org-todo-log-states nil)
10908 (nshiftmax 10) (nshift 0)
10909 re type n what ts time to-state)
10911 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
10912 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
10913 org-todo-repeat-to-state))
10914 (unless (and to-state (member to-state org-todo-keywords-1))
10915 (setq to-state (if (eq interpret 'type) last-state head)))
10916 (org-todo to-state)
10917 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
10918 (org-entry-put nil "LAST_REPEAT" (format-time-string
10919 (org-time-stamp-format t t))))
10920 (when org-log-repeat
10921 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
10922 (memq 'org-add-log-note post-command-hook))
10923 ;; OK, we are already setup for some record
10924 (if (eq org-log-repeat 'note)
10925 ;; make sure we take a note, not only a time stamp
10926 (setq org-log-note-how 'note))
10927 ;; Set up for taking a record
10928 (org-add-log-setup 'state (or done-word (car org-done-keywords))
10930 'findpos org-log-repeat)))
10931 (org-back-to-heading t)
10932 (org-add-planning-info nil nil 'closed)
10933 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
10934 org-deadline-time-regexp "\\)\\|\\("
10935 org-ts-regexp "\\)"))
10936 (while (re-search-forward
10937 re (save-excursion (outline-next-heading) (point)) t)
10938 (setq type (if (match-end 1) org-scheduled-string
10939 (if (match-end 3) org-deadline-string "Plain:"))
10940 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
10941 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
10942 (setq n (string-to-number (match-string 2 ts))
10943 what (match-string 3 ts))
10944 (if (equal what "w") (setq n (* n 7) what "d"))
10945 ;; Preparation, see if we need to modify the start date for the change
10946 (when (match-end 1)
10947 (setq time (save-match-data (org-time-string-to-time ts)))
10949 ((equal (match-string 1 ts) ".")
10950 ;; Shift starting date to today
10951 (org-timestamp-change
10952 (- (time-to-days (current-time)) (time-to-days time))
10954 ((equal (match-string 1 ts) "+")
10955 (while (or (= nshift 0)
10956 (<= (time-to-days time) (time-to-days (current-time))))
10957 (when (= (incf nshift) nshiftmax)
10958 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
10960 (org-timestamp-change n (cdr (assoc what whata)))
10961 (org-at-timestamp-p t)
10962 (setq ts (match-string 1))
10963 (setq time (save-match-data (org-time-string-to-time ts))))
10964 (org-timestamp-change (- n) (cdr (assoc what whata)))
10965 ;; rematch, so that we have everything in place for the real shift
10966 (org-at-timestamp-p t)
10967 (setq ts (match-string 1))
10968 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
10969 (org-timestamp-change n (cdr (assoc what whata)))
10970 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
10971 (setq org-log-post-message msg)
10972 (message "%s" msg))))
10974 (defun org-show-todo-tree (arg)
10975 "Make a compact tree which shows all headlines marked with TODO.
10976 The tree will show the lines where the regexp matches, and all higher
10977 headlines above the match.
10978 With a \\[universal-argument] prefix, prompt for a regexp to match.
10979 With a numeric prefix N, construct a sparse tree for the Nth element
10980 of `org-todo-keywords-1'."
10982 (let ((case-fold-search nil)
10984 (cond ((null arg) org-not-done-regexp)
10986 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
10987 (mapcar 'list org-todo-keywords-1))))
10989 (mapconcat 'identity (org-split-string kwd "|") "\\|")
10991 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
10992 (regexp-quote (nth (1- (prefix-numeric-value arg))
10993 org-todo-keywords-1)))
10994 (t (error "Invalid prefix argument: %s" arg)))))
10995 (message "%d TODO entries found"
10996 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
10998 (defun org-deadline (&optional remove time)
10999 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
11000 With argument REMOVE, remove any deadline from the item.
11001 When TIME is set, it should be an internal time specification, and the
11002 scheduling will use the corresponding date."
11004 (let* ((old-date (org-entry-get nil "DEADLINE"))
11005 (repeater (and old-date
11006 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11007 (match-string 1 old-date))))
11010 (when (and old-date org-log-redeadline)
11011 (org-add-log-setup 'deldeadline nil old-date 'findpos
11012 org-log-redeadline))
11013 (org-remove-timestamp-with-keyword org-deadline-string)
11014 (message "Item no longer has a deadline."))
11015 (org-add-planning-info 'deadline time 'closed)
11016 (when (and old-date org-log-redeadline
11017 (not (equal old-date
11018 (substring org-last-inserted-timestamp 1 -1))))
11019 (org-add-log-setup 'redeadline nil old-date 'findpos
11020 org-log-redeadline))
11023 (org-back-to-heading t)
11024 (when (re-search-forward (concat org-deadline-string " "
11025 org-last-inserted-timestamp)
11027 (outline-next-heading) (point)) t)
11028 (goto-char (1- (match-end 0)))
11029 (insert " " repeater)
11030 (setq org-last-inserted-timestamp
11031 (concat (substring org-last-inserted-timestamp 0 -1)
11033 (substring org-last-inserted-timestamp -1))))))
11034 (message "Deadline on %s" org-last-inserted-timestamp))))
11036 (defun org-schedule (&optional remove time)
11037 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11038 With argument REMOVE, remove any scheduling date from the item.
11039 When TIME is set, it should be an internal time specification, and the
11040 scheduling will use the corresponding date."
11042 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11043 (repeater (and old-date
11044 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11045 (match-string 1 old-date))))
11048 (when (and old-date org-log-reschedule)
11049 (org-add-log-setup 'delschedule nil old-date 'findpos
11050 org-log-reschedule))
11051 (org-remove-timestamp-with-keyword org-scheduled-string)
11052 (message "Item is no longer scheduled."))
11053 (org-add-planning-info 'scheduled time 'closed)
11054 (when (and old-date org-log-reschedule
11055 (not (equal old-date
11056 (substring org-last-inserted-timestamp 1 -1))))
11057 (org-add-log-setup 'reschedule nil old-date 'findpos
11058 org-log-reschedule))
11061 (org-back-to-heading t)
11062 (when (re-search-forward (concat org-scheduled-string " "
11063 org-last-inserted-timestamp)
11065 (outline-next-heading) (point)) t)
11066 (goto-char (1- (match-end 0)))
11067 (insert " " repeater)
11068 (setq org-last-inserted-timestamp
11069 (concat (substring org-last-inserted-timestamp 0 -1)
11071 (substring org-last-inserted-timestamp -1))))))
11072 (message "Scheduled to %s" org-last-inserted-timestamp))))
11074 (defun org-get-scheduled-time (pom &optional inherit)
11075 "Get the scheduled time as a time tuple, of a format suitable
11076 for calling org-schedule with, or if there is no scheduling,
11078 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11080 (apply 'encode-time (org-parse-time-string time)))))
11082 (defun org-get-deadline-time (pom &optional inherit)
11083 "Get the deadine as a time tuple, of a format suitable for
11084 calling org-deadline with, or if there is no scheduling, returns
11086 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11088 (apply 'encode-time (org-parse-time-string time)))))
11090 (defun org-remove-timestamp-with-keyword (keyword)
11091 "Remove all time stamps with KEYWORD in the current entry."
11092 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11095 (org-back-to-heading t)
11097 (outline-next-heading)
11098 (while (re-search-backward re beg t)
11100 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11101 (equal (char-before) ?\ ))
11102 (backward-delete-char 1)
11103 (if (string-match "^[ \t]*$" (buffer-substring
11104 (point-at-bol) (point-at-eol)))
11105 (delete-region (point-at-bol)
11106 (min (point-max) (1+ (point-at-eol))))))))))
11108 (defun org-add-planning-info (what &optional time &rest remove)
11109 "Insert new timestamp with keyword in the line directly after the headline.
11110 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11111 If non is given, the user is prompted for a date.
11112 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11115 (let (org-time-was-given org-end-time-was-given ts
11116 end default-time default-input)
11119 (when (and (not time) (memq what '(scheduled deadline)))
11120 ;; Try to get a default date/time from existing timestamp
11122 (org-back-to-heading t)
11123 (setq end (save-excursion (outline-next-heading) (point)))
11124 (when (re-search-forward (if (eq what 'scheduled)
11125 org-scheduled-time-regexp
11126 org-deadline-time-regexp)
11128 (setq ts (match-string 1)
11130 (apply 'encode-time (org-parse-time-string ts))
11131 default-input (and ts (org-get-compact-tod ts))))))
11133 ;; If necessary, get the time from the user
11134 (setq time (or time (org-read-date nil 'to-time nil nil
11135 default-time default-input))))
11137 (when (and org-insert-labeled-timestamps-at-point
11138 (member what '(scheduled deadline)))
11140 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11141 (org-insert-time-stamp time org-time-was-given
11142 nil nil nil (list org-end-time-was-given))
11146 (let (col list elt ts buffer-invisibility-spec)
11147 (org-back-to-heading t)
11148 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11149 (goto-char (match-end 1))
11150 (setq col (current-column))
11151 (goto-char (match-end 0))
11152 (if (eobp) (insert "\n") (forward-char 1))
11153 (when (and (not what)
11156 org-keyword-time-not-clock-regexp))))
11157 ;; Nothing to add, nothing to remove...... :-)
11159 (if (and (not (looking-at outline-regexp))
11160 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11162 (not (equal (match-string 1) org-clock-string)))
11163 (narrow-to-region (match-beginning 0) (match-end 0))
11164 (insert-before-markers "\n")
11166 (narrow-to-region (point) (point))
11167 (and org-adapt-indentation (org-indent-to-column col)))
11168 ;; Check if we have to remove something.
11169 (setq list (cons what remove))
11171 (setq elt (pop list))
11172 (goto-char (point-min))
11173 (when (or (and (eq elt 'scheduled)
11174 (re-search-forward org-scheduled-time-regexp nil t))
11175 (and (eq elt 'deadline)
11176 (re-search-forward org-deadline-time-regexp nil t))
11177 (and (eq elt 'closed)
11178 (re-search-forward org-closed-time-regexp nil t)))
11180 (if (looking-at "--+<[^>]+>") (replace-match ""))
11181 (skip-chars-backward " ")
11182 (if (looking-at " +") (replace-match ""))))
11183 (goto-char (point-max))
11184 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11187 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11188 (cond ((eq what 'scheduled) org-scheduled-string)
11189 ((eq what 'deadline) org-deadline-string)
11190 ((eq what 'closed) org-closed-string))
11192 (setq ts (org-insert-time-stamp
11194 (or org-time-was-given
11195 (and (eq what 'closed) org-log-done-with-time))
11197 nil nil (list org-end-time-was-given)))
11199 (goto-char (point-min))
11201 (if (and (looking-at "[ \t]+\n")
11202 (equal (char-before) ?\n))
11203 (delete-region (1- (point)) (point-at-eol)))
11206 (defvar org-log-note-marker (make-marker))
11207 (defvar org-log-note-purpose nil)
11208 (defvar org-log-note-state nil)
11209 (defvar org-log-note-previous-state nil)
11210 (defvar org-log-note-how nil)
11211 (defvar org-log-note-extra nil)
11212 (defvar org-log-note-window-configuration nil)
11213 (defvar org-log-note-return-to (make-marker))
11214 (defvar org-log-post-message nil
11215 "Message to be displayed after a log note has been stored.
11216 The auto-repeater uses this.")
11218 (defun org-add-note ()
11219 "Add a note to the current entry.
11220 This is done in the same way as adding a state change note."
11222 (org-add-log-setup 'note nil nil 'findpos nil))
11224 (defvar org-property-end-re)
11225 (defun org-add-log-setup (&optional purpose state prev-state
11226 findpos how &optional extra)
11227 "Set up the post command hook to take a note.
11228 If this is about to TODO state change, the new state is expected in STATE.
11229 When FINDPOS is non-nil, find the correct position for the note in
11230 the current entry. If not, assume that it can be inserted at point.
11231 HOW is an indicator what kind of note should be created.
11232 EXTRA is additional text that will be inserted into the notes buffer."
11233 (let* ((org-log-into-drawer (org-log-into-drawer))
11234 (drawer (cond ((stringp org-log-into-drawer)
11235 org-log-into-drawer)
11236 (org-log-into-drawer "LOGBOOK")
11241 (org-back-to-heading t)
11242 (narrow-to-region (point) (save-excursion
11243 (outline-next-heading) (point)))
11244 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11245 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11247 (goto-char (match-end 0))
11250 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11253 (goto-char (match-end 0))
11254 (or org-log-states-order-reversed
11255 (and (re-search-forward org-property-end-re nil t)
11256 (goto-char (1- (match-beginning 0))))))
11257 (insert "\n:" drawer ":\n:END:")
11258 (beginning-of-line 0)
11259 (org-indent-line-function)
11260 (beginning-of-line 2)
11261 (org-indent-line-function)
11263 ((and org-log-state-notes-insert-after-drawers
11265 (forward-line) (looking-at org-drawer-regexp)))
11267 (while (looking-at org-drawer-regexp)
11268 (goto-char (match-end 0))
11269 (re-search-forward org-property-end-re (point-max) t)
11271 (forward-line -1)))
11272 (unless org-log-states-order-reversed
11273 (and (= (char-after) ?\n) (forward-char 1))
11274 (org-skip-over-state-notes)
11275 (skip-chars-backward " \t\n\r")))
11276 (move-marker org-log-note-marker (point))
11277 (setq org-log-note-purpose purpose
11278 org-log-note-state state
11279 org-log-note-previous-state prev-state
11280 org-log-note-how how
11281 org-log-note-extra extra)
11282 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11284 (defun org-skip-over-state-notes ()
11285 "Skip past the list of State notes in an entry."
11286 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11287 (while (looking-at "[ \t]*- State")
11288 (condition-case nil
11290 (error (org-end-of-item)))))
11292 (defun org-add-log-note (&optional purpose)
11293 "Pop up a window for taking a note, and add this note later at point."
11294 (remove-hook 'post-command-hook 'org-add-log-note)
11295 (setq org-log-note-window-configuration (current-window-configuration))
11296 (delete-other-windows)
11297 (move-marker org-log-note-return-to (point))
11298 (switch-to-buffer (marker-buffer org-log-note-marker))
11299 (goto-char org-log-note-marker)
11300 (org-switch-to-buffer-other-window "*Org Note*")
11302 (if (memq org-log-note-how '(time state))
11303 (let (current-prefix-arg) (org-store-log-note))
11304 (let ((org-inhibit-startup t)) (org-mode))
11305 (insert (format "# Insert note for %s.
11306 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11308 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11309 ((eq org-log-note-purpose 'done) "closed todo item")
11310 ((eq org-log-note-purpose 'state)
11311 (format "state change from \"%s\" to \"%s\""
11312 (or org-log-note-previous-state "")
11313 (or org-log-note-state "")))
11314 ((eq org-log-note-purpose 'reschedule)
11316 ((eq org-log-note-purpose 'delschedule)
11317 "no longer scheduled")
11318 ((eq org-log-note-purpose 'redeadline)
11319 "changing deadline")
11320 ((eq org-log-note-purpose 'deldeadline)
11321 "removing deadline")
11322 ((eq org-log-note-purpose 'refile)
11324 ((eq org-log-note-purpose 'note)
11326 (t (error "This should not happen")))))
11327 (if org-log-note-extra (insert org-log-note-extra))
11328 (org-set-local 'org-finish-function 'org-store-log-note)))
11330 (defvar org-note-abort nil) ; dynamically scoped
11331 (defun org-store-log-note ()
11332 "Finish taking a log note, and insert it to where it belongs."
11333 (let ((txt (buffer-string))
11334 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11336 (kill-buffer (current-buffer))
11337 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11338 (setq txt (replace-match "" t t txt)))
11339 (if (string-match "\\s-+\\'" txt)
11340 (setq txt (replace-match "" t t txt)))
11341 (setq lines (org-split-string txt "\n"))
11342 (when (and note (string-match "\\S-" note))
11344 (org-replace-escapes
11346 (list (cons "%u" (user-login-name))
11347 (cons "%U" user-full-name)
11348 (cons "%t" (format-time-string
11349 (org-time-stamp-format 'long 'inactive)
11351 (cons "%s" (if org-log-note-state
11352 (concat "\"" org-log-note-state "\"")
11354 (cons "%S" (if org-log-note-previous-state
11355 (concat "\"" org-log-note-previous-state "\"")
11357 (if lines (setq note (concat note " \\\\")))
11359 (when (or current-prefix-arg org-note-abort)
11360 (when org-log-into-drawer
11361 (org-remove-empty-drawer-at
11362 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11363 org-log-note-marker))
11366 (with-current-buffer (marker-buffer org-log-note-marker)
11368 (goto-char org-log-note-marker)
11369 (move-marker org-log-note-marker nil)
11371 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11372 (insert "- " (pop lines))
11373 (org-indent-line-function)
11374 (beginning-of-line 1)
11375 (looking-at "[ \t]*")
11376 (setq ind (concat (match-string 0) " "))
11378 (while lines (insert "\n" ind (pop lines)))
11379 (message "Note stored")
11380 (org-back-to-heading t)
11381 (org-cycle-hide-drawers 'children)))))
11382 (set-window-configuration org-log-note-window-configuration)
11383 (with-current-buffer (marker-buffer org-log-note-return-to)
11384 (goto-char org-log-note-return-to))
11385 (move-marker org-log-note-return-to nil)
11386 (and org-log-post-message (message "%s" org-log-post-message)))
11388 (defun org-remove-empty-drawer-at (drawer pos)
11389 "Remove an empty drawer DRAWER at position POS.
11390 POS may also be a marker."
11391 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11397 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11398 (replace-match ""))))))
11400 (defun org-sparse-tree (&optional arg)
11401 "Create a sparse tree, prompt for the details.
11402 This command can create sparse trees. You first need to select the type
11403 of match used to create the tree:
11405 t Show all TODO entries.
11406 T Show entries with a specific TODO keyword.
11407 m Show entries selected by a tags/property match.
11408 p Enter a property name and its value (both with completion on existing
11409 names/values) and show entries with that property.
11410 / Show entries matching a regular expression (`r' can be used as well)
11411 d Show deadlines due within `org-deadline-warning-days'.
11412 b Show deadlines and scheduled items before a date.
11413 a Show deadlines and scheduled items after a date."
11415 (let (ans kwd value)
11416 (message "Sparse tree: [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty [d]eadlines\n [b]efore-date [a]fter-date")
11417 (setq ans (read-char-exclusive))
11420 (call-interactively 'org-check-deadlines))
11422 (call-interactively 'org-check-before-date))
11424 (call-interactively 'org-check-after-date))
11426 (org-show-todo-tree nil))
11428 (org-show-todo-tree '(4)))
11429 ((member ans '(?T ?m))
11430 (call-interactively 'org-match-sparse-tree))
11431 ((member ans '(?p ?P))
11432 (setq kwd (org-icompleting-read "Property: "
11433 (mapcar 'list (org-buffer-property-keys))))
11434 (setq value (org-icompleting-read "Value: "
11435 (mapcar 'list (org-property-values kwd))))
11436 (unless (string-match "\\`{.*}\\'" value)
11437 (setq value (concat "\"" value "\"")))
11438 (org-match-sparse-tree arg (concat kwd "=" value)))
11439 ((member ans '(?r ?R ?/))
11440 (call-interactively 'org-occur))
11441 (t (error "No such sparse tree command \"%c\"" ans)))))
11443 (defvar org-occur-highlights nil
11444 "List of overlays used for occur matches.")
11445 (make-variable-buffer-local 'org-occur-highlights)
11446 (defvar org-occur-parameters nil
11447 "Parameters of the active org-occur calls.
11448 This is a list, each call to org-occur pushes as cons cell,
11449 containing the regular expression and the callback, onto the list.
11450 The list can contain several entries if `org-occur' has been called
11451 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11452 will only contain one set of parameters. When the highlights are
11453 removed (for example with `C-c C-c', or with the next edit (depending
11454 on `org-remove-highlights-with-change'), this variable is emptied
11456 (make-variable-buffer-local 'org-occur-parameters)
11458 (defun org-occur (regexp &optional keep-previous callback)
11459 "Make a compact tree which shows all matches of REGEXP.
11460 The tree will show the lines where the regexp matches, and all higher
11461 headlines above the match. It will also show the heading after the match,
11462 to make sure editing the matching entry is easy.
11463 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11464 call to `org-occur' will be kept, to allow stacking of calls to this
11466 If CALLBACK is non-nil, it is a function which is called to confirm
11467 that the match should indeed be shown."
11468 (interactive "sRegexp: \nP")
11469 (when (equal regexp "")
11470 (error "Regexp cannot be empty"))
11471 (unless keep-previous
11472 (org-remove-occur-highlights nil nil t))
11473 (push (cons regexp callback) org-occur-parameters)
11476 (goto-char (point-min))
11477 (if (or (not keep-previous) ; do not want to keep
11478 (not org-occur-highlights)) ; no previous matches
11481 (while (re-search-forward regexp nil t)
11482 (when (or (not callback)
11483 (save-match-data (funcall callback)))
11484 (setq cnt (1+ cnt))
11485 (when org-highlight-sparse-tree-matches
11486 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11487 (org-show-context 'occur-tree))))
11488 (when org-remove-highlights-with-change
11489 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11491 (unless org-sparse-tree-open-archived-trees
11492 (org-hide-archived-subtrees (point-min) (point-max)))
11493 (run-hooks 'org-occur-hook)
11494 (if (interactive-p)
11495 (message "%d match(es) for regexp %s" cnt regexp))
11498 (defun org-show-context (&optional key)
11499 "Make sure point and context and visible.
11500 How much context is shown depends upon the variables
11501 `org-show-hierarchy-above', `org-show-following-heading'. and
11502 `org-show-siblings'."
11503 (let ((heading-p (org-on-heading-p t))
11504 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11505 (following-p (org-get-alist-option org-show-following-heading key))
11506 (entry-p (org-get-alist-option org-show-entry-below key))
11507 (siblings-p (org-get-alist-option org-show-siblings key)))
11509 ;; Show heading or entry text
11510 (if (and heading-p (not entry-p))
11511 (org-flag-heading nil) ; only show the heading
11512 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11513 (org-show-hidden-entry))) ; show entire entry
11515 ;; Show next sibling, or heading below text
11517 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11518 (org-flag-heading nil))))
11519 (when siblings-p (org-show-siblings))
11521 ;; show all higher headings, possibly with siblings
11523 (while (and (condition-case nil
11524 (progn (org-up-heading-all 1) t)
11527 (org-flag-heading nil)
11528 (when siblings-p (org-show-siblings))))))))
11530 (defvar org-reveal-start-hook nil
11531 "Hook run before revealing a location.")
11533 (defun org-reveal (&optional siblings)
11534 "Show current entry, hierarchy above it, and the following headline.
11535 This can be used to show a consistent set of context around locations
11536 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11537 not t for the search context.
11539 With optional argument SIBLINGS, on each level of the hierarchy all
11540 siblings are shown. This repairs the tree structure to what it would
11541 look like when opened with hierarchical calls to `org-cycle'.
11542 With double optional argument `C-u C-u', go to the parent and show the
11545 (run-hooks 'org-reveal-start-hook)
11546 (let ((org-show-hierarchy-above t)
11547 (org-show-following-heading t)
11548 (org-show-siblings (if siblings t org-show-siblings)))
11549 (org-show-context nil))
11550 (when (equal siblings '(16))
11552 (when (org-up-heading-safe)
11554 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11556 (defun org-highlight-new-match (beg end)
11557 "Highlight from BEG to END and mark the highlight is an occur headline."
11558 (let ((ov (make-overlay beg end)))
11559 (overlay-put ov 'face 'secondary-selection)
11560 (push ov org-occur-highlights)))
11562 (defun org-remove-occur-highlights (&optional beg end noremove)
11563 "Remove the occur highlights from the buffer.
11564 BEG and END are ignored. If NOREMOVE is nil, remove this function
11565 from the `before-change-functions' in the current buffer."
11567 (unless org-inhibit-highlight-removal
11568 (mapc 'delete-overlay org-occur-highlights)
11569 (setq org-occur-highlights nil)
11570 (setq org-occur-parameters nil)
11572 (remove-hook 'before-change-functions
11573 'org-remove-occur-highlights 'local))))
11577 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11578 "Regular expression matching the priority indicator.")
11580 (defvar org-remove-priority-next-time nil)
11582 (defun org-priority-up ()
11583 "Increase the priority of the current item."
11585 (org-priority 'up))
11587 (defun org-priority-down ()
11588 "Decrease the priority of the current item."
11590 (org-priority 'down))
11592 (defun org-priority (&optional action)
11593 "Change the priority of an item by ARG.
11594 ACTION can be `set', `up', `down', or a character."
11596 (unless org-enable-priority-commands
11597 (error "Priority commands are disabled"))
11598 (setq action (or action 'set))
11599 (let (current new news have remove)
11601 (org-back-to-heading t)
11602 (if (looking-at org-priority-regexp)
11603 (setq current (string-to-char (match-string 2))
11605 (setq current org-default-priority))
11607 ((eq action 'remove)
11608 (setq remove t new ?\ ))
11609 ((or (eq action 'set)
11610 (if (featurep 'xemacs) (characterp action) (integerp action)))
11611 (if (not (eq action 'set))
11613 (message "Priority %c-%c, SPC to remove: "
11614 org-highest-priority org-lowest-priority)
11615 (setq new (read-char-exclusive)))
11616 (if (and (= (upcase org-highest-priority) org-highest-priority)
11617 (= (upcase org-lowest-priority) org-lowest-priority))
11618 (setq new (upcase new)))
11619 (cond ((equal new ?\ ) (setq remove t))
11620 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
11621 (error "Priority must be between `%c' and `%c'"
11622 org-highest-priority org-lowest-priority))))
11624 (if (and (not have) (eq last-command this-command))
11625 (setq new org-lowest-priority)
11626 (setq new (if (and org-priority-start-cycle-with-default (not have))
11627 org-default-priority (1- current)))))
11629 (if (and (not have) (eq last-command this-command))
11630 (setq new org-highest-priority)
11631 (setq new (if (and org-priority-start-cycle-with-default (not have))
11632 org-default-priority (1+ current)))))
11633 (t (error "Invalid action")))
11634 (if (or (< (upcase new) org-highest-priority)
11635 (> (upcase new) org-lowest-priority))
11637 (setq news (format "%c" new))
11640 (replace-match "" t t nil 1)
11641 (replace-match news t t nil 2))
11643 (error "No priority cookie found in line")
11644 (let ((case-fold-search nil))
11645 (looking-at org-todo-line-regexp))
11648 (goto-char (match-end 2))
11649 (insert " [#" news "]"))
11650 (goto-char (match-beginning 3))
11651 (insert "[#" news "] "))))
11652 (org-preserve-lc (org-set-tags nil 'align)))
11654 (message "Priority removed")
11655 (message "Priority of current item set to %s" news))))
11657 (defun org-get-priority (s)
11658 "Find priority cookie and return priority."
11660 (if (not (string-match org-priority-regexp s))
11661 (* 1000 (- org-lowest-priority org-default-priority))
11662 (* 1000 (- org-lowest-priority
11663 (string-to-char (match-string 2 s)))))))
11667 (defvar org-agenda-archives-mode)
11668 (defvar org-map-continue-from nil
11669 "Position from where mapping should continue.
11670 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
11672 (defvar org-scanner-tags nil
11673 "The current tag list while the tags scanner is running.")
11674 (defvar org-trust-scanner-tags nil
11675 "Should `org-get-tags-at' use the tags fro the scanner.
11676 This is for internal dynamical scoping only.
11677 When this is non-nil, the function `org-get-tags-at' will return the value
11678 of `org-scanner-tags' instead of building the list by itself. This
11679 can lead to large speed-ups when the tags scanner is used in a file with
11680 many entries, and when the list of tags is retrieved, for example to
11681 obtain a list of properties. Building the tags list for each entry in such
11682 a file becomes an N^2 operation - but with this variable set, it scales
11685 (defun org-scan-tags (action matcher &optional todo-only)
11686 "Scan headline tags with inheritance and produce output ACTION.
11688 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
11689 or `agenda' to produce an entry list for an agenda view. It can also be
11690 a Lisp form or a function that should be called at each matched headline, in
11691 this case the return value is a list of all return values from these calls.
11693 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
11694 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
11695 only lines with a TODO keyword are included in the output."
11696 (require 'org-agenda)
11697 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
11698 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
11700 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
11701 (props (list 'face 'default
11702 'done-face 'org-agenda-done
11703 'undone-face 'default
11704 'mouse-face 'highlight
11705 'org-not-done-regexp org-not-done-regexp
11706 'org-todo-regexp org-todo-regexp
11708 (format "mouse-2 or RET jump to org file %s"
11709 (abbreviate-file-name
11710 (or (buffer-file-name (buffer-base-buffer))
11711 (buffer-name (buffer-base-buffer)))))))
11712 (case-fold-search nil)
11713 (org-map-continue-from nil)
11714 lspos tags tags-list
11715 (tags-alist (list (cons 0 org-file-tags)))
11716 (llast 0) rtn rtn1 level category i txt
11717 todo marker entry priority)
11718 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
11719 (setq action (list 'lambda nil action)))
11721 (goto-char (point-min))
11722 (when (eq action 'sparse-tree)
11724 (org-remove-occur-highlights))
11725 (while (re-search-forward re nil t)
11727 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
11728 tags (if (match-end 4) (org-match-string-no-properties 4)))
11729 (goto-char (setq lspos (match-beginning 0)))
11730 (setq level (org-reduced-level (funcall outline-level))
11731 category (org-get-category))
11732 (setq i llast llast level)
11733 ;; remove tag lists from same and sublevels
11734 (while (>= i level)
11735 (when (setq entry (assoc i tags-alist))
11736 (setq tags-alist (delete entry tags-alist)))
11738 ;; add the next tags
11740 (setq tags (org-split-string tags ":")
11742 (cons (cons level tags) tags-alist)))
11743 ;; compile tags for current headline
11745 (if org-use-tag-inheritance
11746 (apply 'append (mapcar 'cdr (reverse tags-alist)))
11748 org-scanner-tags tags-list)
11749 (when org-use-tag-inheritance
11750 (setcdr (car tags-alist)
11751 (mapcar (lambda (x)
11752 (setq x (copy-sequence x))
11753 (org-add-prop-inherited x))
11754 (cdar tags-alist))))
11755 (when (and tags org-use-tag-inheritance
11756 (or (not (eq t org-use-tag-inheritance))
11757 org-tags-exclude-from-inheritance))
11758 ;; selective inheritance, remove uninherited ones
11759 (setcdr (car tags-alist)
11760 (org-remove-uniherited-tags (cdar tags-alist))))
11761 (when (and (or (not todo-only)
11762 (and (member todo org-not-done-keywords)
11763 (or (not org-agenda-tags-todo-honor-ignore-options)
11764 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
11765 (let ((case-fold-search t)) (eval matcher))
11767 (not (member org-archive-tag tags-list))
11768 ;; we have an archive tag, should we use this anyway?
11769 (or (not org-agenda-skip-archived-trees)
11770 (and (eq action 'agenda) org-agenda-archives-mode))))
11771 (unless (eq action 'sparse-tree) (org-agenda-skip))
11773 ;; select this headline
11776 ((eq action 'sparse-tree)
11777 (and org-highlight-sparse-tree-matches
11778 (org-get-heading) (match-end 0)
11779 (org-highlight-new-match
11780 (match-beginning 0) (match-beginning 1)))
11781 (org-show-context 'tags-tree))
11782 ((eq action 'agenda)
11783 (setq txt (org-format-agenda-item
11786 (if (eq org-tags-match-list-sublevels 'indented)
11787 (make-string (1- level) ?.) "")
11792 priority (org-get-priority txt))
11794 (setq marker (org-agenda-new-marker))
11795 (org-add-props txt props
11796 'org-marker marker 'org-hd-marker marker 'org-category category
11798 'priority priority 'type "tagsmatch")
11800 ((functionp action)
11801 (setq org-map-continue-from nil)
11803 (setq rtn1 (funcall action))
11805 (t (error "Invalid action")))
11807 ;; if we are to skip sublevels, jump to end of subtree
11808 (unless org-tags-match-list-sublevels
11809 (org-end-of-subtree t)
11810 (backward-char 1))))
11811 ;; Get the correct position from where to continue
11812 (if org-map-continue-from
11813 (goto-char org-map-continue-from)
11814 (and (= (point) lspos) (end-of-line 1)))))
11815 (when (and (eq action 'sparse-tree)
11816 (not org-sparse-tree-open-archived-trees))
11817 (org-hide-archived-subtrees (point-min) (point-max)))
11820 (defun org-remove-uniherited-tags (tags)
11821 "Remove all tags that are not inherited from the list TAGS."
11823 ((eq org-use-tag-inheritance t)
11824 (if org-tags-exclude-from-inheritance
11825 (org-delete-all org-tags-exclude-from-inheritance tags)
11827 ((not org-use-tag-inheritance) nil)
11828 ((stringp org-use-tag-inheritance)
11831 (if (and (string-match org-use-tag-inheritance x)
11832 (not (member x org-tags-exclude-from-inheritance)))
11835 ((listp org-use-tag-inheritance)
11838 (if (member x org-use-tag-inheritance) x nil))
11841 (defvar todo-only) ;; dynamically scoped
11843 (defun org-match-sparse-tree (&optional todo-only match)
11844 "Create a sparse tree according to tags string MATCH.
11845 MATCH can contain positive and negative selection of tags, like
11846 \"+WORK+URGENT-WITHBOSS\".
11847 If optional argument TODO-ONLY is non-nil, only select lines that are
11850 (org-prepare-agenda-buffers (list (current-buffer)))
11851 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
11853 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
11855 (defvar org-cached-props nil)
11856 (defun org-cached-entry-get (pom property)
11857 (if (or (eq t org-use-property-inheritance)
11858 (and (stringp org-use-property-inheritance)
11859 (string-match org-use-property-inheritance property))
11860 (and (listp org-use-property-inheritance)
11861 (member property org-use-property-inheritance)))
11862 ;; Caching is not possible, check it directly
11863 (org-entry-get pom property 'inherit)
11864 ;; Get all properties, so that we can do complicated checks easily
11865 (cdr (assoc property (or org-cached-props
11866 (setq org-cached-props
11867 (org-entry-properties pom)))))))
11869 (defun org-global-tags-completion-table (&optional files)
11870 "Return the list of all tags in all agenda buffer/files."
11877 (set-buffer (find-file-noselect file))
11878 (append (org-get-buffer-tags)
11879 (mapcar (lambda (x) (if (stringp (car-safe x))
11880 (list (car-safe x)) nil))
11882 (if (and files (car files))
11884 (org-agenda-files))))))))
11886 (defun org-make-tags-matcher (match)
11887 "Create the TAGS//TODO matcher form for the selection string MATCH."
11888 ;; todo-only is scoped dynamically into this function, and the function
11889 ;; may change it if the matcher asks for it.
11891 ;; Get a new match request, with completion
11892 (let ((org-last-tags-completion-table
11893 (org-global-tags-completion-table)))
11894 (setq match (org-completing-read-no-i
11895 "Match: " 'org-tags-completion-function nil nil nil
11896 'org-tags-history))))
11898 ;; Parse the string and create a lisp form
11899 (let ((match0 match)
11900 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
11902 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
11903 orterms term orlist re-p str-p level-p level-op time-p
11904 prop-p pn pv po cat-p gv rest)
11905 (if (string-match "/+" match)
11906 ;; match contains also a todo-matching request
11908 (setq tagsmatch (substring match 0 (match-beginning 0))
11909 todomatch (substring match (match-end 0)))
11910 (if (string-match "^!" todomatch)
11911 (setq todo-only t todomatch (substring todomatch 1)))
11912 (if (string-match "^\\s-*$" todomatch)
11913 (setq todomatch nil)))
11914 ;; only matching tags
11915 (setq tagsmatch match todomatch nil))
11917 ;; Make the tags matcher
11918 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
11919 (setq tagsmatcher t)
11920 (setq orterms (org-split-string tagsmatch "|") orlist nil)
11921 (while (setq term (pop orterms))
11922 (while (and (equal (substring term -1) "\\") orterms)
11923 (setq term (concat term "|" (pop orterms)))) ; repair bad split
11924 (while (string-match re term)
11925 (setq rest (substring term (match-end 0))
11926 minus (and (match-end 1)
11927 (equal (match-string 1 term) "-"))
11928 tag (match-string 2 term)
11929 re-p (equal (string-to-char tag) ?{)
11930 level-p (match-end 4)
11931 prop-p (match-end 5)
11933 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
11935 (setq level-op (org-op-to-function (match-string 3 term)))
11936 `(,level-op level ,(string-to-number
11937 (match-string 4 term))))
11939 (setq pn (match-string 5 term)
11940 po (match-string 6 term)
11941 pv (match-string 7 term)
11942 cat-p (equal pn "CATEGORY")
11943 re-p (equal (string-to-char pv) ?{)
11944 str-p (equal (string-to-char pv) ?\")
11945 time-p (save-match-data
11946 (string-match "^\"[[<].*[]>]\"$" pv))
11947 pv (if (or re-p str-p) (substring pv 1 -1) pv))
11948 (if time-p (setq pv (org-matcher-time pv)))
11949 (setq po (org-op-to-function po (if time-p 'time str-p)))
11951 ((equal pn "CATEGORY")
11952 (setq gv '(get-text-property (point) 'org-category)))
11956 (setq gv `(org-cached-entry-get nil ,pn))))
11959 `(not (string-match ,pv (or ,gv "")))
11960 `(string-match ,pv (or ,gv "")))
11962 `(,po (or ,gv "") ,pv)
11963 `(,po (string-to-number (or ,gv ""))
11964 ,(string-to-number pv) ))))
11965 (t `(member ,tag tags-list)))
11966 mm (if minus (list 'not mm) mm)
11968 (push mm tagsmatcher))
11969 (push (if (> (length tagsmatcher) 1)
11970 (cons 'and tagsmatcher)
11973 (setq tagsmatcher nil))
11974 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
11976 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
11977 ;; Make the todo matcher
11978 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
11979 (setq todomatcher t)
11980 (setq orterms (org-split-string todomatch "|") orlist nil)
11981 (while (setq term (pop orterms))
11982 (while (string-match re term)
11983 (setq minus (and (match-end 1)
11984 (equal (match-string 1 term) "-"))
11985 kwd (match-string 2 term)
11986 re-p (equal (string-to-char kwd) ?{)
11987 term (substring term (match-end 0))
11989 `(string-match ,(substring kwd 1 -1) todo)
11990 (list 'equal 'todo kwd))
11991 mm (if minus (list 'not mm) mm))
11992 (push mm todomatcher))
11993 (push (if (> (length todomatcher) 1)
11994 (cons 'and todomatcher)
11997 (setq todomatcher nil))
11998 (setq todomatcher (if (> (length orlist) 1)
11999 (cons 'or orlist) (car orlist))))
12001 ;; Return the string and lisp forms of the matcher
12002 (setq matcher (if todomatcher
12003 (list 'and tagsmatcher todomatcher)
12005 (cons match0 matcher)))
12007 (defun org-op-to-function (op &optional stringp)
12008 "Turn an operator into the appropriate function."
12011 ((equal op "<" ) '(< string< org-time<))
12012 ((equal op ">" ) '(> org-string> org-time>))
12013 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
12014 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
12015 ((member op '("=" "==")) '(= string= org-time=))
12016 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
12017 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
12019 (defun org<> (a b) (not (= a b)))
12020 (defun org-string<= (a b) (or (string= a b) (string< a b)))
12021 (defun org-string>= (a b) (not (string< a b)))
12022 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
12023 (defun org-string<> (a b) (not (string= a b)))
12024 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
12025 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
12026 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
12027 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
12028 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
12029 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
12031 "Convert S to a floating point time.
12032 If S is already a number, just return it. If it is a string, parse
12033 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12037 (condition-case nil
12038 (float-time (apply 'encode-time (org-parse-time-string s)))
12042 (defun org-time-today ()
12043 "Time in seconds today at 0:00.
12044 Returns the float number of seconds since the beginning of the
12045 epoch to the beginning of today (00:00)."
12046 (float-time (apply 'encode-time
12047 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12049 (defun org-matcher-time (s)
12050 "Interpret a time comparison value."
12053 ((string= s "<now>") (float-time))
12054 ((string= s "<today>") (org-time-today))
12055 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12056 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12057 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12058 (+ (org-time-today)
12059 (* (string-to-number (match-string 1 s))
12060 (cdr (assoc (match-string 2 s)
12061 '(("d" . 86400.0) ("w" . 604800.0)
12062 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12065 (defun org-match-any-p (re list)
12066 "Does re match any element of list?"
12067 (setq list (mapcar (lambda (x) (string-match re x)) list))
12070 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12071 (defvar org-tags-overlay (make-overlay 1 1))
12072 (org-detach-overlay org-tags-overlay)
12074 (defun org-get-local-tags-at (&optional pos)
12075 "Get a list of tags defined in the current headline."
12076 (org-get-tags-at pos 'local))
12078 (defun org-get-local-tags ()
12079 "Get a list of tags defined in the current headline."
12080 (org-get-tags-at nil 'local))
12082 (defun org-get-tags-at (&optional pos local)
12083 "Get a list of all headline tags applicable at POS.
12084 POS defaults to point. If tags are inherited, the list contains
12085 the targets in the same sequence as the headlines appear, i.e.
12086 the tags of the current headline come last.
12087 When LOCAL is non-nil, only return tags from the current headline,
12088 ignore inherited ones."
12090 (if (and org-trust-scanner-tags
12091 (or (not pos) (equal pos (point)))
12094 (let (tags ltags lastpos parent)
12098 (goto-char (or pos (point)))
12101 (condition-case nil
12103 (org-back-to-heading t)
12104 (while (not (equal lastpos (point)))
12105 (setq lastpos (point))
12107 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12108 (setq ltags (org-split-string
12109 (org-match-string-no-properties 1) ":"))
12111 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12114 (org-remove-uniherited-tags ltags)
12117 (or org-use-tag-inheritance (throw 'done t))
12118 (if local (throw 'done t))
12119 (or (org-up-heading-safe) (error nil))
12122 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12124 (defun org-add-prop-inherited (s)
12125 (add-text-properties 0 (length s) '(inherited t) s)
12128 (defun org-toggle-tag (tag &optional onoff)
12129 "Toggle the tag TAG for the current line.
12130 If ONOFF is `on' or `off', don't toggle but set to this state."
12133 (org-back-to-heading t)
12134 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12137 (setq current (match-string 1))
12138 (replace-match ""))
12140 (setq current (nreverse (org-split-string current ":")))
12144 (or (member tag current) (push tag current)))
12146 (or (not (member tag current)) (setq current (delete tag current))))
12147 (t (if (member tag current)
12148 (setq current (delete tag current))
12150 (push tag current))))
12154 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12155 (org-set-tags nil t))
12156 (delete-horizontal-space))
12157 (run-hooks 'org-after-tags-change-hook))
12160 (defun org-align-tags-here (to-col)
12161 ;; Assumes that this is a headline
12162 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12163 (beginning-of-line 1)
12164 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12165 (< pos (match-beginning 2)))
12167 (setq tags-l (- (match-end 2) (match-beginning 2)))
12168 (goto-char (match-beginning 1))
12170 (delete-region (point) (1+ (match-beginning 2)))
12171 (setq ncol (max (1+ (current-column))
12175 (- (abs to-col) tags-l))))
12177 (insert (make-string (- ncol (current-column)) ?\ ))
12178 (setq ncol (current-column))
12179 (when indent-tabs-mode (tabify p (point-at-eol)))
12180 (org-move-to-column (min ncol col) t))
12183 (defun org-set-tags-command (&optional arg just-align)
12184 "Call the set-tags command for the current entry."
12186 (if (org-on-heading-p)
12187 (org-set-tags arg just-align)
12189 (org-back-to-heading t)
12190 (org-set-tags arg just-align))))
12192 (defun org-set-tags-to (data)
12193 "Set the tags of the current entry to DATA, replacing the current tags.
12194 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12195 If DATA is nil or the empty string, any tags will be removed."
12196 (interactive "sTags: ")
12200 ((equal data "") "")
12202 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12205 (concat ":" (mapconcat 'identity data ":") ":"))
12209 (org-back-to-heading t)
12210 (when (looking-at org-complex-heading-regexp)
12213 (goto-char (match-beginning 5))
12215 (delete-region (point) (point-at-eol))
12216 (org-set-tags nil 'align))
12217 (goto-char (point-at-eol))
12219 (org-set-tags nil 'align)))
12220 (beginning-of-line 1)
12221 (if (looking-at ".*?\\([ \t]+\\)$")
12222 (delete-region (match-beginning 1) (match-end 1))))))
12224 (defun org-align-all-tags ()
12225 "Align the tags i all headings."
12228 (or (ignore-errors (org-back-to-heading t))
12229 (outline-next-heading))
12230 (if (org-on-heading-p)
12232 (message "No headings"))))
12234 (defun org-set-tags (&optional arg just-align)
12235 "Set the tags for the current headline.
12236 With prefix ARG, realign all tags in headings in the current buffer."
12238 (let* ((re (concat "^" outline-regexp))
12239 (current (org-get-tags-string))
12240 (col (current-column))
12241 (org-setting-tags t)
12242 table current-tags inherited-tags ; computed below when needed
12246 (goto-char (point-min))
12247 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12248 (while (re-search-forward re nil t)
12249 (org-set-tags nil t)
12251 (message "All tags realigned to column %d" org-tags-column))
12253 (setq tags current)
12254 ;; Get a new set of tags from the user
12256 (setq table (append org-tag-persistent-alist
12257 (or org-tag-alist (org-get-buffer-tags))
12258 (and org-complete-tags-always-offer-all-agenda-tags
12259 (org-global-tags-completion-table (org-agenda-files))))
12260 org-last-tags-completion-table table
12261 current-tags (org-split-string current ":")
12262 inherited-tags (nreverse
12263 (nthcdr (length current-tags)
12264 (nreverse (org-get-tags-at))))
12266 (if (or (eq t org-use-fast-tag-selection)
12267 (and org-use-fast-tag-selection
12268 (delq nil (mapcar 'cdr table))))
12269 (org-fast-tag-selection
12270 current-tags inherited-tags table
12271 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12272 (let ((org-add-colon-after-tag-completion t))
12274 (org-without-partial-completion
12275 (org-icompleting-read "Tags: " 'org-tags-completion-function
12276 nil nil current 'org-tags-history)))))))
12277 (while (string-match "[-+&]+" tags)
12278 ;; No boolean logic, just a list
12279 (setq tags (replace-match ":" t t tags))))
12281 (if org-tags-sort-function
12282 (setq tags (mapconcat 'identity
12283 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12284 org-tags-sort-function) ":")))
12286 (if (string-match "\\`[\t ]*\\'" tags)
12288 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12289 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12291 ;; Insert new tags at the correct column
12292 (beginning-of-line 1)
12294 ((and (equal current "") (equal tags "")))
12295 ((re-search-forward
12296 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12298 (if (equal tags "")
12300 (goto-char (match-beginning 0))
12301 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12302 (1+ (point)) (point))
12303 c1 (max (1+ c0) (if (> org-tags-column 0)
12305 (- (- org-tags-column) (length tags))))
12306 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12307 (replace-match rpl t t)
12308 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12310 (t (error "Tags alignment failed")))
12311 (org-move-to-column col)
12313 (run-hooks 'org-after-tags-change-hook)))))
12315 (defun org-change-tag-in-region (beg end tag off)
12316 "Add or remove TAG for each entry in the region.
12317 This works in the agenda, and also in an org-mode buffer."
12319 (list (region-beginning) (region-end)
12320 (let ((org-last-tags-completion-table
12322 (org-get-buffer-tags)
12323 (org-global-tags-completion-table))))
12324 (org-icompleting-read
12325 "Tag: " 'org-tags-completion-function nil nil nil
12326 'org-tags-history))
12328 (message "[s]et or [r]emove? ")
12329 (equal (read-char-exclusive) ?r))))
12330 (if (fboundp 'deactivate-mark) (deactivate-mark))
12331 (let ((agendap (equal major-mode 'org-agenda-mode))
12332 l1 l2 m buf pos newhead (cnt 0))
12334 (setq l2 (1- (org-current-line)))
12336 (setq l1 (org-current-line))
12337 (loop for l from l1 to l2 do
12339 (setq m (get-text-property (point) 'org-hd-marker))
12340 (when (or (and (org-mode-p) (org-on-heading-p))
12342 (setq buf (if agendap (marker-buffer m) (current-buffer))
12343 pos (if agendap m (point)))
12344 (with-current-buffer buf
12348 (setq cnt (1+ cnt))
12349 (org-toggle-tag tag (if off 'off 'on))
12350 (setq newhead (org-get-heading)))))
12351 (and agendap (org-agenda-change-all-lines newhead m))))
12352 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12354 (defun org-tags-completion-function (string predicate &optional flag)
12355 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12356 (confirm (lambda (x) (stringp (car x)))))
12357 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12358 (setq s1 (match-string 1 string)
12359 s2 (match-string 2 string))
12360 (setq s1 "" s2 string))
12364 (setq rtn (try-completion s2 ctable confirm))
12367 (concat s1 s2 (substring rtn (length s2))
12368 (if (and org-add-colon-after-tag-completion
12369 (assoc rtn ctable))
12374 (all-completions s2 ctable confirm)
12378 (assoc s2 ctable)))
12381 (defun org-fast-tag-insert (kwd tags face &optional end)
12382 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12383 (insert (format "%-12s" (concat kwd ":"))
12384 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12387 (defun org-fast-tag-show-exit (flag)
12390 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12391 (replace-match ""))
12394 (org-move-to-column (- (window-width) 19) t)
12395 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12397 (defun org-set-current-tags-overlay (current prefix)
12398 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12399 (if (featurep 'xemacs)
12400 (org-overlay-display org-tags-overlay (concat prefix s)
12401 'secondary-selection)
12402 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12403 (org-overlay-display org-tags-overlay (concat prefix s)))))
12405 (defvar org-last-tag-selection-key nil)
12406 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12407 "Fast tag selection with single keys.
12408 CURRENT is the current list of tags in the headline, INHERITED is the
12409 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12410 possibly with grouping information. TODO-TABLE is a similar table with
12411 TODO keywords, should these have keys assigned to them.
12412 If the keys are nil, a-z are automatically assigned.
12413 Returns the new tags string, or nil to not change the current settings."
12414 (let* ((fulltable (append table todo-table))
12415 (maxlen (apply 'max (mapcar
12417 (if (stringp (car x)) (string-width (car x)) 0))
12419 (buf (current-buffer))
12420 (expert (eq org-fast-tag-selection-single-key 'expert))
12422 (fwidth (+ maxlen 3 1 3))
12423 (ncol (/ (- (window-width) 4) fwidth))
12426 tg cnt e c char c1 c2 ntable tbl rtn
12427 ov-start ov-end ov-prefix
12428 (exit-after-next org-fast-tag-selection-single-key)
12429 (done-keywords org-done-keywords)
12432 (beginning-of-line 1)
12434 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12435 (setq ov-start (match-beginning 1)
12436 ov-end (match-end 1)
12438 (setq ov-start (1- (point-at-eol))
12439 ov-end (1+ ov-start))
12440 (skip-chars-forward "^\n\r")
12443 (buffer-substring (1- (point)) (point))
12444 (if (> (current-column) org-tags-column)
12446 (make-string (- org-tags-column (current-column)) ?\ ))))))
12447 (move-overlay org-tags-overlay ov-start ov-end)
12448 (save-window-excursion
12450 (set-buffer (get-buffer-create " *Org tags*"))
12451 (delete-other-windows)
12452 (split-window-vertically)
12453 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12455 (org-set-local 'org-done-keywords done-keywords)
12456 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12457 (org-fast-tag-insert "Current" current c-face "\n\n")
12458 (org-fast-tag-show-exit exit-after-next)
12459 (org-set-current-tags-overlay current ov-prefix)
12460 (setq tbl fulltable char ?a cnt 0)
12461 (while (setq e (pop tbl))
12463 ((equal (car e) :startgroup)
12464 (push '() groups) (setq ingroup t)
12465 (when (not (= cnt 0))
12468 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12469 ((equal (car e) :endgroup)
12470 (setq ingroup nil cnt 0)
12471 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12472 ((equal e '(:newline))
12473 (when (not (= cnt 0))
12477 (while (equal (car tbl) '(:newline))
12479 (setq tbl (cdr tbl)))))
12481 (setq tg (copy-sequence (car e)) c2 nil)
12484 ;; automatically assign a character.
12485 (setq c1 (string-to-char
12486 (downcase (substring
12487 tg (if (= (string-to-char tg) ?@) 1 0)))))
12488 (if (or (rassoc c1 ntable) (rassoc c1 table))
12489 (while (or (rassoc char ntable) (rassoc char table))
12490 (setq char (1+ char)))
12492 (setq c (or c2 char)))
12493 (if ingroup (push tg (car groups)))
12494 (setq tg (org-add-props tg nil 'face
12496 ((not (assoc tg table))
12497 (org-get-todo-face tg))
12498 ((member tg current) c-face)
12499 ((member tg inherited) i-face)
12501 (if (and (= cnt 0) (not ingroup)) (insert " "))
12502 (insert "[" c "] " tg (make-string
12503 (- fwidth 4 (length tg)) ?\ ))
12504 (push (cons tg c) ntable)
12505 (when (= (setq cnt (1+ cnt)) ncol)
12507 (if ingroup (insert " "))
12509 (setq ntable (nreverse ntable))
12511 (goto-char (point-min))
12512 (if (not expert) (org-fit-window-to-buffer))
12516 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12517 (if (not groups) "no " "")
12518 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12519 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12520 (setq org-last-tag-selection-key c)
12522 ((= c ?\r) (throw 'exit t))
12524 (setq groups (not groups))
12525 (goto-char (point-min))
12526 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12529 (org-fast-tag-show-exit
12530 (setq exit-after-next (not exit-after-next)))
12532 (delete-other-windows)
12533 (split-window-vertically)
12534 (org-switch-to-buffer-other-window " *Org tags*")
12535 (org-fit-window-to-buffer)))
12537 (and (= c ?q) (not (rassoc c ntable))))
12538 (org-detach-overlay org-tags-overlay)
12539 (setq quit-flag t))
12542 (if exit-after-next (setq exit-after-next 'now)))
12544 (condition-case nil
12545 (setq tg (org-icompleting-read
12548 (with-current-buffer buf
12549 (org-get-buffer-tags)))))
12550 (quit (setq tg "")))
12551 (when (string-match "\\S-" tg)
12552 (add-to-list 'buffer-tags (list tg))
12553 (if (member tg current)
12554 (setq current (delete tg current))
12555 (push tg current)))
12556 (if exit-after-next (setq exit-after-next 'now)))
12557 ((setq e (rassoc c todo-table) tg (car e))
12558 (with-current-buffer buf
12559 (save-excursion (org-todo tg)))
12560 (if exit-after-next (setq exit-after-next 'now)))
12561 ((setq e (rassoc c ntable) tg (car e))
12562 (if (member tg current)
12563 (setq current (delete tg current))
12564 (loop for g in groups do
12567 (setq current (delete x current)))
12570 (if exit-after-next (setq exit-after-next 'now))))
12572 ;; Create a sorted list
12576 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12577 (if (eq exit-after-next 'now) (throw 'exit t))
12578 (goto-char (point-min))
12579 (beginning-of-line 2)
12580 (delete-region (point) (point-at-eol))
12581 (org-fast-tag-insert "Current" current c-face)
12582 (org-set-current-tags-overlay current ov-prefix)
12583 (while (re-search-forward
12584 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12585 (setq tg (match-string 1))
12586 (add-text-properties
12587 (match-beginning 1) (match-end 1)
12590 ((member tg current) c-face)
12591 ((member tg inherited) i-face)
12592 (t (get-text-property (match-beginning 1) 'face))))))
12593 (goto-char (point-min)))))
12594 (org-detach-overlay org-tags-overlay)
12596 (mapconcat 'identity current ":")
12599 (defun org-get-tags-string ()
12600 "Get the TAGS string in the current headline."
12601 (unless (org-on-heading-p t)
12602 (error "Not on a heading"))
12604 (beginning-of-line 1)
12605 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12606 (org-match-string-no-properties 1)
12609 (defun org-get-tags ()
12610 "Get the list of tags specified in the current headline."
12611 (org-split-string (org-get-tags-string) ":"))
12613 (defun org-get-buffer-tags ()
12614 "Get a table of all tags used in the buffer, for completion."
12617 (goto-char (point-min))
12618 (while (re-search-forward
12619 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
12620 (when (equal (char-after (point-at-bol 0)) ?*)
12621 (mapc (lambda (x) (add-to-list 'tags x))
12622 (org-split-string (org-match-string-no-properties 1) ":")))))
12623 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
12624 (mapcar 'list tags)))
12626 ;;;; The mapping API
12629 (defun org-map-entries (func &optional match scope &rest skip)
12630 "Call FUNC at each headline selected by MATCH in SCOPE.
12632 FUNC is a function or a lisp form. The function will be called without
12633 arguments, with the cursor positioned at the beginning of the headline.
12634 The return values of all calls to the function will be collected and
12635 returned as a list.
12637 The call to FUNC will be wrapped into a save-excursion form, so FUNC
12638 does not need to preserve point. After evaluation, the cursor will be
12639 moved to the end of the line (presumably of the headline of the
12640 processed entry) and search continues from there. Under some
12641 circumstances, this may not produce the wanted results. For example,
12642 if you have removed (e.g. archived) the current (sub)tree it could
12643 mean that the next entry will be skipped entirely. In such cases, you
12644 can specify the position from where search should continue by making
12645 FUNC set the variable `org-map-continue-from' to the desired buffer
12648 MATCH is a tags/property/todo match as it is used in the agenda tags view.
12649 Only headlines that are matched by this query will be considered during
12650 the iteration. When MATCH is nil or t, all headlines will be
12651 visited by the iteration.
12653 SCOPE determines the scope of this command. It can be any of:
12655 nil The current buffer, respecting the restriction if any
12656 tree The subtree started with the entry at point
12657 file The current buffer, without restriction
12659 The current buffer, and any archives associated with it
12660 agenda All agenda files
12661 agenda-with-archives
12662 All agenda files with any archive files associated with them
12664 If this is a list, all files in the list will be scanned
12666 The remaining args are treated as settings for the skipping facilities of
12667 the scanner. The following items can be given here:
12669 archive skip trees with the archive tag.
12670 comment skip trees with the COMMENT keyword
12671 function or Emacs Lisp form:
12672 will be used as value for `org-agenda-skip-function', so whenever
12673 the function returns t, FUNC will not be called for that
12674 entry and search will continue from the point where the
12675 function leaves it.
12677 If your function needs to retrieve the tags including inherited tags
12678 at the *current* entry, you can use the value of the variable
12679 `org-scanner-tags' which will be much faster than getting the value
12680 with `org-get-tags-at'. If your function gets properties with
12681 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
12682 to t around the call to `org-entry-properties' to get the same speedup.
12683 Note that if your function moves around to retrieve tags and properties at
12684 a *different* entry, you cannot use these techniques."
12685 (let* ((org-agenda-archives-mode nil) ; just to make sure
12686 (org-agenda-skip-archived-trees (memq 'archive skip))
12687 (org-agenda-skip-comment-trees (memq 'comment skip))
12688 (org-agenda-skip-function
12689 (car (org-delete-all '(comment archive) skip)))
12690 (org-tags-match-list-sublevels t)
12692 org-todo-keywords-for-agenda
12693 org-done-keywords-for-agenda
12694 org-todo-keyword-alist-for-agenda
12695 org-drawers-for-agenda
12696 org-tag-alist-for-agenda)
12699 ((eq match t) (setq matcher t))
12700 ((eq match nil) (setq matcher t))
12701 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
12705 (when (eq scope 'tree)
12706 (org-back-to-heading t)
12707 (org-narrow-to-subtree)
12712 (org-prepare-agenda-buffers
12713 (list (buffer-file-name (current-buffer))))
12714 (setq res (org-scan-tags func matcher)))
12715 ;; Get the right scope
12717 ((and scope (listp scope) (symbolp (car scope)))
12718 (setq scope (eval scope)))
12719 ((eq scope 'agenda)
12720 (setq scope (org-agenda-files t)))
12721 ((eq scope 'agenda-with-archives)
12722 (setq scope (org-agenda-files t))
12723 (setq scope (org-add-archive-files scope)))
12725 (setq scope (list (buffer-file-name))))
12726 ((eq scope 'file-with-archives)
12727 (setq scope (org-add-archive-files (list (buffer-file-name))))))
12728 (org-prepare-agenda-buffers scope)
12729 (while (setq file (pop scope))
12730 (with-current-buffer (org-find-base-buffer-visiting file)
12734 (goto-char (point-min))
12735 (setq res (append res (org-scan-tags func matcher))))))))))
12740 ;;; Setting and retrieving properties
12742 (defconst org-special-properties
12743 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
12744 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
12745 "The special properties valid in Org-mode.
12747 These are properties that are not defined in the property drawer,
12748 but in some other way.")
12750 (defconst org-default-properties
12751 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
12752 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
12753 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
12754 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
12755 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
12756 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
12757 "Some properties that are used by Org-mode for various purposes.
12758 Being in this list makes sure that they are offered for completion.")
12760 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
12761 "Regular expression matching the first line of a property drawer.")
12763 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
12764 "Regular expression matching the last line of a property drawer.")
12766 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
12767 "Regular expression matching the first line of a property drawer.")
12769 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
12770 "Regular expression matching the first line of a property drawer.")
12772 (defconst org-property-drawer-re
12773 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
12774 org-property-end-re "\\)\n?")
12775 "Matches an entire property drawer.")
12777 (defconst org-clock-drawer-re
12778 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
12779 org-property-end-re "\\)\n?")
12780 "Matches an entire clock drawer.")
12782 (defun org-property-action ()
12783 "Do an action on properties."
12786 (org-at-property-p)
12787 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
12788 (setq c (read-char-exclusive))
12791 (call-interactively 'org-set-property))
12793 (call-interactively 'org-delete-property))
12795 (call-interactively 'org-delete-property-globally))
12797 (call-interactively 'org-compute-property-at-point))
12798 (t (error "No such property action %c" c)))))
12800 (defun org-set-effort (&optional value)
12801 "Set the effort property of the current entry.
12802 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
12805 (if (equal value 0) (setq value 10))
12806 (let* ((completion-ignore-case t)
12807 (prop org-effort-property)
12808 (cur (org-entry-get nil prop))
12809 (allowed (org-property-get-allowed-values nil prop 'table))
12810 (existing (mapcar 'list (org-property-values prop)))
12813 ((stringp value) value)
12814 ((and allowed (integerp value))
12815 (or (car (nth (1- value) allowed))
12816 (car (org-last allowed))))
12818 (message "Select 1-9,0, [RET%s]: %s"
12819 (if cur (concat "=" cur) "")
12820 (mapconcat 'car allowed " "))
12821 (setq rpl (read-char-exclusive))
12822 (if (equal rpl ?\r)
12824 (setq rpl (- rpl ?0))
12825 (if (equal rpl 0) (setq rpl 10))
12826 (if (and (> rpl 0) (<= rpl (length allowed)))
12827 (car (nth (1- rpl) allowed))
12828 (org-completing-read "Effort: " allowed nil))))
12830 (let (org-completion-use-ido org-completion-use-iswitchb)
12831 (org-completing-read
12832 (concat "Effort " (if (and cur (string-match "\\S-" cur))
12833 (concat "[" cur "]") "")
12835 existing nil nil "" nil cur))))))
12836 (unless (equal (org-entry-get nil prop) val)
12837 (org-entry-put nil prop val))
12838 (message "%s is now %s" prop val)))
12840 (defun org-at-property-p ()
12841 "Is cursor inside a property drawer?"
12843 (beginning-of-line 1)
12844 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
12845 (let ((match (match-data)) ;; Keep match-data for use by calling
12846 (p (point)) ;; procedures.
12847 (range (unless (org-before-first-heading-p)
12848 (org-get-property-block))))
12849 (prog1 (and range (<= (car range) p) (< p (cdr range)))
12850 (set-match-data match))))))
12852 (defun org-get-property-block (&optional beg end force)
12853 "Return the (beg . end) range of the body of the property drawer.
12854 BEG and END can be beginning and end of subtree, if not given
12855 they will be found.
12856 If the drawer does not exist and FORCE is non-nil, create the drawer."
12859 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
12860 (end (or end (progn (outline-next-heading) (point)))))
12862 (if (re-search-forward org-property-start-re end t)
12863 (setq beg (1+ (match-end 0)))
12866 (org-insert-property-drawer)
12867 (setq end (progn (outline-next-heading) (point))))
12870 (if (re-search-forward org-property-start-re end t)
12871 (setq beg (1+ (match-end 0)))))
12872 (if (re-search-forward org-property-end-re end t)
12873 (setq end (match-beginning 0))
12874 (or force (throw 'exit nil))
12877 (org-indent-line-function)
12878 (insert ":END:\n"))
12881 (defun org-entry-properties (&optional pom which specific)
12882 "Get all properties of the entry at point-or-marker POM.
12883 This includes the TODO keyword, the tags, time strings for deadline,
12884 scheduled, and clocking, and any additional properties defined in the
12885 entry. The return value is an alist, keys may occur multiple times
12886 if the property key was used several times.
12887 POM may also be nil, in which case the current entry is used.
12888 If WHICH is nil or `all', get all properties. If WHICH is
12889 `special' or `standard', only get that subclass. If WHICH
12890 is a string only get exactly this property. Specific can be a string, the
12891 specific property we are interested in. Specifying it can speed
12892 things up because then unnecessary parsing is avoided."
12893 (setq which (or which 'all))
12894 (org-with-point-at pom
12895 (let ((clockstr (substring org-clock-string 0 -1))
12896 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
12897 (case-fold-search nil)
12898 beg end range props sum-props key value string clocksum)
12900 (when (condition-case nil
12901 (and (org-mode-p) (org-back-to-heading t))
12904 (setq sum-props (get-text-property (point) 'org-summaries))
12905 (setq clocksum (get-text-property (point) :org-clock-minutes))
12906 (outline-next-heading)
12908 (when (memq which '(all special))
12909 ;; Get the special properties, like TODO and tags
12911 (when (and (or (not specific) (string= specific "TODO"))
12912 (looking-at org-todo-line-regexp) (match-end 2))
12913 (push (cons "TODO" (org-match-string-no-properties 2)) props))
12914 (when (and (or (not specific) (string= specific "PRIORITY"))
12915 (looking-at org-priority-regexp))
12916 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
12917 (when (and (or (not specific) (string= specific "TAGS"))
12918 (setq value (org-get-tags-string))
12919 (string-match "\\S-" value))
12920 (push (cons "TAGS" value) props))
12921 (when (and (or (not specific) (string= specific "ALLTAGS"))
12922 (setq value (org-get-tags-at)))
12923 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
12926 (when (or (not specific) (string= specific "BLOCKED"))
12927 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
12928 (when (or (not specific)
12929 (member specific org-all-time-keywords)
12930 (member specific '("TIMESTAMP" "TIMESTAMP_IA")))
12931 (while (re-search-forward org-maybe-keyword-time-regexp end t)
12932 (setq key (if (match-end 1) (substring (org-match-string-no-properties 1) 0 -1))
12933 string (if (equal key clockstr)
12937 (match-beginning 3) (goto-char (point-at-eol)))))
12938 (substring (org-match-string-no-properties 3) 1 -1)))
12940 (if (= (char-after (match-beginning 3)) ?\[)
12941 (setq key "TIMESTAMP_IA")
12942 (setq key "TIMESTAMP")))
12943 (when (or (equal key clockstr) (not (assoc key props)))
12944 (push (cons key string) props))))
12948 (when (memq which '(all standard))
12949 ;; Get the standard properties, like :PROP: ...
12950 (setq range (org-get-property-block beg end))
12952 (goto-char (car range))
12953 (while (re-search-forward
12954 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
12956 (setq key (org-match-string-no-properties 1)
12957 value (org-trim (or (org-match-string-no-properties 2) "")))
12958 (unless (member key excluded)
12959 (push (cons key (or value "")) props)))))
12961 (push (cons "CLOCKSUM"
12962 (org-columns-number-to-string (/ (float clocksum) 60.)
12965 (unless (assoc "CATEGORY" props)
12966 (setq value (or (org-get-category)
12967 (progn (org-refresh-category-properties)
12968 (org-get-category))))
12969 (push (cons "CATEGORY" value) props))
12970 (append sum-props (nreverse props)))))))
12972 (defun org-entry-get (pom property &optional inherit)
12973 "Get value of PROPERTY for entry at point-or-marker POM.
12974 If INHERIT is non-nil and the entry does not have the property,
12975 then also check higher levels of the hierarchy.
12976 If INHERIT is the symbol `selective', use inheritance only if the setting
12977 in `org-use-property-inheritance' selects PROPERTY for inheritance.
12978 If the property is present but empty, the return value is the empty string.
12979 If the property is not present at all, nil is returned."
12980 (org-with-point-at pom
12981 (if (and inherit (if (eq inherit 'selective)
12982 (org-property-inherit-p property)
12984 (org-entry-get-with-inheritance property)
12985 (if (member property org-special-properties)
12986 ;; We need a special property. Use `org-entry-properties' to
12987 ;; retrieve it, but specify the wanted property
12988 (cdr (assoc property (org-entry-properties nil 'special property)))
12989 (let ((range (org-get-property-block)))
12991 (goto-char (car range))
12993 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
12995 ;; Found the property, return it.
12997 (org-match-string-no-properties 1)
13000 (defun org-property-or-variable-value (var &optional inherit)
13001 "Check if there is a property fixing the value of VAR.
13002 If yes, return this value. If not, return the current value of the variable."
13003 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
13004 (if (and prop (stringp prop) (string-match "\\S-" prop))
13006 (symbol-value var))))
13008 (defun org-entry-delete (pom property)
13009 "Delete the property PROPERTY from entry at point-or-marker POM."
13010 (org-with-point-at pom
13011 (if (member property org-special-properties)
13012 nil ; cannot delete these properties.
13013 (let ((range (org-get-property-block)))
13015 (goto-char (car range))
13017 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
13020 (delete-region (match-beginning 0) (1+ (point-at-eol)))
13024 ;; Multi-values properties are properties that contain multiple values
13025 ;; These values are assumed to be single words, separated by whitespace.
13026 (defun org-entry-add-to-multivalued-property (pom property value)
13027 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
13028 (let* ((old (org-entry-get pom property))
13029 (values (and old (org-split-string old "[ \t]"))))
13030 (setq value (org-entry-protect-space value))
13031 (unless (member value values)
13032 (setq values (cons value values))
13033 (org-entry-put pom property
13034 (mapconcat 'identity values " ")))))
13036 (defun org-entry-remove-from-multivalued-property (pom property value)
13037 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
13038 (let* ((old (org-entry-get pom property))
13039 (values (and old (org-split-string old "[ \t]"))))
13040 (setq value (org-entry-protect-space value))
13041 (when (member value values)
13042 (setq values (delete value values))
13043 (org-entry-put pom property
13044 (mapconcat 'identity values " ")))))
13046 (defun org-entry-member-in-multivalued-property (pom property value)
13047 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
13048 (let* ((old (org-entry-get pom property))
13049 (values (and old (org-split-string old "[ \t]"))))
13050 (setq value (org-entry-protect-space value))
13051 (member value values)))
13053 (defun org-entry-get-multivalued-property (pom property)
13054 "Return a list of values in a multivalued property."
13055 (let* ((value (org-entry-get pom property))
13056 (values (and value (org-split-string value "[ \t]"))))
13057 (mapcar 'org-entry-restore-space values)))
13059 (defun org-entry-put-multivalued-property (pom property &rest values)
13060 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13061 VALUES should be a list of strings. Spaces will be protected."
13062 (org-entry-put pom property
13063 (mapconcat 'org-entry-protect-space values " "))
13064 (let* ((value (org-entry-get pom property))
13065 (values (and value (org-split-string value "[ \t]"))))
13066 (mapcar 'org-entry-restore-space values)))
13068 (defun org-entry-protect-space (s)
13069 "Protect spaces and newline in string S."
13070 (while (string-match " " s)
13071 (setq s (replace-match "%20" t t s)))
13072 (while (string-match "\n" s)
13073 (setq s (replace-match "%0A" t t s)))
13076 (defun org-entry-restore-space (s)
13077 "Restore spaces and newline in string S."
13078 (while (string-match "%20" s)
13079 (setq s (replace-match " " t t s)))
13080 (while (string-match "%0A" s)
13081 (setq s (replace-match "\n" t t s)))
13084 (defvar org-entry-property-inherited-from (make-marker)
13085 "Marker pointing to the entry from where a property was inherited.
13086 Each call to `org-entry-get-with-inheritance' will set this marker to the
13087 location of the entry where the inheritance search matched. If there was
13088 no match, the marker will point nowhere.
13089 Note that also `org-entry-get' calls this function, if the INHERIT flag
13092 (defun org-entry-get-with-inheritance (property)
13093 "Get entry property, and search higher levels if not present."
13094 (move-marker org-entry-property-inherited-from nil)
13101 (when (setq tmp (org-entry-get nil property))
13102 (org-back-to-heading t)
13103 (move-marker org-entry-property-inherited-from (point))
13105 (or (org-up-heading-safe) (throw 'ex nil)))))
13107 (cdr (assoc property org-file-properties))
13108 (cdr (assoc property org-global-properties))
13109 (cdr (assoc property org-global-properties-fixed))))))
13111 (defvar org-property-changed-functions nil
13112 "Hook called when the value of a property has changed.
13113 Each hook function should accept two arguments, the name of the property
13114 and the new value.")
13116 (defun org-entry-put (pom property value)
13117 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13118 (org-with-point-at pom
13119 (org-back-to-heading t)
13120 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13123 ((equal property "TODO")
13124 (when (and (stringp value) (string-match "\\S-" value)
13125 (not (member value org-todo-keywords-1)))
13126 (error "\"%s\" is not a valid TODO state" value))
13127 (if (or (not value)
13128 (not (string-match "\\S-" value)))
13129 (setq value 'none))
13131 (org-set-tags nil 'align))
13132 ((equal property "PRIORITY")
13133 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13134 (string-to-char value) ?\ ))
13135 (org-set-tags nil 'align))
13136 ((equal property "SCHEDULED")
13137 (if (re-search-forward org-scheduled-time-regexp end t)
13139 ((eq value 'earlier) (org-timestamp-change -1 'day))
13140 ((eq value 'later) (org-timestamp-change 1 'day))
13141 (t (call-interactively 'org-schedule)))
13142 (call-interactively 'org-schedule)))
13143 ((equal property "DEADLINE")
13144 (if (re-search-forward org-deadline-time-regexp end t)
13146 ((eq value 'earlier) (org-timestamp-change -1 'day))
13147 ((eq value 'later) (org-timestamp-change 1 'day))
13148 (t (call-interactively 'org-deadline)))
13149 (call-interactively 'org-deadline)))
13150 ((member property org-special-properties)
13151 (error "The %s property can not yet be set with `org-entry-put'"
13153 (t ; a non-special property
13154 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13155 (setq range (org-get-property-block beg end 'force))
13156 (goto-char (car range))
13157 (if (re-search-forward
13158 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13160 (delete-region (match-beginning 1) (match-end 1))
13161 (goto-char (match-beginning 1)))
13162 (goto-char (cdr range))
13165 (org-indent-line-function)
13166 (insert ":" property ":"))
13167 (and value (insert " " value))
13168 (org-indent-line-function)))))
13169 (run-hook-with-args 'org-property-changed-functions property value)))
13171 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13172 "Get all property keys in the current buffer.
13173 With INCLUDE-SPECIALS, also list the special properties that reflect things
13174 like tags and TODO state.
13175 With INCLUDE-DEFAULTS, also include properties that has special meaning
13176 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13177 With INCLUDE-COLUMNS, also include property names given in COLUMN
13178 formats in the current buffer."
13179 (let (rtn range cfmt s p)
13183 (goto-char (point-min))
13184 (while (re-search-forward org-property-start-re nil t)
13185 (setq range (org-get-property-block))
13186 (goto-char (car range))
13187 (while (re-search-forward
13188 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13190 (add-to-list 'rtn (org-match-string-no-properties 1)))
13191 (outline-next-heading))))
13193 (when include-specials
13194 (setq rtn (append org-special-properties rtn)))
13196 (when include-defaults
13197 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13198 (add-to-list 'rtn org-effort-property))
13200 (when include-columns
13204 (goto-char (point-min))
13205 (while (re-search-forward
13206 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13208 (setq cfmt (match-string 2) s 0)
13209 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13211 (setq s (match-end 0)
13212 p (match-string 1 cfmt))
13213 (unless (or (equal p "ITEM")
13214 (member p org-special-properties))
13215 (add-to-list 'rtn (match-string 1 cfmt))))))))
13217 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13219 (defun org-property-values (key)
13220 "Return a list of all values of property KEY."
13224 (goto-char (point-min))
13225 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13227 (while (re-search-forward re nil t)
13228 (add-to-list 'values (org-trim (match-string 1))))
13229 (delete "" values)))))
13231 (defun org-insert-property-drawer ()
13232 "Insert a property drawer into the current entry."
13234 (org-back-to-heading t)
13235 (looking-at outline-regexp)
13236 (let ((indent (if org-adapt-indentation
13237 (- (match-end 0)(match-beginning 0))
13240 (re (concat "^[ \t]*" org-keyword-time-regexp))
13242 (outline-next-heading)
13245 (while (re-search-forward re end t))
13246 (setq hiddenp (org-invisible-p))
13248 (and (equal (char-after) ?\n) (forward-char 1))
13249 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13250 (if (member (match-string 1) '("CLOCK:" ":END:"))
13251 ;; just skip this line
13252 (beginning-of-line 2)
13253 ;; Drawer start, find the end
13254 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13255 (beginning-of-line 1)))
13256 (org-skip-over-state-notes)
13257 (skip-chars-backward " \t\n\r")
13258 (if (eq (char-before) ?*) (forward-char 1))
13259 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13260 (beginning-of-line 0)
13261 (org-indent-to-column indent)
13262 (beginning-of-line 2)
13263 (org-indent-to-column indent)
13264 (beginning-of-line 0)
13267 (org-back-to-heading t)
13269 (org-flag-drawer t))))
13271 (defun org-set-property (property value)
13272 "In the current entry, set PROPERTY to VALUE.
13273 When called interactively, this will prompt for a property name, offering
13274 completion on existing and default properties. And then it will prompt
13275 for a value, offering completion either on allowed values (via an inherited
13276 xxx_ALL property) or on existing values in other instances of this property
13277 in the current file."
13279 (let* ((completion-ignore-case t)
13280 (keys (org-buffer-property-keys nil t t))
13281 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13282 (prop (if (member prop0 keys)
13284 (or (cdr (assoc (downcase prop0)
13285 (mapcar (lambda (x) (cons (downcase x) x))
13288 (cur (org-entry-get nil prop))
13289 (prompt (concat prop " value"
13290 (if (and cur (string-match "\\S-" cur))
13291 (concat " [" cur "]") "") ": "))
13292 (allowed (org-property-get-allowed-values nil prop 'table))
13293 (existing (mapcar 'list (org-property-values prop)))
13295 (org-completing-read prompt allowed nil
13296 (not (get-text-property 0 'org-unrestricted
13298 (let (org-completion-use-ido org-completion-use-iswitchb)
13299 (org-completing-read prompt existing nil nil "" nil cur)))))
13300 (list prop (if (equal val "") cur val))))
13301 (unless (equal (org-entry-get nil property) value)
13302 (org-entry-put nil property value)))
13304 (defun org-delete-property (property)
13305 "In the current entry, delete PROPERTY."
13307 (let* ((completion-ignore-case t)
13308 (prop (org-icompleting-read "Property: " (org-entry-properties nil 'standard))))
13310 (message "Property %s %s" property
13311 (if (org-entry-delete nil property)
13313 "was not present in the entry")))
13315 (defun org-delete-property-globally (property)
13316 "Remove PROPERTY globally, from all entries."
13318 (let* ((completion-ignore-case t)
13319 (prop (org-icompleting-read
13320 "Globally remove property: "
13321 (mapcar 'list (org-buffer-property-keys)))))
13326 (goto-char (point-min))
13328 (while (re-search-forward
13329 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13331 (setq cnt (1+ cnt))
13332 (replace-match ""))
13333 (message "Property \"%s\" removed from %d entries" property cnt)))))
13335 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13337 (defun org-compute-property-at-point ()
13338 "Compute the property at point.
13339 This looks for an enclosing column format, extracts the operator and
13340 then applies it to the property in the column format's scope."
13342 (unless (org-at-property-p)
13343 (error "Not at a property"))
13344 (let ((prop (org-match-string-no-properties 2)))
13345 (org-columns-get-format-and-top-level)
13346 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13347 (error "No operator defined for property %s" prop))
13348 (org-columns-compute prop)))
13350 (defvar org-property-allowed-value-functions nil
13351 "Hook for functions supplying allowed values for a specific property.
13352 The functions must take a single argument, the name of the property, and
13353 return a flat list of allowed values. If \":ETC\" is one of
13354 the values, this means that these values are intended as defaults for
13355 completion, but that other values should be allowed too.
13356 The functions must return nil if they are not responsible for this
13359 (defun org-property-get-allowed-values (pom property &optional table)
13360 "Get allowed values for the property PROPERTY.
13361 When TABLE is non-nil, return an alist that can directly be used for
13365 ((equal property "TODO")
13366 (setq vals (org-with-point-at pom
13367 (append org-todo-keywords-1 '("")))))
13368 ((equal property "PRIORITY")
13369 (let ((n org-lowest-priority))
13370 (while (>= n org-highest-priority)
13371 (push (char-to-string n) vals)
13373 ((member property org-special-properties))
13374 ((setq vals (run-hook-with-args-until-success
13375 'org-property-allowed-value-functions property)))
13377 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13378 (when (and vals (string-match "\\S-" vals))
13379 (setq vals (car (read-from-string (concat "(" vals ")"))))
13380 (setq vals (mapcar (lambda (x)
13381 (cond ((stringp x) x)
13382 ((numberp x) (number-to-string x))
13383 ((symbolp x) (symbol-name x))
13386 (when (member ":ETC" vals)
13387 (setq vals (remove ":ETC" vals))
13388 (org-add-props (car vals) '(org-unrestricted t)))
13389 (if table (mapcar 'list vals) vals)))
13391 (defun org-property-previous-allowed-value (&optional previous)
13392 "Switch to the next allowed value for this property."
13394 (org-property-next-allowed-value t))
13396 (defun org-property-next-allowed-value (&optional previous)
13397 "Switch to the next allowed value for this property."
13399 (unless (org-at-property-p)
13400 (error "Not at a property"))
13401 (let* ((key (match-string 2))
13402 (value (match-string 3))
13403 (allowed (or (org-property-get-allowed-values (point) key)
13404 (and (member value '("[ ]" "[-]" "[X]"))
13408 (error "Allowed values for this property have not been defined"))
13409 (if previous (setq allowed (reverse allowed)))
13410 (if (member value allowed)
13411 (setq nval (car (cdr (member value allowed)))))
13412 (setq nval (or nval (car allowed)))
13413 (if (equal nval value)
13414 (error "Only one allowed value for this property"))
13415 (org-at-property-p)
13416 (replace-match (concat " :" key ": " nval) t t)
13417 (org-indent-line-function)
13418 (beginning-of-line 1)
13419 (skip-chars-forward " \t")
13420 (run-hook-with-args 'org-property-changed-functions key nval)))
13422 (defun org-find-entry-with-id (ident)
13423 "Locate the entry that contains the ID property with exact value IDENT.
13424 IDENT can be a string, a symbol or a number, this function will search for
13425 the string representation of it.
13426 Return the position where this entry starts, or nil if there is no such entry."
13427 (interactive "sID: ")
13429 ((stringp ident) ident)
13430 ((symbol-name ident) (symbol-name ident))
13431 ((numberp ident) (number-to-string ident))
13432 (t (error "IDENT %s must be a string, symbol or number" ident))))
13433 (case-fold-search nil))
13437 (goto-char (point-min))
13438 (when (re-search-forward
13439 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13441 (org-back-to-heading t)
13446 (defvar org-last-changed-timestamp nil)
13447 (defvar org-last-inserted-timestamp nil
13448 "The last time stamp inserted with `org-insert-time-stamp'.")
13449 (defvar org-time-was-given) ; dynamically scoped parameter
13450 (defvar org-end-time-was-given) ; dynamically scoped parameter
13451 (defvar org-ts-what) ; dynamically scoped parameter
13453 (defun org-time-stamp (arg &optional inactive)
13454 "Prompt for a date/time and insert a time stamp.
13455 If the user specifies a time like HH:MM, or if this command is called
13456 with a prefix argument, the time stamp will contain date and time.
13457 Otherwise, only the date will be included. All parts of a date not
13458 specified by the user will be filled in from the current date/time.
13459 So if you press just return without typing anything, the time stamp
13460 will represent the current date/time. If there is already a timestamp
13461 at the cursor, it will be modified."
13465 ;; Default time is either today, or, when entering a range,
13466 ;; the range start.
13467 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13469 (re-search-backward
13470 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13471 (- (point) 20) t)))
13472 (apply 'encode-time (org-parse-time-string (match-string 1)))
13474 (default-input (and ts (org-get-compact-tod ts)))
13475 org-time-was-given org-end-time-was-given time)
13477 ((and (org-at-timestamp-p t)
13478 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13479 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13481 (setq time (let ((this-command this-command))
13482 (org-read-date arg 'totime nil nil
13483 default-time default-input)))
13484 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13485 ((org-at-timestamp-p t)
13486 (setq time (let ((this-command this-command))
13487 (org-read-date arg 'totime nil nil default-time default-input)))
13488 (when (org-at-timestamp-p t) ; just to get the match data
13489 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13491 (setq org-last-changed-timestamp
13492 (org-insert-time-stamp
13493 time (or org-time-was-given arg)
13494 inactive nil nil (list org-end-time-was-given))))
13495 (message "Timestamp updated"))
13497 (setq time (let ((this-command this-command))
13498 (org-read-date arg 'totime nil nil default-time default-input)))
13499 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13500 nil nil (list org-end-time-was-given))))))
13502 ;; FIXME: can we use this for something else, like computing time differences?
13503 (defun org-get-compact-tod (s)
13504 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13505 (let* ((t1 (match-string 1 s))
13506 (h1 (string-to-number (match-string 2 s)))
13507 (m1 (string-to-number (match-string 3 s)))
13508 (t2 (and (match-end 4) (match-string 5 s)))
13509 (h2 (and t2 (string-to-number (match-string 6 s))))
13510 (m2 (and t2 (string-to-number (match-string 7 s))))
13514 (setq dh (- h2 h1) dm (- m2 m1))
13515 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13516 (concat t1 "+" (number-to-string dh)
13517 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13519 (defun org-time-stamp-inactive (&optional arg)
13520 "Insert an inactive time stamp.
13521 An inactive time stamp is enclosed in square brackets instead of angle
13522 brackets. It is inactive in the sense that it does not trigger agenda entries,
13523 does not link to the calendar and cannot be changed with the S-cursor keys.
13524 So these are more for recording a certain time/date."
13526 (org-time-stamp arg 'inactive))
13528 (defvar org-date-ovl (make-overlay 1 1))
13529 (overlay-put org-date-ovl 'face 'org-warning)
13530 (org-detach-overlay org-date-ovl)
13532 (defvar org-ans1) ; dynamically scoped parameter
13533 (defvar org-ans2) ; dynamically scoped parameter
13535 (defvar org-plain-time-of-day-regexp) ; defined below
13537 (defvar org-overriding-default-time nil) ; dynamically scoped
13538 (defvar org-read-date-overlay nil)
13539 (defvar org-dcst nil) ; dynamically scoped
13540 (defvar org-read-date-history nil)
13541 (defvar org-read-date-final-answer nil)
13543 (defun org-read-date (&optional with-time to-time from-string prompt
13544 default-time default-input)
13545 "Read a date, possibly a time, and make things smooth for the user.
13546 The prompt will suggest to enter an ISO date, but you can also enter anything
13547 which will at least partially be understood by `parse-time-string'.
13548 Unrecognized parts of the date will default to the current day, month, year,
13549 hour and minute. If this command is called to replace a timestamp at point,
13550 of to enter the second timestamp of a range, the default time is taken from the
13551 existing stamp. For example,
13552 3-2-5 --> 2003-02-05
13553 feb 15 --> currentyear-02-15
13554 sep 12 9 --> 2009-09-12
13555 12:45 --> today 12:45
13556 22 sept 0:34 --> currentyear-09-22 0:34
13557 12 --> currentyear-currentmonth-12
13558 Fri --> nearest Friday (today or later)
13561 Furthermore you can specify a relative date by giving, as the *first* thing
13562 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
13563 change in days weeks, months, years.
13564 With a single plus or minus, the date is relative to today. With a double
13565 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
13566 +4d --> four days from today
13567 +4 --> same as above
13568 +2w --> two weeks from today
13569 ++5 --> five days from default date
13571 The function understands only English month and weekday abbreviations,
13572 but this can be configured with the variables `parse-time-months' and
13573 `parse-time-weekdays'.
13575 While prompting, a calendar is popped up - you can also select the
13576 date with the mouse (button 1). The calendar shows a period of three
13577 months. To scroll it to other months, use the keys `>' and `<'.
13578 If you don't like the calendar, turn it off with
13579 \(setq org-read-date-popup-calendar nil)
13581 With optional argument TO-TIME, the date will immediately be converted
13582 to an internal time.
13583 With an optional argument WITH-TIME, the prompt will suggest to also
13584 insert a time. Note that when WITH-TIME is not set, you can still
13585 enter a time, and this function will inform the calling routine about
13586 this change. The calling routine may then choose to change the format
13587 used to insert the time stamp into the buffer to include the time.
13588 With optional argument FROM-STRING, read from this string instead from
13589 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
13590 the time/date that is used for everything that is not specified by the
13592 (require 'parse-time)
13593 (let* ((org-time-stamp-rounding-minutes
13594 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
13595 (org-dcst org-display-custom-times)
13596 (ct (org-current-time))
13597 (def (or org-overriding-default-time default-time ct))
13598 (defdecode (decode-time def))
13600 (when (< (nth 2 defdecode) org-extend-today-until)
13601 (setcar (nthcdr 2 defdecode) -1)
13602 (setcar (nthcdr 1 defdecode) 59)
13603 (setq def (apply 'encode-time defdecode)
13604 defdecode (decode-time def)))))
13605 (calendar-frame-setup nil)
13606 (calendar-move-hook nil)
13607 (calendar-view-diary-initially-flag nil)
13608 (calendar-view-holidays-initially-flag nil)
13609 (timestr (format-time-string
13610 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
13611 (prompt (concat (if prompt (concat prompt " ") "")
13612 (format "Date+time [%s]: " timestr)))
13613 ans (org-ans0 "") org-ans1 org-ans2 final)
13616 (from-string (setq ans from-string))
13617 (org-read-date-popup-calendar
13619 (save-window-excursion
13621 (calendar-forward-day (- (time-to-days def)
13622 (calendar-absolute-from-gregorian
13623 (calendar-current-date))))
13624 (org-eval-in-calendar nil t)
13625 (let* ((old-map (current-local-map))
13626 (map (copy-keymap calendar-mode-map))
13627 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
13628 (org-defkey map (kbd "RET") 'org-calendar-select)
13629 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
13630 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
13631 (org-defkey minibuffer-local-map [(meta shift left)]
13632 (lambda () (interactive)
13633 (org-eval-in-calendar '(calendar-backward-month 1))))
13634 (org-defkey minibuffer-local-map [(meta shift right)]
13635 (lambda () (interactive)
13636 (org-eval-in-calendar '(calendar-forward-month 1))))
13637 (org-defkey minibuffer-local-map [(meta shift up)]
13638 (lambda () (interactive)
13639 (org-eval-in-calendar '(calendar-backward-year 1))))
13640 (org-defkey minibuffer-local-map [(meta shift down)]
13641 (lambda () (interactive)
13642 (org-eval-in-calendar '(calendar-forward-year 1))))
13643 (org-defkey minibuffer-local-map [?\e (shift left)]
13644 (lambda () (interactive)
13645 (org-eval-in-calendar '(calendar-backward-month 1))))
13646 (org-defkey minibuffer-local-map [?\e (shift right)]
13647 (lambda () (interactive)
13648 (org-eval-in-calendar '(calendar-forward-month 1))))
13649 (org-defkey minibuffer-local-map [?\e (shift up)]
13650 (lambda () (interactive)
13651 (org-eval-in-calendar '(calendar-backward-year 1))))
13652 (org-defkey minibuffer-local-map [?\e (shift down)]
13653 (lambda () (interactive)
13654 (org-eval-in-calendar '(calendar-forward-year 1))))
13655 (org-defkey minibuffer-local-map [(shift up)]
13656 (lambda () (interactive)
13657 (org-eval-in-calendar '(calendar-backward-week 1))))
13658 (org-defkey minibuffer-local-map [(shift down)]
13659 (lambda () (interactive)
13660 (org-eval-in-calendar '(calendar-forward-week 1))))
13661 (org-defkey minibuffer-local-map [(shift left)]
13662 (lambda () (interactive)
13663 (org-eval-in-calendar '(calendar-backward-day 1))))
13664 (org-defkey minibuffer-local-map [(shift right)]
13665 (lambda () (interactive)
13666 (org-eval-in-calendar '(calendar-forward-day 1))))
13667 (org-defkey minibuffer-local-map ">"
13668 (lambda () (interactive)
13669 (org-eval-in-calendar '(scroll-calendar-left 1))))
13670 (org-defkey minibuffer-local-map "<"
13671 (lambda () (interactive)
13672 (org-eval-in-calendar '(scroll-calendar-right 1))))
13673 (org-defkey minibuffer-local-map "\C-v"
13674 (lambda () (interactive)
13675 (org-eval-in-calendar
13676 '(calendar-scroll-left-three-months 1))))
13677 (org-defkey minibuffer-local-map "\M-v"
13678 (lambda () (interactive)
13679 (org-eval-in-calendar
13680 '(calendar-scroll-right-three-months 1))))
13681 (run-hooks 'org-read-date-minibuffer-setup-hook)
13684 (use-local-map map)
13685 (add-hook 'post-command-hook 'org-read-date-display)
13686 (setq org-ans0 (read-string prompt default-input
13687 'org-read-date-history nil))
13688 ;; org-ans0: from prompt
13689 ;; org-ans1: from mouse click
13690 ;; org-ans2: from calendar motion
13691 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
13692 (remove-hook 'post-command-hook 'org-read-date-display)
13693 (use-local-map old-map)
13694 (when org-read-date-overlay
13695 (delete-overlay org-read-date-overlay)
13696 (setq org-read-date-overlay nil)))))))
13698 (t ; Naked prompt only
13700 (setq ans (read-string prompt default-input
13701 'org-read-date-history timestr))
13702 (when org-read-date-overlay
13703 (delete-overlay org-read-date-overlay)
13704 (setq org-read-date-overlay nil)))))
13706 (setq final (org-read-date-analyze ans def defdecode))
13707 (setq org-read-date-final-answer ans)
13710 (apply 'encode-time final)
13711 (if (and (boundp 'org-time-was-given) org-time-was-given)
13712 (format "%04d-%02d-%02d %02d:%02d"
13713 (nth 5 final) (nth 4 final) (nth 3 final)
13714 (nth 2 final) (nth 1 final))
13715 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
13720 (defvar org-read-date-analyze-futurep nil)
13721 (defun org-read-date-display ()
13722 "Display the current date prompt interpretation in the minibuffer."
13723 (when org-read-date-display-live
13724 (when org-read-date-overlay
13725 (delete-overlay org-read-date-overlay))
13728 (while (not (equal (buffer-substring
13729 (max (point-min) (- (point) 4)) (point))
13733 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
13734 " " (or org-ans1 org-ans2)))
13735 (org-end-time-was-given nil)
13736 (f (org-read-date-analyze ans def defdecode))
13738 org-time-stamp-custom-formats
13739 org-time-stamp-formats))
13740 (fmt (if (or with-time
13741 (and (boundp 'org-time-was-given) org-time-was-given))
13744 (txt (concat "=> " (format-time-string fmt (apply 'encode-time f)))))
13745 (when (and org-end-time-was-given
13746 (string-match org-plain-time-of-day-regexp txt))
13747 (setq txt (concat (substring txt 0 (match-end 0)) "-"
13748 org-end-time-was-given
13749 (substring txt (match-end 0)))))
13750 (when org-read-date-analyze-futurep
13751 (setq txt (concat txt " (=>F)")))
13752 (setq org-read-date-overlay
13753 (make-overlay (1- (point-at-eol)) (point-at-eol)))
13754 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
13756 (defun org-read-date-analyze (ans def defdecode)
13757 "Analyse the combined answer of the date prompt."
13758 ;; FIXME: cleanup and comment
13759 (let ((nowdecode (decode-time (current-time)))
13760 delta deltan deltaw deltadef year month day
13761 hour minute second wday pm h2 m2 tl wday1
13762 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
13763 (setq org-read-date-analyze-futurep nil)
13764 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
13767 (when (setq delta (org-read-date-get-relative ans (current-time) def))
13768 (setq ans (replace-match "" t t ans)
13770 deltaw (nth 1 delta)
13771 deltadef (nth 2 delta)))
13773 ;; Check if there is an iso week date in there
13774 ;; If yes, store the info and postpone interpreting it until the rest
13775 ;; of the parsing is done
13776 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
13777 (setq iso-year (if (match-end 1)
13778 (org-small-year-to-year
13779 (string-to-number (match-string 1 ans))))
13780 iso-weekday (if (match-end 3)
13781 (string-to-number (match-string 3 ans)))
13782 iso-week (string-to-number (match-string 2 ans)))
13783 (setq ans (replace-match "" t t ans)))
13785 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
13786 (when (string-match
13787 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
13788 (setq year (if (match-end 2)
13789 (string-to-number (match-string 2 ans))
13790 (progn (setq kill-year t)
13791 (string-to-number (format-time-string "%Y"))))
13792 month (string-to-number (match-string 3 ans))
13793 day (string-to-number (match-string 4 ans)))
13794 (if (< year 100) (setq year (+ 2000 year)))
13795 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
13797 ;; Help matching american dates, like 5/30 or 5/30/7
13798 (when (string-match
13799 "^ *\\([0-3]?[0-9]\\)/\\([0-1]?[0-9]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
13800 (setq year (if (match-end 4)
13801 (string-to-number (match-string 4 ans))
13802 (progn (setq kill-year t)
13803 (string-to-number (format-time-string "%Y"))))
13804 month (string-to-number (match-string 1 ans))
13805 day (string-to-number (match-string 2 ans)))
13806 (if (< year 100) (setq year (+ 2000 year)))
13807 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
13809 ;; Help matching am/pm times, because `parse-time-string' does not do that.
13810 ;; If there is a time with am/pm, and *no* time without it, we convert
13811 ;; so that matching will be successful.
13812 (loop for i from 1 to 2 do ; twice, for end time as well
13813 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
13814 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
13815 (setq hour (string-to-number (match-string 1 ans))
13816 minute (if (match-end 3)
13817 (string-to-number (match-string 3 ans))
13820 (string-to-char (downcase (match-string 4 ans)))))
13821 (if (and (= hour 12) (not pm))
13823 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
13824 (setq ans (replace-match (format "%02d:%02d" hour minute)
13827 ;; Check if a time range is given as a duration
13828 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
13829 (setq hour (string-to-number (match-string 1 ans))
13830 h2 (+ hour (string-to-number (match-string 3 ans)))
13831 minute (string-to-number (match-string 2 ans))
13832 m2 (+ minute (if (match-end 5) (string-to-number
13833 (match-string 5 ans))0)))
13834 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
13835 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
13838 ;; Check if there is a time range
13839 (when (boundp 'org-end-time-was-given)
13840 (setq org-time-was-given nil)
13841 (when (and (string-match org-plain-time-of-day-regexp ans)
13843 (setq org-end-time-was-given (match-string 8 ans))
13844 (setq ans (concat (substring ans 0 (match-beginning 7))
13845 (substring ans (match-end 7))))))
13847 (setq tl (parse-time-string ans)
13848 day (or (nth 3 tl) (nth 3 defdecode))
13849 month (or (nth 4 tl)
13850 (if (and org-read-date-prefer-future
13851 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
13852 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
13853 (nth 4 defdecode)))
13854 year (or (and (not kill-year) (nth 5 tl))
13855 (if (and org-read-date-prefer-future
13856 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
13857 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
13858 (nth 5 defdecode)))
13859 hour (or (nth 2 tl) (nth 2 defdecode))
13860 minute (or (nth 1 tl) (nth 1 defdecode))
13861 second (or (nth 0 tl) 0)
13864 (when (and (eq org-read-date-prefer-future 'time)
13865 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
13866 (equal day (nth 3 nowdecode))
13867 (equal month (nth 4 nowdecode))
13868 (equal year (nth 5 nowdecode))
13870 (or (< (nth 2 tl) (nth 2 nowdecode))
13871 (and (= (nth 2 tl) (nth 2 nowdecode))
13873 (< (nth 1 tl) (nth 1 nowdecode)))))
13877 ;; Special date definitions below
13880 ;; There was an iso week
13883 (setq year (or iso-year year)
13884 day (or iso-weekday wday 1)
13885 wday nil ; to make sure that the trigger below does not match
13886 iso-date (calendar-gregorian-from-absolute
13887 (calendar-absolute-from-iso
13888 (list iso-week day year))))
13889 ; FIXME: Should we also push ISO weeks into the future?
13890 ; (when (and org-read-date-prefer-future
13892 ; (< (calendar-absolute-from-gregorian iso-date)
13893 ; (time-to-days (current-time))))
13894 ; (setq year (1+ year)
13895 ; iso-date (calendar-gregorian-from-absolute
13896 ; (calendar-absolute-from-iso
13897 ; (list iso-week day year)))))
13898 (setq month (car iso-date)
13899 year (nth 2 iso-date)
13900 day (nth 1 iso-date)))
13904 (let ((now (decode-time (current-time))))
13905 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
13906 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
13907 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
13908 ((equal deltaw "m") (setq month (+ month deltan)))
13909 ((equal deltaw "y") (setq year (+ year deltan)))))
13910 ((and wday (not (nth 3 tl)))
13912 ;; Weekday was given, but no day, so pick that day in the week
13913 ;; on or after the derived date.
13914 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
13915 (unless (equal wday wday1)
13916 (setq day (+ day (% (- wday wday1 -7) 7))))))
13917 (if (and (boundp 'org-time-was-given)
13919 (setq org-time-was-given t))
13920 (if (< year 100) (setq year (+ 2000 year)))
13921 (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
13922 (setq org-read-date-analyze-futurep futurep)
13923 (list second minute hour day month year)))
13925 (defvar parse-time-weekdays)
13927 (defun org-read-date-get-relative (s today default)
13928 "Check string S for special relative date string.
13929 TODAY and DEFAULT are internal times, for today and for a default.
13930 Return shift list (N what def-flag)
13931 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
13932 N is the number of WHATs to shift.
13933 DEF-FLAG is t when a double ++ or -- indicates shift relative to
13934 the DEFAULT date rather than TODAY."
13938 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
13940 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
13941 "\\([ \t]\\|$\\)") s)
13942 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
13943 (let* ((dir (if (> (match-end 1) (match-beginning 1))
13944 (string-to-char (substring (match-string 1 s) -1))
13946 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
13947 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
13948 (what (if (match-end 3) (match-string 3 s) "d"))
13949 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
13950 (date (if rel default today))
13951 (wday (nth 6 (decode-time date)))
13955 (setq delta (mod (+ 7 (- wday1 wday)) 7))
13956 (if (= dir ?-) (setq delta (- delta 7)))
13957 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
13958 (list delta "d" rel))
13959 (list (* n (if (= dir ?-) -1 1)) what rel)))))
13961 (defun org-order-calendar-date-args (arg1 arg2 arg3)
13962 "Turn a user-specified date into the internal representation.
13963 The internal representation needed by the calendar is (month day year).
13964 This is a wrapper to handle the brain-dead convention in calendar that
13965 user function argument order change dependent on argument order."
13966 (if (boundp 'calendar-date-style)
13968 ((eq calendar-date-style 'american)
13969 (list arg1 arg2 arg3))
13970 ((eq calendar-date-style 'european)
13971 (list arg2 arg1 arg3))
13972 ((eq calendar-date-style 'iso)
13973 (list arg2 arg3 arg1)))
13974 (if (org-bound-and-true-p european-calendar-style)
13975 (list arg2 arg1 arg3)
13976 (list arg1 arg2 arg3))))
13978 (defun org-eval-in-calendar (form &optional keepdate)
13979 "Eval FORM in the calendar window and return to current window.
13980 Also, store the cursor date in variable org-ans2."
13981 (let ((sf (selected-frame))
13982 (sw (selected-window)))
13983 (select-window (get-buffer-window "*Calendar*" t))
13985 (when (and (not keepdate) (calendar-cursor-to-date))
13986 (let* ((date (calendar-cursor-to-date))
13987 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
13988 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
13989 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
13991 (org-select-frame-set-input-focus sf)))
13993 (defun org-calendar-select ()
13994 "Return to `org-read-date' with the date currently selected.
13995 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
13997 (when (calendar-cursor-to-date)
13998 (let* ((date (calendar-cursor-to-date))
13999 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14000 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14001 (if (active-minibuffer-window) (exit-minibuffer))))
14003 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
14004 "Insert a date stamp for the date given by the internal TIME.
14005 WITH-HM means use the stamp format that includes the time of the day.
14006 INACTIVE means use square brackets instead of angular ones, so that the
14007 stamp will not contribute to the agenda.
14008 PRE and POST are optional strings to be inserted before and after the
14010 The command returns the inserted time stamp."
14011 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
14013 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
14014 (insert-before-markers (or pre ""))
14015 (insert-before-markers (setq stamp (format-time-string fmt time)))
14016 (when (listp extra)
14017 (setq extra (car extra))
14018 (if (and (stringp extra)
14019 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
14020 (setq extra (format "-%02d:%02d"
14021 (string-to-number (match-string 1 extra))
14022 (string-to-number (match-string 2 extra))))
14026 (insert-before-markers extra)
14028 (insert-before-markers (or post ""))
14029 (setq org-last-inserted-timestamp stamp)))
14031 (defun org-toggle-time-stamp-overlays ()
14032 "Toggle the use of custom time stamp formats."
14034 (setq org-display-custom-times (not org-display-custom-times))
14035 (unless org-display-custom-times
14036 (let ((p (point-min)) (bmp (buffer-modified-p)))
14037 (while (setq p (next-single-property-change p 'display))
14038 (if (and (get-text-property p 'display)
14039 (eq (get-text-property p 'face) 'org-date))
14040 (remove-text-properties
14041 p (setq p (next-single-property-change p 'display))
14043 (set-buffer-modified-p bmp)))
14044 (if (featurep 'xemacs)
14045 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
14046 (org-restart-font-lock)
14047 (setq org-table-may-need-update t)
14048 (if org-display-custom-times
14049 (message "Time stamps are overlayed with custom format")
14050 (message "Time stamp overlays removed")))
14052 (defun org-display-custom-time (beg end)
14053 "Overlay modified time stamp format over timestamp between BEG and END."
14054 (let* ((ts (buffer-substring beg end))
14055 t1 w1 with-hm tf time str w2 (off 0))
14057 (setq t1 (org-parse-time-string ts t))
14058 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
14059 (setq off (- (match-end 0) (match-beginning 0)))))
14060 (setq end (- end off))
14061 (setq w1 (- end beg)
14062 with-hm (and (nth 1 t1) (nth 2 t1))
14063 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
14064 time (org-fix-decoded-time t1)
14066 (format-time-string
14067 (substring tf 1 -1) (apply 'encode-time time))
14068 nil 'mouse-face 'highlight)
14070 (if (not (= w2 w1))
14071 (add-text-properties (1+ beg) (+ 2 beg)
14072 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
14073 (if (featurep 'xemacs)
14075 (put-text-property beg end 'invisible t)
14076 (put-text-property beg end 'end-glyph (make-glyph str)))
14077 (put-text-property beg end 'display str))))
14079 (defun org-translate-time (string)
14080 "Translate all timestamps in STRING to custom format.
14081 But do this only if the variable `org-display-custom-times' is set."
14082 (when org-display-custom-times
14085 (re org-ts-regexp-both)
14086 t1 with-hm inactive tf time str beg end)
14087 (while (setq start (string-match re string start))
14088 (setq beg (match-beginning 0)
14090 t1 (save-match-data
14091 (org-parse-time-string (substring string beg end) t))
14092 with-hm (and (nth 1 t1) (nth 2 t1))
14093 inactive (equal (substring string beg (1+ beg)) "[")
14094 tf (funcall (if with-hm 'cdr 'car)
14095 org-time-stamp-custom-formats)
14096 time (org-fix-decoded-time t1)
14097 str (format-time-string
14099 (if inactive "[" "<") (substring tf 1 -1)
14100 (if inactive "]" ">"))
14101 (apply 'encode-time time))
14102 string (replace-match str t t string)
14103 start (+ start (length str)))))))
14106 (defun org-fix-decoded-time (time)
14107 "Set 0 instead of nil for the first 6 elements of time.
14108 Don't touch the rest."
14110 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
14112 (defun org-days-to-time (timestamp-string)
14113 "Difference between TIMESTAMP-STRING and now in days."
14114 (- (time-to-days (org-time-string-to-time timestamp-string))
14115 (time-to-days (current-time))))
14117 (defun org-deadline-close (timestamp-string &optional ndays)
14118 "Is the time in TIMESTAMP-STRING close to the current date?"
14119 (setq ndays (or ndays (org-get-wdays timestamp-string)))
14120 (and (< (org-days-to-time timestamp-string) ndays)
14121 (not (org-entry-is-done-p))))
14123 (defun org-get-wdays (ts)
14124 "Get the deadline lead time appropriate for timestring TS."
14126 ((<= org-deadline-warning-days 0)
14127 ;; 0 or negative, enforce this value no matter what
14128 (- org-deadline-warning-days))
14129 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
14130 ;; lead time is specified.
14131 (floor (* (string-to-number (match-string 1 ts))
14132 (cdr (assoc (match-string 2 ts)
14133 '(("d" . 1) ("w" . 7)
14134 ("m" . 30.4) ("y" . 365.25)))))))
14135 ;; go for the default.
14136 (t org-deadline-warning-days)))
14138 (defun org-calendar-select-mouse (ev)
14139 "Return to `org-read-date' with the date currently selected.
14140 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14142 (mouse-set-point ev)
14143 (when (calendar-cursor-to-date)
14144 (let* ((date (calendar-cursor-to-date))
14145 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14146 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14147 (if (active-minibuffer-window) (exit-minibuffer))))
14149 (defun org-check-deadlines (ndays)
14150 "Check if there are any deadlines due or past due.
14151 A deadline is considered due if it happens within `org-deadline-warning-days'
14152 days from today's date. If the deadline appears in an entry marked DONE,
14153 it is not shown. The prefix arg NDAYS can be used to test that many
14154 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14156 (let* ((org-warn-days
14158 ((equal ndays '(4)) 100000)
14159 (ndays (prefix-numeric-value ndays))
14160 (t (abs org-deadline-warning-days))))
14161 (case-fold-search nil)
14162 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
14164 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
14166 (message "%d deadlines past-due or due within %d days"
14167 (org-occur regexp nil callback)
14170 (defun org-check-before-date (date)
14171 "Check if there are deadlines or scheduled entries before DATE."
14172 (interactive (list (org-read-date)))
14173 (let ((case-fold-search nil)
14174 (regexp (concat "\\<\\(" org-deadline-string
14175 "\\|" org-scheduled-string
14176 "\\) *<\\([^>]+\\)>"))
14178 (lambda () (time-less-p
14179 (org-time-string-to-time (match-string 2))
14180 (org-time-string-to-time date)))))
14181 (message "%d entries before %s"
14182 (org-occur regexp nil callback) date)))
14184 (defun org-check-after-date (date)
14185 "Check if there are deadlines or scheduled entries after DATE."
14186 (interactive (list (org-read-date)))
14187 (let ((case-fold-search nil)
14188 (regexp (concat "\\<\\(" org-deadline-string
14189 "\\|" org-scheduled-string
14190 "\\) *<\\([^>]+\\)>"))
14194 (org-time-string-to-time (match-string 2))
14195 (org-time-string-to-time date))))))
14196 (message "%d entries after %s"
14197 (org-occur regexp nil callback) date)))
14199 (defun org-evaluate-time-range (&optional to-buffer)
14200 "Evaluate a time range by computing the difference between start and end.
14201 Normally the result is just printed in the echo area, but with prefix arg
14202 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14203 If the time range is actually in a table, the result is inserted into the
14205 For time difference computation, a year is assumed to be exactly 365
14206 days in order to avoid rounding problems."
14209 (org-clock-update-time-maybe)
14211 (unless (org-at-date-range-p t)
14212 (goto-char (point-at-bol))
14213 (re-search-forward org-tr-regexp-both (point-at-eol) t))
14214 (if (not (org-at-date-range-p t))
14215 (error "Not at a time-stamp range, and none found in current line")))
14216 (let* ((ts1 (match-string 1))
14217 (ts2 (match-string 2))
14218 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
14219 (match-end (match-end 0))
14220 (time1 (org-time-string-to-time ts1))
14221 (time2 (org-time-string-to-time ts2))
14222 (t1 (org-float-time time1))
14223 (t2 (org-float-time time2))
14224 (diff (abs (- t2 t1)))
14225 (negative (< (- t2 t1) 0))
14226 ;; (ys (floor (* 365 24 60 60)))
14229 (fy "%dy %dd %02d:%02d")
14231 (fd "%dd %02d:%02d")
14236 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14238 d (floor (/ diff ds)) diff (mod diff ds)
14239 h (floor (/ diff hs)) diff (mod diff hs)
14240 m (floor (/ diff 60)))
14241 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14243 d (floor (+ (/ diff ds) 0.5))
14245 (if (not to-buffer)
14246 (message "%s" (org-make-tdiff-string y d h m))
14247 (if (org-at-table-p)
14249 (goto-char match-end)
14251 (and (looking-at " *|") (goto-char (match-end 0))))
14252 (goto-char match-end))
14254 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14255 (replace-match ""))
14256 (if negative (insert " -"))
14257 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
14258 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
14259 (insert " " (format fh h m))))
14260 (if align (org-table-align))
14261 (message "Time difference inserted")))))
14263 (defun org-make-tdiff-string (y d h m)
14266 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
14268 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
14270 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
14272 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
14274 (apply 'format fmt (nreverse l))))
14276 (defun org-time-string-to-time (s)
14277 (apply 'encode-time (org-parse-time-string s)))
14278 (defun org-time-string-to-seconds (s)
14279 (org-float-time (org-time-string-to-time s)))
14281 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
14282 "Convert a time stamp to an absolute day number.
14283 If there is a specifyer for a cyclic time stamp, get the closest date to
14285 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14286 the variable date is bound by the calendar when this is called."
14288 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
14289 (if (org-diary-sexp-entry (match-string 1 s) "" date)
14292 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
14293 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
14294 (time-to-days (current-time))) (match-string 0 s)
14296 (t (time-to-days (apply 'encode-time (org-parse-time-string s))))))
14298 (defun org-days-to-iso-week (days)
14299 "Return the iso week number."
14301 (car (calendar-iso-from-absolute days)))
14303 (defun org-small-year-to-year (year)
14304 "Convert 2-digit years into 4-digit years.
14305 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14306 The year 2000 cannot be abbreviated. Any year larger than 99
14307 is returned unchanged."
14309 (setq year (+ 2000 year))
14311 (setq year (+ 1900 year))))
14314 (defun org-time-from-absolute (d)
14315 "Return the time corresponding to date D.
14316 D may be an absolute day number, or a calendar-type list (month day year)."
14317 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
14318 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
14320 (defun org-calendar-holiday ()
14321 "List of holidays, for Diary display in Org-mode."
14322 (require 'holidays)
14324 (if (fboundp 'calendar-check-holidays)
14325 'calendar-check-holidays 'check-calendar-holidays) date)))
14326 (if hl (mapconcat 'identity hl "; "))))
14328 (defun org-diary-sexp-entry (sexp entry date)
14329 "Process a SEXP diary ENTRY for DATE."
14330 (require 'diary-lib)
14331 (let ((result (if calendar-debug-sexp
14332 (let ((stack-trace-on-error t))
14333 (eval (car (read-from-string sexp))))
14334 (condition-case nil
14335 (eval (car (read-from-string sexp)))
14338 (message "Bad sexp at line %d in %s: %s"
14340 (buffer-file-name) sexp)
14342 (cond ((stringp result) result)
14343 ((and (consp result)
14344 (stringp (cdr result))) (cdr result))
14348 (defun org-diary-to-ical-string (frombuf)
14349 "Get iCalendar entries from diary entries in buffer FROMBUF.
14350 This uses the icalendar.el library."
14351 (let* ((tmpdir (if (featurep 'xemacs)
14353 temporary-file-directory))
14354 (tmpfile (make-temp-name
14355 (expand-file-name "orgics" tmpdir)))
14357 (with-current-buffer frombuf
14358 (icalendar-export-region (point-min) (point-max) tmpfile)
14359 (setq buf (find-buffer-visiting tmpfile))
14361 (goto-char (point-min))
14362 (if (re-search-forward "^BEGIN:VEVENT" nil t)
14363 (setq b (match-beginning 0)))
14364 (goto-char (point-max))
14365 (if (re-search-backward "^END:VEVENT" nil t)
14366 (setq e (match-end 0)))
14367 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
14369 (delete-file tmpfile)
14372 (defun org-closest-date (start current change prefer show-all)
14373 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14374 When PREFER is `past' return a date that is either CURRENT or past.
14375 When PREFER is `future', return a date that is either CURRENT or future.
14376 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14377 ;; Make the proper lists from the dates
14379 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
14380 dn dw sday cday n1 n2 n0
14381 d m y y1 y2 date1 date2 nmonths nm ny m2)
14383 (setq start (org-date-to-gregorian start)
14384 current (org-date-to-gregorian
14387 (time-to-days (current-time))))
14388 sday (calendar-absolute-from-gregorian start)
14389 cday (calendar-absolute-from-gregorian current))
14391 (if (<= cday sday) (throw 'exit sday))
14393 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
14394 (setq dn (string-to-number (match-string 1 change))
14395 dw (cdr (assoc (match-string 2 change) a1)))
14396 (error "Invalid change specifyer: %s" change))
14397 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
14400 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
14403 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
14404 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
14405 (setq date1 (list m d y1)
14406 n1 (calendar-absolute-from-gregorian date1)
14407 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
14408 n2 (calendar-absolute-from-gregorian date2)))
14410 ;; approx number of month between the two dates
14411 (setq nmonths (floor (/ (- cday sday) 30.436875)))
14412 ;; How often does dn fit in there?
14413 (setq d (nth 1 start) m (car start) y (nth 2 start)
14414 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
14416 ny (floor (/ m 12))
14419 (while (> m 12) (setq m (- m 12) y (1+ y)))
14420 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
14421 (setq m2 (+ m dn) y2 y)
14422 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14423 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
14424 (while (<= n2 cday)
14425 (setq n1 n2 m m2 y y2)
14426 (setq m2 (+ m dn) y2 y)
14427 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14428 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
14429 ;; Make sure n1 is the earlier date
14430 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
14433 ((eq prefer 'past) (if (= cday n2) n2 n1))
14434 ((eq prefer 'future) (if (= cday n1) n1 n2))
14435 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
14437 ((eq prefer 'past) (if (= cday n2) n2 n1))
14438 ((eq prefer 'future) (if (= cday n1) n1 n2))
14439 (t (if (= cday n1) n1 n2)))))))
14441 (defun org-date-to-gregorian (date)
14442 "Turn any specification of DATE into a gregorian date for the calendar."
14443 (cond ((integerp date) (calendar-gregorian-from-absolute date))
14444 ((and (listp date) (= (length date) 3)) date)
14446 (setq date (org-parse-time-string date))
14447 (list (nth 4 date) (nth 3 date) (nth 5 date)))
14449 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
14451 (defun org-parse-time-string (s &optional nodefault)
14452 "Parse the standard Org-mode time string.
14453 This should be a lot faster than the normal `parse-time-string'.
14454 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14455 hour and minute fields will be nil if not given."
14456 (if (string-match org-ts-regexp0 s)
14458 (if (or (match-beginning 8) (not nodefault))
14459 (string-to-number (or (match-string 8 s) "0")))
14460 (if (or (match-beginning 7) (not nodefault))
14461 (string-to-number (or (match-string 7 s) "0")))
14462 (string-to-number (match-string 4 s))
14463 (string-to-number (match-string 3 s))
14464 (string-to-number (match-string 2 s))
14466 (error "Not a standard Org-mode time string: %s" s)))
14468 (defun org-timestamp-up (&optional arg)
14469 "Increase the date item at the cursor by one.
14470 If the cursor is on the year, change the year. If it is on the month or
14471 the day, change that.
14472 With prefix ARG, change by that many units."
14474 (org-timestamp-change (prefix-numeric-value arg)))
14476 (defun org-timestamp-down (&optional arg)
14477 "Decrease the date item at the cursor by one.
14478 If the cursor is on the year, change the year. If it is on the month or
14479 the day, change that.
14480 With prefix ARG, change by that many units."
14482 (org-timestamp-change (- (prefix-numeric-value arg))))
14484 (defun org-timestamp-up-day (&optional arg)
14485 "Increase the date in the time stamp by one day.
14486 With prefix ARG, change that many days."
14488 (if (and (not (org-at-timestamp-p t))
14489 (org-on-heading-p))
14491 (org-timestamp-change (prefix-numeric-value arg) 'day)))
14493 (defun org-timestamp-down-day (&optional arg)
14494 "Decrease the date in the time stamp by one day.
14495 With prefix ARG, change that many days."
14497 (if (and (not (org-at-timestamp-p t))
14498 (org-on-heading-p))
14500 (org-timestamp-change (- (prefix-numeric-value arg)) 'day)))
14502 (defun org-at-timestamp-p (&optional inactive-ok)
14503 "Determine if the cursor is in or at a timestamp."
14505 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
14507 (ans (or (looking-at tsr)
14509 (skip-chars-backward "^[<\n\r\t")
14510 (if (> (point) (point-min)) (backward-char 1))
14511 (and (looking-at tsr)
14512 (> (- (match-end 0) pos) -1))))))
14514 (boundp 'org-ts-what)
14517 ((= pos (match-beginning 0)) 'bracket)
14518 ((= pos (1- (match-end 0))) 'bracket)
14519 ((org-pos-in-match-range pos 2) 'year)
14520 ((org-pos-in-match-range pos 3) 'month)
14521 ((org-pos-in-match-range pos 7) 'hour)
14522 ((org-pos-in-match-range pos 8) 'minute)
14523 ((or (org-pos-in-match-range pos 4)
14524 (org-pos-in-match-range pos 5)) 'day)
14525 ((and (> pos (or (match-end 8) (match-end 5)))
14526 (< pos (match-end 0)))
14527 (- pos (or (match-end 8) (match-end 5))))
14531 (defun org-toggle-timestamp-type ()
14532 "Toggle the type (<active> or [inactive]) of a time stamp."
14534 (when (org-at-timestamp-p t)
14535 (let ((beg (match-beginning 0)) (end (match-end 0))
14536 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
14539 (while (re-search-forward "[][<>]" end t)
14540 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
14542 (message "Timestamp is now %sactive"
14543 (if (equal (char-after beg) ?<) "" "in")))))
14545 (defun org-timestamp-change (n &optional what)
14546 "Change the date in the time stamp at point.
14547 The date will be changed by N times WHAT. WHAT can be `day', `month',
14548 `year', `minute', `second'. If WHAT is not given, the cursor position
14549 in the timestamp determines what will be changed."
14550 (let ((pos (point))
14552 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
14556 (if (not (org-at-timestamp-p t))
14557 (error "Not at a timestamp"))
14558 (if (and (not what) (eq org-ts-what 'bracket))
14559 (org-toggle-timestamp-type)
14560 (if (and (not what) (not (eq org-ts-what 'day))
14561 org-display-custom-times
14562 (get-text-property (point) 'display)
14563 (not (get-text-property (1- (point)) 'display)))
14564 (setq org-ts-what 'day))
14565 (setq org-ts-what (or what org-ts-what)
14566 inactive (= (char-after (match-beginning 0)) ?\[)
14567 ts (match-string 0))
14570 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
14572 (setq extra (match-string 1 ts)))
14573 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
14575 (setq time0 (org-parse-time-string ts))
14576 (when (and (eq org-ts-what 'minute)
14577 (eq current-prefix-arg nil))
14578 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
14579 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
14580 (setcar (cdr time0) (+ (nth 1 time0)
14581 (if (> n 0) (- rem) (- dm rem))))))
14583 (encode-time (or (car time0) 0)
14584 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
14585 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
14586 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
14587 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
14588 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
14590 (when (and (member org-ts-what '(hour minute))
14592 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
14593 (setq extra (org-modify-ts-extra
14595 (if (eq org-ts-what 'hour) 2 5)
14597 (when (integerp org-ts-what)
14598 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
14599 (if (eq what 'calendar)
14600 (let ((cal-date (org-get-date-from-calendar)))
14601 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
14602 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
14603 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
14604 (setcar time0 (or (car time0) 0))
14605 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
14606 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
14607 (setq time (apply 'encode-time time0))))
14608 (setq org-last-changed-timestamp
14609 (org-insert-time-stamp time with-hm inactive nil nil extra))
14610 (org-clock-update-time-maybe)
14612 ;; Try to recenter the calendar window, if any
14613 (if (and org-calendar-follow-timestamp-change
14614 (get-buffer-window "*Calendar*" t)
14615 (memq org-ts-what '(day month year)))
14616 (org-recenter-calendar (time-to-days time))))))
14618 (defun org-modify-ts-extra (s pos n dm)
14619 "Change the different parts of the lead-time and repeat fields in timestamp."
14620 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
14622 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
14624 ((or (org-pos-in-match-range pos 2)
14625 (org-pos-in-match-range pos 3))
14626 (setq m (string-to-number (match-string 3 s))
14627 h (string-to-number (match-string 2 s)))
14628 (if (org-pos-in-match-range pos 2)
14630 (setq n (* dm (org-no-warnings (signum n))))
14631 (when (not (= 0 (setq rem (% m dm))))
14632 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
14634 (if (< m 0) (setq m (+ m 60) h (1- h)))
14635 (if (> m 59) (setq m (- m 60) h (1+ h)))
14636 (setq h (min 24 (max 0 h)))
14637 (setq ng 1 new (format "-%02d:%02d" h m)))
14638 ((org-pos-in-match-range pos 6)
14639 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
14640 ((org-pos-in-match-range pos 5)
14641 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
14643 ((org-pos-in-match-range pos 9)
14644 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
14645 ((org-pos-in-match-range pos 8)
14646 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
14650 (substring s 0 (match-beginning ng))
14652 (substring s (match-end ng))))))
14655 (defun org-recenter-calendar (date)
14656 "If the calendar is visible, recenter it to DATE."
14657 (let* ((win (selected-window))
14658 (cwin (get-buffer-window "*Calendar*" t))
14659 (calendar-move-hook nil))
14661 (select-window cwin)
14662 (calendar-goto-date (if (listp date) date
14663 (calendar-gregorian-from-absolute date)))
14664 (select-window win))))
14666 (defun org-goto-calendar (&optional arg)
14667 "Go to the Emacs calendar at the current date.
14668 If there is a time stamp in the current line, go to that date.
14669 A prefix ARG can be used to force the current date."
14671 (let ((tsr org-ts-regexp) diff
14672 (calendar-move-hook nil)
14673 (calendar-view-holidays-initially-flag nil)
14674 (calendar-view-diary-initially-flag nil))
14675 (if (or (org-at-timestamp-p)
14677 (beginning-of-line 1)
14678 (looking-at (concat ".*" tsr))))
14679 (let ((d1 (time-to-days (current-time)))
14681 (org-time-string-to-time (match-string 1)))))
14682 (setq diff (- d2 d1))))
14684 (calendar-goto-today)
14685 (if (and diff (not arg)) (calendar-forward-day diff))))
14687 (defun org-get-date-from-calendar ()
14688 "Return a list (month day year) of date at point in calendar."
14689 (with-current-buffer "*Calendar*"
14691 (calendar-cursor-to-date))))
14693 (defun org-date-from-calendar ()
14694 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
14695 If there is already a time stamp at the cursor position, update it."
14697 (if (org-at-timestamp-p t)
14698 (org-timestamp-change 0 'calendar)
14699 (let ((cal-date (org-get-date-from-calendar)))
14700 (org-insert-time-stamp
14701 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
14703 (defun org-minutes-to-hh:mm-string (m)
14704 "Compute H:MM from a number of minutes."
14705 (let ((h (/ m 60)))
14706 (setq m (- m (* 60 h)))
14707 (format org-time-clocksum-format h m)))
14709 (defun org-hh:mm-string-to-minutes (s)
14710 "Convert a string H:MM to a number of minutes.
14711 If the string is just a number, interpret it as minutes.
14712 In fact, the first hh:mm or number in the string will be taken,
14713 there can be extra stuff in the string.
14714 If no number is found, the return value is 0."
14716 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
14717 (+ (* (string-to-number (match-string 1 s)) 60)
14718 (string-to-number (match-string 2 s))))
14719 ((string-match "\\([0-9]+\\)" s)
14720 (string-to-number (match-string 1 s)))
14725 (defun org-save-all-org-buffers ()
14726 "Save all Org-mode buffers without user confirmation."
14728 (message "Saving all Org-mode buffers...")
14729 (save-some-buffers t 'org-mode-p)
14730 (when (featurep 'org-id) (org-id-locations-save))
14731 (message "Saving all Org-mode buffers... done"))
14733 (defun org-revert-all-org-buffers ()
14734 "Revert all Org-mode buffers.
14735 Prompt for confirmation when there are unsaved changes.
14736 Be sure you know what you are doing before letting this function
14737 overwrite your changes.
14739 This function is useful in a setup where one tracks org files
14740 with a version control system, to revert on one machine after pulling
14741 changes from another. I believe the procedure must be like this:
14743 1. M-x org-save-all-org-buffers
14744 2. Pull changes from the other machine, resolve conflicts
14745 3. M-x org-revert-all-org-buffers"
14747 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
14750 (save-window-excursion
14753 (when (and (with-current-buffer b (org-mode-p))
14754 (with-current-buffer b buffer-file-name))
14755 (switch-to-buffer b)
14756 (revert-buffer t 'no-confirm)))
14758 (when (and (featurep 'org-id) org-id-track-globally)
14759 (org-id-locations-load)))))
14764 (defun org-iswitchb (&optional arg)
14765 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
14766 With a prefix argument, restrict available to files.
14767 With two prefix arguments, restrict available buffers to agenda files."
14769 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
14770 ((equal arg '(16)) (org-buffer-list 'agenda))
14771 (t (org-buffer-list)))))
14773 (org-icompleting-read "Org buffer: "
14774 (mapcar 'list (mapcar 'buffer-name blist))
14778 (defalias 'org-ido-switchb 'org-iswitchb)
14780 (defun org-buffer-list (&optional predicate exclude-tmp)
14781 "Return a list of Org buffers.
14782 PREDICATE can be `export', `files' or `agenda'.
14784 export restrict the list to Export buffers.
14785 files restrict the list to buffers visiting Org files.
14786 agenda restrict the list to buffers visiting agenda files.
14788 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
14790 (agenda-files (and (eq predicate 'agenda)
14791 (mapcar 'file-truename (org-agenda-files t))))
14794 ((eq predicate 'files)
14795 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
14796 ((eq predicate 'export)
14797 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
14798 ((eq predicate 'agenda)
14800 (with-current-buffer b
14801 (and (eq major-mode 'org-mode)
14802 (setq bfn (buffer-file-name b))
14803 (member (file-truename bfn) agenda-files)))))
14804 (t (lambda (b) (with-current-buffer b
14805 (or (eq major-mode 'org-mode)
14806 (string-match "\*Org .*Export"
14807 (buffer-name b)))))))))
14811 (if (and (funcall filter b)
14812 (or (not exclude-tmp)
14813 (not (string-match "tmp" (buffer-name b)))))
14818 (defun org-agenda-files (&optional unrestricted archives)
14819 "Get the list of agenda files.
14820 Optional UNRESTRICTED means return the full list even if a restriction
14821 is currently in place.
14822 When ARCHIVES is t, include all archive files that are really being
14823 used by the agenda files. If ARCHIVE is `ifmode', do this only if
14824 `org-agenda-archives-mode' is t."
14827 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
14828 ((stringp org-agenda-files) (org-read-agenda-file-list))
14829 ((listp org-agenda-files) org-agenda-files)
14830 (t (error "Invalid value of `org-agenda-files'")))))
14831 (setq files (apply 'append
14832 (mapcar (lambda (f)
14833 (if (file-directory-p f)
14835 f t org-agenda-file-regexp)
14838 (when org-agenda-skip-unavailable-files
14839 (setq files (delq nil
14842 (and (file-readable-p file) file)))
14844 (when (or (eq archives t)
14845 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
14846 (setq files (org-add-archive-files files)))
14849 (defun org-edit-agenda-file-list ()
14850 "Edit the list of agenda files.
14851 Depending on setup, this either uses customize to edit the variable
14852 `org-agenda-files', or it visits the file that is holding the list. In the
14853 latter case, the buffer is set up in a way that saving it automatically kills
14854 the buffer and restores the previous window configuration."
14856 (if (stringp org-agenda-files)
14857 (let ((cw (current-window-configuration)))
14858 (find-file org-agenda-files)
14859 (org-set-local 'org-window-configuration cw)
14860 (org-add-hook 'after-save-hook
14862 (set-window-configuration
14863 (prog1 org-window-configuration
14864 (kill-buffer (current-buffer))))
14865 (org-install-agenda-files-menu)
14866 (message "New agenda file list installed"))
14868 (message "%s" (substitute-command-keys
14869 "Edit list and finish with \\[save-buffer]")))
14870 (customize-variable 'org-agenda-files)))
14872 (defun org-store-new-agenda-file-list (list)
14873 "Set new value for the agenda file list and save it correctly."
14874 (if (stringp org-agenda-files)
14875 (let ((fe (org-read-agenda-file-list t)) b u)
14876 (while (setq b (find-buffer-visiting org-agenda-files))
14878 (with-temp-file org-agenda-files
14881 (lambda (f) ;; Keep un-expanded entries.
14882 (if (setq u (assoc f fe))
14887 (let ((org-mode-hook nil) (org-inhibit-startup t)
14888 (org-insert-mode-line-in-empty-file nil))
14889 (setq org-agenda-files list)
14890 (customize-save-variable 'org-agenda-files org-agenda-files))))
14892 (defun org-read-agenda-file-list (&optional pair-with-expansion)
14893 "Read the list of agenda files from a file.
14894 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
14895 filenames, used by `org-store-new-agenda-file-list' to write back
14896 un-expanded file names."
14897 (when (file-directory-p org-agenda-files)
14898 (error "`org-agenda-files' cannot be a single directory"))
14899 (when (stringp org-agenda-files)
14901 (insert-file-contents org-agenda-files)
14904 (let ((e (expand-file-name (substitute-in-file-name f)
14906 (if pair-with-expansion
14909 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
14912 (defun org-cycle-agenda-files ()
14913 "Cycle through the files in `org-agenda-files'.
14914 If the current buffer visits an agenda file, find the next one in the list.
14915 If the current buffer does not, find the first agenda file."
14917 (let* ((fs (org-agenda-files t))
14918 (files (append fs (list (car fs))))
14919 (tcf (if buffer-file-name (file-truename buffer-file-name)))
14921 (unless files (error "No agenda files"))
14923 (while (setq file (pop files))
14924 (if (equal (file-truename file) tcf)
14926 (find-file (car files))
14928 (find-file (car fs)))
14929 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
14931 (defun org-agenda-file-to-front (&optional to-end)
14932 "Move/add the current file to the top of the agenda file list.
14933 If the file is not present in the list, it is added to the front. If it is
14934 present, it is moved there. With optional argument TO-END, add/move to the
14937 (let ((org-agenda-skip-unavailable-files nil)
14938 (file-alist (mapcar (lambda (x)
14939 (cons (file-truename x) x))
14940 (org-agenda-files t)))
14941 (ctf (file-truename buffer-file-name))
14943 (setq x (assoc ctf file-alist) had x)
14945 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
14947 (setq file-alist (append (delq x file-alist) (list x)))
14948 (setq file-alist (cons x (delq x file-alist))))
14949 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
14950 (org-install-agenda-files-menu)
14951 (message "File %s to %s of agenda file list"
14952 (if had "moved" "added") (if to-end "end" "front"))))
14954 (defun org-remove-file (&optional file)
14955 "Remove current file from the list of files in variable `org-agenda-files'.
14956 These are the files which are being checked for agenda entries.
14957 Optional argument FILE means use this file instead of the current."
14959 (let* ((org-agenda-skip-unavailable-files nil)
14960 (file (or file buffer-file-name))
14961 (true-file (file-truename file))
14962 (afile (abbreviate-file-name file))
14963 (files (delq nil (mapcar
14965 (if (equal true-file
14968 (org-agenda-files t)))))
14969 (if (not (= (length files) (length (org-agenda-files t))))
14971 (org-store-new-agenda-file-list files)
14972 (org-install-agenda-files-menu)
14973 (message "Removed file: %s" afile))
14974 (message "File was not in list: %s (not removed)" afile))))
14976 (defun org-file-menu-entry (file)
14977 (vector file (list 'find-file file) t))
14979 (defun org-check-agenda-file (file)
14980 "Make sure FILE exists. If not, ask user what to do."
14981 (when (not (file-exists-p file))
14982 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
14983 (abbreviate-file-name file))
14984 (let ((r (downcase (read-char-exclusive))))
14987 (org-remove-file file)
14988 (throw 'nextfile t))
14989 (t (error "Abort"))))))
14991 (defun org-get-agenda-file-buffer (file)
14992 "Get a buffer visiting FILE. If the buffer needs to be created, add
14993 it to the list of buffers which might be released later."
14994 (let ((buf (org-find-base-buffer-visiting file)))
14996 buf ; just return it
14997 ;; Make a new buffer and remember it
14998 (setq buf (find-file-noselect file))
14999 (if buf (push buf org-agenda-new-buffers))
15002 (defun org-release-buffers (blist)
15003 "Release all buffers in list, asking the user for confirmation when needed.
15004 When a buffer is unmodified, it is just killed. When modified, it is saved
15005 \(if the user agrees) and then killed."
15007 (while (setq buf (pop blist))
15008 (setq file (buffer-file-name buf))
15009 (when (and (buffer-modified-p buf)
15011 (y-or-n-p (format "Save file %s? " file)))
15012 (with-current-buffer buf (save-buffer)))
15013 (kill-buffer buf))))
15015 (defun org-prepare-agenda-buffers (files)
15016 "Create buffers for all agenda files, protect archived trees and comments."
15018 (let ((pa '(:org-archived t))
15019 (pc '(:org-comment t))
15020 (pall '(:org-archived t :org-comment t))
15021 (inhibit-read-only t)
15022 (rea (concat ":" org-archive-tag ":"))
15026 (while (setq file (pop files))
15030 (org-check-agenda-file file)
15031 (set-buffer (org-get-agenda-file-buffer file)))
15033 (setq bmp (buffer-modified-p))
15034 (org-refresh-category-properties)
15035 (setq org-todo-keywords-for-agenda
15036 (append org-todo-keywords-for-agenda org-todo-keywords-1))
15037 (setq org-done-keywords-for-agenda
15038 (append org-done-keywords-for-agenda org-done-keywords))
15039 (setq org-todo-keyword-alist-for-agenda
15040 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
15041 (setq org-drawers-for-agenda
15042 (append org-drawers-for-agenda org-drawers))
15043 (setq org-tag-alist-for-agenda
15044 (append org-tag-alist-for-agenda org-tag-alist))
15047 (remove-text-properties (point-min) (point-max) pall)
15048 (when org-agenda-skip-archived-trees
15049 (goto-char (point-min))
15050 (while (re-search-forward rea nil t)
15051 (if (org-on-heading-p t)
15052 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
15053 (goto-char (point-min))
15054 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
15055 (while (re-search-forward re nil t)
15056 (add-text-properties
15057 (match-beginning 0) (org-end-of-subtree t) pc)))
15058 (set-buffer-modified-p bmp)))))
15059 (setq org-todo-keywords-for-agenda
15060 (org-uniquify org-todo-keywords-for-agenda))
15061 (setq org-todo-keyword-alist-for-agenda
15062 (org-uniquify org-todo-keyword-alist-for-agenda)
15063 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
15065 ;;;; Embedded LaTeX
15067 (defvar org-cdlatex-mode-map (make-sparse-keymap)
15068 "Keymap for the minor `org-cdlatex-mode'.")
15070 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
15071 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
15072 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
15073 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
15074 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
15076 (defvar org-cdlatex-texmathp-advice-is-done nil
15077 "Flag remembering if we have applied the advice to texmathp already.")
15079 (define-minor-mode org-cdlatex-mode
15080 "Toggle the minor `org-cdlatex-mode'.
15081 This mode supports entering LaTeX environment and math in LaTeX fragments
15083 \\{org-cdlatex-mode-map}"
15085 (when org-cdlatex-mode (require 'cdlatex))
15086 (unless org-cdlatex-texmathp-advice-is-done
15087 (setq org-cdlatex-texmathp-advice-is-done t)
15088 (defadvice texmathp (around org-math-always-on activate)
15089 "Always return t in org-mode buffers.
15090 This is because we want to insert math symbols without dollars even outside
15091 the LaTeX math segments. If Orgmode thinks that point is actually inside
15092 an embedded LaTeX fragment, let texmathp do its job.
15093 \\[org-cdlatex-mode-map]"
15097 ((not (org-mode-p)) ad-do-it)
15098 ((eq this-command 'cdlatex-math-symbol)
15099 (setq ad-return-value t
15100 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
15102 (let ((p (org-inside-LaTeX-fragment-p)))
15103 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
15104 (setq ad-return-value t
15105 texmathp-why '("Org-mode embedded math" . 0))
15106 (if p ad-do-it)))))))))
15108 (defun turn-on-org-cdlatex ()
15109 "Unconditionally turn on `org-cdlatex-mode'."
15110 (org-cdlatex-mode 1))
15112 (defun org-inside-LaTeX-fragment-p ()
15113 "Test if point is inside a LaTeX fragment.
15114 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15115 sequence appearing also before point.
15116 Even though the matchers for math are configurable, this function assumes
15117 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15118 delimiters are skipped when they have been removed by customization.
15119 The return value is nil, or a cons cell with the delimiter and
15120 and the position of this delimiter.
15122 This function does a reasonably good job, but can locally be fooled by
15123 for example currency specifications. For example it will assume being in
15124 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15125 fragments that are properly closed, but during editing, we have to live
15126 with the uncertainty caused by missing closing delimiters. This function
15127 looks only before point, not after."
15129 (let ((pos (point))
15130 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
15132 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
15134 dd-on str (start 0) m re)
15137 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
15138 re (nth 1 (assoc "$" org-latex-regexps)))
15139 (while (string-match re str start)
15141 ((= (match-end 0) (length str))
15142 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
15143 ((= (match-end 0) (- (length str) 5))
15145 (t (setq start (match-end 0))))))
15146 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
15148 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
15149 (and (match-beginning 2) (throw 'exit nil))
15151 (while (re-search-backward "\\$\\$" lim t)
15152 (setq dd-on (not dd-on)))
15154 (if dd-on (cons "$$" m))))))
15156 (defun org-inside-latex-macro-p ()
15157 "Is point inside a LaTeX macro or its arguments?"
15160 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15164 (message "%s" (org-inside-latex-macro-p)))
15166 (defun org-try-cdlatex-tab ()
15167 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15168 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15169 - inside a LaTeX fragment, or
15170 - after the first word in a line, where an abbreviation expansion could
15171 insert a LaTeX environment."
15172 (when org-cdlatex-mode
15175 (skip-chars-backward "a-zA-Z0-9*")
15176 (skip-chars-backward " \t")
15179 ((org-inside-LaTeX-fragment-p)
15183 (defun org-cdlatex-underscore-caret (&optional arg)
15184 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15185 Revert to the normal definition outside of these fragments."
15187 (if (org-inside-LaTeX-fragment-p)
15188 (call-interactively 'cdlatex-sub-superscript)
15189 (let (org-cdlatex-mode)
15190 (call-interactively (key-binding (vector last-input-event))))))
15192 (defun org-cdlatex-math-modify (&optional arg)
15193 "Execute `cdlatex-math-modify' in LaTeX fragments.
15194 Revert to the normal definition outside of these fragments."
15196 (if (org-inside-LaTeX-fragment-p)
15197 (call-interactively 'cdlatex-math-modify)
15198 (let (org-cdlatex-mode)
15199 (call-interactively (key-binding (vector last-input-event))))))
15201 (defvar org-latex-fragment-image-overlays nil
15202 "List of overlays carrying the images of latex fragments.")
15203 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
15205 (defun org-remove-latex-fragment-image-overlays ()
15206 "Remove all overlays with LaTeX fragment images in current buffer."
15207 (mapc 'delete-overlay org-latex-fragment-image-overlays)
15208 (setq org-latex-fragment-image-overlays nil))
15210 (defun org-preview-latex-fragment (&optional subtree)
15211 "Preview the LaTeX fragment at point, or all locally or globally.
15212 If the cursor is in a LaTeX fragment, create the image and overlay
15213 it over the source code. If there is no fragment at point, display
15214 all fragments in the current text, from one headline to the next. With
15215 prefix SUBTREE, display all fragments in the current subtree. With a
15216 double prefix `C-u C-u', or when the cursor is before the first headline,
15217 display all fragments in the buffer.
15218 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15220 (org-remove-latex-fragment-image-overlays)
15223 (let (beg end at msg)
15225 ((or (equal subtree '(16))
15226 (not (save-excursion
15227 (re-search-backward (concat "^" outline-regexp) nil t))))
15228 (setq beg (point-min) end (point-max)
15229 msg "Creating images for buffer...%s"))
15230 ((equal subtree '(4))
15231 (org-back-to-heading)
15232 (setq beg (point) end (org-end-of-subtree t)
15233 msg "Creating images for subtree...%s"))
15235 (if (setq at (org-inside-LaTeX-fragment-p))
15236 (goto-char (max (point-min) (- (cdr at) 2)))
15237 (org-back-to-heading))
15238 (setq beg (point) end (progn (outline-next-heading) (point))
15239 msg (if at "Creating image...%s"
15240 "Creating images for entry...%s"))))
15242 (narrow-to-region beg end)
15245 (concat "ltxpng/" (file-name-sans-extension
15246 (file-name-nondirectory
15247 buffer-file-name)))
15248 default-directory 'overlays msg at 'forbuffer)
15249 (message msg "done. Use `C-c C-c' to remove images.")))))
15251 (defvar org-latex-regexps
15252 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
15253 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15254 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15255 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15256 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15257 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
15258 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
15259 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
15260 "Regular expressions for matching embedded LaTeX.")
15262 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer)
15263 "Replace LaTeX fragments with links to an image, and produce images.
15264 Some of the options can be changed using the variable
15265 `org-format-latex-options'."
15266 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
15267 (let* ((prefixnodir (file-name-nondirectory prefix))
15268 (absprefix (expand-file-name prefix dir))
15269 (todir (file-name-directory absprefix))
15270 (opt org-format-latex-options)
15271 (matchers (plist-get opt :matchers))
15272 (re-list org-latex-regexps)
15273 (org-format-latex-header-extra
15274 (plist-get (org-infile-export-plist) :latex-header-extra))
15275 (cnt 0) txt hash link beg end re e checkdir
15276 executables-checked
15277 m n block linkfile movefile ov)
15278 ;; Check the different regular expressions
15279 (while (setq e (pop re-list))
15280 (setq m (car e) re (nth 1 e) n (nth 2 e)
15281 block (if (nth 3 e) "\n\n" ""))
15282 (when (member m matchers)
15283 (goto-char (point-min))
15284 (while (re-search-forward re nil t)
15285 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
15286 (not (get-text-property (match-beginning n)
15289 (not (eq (get-char-property (match-beginning n)
15291 'org-latex-overlay))))
15292 (setq txt (match-string n)
15293 beg (match-beginning n) end (match-end n)
15295 (let (print-length print-level) ; make sure full list is printed
15296 (setq hash (sha1 (prin1-to-string
15297 (list org-format-latex-header
15298 org-format-latex-header-extra
15299 org-export-latex-default-packages-alist
15300 org-export-latex-packages-alist
15301 org-format-latex-options
15303 linkfile (format "%s_%s.png" prefix hash)
15304 movefile (format "%s_%s.png" absprefix hash)))
15305 (setq link (concat block "[[file:" linkfile "]]" block))
15306 (if msg (message msg cnt))
15308 (unless checkdir ; make sure the directory exists
15310 (or (file-directory-p todir) (make-directory todir)))
15312 (unless executables-checked
15313 (org-check-external-command
15314 "latex" "needed to convert LaTeX fragments to images")
15315 (org-check-external-command
15316 "dvipng" "needed to convert LaTeX fragments to images")
15317 (setq executables-checked t))
15319 (unless (file-exists-p movefile)
15320 (org-create-formula-image
15321 txt movefile opt forbuffer))
15325 (if (eq (overlay-get o 'org-overlay-type)
15326 'org-latex-overlay)
15327 (delete-overlay o)))
15328 (overlays-in beg end))
15329 (setq ov (make-overlay beg end))
15330 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
15331 (if (featurep 'xemacs)
15333 (overlay-put ov 'invisible t)
15336 (make-glyph (vector 'png :file movefile))))
15339 (list 'image :type 'png :file movefile :ascent 'center)))
15340 (push ov org-latex-fragment-image-overlays)
15342 (delete-region beg end)
15343 (insert (org-add-props link
15344 (list 'org-latex-src
15345 (replace-regexp-in-string "\"" "" txt)))))))))))
15347 ;; This function borrows from Ganesh Swami's latex2png.el
15348 (defun org-create-formula-image (string tofile options buffer)
15349 "This calls dvipng."
15350 (require 'org-latex)
15351 (let* ((tmpdir (if (featurep 'xemacs)
15353 temporary-file-directory))
15354 (texfilebase (make-temp-name
15355 (expand-file-name "orgtex" tmpdir)))
15356 (texfile (concat texfilebase ".tex"))
15357 (dvifile (concat texfilebase ".dvi"))
15358 (pngfile (concat texfilebase ".png"))
15359 (fnh (if (featurep 'xemacs)
15360 (font-height (get-face-font 'default))
15361 (face-attribute 'default :height nil)))
15362 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
15363 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
15364 (fg (or (plist-get options (if buffer :foreground :html-foreground))
15366 (bg (or (plist-get options (if buffer :background :html-background))
15368 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
15369 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
15370 (with-temp-file texfile
15371 (insert (org-splice-latex-header
15372 org-format-latex-header
15373 org-export-latex-default-packages-alist
15374 org-export-latex-packages-alist t
15375 org-format-latex-header-extra))
15376 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
15377 (require 'org-latex)
15378 (org-export-latex-fix-inputenc))
15379 (let ((dir default-directory))
15380 (condition-case nil
15383 (call-process "latex" nil nil nil texfile))
15386 (if (not (file-exists-p dvifile))
15387 (progn (message "Failed to create dvi file from %s" texfile) nil)
15388 (condition-case nil
15389 (call-process "dvipng" nil nil nil
15392 ;;"-x" scale "-y" scale
15397 (if (not (file-exists-p pngfile))
15398 (if org-format-latex-signal-error
15399 (error "Failed to create png file from %s" texfile)
15400 (message "Failed to create png file from %s" texfile)
15402 ;; Use the requested file name and clean up
15403 (copy-file pngfile tofile 'replace)
15404 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
15405 (delete-file (concat texfilebase e)))
15408 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
15409 "Fill a LaTeX header template TPL.
15410 In the template, the following place holders will be recognized:
15412 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15413 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15414 [PACKAGES] \\usepackage statements for PKG
15415 [NO-PACKAGES] do not include PKG
15416 [EXTRA] the string EXTRA
15417 [NO-EXTRA] do not include EXTRA
15419 For backward compatibility, if both the positive and the negative place
15420 holder is missing, the positive one (without the \"NO-\") will be
15421 assumed to be present at the end of the template.
15422 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15424 SNIPPETS-P indicates if this is run to create snippet images for HTML."
15425 (let (rpl (end ""))
15426 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
15427 (setq rpl (if (or (match-end 1) (not def-pkg))
15428 "" (org-latex-packages-to-string def-pkg snippets-p t))
15429 tpl (replace-match rpl t t tpl))
15430 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
15432 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
15433 (setq rpl (if (or (match-end 1) (not pkg))
15434 "" (org-latex-packages-to-string pkg snippets-p t))
15435 tpl (replace-match rpl t t tpl))
15438 (org-latex-packages-to-string pkg snippets-p)))))
15440 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
15441 (setq rpl (if (or (match-end 1) (not extra))
15442 "" (concat extra "\n"))
15443 tpl (replace-match rpl t t tpl))
15444 (if (and extra (string-match "\\S-" extra))
15445 (setq end (concat end "\n" extra))))
15447 (if (string-match "\\S-" end)
15448 (concat tpl "\n" end)
15451 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
15452 "Turn an alist of packages into a string with the \\usepackage macros."
15453 (setq pkg (mapconcat (lambda(p)
15456 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
15457 (format "%% Package %s omitted" (cadr p)))
15458 ((equal "" (car p))
15459 (format "\\usepackage{%s}" (cadr p)))
15461 (format "\\usepackage[%s]{%s}"
15462 (car p) (cadr p)))))
15465 (if newline (concat pkg "\n") pkg))
15467 (defun org-dvipng-color (attr)
15468 "Return an rgb color specification for dvipng."
15469 (apply 'format "rgb %s %s %s"
15470 (mapcar 'org-normalize-color
15471 (color-values (face-attribute 'default attr nil)))))
15473 (defun org-normalize-color (value)
15474 "Return string to be used as color value for an RGB component."
15475 (format "%g" (/ value 65535.0)))
15480 (defvar org-inline-image-overlays nil)
15481 (make-variable-buffer-local 'org-inline-image-overlays)
15483 (defun org-toggle-inline-images (&optional include-linked)
15484 "Toggle the display of inline images.
15485 INCLUDE-LINKED is passed to `org-display-inline-images'."
15487 (if org-inline-image-overlays
15489 (org-remove-inline-images)
15490 (message "Inline image display turned off"))
15491 (org-display-inline-images include-linked)
15492 (if org-inline-image-overlays
15493 (message "%d images displayed inline"
15494 (length org-inline-image-overlays))
15495 (message "No images to display inline"))))
15497 (defun org-display-inline-images (&optional include-linked)
15498 "Display inline images.
15499 Normally only links without a description part are inlined, because this
15500 is how it will work for export. When INCLUDE-LINKED is set, also links
15501 with a description part will be inlined."
15503 (org-remove-inline-images)
15504 (goto-char (point-min))
15505 (let ((re (concat "\\[\\[\\(file:\\|\\./\\)\\(~?" "[-+./_0-9a-zA-Z]+"
15506 (substring (org-image-file-name-regexp) 0 -2)
15507 "\\)\\]" (if include-linked "" "\\]")))
15509 (while (re-search-forward re nil t)
15510 (setq file (expand-file-name (match-string 2)))
15511 (when (file-exists-p file)
15512 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
15513 (overlay-put ov 'display (create-image file))
15514 (overlay-put ov 'face 'default)
15515 (push ov org-inline-image-overlays)))))
15517 (defun org-remove-inline-images ()
15518 "Remove inline display of images."
15520 (mapc 'delete-overlay org-inline-image-overlays)
15521 (setq org-inline-image-overlays nil))
15525 ;; Make `C-c C-x' a prefix key
15526 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
15528 ;; TAB key with modifiers
15529 (org-defkey org-mode-map "\C-i" 'org-cycle)
15530 (org-defkey org-mode-map [(tab)] 'org-cycle)
15531 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
15532 (org-defkey org-mode-map [(meta tab)] 'org-complete)
15533 (org-defkey org-mode-map "\M-\t" 'org-complete)
15534 (org-defkey org-mode-map "\M-\C-i" 'org-complete)
15535 ;; The following line is necessary under Suse GNU/Linux
15536 (unless (featurep 'xemacs)
15537 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
15538 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
15539 (define-key org-mode-map [backtab] 'org-shifttab)
15541 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
15542 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
15543 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
15545 ;; Cursor keys with modifiers
15546 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
15547 (org-defkey org-mode-map [(meta right)] 'org-metaright)
15548 (org-defkey org-mode-map [(meta up)] 'org-metaup)
15549 (org-defkey org-mode-map [(meta down)] 'org-metadown)
15551 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
15552 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
15553 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
15554 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
15556 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
15557 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
15558 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
15559 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
15561 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
15562 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
15564 ;;; Extra keys for tty access.
15565 ;; We only set them when really needed because otherwise the
15566 ;; menus don't show the simple keys
15568 (when (or org-use-extra-keys
15569 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
15570 (not window-system))
15571 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
15572 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
15573 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
15574 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
15575 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
15576 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
15577 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
15578 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
15579 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
15580 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
15581 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
15582 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
15583 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
15584 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
15585 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
15586 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
15587 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
15588 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
15589 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
15590 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
15591 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
15592 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
15593 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
15594 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
15595 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
15596 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
15597 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
15598 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
15600 ;; All the other keys
15602 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
15603 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
15604 (if (boundp 'narrow-map)
15605 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
15606 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
15607 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
15608 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
15609 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
15610 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
15611 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
15612 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
15613 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
15614 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
15615 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
15616 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
15617 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
15618 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
15619 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
15620 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
15621 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
15622 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
15623 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
15624 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
15625 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
15626 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
15627 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
15628 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
15629 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
15630 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
15631 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
15632 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
15633 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
15634 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
15635 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
15636 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
15637 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
15638 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
15639 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
15640 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
15641 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
15642 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
15643 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
15644 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
15645 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
15646 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
15647 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
15648 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
15649 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
15650 (org-defkey org-mode-map "\C-c^" 'org-sort)
15651 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
15652 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
15653 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
15654 (org-defkey org-mode-map "\C-m" 'org-return)
15655 (org-defkey org-mode-map "\C-j" 'org-return-indent)
15656 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
15657 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
15658 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
15659 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
15660 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
15661 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
15662 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
15663 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
15664 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
15665 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
15666 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
15667 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
15668 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
15669 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
15670 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
15671 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
15672 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
15673 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
15674 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
15675 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
15677 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
15678 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
15679 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
15680 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
15682 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
15683 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
15684 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
15685 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
15686 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
15687 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
15688 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
15689 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
15690 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
15691 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
15692 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
15693 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
15694 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
15695 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
15696 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
15697 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
15699 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
15700 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
15701 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
15702 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
15704 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
15706 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
15708 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
15709 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
15711 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
15714 (when (featurep 'xemacs)
15715 (org-defkey org-mode-map 'button3 'popup-mode-menu))
15718 (defconst org-speed-commands-default
15720 ("Outline Navigation")
15721 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
15722 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
15723 ("f" . (org-speed-move-safe 'org-forward-same-level))
15724 ("b" . (org-speed-move-safe 'org-backward-same-level))
15725 ("u" . (org-speed-move-safe 'outline-up-heading))
15727 ("g" . (org-refile t))
15728 ("Outline Visibility")
15730 ("C" . org-shifttab)
15731 (" " . org-display-outline-path)
15732 ("Outline Structure Editing")
15733 ("U" . org-shiftmetaup)
15734 ("D" . org-shiftmetadown)
15735 ("r" . org-metaright)
15736 ("l" . org-metaleft)
15737 ("R" . org-shiftmetaright)
15738 ("L" . org-shiftmetaleft)
15739 ("i" . (progn (forward-char 1) (call-interactively
15740 'org-insert-heading-respect-content)))
15743 ("a" . org-archive-subtree-default-with-confirmation)
15744 ("." . outline-mark-subtree)
15746 ("I" . org-clock-in)
15747 ("O" . org-clock-out)
15748 ("Meta Data Editing")
15750 ("0" . (org-priority ?\ ))
15751 ("1" . (org-priority ?A))
15752 ("2" . (org-priority ?B))
15753 ("3" . (org-priority ?C))
15754 (";" . org-set-tags-command)
15755 ("e" . org-set-effort)
15756 ("Agenda Views etc")
15758 ("/" . org-sparse-tree)
15760 ("o" . org-open-at-point)
15761 ("?" . org-speed-command-help)
15763 "The default speed commands.")
15765 (defun org-print-speed-command (e)
15766 (if (> (length (car e)) 1)
15771 (princ (make-string (length (car e)) ?-))
15775 (if (symbolp (cdr e))
15776 (princ (symbol-name (cdr e)))
15780 (defun org-speed-command-help ()
15781 "Show the available speed commands."
15783 (if (not org-use-speed-commands)
15784 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
15785 (with-output-to-temp-buffer "*Help*"
15786 (princ "User-defined Speed commands\n===========================\n")
15787 (mapc 'org-print-speed-command org-speed-commands-user)
15789 (princ "Built-in Speed commands\n=======================\n")
15790 (mapc 'org-print-speed-command org-speed-commands-default))
15791 (with-current-buffer "*Help*"
15792 (setq truncate-lines t))))
15794 (defun org-speed-move-safe (cmd)
15795 "Execute CMD, but make sure that the cursor always ends up in a headline.
15796 If not, return to the original position and throw an error."
15798 (let ((pos (point)))
15799 (call-interactively cmd)
15800 (unless (and (bolp) (org-on-heading-p))
15802 (error "Boundary reached while executing %s" cmd))))
15804 (defvar org-self-insert-command-undo-counter 0)
15806 (defvar org-table-auto-blank-field) ; defined in org-table.el
15807 (defvar org-speed-command nil)
15808 (defun org-self-insert-command (N)
15809 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
15810 If the cursor is in a table looking at whitespace, the whitespace is
15811 overwritten, and the table is not marked as requiring realignment."
15814 ((and org-use-speed-commands
15815 (or (and (bolp) (looking-at outline-regexp))
15816 (and (functionp org-use-speed-commands)
15817 (funcall org-use-speed-commands)))
15820 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
15821 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
15823 ((commandp org-speed-command)
15824 (setq this-command org-speed-command)
15825 (call-interactively org-speed-command))
15826 ((functionp org-speed-command)
15827 (funcall org-speed-command))
15828 ((and org-speed-command (listp org-speed-command))
15829 (eval org-speed-command))
15830 (t (let (org-use-speed-commands)
15831 (call-interactively 'org-self-insert-command)))))
15835 ;; check if we blank the field, and if that triggers align
15836 (and (featurep 'org-table) org-table-auto-blank-field
15837 (member last-command
15838 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
15839 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
15840 ;; got extra space, this field does not determine column width
15841 (let (org-table-may-need-update) (org-table-blank-field))
15842 ;; no extra space, this field may determine column width
15843 (org-table-blank-field)))
15846 (looking-at "[^|\n]* |"))
15847 (let (org-table-may-need-update)
15848 (goto-char (1- (match-end 0)))
15849 (delete-backward-char 1)
15850 (goto-char (match-beginning 0))
15851 (self-insert-command N)))
15853 (setq org-table-may-need-update t)
15854 (self-insert-command N)
15855 (org-fix-tags-on-the-fly)
15856 (if org-self-insert-cluster-for-undo
15857 (if (not (eq last-command 'org-self-insert-command))
15858 (setq org-self-insert-command-undo-counter 1)
15859 (if (>= org-self-insert-command-undo-counter 20)
15860 (setq org-self-insert-command-undo-counter 1)
15861 (and (> org-self-insert-command-undo-counter 0)
15863 (not (cadr buffer-undo-list)) ; remove nil entry
15864 (setcdr buffer-undo-list (cddr buffer-undo-list)))
15865 (setq org-self-insert-command-undo-counter
15866 (1+ org-self-insert-command-undo-counter))))))))
15868 (defun org-fix-tags-on-the-fly ()
15869 (when (and (equal (char-after (point-at-bol)) ?*)
15870 (org-on-heading-p))
15871 (org-align-tags-here org-tags-column)))
15873 (defun org-delete-backward-char (N)
15874 "Like `delete-backward-char', insert whitespace at field end in tables.
15875 When deleting backwards, in tables this function will insert whitespace in
15876 front of the next \"|\" separator, to keep the table aligned. The table will
15877 still be marked for re-alignment if the field did fill the entire column,
15878 because, in this case the deletion might narrow the column."
15880 (if (and (org-table-p)
15882 (string-match "|" (buffer-substring (point-at-bol) (point)))
15883 (looking-at ".*?|"))
15884 (let ((pos (point))
15885 (noalign (looking-at "[^|\n\r]* |"))
15886 (c org-table-may-need-update))
15887 (backward-delete-char N)
15888 (skip-chars-forward "^|")
15890 (goto-char (1- pos))
15891 ;; noalign: if there were two spaces at the end, this field
15892 ;; does not determine the width of the column.
15893 (if noalign (setq org-table-may-need-update c)))
15894 (backward-delete-char N)
15895 (org-fix-tags-on-the-fly)))
15897 (defun org-delete-char (N)
15898 "Like `delete-char', but insert whitespace at field end in tables.
15899 When deleting characters, in tables this function will insert whitespace in
15900 front of the next \"|\" separator, to keep the table aligned. The table will
15901 still be marked for re-alignment if the field did fill the entire column,
15902 because, in this case the deletion might narrow the column."
15904 (if (and (org-table-p)
15906 (not (= (char-after) ?|))
15908 (if (looking-at ".*?|")
15909 (let ((pos (point))
15910 (noalign (looking-at "[^|\n\r]* |"))
15911 (c org-table-may-need-update))
15912 (replace-match (concat
15913 (substring (match-string 0) 1 -1)
15916 ;; noalign: if there were two spaces at the end, this field
15917 ;; does not determine the width of the column.
15918 (if noalign (setq org-table-may-need-update c)))
15921 (org-fix-tags-on-the-fly)))
15923 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
15924 (put 'org-self-insert-command 'delete-selection t)
15925 (put 'orgtbl-self-insert-command 'delete-selection t)
15926 (put 'org-delete-char 'delete-selection 'supersede)
15927 (put 'org-delete-backward-char 'delete-selection 'supersede)
15928 (put 'org-yank 'delete-selection 'yank)
15930 ;; Make `flyspell-mode' delay after some commands
15931 (put 'org-self-insert-command 'flyspell-delayed t)
15932 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
15933 (put 'org-delete-char 'flyspell-delayed t)
15934 (put 'org-delete-backward-char 'flyspell-delayed t)
15936 ;; Make pabbrev-mode expand after org-mode commands
15937 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
15938 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
15940 ;; How to do this: Measure non-white length of current string
15941 ;; If equal to column width, we should realign.
15943 (defun org-remap (map &rest commands)
15944 "In MAP, remap the functions given in COMMANDS.
15945 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
15948 (setq old (pop commands) new (pop commands))
15949 (if (fboundp 'command-remapping)
15950 (org-defkey map (vector 'remap old) new)
15951 (substitute-key-definition old new map global-map)))))
15953 (when (eq org-enable-table-editor 'optimized)
15954 ;; If the user wants maximum table support, we need to hijack
15955 ;; some standard editing functions
15956 (org-remap org-mode-map
15957 'self-insert-command 'org-self-insert-command
15958 'delete-char 'org-delete-char
15959 'delete-backward-char 'org-delete-backward-char)
15960 (org-defkey org-mode-map "|" 'org-force-self-insert))
15962 (defvar org-ctrl-c-ctrl-c-hook nil
15963 "Hook for functions attaching themselves to `C-c C-c'.
15964 This can be used to add additional functionality to the C-c C-c key which
15965 executes context-dependent commands.
15966 Each function will be called with no arguments. The function must check
15967 if the context is appropriate for it to act. If yes, it should do its
15968 thing and then return a non-nil value. If the context is wrong,
15969 just do nothing and return nil.")
15971 (defvar org-tab-first-hook nil
15972 "Hook for functions to attach themselves to TAB.
15973 See `org-ctrl-c-ctrl-c-hook' for more information.
15974 This hook runs as the first action when TAB is pressed, even before
15975 `org-cycle' messes around with the `outline-regexp' to cater for
15976 inline tasks and plain list item folding.
15977 If any function in this hook returns t, any other actions that
15978 would have been caused by TAB (such as table field motion or visibility
15979 cycling) will not occur.")
15981 (defvar org-tab-after-check-for-table-hook nil
15982 "Hook for functions to attach themselves to TAB.
15983 See `org-ctrl-c-ctrl-c-hook' for more information.
15984 This hook runs after it has been established that the cursor is not in a
15985 table, but before checking if the cursor is in a headline or if global cycling
15987 If any function in this hook returns t, not other actions like visibility
15988 cycling will be done.")
15990 (defvar org-tab-after-check-for-cycling-hook nil
15991 "Hook for functions to attach themselves to TAB.
15992 See `org-ctrl-c-ctrl-c-hook' for more information.
15993 This hook runs after it has been established that not table field motion and
15994 not visibility should be done because of current context. This is probably
15995 the place where a package like yasnippets can hook in.")
15997 (defvar org-tab-before-tab-emulation-hook nil
15998 "Hook for functions to attach themselves to TAB.
15999 See `org-ctrl-c-ctrl-c-hook' for more information.
16000 This hook runs after every other options for TAB have been exhausted, but
16001 before indentation and \t insertion takes place.")
16003 (defvar org-metaleft-hook nil
16004 "Hook for functions attaching themselves to `M-left'.
16005 See `org-ctrl-c-ctrl-c-hook' for more information.")
16006 (defvar org-metaright-hook nil
16007 "Hook for functions attaching themselves to `M-right'.
16008 See `org-ctrl-c-ctrl-c-hook' for more information.")
16009 (defvar org-metaup-hook nil
16010 "Hook for functions attaching themselves to `M-up'.
16011 See `org-ctrl-c-ctrl-c-hook' for more information.")
16012 (defvar org-metadown-hook nil
16013 "Hook for functions attaching themselves to `M-down'.
16014 See `org-ctrl-c-ctrl-c-hook' for more information.")
16015 (defvar org-shiftmetaleft-hook nil
16016 "Hook for functions attaching themselves to `M-S-left'.
16017 See `org-ctrl-c-ctrl-c-hook' for more information.")
16018 (defvar org-shiftmetaright-hook nil
16019 "Hook for functions attaching themselves to `M-S-right'.
16020 See `org-ctrl-c-ctrl-c-hook' for more information.")
16021 (defvar org-shiftmetaup-hook nil
16022 "Hook for functions attaching themselves to `M-S-up'.
16023 See `org-ctrl-c-ctrl-c-hook' for more information.")
16024 (defvar org-shiftmetadown-hook nil
16025 "Hook for functions attaching themselves to `M-S-down'.
16026 See `org-ctrl-c-ctrl-c-hook' for more information.")
16027 (defvar org-metareturn-hook nil
16028 "Hook for functions attaching themselves to `M-RET'.
16029 See `org-ctrl-c-ctrl-c-hook' for more information.")
16030 (defvar org-shiftup-hook nil
16031 "Hook for functions attaching themselves to `S-up'.
16032 See `org-ctrl-c-ctrl-c-hook' for more information.")
16033 (defvar org-shiftup-final-hook nil
16034 "Hook for functions attaching themselves to `S-up'.
16035 This one runs after all other options except shift-select have been excluded.
16036 See `org-ctrl-c-ctrl-c-hook' for more information.")
16037 (defvar org-shiftdown-hook nil
16038 "Hook for functions attaching themselves to `S-down'.
16039 See `org-ctrl-c-ctrl-c-hook' for more information.")
16040 (defvar org-shiftdown-final-hook nil
16041 "Hook for functions attaching themselves to `S-down'.
16042 This one runs after all other options except shift-select have been excluded.
16043 See `org-ctrl-c-ctrl-c-hook' for more information.")
16044 (defvar org-shiftleft-hook nil
16045 "Hook for functions attaching themselves to `S-left'.
16046 See `org-ctrl-c-ctrl-c-hook' for more information.")
16047 (defvar org-shiftleft-final-hook nil
16048 "Hook for functions attaching themselves to `S-left'.
16049 This one runs after all other options except shift-select have been excluded.
16050 See `org-ctrl-c-ctrl-c-hook' for more information.")
16051 (defvar org-shiftright-hook nil
16052 "Hook for functions attaching themselves to `S-right'.
16053 See `org-ctrl-c-ctrl-c-hook' for more information.")
16054 (defvar org-shiftright-final-hook nil
16055 "Hook for functions attaching themselves to `S-right'.
16056 This one runs after all other options except shift-select have been excluded.
16057 See `org-ctrl-c-ctrl-c-hook' for more information.")
16059 (defun org-modifier-cursor-error ()
16060 "Throw an error, a modified cursor command was applied in wrong context."
16061 (error "This command is active in special context like tables, headlines or items"))
16063 (defun org-shiftselect-error ()
16064 "Throw an error because Shift-Cursor command was applied in wrong context."
16065 (if (and (boundp 'shift-select-mode) shift-select-mode)
16066 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
16067 (error "This command works only in special context like headlines or timestamps")))
16069 (defun org-call-for-shift-select (cmd)
16070 (let ((this-command-keys-shift-translated t))
16071 (call-interactively cmd)))
16073 (defun org-shifttab (&optional arg)
16074 "Global visibility cycling or move to previous table field.
16075 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
16077 See the individual commands for more information."
16080 ((org-at-table-p) (call-interactively 'org-table-previous-field))
16082 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
16083 (message "Content view to level: %d" arg)
16084 (org-content (prefix-numeric-value arg2))
16085 (setq org-cycle-global-status 'overview)))
16086 (t (call-interactively 'org-global-cycle))))
16088 (defun org-shiftmetaleft ()
16089 "Promote subtree or delete table column.
16090 Calls `org-promote-subtree', `org-outdent-item',
16091 or `org-table-delete-column', depending on context.
16092 See the individual commands for more information."
16095 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
16096 ((org-at-table-p) (call-interactively 'org-table-delete-column))
16097 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
16098 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
16099 (t (org-modifier-cursor-error))))
16101 (defun org-shiftmetaright ()
16102 "Demote subtree or insert table column.
16103 Calls `org-demote-subtree', `org-indent-item',
16104 or `org-table-insert-column', depending on context.
16105 See the individual commands for more information."
16108 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
16109 ((org-at-table-p) (call-interactively 'org-table-insert-column))
16110 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
16111 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
16112 (t (org-modifier-cursor-error))))
16114 (defun org-shiftmetaup (&optional arg)
16115 "Move subtree up or kill table row.
16116 Calls `org-move-subtree-up' or `org-table-kill-row' or
16117 `org-move-item-up' depending on context. See the individual commands
16118 for more information."
16121 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16122 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16123 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16124 ((org-at-item-p) (call-interactively 'org-move-item-up))
16125 (t (org-modifier-cursor-error))))
16127 (defun org-shiftmetadown (&optional arg)
16128 "Move subtree down or insert table row.
16129 Calls `org-move-subtree-down' or `org-table-insert-row' or
16130 `org-move-item-down', depending on context. See the individual
16131 commands for more information."
16134 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16135 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16136 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16137 ((org-at-item-p) (call-interactively 'org-move-item-down))
16138 (t (org-modifier-cursor-error))))
16140 (defsubst org-hidden-tree-error ()
16142 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
16144 (defun org-metaleft (&optional arg)
16145 "Promote heading or move table column to left.
16146 Calls `org-do-promote' or `org-table-move-column', depending on context.
16147 With no specific context, calls the Emacs default `backward-word'.
16148 See the individual commands for more information."
16151 ((run-hook-with-args-until-success 'org-metaleft-hook))
16152 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16153 ((or (org-on-heading-p)
16154 (and (org-region-active-p)
16156 (goto-char (region-beginning))
16157 (org-on-heading-p))))
16158 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16159 (call-interactively 'org-do-promote))
16160 ((or (org-at-item-p)
16161 (and (org-region-active-p)
16163 (goto-char (region-beginning))
16165 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16166 (call-interactively 'org-outdent-item))
16167 (t (call-interactively 'backward-word))))
16169 (defun org-metaright (&optional arg)
16170 "Demote subtree or move table column to right.
16171 Calls `org-do-demote' or `org-table-move-column', depending on context.
16172 With no specific context, calls the Emacs default `forward-word'.
16173 See the individual commands for more information."
16176 ((run-hook-with-args-until-success 'org-metaright-hook))
16177 ((org-at-table-p) (call-interactively 'org-table-move-column))
16178 ((or (org-on-heading-p)
16179 (and (org-region-active-p)
16181 (goto-char (region-beginning))
16182 (org-on-heading-p))))
16183 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16184 (call-interactively 'org-do-demote))
16185 ((or (org-at-item-p)
16186 (and (org-region-active-p)
16188 (goto-char (region-beginning))
16190 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16191 (call-interactively 'org-indent-item))
16192 (t (call-interactively 'forward-word))))
16194 (defun org-check-for-hidden (what)
16195 "Check if there are hidden headlines/items in the current visual line.
16196 WHAT can be either `headlines' or `items'. If the current line is
16197 an outline or item heading and it has a folded subtree below it,
16198 this fucntion returns t, nil otherwise."
16200 ((eq what 'headlines) (concat "^" org-outline-regexp))
16201 ((eq what 'items) (concat "^" (org-item-re t)))
16202 (t (error "This should not happen"))))
16206 (unless (org-region-active-p)
16207 (setq beg (point-at-bol))
16208 (beginning-of-line 2)
16209 (while (and (not (eobp)) ;; this is like `next-line'
16210 (get-char-property (1- (point)) 'invisible))
16211 (beginning-of-line 2))
16214 (goto-char (point-at-eol))
16215 (setq end (max end (point)))
16216 (while (re-search-forward re end t)
16217 (if (get-char-property (match-beginning 0) 'invisible)
16221 (defun org-metaup (&optional arg)
16222 "Move subtree up or move table row up.
16223 Calls `org-move-subtree-up' or `org-table-move-row' or
16224 `org-move-item-up', depending on context. See the individual commands
16225 for more information."
16228 ((run-hook-with-args-until-success 'org-metaup-hook))
16229 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16230 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16231 ((org-at-item-p) (call-interactively 'org-move-item-up))
16232 (t (transpose-lines 1) (beginning-of-line -1))))
16234 (defun org-metadown (&optional arg)
16235 "Move subtree down or move table row down.
16236 Calls `org-move-subtree-down' or `org-table-move-row' or
16237 `org-move-item-down', depending on context. See the individual
16238 commands for more information."
16241 ((run-hook-with-args-until-success 'org-metadown-hook))
16242 ((org-at-table-p) (call-interactively 'org-table-move-row))
16243 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16244 ((org-at-item-p) (call-interactively 'org-move-item-down))
16245 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16247 (defun org-shiftup (&optional arg)
16248 "Increase item in timestamp or increase priority of current headline.
16249 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16250 depending on context. See the individual commands for more information."
16253 ((run-hook-with-args-until-success 'org-shiftup-hook))
16254 ((and org-support-shift-select (org-region-active-p))
16255 (org-call-for-shift-select 'previous-line))
16256 ((org-at-timestamp-p t)
16257 (call-interactively (if org-edit-timestamp-down-means-later
16258 'org-timestamp-down 'org-timestamp-up)))
16259 ((and (not (eq org-support-shift-select 'always))
16260 org-enable-priority-commands
16261 (org-on-heading-p))
16262 (call-interactively 'org-priority-up))
16263 ((and (not org-support-shift-select) (org-at-item-p))
16264 (call-interactively 'org-previous-item))
16265 ((org-clocktable-try-shift 'up arg))
16266 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
16267 (org-support-shift-select
16268 (org-call-for-shift-select 'previous-line))
16269 (t (org-shiftselect-error))))
16271 (defun org-shiftdown (&optional arg)
16272 "Decrease item in timestamp or decrease priority of current headline.
16273 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16274 depending on context. See the individual commands for more information."
16277 ((run-hook-with-args-until-success 'org-shiftdown-hook))
16278 ((and org-support-shift-select (org-region-active-p))
16279 (org-call-for-shift-select 'next-line))
16280 ((org-at-timestamp-p t)
16281 (call-interactively (if org-edit-timestamp-down-means-later
16282 'org-timestamp-up 'org-timestamp-down)))
16283 ((and (not (eq org-support-shift-select 'always))
16284 org-enable-priority-commands
16285 (org-on-heading-p))
16286 (call-interactively 'org-priority-down))
16287 ((and (not org-support-shift-select) (org-at-item-p))
16288 (call-interactively 'org-next-item))
16289 ((org-clocktable-try-shift 'down arg))
16290 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
16291 (org-support-shift-select
16292 (org-call-for-shift-select 'next-line))
16293 (t (org-shiftselect-error))))
16295 (defun org-shiftright (&optional arg)
16296 "Cycle the thing at point or in the current line, depending on context.
16297 Depending on context, this does one of the following:
16299 - switch a timestamp at point one day into the future
16300 - on a headline, switch to the next TODO keyword.
16301 - on an item, switch entire list to the next bullet type
16302 - on a property line, switch to the next allowed value
16303 - on a clocktable definition line, move time block into the future"
16306 ((run-hook-with-args-until-success 'org-shiftright-hook))
16307 ((and org-support-shift-select (org-region-active-p))
16308 (org-call-for-shift-select 'forward-char))
16309 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16310 ((and (not (eq org-support-shift-select 'always))
16311 (org-on-heading-p))
16312 (let ((org-inhibit-logging
16313 (not org-treat-S-cursor-todo-selection-as-state-change))
16314 (org-inhibit-blocking
16315 (not org-treat-S-cursor-todo-selection-as-state-change)))
16316 (org-call-with-arg 'org-todo 'right)))
16317 ((or (and org-support-shift-select
16318 (not (eq org-support-shift-select 'always))
16319 (org-at-item-bullet-p))
16320 (and (not org-support-shift-select) (org-at-item-p)))
16321 (org-call-with-arg 'org-cycle-list-bullet nil))
16322 ((and (not (eq org-support-shift-select 'always))
16323 (org-at-property-p))
16324 (call-interactively 'org-property-next-allowed-value))
16325 ((org-clocktable-try-shift 'right arg))
16326 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
16327 (org-support-shift-select
16328 (org-call-for-shift-select 'forward-char))
16329 (t (org-shiftselect-error))))
16331 (defun org-shiftleft (&optional arg)
16332 "Cycle the thing at point or in the current line, depending on context.
16333 Depending on context, this does one of the following:
16335 - switch a timestamp at point one day into the past
16336 - on a headline, switch to the previous TODO keyword.
16337 - on an item, switch entire list to the previous bullet type
16338 - on a property line, switch to the previous allowed value
16339 - on a clocktable definition line, move time block into the past"
16342 ((run-hook-with-args-until-success 'org-shiftleft-hook))
16343 ((and org-support-shift-select (org-region-active-p))
16344 (org-call-for-shift-select 'backward-char))
16345 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16346 ((and (not (eq org-support-shift-select 'always))
16347 (org-on-heading-p))
16348 (let ((org-inhibit-logging
16349 (not org-treat-S-cursor-todo-selection-as-state-change))
16350 (org-inhibit-blocking
16351 (not org-treat-S-cursor-todo-selection-as-state-change)))
16352 (org-call-with-arg 'org-todo 'left)))
16353 ((or (and org-support-shift-select
16354 (not (eq org-support-shift-select 'always))
16355 (org-at-item-bullet-p))
16356 (and (not org-support-shift-select) (org-at-item-p)))
16357 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16358 ((and (not (eq org-support-shift-select 'always))
16359 (org-at-property-p))
16360 (call-interactively 'org-property-previous-allowed-value))
16361 ((org-clocktable-try-shift 'left arg))
16362 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
16363 (org-support-shift-select
16364 (org-call-for-shift-select 'backward-char))
16365 (t (org-shiftselect-error))))
16367 (defun org-shiftcontrolright ()
16368 "Switch to next TODO set."
16371 ((and org-support-shift-select (org-region-active-p))
16372 (org-call-for-shift-select 'forward-word))
16373 ((and (not (eq org-support-shift-select 'always))
16374 (org-on-heading-p))
16375 (org-call-with-arg 'org-todo 'nextset))
16376 (org-support-shift-select
16377 (org-call-for-shift-select 'forward-word))
16378 (t (org-shiftselect-error))))
16380 (defun org-shiftcontrolleft ()
16381 "Switch to previous TODO set."
16384 ((and org-support-shift-select (org-region-active-p))
16385 (org-call-for-shift-select 'backward-word))
16386 ((and (not (eq org-support-shift-select 'always))
16387 (org-on-heading-p))
16388 (org-call-with-arg 'org-todo 'previousset))
16389 (org-support-shift-select
16390 (org-call-for-shift-select 'backward-word))
16391 (t (org-shiftselect-error))))
16393 (defun org-ctrl-c-ret ()
16394 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16397 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16398 (t (call-interactively 'org-insert-heading))))
16400 (defun org-copy-special ()
16401 "Copy region in table or copy current subtree.
16402 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16403 See the individual commands for more information."
16405 (call-interactively
16406 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16408 (defun org-cut-special ()
16409 "Cut region in table or cut current subtree.
16410 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16411 See the individual commands for more information."
16413 (call-interactively
16414 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16416 (defun org-paste-special (arg)
16417 "Paste rectangular region into table, or past subtree relative to level.
16418 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16419 See the individual commands for more information."
16421 (if (org-at-table-p)
16422 (org-table-paste-rectangle)
16423 (org-paste-subtree arg)))
16425 (defun org-edit-special ()
16426 "Call a special editor for the stuff at point.
16427 When at a table, call the formula editor with `org-table-edit-formulas'.
16428 When at the first line of an src example, call `org-edit-src-code'.
16429 When in an #+include line, visit the include file. Otherwise call
16430 `ffap' to visit the file at point."
16433 ((org-at-table.el-p)
16434 (org-edit-src-code))
16436 (call-interactively 'org-table-edit-formulas))
16438 (beginning-of-line 1)
16439 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16440 (find-file (org-trim (match-string 1))))
16441 ((org-edit-src-code))
16442 ((org-edit-fixed-width-region))
16443 (t (call-interactively 'ffap))))
16446 (defun org-ctrl-c-ctrl-c (&optional arg)
16447 "Set tags in headline, or update according to changed information at point.
16449 This command does many different things, depending on context:
16451 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
16452 this is what we do.
16454 - If the cursor is on a statistics cookie, update it.
16456 - If the cursor is in a headline, prompt for tags and insert them
16457 into the current line, aligned to `org-tags-column'. When called
16458 with prefix arg, realign all tags in the current buffer.
16460 - If the cursor is in one of the special #+KEYWORD lines, this
16461 triggers scanning the buffer for these lines and updating the
16464 - If the cursor is inside a table, realign the table. This command
16465 works even if the automatic table editor has been turned off.
16467 - If the cursor is on a #+TBLFM line, re-apply the formulas to
16470 - If the cursor is at a footnote reference or definition, jump to
16471 the corresponding definition or references, respectively.
16473 - If the cursor is a the beginning of a dynamic block, update it.
16475 - If the current buffer is a remember buffer, close note and file
16476 it. A prefix argument of 1 files to the default location
16477 without further interaction. A prefix argument of 2 files to
16478 the currently clocking task.
16480 - If the cursor is on a <<<target>>>, update radio targets and corresponding
16481 links in this buffer.
16483 - If the cursor is on a numbered item in a plain list, renumber the
16486 - If the cursor is on a checkbox, toggle it."
16488 (let ((org-enable-table-editor t))
16490 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
16491 org-occur-highlights
16492 org-latex-fragment-image-overlays)
16493 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
16494 (org-remove-occur-highlights)
16495 (org-remove-latex-fragment-image-overlays)
16496 (message "Temporary highlights/overlays removed from current buffer"))
16497 ((and (local-variable-p 'org-finish-function (current-buffer))
16498 (fboundp org-finish-function))
16499 (funcall org-finish-function))
16500 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
16501 ((or (looking-at org-property-start-re)
16502 (org-at-property-p))
16503 (call-interactively 'org-property-action))
16504 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
16505 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
16506 (or (org-on-heading-p) (org-at-item-p)))
16507 (call-interactively 'org-update-statistics-cookies))
16508 ((org-on-heading-p) (call-interactively 'org-set-tags))
16509 ((org-at-table.el-p)
16510 (message "Use C-c ' to edit table.el tables"))
16512 (org-table-maybe-eval-formula)
16514 (call-interactively 'org-table-recalculate)
16515 (org-table-maybe-recalculate-line))
16516 (call-interactively 'org-table-align))
16517 ((or (org-footnote-at-reference-p)
16518 (org-footnote-at-definition-p))
16519 (call-interactively 'org-footnote-action))
16520 ((org-at-item-checkbox-p)
16521 (call-interactively 'org-toggle-checkbox))
16524 (call-interactively 'org-toggle-checkbox)
16525 (call-interactively 'org-maybe-renumber-ordered-list)))
16526 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
16528 (beginning-of-line 1)
16529 (save-excursion (org-update-dblock)))
16531 (beginning-of-line 1)
16532 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
16534 ((equal (match-string 1) "TBLFM")
16535 ;; Recalculate the table before this line
16537 (beginning-of-line 1)
16538 (skip-chars-backward " \r\n\t")
16539 (if (org-at-table-p)
16540 (org-call-with-arg 'org-table-recalculate (or arg t)))))
16542 (let ((org-inhibit-startup-visibility-stuff t)
16543 (org-startup-align-all-tables nil))
16544 (org-save-outline-visibility 'use-markers (org-mode-restart)))
16545 (message "Local setup has been refreshed"))))
16546 ((org-clock-update-time-maybe))
16547 (t (error "C-c C-c can do nothing useful at this location")))))
16549 (defun org-mode-restart ()
16550 "Restart Org-mode, to scan again for special lines.
16551 Also updates the keyword regular expressions."
16554 (message "Org-mode restarted"))
16556 (defun org-kill-note-or-show-branches ()
16557 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
16559 (if (not org-finish-function)
16560 (call-interactively 'show-branches)
16561 (let ((org-note-abort t))
16562 (funcall org-finish-function))))
16564 (defun org-return (&optional indent)
16565 "Goto next table row or insert a newline.
16566 Calls `org-table-next-row' or `newline', depending on context.
16567 See the individual commands for more information."
16570 ((bobp) (if indent (newline-and-indent) (newline)))
16572 (org-table-justify-field-maybe)
16573 (call-interactively 'org-table-next-row))
16574 ((and org-return-follows-link
16575 (eq (get-text-property (point) 'face) 'org-link))
16576 (call-interactively 'org-open-at-point))
16577 ((and (org-at-heading-p)
16579 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
16583 (t (if indent (newline-and-indent) (newline)))))
16585 (defun org-return-indent ()
16586 "Goto next table row or insert a newline and indent.
16587 Calls `org-table-next-row' or `newline-and-indent', depending on
16588 context. See the individual commands for more information."
16592 (defun org-ctrl-c-star ()
16593 "Compute table, or change heading status of lines.
16594 Calls `org-table-recalculate' or `org-toggle-heading',
16595 depending on context."
16599 (call-interactively 'org-table-recalculate))
16601 ;; Convert all lines in region to list items
16602 (call-interactively 'org-toggle-heading))))
16604 (defun org-ctrl-c-minus ()
16605 "Insert separator line in table or modify bullet status of line.
16606 Also turns a plain line or a region of lines into list items.
16607 Calls `org-table-insert-hline', `org-toggle-item', or
16608 `org-cycle-list-bullet', depending on context."
16612 (call-interactively 'org-table-insert-hline))
16613 ((org-region-active-p)
16614 (call-interactively 'org-toggle-item))
16616 (call-interactively 'org-cycle-list-bullet))
16618 (call-interactively 'org-toggle-item))))
16620 (defun org-toggle-item ()
16621 "Convert headings or normal lines to items, items to normal lines.
16622 If there is no active region, only the current line is considered.
16624 If the first line in the region is a headline, convert all headlines to items.
16626 If the first line in the region is an item, convert all items to normal lines.
16628 If the first line is normal text, add an item bullet to each line."
16630 (let (l2 l beg end)
16631 (if (org-region-active-p)
16632 (setq beg (region-beginning) end (region-end))
16633 (setq beg (point-at-bol)
16634 end (min (1+ (point-at-eol)) (point-max))))
16637 (setq l2 (org-current-line))
16639 (beginning-of-line 1)
16640 (setq l (1- (org-current-line)))
16641 (if (org-at-item-p)
16642 ;; We already have items, de-itemize
16643 (while (< (setq l (1+ l)) l2)
16644 (when (org-at-item-p)
16645 (goto-char (match-beginning 2))
16646 (delete-region (match-beginning 2) (match-end 2))
16647 (and (looking-at "[ \t]+") (replace-match "")))
16648 (beginning-of-line 2))
16649 (if (org-on-heading-p)
16650 ;; Headings, convert to items
16651 (while (< (setq l (1+ l)) l2)
16652 (if (looking-at org-outline-regexp)
16653 (replace-match "- " t t))
16654 (beginning-of-line 2))
16655 ;; normal lines, turn them into items
16656 (while (< (setq l (1+ l)) l2)
16657 (unless (org-at-item-p)
16658 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16659 (replace-match "\\1- \\2")))
16660 (beginning-of-line 2)))))))
16662 (defun org-toggle-heading (&optional nstars)
16663 "Convert headings to normal text, or items or text to headings.
16664 If there is no active region, only the current line is considered.
16666 If the first line is a heading, remove the stars from all headlines
16669 If the first line is a plain list item, turn all plain list items
16672 If the first line is a normal line, turn each and every line in the
16673 region into a heading.
16675 When converting a line into a heading, the number of stars is chosen
16676 such that the lines become children of the current entry. However,
16677 when a prefix argument is given, its value determines the number of
16680 (let (l2 l itemp beg end)
16681 (if (org-region-active-p)
16682 (setq beg (region-beginning) end (region-end))
16683 (setq beg (point-at-bol)
16684 end (min (1+ (point-at-eol)) (point-max))))
16687 (setq l2 (org-current-line))
16689 (beginning-of-line 1)
16690 (setq l (1- (org-current-line)))
16691 (if (org-on-heading-p)
16692 ;; We already have headlines, de-star them
16693 (while (< (setq l (1+ l)) l2)
16694 (when (org-on-heading-p t)
16695 (and (looking-at outline-regexp) (replace-match "")))
16696 (beginning-of-line 2))
16697 (setq itemp (org-at-item-p))
16700 (make-string (prefix-numeric-value current-prefix-arg)
16703 (if (re-search-backward org-complex-heading-regexp nil t)
16704 (match-string 1) ""))))
16705 (add-stars (cond (nstars "")
16706 ((equal stars "") "*")
16707 (org-odd-levels-only "**")
16709 (rpl (concat stars add-stars " ")))
16710 (while (< (setq l (1+ l)) l2)
16712 (and (org-at-item-p) (replace-match rpl t t))
16713 (unless (org-on-heading-p)
16714 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16715 (replace-match (concat rpl (match-string 2))))))
16716 (beginning-of-line 2)))))))
16718 (defun org-meta-return (&optional arg)
16719 "Insert a new heading or wrap a region in a table.
16720 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
16721 See the individual commands for more information."
16724 ((run-hook-with-args-until-success 'org-metareturn-hook))
16726 (call-interactively 'org-table-wrap-region))
16727 (t (call-interactively 'org-insert-heading))))
16731 ;; Define the Org-mode menus
16732 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
16734 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
16735 ["Next Field" org-cycle (org-at-table-p)]
16736 ["Previous Field" org-shifttab (org-at-table-p)]
16737 ["Next Row" org-return (org-at-table-p)]
16739 ["Blank Field" org-table-blank-field (org-at-table-p)]
16740 ["Edit Field" org-table-edit-field (org-at-table-p)]
16741 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
16744 ["Move Column Left" org-metaleft (org-at-table-p)]
16745 ["Move Column Right" org-metaright (org-at-table-p)]
16746 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
16747 ["Insert Column" org-shiftmetaright (org-at-table-p)])
16749 ["Move Row Up" org-metaup (org-at-table-p)]
16750 ["Move Row Down" org-metadown (org-at-table-p)]
16751 ["Delete Row" org-shiftmetaup (org-at-table-p)]
16752 ["Insert Row" org-shiftmetadown (org-at-table-p)]
16753 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
16755 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
16757 ["Copy Rectangle" org-copy-special (org-at-table-p)]
16758 ["Cut Rectangle" org-cut-special (org-at-table-p)]
16759 ["Paste Rectangle" org-paste-special (org-at-table-p)]
16760 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
16763 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
16764 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
16765 ["Edit Formulas" org-edit-special (org-at-table-p)]
16767 ["Recalculate line" org-table-recalculate (org-at-table-p)]
16768 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
16769 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
16771 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
16773 ["Sum Column/Rectangle" org-table-sum
16774 (or (org-at-table-p) (org-region-active-p))]
16775 ["Which Column?" org-table-current-column (org-at-table-p)])
16777 org-table-toggle-formula-debugger
16778 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
16779 ["Show Col/Row Numbers"
16780 org-table-toggle-coordinate-overlays
16782 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
16784 ["Create" org-table-create (and (not (org-at-table-p))
16785 org-enable-table-editor)]
16786 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
16787 ["Import from File" org-table-import (not (org-at-table-p))]
16788 ["Export to File" org-table-export (org-at-table-p)]
16790 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
16792 (easy-menu-define org-org-menu org-mode-map "Org menu"
16795 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
16796 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
16797 ["Sparse Tree..." org-sparse-tree t]
16798 ["Reveal Context" org-reveal t]
16799 ["Show All" show-all t]
16801 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
16803 ["New Heading" org-insert-heading t]
16804 ("Navigate Headings"
16805 ["Up" outline-up-heading t]
16806 ["Next" outline-next-visible-heading t]
16807 ["Previous" outline-previous-visible-heading t]
16808 ["Next Same Level" outline-forward-same-level t]
16809 ["Previous Same Level" outline-backward-same-level t]
16811 ["Jump" org-goto t])
16813 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
16814 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
16816 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
16817 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
16818 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
16820 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
16822 ["Promote Heading" org-metaleft (not (org-at-table-p))]
16823 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
16824 ["Demote Heading" org-metaright (not (org-at-table-p))]
16825 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
16827 ["Sort Region/Children" org-sort (not (org-at-table-p))]
16829 ["Convert to odd levels" org-convert-to-odd-levels t]
16830 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
16832 ["Emphasis..." org-emphasize t]
16833 ["Edit Source Example" org-edit-special t]
16835 ["Footnote new/jump" org-footnote-action t]
16836 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
16838 ["Archive (default method)" org-archive-subtree-default t]
16840 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
16841 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
16842 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
16846 ["Store Link (Global)" org-store-link t]
16847 ["Find existing link to here" org-occur-link-in-agenda-files t]
16848 ["Insert Link" org-insert-link t]
16849 ["Follow Link" org-open-at-point t]
16851 ["Next link" org-next-link t]
16852 ["Previous link" org-previous-link t]
16854 ["Descriptive Links"
16855 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
16857 :selected (member '(org-link) buffer-invisibility-spec)]
16860 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
16862 :selected (not (member '(org-link) buffer-invisibility-spec))])
16865 ["TODO/DONE/-" org-todo t]
16867 ["Next keyword" org-shiftright (org-on-heading-p)]
16868 ["Previous keyword" org-shiftleft (org-on-heading-p)]
16869 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
16870 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
16871 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
16872 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
16873 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
16875 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
16876 :selected org-enforce-todo-dependencies :style toggle :active t]
16877 "Settings for tree at point"
16878 ["Do Children sequentially" org-toggle-ordered-property :style radio
16879 :selected (ignore-errors (org-entry-get nil "ORDERED"))
16880 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16881 ["Do Children parallel" org-toggle-ordered-property :style radio
16882 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
16883 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16885 ["Set Priority" org-priority t]
16886 ["Priority Up" org-shiftup t]
16887 ["Priority Down" org-shiftdown t]
16889 ["Get news from all feeds" org-feed-update-all t]
16890 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
16891 ["Customize feeds" (customize-variable 'org-feed-alist) t])
16892 ("TAGS and Properties"
16893 ["Set Tags" org-set-tags-command t]
16894 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
16896 ["Set property" org-set-property t]
16897 ["Column view of properties" org-columns t]
16898 ["Insert Column View DBlock" org-insert-columns-dblock t])
16899 ("Dates and Scheduling"
16900 ["Timestamp" org-time-stamp t]
16901 ["Timestamp (inactive)" org-time-stamp-inactive t]
16903 ["1 Day Later" org-shiftright t]
16904 ["1 Day Earlier" org-shiftleft t]
16905 ["1 ... Later" org-shiftup t]
16906 ["1 ... Earlier" org-shiftdown t])
16907 ["Compute Time Range" org-evaluate-time-range t]
16908 ["Schedule Item" org-schedule t]
16909 ["Deadline" org-deadline t]
16911 ["Custom time format" org-toggle-time-stamp-overlays
16912 :style radio :selected org-display-custom-times]
16914 ["Goto Calendar" org-goto-calendar t]
16915 ["Date from Calendar" org-date-from-calendar t]
16917 ["Start/Restart Timer" org-timer-start t]
16918 ["Pause/Continue Timer" org-timer-pause-or-continue t]
16919 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
16920 ["Insert Timer String" org-timer t]
16921 ["Insert Timer Item" org-timer-item t])
16923 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
16924 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
16925 ["Clock out" org-clock-out t]
16926 ["Clock cancel" org-clock-cancel t]
16928 ["Mark as default task" org-clock-mark-default-task t]
16929 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
16930 ["Goto running clock" org-clock-goto t]
16932 ["Display times" org-clock-display t]
16933 ["Create clock table" org-clock-report t]
16935 ["Record DONE time"
16936 (progn (setq org-log-done (not org-log-done))
16937 (message "Switching to %s will %s record a timestamp"
16938 (car org-done-keywords)
16939 (if org-log-done "automatically" "not")))
16940 :style toggle :selected org-log-done])
16942 ["Agenda Command..." org-agenda t]
16943 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
16944 ("File List for Agenda")
16945 ("Special views current file"
16946 ["TODO Tree" org-show-todo-tree t]
16947 ["Check Deadlines" org-check-deadlines t]
16948 ["Timeline" org-timeline t]
16949 ["Tags/Property tree" org-match-sparse-tree t])
16951 ["Export/Publish..." org-export t]
16953 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
16954 :selected org-cdlatex-mode]
16955 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
16956 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
16957 ["Modify math symbol" org-cdlatex-math-modify
16958 (org-inside-LaTeX-fragment-p)]
16959 ["Insert citation" org-reftex-citation t]
16961 ["Export LaTeX fragments as images"
16962 (if (featurep 'org-exp)
16963 (setq org-export-with-LaTeX-fragments
16964 (not org-export-with-LaTeX-fragments))
16965 (require 'org-exp))
16966 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
16967 org-export-with-LaTeX-fragments)]
16969 ["Template for BEAMER" org-beamer-settings-template t])
16972 ["Push Files and Views" org-mobile-push t]
16973 ["Get Captured and Flagged" org-mobile-pull t]
16974 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
16976 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
16979 ["Show Version" org-version t]
16980 ["Info Documentation" org-info t])
16982 ["Browse Org Group" org-customize t]
16984 ["Expand This Menu" org-create-customize-menu
16985 (fboundp 'customize-menu-create)])
16986 ["Send bug report" org-submit-bug-report t]
16989 ["Refresh setup current buffer" org-mode-restart t]
16990 ["Reload Org (after update)" org-reload t]
16991 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
16994 (defun org-info (&optional node)
16995 "Read documentation for Org-mode in the info system.
16996 With optional NODE, go directly to that node."
16998 (info (format "(org)%s" (or node ""))))
17001 (defun org-submit-bug-report ()
17002 "Submit a bug report on Org-mode via mail.
17004 Don't hesitate to report any problems or inaccurate documentation.
17006 If you don't have setup sending mail from (X)Emacs, please copy the
17007 output buffer into your mail program, as it gives us important
17008 information about your Org-mode version and configuration."
17010 (require 'reporter)
17011 (org-load-modules-maybe)
17012 (org-require-autoloaded-modules)
17013 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
17014 (reporter-submit-bug-report
17015 "emacs-orgmode@gnu.org"
17018 (save-window-excursion
17019 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
17020 (delete-other-windows)
17022 (insert "You are about to submit a bug report to the Org-mode mailing list.
17024 We would like to add your full Org-mode and Outline configuration to the
17025 bug report. This greatly simplifies the work of the maintainer and
17026 other experts on the mailing list.
17028 HOWEVER, some variables you have customized may contain private
17029 information. The names of customers, colleagues, or friends, might
17030 appear in the form of file names, tags, todo states, or search strings.
17031 If you answer yes to the prompt, you might want to check and remove
17032 such private information before sending the email.")
17033 (add-text-properties (point-min) (point-max) '(face org-warning))
17034 (when (yes-or-no-p "Include your Org-mode configuration ")
17038 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
17039 (or (and (symbol-value v)
17040 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
17042 (get v 'custom-type) (get v 'standard-value)
17043 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
17045 (kill-buffer (get-buffer "*Warn about privacy*"))
17048 "Remember to cover the basics, that is, what you expected to happen and
17049 what in fact did happen. You don't know how to make a good report? See
17051 http://orgmode.org/manual/Feedback.html#Feedback
17053 Your bug report will be posted to the Org-mode mailing list.
17054 ------------------------------------------------------------------------")
17056 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
17057 (replace-match "\\1Bug: \\3 [\\2]")))))
17060 (defun org-install-agenda-files-menu ()
17061 (let ((bl (buffer-list)))
17064 (set-buffer (pop bl))
17065 (if (org-mode-p) (setq bl nil)))
17068 '("Org") "File List for Agenda"
17071 ["Edit File List" (org-edit-agenda-file-list) t]
17072 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
17073 ["Remove Current File from List" org-remove-file t]
17074 ["Cycle through agenda files" org-cycle-agenda-files t]
17075 ["Occur in all agenda files" org-occur-in-agenda-files t]
17077 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
17082 (defun org-require-autoloaded-modules ()
17085 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
17086 org-docbook org-exp org-html org-icalendar
17088 org-publish org-remember org-table
17089 org-timer org-xoxo)))
17092 (defun org-reload (&optional uncompiled)
17093 "Reload all org lisp files.
17094 With prefix arg UNCOMPILED, load the uncompiled versions."
17096 (require 'find-func)
17097 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
17098 (dir-org (file-name-directory (org-find-library-name "org")))
17099 (dir-org-contrib (ignore-errors
17100 (file-name-directory
17101 (org-find-library-name "org-contribdir"))))
17103 (append (directory-files dir-org t file-re)
17104 (and dir-org-contrib
17105 (directory-files dir-org-contrib t file-re))))
17106 (remove-re (concat (if (featurep 'xemacs)
17107 "org-colview" "org-colview-xemacs")
17109 (setq files (mapcar 'file-name-sans-extension files))
17110 (setq files (mapcar
17111 (lambda (x) (if (string-match remove-re x) nil x))
17113 (setq files (delq nil files))
17116 (when (featurep (intern (file-name-nondirectory f)))
17117 (if (and (not uncompiled)
17118 (file-exists-p (concat f ".elc")))
17119 (load (concat f ".elc") nil nil t)
17120 (load (concat f ".el") nil nil t))))
17125 (defun org-customize ()
17126 "Call the customize function with org as argument."
17128 (org-load-modules-maybe)
17129 (org-require-autoloaded-modules)
17130 (customize-browse 'org))
17132 (defun org-create-customize-menu ()
17133 "Create a full customization menu for Org-mode, insert it into the menu."
17135 (org-load-modules-maybe)
17136 (org-require-autoloaded-modules)
17137 (if (fboundp 'customize-menu-create)
17140 '("Org") "Customize"
17141 `(["Browse Org group" org-customize t]
17143 ,(customize-menu-create 'org)
17144 ["Set" Custom-set t]
17145 ["Save" Custom-save t]
17146 ["Reset to Current" Custom-reset-current t]
17147 ["Reset to Saved" Custom-reset-saved t]
17148 ["Reset to Standard Settings" Custom-reset-standard t]))
17149 (message "\"Org\"-menu now contains full customization menu"))
17150 (error "Cannot expand menu (outdated version of cus-edit.el)")))
17152 ;;;; Miscellaneous stuff
17154 ;;; Generally useful functions
17156 (defun org-get-at-bol (property)
17157 "Get text property PROPERTY at beginning of line."
17158 (get-text-property (point-at-bol) property))
17160 (defun org-find-text-property-in-string (prop s)
17161 "Return the first non-nil value of property PROP in string S."
17162 (or (get-text-property 0 prop s)
17163 (get-text-property (or (next-single-property-change 0 prop s) 0)
17166 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17167 "Display the given MESSAGE as a warning."
17168 (if (fboundp 'display-warning)
17169 (display-warning 'org message
17170 (if (featurep 'xemacs) 'warning :warning))
17171 (let ((buf (get-buffer-create "*Org warnings*")))
17172 (with-current-buffer buf
17173 (goto-char (point-max))
17174 (insert "Warning (Org): " message)
17177 (display-buffer buf)
17180 (defun org-in-commented-line ()
17181 "Is point in a line starting with `#'?"
17182 (equal (char-after (point-at-bol)) ?#))
17184 (defun org-in-verbatim-emphasis ()
17186 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17188 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17189 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17190 (if (and marker (marker-buffer marker)
17191 (buffer-live-p (marker-buffer marker)))
17193 (switch-to-buffer (marker-buffer marker))
17194 (if (or (> marker (point-max)) (< marker (point-min)))
17197 (org-show-context 'org-goto))
17199 (bookmark-jump bookmark)
17200 (error "Cannot find location"))))
17202 (defun org-quote-csv-field (s)
17203 "Quote field for inclusion in CSV material."
17204 (if (string-match "[\",]" s)
17205 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17208 (defun org-plist-delete (plist property)
17209 "Delete PROPERTY from PLIST.
17210 This is in contrast to merely setting it to 0."
17213 (if (not (eq property (car plist)))
17214 (setq p (plist-put p (car plist) (nth 1 plist))))
17215 (setq plist (cddr plist)))
17218 (defun org-force-self-insert (N)
17219 "Needed to enforce self-insert under remapping."
17221 (self-insert-command N))
17223 (defun org-string-width (s)
17224 "Compute width of string, ignoring invisible characters.
17225 This ignores character with invisibility property `org-link', and also
17226 characters with property `org-cwidth', because these will become invisible
17227 upon the next fontification round."
17229 (when (or (eq t buffer-invisibility-spec)
17230 (assq 'org-link buffer-invisibility-spec))
17231 (while (setq b (text-property-any 0 (length s)
17232 'invisible 'org-link s))
17233 (setq s (concat (substring s 0 b)
17234 (substring s (or (next-single-property-change
17235 b 'invisible s) (length s)))))))
17236 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17237 (setq s (concat (substring s 0 b)
17238 (substring s (or (next-single-property-change
17239 b 'org-cwidth s) (length s))))))
17240 (setq l (string-width s) b -1)
17241 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17242 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17245 (defun org-get-indentation (&optional line)
17246 "Get the indentation of the current line, interpreting tabs.
17247 When LINE is given, assume it represents a line and compute its indentation."
17249 (if (string-match "^ *" (org-remove-tabs line))
17252 (beginning-of-line 1)
17253 (skip-chars-forward " \t")
17254 (current-column))))
17256 (defun org-remove-tabs (s &optional width)
17257 "Replace tabulators in S with spaces.
17258 Assumes that s is a single line, starting in column 0."
17259 (setq width (or width tab-width))
17260 (while (string-match "\t" s)
17261 (setq s (replace-match
17263 (- (* width (/ (+ (match-beginning 0) width) width))
17264 (match-beginning 0)) ?\ )
17268 (defun org-fix-indentation (line ind)
17269 "Fix indentation in LINE.
17270 IND is a cons cell with target and minimum indentation.
17271 If the current indentation in LINE is smaller than the minimum,
17272 leave it alone. If it is larger than ind, set it to the target."
17273 (let* ((l (org-remove-tabs line))
17274 (i (org-get-indentation l))
17275 (i1 (car ind)) (i2 (cdr ind)))
17276 (if (>= i i2) (setq l (substring line i2)))
17278 (concat (make-string i1 ?\ ) l)
17281 (defun org-remove-indentation (code &optional n)
17282 "Remove the maximum common indentation from the lines in CODE.
17283 N may optionally be the number of spaces to remove."
17286 (org-do-remove-indentation n)
17289 (defun org-do-remove-indentation (&optional n)
17290 "Remove the maximum common indentation from the buffer."
17291 (untabify (point-min) (point-max))
17292 (let ((min 10000) re)
17295 (goto-char (point-min))
17296 (while (re-search-forward "^ *[^ \n]" nil t)
17297 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17298 (unless (or (= min 0) (= min 10000))
17299 (setq re (format "^ \\{%d\\}" min))
17300 (goto-char (point-min))
17301 (while (re-search-forward re nil t)
17306 (defun org-fill-template (template alist)
17307 "Find each %key of ALIST in TEMPLATE and replace it."
17308 (let ((case-fold-search nil)
17310 (setq alist (sort (copy-sequence alist)
17311 (lambda (a b) (< (length (car a)) (length (car b))))))
17312 (while (setq entry (pop alist))
17314 (replace-regexp-in-string
17315 (concat "%" (regexp-quote (car entry)))
17316 (cdr entry) template t t)))
17319 (defun org-base-buffer (buffer)
17320 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17323 (or (buffer-base-buffer buffer)
17326 (defun org-trim (s)
17327 "Remove whitespace at beginning and end of string."
17328 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17329 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17332 (defun org-wrap (string &optional width lines)
17333 "Wrap string to either a number of lines, or a width in characters.
17334 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17335 that costs. If there is a word longer than WIDTH, the text is actually
17336 wrapped to the length of that word.
17337 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17338 many lines, whatever width that takes.
17339 The return value is a list of lines, without newlines at the end."
17340 (let* ((words (org-split-string string "[ \t\n]+"))
17341 (maxword (apply 'max (mapcar 'org-string-width words)))
17344 (org-do-wrap words (max maxword width)))
17347 (setq ll (org-do-wrap words maxword))
17348 (if (<= (length ll) lines)
17351 (while (> (length ll) lines)
17353 (setq ll (org-do-wrap words w)))
17355 (t (error "Cannot wrap this")))))
17357 (defun org-do-wrap (words width)
17358 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17361 (setq line (pop words))
17362 (while (and words (< (+ (length line) (length (car words))) width))
17363 (setq line (concat line " " (pop words))))
17364 (setq lines (push line lines)))
17367 (defun org-split-string (string &optional separators)
17368 "Splits STRING into substrings at SEPARATORS.
17369 No empty strings are returned if there are matches at the beginning
17370 and end of string."
17371 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17375 (while (and (string-match rexp string
17377 (= start (match-beginning 0))
17378 (< start (length string)))
17380 (< (match-beginning 0) (length string)))
17382 (or (eq (match-beginning 0) 0)
17383 (and (eq (match-beginning 0) (match-end 0))
17384 (eq (match-beginning 0) start))
17386 (cons (substring string start (match-beginning 0))
17388 (setq start (match-end 0)))
17389 (or (eq start (length string))
17391 (cons (substring string start)
17395 (defun org-quote-vert (s)
17396 "Replace \"|\" with \"\\vert\"."
17397 (while (string-match "|" s)
17398 (setq s (replace-match "\\vert" t t s)))
17401 (defun org-uuidgen-p (s)
17402 "Is S an ID created by UUIDGEN?"
17403 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17405 (defun org-context ()
17406 "Return a list of contexts of the current cursor position.
17407 If several contexts apply, all are returned.
17408 Each context entry is a list with a symbol naming the context, and
17409 two positions indicating start and end of the context. Possible
17412 :headline anywhere in a headline
17413 :headline-stars on the leading stars in a headline
17414 :todo-keyword on a TODO keyword (including DONE) in a headline
17415 :tags on the TAGS in a headline
17416 :priority on the priority cookie in a headline
17417 :item on the first line of a plain list item
17418 :item-bullet on the bullet/number of a plain list item
17419 :checkbox on the checkbox in a plain list item
17420 :table in an org-mode table
17421 :table-special on a special filed in a table
17422 :table-table in a table.el table
17423 :link on a hyperlink
17424 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
17425 :target on a <<target>>
17426 :radio-target on a <<<radio-target>>>
17427 :latex-fragment on a LaTeX fragment
17428 :latex-preview on a LaTeX fragment with overlayed preview image
17430 This function expects the position to be visible because it uses font-lock
17431 faces as a help to recognize the following contexts: :table-special, :link,
17433 (let* ((f (get-text-property (point) 'face))
17434 (faces (if (listp f) f (list f)))
17435 (p (point)) clist o)
17436 ;; First the large context
17438 ((org-on-heading-p t)
17439 (push (list :headline (point-at-bol) (point-at-eol)) clist)
17441 (beginning-of-line 1)
17442 (looking-at org-todo-line-tags-regexp))
17443 (push (org-point-in-group p 1 :headline-stars) clist)
17444 (push (org-point-in-group p 2 :todo-keyword) clist)
17445 (push (org-point-in-group p 4 :tags) clist))
17447 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
17448 (if (looking-at "\\[#[A-Z0-9]\\]")
17449 (push (org-point-in-group p 0 :priority) clist)))
17452 (push (org-point-in-group p 2 :item-bullet) clist)
17453 (push (list :item (point-at-bol)
17454 (save-excursion (org-end-of-item) (point)))
17456 (and (org-at-item-checkbox-p)
17457 (push (org-point-in-group p 0 :checkbox) clist)))
17460 (push (list :table (org-table-begin) (org-table-end)) clist)
17461 (if (memq 'org-formula faces)
17462 (push (list :table-special
17463 (previous-single-property-change p 'face)
17464 (next-single-property-change p 'face)) clist)))
17465 ((org-at-table-p 'any)
17466 (push (list :table-table) clist)))
17469 ;; Now the small context
17471 ((org-at-timestamp-p)
17472 (push (org-point-in-group p 0 :timestamp) clist))
17473 ((memq 'org-link faces)
17475 (previous-single-property-change p 'face)
17476 (next-single-property-change p 'face)) clist))
17477 ((memq 'org-special-keyword faces)
17478 (push (list :keyword
17479 (previous-single-property-change p 'face)
17480 (next-single-property-change p 'face)) clist))
17482 (push (org-point-in-group p 0 :target) clist)
17483 (goto-char (1- (match-beginning 0)))
17484 (if (looking-at org-radio-target-regexp)
17485 (push (org-point-in-group p 0 :radio-target) clist))
17487 ((setq o (car (delq nil
17490 (if (memq x org-latex-fragment-image-overlays) x))
17491 (overlays-at (point))))))
17492 (push (list :latex-fragment
17493 (overlay-start o) (overlay-end o)) clist)
17494 (push (list :latex-preview
17495 (overlay-start o) (overlay-end o)) clist))
17496 ((org-inside-LaTeX-fragment-p)
17497 ;; FIXME: positions wrong.
17498 (push (list :latex-fragment (point) (point)) clist)))
17500 (setq clist (nreverse (delq nil clist)))
17503 ;; FIXME: Compare with at-regexp-p Do we need both?
17504 (defun org-in-regexp (re &optional nlines visually)
17505 "Check if point is inside a match of regexp.
17506 Normally only the current line is checked, but you can include NLINES extra
17507 lines both before and after point into the search.
17508 If VISUALLY is set, require that the cursor is not after the match but
17509 really on, so that the block visually is on the match."
17511 (let ((pos (point))
17512 (eol (point-at-eol (+ 1 (or nlines 0))))
17513 (inc (if visually 1 0)))
17515 (beginning-of-line (- 1 (or nlines 0)))
17516 (while (re-search-forward re eol t)
17517 (if (and (<= (match-beginning 0) pos)
17518 (>= (+ inc (match-end 0)) pos))
17519 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
17521 (defun org-at-regexp-p (regexp)
17522 "Is point inside a match of REGEXP in the current line?"
17525 (let ((pos (point)) (end (point-at-eol)))
17526 (beginning-of-line 1)
17527 (while (re-search-forward regexp end t)
17528 (if (and (<= (match-beginning 0) pos)
17529 (>= (match-end 0) pos))
17533 (defun org-in-regexps-block-p (start-re end-re)
17534 "Returns t if the current point is between matches of START-RE and END-RE.
17535 This will also return to if point is on one of the two matches."
17539 (and (or (org-at-regexp-p start-re)
17540 (re-search-backward start-re nil t))
17541 (re-search-forward end-re nil t)
17544 (defun org-occur-in-agenda-files (regexp &optional nlines)
17545 "Call `multi-occur' with buffers for all agenda files."
17546 (interactive "sOrg-files matching: \np")
17547 (let* ((files (org-agenda-files))
17548 (tnames (mapcar 'file-truename files))
17549 (extra org-agenda-text-search-extra-files)
17551 (when (eq (car extra) 'agenda-archives)
17552 (setq extra (cdr extra))
17553 (setq files (org-add-archive-files files)))
17554 (while (setq f (pop extra))
17555 (unless (member (file-truename f) tnames)
17556 (add-to-list 'files f 'append)
17557 (add-to-list 'tnames (file-truename f) 'append)))
17559 (mapcar (lambda (x)
17560 (with-current-buffer
17561 (or (get-file-buffer x) (find-file-noselect x))
17567 (if (boundp 'occur-mode-find-occurrence-hook)
17569 (add-hook 'occur-mode-find-occurrence-hook
17574 (defadvice occur-mode-goto-occurrence
17575 (after org-occur-reveal activate)
17576 (and (org-mode-p) (org-reveal)))
17577 (defadvice occur-mode-goto-occurrence-other-window
17578 (after org-occur-reveal activate)
17579 (and (org-mode-p) (org-reveal)))
17580 (defadvice occur-mode-display-occurrence
17581 (after org-occur-reveal activate)
17583 (let ((pos (occur-mode-find-occurrence)))
17584 (with-current-buffer (marker-buffer pos)
17589 (defun org-occur-link-in-agenda-files ()
17590 "Create a link and search for it in the agendas.
17591 The link is not stored in `org-stored-links', it is just created
17592 for the search purpose."
17594 (let ((link (condition-case nil
17595 (org-store-link nil)
17596 (error "Unable to create a link to here"))))
17597 (org-occur-in-agenda-files (regexp-quote link))))
17599 (defun org-uniquify (list)
17600 "Remove duplicate elements from LIST."
17602 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
17605 (defun org-delete-all (elts list)
17606 "Remove all elements in ELTS from LIST."
17608 (setq list (delete (pop elts) list)))
17611 (defun org-remove-if (predicate seq)
17612 "Remove everything from SEQ that fulfills PREDICATE."
17616 (if (not (funcall predicate e)) (push e res)))
17619 (defun org-remove-if-not (predicate seq)
17620 "Remove everything from SEQ that does not fulfill PREDICATE."
17624 (if (funcall predicate e) (push e res)))
17627 (defun org-back-over-empty-lines ()
17628 "Move backwards over whitespace, to the beginning of the first empty line.
17629 Returns the number of empty lines passed."
17630 (let ((pos (point)))
17631 (skip-chars-backward " \t\n\r")
17632 (beginning-of-line 2)
17633 (goto-char (min (point) pos))
17634 (count-lines (point) pos)))
17636 (defun org-skip-whitespace ()
17637 (skip-chars-forward " \t\n\r"))
17639 (defun org-point-in-group (point group &optional context)
17640 "Check if POINT is in match-group GROUP.
17641 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
17642 match. If the match group does ot exist or point is not inside it,
17644 (and (match-beginning group)
17645 (>= point (match-beginning group))
17646 (<= point (match-end group))
17648 (list context (match-beginning group) (match-end group))
17651 (defun org-switch-to-buffer-other-window (&rest args)
17652 "Switch to buffer in a second window on the current frame.
17653 In particular, do not allow pop-up frames."
17654 (let (pop-up-frames special-display-buffer-names special-display-regexps
17655 special-display-function)
17656 (apply 'switch-to-buffer-other-window args)))
17658 (defun org-combine-plists (&rest plists)
17659 "Create a single property list from all plists in PLISTS.
17660 The process starts by copying the first list, and then setting properties
17661 from the other lists. Settings in the last list are the most significant
17662 ones and overrule settings in the other lists."
17663 (let ((rtn (copy-sequence (pop plists)))
17666 (setq ls (pop plists))
17668 (setq p (pop ls) v (pop ls))
17669 (setq rtn (plist-put rtn p v))))
17672 (defun org-move-line-down (arg)
17673 "Move the current line down. With prefix argument, move it past ARG lines."
17675 (let ((col (current-column))
17677 (beginning-of-line 1) (setq beg (point))
17678 (beginning-of-line 2) (setq end (point))
17679 (beginning-of-line (+ 1 arg))
17680 (setq pos (move-marker (make-marker) (point)))
17681 (insert (delete-and-extract-region beg end))
17683 (org-move-to-column col)))
17685 (defun org-move-line-up (arg)
17686 "Move the current line up. With prefix argument, move it past ARG lines."
17688 (let ((col (current-column))
17690 (beginning-of-line 1) (setq beg (point))
17691 (beginning-of-line 2) (setq end (point))
17692 (beginning-of-line (- arg))
17693 (setq pos (move-marker (make-marker) (point)))
17694 (insert (delete-and-extract-region beg end))
17696 (org-move-to-column col)))
17698 (defun org-replace-escapes (string table)
17699 "Replace %-escapes in STRING with values in TABLE.
17700 TABLE is an association list with keys like \"%a\" and string values.
17701 The sequences in STRING may contain normal field width and padding information,
17702 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
17703 so values can contain further %-escapes if they are define later in TABLE."
17704 (let ((tbl (copy-alist table))
17705 (case-fold-search nil)
17708 (while (setq e (pop tbl))
17709 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
17710 (when (and (cdr e) (string-match re (cdr e)))
17711 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
17713 (add-text-properties 0 3 (list 'sref sref) safe)
17714 (setcdr e (replace-match safe t t (cdr e)))))
17715 (while (string-match re string)
17716 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
17718 (setq string (replace-match rpl t t string))))
17719 (while (setq pchg (next-property-change pchg string))
17720 (let ((sref (get-text-property pchg 'sref string)))
17721 (when (and sref (string-match "SREF" string pchg))
17722 (setq string (replace-match sref t t string)))))
17725 (defun org-sublist (list start end)
17726 "Return a section of LIST, from START to END.
17727 Counting starts at 1."
17728 (let (rtn (c start))
17729 (setq list (nthcdr (1- start) list))
17730 (while (and list (<= c end))
17731 (push (pop list) rtn)
17735 (defun org-find-base-buffer-visiting (file)
17736 "Like `find-buffer-visiting' but always return the base buffer and
17737 not an indirect buffer."
17738 (let ((buf (or (get-file-buffer file)
17739 (find-buffer-visiting file))))
17741 (or (buffer-base-buffer buf) buf)
17744 (defun org-image-file-name-regexp (&optional extensions)
17745 "Return regexp matching the file names of images.
17746 If EXTENSIONS is given, only match these."
17747 (if (and (not extensions) (fboundp 'image-file-name-regexp))
17748 (image-file-name-regexp)
17749 (let ((image-file-name-extensions
17751 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
17752 "xbm" "xpm" "pbm" "pgm" "ppm"))))
17754 (regexp-opt (nconc (mapcar 'upcase
17755 image-file-name-extensions)
17756 image-file-name-extensions)
17760 (defun org-file-image-p (file &optional extensions)
17761 "Return non-nil if FILE is an image."
17763 (string-match (org-image-file-name-regexp extensions) file)))
17765 (defun org-get-cursor-date ()
17766 "Return the date at cursor in as a time.
17767 This works in the calendar and in the agenda, anywhere else it just
17768 returns the current time."
17769 (let (date day defd)
17771 ((eq major-mode 'calendar-mode)
17772 (setq date (calendar-cursor-to-date)
17773 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
17774 ((eq major-mode 'org-agenda-mode)
17775 (setq day (get-text-property (point) 'day))
17777 (setq date (calendar-gregorian-from-absolute day)
17778 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
17780 (or defd (current-time))))
17782 (defvar org-agenda-action-marker (make-marker)
17783 "Marker pointing to the entry for the next agenda action.")
17785 (defun org-mark-entry-for-agenda-action ()
17786 "Mark the current entry as target of an agenda action.
17787 Agenda actions are actions executed from the agenda with the key `k',
17788 which make use of the date at the cursor."
17790 (move-marker org-agenda-action-marker
17791 (save-excursion (org-back-to-heading t) (point))
17794 "Entry marked for action; press `k' at desired date in agenda or calendar"))
17796 ;;; Paragraph filling stuff.
17797 ;; We want this to be just right, so use the full arsenal.
17799 (defun org-indent-line-function ()
17800 "Indent line like previous, but further if previous was headline or item."
17802 (let* ((pos (point))
17803 (itemp (org-at-item-p))
17804 (case-fold-search t)
17805 (org-drawer-regexp (or org-drawer-regexp "\000"))
17806 column bpos bcol tpos tcol bullet btype bullet-type)
17807 ;; Find the previous relevant line
17808 (beginning-of-line 1)
17810 ((looking-at "#") (setq column 0))
17811 ((looking-at "\\*+ ") (setq column 0))
17812 ((and (looking-at "[ \t]*:END:")
17813 (save-excursion (re-search-backward org-drawer-regexp nil t)))
17815 (goto-char (1- (match-beginning 1)))
17816 (setq column (current-column))))
17817 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
17819 (re-search-backward
17820 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
17821 (setq column (org-get-indentation (match-string 0))))
17823 (beginning-of-line 0)
17824 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
17825 (not (looking-at "[ \t]*:END:"))
17826 (not (looking-at org-drawer-regexp)))
17827 (beginning-of-line 0))
17829 ((looking-at "\\*+[ \t]+")
17830 (if (not org-adapt-indentation)
17832 (goto-char (match-end 0))
17833 (setq column (current-column))))
17834 ((looking-at org-drawer-regexp)
17835 (goto-char (1- (match-beginning 1)))
17836 (setq column (current-column)))
17837 ((looking-at "\\([ \t]*\\):END:")
17838 (goto-char (match-end 1))
17839 (setq column (current-column)))
17841 (org-beginning-of-item)
17842 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
17843 (setq bpos (match-beginning 1) tpos (match-end 0)
17844 bcol (progn (goto-char bpos) (current-column))
17845 tcol (progn (goto-char tpos) (current-column))
17846 bullet (match-string 1)
17847 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
17848 (if (> tcol (+ bcol org-description-max-indent))
17849 (setq tcol (+ bcol 5)))
17853 (beginning-of-line 1)
17854 (if (looking-at "\\S-")
17856 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
17857 (setq bullet (match-string 1)
17858 btype (if (string-match "[0-9]" bullet) "n" bullet))
17859 (setq column (if (equal btype bullet-type) bcol tcol)))
17860 (setq column (org-get-indentation)))))
17861 (t (setq column (org-get-indentation))))))
17863 (if (<= (current-column) (current-indentation))
17864 (org-indent-line-to column)
17865 (save-excursion (org-indent-line-to column)))
17866 (setq column (current-column))
17867 (beginning-of-line 1)
17869 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
17870 (replace-match (concat (match-string 1)
17871 (format org-property-format
17872 (match-string 2) (match-string 3)))
17874 (org-move-to-column column)))
17876 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
17877 "Variable to store copy of `adaptive-fill-regexp'.
17878 Since `adaptive-fill-regexp' is set to never match, we need to
17879 store a backup of its value before entering `org-mode' so that
17880 the functionality can be provided as a fall-back.")
17882 (defun org-set-autofill-regexps ()
17884 ;; In the paragraph separator we include headlines, because filling
17885 ;; text in a line directly attached to a headline would otherwise
17886 ;; fill the headline as well.
17887 (org-set-local 'comment-start-skip "^#+[ \t]*")
17888 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
17889 ;; The paragraph starter includes hand-formatted lists.
17897 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
17900 "\\\\\\(begin\\|end\\|[][]\\)"))
17901 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
17902 ;; But only if the user has not turned off tables or fixed-width regions
17904 'auto-fill-inhibit-regexp
17905 (concat "\\*+ \\|#\\+"
17906 "\\|[ \t]*" org-keyword-time-regexp
17907 (if (or org-enable-table-editor org-enable-fixed-width-editor)
17910 (if org-enable-table-editor "|" "")
17911 (if org-enable-fixed-width-editor ":" "")
17913 ;; We use our own fill-paragraph function, to make sure that tables
17914 ;; and fixed-width regions are not wrapped. That function will pass
17915 ;; through to `fill-paragraph' when appropriate.
17916 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
17917 ;; Adaptive filling: To get full control, first make sure that
17918 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
17919 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
17920 (org-set-local 'org-adaptive-fill-regexp-backup
17921 adaptive-fill-regexp))
17922 (org-set-local 'adaptive-fill-regexp "\000")
17923 (org-set-local 'adaptive-fill-function
17924 'org-adaptive-fill-function)
17926 'align-mode-rules-list
17927 '((org-in-buffer-settings
17928 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
17929 (modes . '(org-mode))))))
17931 (defun org-fill-paragraph (&optional justify)
17932 "Re-align a table, pass through to fill-paragraph if no table."
17933 (let ((table-p (org-at-table-p))
17934 (table.el-p (org-at-table.el-p)))
17935 (cond ((and (equal (char-after (point-at-bol)) ?*)
17936 (save-excursion (goto-char (point-at-bol))
17937 (looking-at outline-regexp)))
17938 t) ; skip headlines
17939 (table.el-p t) ; skip table.el tables
17940 (table-p (org-table-align) t) ; align org-mode tables
17941 (t nil)))) ; call paragraph-fill
17943 ;; For reference, this is the default value of adaptive-fill-regexp
17944 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
17946 (defun org-adaptive-fill-function ()
17947 "Return a fill prefix for org-mode files.
17948 In particular, this makes sure hanging paragraphs for hand-formatted lists
17952 ((looking-at "#[ \t]+")
17953 (match-string-no-properties 0))
17954 ;; Description list
17955 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
17957 (if (> (match-end 1) (+ (match-beginning 1)
17958 org-description-max-indent))
17959 (goto-char (+ (match-beginning 1) 5))
17960 (goto-char (match-end 0)))
17961 (make-string (current-column) ?\ )))
17962 ;; Ordered or unordered list
17963 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
17965 (goto-char (match-end 0))
17966 (make-string (current-column) ?\ )))
17968 ((looking-at org-adaptive-fill-regexp-backup)
17969 (match-string-no-properties 0))))
17973 (defun org-toggle-fixed-width-section (arg)
17974 "Toggle the fixed-width export.
17975 If there is no active region, the QUOTE keyword at the current headline is
17976 inserted or removed. When present, it causes the text between this headline
17977 and the next to be exported as fixed-width text, and unmodified.
17978 If there is an active region, this command adds or removes a colon as the
17979 first character of this line. If the first character of a line is a colon,
17980 this line is also exported in fixed-width font."
17983 (regionp (org-region-active-p))
17984 (beg (if regionp (region-beginning) (point)))
17985 (end (if regionp (region-end)))
17986 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
17987 (case-fold-search nil)
17988 (re "[ \t]*\\(: \\)")
17993 (setq cc (current-column))
17994 (beginning-of-line 1)
17995 (setq off (looking-at re))
17996 (while (> nlines 0)
17997 (setq nlines (1- nlines))
17998 (beginning-of-line 1)
18001 (org-move-to-column cc t)
18004 ((and off (looking-at re))
18005 (replace-match "" t t nil 1))
18006 ((not off) (org-move-to-column cc t) (insert ": ")))
18009 (org-back-to-heading)
18010 (if (looking-at (concat outline-regexp
18011 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
18012 (replace-match "" t t nil 1)
18013 (if (looking-at outline-regexp)
18015 (goto-char (match-end 0))
18016 (insert org-quote-string " "))))))))
18018 (defun org-reftex-citation ()
18019 "Use reftex-citation to insert a citation into the buffer.
18020 This looks for a line like
18022 #+BIBLIOGRAPHY: foo plain option:-d
18024 and derives from it that foo.bib is the bibliography file relevant
18025 for this document. It then installs the necessary environment for RefTeX
18026 to work in this buffer and calls `reftex-citation' to insert a citation
18029 Export of such citations to both LaTeX and HTML is handled by the contributed
18030 package org-exp-bibtex by Taru Karttunen."
18032 (let ((reftex-docstruct-symbol 'rds)
18033 (reftex-cite-format "\\cite{%l}")
18038 (let ((case-fold-search t)
18039 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
18040 (if (not (save-excursion
18041 (or (re-search-forward re nil t)
18042 (re-search-backward re nil t))))
18043 (error "No bibliography defined in file")
18044 (setq bib (concat (match-string 1) ".bib")
18045 rds (list (list 'bib bib)))))))
18046 (call-interactively 'reftex-citation)))
18048 ;;;; Functions extending outline functionality
18050 (defun org-beginning-of-line (&optional arg)
18051 "Go to the beginning of the current line. If that is invisible, continue
18052 to a visible line beginning. This makes the function of C-a more intuitive.
18053 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18054 first attempt, and only move to after the tags when the cursor is already
18055 beyond the end of the headline."
18057 (let ((pos (point))
18058 (special (if (consp org-special-ctrl-a/e)
18059 (car org-special-ctrl-a/e)
18060 org-special-ctrl-a/e))
18062 (if (org-bound-and-true-p line-move-visual)
18063 (beginning-of-visual-line 1)
18064 (beginning-of-line 1))
18065 (if (and arg (fboundp 'move-beginning-of-line))
18066 (call-interactively 'move-beginning-of-line)
18070 (if (org-invisible-p)
18071 (while (and (not (bobp)) (org-invisible-p))
18073 (beginning-of-line 1))
18074 (forward-char 1))))
18077 ((and (looking-at org-complex-heading-regexp)
18078 (= (char-after (match-end 1)) ?\ ))
18079 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
18083 (cond ((> pos refpos) refpos)
18084 ((= pos (point)) refpos)
18086 (cond ((> pos (point)) (point))
18087 ((not (eq last-command this-command)) (point))
18092 (cond ((> pos (match-end 4)) (match-end 4))
18093 ((= pos (point)) (match-end 4))
18095 (cond ((> pos (point)) (point))
18096 ((not (eq last-command this-command)) (point))
18097 (t (match-end 4))))))))
18099 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18101 (defun org-end-of-line (&optional arg)
18102 "Go to the end of the line.
18103 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18104 first attempt, and only move to after the tags when the cursor is already
18105 beyond the end of the headline."
18107 (let ((special (if (consp org-special-ctrl-a/e)
18108 (cdr org-special-ctrl-a/e)
18109 org-special-ctrl-a/e)))
18110 (if (or (not special)
18111 (not (org-on-heading-p))
18113 (call-interactively
18114 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
18115 ((fboundp 'move-end-of-line) 'move-end-of-line)
18117 (let ((pos (point)))
18118 (beginning-of-line 1)
18119 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
18121 (if (or (< pos (match-beginning 1))
18122 (= pos (match-end 0)))
18123 (goto-char (match-beginning 1))
18124 (goto-char (match-end 0)))
18125 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
18126 (goto-char (match-end 0))
18127 (goto-char (match-beginning 1))))
18128 (call-interactively (if (fboundp 'move-end-of-line)
18132 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18134 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
18135 (define-key org-mode-map "\C-e" 'org-end-of-line)
18136 (define-key org-mode-map [home] 'org-beginning-of-line)
18137 (define-key org-mode-map [end] 'org-end-of-line)
18139 (defun org-backward-sentence (&optional arg)
18140 "Go to beginning of sentence, or beginning of table field.
18141 This will call `backward-sentence' or `org-table-beginning-of-field',
18142 depending on context."
18145 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
18146 (t (call-interactively 'backward-sentence))))
18148 (defun org-forward-sentence (&optional arg)
18149 "Go to end of sentence, or end of table field.
18150 This will call `forward-sentence' or `org-table-end-of-field',
18151 depending on context."
18154 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
18155 (t (call-interactively 'forward-sentence))))
18157 (define-key org-mode-map "\M-a" 'org-backward-sentence)
18158 (define-key org-mode-map "\M-e" 'org-forward-sentence)
18160 (defun org-kill-line (&optional arg)
18161 "Kill line, to tags or end of line."
18164 ((or (not org-special-ctrl-k)
18166 (not (org-on-heading-p)))
18167 (call-interactively 'kill-line))
18168 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
18169 (kill-region (point) (match-beginning 1))
18170 (org-set-tags nil t))
18171 (t (kill-region (point) (point-at-eol)))))
18173 (define-key org-mode-map "\C-k" 'org-kill-line)
18175 (defun org-yank (&optional arg)
18176 "Yank. If the kill is a subtree, treat it specially.
18177 This command will look at the current kill and check if is a single
18178 subtree, or a series of subtrees[1]. If it passes the test, and if the
18179 cursor is at the beginning of a line or after the stars of a currently
18180 empty headline, then the yank is handled specially. How exactly depends
18181 on the value of the following variables, both set by default.
18183 org-yank-folded-subtrees
18184 When set, the subtree(s) will be folded after insertion, but only
18185 if doing so would now swallow text after the yanked text.
18187 org-yank-adjusted-subtrees
18188 When set, the subtree will be promoted or demoted in order to
18189 fit into the local outline tree structure, which means that the level
18190 will be adjusted so that it becomes the smaller one of the two
18191 *visible* surrounding headings.
18193 Any prefix to this command will cause `yank' to be called directly with
18194 no special treatment. In particular, a simple `C-u' prefix will just
18195 plainly yank the text as it is.
18197 \[1] The test checks if the first non-white line is a heading
18198 and if there are no other headings with fewer stars."
18200 (org-yank-generic 'yank arg))
18202 (defun org-yank-generic (command arg)
18203 "Perform some yank-like command.
18205 This function implements the behavior described in the `org-yank'
18206 documentation. However, it has been generalized to work for any
18207 interactive command with similar behavior."
18209 ;; pretend to be command COMMAND
18210 (setq this-command command)
18213 (call-interactively command)
18215 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18216 (and (org-kill-is-subtree-p)
18218 (and (looking-at "[ \t]*$")
18221 (buffer-substring (point-at-bol) (point)))))))
18224 ((and subtreep org-yank-folded-subtrees)
18225 (let ((beg (point))
18227 (if (and subtreep org-yank-adjusted-subtrees)
18228 (org-paste-subtree nil nil 'for-yank)
18229 (call-interactively command))
18233 (when (and (bolp) subtreep
18234 (not (setq swallowp
18235 (org-yank-folding-would-swallow-text beg end))))
18236 (or (looking-at outline-regexp)
18237 (re-search-forward (concat "^" outline-regexp) end t))
18238 (while (and (< (point) end) (looking-at outline-regexp))
18240 (org-cycle-show-empty-lines 'folded)
18241 (condition-case nil
18242 (outline-forward-same-level 1)
18243 (error (goto-char end)))))
18246 "Inserted text not folded because that would swallow text"))
18249 (skip-chars-forward " \t\n\r")
18250 (beginning-of-line 1)
18251 (push-mark beg 'nomsg)))
18252 ((and subtreep org-yank-adjusted-subtrees)
18253 (let ((beg (point-at-bol)))
18254 (org-paste-subtree nil nil 'for-yank)
18255 (push-mark beg 'nomsg)))
18257 (call-interactively command))))))
18259 (defun org-yank-folding-would-swallow-text (beg end)
18260 "Would hide-subtree at BEG swallow any text after END?"
18264 (when (or (looking-at outline-regexp)
18265 (re-search-forward (concat "^" outline-regexp) end t))
18266 (setq level (org-outline-level)))
18268 (skip-chars-forward " \t\r\n\v\f")
18270 (and (bolp) (looking-at org-outline-regexp)
18271 (<= (org-outline-level) level)))
18272 nil ; Nothing would be swallowed
18273 t)))) ; something would swallow
18275 (define-key org-mode-map "\C-y" 'org-yank)
18277 (defun org-invisible-p ()
18278 "Check if point is at a character currently not visible."
18279 ;; Early versions of noutline don't have `outline-invisible-p'.
18280 (if (fboundp 'outline-invisible-p)
18281 (outline-invisible-p)
18282 (get-char-property (point) 'invisible)))
18284 (defun org-invisible-p2 ()
18285 "Check if point is at a character currently not visible."
18287 (if (and (eolp) (not (bobp))) (backward-char 1))
18288 ;; Early versions of noutline don't have `outline-invisible-p'.
18289 (if (fboundp 'outline-invisible-p)
18290 (outline-invisible-p)
18291 (get-char-property (point) 'invisible))))
18293 (defun org-back-to-heading (&optional invisible-ok)
18294 "Call `outline-back-to-heading', but provide a better error message."
18295 (condition-case nil
18296 (outline-back-to-heading invisible-ok)
18297 (error (error "Before first headline at position %d in buffer %s"
18298 (point) (current-buffer)))))
18300 (defun org-before-first-heading-p ()
18301 "Before first heading?"
18303 (null (re-search-backward "^\\*+ " nil t))))
18305 (defun org-on-heading-p (&optional ignored)
18306 (outline-on-heading-p t))
18307 (defun org-at-heading-p (&optional ignored)
18308 (outline-on-heading-p t))
18310 (defun org-point-at-end-of-empty-headline ()
18311 "If point is at the end of an empty headline, return t, else nil.
18312 If the heading only contains a TODO keyword, it is still still considered
18314 (and (looking-at "[ \t]*$")
18316 (beginning-of-line 1)
18317 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18319 (defun org-at-heading-or-item-p ()
18320 (or (org-on-heading-p) (org-at-item-p)))
18322 (defun org-on-target-p ()
18323 (or (org-in-regexp org-radio-target-regexp)
18324 (org-in-regexp org-target-regexp)))
18326 (defun org-up-heading-all (arg)
18327 "Move to the heading line of which the present line is a subheading.
18328 This function considers both visible and invisible heading lines.
18329 With argument, move up ARG levels."
18330 (if (fboundp 'outline-up-heading-all)
18331 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18332 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18334 (defun org-up-heading-safe ()
18335 "Move to the heading line of which the present line is a subheading.
18336 This version will not throw an error. It will return the level of the
18337 headline found, or nil if no higher level is found.
18339 Also, this function will be a lot faster than `outline-up-heading',
18340 because it relies on stars being the outline starters. This can really
18341 make a significant difference in outlines with very many siblings."
18342 (let (start-level re)
18343 (org-back-to-heading t)
18344 (setq start-level (funcall outline-level))
18345 (if (equal start-level 1)
18347 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18348 (if (re-search-backward re nil t)
18349 (funcall outline-level)))))
18351 (defun org-first-sibling-p ()
18352 "Is this heading the first child of its parents?"
18354 (let ((re (concat "^" outline-regexp))
18356 (unless (org-at-heading-p t)
18357 (error "Not at a heading"))
18358 (setq level (funcall outline-level))
18360 (if (not (re-search-backward re nil t))
18362 (setq l (funcall outline-level))
18365 (defun org-goto-sibling (&optional previous)
18366 "Goto the next sibling, even if it is invisible.
18367 When PREVIOUS is set, go to the previous sibling instead. Returns t
18368 when a sibling was found. When none is found, return nil and don't
18370 (let ((fun (if previous 're-search-backward 're-search-forward))
18372 (re (concat "^" outline-regexp))
18374 (when (condition-case nil (org-back-to-heading t) (error nil))
18375 (setq level (funcall outline-level))
18377 (or previous (forward-char 1))
18378 (while (funcall fun re nil t)
18379 (setq l (funcall outline-level))
18380 (when (< l level) (goto-char pos) (throw 'exit nil))
18381 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18385 (defun org-show-siblings ()
18386 "Show all siblings of the current headline."
18388 (while (org-goto-sibling) (org-flag-heading nil)))
18390 (while (org-goto-sibling 'previous)
18391 (org-flag-heading nil))))
18393 (defun org-show-hidden-entry ()
18394 "Show an entry where even the heading is hidden."
18398 (defun org-flag-heading (flag &optional entry)
18399 "Flag the current heading. FLAG non-nil means make invisible.
18400 When ENTRY is non-nil, show the entire entry."
18402 (org-back-to-heading t)
18403 ;; Check if we should show the entire entry
18408 (and (outline-next-heading)
18409 (org-flag-heading nil))))
18410 (outline-flag-region (max (point-min) (1- (point)))
18411 (save-excursion (outline-end-of-heading) (point))
18414 (defun org-get-next-sibling ()
18415 "Move to next heading of the same level, and return point.
18416 If there is no such heading, return nil.
18417 This is like outline-next-sibling, but invisible headings are ok."
18418 (let ((level (funcall outline-level)))
18419 (outline-next-heading)
18420 (while (and (not (eobp)) (> (funcall outline-level) level))
18421 (outline-next-heading))
18422 (if (or (eobp) (< (funcall outline-level) level))
18426 (defun org-get-last-sibling ()
18427 "Move to previous heading of the same level, and return point.
18428 If there is no such heading, return nil."
18429 (let ((opoint (point))
18430 (level (funcall outline-level)))
18431 (outline-previous-heading)
18432 (when (and (/= (point) opoint) (outline-on-heading-p t))
18433 (while (and (> (funcall outline-level) level)
18435 (outline-previous-heading))
18436 (if (< (funcall outline-level) level)
18440 (defun org-end-of-subtree (&optional invisible-OK to-heading)
18441 ;; This contains an exact copy of the original function, but it uses
18442 ;; `org-back-to-heading', to make it work also in invisible
18443 ;; trees. And is uses an invisible-OK argument.
18444 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
18445 ;; Furthermore, when used inside Org, finding the end of a large subtree
18446 ;; with many children and grandchildren etc, this can be much faster
18447 ;; than the outline version.
18448 (org-back-to-heading invisible-OK)
18450 (level (funcall outline-level)))
18451 (if (and (org-mode-p) (< level 1000))
18452 ;; A true heading (not a plain list item), in Org-mode
18453 ;; This means we can easily find the end by looking
18454 ;; only for the right number of stars. Using a regexp to do
18455 ;; this is so much faster than using a Lisp loop.
18456 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
18458 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
18459 ;; something else, do it the slow way
18460 (while (and (not (eobp))
18461 (or first (> (funcall outline-level) level)))
18463 (outline-next-heading)))
18465 (if (memq (preceding-char) '(?\n ?\^M))
18467 ;; Go to end of line before heading
18469 (if (memq (preceding-char) '(?\n ?\^M))
18470 ;; leave blank line before heading
18471 (forward-char -1))))))
18474 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
18475 "Use Org version in org-mode, for dramatic speed-up."
18476 (if (eq major-mode 'org-mode)
18478 (org-end-of-subtree nil t)
18479 (unless (eobp) (backward-char 1)))
18482 (defun org-forward-same-level (arg &optional invisible-ok)
18483 "Move forward to the arg'th subheading at same level as this one.
18484 Stop at the first and last subheadings of a superior heading."
18486 (org-back-to-heading invisible-ok)
18488 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18489 (re (format "^\\*\\{1,%d\\} " level))
18493 (while (and (re-search-forward re nil 'move)
18494 (setq l (- (match-end 0) (match-beginning 0) 1))
18497 (progn (backward-char 1) (org-invisible-p)))
18498 (if (< l level) (setq arg 1)))
18499 (setq arg (1- arg)))
18500 (beginning-of-line 1)))
18502 (defun org-backward-same-level (arg &optional invisible-ok)
18503 "Move backward to the arg'th subheading at same level as this one.
18504 Stop at the first and last subheadings of a superior heading."
18506 (org-back-to-heading)
18508 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18509 (re (format "^\\*\\{1,%d\\} " level))
18512 (while (and (re-search-backward re nil 'move)
18513 (setq l (- (match-end 0) (match-beginning 0) 1))
18517 (if (< l level) (setq arg 1)))
18518 (setq arg (1- arg)))))
18520 (defun org-show-subtree ()
18521 "Show everything after this heading at deeper levels."
18522 (outline-flag-region
18525 (org-end-of-subtree t t))
18528 (defun org-show-entry ()
18529 "Show the body directly following this heading.
18530 Show the heading too, if it is currently invisible."
18533 (condition-case nil
18535 (org-back-to-heading t)
18536 (outline-flag-region
18537 (max (point-min) (1- (point)))
18539 (if (re-search-forward
18540 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
18541 (match-beginning 1)
18544 (org-cycle-hide-drawers 'children))
18547 (defun org-make-options-regexp (kwds &optional extra)
18548 "Make a regular expression for keyword lines."
18552 (mapconcat 'regexp-quote kwds "\\|")
18553 (if extra (concat "\\|" extra))
18557 ;; Make isearch reveal the necessary context
18558 (defun org-isearch-end ()
18559 "Reveal context after isearch exits."
18560 (when isearch-success ; only if search was successful
18561 (if (featurep 'xemacs)
18562 ;; Under XEmacs, the hook is run in the correct place,
18563 ;; we directly show the context.
18564 (org-show-context 'isearch)
18565 ;; In Emacs the hook runs *before* restoring the overlays.
18566 ;; So we have to use a one-time post-command-hook to do this.
18567 ;; (Emacs 22 has a special variable, see function `org-mode')
18568 (unless (and (boundp 'isearch-mode-end-hook-quit)
18569 isearch-mode-end-hook-quit)
18570 ;; Only when the isearch was not quitted.
18571 (org-add-hook 'post-command-hook 'org-isearch-post-command
18572 'append 'local)))))
18574 (defun org-isearch-post-command ()
18575 "Remove self from hook, and show context."
18576 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
18577 (org-show-context 'isearch))
18580 ;;;; Integration with and fixes for other packages
18584 (defvar org-imenu-markers nil
18585 "All markers currently used by Imenu.")
18586 (make-variable-buffer-local 'org-imenu-markers)
18588 (defun org-imenu-new-marker (&optional pos)
18589 "Return a new marker for use by Imenu, and remember the marker."
18590 (let ((m (make-marker)))
18591 (move-marker m (or pos (point)))
18592 (push m org-imenu-markers)
18595 (defun org-imenu-get-tree ()
18596 "Produce the index for Imenu."
18597 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
18598 (setq org-imenu-markers nil)
18599 (let* ((n org-imenu-depth)
18600 (re (concat "^" outline-regexp))
18601 (subs (make-vector (1+ n) nil))
18607 (goto-char (point-max))
18608 (while (re-search-backward re nil t)
18609 (setq level (org-reduced-level (funcall outline-level)))
18611 (looking-at org-complex-heading-regexp)
18612 (setq head (org-link-display-format
18613 (org-match-string-no-properties 4))
18614 m (org-imenu-new-marker))
18615 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
18616 (if (>= level last-level)
18617 (push (cons head m) (aref subs level))
18618 (push (cons head (aref subs (1+ level))) (aref subs level))
18619 (loop for i from (1+ level) to n do (aset subs i nil)))
18620 (setq last-level level)))))
18623 (eval-after-load "imenu"
18625 (add-hook 'imenu-after-jump-hook
18627 (if (eq major-mode 'org-mode)
18628 (org-show-context 'org-goto))))))
18630 (defun org-link-display-format (link)
18631 "Replace a link with either the description, or the link target
18632 if no description is present"
18634 (if (string-match org-bracket-link-analytic-regexp link)
18635 (replace-match (if (match-end 5)
18636 (match-string 5 link)
18637 (concat (match-string 1 link)
18638 (match-string 3 link)))
18642 ;; Speedbar support
18644 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
18645 "Overlay marking the agenda restriction line in speedbar.")
18646 (overlay-put org-speedbar-restriction-lock-overlay
18647 'face 'org-agenda-restriction-lock)
18648 (overlay-put org-speedbar-restriction-lock-overlay
18649 'help-echo "Agendas are currently limited to this item.")
18650 (org-detach-overlay org-speedbar-restriction-lock-overlay)
18652 (defun org-speedbar-set-agenda-restriction ()
18653 "Restrict future agenda commands to the location at point in speedbar.
18654 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
18656 (require 'org-agenda)
18657 (let (p m tp np dir txt)
18659 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18661 (setq m (get-text-property p 'org-imenu-marker))
18662 (with-current-buffer (marker-buffer m)
18664 (org-agenda-set-restriction-lock 'subtree)))
18665 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18666 'speedbar-function 'speedbar-find-file))
18667 (setq tp (previous-single-property-change
18668 (1+ p) 'speedbar-function)
18669 np (next-single-property-change
18670 tp 'speedbar-function)
18671 dir (speedbar-line-directory)
18672 txt (buffer-substring-no-properties (or tp (point-min))
18673 (or np (point-max))))
18674 (with-current-buffer (find-file-noselect
18675 (let ((default-directory dir))
18676 (expand-file-name txt)))
18677 (unless (org-mode-p)
18678 (error "Cannot restrict to non-Org-mode file"))
18679 (org-agenda-set-restriction-lock 'file)))
18680 (t (error "Don't know how to restrict Org-mode's agenda")))
18681 (move-overlay org-speedbar-restriction-lock-overlay
18682 (point-at-bol) (point-at-eol))
18683 (setq current-prefix-arg nil)
18684 (org-agenda-maybe-redo)))
18686 (eval-after-load "speedbar"
18688 (speedbar-add-supported-extension ".org")
18689 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
18690 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
18691 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
18692 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
18693 (add-hook 'speedbar-visiting-tag-hook
18694 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
18696 ;;; Fixes and Hacks for problems with other packages
18698 ;; Make flyspell not check words in links, to not mess up our keymap
18699 (defun org-mode-flyspell-verify ()
18700 "Don't let flyspell put overlays at active buttons."
18701 (and (not (get-text-property (point) 'keymap))
18702 (not (get-text-property (point) 'org-no-flyspell))))
18704 (defun org-remove-flyspell-overlays-in (beg end)
18705 "Remove flyspell overlays in region."
18706 (and (org-bound-and-true-p flyspell-mode)
18707 (fboundp 'flyspell-delete-region-overlays)
18708 (flyspell-delete-region-overlays beg end))
18709 (add-text-properties beg end '(org-no-flyspell t)))
18711 ;; Make `bookmark-jump' shows the jump location if it was hidden.
18712 (eval-after-load "bookmark"
18713 '(if (boundp 'bookmark-after-jump-hook)
18714 ;; We can use the hook
18715 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
18716 ;; Hook not available, use advice
18717 (defadvice bookmark-jump (after org-make-visible activate)
18718 "Make the position visible."
18719 (org-bookmark-jump-unhide))))
18721 ;; Make sure saveplace shows the location if it was hidden
18722 (eval-after-load "saveplace"
18723 '(defadvice save-place-find-file-hook (after org-make-visible activate)
18724 "Make the position visible."
18725 (org-bookmark-jump-unhide)))
18727 ;; Make sure ecb shows the location if it was hidden
18728 (eval-after-load "ecb"
18729 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
18730 "Make hierarchy visible when jumping into location from ECB tree buffer."
18731 (if (eq major-mode 'org-mode)
18732 (org-show-context))))
18734 (defun org-bookmark-jump-unhide ()
18735 "Unhide the current position, to show the bookmark location."
18737 (or (org-invisible-p)
18738 (save-excursion (goto-char (max (point-min) (1- (point))))
18739 (org-invisible-p)))
18740 (org-show-context 'bookmark-jump)))
18742 ;; Make session.el ignore our circular variable
18743 (eval-after-load "session"
18744 '(add-to-list 'session-globals-exclude 'org-mark-ring))
18746 ;;;; Experimental code
18748 (defun org-closed-in-range ()
18749 "Sparse tree of items closed in a certain time range.
18750 Still experimental, may disappear in the future."
18752 ;; Get the time interval from the user.
18753 (let* ((time1 (org-float-time
18754 (org-read-date nil 'to-time nil "Starting date: ")))
18755 (time2 (org-float-time
18756 (org-read-date nil 'to-time nil "End date:")))
18757 ;; callback function
18758 (callback (lambda ()
18761 (apply 'encode-time
18762 (org-parse-time-string
18763 (match-string 1))))))
18764 ;; check if time in interval
18765 (and (>= time time1) (<= time time2))))))
18766 ;; make tree, check each match with the callback
18767 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
18773 (run-hooks 'org-load-hook)
18775 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
18777 ;;; org.el ends here