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
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
77 ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
78 ;; the file noutline.el being loaded.
79 (if (featurep 'xemacs
) (condition-case nil
(require 'noutline
)))
80 ;; We require noutline, which might be provided in outline.el
81 (require 'outline
) (require 'noutline
)
82 ;; Other stuff we need.
84 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
91 (require 'org-footnote
)
93 ;;;; Customization variables
97 (defconst org-version
"6.23trans"
98 "The version number of the file org.el.")
100 (defun org-version (&optional here
)
101 "Show the org-mode version in the echo area.
102 With prefix arg HERE, insert it at point."
104 (let ((version (format "Org-mode version %s" org-version
)))
109 ;;; Compatibility constants
111 ;;; The custom variables
114 "Outline-based notes management and organizer."
120 (defcustom org-load-hook nil
121 "Hook that is run after org.el has been loaded."
125 (defvar org-modules
) ; defined below
126 (defvar org-modules-loaded nil
127 "Have the modules been loaded already?")
129 (defun org-load-modules-maybe (&optional force
)
130 "Load all extensions listed in `org-modules'."
131 (when (or force
(not org-modules-loaded
))
133 (condition-case nil
(require ext
)
134 (error (message "Problems while trying to load feature `%s'" ext
))))
136 (setq org-modules-loaded t
)))
138 (defun org-set-modules (var value
)
139 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
141 (when (featurep 'org
)
142 (org-load-modules-maybe 'force
)))
144 (when (org-bound-and-true-p org-modules
)
145 (let ((a (member 'org-infojs org-modules
)))
146 (and a
(setcar a
'org-jsinfo
))))
148 (defcustom org-modules
'(org-bbdb org-bibtex org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-w3m org-wl
)
149 "Modules that should always be loaded together with org.el.
150 If a description starts with <C>, the file is not part of Emacs
151 and loading it will require that you have downloaded and properly installed
152 the org-mode distribution.
154 You can also use this system to load external packages (i.e. neither Org
155 core modules, not modules from the CONTRIB directory). Just add symbols
156 to the end of the list. If the package is called org-xyz.el, then you need
157 to add the symbol `xyz', and the package must have a call to
161 :set
'org-set-modules
164 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
165 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
166 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
167 (const :tag
" id: Global IDs for identifying entries" org-id
)
168 (const :tag
" info: Links to Info nodes" org-info
)
169 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
170 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
171 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
172 (const :tag
" mew Links to Mew folders/messages" org-mew
)
173 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
174 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
175 (const :tag
" vm: Links to VM folders/messages" org-vm
)
176 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
177 (const :tag
" w3m: Special cut/past from w3m to Org." org-w3m
)
178 (const :tag
" mouse: Additional mouse support" org-mouse
)
180 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
181 (const :tag
"C annotation-helper: Call Remember directly from Browser" org-annotation-helper
)
182 (const :tag
"C bookmark: Org links to bookmarks" org-bookmark
)
183 (const :tag
"C browser-url: Store link, directly from Browser" org-browser-url
)
184 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
185 (const :tag
"C depend: TODO dependencies for Org-mode" org-depend
)
186 (const :tag
"C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol
)
187 (const :tag
"C eval: Include command output as text" org-eval
)
188 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
189 (const :tag
"C expiry: Expiry mechanism for Org entries" org-expiry
)
190 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
191 (const :tag
"C exp-blocks: Pre-process blocks for export" org-exp-blocks
)
192 (const :tag
"C interactive-query: Interactive modification of tags query" org-interactive-query
)
193 (const :tag
"C mairix: Hook mairix search into Org for different MUAs" org-mairix
)
194 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
195 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
196 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
197 (const :tag
"C R: Computation using the R language" org-R
)
198 (const :tag
"C registry: A registry for Org links" org-registry
)
199 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
200 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
201 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
202 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
203 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
205 (defcustom org-support-shift-select nil
206 "Non-nil means, make shift-cursor commands select text when possible.
208 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
209 selecting a region, or enlarge thusly regions started in this way.
210 In Org-mode, in special contexts, these same keys are used for other
211 purposes, important enough to compete with shift selection. Org tries
212 to balance these needs by supporting `shift-select-mode' outside these
213 special contexts, under control of this variable.
215 The default of this variable is nil, to avoid confusing behavior. Shifted
216 cursor keys will then execute Org commands in the following contexts:
217 - on a headline, changing TODO state (left/right) and priority (up/down)
218 - on a time stamp, changing the time
219 - in a plain list item, changing the bullet type
220 - in a property definition line, switching between allowed values
221 - in the BEGIN line of a clock table (changing the time block).
222 Outside these contexts, the commands will throw an error.
224 When this variable is t and the cursor is not in a special context,
225 Org-mode will support shift-selection for making and enlarging regions.
226 To make this more effective, the bullet cycling will no longer happen
227 anywhere in an item line, but only if the cursor is exactly on the bullet.
229 If you set this variable to the symbol `always', then the keys
230 will not be special in headlines, property lines, and item lines, to make
231 shift selection work there as well. If this is what you want, you can
232 use the following alternative commands: `C-c C-t' and `C-c ,' to
233 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
234 TODO sets, `C-c -' to cycle item bullet types, and properties can be
235 edited by hand or in column view.
237 However, when the cursor is on a timestamp, shift-cursor commands
238 will still edit the time stamp - this is just too good to give up.
240 XEmacs user should have this variable set to nil, because shift-select-mode
244 (const :tag
"Never" nil
)
245 (const :tag
"When outside special context" t
)
246 (const :tag
"Everywhere except timestamps" always
)))
248 (defgroup org-startup nil
249 "Options concerning startup of Org-mode."
253 (defcustom org-startup-folded t
254 "Non-nil means, entering Org-mode will switch to OVERVIEW.
255 This can also be configured on a per-file basis by adding one of
256 the following lines anywhere in the buffer:
263 (const :tag
"nofold: show all" nil
)
264 (const :tag
"fold: overview" t
)
265 (const :tag
"content: all headlines" content
)))
267 (defcustom org-startup-truncated t
268 "Non-nil means, entering Org-mode will set `truncate-lines'.
269 This is useful since some lines containing links can be very long and
270 uninteresting. Also tables look terrible when wrapped."
274 (defcustom org-startup-align-all-tables nil
275 "Non-nil means, align all tables when visiting a file.
276 This is useful when the column width in tables is forced with <N> cookies
277 in table fields. Such tables will look correct only after the first re-align.
278 This can also be configured on a per-file basis by adding one of
279 the following lines anywhere in the buffer:
285 (defcustom org-insert-mode-line-in-empty-file nil
286 "Non-nil means insert the first line setting Org-mode in empty files.
287 When the function `org-mode' is called interactively in an empty file, this
288 normally means that the file name does not automatically trigger Org-mode.
289 To ensure that the file will always be in Org-mode in the future, a
290 line enforcing Org-mode will be inserted into the buffer, if this option
295 (defcustom org-replace-disputed-keys nil
296 "Non-nil means use alternative key bindings for some keys.
297 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
298 These keys are also used by other packages like `CUA-mode' or `windmove.el'.
299 If you want to use Org-mode together with one of these other modes,
300 or more generally if you would like to move some Org-mode commands to
301 other keys, set this variable and configure the keys with the variable
304 This option is only relevant at load-time of Org-mode, and must be set
305 *before* org.el is loaded. Changing it requires a restart of Emacs to
310 (defcustom org-use-extra-keys nil
311 "Non-nil means use extra key sequence definitions for certain
312 commands. This happens automatically if you run XEmacs or if
313 window-system is nil. This variable lets you do the same
314 manually. You must set it before loading org.
316 Example: on Carbon Emacs 22 running graphically, with an external
317 keyboard on a Powerbook, the default way of setting M-left might
318 not work for either Alt or ESC. Setting this variable will make
323 (if (fboundp 'defvaralias
)
324 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
326 (defcustom org-disputed-keys
327 '(([(shift up
)] .
[(meta p
)])
328 ([(shift down
)] .
[(meta n
)])
329 ([(shift left
)] .
[(meta -
)])
330 ([(shift right
)] .
[(meta +)])
331 ([(control shift right
)] .
[(meta shift
+)])
332 ([(control shift left
)] .
[(meta shift -
)]))
333 "Keys for which Org-mode and other modes compete.
334 This is an alist, cars are the default keys, second element specifies
335 the alternative to use when `org-replace-disputed-keys' is t.
337 Keys can be specified in any syntax supported by `define-key'.
338 The value of this option takes effect only at Org-mode's startup,
339 therefore you'll have to restart Emacs to apply it after changing."
344 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
345 Or return the original if not disputed."
346 (if org-replace-disputed-keys
347 (let* ((nkey (key-description key
))
348 (x (org-find-if (lambda (x)
349 (equal (key-description (car x
)) nkey
))
354 (defun org-find-if (predicate seq
)
357 (if (funcall predicate
(car seq
))
358 (throw 'exit
(car seq
))
361 (defun org-defkey (keymap key def
)
362 "Define a key, possibly translated, as returned by `org-key'."
363 (define-key keymap
(org-key key
) def
))
365 (defcustom org-ellipsis nil
366 "The ellipsis to use in the Org-mode outline.
367 When nil, just use the standard three dots. When a string, use that instead,
368 When a face, use the standard 3 dots, but with the specified face.
369 The change affects only Org-mode (which will then use its own display table).
370 Changing this requires executing `M-x org-mode' in a buffer to become
373 :type
'(choice (const :tag
"Default" nil
)
374 (face :tag
"Face" :value org-warning
)
375 (string :tag
"String" :value
"...#")))
377 (defvar org-display-table nil
378 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
380 (defgroup org-keywords nil
381 "Keywords in Org-mode."
385 (defcustom org-deadline-string
"DEADLINE:"
386 "String to mark deadline entries.
387 A deadline is this string, followed by a time stamp. Should be a word,
388 terminated by a colon. You can insert a schedule keyword and
389 a timestamp with \\[org-deadline].
390 Changes become only effective after restarting Emacs."
394 (defcustom org-scheduled-string
"SCHEDULED:"
395 "String to mark scheduled TODO entries.
396 A schedule is this string, followed by a time stamp. Should be a word,
397 terminated by a colon. You can insert a schedule keyword and
398 a timestamp with \\[org-schedule].
399 Changes become only effective after restarting Emacs."
403 (defcustom org-closed-string
"CLOSED:"
404 "String used as the prefix for timestamps logging closing a TODO entry."
408 (defcustom org-clock-string
"CLOCK:"
409 "String used as prefix for timestamps clocking work hours on an item."
413 (defcustom org-comment-string
"COMMENT"
414 "Entries starting with this keyword will never be exported.
415 An entry can be toggled between COMMENT and normal with
416 \\[org-toggle-comment].
417 Changes become only effective after restarting Emacs."
421 (defcustom org-quote-string
"QUOTE"
422 "Entries starting with this keyword will be exported in fixed-width font.
423 Quoting applies only to the text in the entry following the headline, and does
424 not extend beyond the next headline, even if that is lower level.
425 An entry can be toggled between QUOTE and normal with
426 \\[org-toggle-fixed-width-section]."
430 (defconst org-repeat-re
431 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*\\([.+]?\\+[0-9]+[dwmy]\\)"
432 "Regular expression for specifying repeated events.
433 After a match, group 1 contains the repeat expression.")
435 (defgroup org-structure nil
436 "Options concerning the general structure of Org-mode files."
440 (defgroup org-reveal-location nil
441 "Options about how to make context of a location visible."
442 :tag
"Org Reveal Location"
443 :group
'org-structure
)
445 (defconst org-context-choice
447 (const :tag
"Always" t
)
448 (const :tag
"Never" nil
)
449 (repeat :greedy t
:tag
"Individual contexts"
451 (choice :tag
"Context"
458 (const bookmark-jump
)
462 "Contexts for the reveal options.")
464 (defcustom org-show-hierarchy-above
'((default . t
))
465 "Non-nil means, show full hierarchy when revealing a location.
466 Org-mode often shows locations in an org-mode file which might have
467 been invisible before. When this is set, the hierarchy of headings
468 above the exposed location is shown.
469 Turning this off for example for sparse trees makes them very compact.
470 Instead of t, this can also be an alist specifying this option for different
471 contexts. Valid contexts are
472 agenda when exposing an entry from the agenda
473 org-goto when using the command `org-goto' on key C-c C-j
474 occur-tree when using the command `org-occur' on key C-c /
475 tags-tree when constructing a sparse tree based on tags matches
476 link-search when exposing search matches associated with a link
477 mark-goto when exposing the jump goal of a mark
478 bookmark-jump when exposing a bookmark location
479 isearch when exiting from an incremental search
480 default default for all contexts not set explicitly"
481 :group
'org-reveal-location
482 :type org-context-choice
)
484 (defcustom org-show-following-heading
'((default . nil
))
485 "Non-nil means, show following heading when revealing a location.
486 Org-mode often shows locations in an org-mode file which might have
487 been invisible before. When this is set, the heading following the
489 Turning this off for example for sparse trees makes them very compact,
490 but makes it harder to edit the location of the match. In such a case,
491 use the command \\[org-reveal] to show more context.
492 Instead of t, this can also be an alist specifying this option for different
493 contexts. See `org-show-hierarchy-above' for valid contexts."
494 :group
'org-reveal-location
495 :type org-context-choice
)
497 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
498 "Non-nil means, show all sibling heading when revealing a location.
499 Org-mode often shows locations in an org-mode file which might have
500 been invisible before. When this is set, the sibling of the current entry
501 heading are all made visible. If `org-show-hierarchy-above' is t,
502 the same happens on each level of the hierarchy above the current entry.
504 By default this is on for the isearch context, off for all other contexts.
505 Turning this off for example for sparse trees makes them very compact,
506 but makes it harder to edit the location of the match. In such a case,
507 use the command \\[org-reveal] to show more context.
508 Instead of t, this can also be an alist specifying this option for different
509 contexts. See `org-show-hierarchy-above' for valid contexts."
510 :group
'org-reveal-location
511 :type org-context-choice
)
513 (defcustom org-show-entry-below
'((default . nil
))
514 "Non-nil means, show the entry below a headline when revealing a location.
515 Org-mode often shows locations in an org-mode file which might have
516 been invisible before. When this is set, the text below the headline that is
517 exposed is also shown.
519 By default this is off for all contexts.
520 Instead of t, this can also be an alist specifying this option for different
521 contexts. See `org-show-hierarchy-above' for valid contexts."
522 :group
'org-reveal-location
523 :type org-context-choice
)
525 (defcustom org-indirect-buffer-display
'other-window
526 "How should indirect tree buffers be displayed?
527 This applies to indirect buffers created with the commands
528 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
530 current-window Display in the current window
531 other-window Just display in another window.
532 dedicated-frame Create one new frame, and re-use it each time.
533 new-frame Make a new frame each time. Note that in this case
534 previously-made indirect buffers are kept, and you need to
535 kill these buffers yourself."
536 :group
'org-structure
537 :group
'org-agenda-windows
539 (const :tag
"In current window" current-window
)
540 (const :tag
"In current frame, other window" other-window
)
541 (const :tag
"Each time a new frame" new-frame
)
542 (const :tag
"One dedicated frame" dedicated-frame
)))
544 (defgroup org-cycle nil
545 "Options concerning visibility cycling in Org-mode."
547 :group
'org-structure
)
549 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
550 "Names of drawers. Drawers are not opened by cycling on the headline above.
551 Drawers only open with a TAB on the drawer line itself. A drawer looks like
556 The drawer \"PROPERTIES\" is special for capturing properties through
559 Drawers can be defined on the per-file basis with a line like:
561 #+DRAWERS: HIDDEN STATE PROPERTIES"
562 :group
'org-structure
563 :type
'(repeat (string :tag
"Drawer Name")))
565 (defcustom org-cycle-global-at-bob nil
566 "Cycle globally if cursor is at beginning of buffer and not at a headline.
567 This makes it possible to do global cycling without having to use S-TAB or
568 C-u TAB. For this special case to work, the first line of the buffer
569 must not be a headline - it may be empty or some other text. When used in
570 this way, `org-cycle-hook' is disables temporarily, to make sure the
571 cursor stays at the beginning of the buffer.
572 When this option is nil, don't do anything special at the beginning
577 (defcustom org-cycle-emulate-tab t
578 "Where should `org-cycle' emulate TAB.
580 white Only in completely white lines
581 whitestart Only at the beginning of lines, before the first non-white char
582 t Everywhere except in headlines
583 exc-hl-bol Everywhere except at the start of a headline
584 If TAB is used in a place where it does not emulate TAB, the current subtree
585 visibility is cycled."
587 :type
'(choice (const :tag
"Never" nil
)
588 (const :tag
"Only in completely white lines" white
)
589 (const :tag
"Before first char in a line" whitestart
)
590 (const :tag
"Everywhere except in headlines" t
)
591 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
594 (defcustom org-cycle-separator-lines
2
595 "Number of empty lines needed to keep an empty line between collapsed trees.
596 If you leave an empty line between the end of a subtree and the following
597 headline, this empty line is hidden when the subtree is folded.
598 Org-mode will leave (exactly) one empty line visible if the number of
599 empty lines is equal or larger to the number given in this variable.
600 So the default 2 means, at least 2 empty lines after the end of a subtree
601 are needed to produce free space between a collapsed subtree and the
604 Special case: when 0, never leave empty lines in collapsed view."
607 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
609 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
610 org-cycle-hide-drawers
611 org-cycle-show-empty-lines
612 org-optimize-window-after-visibility-change
)
613 "Hook that is run after `org-cycle' has changed the buffer visibility.
614 The function(s) in this hook must accept a single argument which indicates
615 the new state that was set by the most recent `org-cycle' command. The
616 argument is a symbol. After a global state change, it can have the values
617 `overview', `content', or `all'. After a local state change, it can have
618 the values `folded', `children', or `subtree'."
622 (defgroup org-edit-structure nil
623 "Options concerning structure editing in Org-mode."
624 :tag
"Org Edit Structure"
625 :group
'org-structure
)
627 (defcustom org-odd-levels-only nil
628 "Non-nil means, skip even levels and only use odd levels for the outline.
629 This has the effect that two stars are being added/taken away in
630 promotion/demotion commands. It also influences how levels are
631 handled by the exporters.
632 Changing it requires restart of `font-lock-mode' to become effective
633 for fontification also in regions already fontified.
634 You may also set this on a per-file basis by adding one of the following
639 :group
'org-edit-structure
640 :group
'org-font-lock
643 (defcustom org-adapt-indentation t
644 "Non-nil means, adapt indentation when promoting and demoting.
645 When this is set and the *entire* text in an entry is indented, the
646 indentation is increased by one space in a demotion command, and
647 decreased by one in a promotion command. If any line in the entry
648 body starts at column 0, indentation is not changed at all."
649 :group
'org-edit-structure
652 (defcustom org-special-ctrl-a
/e nil
653 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
655 When t, `C-a' will bring back the cursor to the beginning of the
656 headline text, i.e. after the stars and after a possible TODO keyword.
657 In an item, this will be the position after the bullet.
658 When the cursor is already at that position, another `C-a' will bring
659 it to the beginning of the line.
661 `C-e' will jump to the end of the headline, ignoring the presence of tags
662 in the headline. A second `C-e' will then jump to the true end of the
663 line, after any tags.
665 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
666 and only a directly following, identical keypress will bring the cursor
667 to the special positions.
669 This may also be a cons cell where the behavior for `C-a' and `C-e' is
671 :group
'org-edit-structure
673 (const :tag
"off" nil
)
674 (const :tag
"after stars/bullet and before tags first" t
)
675 (const :tag
"true line boundary first" reversed
)
676 (cons :tag
"Set C-a and C-e separately"
677 (choice :tag
"Special C-a"
678 (const :tag
"off" nil
)
679 (const :tag
"after stars/bullet first" t
)
680 (const :tag
"before stars/bullet first" reversed
))
681 (choice :tag
"Special C-e"
682 (const :tag
"off" nil
)
683 (const :tag
"before tags first" t
)
684 (const :tag
"after tags first" reversed
)))))
685 (if (fboundp 'defvaralias
)
686 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
688 (defcustom org-special-ctrl-k nil
689 "Non-nil means `C-k' will behave specially in headlines.
690 When nil, `C-k' will call the default `kill-line' command.
691 When t, the following will happen while the cursor is in the headline:
693 - When the cursor is at the beginning of a headline, kill the entire
694 line and possible the folded subtree below the line.
695 - When in the middle of the headline text, kill the headline up to the tags.
696 - When after the headline text, kill the tags."
697 :group
'org-edit-structure
700 (defcustom org-yank-folded-subtrees t
701 "Non-nil means, when yanking subtrees, fold them.
702 If the kill is a single subtree, or a sequence of subtrees, i.e. if
703 it starts with a heading and all other headings in it are either children
704 or siblings, then fold all the subtrees. However, do this only if no
705 text after the yank would be swallowed into a folded tree by this action."
706 :group
'org-edit-structure
709 (defcustom org-yank-adjusted-subtrees nil
710 "Non-nil means, when yanking subtrees, adjust the level.
711 With this setting, `org-paste-subtree' is used to insert the subtree, see
712 this function for details."
713 :group
'org-edit-structure
716 (defcustom org-M-RET-may-split-line
'((default . t
))
717 "Non-nil means, M-RET will split the line at the cursor position.
718 When nil, it will go to the end of the line before making a
720 You may also set this option in a different way for different
721 contexts. Valid contexts are:
723 headline when creating a new headline
724 item when creating a new item
725 table in a table field
726 default the value to be used for all contexts not explicitly
728 :group
'org-structure
731 (const :tag
"Always" t
)
732 (const :tag
"Never" nil
)
733 (repeat :greedy t
:tag
"Individual contexts"
735 (choice :tag
"Context"
743 (defcustom org-insert-heading-respect-content nil
744 "Non-nil means, insert new headings after the current subtree.
745 When nil, the new heading is created directly after the current line.
746 The commands \\[org-insert-heading-respect-content] and
747 \\[org-insert-todo-heading-respect-content] turn this variable on
748 for the duration of the command."
749 :group
'org-structure
752 (defcustom org-blank-before-new-entry
'((heading . auto
)
753 (plain-list-item . auto
))
754 "Should `org-insert-heading' leave a blank line before new heading/item?
755 The value is an alist, with `heading' and `plain-list-item' as car,
756 and a boolean flag as cdr. For plain lists, if the variable
757 `org-empty-line-terminates-plain-lists' is set, the setting here
758 is ignored and no empty line is inserted, to keep the list in tact."
759 :group
'org-edit-structure
761 (cons (const heading
)
762 (choice (const :tag
"Never" nil
)
763 (const :tag
"Always" t
)
764 (const :tag
"Auto" auto
)))
765 (cons (const plain-list-item
)
766 (choice (const :tag
"Never" nil
)
767 (const :tag
"Always" t
)
768 (const :tag
"Auto" auto
)))))
770 (defcustom org-insert-heading-hook nil
771 "Hook being run after inserting a new heading."
772 :group
'org-edit-structure
775 (defcustom org-enable-fixed-width-editor t
776 "Non-nil means, lines starting with \":\" are treated as fixed-width.
777 This currently only means, they are never auto-wrapped.
778 When nil, such lines will be treated like ordinary lines.
779 See also the QUOTE keyword."
780 :group
'org-edit-structure
783 (defcustom org-edit-src-region-extra nil
784 "Additional regexps to identify regions for editing with `org-edit-src-code'.
785 For examples see the function `org-edit-src-find-region-and-lang'.
786 The regular expression identifying the begin marker should end with a newline,
787 and the regexp marking the end line should start with a newline, to make sure
788 there are kept outside the narrowed region."
789 :group
'org-edit-structure
792 (regexp :tag
"begin regexp")
793 (regexp :tag
"end regexp")
794 (choice :tag
"language"
795 (string :tag
"specify")
796 (integer :tag
"from match group")
797 (const :tag
"from `lang' element")
798 (const :tag
"from `style' element")))))
800 (defcustom org-coderef-label-format
"(ref:%s)"
801 "The default coderef format.
802 This format string will be used to search for coderef labels in literal
803 examples (EXAMPLE and SRC blocks). The format can be overwritten
804 an individual literal example with the -f option, like
806 #+BEGIN_SRC pascal +n -r -l \"((%s))\"
810 If you want to use this for HTML export, make sure that the format does
811 not introduce special font-locking, and avoid the HTML special
812 characters `<', `>', and `&'. The reason for this restriction is that
813 the labels are searched for only after htmlize has done its job."
814 :group
'org-edit-structure
; FIXME this is not in the right group
817 (defcustom org-edit-fixed-width-region-mode
'artist-mode
818 "The mode that should be used to edit fixed-width regions.
819 These are the regions where each line starts with a colon."
820 :group
'org-edit-structure
824 (const fundamental-mode
)
825 (function :tag
"Other (specify)")))
827 (defcustom org-goto-auto-isearch t
828 "Non-nil means, typing characters in org-goto starts incremental search."
829 :group
'org-edit-structure
832 (defgroup org-sparse-trees nil
833 "Options concerning sparse trees in Org-mode."
834 :tag
"Org Sparse Trees"
835 :group
'org-structure
)
837 (defcustom org-highlight-sparse-tree-matches t
838 "Non-nil means, highlight all matches that define a sparse tree.
839 The highlights will automatically disappear the next time the buffer is
840 changed by an edit command."
841 :group
'org-sparse-trees
844 (defcustom org-remove-highlights-with-change t
845 "Non-nil means, any change to the buffer will remove temporary highlights.
846 Such highlights are created by `org-occur' and `org-clock-display'.
847 When nil, `C-c C-c needs to be used to get rid of the highlights.
848 The highlights created by `org-preview-latex-fragment' always need
849 `C-c C-c' to be removed."
850 :group
'org-sparse-trees
855 (defcustom org-occur-hook
'(org-first-headline-recenter)
856 "Hook that is run after `org-occur' has constructed a sparse tree.
857 This can be used to recenter the window to show as much of the structure
859 :group
'org-sparse-trees
862 (defgroup org-imenu-and-speedbar nil
863 "Options concerning imenu and speedbar in Org-mode."
864 :tag
"Org Imenu and Speedbar"
865 :group
'org-structure
)
867 (defcustom org-imenu-depth
2
868 "The maximum level for Imenu access to Org-mode headlines.
869 This also applied for speedbar access."
870 :group
'org-imenu-and-speedbar
873 (defgroup org-table nil
874 "Options concerning tables in Org-mode."
878 (defcustom org-enable-table-editor
'optimized
879 "Non-nil means, lines starting with \"|\" are handled by the table editor.
880 When nil, such lines will be treated like ordinary lines.
882 When equal to the symbol `optimized', the table editor will be optimized to
884 - Automatic overwrite mode in front of whitespace in table fields.
885 This makes the structure of the table stay in tact as long as the edited
886 field does not exceed the column width.
887 - Minimize the number of realigns. Normally, the table is aligned each time
888 TAB or RET are pressed to move to another field. With optimization this
889 happens only if changes to a field might have changed the column width.
890 Optimization requires replacing the functions `self-insert-command',
891 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
892 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
893 very good at guessing when a re-align will be necessary, but you can always
894 force one with \\[org-ctrl-c-ctrl-c].
896 If you would like to use the optimized version in Org-mode, but the
897 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
899 This variable can be used to turn on and off the table editor during a session,
900 but in order to toggle optimization, a restart is required.
902 See also the variable `org-table-auto-blank-field'."
905 (const :tag
"off" nil
)
907 (const :tag
"on, optimized" optimized
)))
909 (defcustom org-self-insert-cluster-for-undo t
910 "Non-nil means cluster self-insert commands for undo when possible.
911 If this is set, then, like in the Emacs command loop, 20 consequtive
912 characters will be undone together.
913 This is configurable, because there is some impact on typing performance."
917 (defcustom org-table-tab-recognizes-table.el t
918 "Non-nil means, TAB will automatically notice a table.el table.
919 When it sees such a table, it moves point into it and - if necessary -
920 calls `table-recognize-table'."
921 :group
'org-table-editing
924 (defgroup org-link nil
925 "Options concerning links in Org-mode."
929 (defvar org-link-abbrev-alist-local nil
930 "Buffer-local version of `org-link-abbrev-alist', which see.
931 The value of this is taken from the #+LINK lines.")
932 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
934 (defcustom org-link-abbrev-alist nil
935 "Alist of link abbreviations.
936 The car of each element is a string, to be replaced at the start of a link.
937 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
938 links in Org-mode buffers can have an optional tag after a double colon, e.g.
940 [[linkkey:tag][description]]
942 The 'linkkey' must be a word word, starting with a letter, followed
943 by letters, numbers, '-' or '_'.
945 If REPLACE is a string, the tag will simply be appended to create the link.
946 If the string contains \"%s\", the tag will be inserted there. Alternatively,
947 the placeholder \"%h\" will cause a url-encoded version of the tag to
948 be inserted at that point (see the function `url-hexify-string').
950 REPLACE may also be a function that will be called with the tag as the
951 only argument to create the link, which should be returned as a string.
953 See the manual for examples."
957 (string :tag
"Protocol")
959 (string :tag
"Format")
962 (defcustom org-descriptive-links t
963 "Non-nil means, hide link part and only show description of bracket links.
964 Bracket links are like [[link][description]]. This variable sets the initial
965 state in new org-mode buffers. The setting can then be toggled on a
966 per-buffer basis from the Org->Hyperlinks menu."
970 (defcustom org-link-file-path-type
'adaptive
971 "How the path name in file links should be stored.
974 relative Relative to the current directory, i.e. the directory of the file
975 into which the link is being inserted.
976 absolute Absolute path, if possible with ~ for home directory.
977 noabbrev Absolute path, no abbreviation of home directory.
978 adaptive Use relative path for files in the current directory and sub-
979 directories of it. For other files, use an absolute path."
987 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
988 "Types of links that should be activated in Org-mode files.
989 This is a list of symbols, each leading to the activation of a certain link
990 type. In principle, it does not hurt to turn on most link types - there may
991 be a small gain when turning off unused link types. The types are:
993 bracket The recommended [[link][description]] or [[link]] links with hiding.
994 angular Links in angular brackets that may contain whitespace like
995 <bbdb:Carsten Dominik>.
996 plain Plain links in normal text, no whitespace, like http://google.com.
997 radio Text that is matched by a radio target, see manual for details.
998 tag Tag settings in a headline (link to tag search).
999 date Time stamps (link to calendar).
1000 footnote Footnote labels.
1002 Changing this variable requires a restart of Emacs to become effective."
1004 :type
'(set :greedy t
1005 (const :tag
"Double bracket links (new style)" bracket
)
1006 (const :tag
"Angular bracket links (old style)" angular
)
1007 (const :tag
"Plain text links" plain
)
1008 (const :tag
"Radio target matches" radio
)
1009 (const :tag
"Tags" tag
)
1010 (const :tag
"Timestamps" date
)
1011 (const :tag
"Footnotes" footnote
)))
1013 (defcustom org-make-link-description-function nil
1014 "Function to use to generate link descriptions from links. If
1015 nil the link location will be used. This function must take two
1016 parameters; the first is the link and the second the description
1017 org-insert-link has generated, and should return the description
1022 (defgroup org-link-store nil
1023 "Options concerning storing links in Org-mode."
1024 :tag
"Org Store Link"
1027 (defcustom org-email-link-description-format
"Email %c: %.30s"
1028 "Format of the description part of a link to an email or usenet message.
1029 The following %-escapes will be replaced by corresponding information:
1031 %F full \"From\" field
1032 %f name, taken from \"From\" field, address if no name
1033 %T full \"To\" field
1034 %t first name in \"To\" field, address if no name
1035 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1036 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1040 You may use normal field width specification between the % and the letter.
1041 This is for example useful to limit the length of the subject.
1043 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1044 :group
'org-link-store
1047 (defcustom org-from-is-user-regexp
1049 (when (and user-mail-address
(not (string= user-mail-address
"")))
1050 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1051 (when (and user-full-name
(not (string= user-full-name
"")))
1052 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1053 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1054 "Regexp matched against the \"From:\" header of an email or usenet message.
1055 It should match if the message is from the user him/herself."
1056 :group
'org-link-store
1059 (defcustom org-link-to-org-use-id
'create-if-interactive
1060 "Non-nil means, storing a link to an Org file will use entry IDs.
1062 Note that before this variable is even considered, org-id must be loaded,
1063 to please customize `org-modules' and turn it on.
1065 The variable can have the following values:
1067 t Create an ID if needed to make a link to the current entry.
1069 create-if-interactive
1070 If `org-store-link' is called directly (interactively, as a user
1071 command), do create an ID to support the link. But when doing the
1072 job for remember, only use the ID if it already exists. The
1073 purpose of this setting is to avoid proliferation of unwanted
1074 IDs, just because you happen to be in an Org file when you
1075 call `org-remember' that automatically and preemptively
1076 creates a link. If you do want to get an ID link in a remember
1077 template to an entry not having an ID, create it first by
1078 explicitly creating a link to it, using `C-c C-l' first.
1081 Use existing ID, do not create one.
1083 nil Never use an ID to make a link, instead link using a text search for
1085 :group
'org-link-store
1087 (const :tag
"Create ID to make link" t
)
1088 (const :tag
"Create if string link interactively"
1089 'create-if-interactive
)
1090 (const :tag
"Only use existing" 'use-existing
)
1091 (const :tag
"Do not use ID to create link" nil
)))
1093 (defcustom org-context-in-file-links t
1094 "Non-nil means, file links from `org-store-link' contain context.
1095 A search string will be added to the file name with :: as separator and
1096 used to find the context when the link is activated by the command
1097 `org-open-at-point'.
1098 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1099 negates this setting for the duration of the command."
1100 :group
'org-link-store
1103 (defcustom org-keep-stored-link-after-insertion nil
1104 "Non-nil means, keep link in list for entire session.
1106 The command `org-store-link' adds a link pointing to the current
1107 location to an internal list. These links accumulate during a session.
1108 The command `org-insert-link' can be used to insert links into any
1109 Org-mode file (offering completion for all stored links). When this
1110 option is nil, every link which has been inserted once using \\[org-insert-link]
1111 will be removed from the list, to make completing the unused links
1113 :group
'org-link-store
1116 (defgroup org-link-follow nil
1117 "Options concerning following links in Org-mode."
1118 :tag
"Org Follow Link"
1121 (defcustom org-link-translation-function nil
1122 "Function to translate links with different syntax to Org syntax.
1123 This can be used to translate links created for example by the Planner
1124 or emacs-wiki packages to Org syntax.
1125 The function must accept two parameters, a TYPE containing the link
1126 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1127 which is everything after the link protocol. It should return a cons
1128 with possibly modified values of type and path.
1129 Org contains a function for this, so if you set this variable to
1130 `org-translate-link-from-planner', you should be able follow many
1131 links created by planner."
1132 :group
'org-link-follow
1135 (defcustom org-follow-link-hook nil
1136 "Hook that is run after a link has been followed."
1137 :group
'org-link-follow
1140 (defcustom org-tab-follows-link nil
1141 "Non-nil means, on links TAB will follow the link.
1142 Needs to be set before org.el is loaded.
1143 This really should not be used, it does not make sense, and the
1144 implementation is bad."
1145 :group
'org-link-follow
1148 (defcustom org-return-follows-link nil
1149 "Non-nil means, on links RET will follow the link.
1150 Needs to be set before org.el is loaded."
1151 :group
'org-link-follow
1154 (defcustom org-mouse-1-follows-link
1155 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1156 "Non-nil means, mouse-1 on a link will follow the link.
1157 A longer mouse click will still set point. Does not work on XEmacs.
1158 Needs to be set before org.el is loaded."
1159 :group
'org-link-follow
1162 (defcustom org-mark-ring-length
4
1163 "Number of different positions to be recorded in the ring
1164 Changing this requires a restart of Emacs to work correctly."
1165 :group
'org-link-follow
1168 (defcustom org-link-frame-setup
1169 '((vm . vm-visit-folder-other-frame
)
1170 (gnus . gnus-other-frame
)
1171 (file . find-file-other-window
))
1172 "Setup the frame configuration for following links.
1173 When following a link with Emacs, it may often be useful to display
1174 this link in another window or frame. This variable can be used to
1175 set this up for the different types of links.
1178 `vm-visit-folder-other-frame'
1179 For Gnus, use any of
1182 `org-gnus-no-new-news'
1183 For FILE, use any of
1185 `find-file-other-window'
1186 `find-file-other-frame'
1187 For the calendar, use the variable `calendar-setup'.
1188 For BBDB, it is currently only possible to display the matches in
1190 :group
'org-link-follow
1194 (const vm-visit-folder
)
1195 (const vm-visit-folder-other-window
)
1196 (const vm-visit-folder-other-frame
)))
1200 (const gnus-other-frame
)
1201 (const org-gnus-no-new-news
)))
1205 (const find-file-other-window
)
1206 (const find-file-other-frame
)))))
1208 (defcustom org-display-internal-link-with-indirect-buffer nil
1209 "Non-nil means, use indirect buffer to display infile links.
1210 Activating internal links (from one location in a file to another location
1211 in the same file) normally just jumps to the location. When the link is
1212 activated with a C-u prefix (or with mouse-3), the link is displayed in
1213 another window. When this option is set, the other window actually displays
1214 an indirect buffer clone of the current buffer, to avoid any visibility
1215 changes to the current buffer."
1216 :group
'org-link-follow
1219 (defcustom org-open-non-existing-files nil
1220 "Non-nil means, `org-open-file' will open non-existing files.
1221 When nil, an error will be generated."
1222 :group
'org-link-follow
1225 (defcustom org-open-directory-means-index-dot-org nil
1226 "Non-nil means, a link to a directory really means to index.org.
1227 When nil, following a directory link will run dired or open a finder/explorer
1228 window on that directory."
1229 :group
'org-link-follow
1232 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1233 "Function and arguments to call for following mailto links.
1234 This is a list with the first element being a lisp function, and the
1235 remaining elements being arguments to the function. In string arguments,
1236 %a will be replaced by the address, and %s will be replaced by the subject
1237 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1238 :group
'org-link-follow
1240 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1241 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1242 (const :tag
"message-mail" (message-mail "%a" "%s"))
1243 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1245 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1246 "Non-nil means, ask for confirmation before executing shell links.
1247 Shell links can be dangerous: just think about a link
1249 [[shell:rm -rf ~/*][Google Search]]
1251 This link would show up in your Org-mode document as \"Google Search\",
1252 but really it would remove your entire home directory.
1253 Therefore we advise against setting this variable to nil.
1254 Just change it to `y-or-n-p' of you want to confirm with a
1255 single keystroke rather than having to type \"yes\"."
1256 :group
'org-link-follow
1258 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1259 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1260 (const :tag
"no confirmation (dangerous)" nil
)))
1262 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1263 "Non-nil means, ask for confirmation before executing Emacs Lisp links.
1264 Elisp links can be dangerous: just think about a link
1266 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1268 This link would show up in your Org-mode document as \"Google Search\",
1269 but really it would remove your entire home directory.
1270 Therefore we advise against setting this variable to nil.
1271 Just change it to `y-or-n-p' of you want to confirm with a
1272 single keystroke rather than having to type \"yes\"."
1273 :group
'org-link-follow
1275 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1276 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1277 (const :tag
"no confirmation (dangerous)" nil
)))
1279 (defconst org-file-apps-defaults-gnu
1283 "Default file applications on a UNIX or GNU/Linux system.
1284 See `org-file-apps'.")
1286 (defconst org-file-apps-defaults-macosx
1289 (system .
"open %s")
1291 ("eps.gz" .
"gv %s")
1293 ("fig" .
"xfig %s"))
1294 "Default file applications on a MacOS X system.
1295 The system \"open\" is known as a default, but we use X11 applications
1296 for some files for which the OS does not have a good default.
1297 See `org-file-apps'.")
1299 (defconst org-file-apps-defaults-windowsnt
1303 (list (if (featurep 'xemacs
)
1304 'mswindows-shell-execute
1308 (list (if (featurep 'xemacs
)
1309 'mswindows-shell-execute
1312 "Default file applications on a Windows NT system.
1313 The system \"open\" is used for most files.
1314 See `org-file-apps'.")
1316 (defcustom org-file-apps
1319 ("\\.x?html?\\'" . default
)
1320 ("\\.pdf\\'" . default
)
1322 "External applications for opening `file:path' items in a document.
1323 Org-mode uses system defaults for different file types, but
1324 you can use this variable to set the application for a given file
1325 extension. The entries in this list are cons cells where the car identifies
1326 files and the cdr the corresponding command. Possible values for the
1328 \"regex\" Regular expression matched against the file name. For backward
1329 compatibility, this can also be a string with only alphanumeric
1330 characters, which is then interpreted as an extension.
1331 `directory' Matches a directory
1332 `remote' Matches a remote file, accessible through tramp or efs.
1333 Remote files most likely should be visited through Emacs
1334 because external applications cannot handle such paths.
1335 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1336 so all files Emacs knows how to handle. Using this with
1337 command `emacs' will open most files in Emacs. Beware that this
1338 will also open html files inside Emacs, unless you add
1339 (\"html\" . default) to the list as well.
1340 t Default for files not matched by any of the other options.
1341 `system' The system command to open files, like `open' on Windows
1342 and Mac OS X, and mailcap under GNU/Linux. This is the command
1343 that will be selected if you call `C-c C-o' with a double
1346 Possible values for the command are:
1347 `emacs' The file will be visited by the current Emacs process.
1348 `default' Use the default application for this file type, which is the
1349 association for t in the list, most likely in the system-specific
1351 This can be used to overrule an unwanted setting in the
1352 system-specific variable.
1353 `system' Use the system command for opening files, like \"open\".
1354 This command is specified by the entry whose car is `system'.
1355 Most likely, the system-specific version of this variable
1356 does define this command, but you can overrule/replace it
1358 string A command to be executed by a shell; %s will be replaced
1359 by the path to the file.
1360 sexp A Lisp form which will be evaluated. The file path will
1361 be available in the Lisp variable `file'.
1362 For more examples, see the system specific constants
1363 `org-file-apps-defaults-macosx'
1364 `org-file-apps-defaults-windowsnt'
1365 `org-file-apps-defaults-gnu'."
1366 :group
'org-link-follow
1368 (cons (choice :value
""
1369 (string :tag
"Extension")
1370 (const :tag
"System command to open files" system
)
1371 (const :tag
"Default for unrecognized files" t
)
1372 (const :tag
"Remote file" remote
)
1373 (const :tag
"Links to a directory" directory
)
1374 (const :tag
"Any files that have Emacs modes"
1377 (const :tag
"Visit with Emacs" emacs
)
1378 (const :tag
"Use default" default
)
1379 (const :tag
"Use the system command" system
)
1380 (string :tag
"Command")
1381 (sexp :tag
"Lisp form")))))
1383 (defgroup org-refile nil
1384 "Options concerning refiling entries in Org-mode."
1388 (defcustom org-directory
"~/org"
1389 "Directory with org files.
1390 This is just a default location to look for Org files. There is no need
1391 at all to put your files into this directory. It is only used in the
1392 following situations:
1394 1. When a remember template specifies a target file that is not an
1395 absolute path. The path will then be interpreted relative to
1397 2. When a remember note is filed away in an interactive way (when exiting the
1398 note buffer with `C-1 C-c C-c'. The the user is prompted for an org file,
1399 with `org-directory' as the default path."
1401 :group
'org-remember
1404 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1405 "Default target for storing notes.
1406 Used by the hooks for remember.el. This can be a string, or nil to mean
1407 the value of `remember-data-file'.
1408 You can set this on a per-template basis with the variable
1409 `org-remember-templates'."
1411 :group
'org-remember
1413 (const :tag
"Default from remember-data-file" nil
)
1416 (defcustom org-goto-interface
'outline
1417 "The default interface to be used for `org-goto'.
1419 outline The interface shows an outline of the relevant file
1420 and the correct heading is found by moving through
1421 the outline or by searching with incremental search.
1422 outline-path-completion Headlines in the current buffer are offered via
1423 completion. This is the interface also used by
1424 the refile command."
1427 (const :tag
"Outline" outline
)
1428 (const :tag
"Outline-path-completion" outline-path-completion
)))
1430 (defcustom org-goto-max-level
5
1431 "Maximum level to be considered when running org-goto with refile interface."
1435 (defcustom org-reverse-note-order nil
1436 "Non-nil means, store new notes at the beginning of a file or entry.
1437 When nil, new notes will be filed to the end of a file or entry.
1438 This can also be a list with cons cells of regular expressions that
1439 are matched against file names, and values."
1440 :group
'org-remember
1443 (const :tag
"Reverse always" t
)
1444 (const :tag
"Reverse never" nil
)
1445 (repeat :tag
"By file name regexp"
1446 (cons regexp boolean
))))
1448 (defcustom org-refile-targets nil
1449 "Targets for refiling entries with \\[org-refile].
1450 This is list of cons cells. Each cell contains:
1451 - a specification of the files to be considered, either a list of files,
1452 or a symbol whose function or variable value will be used to retrieve
1453 a file name or a list of file names. If you use `org-agenda-files' for
1454 that, all agenda files will be scanned for targets. Nil means, consider
1455 headings in the current buffer.
1456 - A specification of how to find candidate refile targets. This may be
1458 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1459 This tag has to be present in all target headlines, inheritance will
1461 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1463 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1464 headlines that are refiling targets.
1465 - a cons cell (:level . N). Any headline of level N is considered a target.
1466 Note that, when `org-odd-levels-only' is set, level corresponds to
1467 order in hierarchy, not to the number of stars.
1468 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1469 Note that, when `org-odd-levels-only' is set, level corresponds to
1470 order in hierarchy, not to the number of stars.
1472 When this variable is nil, all top-level headlines in the current buffer
1473 are used, equivalent to the value `((nil . (:level . 1))'."
1477 (choice :value org-agenda-files
1478 (const :tag
"All agenda files" org-agenda-files
)
1479 (const :tag
"Current buffer" nil
)
1480 (function) (variable) (file))
1481 (choice :tag
"Identify target headline by"
1482 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1483 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1484 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1485 (cons :tag
"Level number" (const :value
:level
) (integer))
1486 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1488 (defcustom org-refile-use-outline-path nil
1489 "Non-nil means, provide refile targets as paths.
1490 So a level 3 headline will be available as level1/level2/level3.
1491 When the value is `file', also include the file name (without directory)
1492 into the path. When `full-file-path', include the full file path."
1495 (const :tag
"Not" nil
)
1496 (const :tag
"Yes" t
)
1497 (const :tag
"Start with file name" file
)
1498 (const :tag
"Start with full file path" full-file-path
)))
1500 (defcustom org-outline-path-complete-in-steps t
1501 "Non-nil means, complete the outline path in hierarchical steps.
1502 When Org-mode uses the refile interface to select an outline path
1503 \(see variable `org-refile-use-outline-path'), the completion of
1504 the path can be done is a single go, or if can be done in steps down
1505 the headline hierarchy. Going in steps is probably the best if you
1506 do not use a special completion package like `ido' or `icicles'.
1507 However, when using these packages, going in one step can be very
1508 fast, while still showing the whole path to the entry."
1512 (defgroup org-todo nil
1513 "Options concerning TODO items in Org-mode."
1517 (defgroup org-progress nil
1518 "Options concerning Progress logging in Org-mode."
1522 (defvar org-todo-interpretation-widgets
1524 (:tag
"Sequence (cycling hits every state)" sequence
)
1525 (:tag
"Type (cycling directly to DONE)" type
))
1526 "The available interpretation symbols for customizing
1527 `org-todo-keywords'.
1528 Interested libraries should add to this list.")
1530 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1531 "List of TODO entry keyword sequences and their interpretation.
1532 \\<org-mode-map>This is a list of sequences.
1534 Each sequence starts with a symbol, either `sequence' or `type',
1535 indicating if the keywords should be interpreted as a sequence of
1536 action steps, or as different types of TODO items. The first
1537 keywords are states requiring action - these states will select a headline
1538 for inclusion into the global TODO list Org-mode produces. If one of
1539 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1540 signify that no further action is necessary. If \"|\" is not found,
1541 the last keyword is treated as the only DONE state of the sequence.
1543 The command \\[org-todo] cycles an entry through these states, and one
1544 additional state where no keyword is present. For details about this
1545 cycling, see the manual.
1547 TODO keywords and interpretation can also be set on a per-file basis with
1548 the special #+SEQ_TODO and #+TYP_TODO lines.
1550 Each keyword can optionally specify a character for fast state selection
1551 \(in combination with the variable `org-use-fast-todo-selection')
1552 and specifiers for state change logging, using the same syntax
1553 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1554 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1555 indicates to record a time stamp each time this state is selected.
1557 Each keyword may also specify if a timestamp or a note should be
1558 recorded when entering or leaving the state, by adding additional
1559 characters in the parenthesis after the keyword. This looks like this:
1560 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1561 record only the time of the state change. With X and Y being either
1562 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1563 Y when leaving the state if and only if the *target* state does not
1564 define X. You may omit any of the fast-selection key or X or /Y,
1565 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1567 For backward compatibility, this variable may also be just a list
1568 of keywords - in this case the interpretation (sequence or type) will be
1569 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1571 :group
'org-keywords
1573 (repeat :tag
"Old syntax, just keywords"
1574 (string :tag
"Keyword"))
1575 (repeat :tag
"New syntax"
1578 :tag
"Interpretation"
1579 ;;Quick and dirty way to see
1580 ;;`org-todo-interpretations'. This takes the
1581 ;;place of item arguments
1589 org-todo-interpretation-widgets
))
1592 (string :tag
"Keyword"))))))
1594 (defvar org-todo-keywords-1 nil
1595 "All TODO and DONE keywords active in a buffer.")
1596 (make-variable-buffer-local 'org-todo-keywords-1
)
1597 (defvar org-todo-keywords-for-agenda nil
)
1598 (defvar org-done-keywords-for-agenda nil
)
1599 (defvar org-todo-keyword-alist-for-agenda nil
)
1600 (defvar org-tag-alist-for-agenda nil
)
1601 (defvar org-agenda-contributing-files nil
)
1602 (defvar org-not-done-keywords nil
)
1603 (make-variable-buffer-local 'org-not-done-keywords
)
1604 (defvar org-done-keywords nil
)
1605 (make-variable-buffer-local 'org-done-keywords
)
1606 (defvar org-todo-heads nil
)
1607 (make-variable-buffer-local 'org-todo-heads
)
1608 (defvar org-todo-sets nil
)
1609 (make-variable-buffer-local 'org-todo-sets
)
1610 (defvar org-todo-log-states nil
)
1611 (make-variable-buffer-local 'org-todo-log-states
)
1612 (defvar org-todo-kwd-alist nil
)
1613 (make-variable-buffer-local 'org-todo-kwd-alist
)
1614 (defvar org-todo-key-alist nil
)
1615 (make-variable-buffer-local 'org-todo-key-alist
)
1616 (defvar org-todo-key-trigger nil
)
1617 (make-variable-buffer-local 'org-todo-key-trigger
)
1619 (defcustom org-todo-interpretation
'sequence
1620 "Controls how TODO keywords are interpreted.
1621 This variable is in principle obsolete and is only used for
1622 backward compatibility, if the interpretation of todo keywords is
1623 not given already in `org-todo-keywords'. See that variable for
1626 :group
'org-keywords
1627 :type
'(choice (const sequence
)
1630 (defcustom org-use-fast-todo-selection t
1631 "Non-nil means, use the fast todo selection scheme with C-c C-t.
1632 This variable describes if and under what circumstances the cycling
1633 mechanism for TODO keywords will be replaced by a single-key, direct
1636 When nil, fast selection is never used.
1638 When the symbol `prefix', it will be used when `org-todo' is called with
1639 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1640 in an agenda buffer.
1642 When t, fast selection is used by default. In this case, the prefix
1643 argument forces cycling instead.
1645 In all cases, the special interface is only used if access keys have actually
1646 been assigned by the user, i.e. if keywords in the configuration are followed
1647 by a letter in parenthesis, like TODO(t)."
1650 (const :tag
"Never" nil
)
1651 (const :tag
"By default" t
)
1652 (const :tag
"Only with C-u C-c C-t" prefix
)))
1654 (defcustom org-provide-todo-statistics t
1655 "Non-nil means, update todo statistics after insert and toggle.
1656 When this is set, todo statistics is updated in the parent of the current
1657 entry each time a todo state is changed."
1661 (defcustom org-after-todo-state-change-hook nil
1662 "Hook which is run after the state of a TODO item was changed.
1663 The new state (a string with a TODO keyword, or nil) is available in the
1664 Lisp variable `state'."
1668 (defvar org-blocker-hook nil
1669 "Hook for functions that are allowed to block a state change.
1671 Each function gets as its single argument a property list, see
1672 `org-trigger-hook' for more information about this list.
1674 If any of the functions in this hook returns nil, the state change
1677 (defvar org-trigger-hook nil
1678 "Hook for functions that are triggered by a state change.
1680 Each function gets as its single argument a property list with at least
1681 the following elements:
1683 (:type type-of-change :position pos-at-entry-start
1684 :from old-state :to new-state)
1686 Depending on the type, more properties may be present.
1688 This mechanism is currently implemented for:
1692 :type todo-state-change
1693 :from previous state (keyword as a string), or nil, or a symbol
1694 'todo' or 'done', to indicate the general type of state.
1695 :to new state, like in :from")
1697 (defcustom org-enforce-todo-dependencies nil
1698 "Non-nil means, undone TODO entries will block switching the parent to DONE.
1699 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1700 be blocked if any prior sibling is not yet done.
1701 This variable needs to be set before org.el is loaded, and you need to
1702 restart Emacs after a change to make the change effective. The only way
1703 to change is while Emacs is running is through the customize interface."
1704 :set
(lambda (var val
)
1707 (add-hook 'org-blocker-hook
1708 'org-block-todo-from-children-or-siblings
)
1709 (remove-hook 'org-blocker-hook
1710 'org-block-todo-from-children-or-siblings
)))
1714 (defcustom org-enforce-todo-checkbox-dependencies nil
1715 "Non-nil means, unchecked boxes will block switching the parent to DONE.
1716 When this is nil, checkboxes have no influence on switching TODO states.
1717 When non-nil, you first need to check off all check boxes before the TODO
1718 entry can be switched to DONE.
1719 This variable needs to be set before org.el is loaded, and you need to
1720 restart Emacs after a change to make the change effective. The only way
1721 to change is while Emacs is running is through the customize interface."
1722 :set
(lambda (var val
)
1725 (add-hook 'org-blocker-hook
1726 'org-block-todo-from-checkboxes
)
1727 (remove-hook 'org-blocker-hook
1728 'org-block-todo-from-checkboxes
)))
1732 (defcustom org-todo-state-tags-triggers nil
1733 "Tag changes that should be triggered by TODO state changes.
1734 This is a list. Each entry is
1736 (state-change (tag . flag) .......)
1738 State-change can be a string with a state, and empty string to indicate the
1739 state that has no TODO keyword, or it can be one of the symbols `todo'
1740 or `done', meaning any not-done or done state, respectively."
1744 (cons (choice :tag
"When changing to"
1745 (const :tag
"Not-done state" todo
)
1746 (const :tag
"Done state" done
)
1747 (string :tag
"State"))
1749 (cons :tag
"Tag action"
1751 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
1753 (defcustom org-log-done nil
1754 "Information to record when a task moves to the DONE state.
1756 Possible values are:
1758 nil Don't add anything, just change the keyword
1759 time Add a time stamp to the task
1760 note Prompt a closing note and add it with template `org-log-note-headings'
1762 This option can also be set with on a per-file-basis with
1764 #+STARTUP: nologdone
1766 #+STARTUP: lognotedone
1768 You can have local logging settings for a subtree by setting the LOGGING
1769 property to one or more of these keywords."
1771 :group
'org-progress
1773 (const :tag
"No logging" nil
)
1774 (const :tag
"Record CLOSED timestamp" time
)
1775 (const :tag
"Record CLOSED timestamp with closing note." note
)))
1777 ;; Normalize old uses of org-log-done.
1779 ((eq org-log-done t
) (setq org-log-done
'time
))
1780 ((and (listp org-log-done
) (memq 'done org-log-done
))
1781 (setq org-log-done
'note
)))
1783 (defcustom org-log-note-clock-out nil
1784 "Non-nil means, record a note when clocking out of an item.
1785 This can also be configured on a per-file basis by adding one of
1786 the following lines anywhere in the buffer:
1788 #+STARTUP: lognoteclock-out
1789 #+STARTUP: nolognoteclock-out"
1791 :group
'org-progress
1794 (defcustom org-log-done-with-time t
1795 "Non-nil means, the CLOSED time stamp will contain date and time.
1796 When nil, only the date will be recorded."
1797 :group
'org-progress
1800 (defcustom org-log-note-headings
1801 '((done .
"CLOSING NOTE %t")
1802 (state .
"State %-12s from %-12S %t")
1803 (note .
"Note taken on %t")
1805 "Headings for notes added to entries.
1806 The value is an alist, with the car being a symbol indicating the note
1807 context, and the cdr is the heading to be used. The heading may also be the
1809 %t in the heading will be replaced by a time stamp.
1810 %s will be replaced by the new TODO state, in double quotes.
1811 %S will be replaced by the old TODO state, in double quotes.
1812 %u will be replaced by the user name.
1813 %U will be replaced by the full user name."
1815 :group
'org-progress
1816 :type
'(list :greedy t
1817 (cons (const :tag
"Heading when closing an item" done
) string
)
1819 "Heading when changing todo state (todo sequence only)"
1821 (cons (const :tag
"Heading when just taking a note" note
) string
)
1822 (cons (const :tag
"Heading when clocking out" clock-out
) string
)))
1824 (unless (assq 'note org-log-note-headings
)
1825 (push '(note .
"%t") org-log-note-headings
))
1827 (defcustom org-log-into-drawer nil
1828 "Non-nil means, insert state change notes and time stamps into a drawer.
1829 When nil, state changes notes will be inserted after the headline and
1830 any scheduling and clock lines, but not inside a drawer.
1832 The value of this variable should be the name of the drawer to use.
1833 LOGBOOK is proposed at the default drawer for this purpose, you can
1834 also set this to a string to define the drawer of your choice.
1836 A value of t is also allowed, representing \"LOGBOOK\".
1838 If this variable is set, `org-log-state-notes-insert-after-drawers'
1841 :group
'org-progress
1843 (const :tag
"Not into a drawer" nil
)
1844 (const :tag
"LOGBOOK" t
)
1845 (string :tag
"Other")))
1847 (if (fboundp 'defvaralias
)
1848 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
1850 (defcustom org-log-state-notes-insert-after-drawers nil
1851 "Non-nil means, insert state change notes after any drawers in entry.
1852 Only the drawers that *immediately* follow the headline and the
1853 deadline/scheduled line are skipped.
1854 When nil, insert notes right after the heading and perhaps the line
1855 with deadline/scheduling if present.
1857 This variable will have no effect if `org-log-into-drawer' is
1860 :group
'org-progress
1863 (defcustom org-log-states-order-reversed t
1864 "Non-nil means, the latest state change note will be directly after heading.
1865 When nil, the notes will be orderer according to time."
1867 :group
'org-progress
1870 (defcustom org-log-repeat
'time
1871 "Non-nil means, record moving through the DONE state when triggering repeat.
1872 An auto-repeating tasks is immediately switched back to TODO when marked
1873 done. If you are not logging state changes (by adding \"@\" or \"!\" to
1874 the TODO keyword definition, or recording a closing note by setting
1875 `org-log-done', there will be no record of the task moving through DONE.
1876 This variable forces taking a note anyway. Possible values are:
1878 nil Don't force a record
1879 time Record a time stamp
1882 This option can also be set with on a per-file-basis with
1884 #+STARTUP: logrepeat
1885 #+STARTUP: lognoterepeat
1886 #+STARTUP: nologrepeat
1888 You can have local logging settings for a subtree by setting the LOGGING
1889 property to one or more of these keywords."
1891 :group
'org-progress
1893 (const :tag
"Don't force a record" nil
)
1894 (const :tag
"Force recording the DONE state" time
)
1895 (const :tag
"Force recording a note with the DONE state" note
)))
1898 (defgroup org-priorities nil
1899 "Priorities in Org-mode."
1900 :tag
"Org Priorities"
1903 (defcustom org-highest-priority ?A
1904 "The highest priority of TODO items. A character like ?A, ?B etc.
1905 Must have a smaller ASCII number than `org-lowest-priority'."
1906 :group
'org-priorities
1909 (defcustom org-lowest-priority ?C
1910 "The lowest priority of TODO items. A character like ?A, ?B etc.
1911 Must have a larger ASCII number than `org-highest-priority'."
1912 :group
'org-priorities
1915 (defcustom org-default-priority ?B
1916 "The default priority of TODO items.
1917 This is the priority an item get if no explicit priority is given."
1918 :group
'org-priorities
1921 (defcustom org-priority-start-cycle-with-default t
1922 "Non-nil means, start with default priority when starting to cycle.
1923 When this is nil, the first step in the cycle will be (depending on the
1924 command used) one higher or lower that the default priority."
1925 :group
'org-priorities
1928 (defgroup org-time nil
1929 "Options concerning time stamps and deadlines in Org-mode."
1933 (defcustom org-insert-labeled-timestamps-at-point nil
1934 "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point.
1935 When nil, these labeled time stamps are forces into the second line of an
1936 entry, just after the headline. When scheduling from the global TODO list,
1937 the time stamp will always be forced into the second line."
1941 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
1942 "Formats for `format-time-string' which are used for time stamps.
1943 It is not recommended to change this constant.")
1945 (defcustom org-time-stamp-rounding-minutes
'(0 5)
1946 "Number of minutes to round time stamps to.
1947 These are two values, the first applies when first creating a time stamp.
1948 The second applies when changing it with the commands `S-up' and `S-down'.
1949 When changing the time stamp, this means that it will change in steps
1950 of N minutes, as given by the second value.
1952 When a setting is 0 or 1, insert the time unmodified. Useful rounding
1953 numbers should be factors of 60, so for example 5, 10, 15.
1955 When this is larger than 1, you can still force an exact time-stamp by using
1956 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
1957 and by using a prefix arg to `S-up/down' to specify the exact number
1958 of minutes to shift."
1960 :get
'(lambda (var) ; Make sure all entries have 5 elements
1961 (if (integerp (default-value var
))
1962 (list (default-value var
) 5)
1963 (default-value var
)))
1965 (integer :tag
"when inserting times")
1966 (integer :tag
"when modifying times")))
1968 ;; Normalize old customizations of this variable.
1969 (when (integerp org-time-stamp-rounding-minutes
)
1970 (setq org-time-stamp-rounding-minutes
1971 (list org-time-stamp-rounding-minutes
1972 org-time-stamp-rounding-minutes
)))
1974 (defcustom org-display-custom-times nil
1975 "Non-nil means, overlay custom formats over all time stamps.
1976 The formats are defined through the variable `org-time-stamp-custom-formats'.
1977 To turn this on on a per-file basis, insert anywhere in the file:
1978 #+STARTUP: customtime"
1982 (make-variable-buffer-local 'org-display-custom-times
)
1984 (defcustom org-time-stamp-custom-formats
1985 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
1986 "Custom formats for time stamps. See `format-time-string' for the syntax.
1987 These are overlayed over the default ISO format if the variable
1988 `org-display-custom-times' is set. Time like %H:%M should be at the
1989 end of the second format."
1993 (defun org-time-stamp-format (&optional long inactive
)
1994 "Get the right format for a time string."
1995 (let ((f (if long
(cdr org-time-stamp-formats
)
1996 (car org-time-stamp-formats
))))
1998 (concat "[" (substring f
1 -
1) "]")
2001 (defcustom org-time-clocksum-format
"%d:%02d"
2002 "The format string used when creating CLOCKSUM lines, or when
2003 org-mode generates a time duration."
2007 (defcustom org-deadline-warning-days
14
2008 "No. of days before expiration during which a deadline becomes active.
2009 This variable governs the display in sparse trees and in the agenda.
2010 When 0 or negative, it means use this number (the absolute value of it)
2011 even if a deadline has a different individual lead time specified."
2013 :group
'org-agenda-daily
/weekly
2016 (defcustom org-read-date-prefer-future t
2017 "Non-nil means, assume future for incomplete date input from user.
2018 This affects the following situations:
2019 1. The user gives a day, but no month.
2020 For example, if today is the 15th, and you enter \"3\", Org-mode will
2021 read this as the third of *next* month. However, if you enter \"17\",
2022 it will be considered as *this* month.
2023 2. The user gives a month but not a year.
2024 For example, if it is april and you enter \"feb 2\", this will be read
2025 as feb 2, *next* year. \"May 5\", however, will be this year.
2027 Currently this does not work for ISO week specifications.
2029 When this option is nil, the current month and year will always be used
2034 (defcustom org-read-date-display-live t
2035 "Non-nil means, display current interpretation of date prompt live.
2036 This display will be in an overlay, in the minibuffer."
2040 (defcustom org-read-date-popup-calendar t
2041 "Non-nil means, pop up a calendar when prompting for a date.
2042 In the calendar, the date can be selected with mouse-1. However, the
2043 minibuffer will also be active, and you can simply enter the date as well.
2044 When nil, only the minibuffer will be available."
2047 (if (fboundp 'defvaralias
)
2048 (defvaralias 'org-popup-calendar-for-date-prompt
2049 'org-read-date-popup-calendar
))
2051 (defcustom org-extend-today-until
0
2052 "The hour when your day really ends. Must be an integer.
2053 This has influence for the following applications:
2054 - When switching the agenda to \"today\". It it is still earlier than
2055 the time given here, the day recognized as TODAY is actually yesterday.
2056 - When a date is read from the user and it is still before the time given
2057 here, the current date and time will be assumed to be yesterday, 23:59.
2058 Also, timestamps inserted in remember templates follow this rule.
2060 IMPORTANT: This is a feature whose implementation is and likely will
2061 remain incomplete. Really, it is only here because past midnight seems to
2062 be the favorite working time of John Wiegley :-)"
2066 (defcustom org-edit-timestamp-down-means-later nil
2067 "Non-nil means, S-down will increase the time in a time stamp.
2068 When nil, S-up will increase."
2072 (defcustom org-calendar-follow-timestamp-change t
2073 "Non-nil means, make the calendar window follow timestamp changes.
2074 When a timestamp is modified and the calendar window is visible, it will be
2075 moved to the new date."
2079 (defgroup org-tags nil
2080 "Options concerning tags in Org-mode."
2084 (defcustom org-tag-alist nil
2085 "List of tags allowed in Org-mode files.
2086 When this list is nil, Org-mode will base TAG input on what is already in the
2088 The value of this variable is an alist, the car of each entry must be a
2089 keyword as a string, the cdr may be a character that is used to select
2090 that tag through the fast-tag-selection interface.
2091 See the manual for details."
2095 (cons (string :tag
"Tag name")
2096 (character :tag
"Access char"))
2097 (const :tag
"Start radio group" (:startgroup
))
2098 (const :tag
"End radio group" (:endgroup
))
2099 (const :tag
"New line" (:newline
)))))
2101 (defcustom org-tag-persistent-alist nil
2102 "List of tags that will always appear in all Org-mode files.
2103 This is in addition to any in buffer settings or customizations
2105 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2106 The value of this variable is an alist, the car of each entry must be a
2107 keyword as a string, the cdr may be a character that is used to select
2108 that tag through the fast-tag-selection interface.
2109 See the manual for details.
2110 To disable these tags on a per-file basis, insert anywhere in the file:
2115 (cons (string :tag
"Tag name")
2116 (character :tag
"Access char"))
2117 (const :tag
"Start radio group" (:startgroup
))
2118 (const :tag
"End radio group" (:endgroup
))
2119 (const :tag
"New line" (:newline
)))))
2121 (defvar org-file-tags nil
2122 "List of tags that can be inherited by all entries in the file.
2123 The tags will be inherited if the variable `org-use-tag-inheritance'
2124 says they should be.
2125 This variable is populated from #+TAG lines.")
2127 (defcustom org-use-fast-tag-selection
'auto
2128 "Non-nil means, use fast tag selection scheme.
2129 This is a special interface to select and deselect tags with single keys.
2130 When nil, fast selection is never used.
2131 When the symbol `auto', fast selection is used if and only if selection
2132 characters for tags have been configured, either through the variable
2133 `org-tag-alist' or through a #+TAGS line in the buffer.
2134 When t, fast selection is always used and selection keys are assigned
2135 automatically if necessary."
2138 (const :tag
"Always" t
)
2139 (const :tag
"Never" nil
)
2140 (const :tag
"When selection characters are configured" 'auto
)))
2142 (defcustom org-fast-tag-selection-single-key nil
2143 "Non-nil means, fast tag selection exits after first change.
2144 When nil, you have to press RET to exit it.
2145 During fast tag selection, you can toggle this flag with `C-c'.
2146 This variable can also have the value `expert'. In this case, the window
2147 displaying the tags menu is not even shown, until you press C-c again."
2150 (const :tag
"No" nil
)
2151 (const :tag
"Yes" t
)
2152 (const :tag
"Expert" expert
)))
2154 (defvar org-fast-tag-selection-include-todo nil
2155 "Non-nil means, fast tags selection interface will also offer TODO states.
2156 This is an undocumented feature, you should not rely on it.")
2158 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2159 "The column to which tags should be indented in a headline.
2160 If this number is positive, it specifies the column. If it is negative,
2161 it means that the tags should be flushright to that column. For example,
2162 -80 works well for a normal 80 character screen."
2166 (defcustom org-auto-align-tags t
2167 "Non-nil means, realign tags after pro/demotion of TODO state change.
2168 These operations change the length of a headline and therefore shift
2169 the tags around. With this options turned on, after each such operation
2170 the tags are again aligned to `org-tags-column'."
2174 (defcustom org-use-tag-inheritance t
2175 "Non-nil means, tags in levels apply also for sublevels.
2176 When nil, only the tags directly given in a specific line apply there.
2177 This may also be a list of tags that should be inherited, or a regexp that
2178 matches tags that should be inherited. Additional control is possible
2179 with the variable `org-tags-exclude-from-inheritance' which gives an
2180 explicit list of tags to be excluded from inheritance., even if the value of
2181 `org-use-tag-inheritance' would select it for inheritance.
2183 If this option is t, a match early-on in a tree can lead to a large
2184 number of matches in the subtree when constructing the agenda or creating
2185 a sparse tree. If you only want to see the first match in a tree during
2186 a search, check out the variable `org-tags-match-list-sublevels'."
2189 (const :tag
"Not" nil
)
2190 (const :tag
"Always" t
)
2191 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2192 (regexp :tag
"Tags matched by regexp")))
2194 (defcustom org-tags-exclude-from-inheritance nil
2195 "List of tags that should never be inherited.
2196 This is a way to exclude a few tags from inheritance. For way to do
2197 the opposite, to actively allow inheritance for selected tags,
2198 see the variable `org-use-tag-inheritance'."
2200 :type
'(repeat (string :tag
"Tag")))
2202 (defun org-tag-inherit-p (tag)
2203 "Check if TAG is one that should be inherited."
2205 ((member tag org-tags-exclude-from-inheritance
) nil
)
2206 ((eq org-use-tag-inheritance t
) t
)
2207 ((not org-use-tag-inheritance
) nil
)
2208 ((stringp org-use-tag-inheritance
)
2209 (string-match org-use-tag-inheritance tag
))
2210 ((listp org-use-tag-inheritance
)
2211 (member tag org-use-tag-inheritance
))
2212 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2214 (defcustom org-tags-match-list-sublevels t
2215 "Non-nil means list also sublevels of headlines matching tag search.
2216 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2217 the sublevels of a headline matching a tag search often also match
2218 the same search. Listing all of them can create very long lists.
2219 Setting this variable to nil causes subtrees of a match to be skipped.
2220 This option is off by default, because inheritance in on. If you turn
2221 inheritance off, you very likely want to turn this option on.
2223 As a special case, if the tag search is restricted to TODO items, the
2224 value of this variable is ignored and sublevels are always checked, to
2225 make sure all corresponding TODO items find their way into the list.
2227 This variable is semi-obsolete and probably should always be true. It
2228 is better to limit inheritance to certain tags using the variables
2229 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2233 (defvar org-tags-history nil
2234 "History of minibuffer reads for tags.")
2235 (defvar org-last-tags-completion-table nil
2236 "The last used completion table for tags.")
2237 (defvar org-after-tags-change-hook nil
2238 "Hook that is run after the tags in a line have changed.")
2240 (defgroup org-properties nil
2241 "Options concerning properties in Org-mode."
2242 :tag
"Org Properties"
2245 (defcustom org-property-format
"%-10s %s"
2246 "How property key/value pairs should be formatted by `indent-line'.
2247 When `indent-line' hits a property definition, it will format the line
2248 according to this format, mainly to make sure that the values are
2249 lined-up with respect to each other."
2250 :group
'org-properties
2253 (defcustom org-use-property-inheritance nil
2254 "Non-nil means, properties apply also for sublevels.
2256 This setting is chiefly used during property searches. Turning it on can
2257 cause significant overhead when doing a search, which is why it is not
2260 When nil, only the properties directly given in the current entry count.
2261 When t, every property is inherited. The value may also be a list of
2262 properties that should have inheritance, or a regular expression matching
2263 properties that should be inherited.
2265 However, note that some special properties use inheritance under special
2266 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2267 and the properties ending in \"_ALL\" when they are used as descriptor
2268 for valid values of a property.
2270 Note for programmers:
2271 When querying an entry with `org-entry-get', you can control if inheritance
2272 should be used. By default, `org-entry-get' looks only at the local
2273 properties. You can request inheritance by setting the inherit argument
2274 to t (to force inheritance) or to `selective' (to respect the setting
2276 :group
'org-properties
2278 (const :tag
"Not" nil
)
2279 (const :tag
"Always" t
)
2280 (repeat :tag
"Specific properties" (string :tag
"Property"))
2281 (regexp :tag
"Properties matched by regexp")))
2283 (defun org-property-inherit-p (property)
2284 "Check if PROPERTY is one that should be inherited."
2286 ((eq org-use-property-inheritance t
) t
)
2287 ((not org-use-property-inheritance
) nil
)
2288 ((stringp org-use-property-inheritance
)
2289 (string-match org-use-property-inheritance property
))
2290 ((listp org-use-property-inheritance
)
2291 (member property org-use-property-inheritance
))
2292 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2294 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2295 "The default column format, if no other format has been defined.
2296 This variable can be set on the per-file basis by inserting a line
2298 #+COLUMNS: %25ITEM ....."
2299 :group
'org-properties
2302 (defcustom org-columns-ellipses
".."
2303 "The ellipses to be used when a field in column view is truncated.
2304 When this is the empty string, as many characters as possible are shown,
2305 but then there will be no visual indication that the field has been truncated.
2306 When this is a string of length N, the last N characters of a truncated
2307 field are replaced by this string. If the column is narrower than the
2308 ellipses string, only part of the ellipses string will be shown."
2309 :group
'org-properties
2312 (defcustom org-columns-modify-value-for-display-function nil
2313 "Function that modifies values for display in column view.
2314 For example, it can be used to cut out a certain part from a time stamp.
2315 The function must take 2 arguments:
2317 column-title The title of the column (*not* the property name)
2318 value The value that should be modified.
2320 The function should return the value that should be displayed,
2321 or nil if the normal value should be used."
2322 :group
'org-properties
2325 (defcustom org-effort-property
"Effort"
2326 "The property that is being used to keep track of effort estimates.
2327 Effort estimates given in this property need to have the format H:MM."
2328 :group
'org-properties
2329 :group
'org-progress
2330 :type
'(string :tag
"Property"))
2332 (defconst org-global-properties-fixed
2333 '(("VISIBILITY_ALL" .
"folded children content all"))
2334 "List of property/value pairs that can be inherited by any entry.
2336 These are fixed values, for the preset properties. The user variable
2337 that can be used to add to this list is `org-global-properties'.
2339 The entries in this list are cons cells where the car is a property
2340 name and cdr is a string with the value. If the value represents
2341 multiple items like an \"_ALL\" property, separate the items by
2344 (defcustom org-global-properties nil
2345 "List of property/value pairs that can be inherited by any entry.
2347 This list will be combined with the constant `org-global-properties-fixed'.
2349 The entries in this list are cons cells where the car is a property
2350 name and cdr is a string with the value.
2352 You can set buffer-local values for the same purpose in the variable
2353 `org-file-properties' this by adding lines like
2355 #+PROPERTY: NAME VALUE"
2356 :group
'org-properties
2358 (cons (string :tag
"Property")
2359 (string :tag
"Value"))))
2361 (defvar org-file-properties nil
2362 "List of property/value pairs that can be inherited by any entry.
2363 Valid for the current buffer.
2364 This variable is populated from #+PROPERTY lines.")
2365 (make-variable-buffer-local 'org-file-properties
)
2367 (defgroup org-agenda nil
2368 "Options concerning agenda views in Org-mode."
2372 (defvar org-category nil
2373 "Variable used by org files to set a category for agenda display.
2374 Such files should use a file variable to set it, for example
2376 # -*- mode: org; org-category: \"ELisp\"
2378 or contain a special line
2382 If the file does not specify a category, then file's base name
2384 (make-variable-buffer-local 'org-category
)
2385 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2387 (defcustom org-agenda-files nil
2388 "The files to be used for agenda display.
2389 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2390 \\[org-remove-file]. You can also use customize to edit the list.
2392 If an entry is a directory, all files in that directory that are matched by
2393 `org-agenda-file-regexp' will be part of the file list.
2395 If the value of the variable is not a list but a single file name, then
2396 the list of agenda files is actually stored and maintained in that file, one
2397 agenda file per line."
2400 (repeat :tag
"List of files and directories" file
)
2401 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2403 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2404 "Regular expression to match files for `org-agenda-files'.
2405 If any element in the list in that variable contains a directory instead
2406 of a normal file, all files in that directory that are matched by this
2407 regular expression will be included."
2411 (defcustom org-agenda-text-search-extra-files nil
2412 "List of extra files to be searched by text search commands.
2413 These files will be search in addition to the agenda files by the
2414 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2415 Note that these files will only be searched for text search commands,
2416 not for the other agenda views like todo lists, tag searches or the weekly
2417 agenda. This variable is intended to list notes and possibly archive files
2418 that should also be searched by these two commands.
2419 In fact, if the first element in the list is the symbol `agenda-archives',
2420 than all archive files of all agenda files will be added to the search
2423 :type
'(set :greedy t
2424 (const :tag
"Agenda Archives" agenda-archives
)
2425 (repeat :inline t
(file))))
2427 (if (fboundp 'defvaralias
)
2428 (defvaralias 'org-agenda-multi-occur-extra-files
2429 'org-agenda-text-search-extra-files
))
2431 (defcustom org-agenda-skip-unavailable-files nil
2432 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2433 A nil value means to remove them, after a query, from the list."
2437 (defcustom org-calendar-to-agenda-key
[?c
]
2438 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2439 The command `org-calendar-goto-agenda' will be bound to this key. The
2440 default is the character `c' because then `c' can be used to switch back and
2441 forth between agenda and calendar."
2445 (defcustom org-calendar-agenda-action-key
[?k
]
2446 "The key to be installed in `calendar-mode-map' for agenda-action.
2447 The command `org-agenda-action' will be bound to this key. The
2448 default is the character `k' because we use the same key in the agenda."
2452 (eval-after-load "calendar"
2454 (org-defkey calendar-mode-map org-calendar-to-agenda-key
2455 'org-calendar-goto-agenda
)
2456 (org-defkey calendar-mode-map org-calendar-agenda-action-key
2457 'org-agenda-action
)))
2459 (defgroup org-latex nil
2460 "Options for embedding LaTeX code into Org-mode."
2464 (defcustom org-format-latex-options
2465 '(:foreground default
:background default
:scale
1.0
2466 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
2467 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
2468 "Options for creating images from LaTeX fragments.
2469 This is a property list with the following properties:
2470 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
2471 `default' means use the foreground of the default face.
2472 :background the background color, or \"Transparent\".
2473 `default' means use the background of the default face.
2474 :scale a scaling factor for the size of the images.
2475 :html-foreground, :html-background, :html-scale
2476 the same numbers for HTML export.
2477 :matchers a list indicating which matchers should be used to
2478 find LaTeX fragments. Valid members of this list are:
2479 \"begin\" find environments
2480 \"$1\" find single characters surrounded by $.$
2481 \"$\" find math expressions surrounded by $...$
2482 \"$$\" find math expressions surrounded by $$....$$
2483 \"\\(\" find math expressions surrounded by \\(...\\)
2484 \"\\ [\" find math expressions surrounded by \\ [...\\]"
2488 (defcustom org-format-latex-header
"\\documentclass{article}
2489 \\usepackage{fullpage} % do not remove
2490 \\usepackage{amssymb}
2491 \\usepackage[usenames]{color}
2492 \\usepackage{amsmath}
2493 \\usepackage{latexsym}
2494 \\usepackage[mathscr]{eucal}
2495 \\pagestyle{empty} % do not remove"
2496 "The document header used for processing LaTeX fragments."
2501 (defgroup org-font-lock nil
2502 "Font-lock settings for highlighting in Org-mode."
2503 :tag
"Org Font Lock"
2506 (defcustom org-level-color-stars-only nil
2507 "Non-nil means fontify only the stars in each headline.
2508 When nil, the entire headline is fontified.
2509 Changing it requires restart of `font-lock-mode' to become effective
2510 also in regions already fontified."
2511 :group
'org-font-lock
2514 (defcustom org-hide-leading-stars nil
2515 "Non-nil means, hide the first N-1 stars in a headline.
2516 This works by using the face `org-hide' for these stars. This
2517 face is white for a light background, and black for a dark
2518 background. You may have to customize the face `org-hide' to
2520 Changing it requires restart of `font-lock-mode' to become effective
2521 also in regions already fontified.
2522 You may also set this on a per-file basis by adding one of the following
2523 lines to the buffer:
2525 #+STARTUP: hidestars
2526 #+STARTUP: showstars"
2527 :group
'org-font-lock
2530 (defcustom org-fontify-done-headline nil
2531 "Non-nil means, change the face of a headline if it is marked DONE.
2532 Normally, only the TODO/DONE keyword indicates the state of a headline.
2533 When this is non-nil, the headline after the keyword is set to the
2534 `org-headline-done' as an additional indication."
2535 :group
'org-font-lock
2538 (defcustom org-fontify-emphasized-text t
2539 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
2540 Changing this variable requires a restart of Emacs to take effect."
2541 :group
'org-font-lock
2544 (defcustom org-highlight-latex-fragments-and-specials nil
2545 "Non-nil means, fontify what is treated specially by the exporters."
2546 :group
'org-font-lock
2549 (defcustom org-hide-emphasis-markers nil
2550 "Non-nil mean font-lock should hide the emphasis marker characters."
2551 :group
'org-font-lock
2554 (defvar org-emph-re nil
2555 "Regular expression for matching emphasis.")
2556 (defvar org-verbatim-re nil
2557 "Regular expression for matching verbatim text.")
2558 (defvar org-emphasis-regexp-components
) ; defined just below
2559 (defvar org-emphasis-alist
) ; defined just below
2560 (defun org-set-emph-re (var val
)
2561 "Set variable and compute the emphasis regular expression."
2563 (when (and (boundp 'org-emphasis-alist
)
2564 (boundp 'org-emphasis-regexp-components
)
2565 org-emphasis-alist org-emphasis-regexp-components
)
2566 (let* ((e org-emphasis-regexp-components
)
2572 (body1 (concat body
"*?"))
2573 (markers (mapconcat 'car org-emphasis-alist
""))
2574 (vmarkers (mapconcat
2575 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
2576 org-emphasis-alist
"")))
2577 ;; make sure special characters appear at the right position in the class
2578 (if (string-match "\\^" markers
)
2579 (setq markers
(concat (replace-match "" t t markers
) "^")))
2580 (if (string-match "-" markers
)
2581 (setq markers
(concat (replace-match "" t t markers
) "-")))
2582 (if (string-match "\\^" vmarkers
)
2583 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
2584 (if (string-match "-" vmarkers
)
2585 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
2587 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
2588 (int-to-string nl
) "\\}")))
2591 (concat "\\([" pre
"]\\|^\\)"
2593 "\\([" markers
"]\\)"
2601 "\\([" post
"]\\|$\\)"))
2602 (setq org-verbatim-re
2603 (concat "\\([" pre
"]\\|^\\)"
2605 "\\([" vmarkers
"]\\)"
2613 "\\([" post
"]\\|$\\)")))))
2615 (defcustom org-emphasis-regexp-components
2616 '(" \t('\"" "- \t.,:?;'\")" " \t\r\n,\"'" "." 1)
2617 "Components used to build the regular expression for emphasis.
2618 This is a list with 6 entries. Terminology: In an emphasis string
2619 like \" *strong word* \", we call the initial space PREMATCH, the final
2620 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
2621 and \"trong wor\" is the body. The different components in this variable
2622 specify what is allowed/forbidden in each part:
2624 pre Chars allowed as prematch. Beginning of line will be allowed too.
2625 post Chars allowed as postmatch. End of line will be allowed too.
2626 border The chars *forbidden* as border characters.
2627 body-regexp A regexp like \".\" to match a body character. Don't use
2628 non-shy groups here, and don't allow newline here.
2629 newline The maximum number of newlines allowed in an emphasis exp.
2631 Use customize to modify this, or restart Emacs after changing it."
2632 :group
'org-font-lock
2633 :set
'org-set-emph-re
2635 (sexp :tag
"Allowed chars in pre ")
2636 (sexp :tag
"Allowed chars in post ")
2637 (sexp :tag
"Forbidden chars in border ")
2638 (sexp :tag
"Regexp for body ")
2639 (integer :tag
"number of newlines allowed")
2640 (option (boolean :tag
"Please ignore this button"))))
2642 (defcustom org-emphasis-alist
2643 `(("*" bold
"<b>" "</b>")
2644 ("/" italic
"<i>" "</i>")
2645 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
2646 ("=" org-code
"<code>" "</code>" verbatim
)
2647 ("~" org-verbatim
"<code>" "</code>" verbatim
)
2648 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
2651 "Special syntax for emphasized text.
2652 Text starting and ending with a special character will be emphasized, for
2653 example *bold*, _underlined_ and /italic/. This variable sets the marker
2654 characters, the face to be used by font-lock for highlighting in Org-mode
2655 Emacs buffers, and the HTML tags to be used for this.
2656 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
2657 Use customize to modify this, or restart Emacs after changing it."
2658 :group
'org-font-lock
2659 :set
'org-set-emph-re
2662 (string :tag
"Marker character")
2664 (face :tag
"Font-lock-face")
2665 (plist :tag
"Face property list"))
2666 (string :tag
"HTML start tag")
2667 (string :tag
"HTML end tag")
2668 (option (const verbatim
)))))
2670 ;;; Miscellaneous options
2672 (defgroup org-completion nil
2673 "Completion in Org-mode."
2674 :tag
"Org Completion"
2677 (defcustom org-completion-use-ido nil
2678 "Non-nil means, use ido completion wherever possible.
2679 Note that `ido-mode' must be active for this variable to be relevant.
2680 If you decide to turn this variable on, you might well want to turn off
2681 `org-outline-path-complete-in-steps'."
2682 :group
'org-completion
2685 (defcustom org-completion-fallback-command
'hippie-expand
2686 "The expansion command called by \\[org-complete] in normal context.
2687 Normal means, no org-mode-specific context."
2688 :group
'org-completion
2691 ;;; Functions and variables from ther packages
2692 ;; Declared here to avoid compiler warnings
2695 (defvar outline-mode-menu-heading
)
2696 (defvar outline-mode-menu-show
)
2697 (defvar outline-mode-menu-hide
)
2698 (defvar zmacs-regions
) ; XEmacs regions
2701 (defvar mark-active
)
2704 (declare-function find-library-name
"find-func" (library))
2705 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
2706 (declare-function calendar-forward-day
"cal-move" (arg))
2707 (declare-function calendar-goto-date
"cal-move" (date))
2708 (declare-function calendar-goto-today
"cal-move" ())
2709 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
2710 (defvar calc-embedded-close-formula
)
2711 (defvar calc-embedded-open-formula
)
2712 (declare-function cdlatex-tab
"ext:cdlatex" ())
2713 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
2714 (defvar font-lock-unfontify-region-function
)
2715 (declare-function iswitchb-mode
"iswitchb" (&optional arg
))
2716 (declare-function iswitchb-read-buffer
(prompt &optional default require-match start matches-set
))
2717 (defvar iswitchb-temp-buflist
)
2718 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
2719 (defvar org-agenda-tags-todo-honor-ignore-options
)
2720 (declare-function org-agenda-skip
"org-agenda" ())
2721 (declare-function org-format-agenda-item
"org-agenda"
2722 (extra txt
&optional category tags dotime noprefix remove-re
))
2723 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
2724 (declare-function org-agenda-change-all-lines
"org-agenda"
2725 (newhead hdmarker
&optional fixface just-this
))
2726 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
2727 (declare-function org-agenda-maybe-redo
"org-agenda" ())
2728 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
2730 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
2731 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
2732 "org-agenda" (&optional end
))
2734 (declare-function parse-time-string
"parse-time" (string))
2735 (declare-function remember
"remember" (&optional initial
))
2736 (declare-function remember-buffer-desc
"remember" ())
2737 (declare-function remember-finalize
"remember" ())
2738 (defvar remember-save-after-remembering
)
2739 (defvar remember-data-file
)
2740 (defvar remember-register
)
2741 (defvar remember-buffer
)
2742 (defvar remember-handler-functions
)
2743 (defvar remember-annotation-functions
)
2744 (defvar texmathp-why
)
2745 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
2746 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
2748 (defvar w3m-current-url
)
2749 (defvar w3m-current-title
)
2751 (defvar org-latex-regexps
)
2753 ;;; Autoload and prepare some org modules
2755 ;; Some table stuff that needs to be defined here, because it is used
2756 ;; by the functions setting up org-mode or checking for table context.
2758 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
2759 "Detects an org-type or table-type table.")
2760 (defconst org-table-line-regexp
"^[ \t]*|"
2761 "Detects an org-type table line.")
2762 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
2763 "Detects an org-type table line.")
2764 (defconst org-table-hline-regexp
"^[ \t]*|-"
2765 "Detects an org-type table hline.")
2766 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
2767 "Detects a table-type table hline.")
2768 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
2769 "Searching from within a table (any type) this finds the first line
2770 outside the table.")
2772 ;; Autoload the functions in org-table.el that are needed by functions here.
2775 (org-autoload "org-table"
2776 '(org-table-align org-table-begin org-table-blank-field
2777 org-table-convert org-table-convert-region org-table-copy-down
2778 org-table-copy-region org-table-create
2779 org-table-create-or-convert-from-region
2780 org-table-create-with-table.el org-table-current-dline
2781 org-table-cut-region org-table-delete-column org-table-edit-field
2782 org-table-edit-formulas org-table-end org-table-eval-formula
2783 org-table-export org-table-field-info
2784 org-table-get-stored-formulas org-table-goto-column
2785 org-table-hline-and-move org-table-import org-table-insert-column
2786 org-table-insert-hline org-table-insert-row org-table-iterate
2787 org-table-justify-field-maybe org-table-kill-row
2788 org-table-maybe-eval-formula org-table-maybe-recalculate-line
2789 org-table-move-column org-table-move-column-left
2790 org-table-move-column-right org-table-move-row
2791 org-table-move-row-down org-table-move-row-up
2792 org-table-next-field org-table-next-row org-table-paste-rectangle
2793 org-table-previous-field org-table-recalculate
2794 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
2795 org-table-toggle-coordinate-overlays
2796 org-table-toggle-formula-debugger org-table-wrap-region
2797 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
2799 (defun org-at-table-p (&optional table-type
)
2800 "Return t if the cursor is inside an org-type table.
2801 If TABLE-TYPE is non-nil, also check for table.el-type tables."
2802 (if org-enable-table-editor
2804 (beginning-of-line 1)
2805 (looking-at (if table-type org-table-any-line-regexp
2806 org-table-line-regexp
)))
2808 (defsubst org-table-p
() (org-at-table-p))
2810 (defun org-at-table.el-p
()
2811 "Return t if and only if we are at a table.el table."
2812 (and (org-at-table-p 'any
)
2814 (goto-char (org-table-begin 'any
))
2815 (looking-at org-table1-hline-regexp
))))
2816 (defun org-table-recognize-table.el
()
2817 "If there is a table.el table nearby, recognize it and move into it."
2818 (if org-table-tab-recognizes-table.el
2819 (if (org-at-table.el-p
)
2821 (beginning-of-line 1)
2822 (if (looking-at org-table-dataline-regexp
)
2824 (if (looking-at org-table1-hline-regexp
)
2826 (beginning-of-line 2)
2827 (if (looking-at org-table-any-border-regexp
)
2828 (beginning-of-line -
1)))))
2829 (if (re-search-forward "|" (org-table-end t
) t
)
2832 (if (table--at-cell-p (point))
2834 (message "recognizing table.el table...")
2835 (table-recognize-table)
2836 (message "recognizing table.el table...done")))
2837 (error "This should not happen..."))
2842 (defun org-at-table-hline-p ()
2843 "Return t if the cursor is inside a hline in a table."
2844 (if org-enable-table-editor
2846 (beginning-of-line 1)
2847 (looking-at org-table-hline-regexp
))
2850 (defvar org-table-clean-did-remove-column nil
)
2852 (defun org-table-map-tables (function)
2853 "Apply FUNCTION to the start of all tables in the buffer."
2857 (goto-char (point-min))
2858 (while (re-search-forward org-table-any-line-regexp nil t
)
2859 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
2860 (beginning-of-line 1)
2861 (if (looking-at org-table-line-regexp
)
2862 (save-excursion (funcall function
)))
2863 (re-search-forward org-table-any-border-regexp nil
1))))
2864 (message "Mapping tables: done"))
2866 ;; Declare and autoload functions from org-exp.el
2868 (declare-function org-default-export-plist
"org-exp")
2869 (declare-function org-infile-export-plist
"org-exp")
2870 (declare-function org-get-current-options
"org-exp")
2872 (org-autoload "org-exp"
2873 '(org-export org-export-as-ascii org-export-visible
2874 org-insert-export-options-template org-export-as-html-and-open
2875 org-export-as-html-batch org-export-as-html-to-buffer
2876 org-replace-region-by-html org-export-region-as-html
2877 org-export-as-html org-export-icalendar-this-file
2878 org-export-icalendar-all-agenda-files
2879 org-table-clean-before-export
2880 org-export-icalendar-combine-agenda-files org-export-as-xoxo
)))
2882 ;; Declare and autoload functions from org-agenda.el
2885 (org-autoload "org-agenda"
2886 '(org-agenda org-agenda-list org-search-view
2887 org-todo-list org-tags-view org-agenda-list-stuck-projects
2888 org-diary org-agenda-to-appt
2889 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
2891 ;; Autoload org-remember
2894 (org-autoload "org-remember"
2895 '(org-remember-insinuate org-remember-annotation
2896 org-remember-apply-template org-remember org-remember-handler
)))
2898 ;; Autoload org-clock.el
2901 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
2903 (declare-function org-clock-update-mode-line
"org-clock" ())
2904 (defvar org-clock-start-time
)
2905 (defvar org-clock-marker
(make-marker)
2906 "Marker recording the last clock-in.")
2911 '(org-clock-in org-clock-out org-clock-cancel
2912 org-clock-goto org-clock-sum org-clock-display
2913 org-clock-remove-overlays org-clock-report
2914 org-clocktable-shift org-dblock-write
:clocktable
2915 org-get-clocktable
)))
2917 (defun org-clock-update-time-maybe ()
2918 "If this is a CLOCK line, update it and return t.
2919 Otherwise, return nil."
2922 (beginning-of-line 1)
2923 (skip-chars-forward " \t")
2924 (when (looking-at org-clock-string
)
2925 (let ((re (concat "[ \t]*" org-clock-string
2926 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
2927 "\\([ \t]*=>.*\\)?\\)?"))
2930 ((not (looking-at re
))
2932 ((not (match-end 2))
2933 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
2934 (> org-clock-marker
(point))
2935 (<= org-clock-marker
(point-at-eol)))
2936 ;; The clock is running here
2937 (setq org-clock-start-time
2939 (org-parse-time-string (match-string 1))))
2940 (org-clock-update-mode-line)))
2942 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
2944 (setq ts
(match-string 1)
2945 te
(match-string 3))
2946 (setq s
(- (time-to-seconds
2947 (apply 'encode-time
(org-parse-time-string te
)))
2949 (apply 'encode-time
(org-parse-time-string ts
))))
2952 h
(floor (/ s
3600))
2956 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
2959 (defun org-check-running-clock ()
2960 "Check if the current buffer contains the running clock.
2961 If yes, offer to stop it and to save the buffer with the changes."
2962 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
2963 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
2966 (when (y-or-n-p "Save changed buffer?")
2969 (defun org-clocktable-try-shift (dir n
)
2970 "Check if this line starts a clock table, if yes, shift the time block."
2971 (when (org-match-line "#\\+BEGIN: clocktable\\>")
2972 (org-clocktable-shift dir n
)))
2974 ;; Autoload org-timer.el
2976 ;(declare-function org-timer "org-timer")
2981 '(org-timer-start org-timer org-timer-item
2982 org-timer-change-times-in-region
)))
2985 ;; Autoload archiving code
2986 ;; The stuff that is needed for cycling and tags has to be defined here.
2988 (defgroup org-archive nil
2989 "Options concerning archiving in Org-mode."
2991 :group
'org-structure
)
2993 (defcustom org-archive-location
"%s_archive::"
2994 "The location where subtrees should be archived.
2996 The value of this variable is a string, consisting of two parts,
2997 separated by a double-colon. The first part is a filename and
2998 the second part is a headline.
3000 When the filename is omitted, archiving happens in the same file.
3001 %s in the filename will be replaced by the current file
3002 name (without the directory part). Archiving to a different file
3003 is useful to keep archived entries from contributing to the
3006 The archived entries will be filed as subtrees of the specified
3007 headline. When the headline is omitted, the subtrees are simply
3008 filed away at the end of the file, as top-level entries. Also in
3009 the heading you can use %s to represent the file name, this can be
3010 useful when using the same archive for a number of different files.
3012 Here are a few examples:
3014 If the current file is Projects.org, archive in file
3015 Projects.org_archive, as top-level trees. This is the default.
3017 \"::* Archived Tasks\"
3018 Archive in the current file, under the top-level headline
3019 \"* Archived Tasks\".
3021 \"~/org/archive.org::\"
3022 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3024 \"~/org/archive.org::From %s\"
3025 Archive in file ~/org/archive.org (absolute path), und headlines
3026 \"From FILENAME\" where file name is the current file name.
3028 \"basement::** Finished Tasks\"
3029 Archive in file ./basement (relative path), as level 3 trees
3030 below the level 2 heading \"** Finished Tasks\".
3032 You may set this option on a per-file basis by adding to the buffer a
3035 #+ARCHIVE: basement::** Finished Tasks
3037 You may also define it locally for a subtree by setting an ARCHIVE property
3038 in the entry. If such a property is found in an entry, or anywhere up
3039 the hierarchy, it will be used."
3043 (defcustom org-archive-tag
"ARCHIVE"
3044 "The tag that marks a subtree as archived.
3045 An archived subtree does not open during visibility cycling, and does
3046 not contribute to the agenda listings.
3047 After changing this, font-lock must be restarted in the relevant buffers to
3048 get the proper fontification."
3050 :group
'org-keywords
3053 (defcustom org-agenda-skip-archived-trees t
3054 "Non-nil means, the agenda will skip any items located in archived trees.
3055 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3056 variable is no longer recommended, you should leave it at the value t.
3057 Instead, use the key `v' to cycle the archives-mode in the agenda."
3059 :group
'org-agenda-skip
3062 (defcustom org-cycle-open-archived-trees nil
3063 "Non-nil means, `org-cycle' will open archived trees.
3064 An archived tree is a tree marked with the tag ARCHIVE.
3065 When nil, archived trees will stay folded. You can still open them with
3066 normal outline commands like `show-all', but not with the cycling commands."
3071 (defcustom org-sparse-tree-open-archived-trees nil
3072 "Non-nil means sparse tree construction shows matches in archived trees.
3073 When nil, matches in these trees are highlighted, but the trees are kept in
3076 :group
'org-sparse-trees
3079 (defun org-cycle-hide-archived-subtrees (state)
3080 "Re-hide all archived subtrees after a visibility state change."
3081 (when (and (not org-cycle-open-archived-trees
)
3082 (not (memq state
'(overview folded
))))
3084 (let* ((globalp (memq state
'(contents all
)))
3085 (beg (if globalp
(point-min) (point)))
3086 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3087 (org-hide-archived-subtrees beg end
)
3089 (if (looking-at (concat ".*:" org-archive-tag
":"))
3090 (message "%s" (substitute-command-keys
3091 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3093 (defun org-force-cycle-archived ()
3094 "Cycle subtree even if it is archived."
3096 (setq this-command
'org-cycle
)
3097 (let ((org-cycle-open-archived-trees t
))
3098 (call-interactively 'org-cycle
)))
3100 (defun org-hide-archived-subtrees (beg end
)
3101 "Re-hide all archived subtrees after a visibility state change."
3103 (let* ((re (concat ":" org-archive-tag
":")))
3105 (while (re-search-forward re end t
)
3106 (and (org-on-heading-p) (hide-subtree))
3107 (org-end-of-subtree t
)))))
3109 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3112 (org-autoload "org-archive"
3113 '(org-add-archive-files org-archive-subtree
3114 org-archive-to-archive-sibling org-toggle-archive-tag
)))
3116 ;; Autoload Column View Code
3118 (declare-function org-columns-number-to-string
"org-colview")
3119 (declare-function org-columns-get-format-and-top-level
"org-colview")
3120 (declare-function org-columns-compute
"org-colview")
3122 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3123 '(org-columns-number-to-string org-columns-get-format-and-top-level
3124 org-columns-compute org-agenda-columns org-columns-remove-overlays
3125 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3129 (declare-function org-id-store-link
"org-id")
3130 (declare-function org-id-locations-load
"org-id")
3131 (declare-function org-id-locations-save
"org-id")
3132 (defvar org-id-track-globally
)
3133 (org-autoload "org-id"
3134 '(org-id-get-create org-id-new org-id-copy org-id-get
3135 org-id-get-with-outline-path-completion
3136 org-id-get-with-outline-drilling
3137 org-id-goto org-id-find org-id-store-link
))
3139 ;; Autoload Plotting Code
3141 (org-autoload "org-plot"
3142 '(org-plot/gnuplot
))
3144 ;;; Variables for pre-computed regular expressions, all buffer local
3146 (defvar org-drawer-regexp nil
3147 "Matches first line of a hidden block.")
3148 (make-variable-buffer-local 'org-drawer-regexp
)
3149 (defvar org-todo-regexp nil
3150 "Matches any of the TODO state keywords.")
3151 (make-variable-buffer-local 'org-todo-regexp
)
3152 (defvar org-not-done-regexp nil
3153 "Matches any of the TODO state keywords except the last one.")
3154 (make-variable-buffer-local 'org-not-done-regexp
)
3155 (defvar org-todo-line-regexp nil
3156 "Matches a headline and puts TODO state into group 2 if present.")
3157 (make-variable-buffer-local 'org-todo-line-regexp
)
3158 (defvar org-complex-heading-regexp nil
3159 "Matches a headline and puts everything into groups:
3161 group 2: The todo keyword, maybe
3162 group 3: Priority cookie
3163 group 4: True headline
3165 (make-variable-buffer-local 'org-complex-heading-regexp
)
3166 (defvar org-todo-line-tags-regexp nil
3167 "Matches a headline and puts TODO state into group 2 if present.
3168 Also put tags into group 4 if tags are present.")
3169 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3170 (defvar org-nl-done-regexp nil
3171 "Matches newline followed by a headline with the DONE keyword.")
3172 (make-variable-buffer-local 'org-nl-done-regexp
)
3173 (defvar org-looking-at-done-regexp nil
3174 "Matches the DONE keyword a point.")
3175 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3176 (defvar org-ds-keyword-length
12
3177 "Maximum length of the Deadline and SCHEDULED keywords.")
3178 (make-variable-buffer-local 'org-ds-keyword-length
)
3179 (defvar org-deadline-regexp nil
3180 "Matches the DEADLINE keyword.")
3181 (make-variable-buffer-local 'org-deadline-regexp
)
3182 (defvar org-deadline-time-regexp nil
3183 "Matches the DEADLINE keyword together with a time stamp.")
3184 (make-variable-buffer-local 'org-deadline-time-regexp
)
3185 (defvar org-deadline-line-regexp nil
3186 "Matches the DEADLINE keyword and the rest of the line.")
3187 (make-variable-buffer-local 'org-deadline-line-regexp
)
3188 (defvar org-scheduled-regexp nil
3189 "Matches the SCHEDULED keyword.")
3190 (make-variable-buffer-local 'org-scheduled-regexp
)
3191 (defvar org-scheduled-time-regexp nil
3192 "Matches the SCHEDULED keyword together with a time stamp.")
3193 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3194 (defvar org-closed-time-regexp nil
3195 "Matches the CLOSED keyword together with a time stamp.")
3196 (make-variable-buffer-local 'org-closed-time-regexp
)
3198 (defvar org-keyword-time-regexp nil
3199 "Matches any of the 4 keywords, together with the time stamp.")
3200 (make-variable-buffer-local 'org-keyword-time-regexp
)
3201 (defvar org-keyword-time-not-clock-regexp nil
3202 "Matches any of the 3 keywords, together with the time stamp.")
3203 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
3204 (defvar org-maybe-keyword-time-regexp nil
3205 "Matches a timestamp, possibly preceeded by a keyword.")
3206 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
3207 (defvar org-planning-or-clock-line-re nil
3208 "Matches a line with planning or clock info.")
3209 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
3211 (defconst org-plain-time-of-day-regexp
3214 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3217 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3219 "Regular expression to match a plain time or time range.
3220 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3221 groups carry important information:
3223 1 the first time, range or not
3224 8 the second time, if it is a range.")
3226 (defconst org-plain-time-extension-regexp
3229 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3230 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3231 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3232 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3233 groups carry important information:
3236 9 minutes of duration")
3238 (defconst org-stamp-time-of-day-regexp
3240 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3241 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3243 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3244 "Regular expression to match a timestamp time or time range.
3245 After a match, the following groups carry important information:
3247 1 date plus weekday, for backreferencing to make sure both times on same day
3248 2 the first time, range or not
3249 4 the second time, if it is a range.")
3251 (defconst org-startup-options
3252 '(("fold" org-startup-folded t
)
3253 ("overview" org-startup-folded t
)
3254 ("nofold" org-startup-folded nil
)
3255 ("showall" org-startup-folded nil
)
3256 ("content" org-startup-folded content
)
3257 ("hidestars" org-hide-leading-stars t
)
3258 ("showstars" org-hide-leading-stars nil
)
3259 ("odd" org-odd-levels-only t
)
3260 ("oddeven" org-odd-levels-only nil
)
3261 ("align" org-startup-align-all-tables t
)
3262 ("noalign" org-startup-align-all-tables nil
)
3263 ("customtime" org-display-custom-times t
)
3264 ("logdone" org-log-done time
)
3265 ("lognotedone" org-log-done note
)
3266 ("nologdone" org-log-done nil
)
3267 ("lognoteclock-out" org-log-note-clock-out t
)
3268 ("nolognoteclock-out" org-log-note-clock-out nil
)
3269 ("logrepeat" org-log-repeat state
)
3270 ("lognoterepeat" org-log-repeat note
)
3271 ("nologrepeat" org-log-repeat nil
)
3272 ("fninline" org-footnote-define-inline t
)
3273 ("nofninline" org-footnote-define-inline nil
)
3274 ("fnlocal" org-footnote-section nil
)
3275 ("fnauto" org-footnote-auto-label t
)
3276 ("fnprompt" org-footnote-auto-label nil
)
3277 ("fnconfirm" org-footnote-auto-label confirm
)
3278 ("fnplain" org-footnote-auto-label plain
)
3279 ("constcgs" constants-unit-system cgs
)
3280 ("constSI" constants-unit-system SI
)
3281 ("noptag" org-tag-persistent-alist nil
))
3282 "Variable associated with STARTUP options for org-mode.
3283 Each element is a list of three items: The startup options as written
3284 in the #+STARTUP line, the corresponding variable, and the value to
3285 set this variable to if the option is found. An optional forth element PUSH
3286 means to push this value onto the list in the variable.")
3288 (defun org-set-regexps-and-options ()
3289 "Precompute regular expressions for current buffer."
3291 (org-set-local 'org-todo-kwd-alist nil
)
3292 (org-set-local 'org-todo-key-alist nil
)
3293 (org-set-local 'org-todo-key-trigger nil
)
3294 (org-set-local 'org-todo-keywords-1 nil
)
3295 (org-set-local 'org-done-keywords nil
)
3296 (org-set-local 'org-todo-heads nil
)
3297 (org-set-local 'org-todo-sets nil
)
3298 (org-set-local 'org-todo-log-states nil
)
3299 (org-set-local 'org-file-properties nil
)
3300 (org-set-local 'org-file-tags nil
)
3301 (let ((re (org-make-options-regexp
3302 '("CATEGORY" "TODO" "COLUMNS"
3303 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
3304 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE")
3305 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
3307 kwds kws0 kwsa key log value cat arch tags const links hw dws
3308 tail sep kws1 prio props ftags drawers
3309 ext-setup-or-nil setup-contents
(start 0))
3313 (goto-char (point-min))
3314 (while (or (and ext-setup-or-nil
3315 (string-match re ext-setup-or-nil start
)
3316 (setq start
(match-end 0)))
3317 (and (setq ext-setup-or-nil nil start
0)
3318 (re-search-forward re nil t
)))
3319 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
3320 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
3322 ((equal key
"CATEGORY")
3323 (if (string-match "[ \t]+$" value
)
3324 (setq value
(replace-match "" t t value
)))
3326 ((member key
'("SEQ_TODO" "TODO"))
3327 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
3328 ((equal key
"TYP_TODO")
3329 (push (cons 'type
(org-split-string value splitre
)) kwds
))
3330 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
3331 ;; general TODO-like setup
3332 (push (cons (intern (downcase (match-string 1 key
)))
3333 (org-split-string value splitre
)) kwds
))
3335 (setq tags
(append tags
(if tags
'("\\n") nil
)
3336 (org-split-string value splitre
))))
3337 ((equal key
"COLUMNS")
3338 (org-set-local 'org-columns-default-format value
))
3340 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
3341 (push (cons (match-string 1 value
)
3342 (org-trim (match-string 2 value
)))
3344 ((equal key
"PRIORITIES")
3345 (setq prio
(org-split-string value
" +")))
3346 ((equal key
"PROPERTY")
3347 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
3348 (push (cons (match-string 1 value
) (match-string 2 value
))
3350 ((equal key
"FILETAGS")
3351 (when (string-match "\\S-" value
)
3356 (mapcar (lambda (x) (org-split-string x
":"))
3357 (org-split-string value
)))))))
3358 ((equal key
"DRAWERS")
3359 (setq drawers
(org-split-string value splitre
)))
3360 ((equal key
"CONSTANTS")
3361 (setq const
(append const
(org-split-string value splitre
))))
3362 ((equal key
"STARTUP")
3363 (let ((opts (org-split-string value splitre
))
3365 (while (setq l
(pop opts
))
3366 (when (setq l
(assoc l org-startup-options
))
3367 (setq var
(nth 1 l
) val
(nth 2 l
))
3369 (set (make-local-variable var
) val
)
3370 (if (not (listp (symbol-value var
)))
3371 (set (make-local-variable var
) nil
))
3372 (set (make-local-variable var
) (symbol-value var
))
3373 (add-to-list var val
))))))
3374 ((equal key
"ARCHIVE")
3375 (string-match " *$" value
)
3376 (setq arch
(replace-match "" t t value
))
3377 (remove-text-properties 0 (length arch
)
3378 '(face t fontified t
) arch
))
3379 ((equal key
"SETUPFILE")
3380 (setq setup-contents
(org-file-contents
3382 (org-remove-double-quotes value
))
3384 (if (not ext-setup-or-nil
)
3385 (setq ext-setup-or-nil setup-contents start
0)
3386 (setq ext-setup-or-nil
3387 (concat (substring ext-setup-or-nil
0 start
)
3388 "\n" setup-contents
"\n"
3389 (substring ext-setup-or-nil start
)))))
3392 (org-set-local 'org-category
(intern cat
))
3393 (push (cons "CATEGORY" cat
) props
))
3395 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
3396 (setq prio
(mapcar 'string-to-char prio
))
3397 (org-set-local 'org-highest-priority
(nth 0 prio
))
3398 (org-set-local 'org-lowest-priority
(nth 1 prio
))
3399 (org-set-local 'org-default-priority
(nth 2 prio
)))
3400 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
3401 (and ftags
(org-set-local 'org-file-tags ftags
))
3402 (and drawers
(org-set-local 'org-drawers drawers
))
3403 (and arch
(org-set-local 'org-archive-location arch
))
3404 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
3405 ;; Process the TODO keywords
3407 ;; Use the global values as if they had been given locally.
3408 (setq kwds
(default-value 'org-todo-keywords
))
3409 (if (stringp (car kwds
))
3410 (setq kwds
(list (cons org-todo-interpretation
3411 (default-value 'org-todo-keywords
)))))
3412 (setq kwds
(reverse kwds
)))
3413 (setq kwds
(nreverse kwds
))
3415 (while (setq kws
(pop kwds
))
3417 (run-hook-with-args-until-success
3418 'org-todo-setup-filter-hook kws
)
3420 (setq inter
(pop kws
) sep
(member "|" kws
)
3421 kws0
(delete "|" (copy-sequence kws
))
3426 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
3428 (setq kw
(match-string 1 x
)
3429 key
(and (match-end 2) (match-string 2 x
))
3430 log
(org-extract-log-state-settings x
))
3431 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
3432 (and log
(push log org-todo-log-states
))
3434 (error "Invalid TODO keyword %s" x
)))
3436 kwsa
(if kwsa
(append '((:startgroup
))
3440 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
3441 tail
(list inter hw
(car dws
) (org-last dws
))))
3442 (add-to-list 'org-todo-heads hw
'append
)
3443 (push kws1 org-todo-sets
)
3444 (setq org-done-keywords
(append org-done-keywords dws nil
))
3445 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
3446 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
3447 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
3448 (setq org-todo-sets
(nreverse org-todo-sets
)
3449 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
3450 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
3451 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
3452 ;; Process the constants
3455 (while (setq e
(pop const
))
3456 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
3457 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
3458 (setq org-table-formula-constants-local cst
)))
3460 ;; Process the tags.
3463 (while (setq e
(pop tags
))
3465 ((equal e
"{") (push '(:startgroup
) tgs
))
3466 ((equal e
"}") (push '(:endgroup
) tgs
))
3467 ((equal e
"\\n") (push '(:newline
) tgs
))
3468 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
3469 (push (cons (match-string 1 e
)
3470 (string-to-char (match-string 2 e
)))
3472 (t (push (list e
) tgs
))))
3473 (org-set-local 'org-tag-alist nil
)
3474 (while (setq e
(pop tgs
))
3475 (or (and (stringp (car e
))
3476 (assoc (car e
) org-tag-alist
))
3477 (push e org-tag-alist
)))))
3479 ;; Compute the regular expressions and other local variables
3480 (if (not org-done-keywords
)
3481 (setq org-done-keywords
(list (org-last org-todo-keywords-1
))))
3482 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
3483 (length org-scheduled-string
)
3484 (length org-clock-string
)
3485 (length org-closed-string
)))
3487 (concat "^[ \t]*:\\("
3488 (mapconcat 'regexp-quote org-drawers
"\\|")
3490 org-not-done-keywords
3491 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
3493 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
3497 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
3499 org-todo-line-regexp
3500 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
3501 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
3502 "\\)\\>\\)?[ \t]*\\(.*\\)")
3503 org-complex-heading-regexp
3504 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
3505 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
3506 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
3507 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
3509 (concat "\n\\*+[ \t]+"
3510 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
3512 org-todo-line-tags-regexp
3513 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
3514 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
3516 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
3517 org-looking-at-done-regexp
3519 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
3521 org-deadline-regexp
(concat "\\<" org-deadline-string
)
3522 org-deadline-time-regexp
3523 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
3524 org-deadline-line-regexp
3525 (concat "\\<\\(" org-deadline-string
"\\).*")
3526 org-scheduled-regexp
3527 (concat "\\<" org-scheduled-string
)
3528 org-scheduled-time-regexp
3529 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
3530 org-closed-time-regexp
3531 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
3532 org-keyword-time-regexp
3533 (concat "\\<\\(" org-scheduled-string
3534 "\\|" org-deadline-string
3535 "\\|" org-closed-string
3536 "\\|" org-clock-string
"\\)"
3537 " *[[<]\\([^]>]+\\)[]>]")
3538 org-keyword-time-not-clock-regexp
3539 (concat "\\<\\(" org-scheduled-string
3540 "\\|" org-deadline-string
3541 "\\|" org-closed-string
3543 " *[[<]\\([^]>]+\\)[]>]")
3544 org-maybe-keyword-time-regexp
3545 (concat "\\(\\<\\(" org-scheduled-string
3546 "\\|" org-deadline-string
3547 "\\|" org-closed-string
3548 "\\|" org-clock-string
"\\)\\)?"
3549 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
3550 org-planning-or-clock-line-re
3551 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
3552 "\\|" org-deadline-string
3553 "\\|" org-closed-string
"\\|" org-clock-string
3556 (org-compute-latex-and-specials-regexp)
3557 (org-set-font-lock-defaults))))
3559 (defun org-file-contents (file &optional noerror
)
3560 "Return the contents of FILE, as a string."
3562 (not (file-readable-p file
)))
3565 (message "Cannot read file %s" file
)
3568 (error "Cannot read file %s" file
))
3570 (insert-file-contents file
)
3573 (defun org-extract-log-state-settings (x)
3574 "Extract the log state setting from a TODO keyword string.
3575 This will extract info from a string like \"WAIT(w@/!)\"."
3576 (let (kw key log1 log2
)
3577 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
3578 (setq kw
(match-string 1 x
)
3579 key
(and (match-end 2) (match-string 2 x
))
3580 log1
(and (match-end 3) (match-string 3 x
))
3581 log2
(and (match-end 4) (match-string 4 x
)))
3584 (and log1
(if (equal log1
"!") 'time
'note
))
3585 (and log2
(if (equal log2
"!") 'time
'note
)))))))
3587 (defun org-remove-keyword-keys (list)
3588 "Remove a pair of parenthesis at the end of each string in LIST."
3590 (if (string-match "(.*)$" x
)
3591 (substring x
0 (match-beginning 0))
3595 ;; FIXME: this could be done much better, using second characters etc.
3596 (defun org-assign-fast-keys (alist)
3597 "Assign fast keys to a keyword-key alist.
3598 Respect keys that are already there."
3599 (let (new e k c c1 c2
(char ?a
))
3600 (while (setq e
(pop alist
))
3602 ((equal e
'(:startgroup
)) (push e new
))
3603 ((equal e
'(:endgroup
)) (push e new
))
3604 ((equal e
'(:newline
)) (push e new
))
3606 (setq k
(car e
) c2 nil
)
3609 ;; automatically assign a character.
3610 (setq c1
(string-to-char
3611 (downcase (substring
3612 k
(if (= (string-to-char k
) ?
@) 1 0)))))
3613 (if (or (rassoc c1 new
) (rassoc c1 alist
))
3614 (while (or (rassoc char new
) (rassoc char alist
))
3615 (setq char
(1+ char
)))
3617 (setq c
(or c2 char
)))
3618 (push (cons k c
) new
))))
3621 ;;; Some variables used in various places
3623 (defvar org-window-configuration nil
3624 "Used in various places to store a window configuration.")
3625 (defvar org-finish-function nil
3626 "Function to be called when `C-c C-c' is used.
3627 This is for getting out of special buffers like remember.")
3630 ;; FIXME: Occasionally check by commenting these, to make sure
3631 ;; no other functions uses these, forgetting to let-bind them.
3636 (defvar description
)
3638 ;; Defined somewhere in this file, but used before definition.
3639 (defvar org-html-entities
)
3640 (defvar org-struct-menu
)
3641 (defvar org-org-menu
)
3642 (defvar org-tbl-menu
)
3643 (defvar org-agenda-keymap
)
3645 ;;;; Define the Org-mode
3647 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
3648 (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."))
3651 ;; We use a before-change function to check if a table might need
3653 (defvar org-table-may-need-update t
3654 "Indicates that a table might need an update.
3655 This variable is set by `org-before-change-function'.
3656 `org-table-align' sets it back to nil.")
3657 (defun org-before-change-function (beg end
)
3658 "Every change indicates that a table might need an update."
3659 (setq org-table-may-need-update t
))
3660 (defvar org-mode-map
)
3661 (defvar org-mode-hook nil
3662 "Mode hook for Org-mode, run after the mode was turned on.")
3663 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
3664 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
3665 (defvar org-table-buffer-is-an nil
)
3666 (defconst org-outline-regexp
"\\*+ ")
3669 (define-derived-mode org-mode outline-mode
"Org"
3670 "Outline-based notes management and organizer, alias
3671 \"Carsten's outline-mode for keeping track of everything.\"
3673 Org-mode develops organizational tasks around a NOTES file which
3674 contains information about projects as plain text. Org-mode is
3675 implemented on top of outline-mode, which is ideal to keep the content
3676 of large files well structured. It supports ToDo items, deadlines and
3677 time stamps, which magically appear in the diary listing of the Emacs
3678 calendar. Tables are easily created with a built-in table editor.
3679 Plain text URL-like links connect to websites, emails (VM), Usenet
3680 messages (Gnus), BBDB entries, and any files related to the project.
3681 For printing and sharing of notes, an Org-mode file (or a part of it)
3682 can be exported as a structured ASCII or HTML file.
3684 The following commands are available:
3688 ;; Get rid of Outline menus, they are not needed
3689 ;; Need to do this here because define-derived-mode sets up
3690 ;; the keymap so late. Still, it is a waste to call this each time
3691 ;; we switch another buffer into org-mode.
3692 (if (featurep 'xemacs
)
3693 (when (boundp 'outline-mode-menu-heading
)
3694 ;; Assume this is Greg's port, it used easymenu
3695 (easy-menu-remove outline-mode-menu-heading
)
3696 (easy-menu-remove outline-mode-menu-show
)
3697 (easy-menu-remove outline-mode-menu-hide
))
3698 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
3699 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
3700 (define-key org-mode-map
[menu-bar show
] 'undefined
))
3702 (org-load-modules-maybe)
3703 (easy-menu-add org-org-menu
)
3704 (easy-menu-add org-tbl-menu
)
3705 (org-install-agenda-files-menu)
3706 (if org-descriptive-links
(org-add-to-invisibility-spec '(org-link)))
3707 (org-add-to-invisibility-spec '(org-cwidth))
3708 (when (featurep 'xemacs
)
3709 (org-set-local 'line-move-ignore-invisible t
))
3710 (org-set-local 'outline-regexp org-outline-regexp
)
3711 (org-set-local 'outline-level
'org-outline-level
)
3712 (when (and org-ellipsis
3713 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
3714 (fboundp 'make-glyph-code
))
3715 (unless org-display-table
3716 (setq org-display-table
(make-display-table)))
3717 (set-display-table-slot
3720 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
3722 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
3723 (setq buffer-display-table org-display-table
))
3724 (org-set-regexps-and-options)
3725 (when (and org-tag-faces
(not org-tags-special-faces-re
))
3726 ;; tag faces set outside customize.... force initialization.
3727 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
3729 (org-set-local 'calc-embedded-open-mode
"# ")
3730 (modify-syntax-entry ?
# "<")
3731 (modify-syntax-entry ?
@ "w")
3732 (if org-startup-truncated
(setq truncate-lines t
))
3733 (org-set-local 'font-lock-unfontify-region-function
3734 'org-unfontify-region
)
3735 ;; Activate before-change-function
3736 (org-set-local 'org-table-may-need-update t
)
3737 (org-add-hook 'before-change-functions
'org-before-change-function nil
3739 ;; Check for running clock before killing a buffer
3740 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
3741 ;; Paragraphs and auto-filling
3742 (org-set-autofill-regexps)
3743 (setq indent-line-function
'org-indent-line-function
)
3744 (org-update-radio-target-regexp)
3745 ;; Make sure dependence stuff works reliably, even for users who set it
3747 (if org-enforce-todo-dependencies
3748 (add-hook 'org-blocker-hook
3749 'org-block-todo-from-children-or-siblings
)
3750 (remove-hook 'org-blocker-hook
3751 'org-block-todo-from-children-or-siblings
))
3752 (if org-enforce-todo-checkbox-dependencies
3753 (add-hook 'org-blocker-hook
3754 'org-block-todo-from-checkboxes
)
3755 (remove-hook 'org-blocker-hook
3756 'org-block-todo-from-checkboxes
))
3758 ;; Comment characters
3759 ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
3760 (org-set-local 'comment-padding
" ")
3762 ;; Align options lines
3764 'align-mode-rules-list
3765 '((org-in-buffer-settings
3766 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
3767 (modes .
'(org-mode)))))
3770 (org-set-local 'imenu-create-index-function
3771 'org-imenu-get-tree
)
3773 ;; Make isearch reveal context
3774 (if (or (featurep 'xemacs
)
3775 (not (boundp 'outline-isearch-open-invisible-function
)))
3776 ;; Emacs 21 and XEmacs make use of the hook
3777 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
3778 ;; Emacs 22 deals with this through a special variable
3779 (org-set-local 'outline-isearch-open-invisible-function
3780 (lambda (&rest ignore
) (org-show-context 'isearch
))))
3782 ;; If empty file that did not turn on org-mode automatically, make it to.
3783 (if (and org-insert-mode-line-in-empty-file
3785 (= (point-min) (point-max)))
3786 (insert "# -*- mode: org -*-\n\n"))
3788 (unless org-inhibit-startup
3789 (when org-startup-align-all-tables
3790 (let ((bmp (buffer-modified-p)))
3791 (org-table-map-tables 'org-table-align
)
3792 (set-buffer-modified-p bmp
)))
3793 (org-set-startup-visibility)))
3795 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
3797 (defun org-current-time ()
3798 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
3799 (if (> (car org-time-stamp-rounding-minutes
) 1)
3800 (let ((r (car org-time-stamp-rounding-minutes
))
3801 (time (decode-time)))
3803 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
3807 ;;;; Font-Lock stuff, including the activators
3809 (defvar org-mouse-map
(make-sparse-keymap))
3810 (org-defkey org-mouse-map
3811 (if (featurep 'xemacs
) [button2] [mouse-2]) 'org-open-at-mouse)
3812 (org-defkey org-mouse-map
3813 (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
3814 (when org-mouse-1-follows-link
3815 (org-defkey org-mouse-map [follow-link] 'mouse-face))
3816 (when org-tab-follows-link
3817 (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
3818 (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
3820 (require 'font-lock)
3822 (defconst org-non-link-chars "]\t\n\r<>")
3823 (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
3825 (defvar org-link-types-re nil
3826 "Matches a link that has a url-like prefix like \"http:\"")
3827 (defvar org-link-re-with-space nil
3828 "Matches a link with spaces, optional angular brackets around it.")
3829 (defvar org-link-re-with-space2 nil
3830 "Matches a link with spaces, optional angular brackets around it.")
3831 (defvar org-link-re-with-space3 nil
3832 "Matches a link with spaces, only for internal part in bracket links.")
3833 (defvar org-angle-link-re nil
3834 "Matches link with angular brackets, spaces are allowed.")
3835 (defvar org-plain-link-re nil
3836 "Matches plain link, without spaces.")
3837 (defvar org-bracket-link-regexp nil
3838 "Matches a link in double brackets.")
3839 (defvar org-bracket-link-analytic-regexp nil
3840 "Regular expression used to analyze links.
3841 Here is what the match groups contain after a match:
3847 (defvar org-bracket-link-analytic-regexp++ nil
3848 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
3849 (defvar org-any-link-re nil
3850 "Regular expression matching any link.")
3852 (defun org-make-link-regexps ()
3853 "Update the link regular expressions.
3854 This should be called after the variable `org-link-types' has changed."
3855 (setq org-link-types-re
3857 "\\`\\(" (mapconcat 'identity org-link-types "\\|") "\\):")
3858 org-link-re-with-space
3860 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3861 "\\([^" org-non-link-chars " ]"
3862 "[^" org-non-link-chars "]*"
3863 "[^" org-non-link-chars " ]\\)>?")
3864 org-link-re-with-space2
3866 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3867 "\\([^" org-non-link-chars " ]"
3869 "[^" org-non-link-chars " ]\\)>?")
3870 org-link-re-with-space3
3872 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3873 "\\([^" org-non-link-chars " ]"
3877 "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3878 "\\([^" org-non-link-chars " ]"
3879 "[^" org-non-link-chars "]*"
3883 "\\<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3884 "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
3885 org-bracket-link-regexp
3886 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
3887 org-bracket-link-analytic-regexp
3890 "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?"
3893 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
3895 org-bracket-link-analytic-regexp++
3898 "\\(\\(" (mapconcat 'identity (cons "coderef" org-link-types) "\\|") "\\):\\)?"
3901 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
3904 (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
3905 org-angle-link-re "\\)\\|\\("
3906 org-plain-link-re "\\)")))
3908 (org-make-link-regexps)
3910 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
3911 "Regular expression for fast time stamp matching.")
3912 (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
3913 "Regular expression for fast time stamp matching.")
3914 (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
3915 "Regular expression matching time strings for analysis.
3916 This one does not require the space after the date, so it can be used
3917 on a string that terminates immediately after the date.")
3918 (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
3919 "Regular expression matching time strings for analysis.")
3920 (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
3921 "Regular expression matching time stamps, with groups.")
3922 (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
3923 "Regular expression matching time stamps (also [..]), with groups.")
3924 (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
3925 "Regular expression matching a time stamp range.")
3926 (defconst org-tr-regexp-both
3927 (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
3928 "Regular expression matching a time stamp range.")
3929 (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
3930 org-ts-regexp "\\)?")
3931 "Regular expression matching a time stamp or time stamp range.")
3932 (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
3933 org-ts-regexp-both "\\)?")
3934 "Regular expression matching a time stamp or time stamp range.
3935 The time stamps may be either active or inactive.")
3937 (defvar org-emph-face nil)
3939 (defun org-do-emphasis-faces (limit)
3940 "Run through the buffer and add overlays to links."
3942 (while (and (not rtn) (re-search-forward org-emph-re limit t))
3943 (if (not (= (char-after (match-beginning 3))
3944 (char-after (match-beginning 4))))
3947 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
3949 (nth 1 (assoc (match-string 3)
3950 org-emphasis-alist)))
3951 (add-text-properties (match-beginning 2) (match-end 2)
3952 '(font-lock-multiline t))
3953 (when org-hide-emphasis-markers
3954 (add-text-properties (match-end 4) (match-beginning 5)
3955 '(invisible org-link))
3956 (add-text-properties (match-beginning 3) (match-end 3)
3957 '(invisible org-link)))))
3961 (defun org-emphasize (&optional char)
3962 "Insert or change an emphasis, i.e. a font like bold or italic.
3963 If there is an active region, change that region to a new emphasis.
3964 If there is no region, just insert the marker characters and position
3965 the cursor between them.
3966 CHAR should be either the marker character, or the first character of the
3967 HTML tag associated with that emphasis. If CHAR is a space, the means
3968 to remove the emphasis of the selected region.
3969 If char is not given (for example in an interactive call) it
3970 will be prompted for."
3972 (let ((eal org-emphasis-alist) e det
3973 (erc org-emphasis-regexp-components)
3975 (string "") beg end move tag c s)
3976 (if (org-region-active-p)
3977 (setq beg (region-beginning) end (region-end)
3978 string (buffer-substring beg end))
3981 (while (setq e (pop eal))
3982 (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
3984 (push (cons c (string-to-char (car e))) det)
3985 (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
3986 (substring tag 1)))))
3987 (setq det (nreverse det))
3989 (message "%s" (concat "Emphasis marker or tag:" prompt))
3990 (setq char (read-char-exclusive)))
3991 (setq char (or (cdr (assoc char det)) char))
3992 (if (equal char ?\ )
3993 (setq s "" move nil)
3994 (unless (assoc (char-to-string char) org-emphasis-alist)
3995 (error "No such emphasis marker: \"%c\"" char))
3996 (setq s (char-to-string char)))
3997 (while (and (> (length string) 1)
3998 (equal (substring string 0 1) (substring string -1))
3999 (assoc (substring string 0 1) org-emphasis-alist))
4000 (setq string (substring string 1 -1)))
4001 (setq string (concat s string s))
4002 (if beg (delete-region beg end))
4004 (string-match (concat "[" (nth 0 erc) "\n]")
4005 (char-to-string (char-before (point)))))
4007 (unless (string-match (concat "[" (nth 1 erc) "\n]")
4008 (char-to-string (char-after (point))))
4009 (insert " ") (backward-char 1))
4011 (and move (backward-char 1))))
4013 (defconst org-nonsticky-props
4014 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
4017 (defun org-activate-plain-links (limit)
4018 "Run through the buffer and add overlays to links."
4021 (while (re-search-forward org-plain-link-re limit t)
4022 (setq f (get-text-property (match-beginning 0) 'face))
4023 (if (or (eq f 'org-tag)
4024 (and (listp f) (memq 'org-tag f)))
4026 (add-text-properties (match-beginning 0) (match-end 0)
4027 (list 'mouse-face 'highlight
4028 'rear-nonsticky org-nonsticky-props
4029 'keymap org-mouse-map
4031 (throw 'exit t))))))
4033 (defun org-activate-code (limit)
4034 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
4036 (remove-text-properties (match-beginning 0) (match-end 0)
4037 '(display t invisible t intangible t))
4040 (defun org-activate-angle-links (limit)
4041 "Run through the buffer and add overlays to links."
4042 (if (re-search-forward org-angle-link-re limit t)
4044 (add-text-properties (match-beginning 0) (match-end 0)
4045 (list 'mouse-face 'highlight
4046 'rear-nonsticky org-nonsticky-props
4047 'keymap org-mouse-map
4051 (defun org-activate-footnote-links (limit)
4052 "Run through the buffer and add overlays to links."
4053 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
4056 (add-text-properties (match-beginning 2) (match-end 2)
4057 (list 'mouse-face 'highlight
4058 'rear-nonsticky org-nonsticky-props
4059 'keymap org-mouse-map
4061 (if (= (point-at-bol) (match-beginning 2))
4062 "Footnote definition"
4063 "Footnote reference")
4067 (defun org-activate-bracket-links (limit)
4068 "Run through the buffer and add overlays to bracketed links."
4069 (if (re-search-forward org-bracket-link-regexp limit t)
4070 (let* ((help (concat "LINK: "
4071 (org-match-string-no-properties 1)))
4072 ;; FIXME: above we should remove the escapes.
4073 ;; but that requires another match, protecting match data,
4074 ;; a lot of overhead for font-lock.
4075 (ip (org-maybe-intangible
4076 (list 'invisible 'org-link 'rear-nonsticky org-nonsticky-props
4077 'keymap org-mouse-map 'mouse-face 'highlight
4078 'font-lock-multiline t 'help-echo help)))
4079 (vp (list 'rear-nonsticky org-nonsticky-props
4080 'keymap org-mouse-map 'mouse-face 'highlight
4081 ' font-lock-multiline t 'help-echo help)))
4082 ;; We need to remove the invisible property here. Table narrowing
4083 ;; may have made some of this invisible.
4084 (remove-text-properties (match-beginning 0) (match-end 0)
4088 (add-text-properties (match-beginning 0) (match-beginning 3) ip)
4089 (add-text-properties (match-beginning 3) (match-end 3) vp)
4090 (add-text-properties (match-end 3) (match-end 0) ip))
4091 (add-text-properties (match-beginning 0) (match-beginning 1) ip)
4092 (add-text-properties (match-beginning 1) (match-end 1) vp)
4093 (add-text-properties (match-end 1) (match-end 0) ip))
4096 (defun org-activate-dates (limit)
4097 "Run through the buffer and add overlays to dates."
4098 (if (re-search-forward org-tsr-regexp-both limit t)
4100 (add-text-properties (match-beginning 0) (match-end 0)
4101 (list 'mouse-face 'highlight
4102 'rear-nonsticky org-nonsticky-props
4103 'keymap org-mouse-map))
4104 (when org-display-custom-times
4106 (org-display-custom-time (match-beginning 3) (match-end 3)))
4107 (org-display-custom-time (match-beginning 1) (match-end 1)))
4110 (defvar org-target-link-regexp nil
4111 "Regular expression matching radio targets in plain text.")
4112 (make-variable-buffer-local 'org-target-link-regexp)
4113 (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
4114 "Regular expression matching a link target.")
4115 (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
4116 "Regular expression matching a radio target.")
4117 (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
4118 "Regular expression matching any target.")
4120 (defun org-activate-target-links (limit)
4121 "Run through the buffer and add overlays to target matches."
4122 (when org-target-link-regexp
4123 (let ((case-fold-search t))
4124 (if (re-search-forward org-target-link-regexp limit t)
4126 (add-text-properties (match-beginning 0) (match-end 0)
4127 (list 'mouse-face 'highlight
4128 'rear-nonsticky org-nonsticky-props
4129 'keymap org-mouse-map
4130 'help-echo "Radio target link"
4131 'org-linked-text t))
4134 (defun org-update-radio-target-regexp ()
4135 "Find all radio targets in this file and update the regular expression."
4137 (when (memq 'radio org-activate-links)
4138 (setq org-target-link-regexp
4139 (org-make-target-link-regexp (org-all-targets 'radio)))
4140 (org-restart-font-lock)))
4142 (defun org-hide-wide-columns (limit)
4144 (setq s (text-property-any (point) (or limit (point-max))
4147 (setq e (next-single-property-change s 'org-cwidth))
4148 (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
4152 (defvar org-latex-and-specials-regexp nil
4153 "Regular expression for highlighting export special stuff.")
4154 (defvar org-match-substring-regexp)
4155 (defvar org-match-substring-with-braces-regexp)
4156 (defvar org-export-html-special-string-regexps)
4158 (defun org-compute-latex-and-specials-regexp ()
4159 "Compute regular expression for stuff treated specially by exporters."
4160 (if (not org-highlight-latex-fragments-and-specials)
4161 (org-set-local 'org-latex-and-specials-regexp nil)
4164 ((matchers (plist-get org-format-latex-options :matchers))
4165 (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
4166 org-latex-regexps)))
4167 (options (org-combine-plists (org-default-export-plist)
4168 (org-infile-export-plist)))
4169 (org-export-with-sub-superscripts (plist-get options :sub-superscript))
4170 (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
4171 (org-export-with-TeX-macros (plist-get options :TeX-macros))
4172 (org-export-html-expand (plist-get options :expand-quoted-html))
4173 (org-export-with-special-strings (plist-get options :special-strings))
4176 ((equal org-export-with-sub-superscripts '{})
4177 (list org-match-substring-with-braces-regexp))
4178 (org-export-with-sub-superscripts
4179 (list org-match-substring-regexp))
4182 (if org-export-with-LaTeX-fragments
4183 (mapcar (lambda (x) (nth 1 x)) latexs)))
4185 (if org-export-with-TeX-macros
4186 (list (concat "\\\\"
4188 (append (mapcar 'car org-html-entities)
4189 (if (boundp 'org-latex-entities)
4190 org-latex-entities nil))
4193 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
4194 (re-special (if org-export-with-special-strings
4195 (mapcar (lambda (x) (car x))
4196 org-export-html-special-string-regexps)))
4200 (if org-export-html-expand "@<[^>\n]+>")
4203 'org-latex-and-specials-regexp
4204 (mapconcat 'identity (append re-latex re-sub re-macros re-special
4207 (defun org-do-latex-and-special-faces (limit)
4208 "Run through the buffer and add overlays to links."
4209 (when org-latex-and-specials-regexp
4211 (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
4213 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
4215 '(org-code org-verbatim underline)))
4218 d (cond ((member (char-after (1+ (match-beginning 0)))
4221 (font-lock-prepend-text-property
4222 (+ d (match-beginning 0)) (match-end 0)
4223 'face 'org-latex-and-export-specials)
4224 (add-text-properties (+ d (match-beginning 0)) (match-end 0)
4225 '(font-lock-multiline t)))))
4228 (defun org-restart-font-lock ()
4229 "Restart font-lock-mode, to force refontification."
4230 (when (and (boundp 'font-lock-mode) font-lock-mode)
4232 (font-lock-mode 1)))
4234 (defun org-all-targets (&optional radio)
4235 "Return a list of all targets in this file.
4236 With optional argument RADIO, only find radio targets."
4237 (let ((re (if radio org-radio-target-regexp org-target-regexp))
4240 (goto-char (point-min))
4241 (while (re-search-forward re nil t)
4242 (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
4245 (defun org-make-target-link-regexp (targets)
4246 "Make regular expression matching all strings in TARGETS.
4247 The regular expression finds the targets also if there is a line break
4254 (while (string-match " +" x)
4255 (setq x (replace-match "\\s-+" t t x)))
4261 (defun org-activate-tags (limit)
4262 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
4264 (add-text-properties (match-beginning 1) (match-end 1)
4265 (list 'mouse-face 'highlight
4266 'rear-nonsticky org-nonsticky-props
4267 'keymap org-mouse-map))
4270 (defun org-outline-level ()
4272 (looking-at outline-regexp)
4273 (if (match-beginning 1)
4274 (+ (org-get-string-indentation (match-string 1)) 1000)
4275 (1- (- (match-end 0) (match-beginning 0))))))
4277 (defvar org-font-lock-keywords nil)
4279 (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
4280 "Regular expression matching a property line.")
4282 (defvar org-font-lock-hook nil
4283 "Functions to be called for special font lock stuff.")
4285 (defun org-font-lock-hook (limit)
4286 (run-hook-with-args 'org-font-lock-hook limit))
4288 (defun org-set-font-lock-defaults ()
4289 (let* ((em org-fontify-emphasized-text)
4290 (lk org-activate-links)
4291 (org-font-lock-extra-keywords
4294 '(org-font-lock-hook)
4296 '("^\\(\\**\\)\\(\\* \\)\\(.*\\)" (1 (org-get-level-face 1))
4297 (2 (org-get-level-face 2)) (3 (org-get-level-face 3)))
4299 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
4302 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
4303 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
4304 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
4306 (list org-drawer-regexp '(0 'org-special-keyword t))
4307 (list "^[ \t]*:END:" '(0 'org-special-keyword t))
4309 (list org-property-re
4310 '(1 'org-special-keyword t)
4311 '(3 'org-property-value t))
4312 (if org-format-transports-properties-p
4313 '("| *\\(<[0-9]+>\\) *" (1 'org-formula t)))
4315 (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
4316 (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
4317 (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
4318 (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
4319 (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
4320 (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
4321 (if (memq 'footnote lk) '(org-activate-footnote-links
4322 (2 'org-footnote t)))
4323 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
4324 '(org-hide-wide-columns (0 nil append))
4326 (list (concat "^\\*+[ \t]+" org-todo-regexp)
4327 '(1 (org-get-todo-face 1) t))
4329 (if org-fontify-done-headline
4330 (list (concat "^[*]+ +\\<\\("
4331 (mapconcat 'regexp-quote org-done-keywords "\\|")
4333 '(2 'org-headline-done t))
4336 '(org-font-lock-add-priority-faces)
4338 '(org-font-lock-add-tag-faces)
4340 (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
4341 (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
4342 (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
4343 (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
4346 (if (featurep 'xemacs)
4347 '(org-do-emphasis-faces (0 nil append))
4348 '(org-do-emphasis-faces)))
4350 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
4352 (if org-provide-checkbox-statistics
4353 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
4354 (0 (org-get-checkbox-statistics-face) t)))
4355 ;; Description list items
4356 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
4358 (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
4359 '(1 'org-archived prepend))
4361 '(org-do-latex-and-special-faces)
4363 '(org-activate-code (1 'org-code t))
4365 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
4366 "\\|" org-quote-string "\\)\\>")
4367 '(1 'org-special-keyword t))
4368 '("^#.*" (0 'font-lock-comment-face t))
4370 (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
4371 ;; Now set the full font-lock-keywords
4372 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
4373 (org-set-local 'font-lock-defaults
4374 '(org-font-lock-keywords t nil nil backward-paragraph))
4375 (kill-local-variable 'font-lock-keywords) nil))
4380 (defun org-get-level-face (n)
4381 "Get the right face for match N in font-lock matching of headlines."
4382 (setq org-l (- (match-end 2) (match-beginning 1) 1))
4383 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
4384 (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
4386 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
4388 (t (if org-level-color-stars-only nil org-f))))
4390 (defun org-get-todo-face (kwd)
4391 "Get the right face for a TODO keyword KWD.
4392 If KWD is a number, get the corresponding match group."
4393 (if (numberp kwd) (setq kwd (match-string kwd)))
4394 (or (cdr (assoc kwd org-todo-keyword-faces))
4395 (and (member kwd org-done-keywords) 'org-done)
4398 (defun org-font-lock-add-tag-faces (limit)
4399 "Add the special tag faces."
4400 (when (and org-tag-faces org-tags-special-faces-re)
4401 (while (re-search-forward org-tags-special-faces-re limit t)
4402 (add-text-properties (match-beginning 1) (match-end 1)
4403 (list 'face (org-get-tag-face 1)
4404 'font-lock-fontified t))
4405 (backward-char 1))))
4407 (defun org-font-lock-add-priority-faces (limit)
4408 "Add the special priority faces."
4409 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t)
4410 (add-text-properties
4411 (match-beginning 0) (match-end 0)
4412 (list 'face (or (cdr (assoc (char-after (match-beginning 1))
4413 org-priority-faces))
4414 'org-special-keyword)
4415 'font-lock-fontified t))))
4417 (defun org-get-tag-face (kwd)
4418 "Get the right face for a TODO keyword KWD.
4419 If KWD is a number, get the corresponding match group."
4420 (if (numberp kwd) (setq kwd (match-string kwd)))
4421 (or (cdr (assoc kwd org-tag-faces))
4424 (defun org-unfontify-region (beg end &optional maybe_loudly)
4425 "Remove fontification and activation overlays from links."
4426 (font-lock-default-unfontify-region beg end)
4427 (let* ((buffer-undo-list t)
4428 (inhibit-read-only t) (inhibit-point-motion-hooks t)
4429 (inhibit-modification-hooks t)
4430 deactivate-mark buffer-file-name buffer-file-truename)
4431 (remove-text-properties beg end
4432 '(mouse-face t keymap t org-linked-text t
4433 invisible t intangible t))))
4435 ;;;; Visibility cycling, including org-goto and indirect buffer
4439 (defvar org-cycle-global-status nil)
4440 (make-variable-buffer-local 'org-cycle-global-status)
4441 (defvar org-cycle-subtree-status nil)
4442 (make-variable-buffer-local 'org-cycle-subtree-status)
4445 (defun org-cycle (&optional arg)
4446 "Visibility cycling for Org-mode.
4448 - When this function is called with a prefix argument, rotate the entire
4449 buffer through 3 states (global cycling)
4450 1. OVERVIEW: Show only top-level headlines.
4451 2. CONTENTS: Show all headlines of all levels, but no body text.
4452 3. SHOW ALL: Show everything.
4453 When called with two C-u C-u prefixes, switch to the startup visibility,
4454 determined by the variable `org-startup-folded', and by any VISIBILITY
4455 properties in the buffer.
4456 When called with three C-u C-u C-u prefixed, show the entire buffer,
4459 - When point is at the beginning of a headline, rotate the subtree started
4460 by this line through 3 different states (local cycling)
4461 1. FOLDED: Only the main headline is shown.
4462 2. CHILDREN: The main headline and the direct children are shown.
4463 From this state, you can move to one of the children
4464 and zoom in further.
4465 3. SUBTREE: Show the entire subtree, including body text.
4467 - When there is a numeric prefix, go up to a heading with level ARG, do
4468 a `show-subtree' and return to the previous cursor position. If ARG
4469 is negative, go up that many levels.
4471 - When point is not at the beginning of a headline, execute the global
4472 binding for TAB, which is re-indenting the line. See the option
4473 `org-cycle-emulate-tab' for details.
4475 - Special case: if point is at the beginning of the buffer and there is
4476 no headline in line 1, this function will act as if called with prefix arg.
4477 But only if also the variable `org-cycle-global-at-bob' is t."
4479 (org-load-modules-maybe)
4480 (let* ((outline-regexp
4481 (if (and (org-mode-p) org-cycle-include-plain-lists)
4482 "\\(?:\\*+ \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"
4484 (bob-special (and org-cycle-global-at-bob (bobp)
4485 (not (looking-at outline-regexp))))
4488 (delq 'org-optimize-window-after-visibility-change
4489 (copy-sequence org-cycle-hook))
4493 (if (or bob-special (equal arg '(4)))
4494 ;; special case: use global cycling
4500 (org-set-startup-visibility)
4501 (message "Startup visibility, plus VISIBILITY properties"))
4505 (message "Entire buffer visible, including drawers"))
4507 ((org-at-table-p 'any)
4508 ;; Enter the table or move to the next field in the table
4509 (or (org-table-recognize-table.el)
4511 (if arg (org-table-edit-field t)
4512 (org-table-justify-field-maybe)
4513 (call-interactively 'org-table-next-field)))))
4515 ((eq arg t) ;; Global cycling
4518 ((and (eq last-command this-command)
4519 (eq org-cycle-global-status 'overview))
4520 ;; We just created the overview - now do table of contents
4521 ;; This can be slow in very large buffers, so indicate action
4522 (message "CONTENTS...")
4524 (message "CONTENTS...done")
4525 (setq org-cycle-global-status 'contents)
4526 (run-hook-with-args 'org-cycle-hook 'contents))
4528 ((and (eq last-command this-command)
4529 (eq org-cycle-global-status 'contents))
4530 ;; We just showed the table of contents - now show everything
4532 (message "SHOW ALL")
4533 (setq org-cycle-global-status 'all)
4534 (run-hook-with-args 'org-cycle-hook 'all))
4537 ;; Default action: go to overview
4539 (message "OVERVIEW")
4540 (setq org-cycle-global-status 'overview)
4541 (run-hook-with-args 'org-cycle-hook 'overview))))
4543 ((and org-drawers org-drawer-regexp
4545 (beginning-of-line 1)
4546 (looking-at org-drawer-regexp)))
4547 ;; Toggle block visibility
4549 (not (get-char-property (match-end 0) 'invisible))))
4552 ;; Show-subtree, ARG levels up from here.
4554 (org-back-to-heading)
4555 (outline-up-heading (if (< arg 0) (- arg)
4556 (- (funcall outline-level) arg)))
4557 (org-show-subtree)))
4559 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
4560 (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
4561 ;; At a heading: rotate between three different views
4562 (org-back-to-heading)
4563 (let ((goal-column 0) eoh eol eos)
4564 ;; First, some boundaries
4566 (org-back-to-heading)
4568 (beginning-of-line 2)
4569 (while (and (not (eobp)) ;; this is like `next-line'
4570 (get-char-property (1- (point)) 'invisible))
4571 (beginning-of-line 2)) (setq eol (point)))
4572 (outline-end-of-heading) (setq eoh (point))
4573 (org-end-of-subtree t)
4575 (skip-chars-forward " \t\n")
4576 (beginning-of-line 1) ; in case this is an item
4578 (setq eos (1- (point))))
4579 ;; Find out what to do next and set `this-command'
4582 ;; Nothing is hidden behind this heading
4583 (message "EMPTY ENTRY")
4584 (setq org-cycle-subtree-status nil)
4587 (outline-next-heading)
4588 (if (org-invisible-p) (org-flag-heading nil))))
4590 (not (string-match "\\S-" (buffer-substring eol eos))))
4591 ;; Entire subtree is hidden in one line: open it
4594 (message "CHILDREN")
4597 (outline-next-heading)
4598 (if (org-invisible-p) (org-flag-heading nil)))
4599 (setq org-cycle-subtree-status 'children)
4600 (run-hook-with-args 'org-cycle-hook 'children))
4601 ((and (eq last-command this-command)
4602 (eq org-cycle-subtree-status 'children))
4603 ;; We just showed the children, now show everything.
4606 (setq org-cycle-subtree-status 'subtree)
4607 (run-hook-with-args 'org-cycle-hook 'subtree))
4609 ;; Default action: hide the subtree.
4612 (setq org-cycle-subtree-status 'folded)
4613 (run-hook-with-args 'org-cycle-hook 'folded)))))
4615 ;; TAB emulation and template completion
4616 (buffer-read-only (org-back-to-heading))
4618 ((org-try-structure-completion))
4620 ((org-try-cdlatex-tab))
4622 ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
4624 (not (looking-at outline-regexp))))
4625 (call-interactively (global-key-binding "\t")))
4627 ((if (and (memq org-cycle-emulate-tab '(white whitestart))
4628 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
4629 (or (and (eq org-cycle-emulate-tab 'white)
4630 (= (match-end 0) (point-at-eol)))
4631 (and (eq org-cycle-emulate-tab 'whitestart)
4632 (>= (match-end 0) pos))))
4634 (eq org-cycle-emulate-tab t))
4635 (call-interactively (global-key-binding "\t")))
4638 (org-back-to-heading)
4642 (defun org-global-cycle (&optional arg)
4643 "Cycle the global visibility. For details see `org-cycle'.
4644 With C-u prefix arg, switch to startup visibility.
4645 With a numeric prefix, show all headlines up to that level."
4647 (let ((org-cycle-include-plain-lists
4648 (if (org-mode-p) org-cycle-include-plain-lists nil)))
4652 (hide-sublevels arg)
4653 (setq org-cycle-global-status 'contents))
4655 (org-set-startup-visibility)
4656 (message "Startup visibility, plus VISIBILITY properties."))
4658 (org-cycle '(4))))))
4660 (defun org-set-startup-visibility ()
4661 "Set the visibility required by startup options and properties."
4663 ((eq org-startup-folded t)
4665 ((eq org-startup-folded 'content)
4666 (let ((this-command 'org-cycle) (last-command 'org-cycle))
4667 (org-cycle '(4)) (org-cycle '(4)))))
4668 (org-set-visibility-according-to-property 'no-cleanup)
4669 (org-cycle-hide-archived-subtrees 'all)
4670 (org-cycle-hide-drawers 'all)
4671 (org-cycle-show-empty-lines 'all))
4673 (defun org-set-visibility-according-to-property (&optional no-cleanup)
4674 "Switch subtree visibilities according to :VISIBILITY: property."
4676 (let (org-show-entry-below state)
4678 (goto-char (point-min))
4679 (while (re-search-forward
4680 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
4682 (setq state (match-string 1))
4684 (org-back-to-heading t)
4688 ((equal state '("fold" "folded"))
4690 ((equal state "children")
4691 (org-show-hidden-entry)
4693 ((equal state "content")
4696 (org-narrow-to-subtree)
4698 ((member state '("all" "showall"))
4701 (org-cycle-hide-archived-subtrees 'all)
4702 (org-cycle-hide-drawers 'all)
4703 (org-cycle-show-empty-lines 'all)))))
4705 (defun org-overview ()
4706 "Switch to overview mode, showing only top-level headlines.
4707 Really, this shows all headlines with level equal or greater than the level
4708 of the first headline in the buffer. This is important, because if the
4709 first headline is not level one, then (hide-sublevels 1) gives confusing
4712 (let ((level (save-excursion
4713 (goto-char (point-min))
4714 (if (re-search-forward (concat "^" outline-regexp) nil t)
4716 (goto-char (match-beginning 0))
4717 (funcall outline-level))))))
4718 (and level (hide-sublevels level))))
4720 (defun org-content (&optional arg)
4721 "Show all headlines in the buffer, like a table of contents.
4722 With numerical argument N, show content up to level N."
4725 ;; Visit all headings and show their offspring
4726 (and (integerp arg) (org-overview))
4727 (goto-char (point-max))
4729 (while (and (progn (condition-case nil
4730 (outline-previous-visible-heading 1)
4731 (error (goto-char (point-min))))
4733 (looking-at outline-regexp))
4735 (show-children (1- arg))
4737 (if (bobp) (throw 'exit nil))))))
4740 (defun org-optimize-window-after-visibility-change (state)
4741 "Adjust the window after a change in outline visibility.
4742 This function is the default value of the hook `org-cycle-hook'."
4743 (when (get-buffer-window (current-buffer))
4745 ((eq state 'content) nil)
4746 ((eq state 'all) nil)
4747 ((eq state 'folded) nil)
4748 ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
4749 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
4751 (defun org-compact-display-after-subtree-move ()
4752 "Show a compacter version of the tree of the entry's parent."
4754 (if (org-up-heading-safe)
4759 (org-cycle-show-empty-lines 'children)
4760 (org-cycle-hide-drawers 'children))
4763 (defun org-cycle-show-empty-lines (state)
4764 "Show empty lines above all visible headlines.
4765 The region to be covered depends on STATE when called through
4766 `org-cycle-hook'. Lisp program can use t for STATE to get the
4767 entire buffer covered. Note that an empty line is only shown if there
4768 are at least `org-cycle-separator-lines' empty lines before the headline."
4769 (when (> org-cycle-separator-lines 0)
4771 (let* ((n org-cycle-separator-lines)
4773 ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
4774 ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
4775 (t (let ((ns (number-to-string (- n 2))))
4776 (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
4777 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
4780 ((memq state '(overview contents t))
4781 (setq beg (point-min) end (point-max)))
4782 ((memq state '(children folded))
4783 (setq beg (point) end (progn (org-end-of-subtree t t)
4784 (beginning-of-line 2)
4788 (while (re-search-forward re end t)
4789 (if (not (get-char-property (match-end 1) 'invisible))
4790 (outline-flag-region
4791 (match-beginning 1) (match-end 1) nil)))))))
4792 ;; Never hide empty lines at the end of the file.
4794 (goto-char (point-max))
4795 (outline-previous-heading)
4796 (outline-end-of-heading)
4797 (if (and (looking-at "[ \t\n]+")
4798 (= (match-end 0) (point-max)))
4799 (outline-flag-region (point) (match-end 0) nil))))
4801 (defun org-show-empty-lines-in-parent ()
4802 "Move to the parent and re-show empty lines before visible headlines."
4804 (let ((context (if (org-up-heading-safe) 'children 'overview)))
4805 (org-cycle-show-empty-lines context))))
4807 (defun org-cycle-hide-drawers (state)
4808 "Re-hide all drawers after a visibility state change."
4809 (when (and (org-mode-p)
4810 (not (memq state '(overview folded))))
4812 (let* ((globalp (memq state '(contents all)))
4813 (beg (if globalp (point-min) (point)))
4814 (end (if globalp (point-max) (org-end-of-subtree t))))
4816 (while (re-search-forward org-drawer-regexp end t)
4817 (org-flag-drawer t))))))
4819 (defun org-flag-drawer (flag)
4821 (beginning-of-line 1)
4822 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
4823 (let ((b (match-end 0))
4824 (outline-regexp org-outline-regexp))
4825 (if (re-search-forward
4827 (save-excursion (outline-next-heading) (point)) t)
4828 (outline-flag-region b (point-at-eol) flag)
4829 (error ":END: line missing"))))))
4831 (defun org-subtree-end-visible-p ()
4832 "Is the end of the current subtree visible?"
4833 (pos-visible-in-window-p
4834 (save-excursion (org-end-of-subtree t) (point))))
4836 (defun org-first-headline-recenter (&optional N)
4837 "Move cursor to the first headline and recenter the headline.
4838 Optional argument N means, put the headline into the Nth line of the window."
4839 (goto-char (point-min))
4840 (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
4842 (recenter (prefix-numeric-value N))))
4846 (defvar org-goto-window-configuration nil)
4847 (defvar org-goto-marker nil)
4848 (defvar org-goto-map
4849 (let ((map (make-sparse-keymap)))
4850 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
4851 (while (setq cmd (pop cmds))
4852 (substitute-key-definition cmd cmd map global-map)))
4853 (suppress-keymap map)
4854 (org-defkey map "\C-m" 'org-goto-ret)
4855 (org-defkey map [(return)] 'org-goto-ret)
4856 (org-defkey map [(left)] 'org-goto-left)
4857 (org-defkey map [(right)] 'org-goto-right)
4858 (org-defkey map [(control ?g)] 'org-goto-quit)
4859 (org-defkey map "\C-i" 'org-cycle)
4860 (org-defkey map [(tab)] 'org-cycle)
4861 (org-defkey map [(down)] 'outline-next-visible-heading)
4862 (org-defkey map [(up)] 'outline-previous-visible-heading)
4863 (if org-goto-auto-isearch
4864 (if (fboundp 'define-key-after)
4865 (define-key-after map [t] 'org-goto-local-auto-isearch)
4867 (org-defkey map "q" 'org-goto-quit)
4868 (org-defkey map "n" 'outline-next-visible-heading)
4869 (org-defkey map "p" 'outline-previous-visible-heading)
4870 (org-defkey map "f" 'outline-forward-same-level)
4871 (org-defkey map "b" 'outline-backward-same-level)
4872 (org-defkey map "u" 'outline-up-heading))
4873 (org-defkey map "/" 'org-occur)
4874 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
4875 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
4876 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
4877 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
4878 (org-defkey map "\C-c\C-u" 'outline-up-heading)
4881 (defconst org-goto-help
4882 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
4883 RET=jump to location [Q]uit and return to previous location
4884 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
4886 (defvar org-goto-start-pos) ; dynamically scoped parameter
4888 ;; FIXME: Docstring doe not mention both interfaces
4889 (defun org-goto (&optional alternative-interface)
4890 "Look up a different location in the current file, keeping current visibility.
4892 When you want look-up or go to a different location in a document, the
4893 fastest way is often to fold the entire buffer and then dive into the tree.
4894 This method has the disadvantage, that the previous location will be folded,
4895 which may not be what you want.
4897 This command works around this by showing a copy of the current buffer
4898 in an indirect buffer, in overview mode. You can dive into the tree in
4899 that copy, use org-occur and incremental search to find a location.
4900 When pressing RET or `Q', the command returns to the original buffer in
4901 which the visibility is still unchanged. After RET is will also jump to
4902 the location selected in the indirect buffer and expose the
4903 the headline hierarchy above."
4905 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
4906 (org-refile-use-outline-path t)
4908 (if (not alternative-interface)
4910 (if (eq org-goto-interface 'outline)
4911 'outline-path-completion
4913 (org-goto-start-pos (point))
4915 (if (eq interface 'outline)
4916 (car (org-get-location (current-buffer) org-goto-help))
4917 (nth 3 (org-refile-get-location "Goto: ")))))
4920 (org-mark-ring-push org-goto-start-pos)
4921 (goto-char selected-point)
4922 (if (or (org-invisible-p) (org-invisible-p2))
4923 (org-show-context 'org-goto)))
4926 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
4927 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
4928 (defvar org-goto-local-auto-isearch-map) ; defined below
4930 (defun org-get-location (buf help)
4931 "Let the user select a location in the Org-mode buffer BUF.
4932 This function uses a recursive edit. It returns the selected position
4934 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
4935 (isearch-hide-immediately nil)
4936 (isearch-search-fun-function
4937 (lambda () 'org-goto-local-search-headings))
4938 (org-goto-selected-point org-goto-exit-command))
4940 (save-window-excursion
4941 (delete-other-windows)
4942 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
4945 (make-indirect-buffer (current-buffer) "*org-goto*")
4946 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
4947 (with-output-to-temp-buffer "*Help*"
4949 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
4950 (setq buffer-read-only nil)
4951 (let ((org-startup-truncated t)
4952 (org-startup-folded nil)
4953 (org-startup-align-all-tables nil))
4956 (setq buffer-read-only t)
4957 (if (and (boundp 'org-goto-start-pos)
4958 (integer-or-marker-p org-goto-start-pos))
4959 (let ((org-show-hierarchy-above t)
4960 (org-show-siblings t)
4961 (org-show-following-heading t))
4962 (goto-char org-goto-start-pos)
4963 (and (org-invisible-p) (org-show-context)))
4964 (goto-char (point-min)))
4965 (let (org-special-ctrl-a/e) (org-beginning-of-line))
4966 (message "Select location and press RET")
4967 (use-local-map org-goto-map)
4970 (kill-buffer "*org-goto*")
4971 (cons org-goto-selected-point org-goto-exit-command)))
4973 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
4974 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
4975 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
4976 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
4978 (defun org-goto-local-search-headings (string bound noerror)
4979 "Search and make sure that any matches are in headlines."
4981 (while (if isearch-forward
4982 (search-forward string bound noerror)
4983 (search-backward string bound noerror))
4984 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
4985 (and (member :headline context)
4986 (not (member :tags context))))
4987 (throw 'return (point))))))
4989 (defun org-goto-local-auto-isearch ()
4992 (goto-char (point-min))
4993 (let ((keys (this-command-keys)))
4994 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
4996 (isearch-process-search-char (string-to-char keys)))))
4998 (defun org-goto-ret (&optional arg)
4999 "Finish `org-goto' by going to the new location."
5001 (setq org-goto-selected-point (point)
5002 org-goto-exit-command 'return)
5005 (defun org-goto-left ()
5006 "Finish `org-goto' by going to the new location."
5008 (if (org-on-heading-p)
5010 (beginning-of-line 1)
5011 (setq org-goto-selected-point (point)
5012 org-goto-exit-command 'left)
5014 (error "Not on a heading")))
5016 (defun org-goto-right ()
5017 "Finish `org-goto' by going to the new location."
5019 (if (org-on-heading-p)
5021 (setq org-goto-selected-point (point)
5022 org-goto-exit-command 'right)
5024 (error "Not on a heading")))
5026 (defun org-goto-quit ()
5027 "Finish `org-goto' without cursor motion."
5029 (setq org-goto-selected-point nil)
5030 (setq org-goto-exit-command 'quit)
5033 ;;; Indirect buffer display of subtrees
5035 (defvar org-indirect-dedicated-frame nil
5036 "This is the frame being used for indirect tree display.")
5037 (defvar org-last-indirect-buffer nil)
5039 (defun org-tree-to-indirect-buffer (&optional arg)
5040 "Create indirect buffer and narrow it to current subtree.
5041 With numerical prefix ARG, go up to this level and then take that tree.
5042 If ARG is negative, go up that many levels.
5043 If `org-indirect-buffer-display' is not `new-frame', the command removes the
5044 indirect buffer previously made with this command, to avoid proliferation of
5045 indirect buffers. However, when you call the command with a `C-u' prefix, or
5046 when `org-indirect-buffer-display' is `new-frame', the last buffer
5047 is kept so that you can work with several indirect buffers at the same time.
5048 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
5049 requests that a new frame be made for the new buffer, so that the dedicated
5050 frame is not changed."
5052 (let ((cbuf (current-buffer))
5053 (cwin (selected-window))
5055 beg end level heading ibuf)
5057 (org-back-to-heading t)
5059 (setq level (org-outline-level))
5060 (if (< arg 0) (setq arg (+ level arg)))
5061 (while (> (setq level (org-outline-level)) arg)
5062 (outline-up-heading 1 t)))
5064 heading (org-get-heading))
5065 (org-end-of-subtree t) (setq end (point)))
5066 (if (and (buffer-live-p org-last-indirect-buffer)
5067 (not (eq org-indirect-buffer-display 'new-frame))
5069 (kill-buffer org-last-indirect-buffer))
5070 (setq ibuf (org-get-indirect-buffer cbuf)
5071 org-last-indirect-buffer ibuf)
5073 ((or (eq org-indirect-buffer-display 'new-frame)
5074 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
5075 (select-frame (make-frame))
5076 (delete-other-windows)
5077 (switch-to-buffer ibuf)
5078 (org-set-frame-title heading))
5079 ((eq org-indirect-buffer-display 'dedicated-frame)
5081 (select-frame (or (and org-indirect-dedicated-frame
5082 (frame-live-p org-indirect-dedicated-frame)
5083 org-indirect-dedicated-frame)
5084 (setq org-indirect-dedicated-frame (make-frame)))))
5085 (delete-other-windows)
5086 (switch-to-buffer ibuf)
5087 (org-set-frame-title (concat "Indirect: " heading)))
5088 ((eq org-indirect-buffer-display 'current-window)
5089 (switch-to-buffer ibuf))
5090 ((eq org-indirect-buffer-display 'other-window)
5091 (pop-to-buffer ibuf))
5092 (t (error "Invalid value.")))
5093 (if (featurep 'xemacs)
5094 (save-excursion (org-mode) (turn-on-font-lock)))
5095 (narrow-to-region beg end)
5098 (and (window-live-p cwin) (select-window cwin))))
5100 (defun org-get-indirect-buffer (&optional buffer)
5101 (setq buffer (or buffer (current-buffer)))
5102 (let ((n 1) (base (buffer-name buffer)) bname)
5103 (while (buffer-live-p
5104 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
5107 (make-indirect-buffer buffer bname 'clone)
5108 (error (make-indirect-buffer buffer bname)))))
5110 (defun org-set-frame-title (title)
5111 "Set the title of the current frame to the string TITLE."
5112 ;; FIXME: how to name a single frame in XEmacs???
5113 (unless (featurep 'xemacs)
5114 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
5116 ;;;; Structure editing
5118 ;;; Inserting headlines
5120 (defun org-previous-line-empty-p ()
5123 (or (beginning-of-line 0) t)
5125 (looking-at "[ \t]*$")))))
5127 (defun org-insert-heading (&optional force-heading)
5128 "Insert a new heading or item with same depth at point.
5129 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
5130 If point is at the beginning of a headline, insert a sibling before the
5131 current headline. If point is not at the beginning, do not split the line,
5132 but create the new headline after the current line."
5134 (if (= (buffer-size) 0)
5136 (when (or force-heading (not (org-insert-item)))
5137 (let* ((empty-line-p nil)
5138 (head (save-excursion
5141 (org-back-to-heading)
5142 (setq empty-line-p (org-previous-line-empty-p))
5145 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
5146 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
5147 pos hide-previous previous-pos)
5149 ((and (org-on-heading-p) (bolp)
5151 (save-excursion (backward-char 1) (not (org-invisible-p)))))
5152 ;; insert before the current line
5153 (open-line (if blank 2 1)))
5157 (backward-char 1) (not (org-invisible-p)))))
5158 ;; insert right here
5161 ;; somewhere in the line
5163 (setq previous-pos (point-at-bol))
5165 (setq hide-previous (org-invisible-p)))
5166 (and org-insert-heading-respect-content (org-show-subtree))
5168 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
5171 (goto-char (point-at-bol))
5172 (and (looking-at org-complex-heading-regexp)
5173 (> p (match-beginning 4)))))))
5176 (org-insert-heading-respect-content
5177 (org-end-of-subtree nil t)
5178 (or (bolp) (newline))
5179 (or (org-previous-line-empty-p)
5180 (and blank (newline)))
5186 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
5187 (setq tags (and (match-end 2) (match-string 2)))
5189 (delete-region (match-beginning 1) (match-end 1)))
5190 (setq pos (point-at-bol))
5191 (or split (end-of-line 1))
5192 (delete-horizontal-space)
5193 (newline (if blank 2 1))
5199 (org-set-tags nil 'align))))
5201 (or split (end-of-line 1))
5202 (newline (if blank 2 1)))))))
5203 (insert head) (just-one-space)
5206 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
5207 (when (and org-insert-heading-respect-content hide-previous)
5209 (goto-char previous-pos)
5211 (run-hooks 'org-insert-heading-hook)))))
5213 (defun org-get-heading (&optional no-tags)
5214 "Return the heading of the current entry, without the stars."
5216 (org-back-to-heading t)
5219 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
5220 "\\*+[ \t]+\\([^\r\n]*\\)"))
5221 (match-string 1) "")))
5223 (defun org-heading-components ()
5224 "Return the components of the current heading.
5225 This is a list with the following elements:
5226 - the level as an integer
5227 - the reduced level, different if `org-odd-levels-only' is set.
5228 - the TODO keyword, or nil
5229 - the priority character, like ?A, or nil if no priority is given
5230 - the headline text itself, or the tags string if no headline text
5231 - the tags string, or nil."
5233 (org-back-to-heading t)
5234 (if (looking-at org-complex-heading-regexp)
5235 (list (length (match-string 1))
5236 (org-reduced-level (length (match-string 1)))
5237 (org-match-string-no-properties 2)
5238 (and (match-end 3) (aref (match-string 3) 2))
5239 (org-match-string-no-properties 4)
5240 (org-match-string-no-properties 5)))))
5242 (defun org-insert-heading-after-current ()
5243 "Insert a new heading with same level as current, after current subtree."
5245 (org-back-to-heading)
5246 (org-insert-heading)
5247 (org-move-subtree-down)
5250 (defun org-insert-heading-respect-content ()
5252 (let ((org-insert-heading-respect-content t))
5253 (org-insert-heading t)))
5255 (defun org-insert-todo-heading-respect-content (&optional force-state)
5257 (let ((org-insert-heading-respect-content t))
5258 (org-insert-todo-heading force-state t)))
5260 (defun org-insert-todo-heading (arg &optional force-heading)
5261 "Insert a new heading with the same level and TODO state as current heading.
5262 If the heading has no TODO state, or if the state is DONE, use the first
5263 state (TODO by default). Also with prefix arg, force first state."
5265 (when (or force-heading (not (org-insert-item 'checkbox)))
5266 (org-insert-heading force-heading)
5268 (org-back-to-heading)
5269 (outline-previous-heading)
5270 (looking-at org-todo-line-regexp))
5274 (not (match-beginning 2))
5275 (member (match-string 2) org-done-keywords))
5276 (car org-todo-keywords-1)
5280 (run-hook-with-args-until-success
5281 'org-todo-get-default-hook new-mark-x nil)
5283 (insert new-mark " "))
5284 (when org-provide-todo-statistics
5285 (org-update-parent-todo-statistics))))
5287 (defun org-insert-subheading (arg)
5288 "Insert a new subheading and demote it.
5289 Works for outline headings and for plain lists alike."
5291 (org-insert-heading arg)
5293 ((org-on-heading-p) (org-do-demote))
5294 ((org-at-item-p) (org-indent-item 1))))
5296 (defun org-insert-todo-subheading (arg)
5297 "Insert a new subheading with TODO keyword or checkbox and demote it.
5298 Works for outline headings and for plain lists alike."
5300 (org-insert-todo-heading arg)
5302 ((org-on-heading-p) (org-do-demote))
5303 ((org-at-item-p) (org-indent-item 1))))
5305 ;;; Promotion and Demotion
5307 (defun org-promote-subtree ()
5308 "Promote the entire subtree.
5309 See also `org-promote'."
5312 (org-map-tree 'org-promote))
5313 (org-fix-position-after-promote))
5315 (defun org-demote-subtree ()
5316 "Demote the entire subtree. See `org-demote'.
5317 See also `org-promote'."
5320 (org-map-tree 'org-demote))
5321 (org-fix-position-after-promote))
5324 (defun org-do-promote ()
5325 "Promote the current heading higher up the tree.
5326 If the region is active in `transient-mark-mode', promote all headings
5330 (if (org-region-active-p)
5331 (org-map-region 'org-promote (region-beginning) (region-end))
5333 (org-fix-position-after-promote))
5335 (defun org-do-demote ()
5336 "Demote the current heading lower down the tree.
5337 If the region is active in `transient-mark-mode', demote all headings
5341 (if (org-region-active-p)
5342 (org-map-region 'org-demote (region-beginning) (region-end))
5344 (org-fix-position-after-promote))
5346 (defun org-fix-position-after-promote ()
5347 "Make sure that after pro/demotion cursor position is right."
5348 (let ((pos (point)))
5349 (when (save-excursion
5350 (beginning-of-line 1)
5351 (looking-at org-todo-line-regexp)
5352 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
5353 (cond ((eobp) (insert " "))
5354 ((eolp) (insert " "))
5355 ((equal (char-after) ?\ ) (forward-char 1))))))
5357 (defun org-reduced-level (l)
5358 "Compute the effective level of a heading.
5359 This takes into account the setting of `org-odd-levels-only'."
5360 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
5362 (defun org-get-valid-level (level &optional change)
5363 "Rectify a level change under the influence of `org-odd-levels-only'
5364 LEVEL is a current level, CHANGE is by how much the level should be
5365 modified. Even if CHANGE is nil, LEVEL may be returned modified because
5366 even level numbers will become the next higher odd number."
5367 (if org-odd-levels-only
5368 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
5369 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
5370 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
5371 (max 1 (+ level (or change 0)))))
5373 (if (boundp 'define-obsolete-function-alias)
5374 (if (or (featurep 'xemacs) (< emacs-major-version 23))
5375 (define-obsolete-function-alias 'org-get-legal-level
5376 'org-get-valid-level)
5377 (define-obsolete-function-alias 'org-get-legal-level
5378 'org-get-valid-level "23.1")))
5380 (defun org-promote ()
5381 "Promote the current heading higher up the tree.
5382 If the region is active in `transient-mark-mode', promote all headings
5384 (org-back-to-heading t)
5385 (let* ((level (save-match-data (funcall outline-level)))
5386 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
5387 (diff (abs (- level (length up-head) -1))))
5388 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
5389 (replace-match up-head nil t)
5390 ;; Fixup tag positioning
5391 (and org-auto-align-tags (org-set-tags nil t))
5392 (if org-adapt-indentation (org-fixup-indentation (- diff)))))
5394 (defun org-demote ()
5395 "Demote the current heading lower down the tree.
5396 If the region is active in `transient-mark-mode', demote all headings
5398 (org-back-to-heading t)
5399 (let* ((level (save-match-data (funcall outline-level)))
5400 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
5401 (diff (abs (- level (length down-head) -1))))
5402 (replace-match down-head nil t)
5403 ;; Fixup tag positioning
5404 (and org-auto-align-tags (org-set-tags nil t))
5405 (if org-adapt-indentation (org-fixup-indentation diff))))
5407 (defun org-map-tree (fun)
5408 "Call FUN for every heading underneath the current one."
5409 (org-back-to-heading)
5410 (let ((level (funcall outline-level)))
5414 (outline-next-heading)
5415 (> (funcall outline-level) level))
5419 (defun org-map-region (fun beg end)
5420 "Call FUN for every heading between BEG and END."
5421 (let ((org-ignore-region t))
5423 (setq end (copy-marker end))
5425 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
5429 (outline-next-heading)
5434 (defun org-fixup-indentation (diff)
5435 "Change the indentation in the current entry by DIFF
5436 However, if any line in the current entry has no indentation, or if it
5437 would end up with no indentation after the change, nothing at all is done."
5439 (let ((end (save-excursion (outline-next-heading)
5441 (prohibit (if (> diff 0)
5443 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
5445 (unless (save-excursion (end-of-line 1)
5446 (re-search-forward prohibit end t))
5447 (while (and (< (point) end)
5448 (re-search-forward "^[ \t]+" end t))
5449 (goto-char (match-end 0))
5450 (setq col (current-column))
5451 (if (< diff 0) (replace-match ""))
5452 (org-indent-to-column (+ diff col))))
5453 (move-marker end nil))))
5455 (defun org-convert-to-odd-levels ()
5456 "Convert an org-mode file with all levels allowed to one with odd levels.
5457 This will leave level 1 alone, convert level 2 to level 3, level 3 to
5460 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
5461 (let ((org-odd-levels-only nil) n)
5463 (goto-char (point-min))
5464 (while (re-search-forward "^\\*\\*+ " nil t)
5465 (setq n (- (length (match-string 0)) 2))
5466 (while (>= (setq n (1- n)) 0)
5468 (end-of-line 1))))))
5471 (defun org-convert-to-oddeven-levels ()
5472 "Convert an org-mode file with only odd levels to one with odd and even levels.
5473 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
5474 section with an even level, conversion would destroy the structure of the file. An error
5475 is signaled in this case."
5477 (goto-char (point-min))
5478 ;; First check if there are no even levels
5479 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
5480 (org-show-context t)
5481 (error "Not all levels are odd in this file. Conversion not possible."))
5482 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
5483 (let ((org-odd-levels-only nil) n)
5485 (goto-char (point-min))
5486 (while (re-search-forward "^\\*\\*+ " nil t)
5487 (setq n (/ (1- (length (match-string 0))) 2))
5488 (while (>= (setq n (1- n)) 0)
5490 (end-of-line 1))))))
5492 (defun org-tr-level (n)
5493 "Make N odd if required."
5494 (if org-odd-levels-only (1+ (/ n 2)) n))
5496 ;;; Vertical tree motion, cutting and pasting of subtrees
5498 (defun org-move-subtree-up (&optional arg)
5499 "Move the current subtree up past ARG headlines of the same level."
5501 (org-move-subtree-down (- (prefix-numeric-value arg))))
5503 (defun org-move-subtree-down (&optional arg)
5504 "Move the current subtree down past ARG headlines of the same level."
5506 (setq arg (prefix-numeric-value arg))
5507 (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
5508 'outline-get-last-sibling))
5509 (ins-point (make-marker))
5511 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
5513 (org-back-to-heading)
5516 (setq ne-beg (org-back-over-empty-lines))
5519 (save-excursion (outline-end-of-heading)
5520 (setq folded (org-invisible-p)))
5521 (outline-end-of-subtree))
5522 (outline-next-heading)
5523 (setq ne-end (org-back-over-empty-lines))
5526 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
5527 ;; include less whitespace
5530 (forward-line (- ne-beg ne-end))
5531 (setq beg (point))))
5532 ;; Find insertion point, with error handling
5534 (or (and (funcall movfunc) (looking-at outline-regexp))
5535 (progn (goto-char beg0)
5536 (error "Cannot move past superior level or buffer limit")))
5537 (setq cnt (1- cnt)))
5539 ;; Moving forward - still need to move over subtree
5540 (progn (org-end-of-subtree t t)
5542 (org-back-over-empty-lines)
5543 (or (bolp) (newline)))))
5544 (setq ne-ins (org-back-over-empty-lines))
5545 (move-marker ins-point (point))
5546 (setq txt (buffer-substring beg end))
5547 (org-save-markers-in-region beg end)
5548 (delete-region beg end)
5549 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
5550 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
5551 (let ((bbb (point)))
5552 (insert-before-markers txt)
5553 (org-reinstall-markers-in-region bbb)
5554 (move-marker ins-point bbb))
5555 (or (bolp) (insert "\n"))
5556 (setq ins-end (point))
5557 (goto-char ins-point)
5558 (org-skip-whitespace)
5559 (when (and (< arg 0)
5560 (org-first-sibling-p)
5562 ;; Move whitespace back to beginning
5565 (let ((kill-whole-line t))
5566 (kill-line (- ne-ins ne-beg)) (point)))
5567 (insert (make-string (- ne-ins ne-beg) ?\n)))
5568 (move-marker ins-point nil)
5569 (org-compact-display-after-subtree-move)
5570 (org-show-empty-lines-in-parent)
5574 (org-cycle-hide-drawers 'children))))
5576 (defvar org-subtree-clip ""
5577 "Clipboard for cut and paste of subtrees.
5578 This is actually only a copy of the kill, because we use the normal kill
5579 ring. We need it to check if the kill was created by `org-copy-subtree'.")
5581 (defvar org-subtree-clip-folded nil
5582 "Was the last copied subtree folded?
5583 This is used to fold the tree back after pasting.")
5585 (defun org-cut-subtree (&optional n)
5586 "Cut the current subtree into the clipboard.
5587 With prefix arg N, cut this many sequential subtrees.
5588 This is a short-hand for marking the subtree and then cutting it."
5590 (org-copy-subtree n 'cut))
5592 (defun org-copy-subtree (&optional n cut force-store-markers)
5593 "Cut the current subtree into the clipboard.
5594 With prefix arg N, cut this many sequential subtrees.
5595 This is a short-hand for marking the subtree and then copying it.
5596 If CUT is non-nil, actually cut the subtree.
5597 If FORCE-STORE-MARKERS is non-nil, store the relative locations
5598 of some markers in the region, even if CUT is non-nil. This is
5599 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
5601 (let (beg end folded (beg0 (point)))
5603 (org-back-to-heading nil) ; take what looks like a subtree
5604 (org-back-to-heading t)) ; take what is really there
5605 (org-back-over-empty-lines)
5607 (skip-chars-forward " \t\r\n")
5609 (save-excursion (outline-end-of-heading)
5610 (setq folded (org-invisible-p)))
5612 (outline-forward-same-level (1- n))
5614 (org-end-of-subtree t t))
5615 (org-back-over-empty-lines)
5619 (setq org-subtree-clip-folded folded)
5620 (when (or cut force-store-markers)
5621 (org-save-markers-in-region beg end))
5622 (if cut (kill-region beg end) (copy-region-as-kill beg end))
5623 (setq org-subtree-clip (current-kill 0))
5624 (message "%s: Subtree(s) with %d characters"
5625 (if cut "Cut" "Copied")
5626 (length org-subtree-clip)))))
5628 (defun org-paste-subtree (&optional level tree for-yank)
5629 "Paste the clipboard as a subtree, with modification of headline level.
5630 The entire subtree is promoted or demoted in order to match a new headline
5633 If the cursor is at the beginning of a headline, the same level as
5634 that headline is used to paste the tree
5636 If not, the new level is derived from the *visible* headings
5637 before and after the insertion point, and taken to be the inferior headline
5638 level of the two. So if the previous visible heading is level 3 and the
5639 next is level 4 (or vice versa), level 4 will be used for insertion.
5640 This makes sure that the subtree remains an independent subtree and does
5641 not swallow low level entries.
5643 You can also force a different level, either by using a numeric prefix
5644 argument, or by inserting the heading marker by hand. For example, if the
5645 cursor is after \"*****\", then the tree will be shifted to level 5.
5647 If optional TREE is given, use this text instead of the kill ring.
5649 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
5650 move back over whitespace before inserting, and move point to the end of
5651 the inserted text when done."
5653 (unless (org-kill-is-subtree-p tree)
5655 (substitute-command-keys
5656 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
5657 (let* ((visp (not (org-invisible-p)))
5658 (txt (or tree (and kill-ring (current-kill 0))))
5659 (^re (concat "^\\(" outline-regexp "\\)"))
5660 (re (concat "\\(" outline-regexp "\\)"))
5661 (^re_ (concat "\\(\\*+\\)[ \t]*"))
5663 (old-level (if (string-match ^re txt)
5664 (- (match-end 0) (match-beginning 0) 1)
5666 (force-level (cond (level (prefix-numeric-value level))
5667 ((and (looking-at "[ \t]*$")
5669 ^re_ (buffer-substring
5670 (point-at-bol) (point))))
5671 (- (match-end 1) (match-beginning 1)))
5673 (looking-at org-outline-regexp))
5674 (- (match-end 0) (point) 1))
5676 (previous-level (save-excursion
5679 (outline-previous-visible-heading 1)
5681 (- (match-end 0) (match-beginning 0) 1)
5684 (next-level (save-excursion
5687 (or (looking-at outline-regexp)
5688 (outline-next-visible-heading 1))
5690 (- (match-end 0) (match-beginning 0) 1)
5693 (new-level (or force-level (max previous-level next-level)))
5694 (shift (if (or (= old-level -1)
5696 (= old-level new-level))
5698 (- new-level old-level)))
5699 (delta (if (> shift 0) -1 1))
5700 (func (if (> shift 0) 'org-demote 'org-promote))
5701 (org-odd-levels-only nil)
5703 ;; Remove the forced level indicator
5705 (delete-region (point-at-bol) (point)))
5707 (beginning-of-line 1)
5708 (unless for-yank (org-back-over-empty-lines))
5710 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
5711 (insert-before-markers txt)
5712 (unless (string-match "\n\\'" txt) (insert "\n"))
5713 (setq newend (point))
5714 (org-reinstall-markers-in-region beg)
5717 (skip-chars-forward " \t\n\r")
5719 (if (and (org-invisible-p) visp)
5720 (save-excursion (outline-show-heading)))
5721 ;; Shift if necessary
5724 (narrow-to-region beg end)
5725 (while (not (= shift 0))
5726 (org-map-region func (point-min) (point-max))
5727 (setq shift (+ delta shift)))
5728 (goto-char (point-min))
5729 (setq newend (point-max))))
5730 (when (or (interactive-p) for-yank)
5731 (message "Clipboard pasted as level %d subtree" new-level))
5732 (if (and (not for-yank) ; in this case, org-yank will decide about folding
5734 (eq org-subtree-clip (current-kill 0))
5735 org-subtree-clip-folded)
5736 ;; The tree was folded before it was killed/copied
5738 (and for-yank (goto-char newend))))
5740 (defun org-kill-is-subtree-p (&optional txt)
5741 "Check if the current kill is an outline subtree, or a set of trees.
5742 Returns nil if kill does not start with a headline, or if the first
5743 headline level is not the largest headline level in the tree.
5744 So this will actually accept several entries of equal levels as well,
5745 which is OK for `org-paste-subtree'.
5746 If optional TXT is given, check this string instead of the current kill."
5747 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
5748 (start-level (and kill
5749 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
5750 org-outline-regexp "\\)")
5752 (- (match-end 2) (match-beginning 2) 1)))
5753 (re (concat "^" org-outline-regexp))
5754 (start (1+ (or (match-beginning 2) -1))))
5755 (if (not start-level)
5757 nil) ;; does not even start with a heading
5759 (while (setq start (string-match re kill (1+ start)))
5760 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
5764 (defvar org-markers-to-move nil
5765 "Markers that should be moved with a cut-and-paste operation.
5766 Those markers are stored together with their positions relative to
5767 the start of the region.")
5769 (defun org-save-markers-in-region (beg end)
5770 "Check markers in region.
5771 If these markers are between BEG and END, record their position relative
5772 to BEG, so that after moving the block of text, we can put the markers back
5774 This function gets called just before an entry or tree gets cut from the
5775 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
5776 called immediately, to move the markers with the entries."
5777 (setq org-markers-to-move nil)
5778 (when (featurep 'org-clock)
5779 (org-clock-save-markers-for-cut-and-paste beg end))
5780 (when (featurep 'org-agenda)
5781 (org-agenda-save-markers-for-cut-and-paste beg end)))
5783 (defun org-check-and-save-marker (marker beg end)
5784 "Check if MARKER is between BEG and END.
5785 If yes, remember the marker and the distance to BEG."
5786 (when (and (marker-buffer marker)
5787 (equal (marker-buffer marker) (current-buffer)))
5788 (if (and (>= marker beg) (< marker end))
5789 (push (cons marker (- marker beg)) org-markers-to-move))))
5791 (defun org-reinstall-markers-in-region (beg)
5792 "Move all remembered markers to their position relative to BEG."
5794 (move-marker (car x) (+ beg (cdr x))))
5795 org-markers-to-move)
5796 (setq org-markers-to-move nil))
5798 (defun org-narrow-to-subtree ()
5799 "Narrow buffer to the current subtree."
5804 (progn (org-back-to-heading) (point))
5805 (progn (org-end-of-subtree t) (point))))))
5810 (defun org-sort (with-case)
5811 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
5812 Optional argument WITH-CASE means sort case-sensitively.
5813 With a double prefix argument, also remove duplicate entries."
5815 (if (org-at-table-p)
5816 (org-call-with-arg 'org-table-sort-lines with-case)
5817 (org-call-with-arg 'org-sort-entries-or-items with-case)))
5819 (defun org-sort-remove-invisible (s)
5820 (remove-text-properties 0 (length s) org-rm-props s)
5821 (while (string-match org-bracket-link-regexp s)
5822 (setq s (replace-match (if (match-end 2)
5824 (match-string 1 s)) t t s)))
5827 (defvar org-priority-regexp) ; defined later in the file
5829 (defun org-sort-entries-or-items
5830 (&optional with-case sorting-type getkey-func compare-func property)
5831 "Sort entries on a certain level of an outline tree.
5832 If there is an active region, the entries in the region are sorted.
5833 Else, if the cursor is before the first entry, sort the top-level items.
5834 Else, the children of the entry at point are sorted.
5836 Sorting can be alphabetically, numerically, and by date/time as given by
5837 the first time stamp in the entry. The command prompts for the sorting
5838 type unless it has been given to the function through the SORTING-TYPE
5839 argument, which needs to a character, any of (?n ?N ?a ?A ?t ?T ?p ?P ?f ?F).
5840 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
5841 called with point at the beginning of the record. It must return either
5842 a string or a number that should serve as the sorting key for that record.
5844 Comparing entries ignores case by default. However, with an optional argument
5845 WITH-CASE, the sorting considers case as well."
5847 (let ((case-func (if with-case 'identity 'downcase))
5848 start beg end stars re re2
5849 txt what tmp plain-list-p)
5850 ;; Find beginning and end of region to sort
5852 ((org-region-active-p)
5853 ;; we will sort the region
5854 (setq end (region-end)
5856 (goto-char (region-beginning))
5857 (if (not (org-on-heading-p)) (outline-next-heading))
5858 (setq start (point)))
5860 ;; we will sort this plain list
5861 (org-beginning-of-item-list) (setq start (point))
5862 (org-end-of-item-list) (setq end (point))
5864 (setq plain-list-p t
5866 ((or (org-on-heading-p)
5867 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
5868 ;; we will sort the children of the current headline
5869 (org-back-to-heading)
5871 end (progn (org-end-of-subtree t t)
5872 (org-back-over-empty-lines)
5877 (outline-next-heading))
5879 ;; we will sort the top-level entries in this file
5880 (goto-char (point-min))
5881 (or (org-on-heading-p) (outline-next-heading))
5882 (setq start (point) end (point-max) what "top-level")
5887 (if (>= beg end) (error "Nothing to sort"))
5889 (unless plain-list-p
5890 (looking-at "\\(\\*+\\)")
5891 (setq stars (match-string 1)
5892 re (concat "^" (regexp-quote stars) " +")
5893 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
5894 txt (buffer-substring beg end))
5895 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
5896 (if (and (not (equal stars "*")) (string-match re2 txt))
5897 (error "Region to sort contains a level above the first entry")))
5899 (unless sorting-type
5902 "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
5903 "Sort %s: [a]lpha [n]umeric [t]ime [p]riority p[r]operty todo[o]rder [f]unc A/N/T/P/O/F means reversed:")
5905 (setq sorting-type (read-char-exclusive))
5907 (and (= (downcase sorting-type) ?f)
5909 (org-ido-completing-read "Sort using function: "
5910 obarray 'fboundp t nil nil))
5911 (setq getkey-func (intern getkey-func)))
5913 (and (= (downcase sorting-type) ?r)
5915 (org-ido-completing-read "Property: "
5916 (mapcar 'list (org-buffer-property-keys t))
5919 (message "Sorting entries...")
5922 (narrow-to-region start end)
5924 (let ((dcst (downcase sorting-type))
5925 (now (current-time)))
5927 (/= dcst sorting-type)
5928 ;; This function moves to the beginning character of the "record" to
5932 (if (org-at-item-p) t (goto-char (point-max))))
5934 (if (re-search-forward re nil t)
5935 (goto-char (match-beginning 0))
5936 (goto-char (point-max)))))
5937 ;; This function moves to the last character of the "record" being
5944 (outline-forward-same-level 1)
5946 (goto-char (point-max)))))))
5948 ;; This function returns the value that gets sorted against.
5951 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
5954 (string-to-number (buffer-substring (match-end 0)
5957 (buffer-substring (match-end 0) (point-at-eol)))
5959 (if (re-search-forward org-ts-regexp
5961 (org-time-string-to-time (match-string 0))
5966 (setq tmp (funcall getkey-func))
5967 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
5969 (error "Invalid key function `%s'" getkey-func)))
5970 (t (error "Invalid sorting type `%c'" sorting-type)))))
5974 (if (looking-at org-complex-heading-regexp)
5975 (string-to-number (match-string 4))
5978 (if (looking-at org-complex-heading-regexp)
5979 (funcall case-func (match-string 4))
5982 (if (re-search-forward org-ts-regexp
5986 (org-time-string-to-time (match-string 0))
5989 (if (re-search-forward org-priority-regexp (point-at-eol) t)
5990 (string-to-char (match-string 2))
5991 org-default-priority))
5993 (or (org-entry-get nil property) ""))
5995 (if (looking-at org-complex-heading-regexp)
5996 (- 9999 (length (member (match-string 2)
5997 org-todo-keywords-1)))))
6001 (setq tmp (funcall getkey-func))
6002 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
6004 (error "Invalid key function `%s'" getkey-func)))
6005 (t (error "Invalid sorting type `%c'" sorting-type)))))
6008 ((= dcst ?a) 'string<)
6009 ((= dcst ?t) 'time-less-p)
6010 ((= dcst ?f) compare-func)
6012 (message "Sorting entries...done")))
6014 (defun org-do-sort (table what &optional with-case sorting-type)
6015 "Sort TABLE of WHAT according to SORTING-TYPE.
6016 The user will be prompted for the SORTING-TYPE if the call to this
6017 function does not specify it. WHAT is only for the prompt, to indicate
6018 what is being sorted. The sorting key will be extracted from
6019 the car of the elements of the table.
6020 If WITH-CASE is non-nil, the sorting will be case-sensitive."
6021 (unless sorting-type
6023 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
6025 (setq sorting-type (read-char-exclusive)))
6026 (let ((dcst (downcase sorting-type))
6027 extractfun comparefun)
6028 ;; Define the appropriate functions
6031 (setq extractfun 'string-to-number
6032 comparefun (if (= dcst sorting-type) '< '>)))
6034 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
6035 (lambda(x) (downcase (org-sort-remove-invisible x))))
6036 comparefun (if (= dcst sorting-type)
6038 (lambda (a b) (and (not (string< a b))
6039 (not (string= a b)))))))
6043 (if (or (string-match org-ts-regexp x)
6044 (string-match org-ts-regexp-both x))
6046 (org-time-string-to-time (match-string 0 x)))
6048 comparefun (if (= dcst sorting-type) '< '>)))
6049 (t (error "Invalid sorting type `%c'" sorting-type)))
6051 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
6053 (lambda (a b) (funcall comparefun (car a) (car b))))))
6055 ;;; Editing source examples
6057 (defvar org-exit-edit-mode-map (make-sparse-keymap))
6058 (define-key org-exit-edit-mode-map "\C-c'" 'org-edit-src-exit)
6059 (defvar org-edit-src-force-single-line nil)
6060 (defvar org-edit-src-from-org-mode nil)
6061 (defvar org-edit-src-picture nil)
6063 (define-minor-mode org-exit-edit-mode
6064 "Minor mode installing a single key binding, \"C-c '\" to exit special edit.")
6066 (defun org-edit-src-code ()
6067 "Edit the source code example at point.
6068 An indirect buffer is created, and that buffer is then narrowed to the
6069 example at point and switched to the correct language mode. When done,
6070 exit by killing the buffer with \\[org-edit-src-exit]."
6072 (let ((line (org-current-line))
6073 (case-fold-search t)
6074 (msg (substitute-command-keys
6075 "Edit, then exit with C-c ' (C-c and single quote)"))
6076 (info (org-edit-src-find-region-and-lang))
6077 (org-mode-p (eq major-mode 'org-mode))
6078 beg end lang lang-f single lfmt)
6081 (setq beg (nth 0 info)
6086 lang-f (intern (concat lang "-mode")))
6087 (unless (functionp lang-f)
6088 (error "No such language mode: %s" lang-f))
6090 (if (get-buffer "*Org Edit Src Example*")
6091 (kill-buffer "*Org Edit Src Example*"))
6092 (switch-to-buffer (make-indirect-buffer (current-buffer)
6093 "*Org Edit Src Example*"))
6094 (narrow-to-region beg end)
6095 (remove-text-properties beg end '(display nil invisible nil
6097 (let ((org-inhibit-startup t))
6099 (set (make-local-variable 'org-edit-src-force-single-line) single)
6100 (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
6102 (set (make-local-variable 'org-coderef-label-format) lfmt))
6104 (goto-char (point-min))
6105 (while (re-search-forward "^," nil t)
6106 (replace-match "")))
6108 (org-exit-edit-mode)
6109 (org-set-local 'header-line-format msg)
6113 (defun org-edit-fixed-width-region ()
6114 "Edit the fixed-width ascii drawing at point.
6115 This must be a region where each line starts with a colon followed by
6117 An indirect buffer is created, and that buffer is then narrowed to the
6118 example at point and switched to artist-mode. When done,
6119 exit by killing the buffer with \\[org-edit-src-exit]."
6121 (let ((line (org-current-line))
6122 (case-fold-search t)
6123 (msg (substitute-command-keys
6124 "Edit, then exit with C-c ' (C-c and single quote)"))
6125 (org-mode-p (eq major-mode 'org-mode))
6127 (beginning-of-line 1)
6128 (if (looking-at "[ \t]*[^:\n \t]")
6130 (if (looking-at "[ \t]*\\(\n\\|\\'\\)")
6131 (setq beg (point) end beg)
6133 (if (re-search-backward "^[ \t]*[^:]" nil 'move)
6134 (setq beg (point-at-bol 2))
6135 (setq beg (point))))
6137 (if (re-search-forward "^[ \t]*[^:]" nil 'move)
6138 (setq end (1- (match-beginning 0)))
6139 (setq end (point))))
6141 (if (get-buffer "*Org Edit Picture*")
6142 (kill-buffer "*Org Edit Picture*"))
6143 (switch-to-buffer (make-indirect-buffer (current-buffer)
6144 "*Org Edit Picture*"))
6145 (narrow-to-region beg end)
6146 (remove-text-properties beg end '(display nil invisible nil
6148 (when (fboundp 'font-lock-unfontify-region)
6149 (font-lock-unfontify-region (point-min) (point-max)))
6151 ((eq org-edit-fixed-width-region-mode 'artist-mode)
6154 (t (funcall org-edit-fixed-width-region-mode)))
6155 (set (make-local-variable 'org-edit-src-force-single-line) nil)
6156 (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
6157 (set (make-local-variable 'org-edit-src-picture) t)
6158 (goto-char (point-min))
6159 (while (re-search-forward "^[ \t]*: ?" nil t)
6162 (org-exit-edit-mode)
6163 (org-set-local 'header-line-format msg)
6168 (defun org-edit-src-find-region-and-lang ()
6169 "Find the region and language for a local edit.
6170 Return a list with beginning and end of the region, a string representing
6171 the language, a switch telling of the content should be in a single line."
6174 org-edit-src-region-extra
6176 ("<src\\>[^<]*>[ \t]*\n?" "\n?[ \t]*</src>" lang)
6177 ("<literal\\>[^<]*>[ \t]*\n?" "\n?[ \t]*</literal>" style)
6178 ("<example>[ \t]*\n?" "\n?[ \t]*</example>" "fundamental")
6179 ("<lisp>[ \t]*\n?" "\n?[ \t]*</lisp>" "emacs-lisp")
6180 ("<perl>[ \t]*\n?" "\n?[ \t]*</perl>" "perl")
6181 ("<python>[ \t]*\n?" "\n?[ \t]*</python>" "python")
6182 ("<ruby>[ \t]*\n?" "\n?[ \t]*</ruby>" "ruby")
6183 ("^#\\+begin_src\\( \\([^ \t\n]+\\)\\)?.*\n" "\n#\\+end_src" 2)
6184 ("^#\\+begin_example.*\n" "\n#\\+end_example" "fundamental")
6185 ("^#\\+html:" "\n" "html" single-line)
6186 ("^#\\+begin_html.*\n" "\n#\\+end_html" "html")
6187 ("^#\\+begin_latex.*\n" "\n#\\+end_latex" "latex")
6188 ("^#\\+latex:" "\n" "latex" single-line)
6189 ("^#\\+begin_ascii.*\n" "\n#\\+end_ascii" "fundamental")
6190 ("^#\\+ascii:" "\n" "ascii" single-line)
6193 re1 re2 single beg end lang lfmt match-re1)
6195 (while (setq entry (pop re-list))
6196 (setq re1 (car entry) re2 (nth 1 entry) lang (nth 2 entry)
6197 single (nth 3 entry))
6199 (if (or (looking-at re1)
6200 (re-search-backward re1 nil t))
6202 (setq match-re1 (match-string 0))
6203 (setq beg (match-end 0)
6204 lang (org-edit-src-get-lang lang)
6205 lfmt (org-edit-src-get-label-format match-re1))
6206 (if (and (re-search-forward re2 nil t)
6207 (>= (match-end 0) pos))
6208 (throw 'exit (list beg (match-beginning 0)
6209 lang single lfmt))))
6210 (if (or (looking-at re2)
6211 (re-search-forward re2 nil t))
6213 (setq end (match-beginning 0))
6214 (if (and (re-search-backward re1 nil t)
6215 (<= (match-beginning 0) pos))
6217 (setq lfmt (org-edit-src-get-label-format
6220 (list (match-end 0) end
6221 (org-edit-src-get-lang lang)
6222 single lfmt))))))))))))
6224 (defun org-edit-src-get-lang (lang)
6225 "Extract the src language."
6226 (let ((m (match-string 0)))
6228 ((stringp lang) lang)
6229 ((integerp lang) (match-string lang))
6230 ((and (eq lang 'lang)
6231 (string-match "\\<lang=\"\\([^ \t\n\"]+\\)\"" m))
6233 ((and (eq lang 'style)
6234 (string-match "\\<style=\"\\([^ \t\n\"]+\\)\"" m))
6236 (t "fundamental"))))
6238 (defun org-edit-src-get-label-format (s)
6239 "Extract the label format."
6241 (if (string-match "-l[ \t]+\\\\?\"\\([^\t\r\n\"]+\\)\\\\?\"" s)
6242 (match-string 1 s))))
6244 (defun org-edit-src-exit ()
6245 "Exit special edit and protect problematic lines."
6247 (unless (buffer-base-buffer (current-buffer))
6248 (error "This is not an indirect buffer, something is wrong..."))
6249 (unless (> (point-min) 1)
6250 (error "This buffer is not narrowed, something is wrong..."))
6251 (goto-char (point-min))
6252 (if (looking-at "[ \t\n]*\n") (replace-match ""))
6253 (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))
6254 (when (org-bound-and-true-p org-edit-src-force-single-line)
6255 (goto-char (point-min))
6256 (while (re-search-forward "\n" nil t)
6257 (replace-match " "))
6258 (goto-char (point-min))
6259 (if (looking-at "\\s-*") (replace-match " "))
6260 (if (re-search-forward "\\s-+\\'" nil t)
6261 (replace-match "")))
6262 (when (org-bound-and-true-p org-edit-src-from-org-mode)
6263 (goto-char (point-min))
6264 (while (re-search-forward (if (org-mode-p) "^\\(.\\)" "^\\([*#]\\)") nil t)
6265 (replace-match ",\\1"))
6266 (when font-lock-mode
6267 (font-lock-unfontify-region (point-min) (point-max)))
6268 (put-text-property (point-min) (point-max) 'font-lock-fontified t))
6269 (when (org-bound-and-true-p org-edit-src-picture)
6270 (untabify (point-min) (point-max))
6271 (goto-char (point-min))
6272 (while (re-search-forward "^" nil t)
6273 (replace-match ": "))
6274 (when font-lock-mode
6275 (font-lock-unfontify-region (point-min) (point-max)))
6276 (put-text-property (point-min) (point-max) 'font-lock-fontified t))
6277 (kill-buffer (current-buffer))
6278 (and (org-mode-p) (org-restart-font-lock)))
6281 ;;; The orgstruct minor mode
6283 ;; Define a minor mode which can be used in other modes in order to
6284 ;; integrate the org-mode structure editing commands.
6286 ;; This is really a hack, because the org-mode structure commands use
6287 ;; keys which normally belong to the major mode. Here is how it
6288 ;; works: The minor mode defines all the keys necessary to operate the
6289 ;; structure commands, but wraps the commands into a function which
6290 ;; tests if the cursor is currently at a headline or a plain list
6291 ;; item. If that is the case, the structure command is used,
6292 ;; temporarily setting many Org-mode variables like regular
6293 ;; expressions for filling etc. However, when any of those keys is
6294 ;; used at a different location, function uses `key-binding' to look
6295 ;; up if the key has an associated command in another currently active
6296 ;; keymap (minor modes, major mode, global), and executes that
6297 ;; command. There might be problems if any of the keys is otherwise
6298 ;; used as a prefix key.
6300 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
6301 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
6302 ;; addresses this by checking explicitly for both bindings.
6304 (defvar orgstruct-mode-map (make-sparse-keymap)
6305 "Keymap for the minor `orgstruct-mode'.")
6307 (defvar org-local-vars nil
6308 "List of local variables, for use by `orgstruct-mode'")
6311 (define-minor-mode orgstruct-mode
6312 "Toggle the minor more `orgstruct-mode'.
6313 This mode is for using Org-mode structure commands in other modes.
6314 The following key behave as if Org-mode was active, if the cursor
6315 is on a headline, or on a plain list item (both in the definition
6318 M-up Move entry/item up
6319 M-down Move entry/item down
6322 M-S-up Move entry/item up
6323 M-S-down Move entry/item down
6324 M-S-left Promote subtree
6325 M-S-right Demote subtree
6326 M-q Fill paragraph and items like in Org-mode
6328 C-c - Cycle list bullet
6329 TAB Cycle item visibility
6330 M-RET Insert new heading/item
6331 S-M-RET Insert new TODO heading / Checkbox item
6332 C-c C-c Set tags / toggle checkbox"
6333 nil " OrgStruct" nil
6334 (org-load-modules-maybe)
6335 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
6338 (defun turn-on-orgstruct ()
6339 "Unconditionally turn on `orgstruct-mode'."
6342 (defun orgstruct++-mode (&optional arg)
6343 "Toggle `orgstruct-mode', the enhanced version of it.
6344 In addition to setting orgstruct-mode, this also exports all indentation and
6345 autofilling variables from org-mode into the buffer. It will also
6346 recognize item context in multiline items.
6347 Note that turning off orgstruct-mode will *not* remove the
6348 indentation/paragraph settings. This can only be done by refreshing the
6349 major mode, for example with \[normal-mode]."
6351 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
6359 "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
6360 (symbol-name (car x)))
6361 (setq var (car x) val (nth 1 x))
6362 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
6364 (org-set-local 'orgstruct-is-++ t))))
6366 (defvar orgstruct-is-++ nil
6367 "Is orgstruct-mode in ++ version in the current-buffer?")
6368 (make-variable-buffer-local 'orgstruct-is-++)
6371 (defun turn-on-orgstruct++ ()
6372 "Unconditionally turn on `orgstruct++-mode'."
6373 (orgstruct++-mode 1))
6375 (defun orgstruct-error ()
6376 "Error when there is no default binding for a structure key."
6378 (error "This key has no function outside structure elements"))
6380 (defun orgstruct-setup ()
6381 "Setup orgstruct keymaps."
6385 '([(meta up)] org-metaup)
6386 '([(meta down)] org-metadown)
6387 '([(meta left)] org-metaleft)
6388 '([(meta right)] org-metaright)
6389 '([(meta shift up)] org-shiftmetaup)
6390 '([(meta shift down)] org-shiftmetadown)
6391 '([(meta shift left)] org-shiftmetaleft)
6392 '([(meta shift right)] org-shiftmetaright)
6393 '([(shift up)] org-shiftup)
6394 '([(shift down)] org-shiftdown)
6395 '([(shift left)] org-shiftleft)
6396 '([(shift right)] org-shiftright)
6397 '("\C-c\C-c" org-ctrl-c-ctrl-c)
6398 '("\M-q" fill-paragraph)
6400 '("\C-c-" org-cycle-list-bullet)))
6402 (while (setq elt (pop bindings))
6403 (setq nfunc (1+ nfunc))
6404 (setq key (org-key (car elt))
6406 cmd (orgstruct-make-binding fun nfunc key))
6407 (org-defkey orgstruct-mode-map key cmd))
6409 ;; Special treatment needed for TAB and RET
6410 (org-defkey orgstruct-mode-map [(tab)]
6411 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
6412 (org-defkey orgstruct-mode-map "\C-i"
6413 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
6415 (org-defkey orgstruct-mode-map "\M-\C-m"
6416 (orgstruct-make-binding 'org-insert-heading 105
6417 "\M-\C-m" [(meta return)]))
6418 (org-defkey orgstruct-mode-map [(meta return)]
6419 (orgstruct-make-binding 'org-insert-heading 106
6420 [(meta return)] "\M-\C-m"))
6422 (org-defkey orgstruct-mode-map [(shift meta return)]
6423 (orgstruct-make-binding 'org-insert-todo-heading 107
6424 [(meta return)] "\M-\C-m"))
6426 (unless org-local-vars
6427 (setq org-local-vars (org-get-local-variables)))
6431 (defun orgstruct-make-binding (fun n &rest keys)
6432 "Create a function for binding in the structure minor mode.
6433 FUN is the command to call inside a table. N is used to create a unique
6434 command name. KEYS are keys that should be checked in for a command
6435 to execute outside of tables."
6438 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
6440 (concat "In Structure, run `" (symbol-name fun) "'.\n"
6441 "Outside of structure, run the binding of `"
6442 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
6446 `(org-context-p 'headline 'item
6447 (and orgstruct-is-++
6448 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
6450 (list 'org-run-like-in-org-mode (list 'quote fun))
6451 (list 'let '(orgstruct-mode)
6452 (list 'call-interactively
6455 (list 'key-binding k))
6457 '('orgstruct-error))))))))
6459 (defun org-context-p (&rest contexts)
6460 "Check if local context is any of CONTEXTS.
6461 Possible values in the list of contexts are `table', `headline', and `item'."
6462 (let ((pos (point)))
6463 (goto-char (point-at-bol))
6464 (prog1 (or (and (memq 'table contexts)
6465 (looking-at "[ \t]*|"))
6466 (and (memq 'headline contexts)
6467 ;;????????? (looking-at "\\*+"))
6468 (looking-at outline-regexp))
6469 (and (memq 'item contexts)
6470 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
6471 (and (memq 'item-body contexts)
6475 (defun org-get-local-variables ()
6476 "Return a list of all local variables in an org-mode buffer."
6478 (with-current-buffer (get-buffer-create "*Org tmp*")
6481 (setq varlist (buffer-local-variables)))
6482 (kill-buffer "*Org tmp*")
6489 (list (car x) (list 'quote (cdr x)))))
6491 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
6492 (symbol-name (car x)))
6497 (defun org-run-like-in-org-mode (cmd)
6498 "Run a command, pretending that the current buffer is in Org-mode.
6499 This will temporarily bind local variables that are typically bound in
6500 Org-mode to the values they have in Org-mode, and then interactively
6502 (org-load-modules-maybe)
6503 (unless org-local-vars
6504 (setq org-local-vars (org-get-local-variables)))
6505 (eval (list 'let org-local-vars
6506 (list 'call-interactively (list 'quote cmd)))))
6510 (defun org-get-category (&optional pos)
6511 "Get the category applying to position POS."
6512 (get-text-property (or pos (point)) 'org-category))
6514 (defun org-refresh-category-properties ()
6515 "Refresh category text properties in the buffer."
6516 (let ((def-cat (cond
6517 ((null org-category)
6518 (if buffer-file-name
6519 (file-name-sans-extension
6520 (file-name-nondirectory buffer-file-name))
6522 ((symbolp org-category) (symbol-name org-category))
6524 beg end cat pos optionp)
6529 (goto-char (point-min))
6530 (put-text-property (point) (point-max) 'org-category def-cat)
6531 (while (re-search-forward
6532 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
6533 (setq pos (match-end 0)
6534 optionp (equal (char-after (match-beginning 0)) ?#)
6535 cat (org-trim (match-string 2)))
6537 (setq beg (point-at-bol) end (point-max))
6538 (org-back-to-heading t)
6539 (setq beg (point) end (org-end-of-subtree t t)))
6540 (put-text-property beg end 'org-category cat)
6541 (goto-char pos)))))))
6546 ;;; Link abbreviations
6548 (defun org-link-expand-abbrev (link)
6549 "Apply replacements as defined in `org-link-abbrev-alist."
6550 (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
6551 (let* ((key (match-string 1 link))
6552 (as (or (assoc key org-link-abbrev-alist-local)
6553 (assoc key org-link-abbrev-alist)))
6554 (tag (and (match-end 2) (match-string 3 link)))
6560 ((symbolp rpl) (funcall rpl tag))
6561 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
6562 ((string-match "%h" rpl)
6563 (replace-match (url-hexify-string (or tag "")) t t rpl))
6564 (t (concat rpl tag)))))
6567 ;;; Storing and inserting links
6569 (defvar org-insert-link-history nil
6570 "Minibuffer history for links inserted with `org-insert-link'.")
6572 (defvar org-stored-links nil
6573 "Contains the links stored with `org-store-link'.")
6575 (defvar org-store-link-plist nil
6576 "Plist with info about the most recently link created with `org-store-link'.")
6578 (defvar org-link-protocols nil
6579 "Link protocols added to Org-mode using `org-add-link-type'.")
6581 (defvar org-store-link-functions nil
6582 "List of functions that are called to create and store a link.
6583 Each function will be called in turn until one returns a non-nil
6584 value. Each function should check if it is responsible for creating
6585 this link (for example by looking at the major mode).
6586 If not, it must exit and return nil.
6587 If yes, it should return a non-nil value after a calling
6588 `org-store-link-props' with a list of properties and values.
6589 Special properties are:
6591 :type The link prefix. like \"http\". This must be given.
6592 :link The link, like \"http://www.astro.uva.nl/~dominik\".
6593 This is obligatory as well.
6594 :description Optional default description for the second pair
6595 of brackets in an Org-mode link. The user can still change
6596 this when inserting this link into an Org-mode buffer.
6598 In addition to these, any additional properties can be specified
6599 and then used in remember templates.")
6601 (defun org-add-link-type (type &optional follow export)
6602 "Add TYPE to the list of `org-link-types'.
6603 Re-compute all regular expressions depending on `org-link-types'
6605 FOLLOW and EXPORT are two functions.
6607 FOLLOW should take the link path as the single argument and do whatever
6608 is necessary to follow the link, for example find a file or display
6611 EXPORT should format the link path for export to one of the export formats.
6612 It should be a function accepting three arguments:
6614 path the path of the link, the text after the prefix (like \"http:\")
6615 desc the description of the link, if any, nil if there was no description
6616 format the export format, a symbol like `html' or `latex'.
6618 The function may use the FORMAT information to return different values
6619 depending on the format. The return value will be put literally into
6621 Org-mode has a built-in default for exporting links. If you are happy with
6622 this default, there is no need to define an export function for the link
6623 type. For a simple example of an export function, see `org-bbdb.el'."
6624 (add-to-list 'org-link-types type t)
6625 (org-make-link-regexps)
6626 (if (assoc type org-link-protocols)
6627 (setcdr (assoc type org-link-protocols) (list follow export))
6628 (push (list type follow export) org-link-protocols)))
6631 (defun org-store-link (arg)
6632 "\\<org-mode-map>Store an org-link to the current location.
6633 This link is added to `org-stored-links' and can later be inserted
6634 into an org-buffer with \\[org-insert-link].
6636 For some link types, a prefix arg is interpreted:
6637 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
6638 For file links, arg negates `org-context-in-file-links'."
6640 (org-load-modules-maybe)
6641 (setq org-store-link-plist nil) ; reset
6642 (let (link cpltxt desc description search txt)
6645 ((run-hook-with-args-until-success 'org-store-link-functions)
6646 (setq link (plist-get org-store-link-plist :link)
6647 desc (or (plist-get org-store-link-plist :description) link)))
6649 ((equal (buffer-name) "*Org Edit Src Example*")
6651 (while (or (not label)
6655 (goto-char (point-min))
6657 (regexp-quote (format org-coderef-label-format label))
6659 (when label (message "Label exists already") (sit-for 2))
6660 (setq label (read-string "Code line label: " label)))
6662 (setq link (format org-coderef-label-format label))
6663 (setq gc (- 79 (length link)))
6664 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
6666 (setq link (concat "(" label ")") desc nil)))
6668 ((eq major-mode 'calendar-mode)
6669 (let ((cd (calendar-cursor-to-date)))
6672 (car org-time-stamp-formats)
6674 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
6676 (org-store-link-props :type "calendar" :date cd)))
6678 ((eq major-mode 'w3-mode)
6679 (setq cpltxt (url-view-url t)
6680 link (org-make-link cpltxt))
6681 (org-store-link-props :type "w3" :url (url-view-url t)))
6683 ((eq major-mode 'w3m-mode)
6684 (setq cpltxt (or w3m-current-title w3m-current-url)
6685 link (org-make-link w3m-current-url))
6686 (org-store-link-props :type "w3m" :url (url-view-url t)))
6688 ((setq search (run-hook-with-args-until-success
6689 'org-create-file-search-functions))
6690 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
6692 (setq cpltxt (or description link)))
6694 ((eq major-mode 'image-mode)
6695 (setq cpltxt (concat "file:"
6696 (abbreviate-file-name buffer-file-name))
6697 link (org-make-link cpltxt))
6698 (org-store-link-props :type "image" :file buffer-file-name))
6700 ((eq major-mode 'dired-mode)
6701 ;; link to the file in the current line
6702 (setq cpltxt (concat "file:"
6703 (abbreviate-file-name
6705 (dired-get-filename nil t))))
6706 link (org-make-link cpltxt)))
6708 ((and buffer-file-name (org-mode-p))
6710 ((org-in-regexp "<<\\(.*?\\)>>")
6713 (abbreviate-file-name buffer-file-name)
6714 "::" (match-string 1))
6715 link (org-make-link cpltxt)))
6716 ((and (featurep 'org-id)
6717 (or (eq org-link-to-org-use-id t)
6718 (and (eq org-link-to-org-use-id 'create-if-interactive)
6720 (and org-link-to-org-use-id
6722 (org-entry-get nil "ID")
6724 ;; We can make a link using the ID.
6725 (setq link (condition-case nil
6726 (prog1 (org-id-store-link)
6727 (setq desc (plist-get org-store-link-plist
6730 ;; probably before first headline, link to file only
6732 (abbreviate-file-name buffer-file-name))))))
6734 ;; Just link to current headline
6735 (setq cpltxt (concat "file:"
6736 (abbreviate-file-name buffer-file-name)))
6737 ;; Add a context search string
6738 (when (org-xor org-context-in-file-links arg)
6740 ((org-on-heading-p) nil)
6741 ((org-region-active-p)
6742 (buffer-substring (region-beginning) (region-end)))
6744 (when (or (null txt) (string-match "\\S-" txt))
6748 (org-make-org-heading-search-string txt)
6751 (if (string-match "::\\'" cpltxt)
6752 (setq cpltxt (substring cpltxt 0 -2)))
6753 (setq link (org-make-link cpltxt)))))
6755 ((buffer-file-name (buffer-base-buffer))
6756 ;; Just link to this file here.
6757 (setq cpltxt (concat "file:"
6758 (abbreviate-file-name
6759 (buffer-file-name (buffer-base-buffer)))))
6760 ;; Add a context string
6761 (when (org-xor org-context-in-file-links arg)
6762 (setq txt (if (org-region-active-p)
6763 (buffer-substring (region-beginning) (region-end))
6764 (buffer-substring (point-at-bol) (point-at-eol))))
6765 ;; Only use search option if there is some text.
6766 (when (string-match "\\S-" txt)
6768 (concat cpltxt "::" (org-make-org-heading-search-string txt))
6770 (setq link (org-make-link cpltxt)))
6773 (error "Cannot link to a buffer which is not visiting a file"))
6775 (t (setq link nil)))
6777 (if (consp link) (setq cpltxt (car link) link (cdr link)))
6778 (setq link (or link cpltxt)
6779 desc (or desc cpltxt))
6780 (if (equal desc "NONE") (setq desc nil))
6782 (if (and (interactive-p) link)
6784 (setq org-stored-links
6785 (cons (list link desc) org-stored-links))
6786 (message "Stored: %s" (or desc link)))
6787 (and link (org-make-link-string link desc)))))
6789 (defun org-store-link-props (&rest plist)
6790 "Store link properties, extract names and addresses."
6792 (when (setq x (plist-get plist :from))
6793 (setq adr (mail-extract-address-components x))
6794 (setq plist (plist-put plist :fromname (car adr)))
6795 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
6796 (when (setq x (plist-get plist :to))
6797 (setq adr (mail-extract-address-components x))
6798 (setq plist (plist-put plist :toname (car adr)))
6799 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
6800 (let ((from (plist-get plist :from))
6801 (to (plist-get plist :to)))
6802 (when (and from to org-from-is-user-regexp)
6804 (plist-put plist :fromto
6805 (if (string-match org-from-is-user-regexp from)
6807 (concat "from %f"))))))
6808 (setq org-store-link-plist plist))
6810 (defun org-add-link-props (&rest plist)
6811 "Add these properties to the link property list."
6814 (setq key (pop plist) value (pop plist))
6815 (setq org-store-link-plist
6816 (plist-put org-store-link-plist key value)))))
6818 (defun org-email-link-description (&optional fmt)
6819 "Return the description part of an email link.
6820 This takes information from `org-store-link-plist' and formats it
6821 according to FMT (default from `org-email-link-description-format')."
6822 (setq fmt (or fmt org-email-link-description-format))
6823 (let* ((p org-store-link-plist)
6824 (to (plist-get p :toaddress))
6825 (from (plist-get p :fromaddress))
6828 (cons "%c" (plist-get p :fromto))
6829 (cons "%F" (plist-get p :from))
6830 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
6831 (cons "%T" (plist-get p :to))
6832 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
6833 (cons "%s" (plist-get p :subject))
6834 (cons "%m" (plist-get p :message-id)))))
6835 (when (string-match "%c" fmt)
6836 ;; Check if the user wrote this message
6837 (if (and org-from-is-user-regexp from to
6838 (save-match-data (string-match org-from-is-user-regexp from)))
6839 (setq fmt (replace-match "to %t" t t fmt))
6840 (setq fmt (replace-match "from %f" t t fmt))))
6841 (org-replace-escapes fmt table)))
6843 (defun org-make-org-heading-search-string (&optional string heading)
6844 "Make search string for STRING or current headline."
6846 (let ((s (or string (org-get-heading))))
6847 (unless (and string (not heading))
6848 ;; We are using a headline, clean up garbage in there.
6849 (if (string-match org-todo-regexp s)
6850 (setq s (replace-match "" t t s)))
6851 (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s)
6852 (setq s (replace-match "" t t s)))
6853 (setq s (org-trim s))
6854 (if (string-match (concat "^\\(" org-quote-string "\\|"
6855 org-comment-string "\\)") s)
6856 (setq s (replace-match "" t t s)))
6857 (while (string-match org-ts-regexp s)
6858 (setq s (replace-match "" t t s))))
6859 (while (string-match "[^a-zA-Z_0-9 \t]+" s)
6860 (setq s (replace-match " " t t s)))
6861 (or string (setq s (concat "*" s))) ; Add * for headlines
6862 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
6864 (defun org-make-link (&rest strings)
6865 "Concatenate STRINGS."
6866 (apply 'concat strings))
6868 (defun org-make-link-string (link &optional description)
6869 "Make a link with brackets, consisting of LINK and DESCRIPTION."
6870 (unless (string-match "\\S-" link)
6871 (error "Empty link"))
6872 (when (stringp description)
6873 ;; Remove brackets from the description, they are fatal.
6874 (while (string-match "\\[" description)
6875 (setq description (replace-match "{" t t description)))
6876 (while (string-match "\\]" description)
6877 (setq description (replace-match "}" t t description))))
6878 (when (equal (org-link-escape link) description)
6879 ;; No description needed, it is identical
6880 (setq description nil))
6881 (when (and (not description)
6882 (not (equal link (org-link-escape link))))
6883 (setq description (org-extract-attributes link)))
6884 (concat "[[" (org-link-escape link) "]"
6885 (if description (concat "[" description "]") "")
6888 (defconst org-link-escape-chars
6892 (?\340 . "%E0") ; `a
6893 (?\342 . "%E2") ; ^a
6894 (?\347 . "%E7") ; ,c
6895 (?\350 . "%E8") ; `e
6896 (?\351 . "%E9") ; 'e
6897 (?\352 . "%EA") ; ^e
6898 (?\356 . "%EE") ; ^i
6899 (?\364 . "%F4") ; ^o
6900 (?\371 . "%F9") ; `u
6901 (?\373 . "%FB") ; ^u
6907 "Association list of escapes for some characters problematic in links.
6908 This is the list that is used for internal purposes.")
6910 (defconst org-link-escape-chars-browser
6911 '((?\ . "%20")) ; 32 for the SPC char
6912 "Association list of escapes for some characters problematic in links.
6913 This is the list that is used before handing over to the browser.")
6915 (defun org-link-escape (text &optional table)
6916 "Escape characters in TEXT that are problematic for links."
6917 (setq table (or table org-link-escape-chars))
6919 (let ((re (mapconcat (lambda (x) (regexp-quote
6920 (char-to-string (car x))))
6922 (while (string-match re text)
6925 (cdr (assoc (string-to-char (match-string 0 text))
6930 (defun org-link-unescape (text &optional table)
6931 "Reverse the action of `org-link-escape'."
6932 (setq table (or table org-link-escape-chars))
6934 (let ((re (mapconcat (lambda (x) (regexp-quote (cdr x)))
6936 (while (string-match re text)
6939 (char-to-string (car (rassoc (match-string 0 text) table)))
6943 (defun org-xor (a b)
6947 (defun org-fixup-message-id-for-http (s)
6948 "Replace special characters in a message id, so it can be used in an http query."
6949 (while (string-match "<" s)
6950 (setq s (replace-match "%3C" t t s)))
6951 (while (string-match ">" s)
6952 (setq s (replace-match "%3E" t t s)))
6953 (while (string-match "@" s)
6954 (setq s (replace-match "%40" t t s)))
6958 (defun org-insert-link-global ()
6959 "Insert a link like Org-mode does.
6960 This command can be called in any mode to insert a link in Org-mode syntax."
6962 (org-load-modules-maybe)
6963 (org-run-like-in-org-mode 'org-insert-link))
6965 (defun org-insert-link (&optional complete-file link-location)
6966 "Insert a link. At the prompt, enter the link.
6968 Completion can be used to insert any of the link protocol prefixes like
6971 The history can be used to select a link previously stored with
6972 `org-store-link'. When the empty string is entered (i.e. if you just
6973 press RET at the prompt), the link defaults to the most recently
6974 stored link. As SPC triggers completion in the minibuffer, you need to
6975 use M-SPC or C-q SPC to force the insertion of a space character.
6977 You will also be prompted for a description, and if one is given, it will
6978 be displayed in the buffer instead of the link.
6980 If there is already a link at point, this command will allow you to edit link
6981 and description parts.
6983 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
6984 be selected using completion. The path to the file will be relative to the
6985 current directory if the file is in the current directory or a subdirectory.
6986 Otherwise, the link will be the absolute path as completed in the minibuffer
6987 \(i.e. normally ~/path/to/file). You can configure this behavior using the
6988 option `org-link-file-path-type'.
6990 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
6991 the current directory or below.
6993 With three \\[universal-argument] prefixes, negate the meaning of
6994 `org-keep-stored-link-after-insertion'.
6996 If `org-make-link-description-function' is non-nil, this function will be
6997 called with the link target, and the result will be the default
7000 If the LINK-LOCATION parameter is non-nil, this value will be
7001 used as the link location instead of reading one interactively."
7003 (let* ((wcf (current-window-configuration))
7004 (region (if (org-region-active-p)
7005 (buffer-substring (region-beginning) (region-end))))
7006 (remove (and region (list (region-beginning) (region-end))))
7008 tmphist ; byte-compile incorrectly complains about this
7009 (link link-location)
7012 (link-location) ; specified by arg, just use it.
7013 ((org-in-regexp org-bracket-link-regexp 1)
7014 ;; We do have a link at point, and we are going to edit it.
7015 (setq remove (list (match-beginning 0) (match-end 0)))
7016 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
7017 (setq link (read-string "Link: "
7019 (org-match-string-no-properties 1)))))
7020 ((or (org-in-regexp org-angle-link-re)
7021 (org-in-regexp org-plain-link-re))
7022 ;; Convert to bracket link
7023 (setq remove (list (match-beginning 0) (match-end 0))
7024 link (read-string "Link: "
7025 (org-remove-angle-brackets (match-string 0)))))
7026 ((member complete-file '((4) (16)))
7027 ;; Completing read for file names.
7028 (setq file (read-file-name "File: "))
7029 (let ((pwd (file-name-as-directory (expand-file-name ".")))
7030 (pwd1 (file-name-as-directory (abbreviate-file-name
7031 (expand-file-name ".")))))
7033 ((equal complete-file '(16))
7034 (setq link (org-make-link
7036 (abbreviate-file-name (expand-file-name file)))))
7037 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
7038 (setq link (org-make-link "file:" (match-string 1 file))))
7039 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
7040 (expand-file-name file))
7041 (setq link (org-make-link
7042 "file:" (match-string 1 (expand-file-name file)))))
7043 (t (setq link (org-make-link "file:" file))))))
7045 ;; Read link, with completion for stored links.
7046 (with-output-to-temp-buffer "*Org Links*"
7047 (princ "Insert a link. Use TAB to complete valid link prefixes.\n")
7048 (when org-stored-links
7049 (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
7052 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
7053 (reverse org-stored-links) "\n"))))
7054 (let ((cw (selected-window)))
7055 (select-window (get-buffer-window "*Org Links*"))
7056 (setq truncate-lines t)
7057 (org-fit-window-to-buffer)
7059 ;; Fake a link history, containing the stored links.
7060 (setq tmphist (append (mapcar 'car org-stored-links)
7061 org-insert-link-history))
7064 (let ((org-completion-use-ido nil))
7065 (org-completing-read
7068 (mapcar (lambda (x) (list (concat (car x) ":")))
7069 (append org-link-abbrev-alist-local org-link-abbrev-alist))
7070 (mapcar (lambda (x) (list (concat x ":")))
7074 (or (car (car org-stored-links))))))
7075 (set-window-configuration wcf)
7076 (kill-buffer "*Org Links*"))
7077 (setq entry (assoc link org-stored-links))
7078 (or entry (push link org-insert-link-history))
7079 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
7080 (not org-keep-stored-link-after-insertion))
7081 (setq org-stored-links (delq (assoc link org-stored-links)
7083 (setq desc (or desc (nth 1 entry)))))
7085 (if (string-match org-plain-link-re link)
7086 ;; URL-like link, normalize the use of angular brackets.
7087 (setq link (org-make-link (org-remove-angle-brackets link))))
7089 ;; Check if we are linking to the current file with a search option
7090 ;; If yes, simplify the link by using only the search option.
7091 (when (and buffer-file-name
7092 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
7093 (let* ((path (match-string 1 link))
7094 (case-fold-search nil)
7095 (search (match-string 2 link)))
7097 (if (equal (file-truename buffer-file-name) (file-truename path))
7098 ;; We are linking to this same file, with a search option
7099 (setq link search)))))
7101 ;; Check if we can/should use a relative path. If yes, simplify the link
7102 (when (string-match "^file:\\(.*\\)" link)
7103 (let* ((path (match-string 1 link))
7105 (case-fold-search nil))
7107 ((or (eq org-link-file-path-type 'absolute)
7108 (equal complete-file '(16)))
7109 (setq path (abbreviate-file-name (expand-file-name path))))
7110 ((eq org-link-file-path-type 'noabbrev)
7111 (setq path (expand-file-name path)))
7112 ((eq org-link-file-path-type 'relative)
7113 (setq path (file-relative-name path)))
7116 (if (string-match (concat "^" (regexp-quote
7117 (file-name-as-directory
7118 (expand-file-name "."))))
7119 (expand-file-name path))
7120 ;; We are linking a file with relative path name.
7121 (setq path (substring (expand-file-name path)
7123 (setq path (abbreviate-file-name (expand-file-name path)))))))
7124 (setq link (concat "file:" path))
7125 (if (equal desc origpath)
7128 (if org-make-link-description-function
7129 (setq desc (funcall org-make-link-description-function link desc)))
7131 (setq desc (read-string "Description: " desc))
7132 (unless (string-match "\\S-" desc) (setq desc nil))
7133 (if remove (apply 'delete-region remove))
7134 (insert (org-make-link-string link desc))))
7136 (defun org-completing-read (&rest args)
7137 "Completing-read with SPACE being a normal character."
7138 (let ((minibuffer-local-completion-map
7139 (copy-keymap minibuffer-local-completion-map)))
7140 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
7141 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
7142 (apply 'org-ido-completing-read args)))
7144 (defun org-completing-read-no-ido (&rest args)
7145 (let (org-completion-use-ido)
7146 (apply 'org-completing-read args)))
7148 (defun org-ido-completing-read (&rest args)
7149 "Completing-read using `ido-mode' speedups if available"
7150 (if (and org-completion-use-ido
7151 (fboundp 'ido-completing-read)
7152 (boundp 'ido-mode) ido-mode
7153 (listp (second args)))
7154 (let ((ido-enter-matching-directory nil))
7155 (apply 'ido-completing-read (concat (car args))
7156 (mapcar (lambda (x) (car x)) (nth 1 args))
7158 (apply 'completing-read args)))
7161 (defun org-extract-attributes (s)
7162 "Extract the attributes cookie from a string and set as text property."
7163 (let (a attr (start 0) key value)
7165 (when (string-match "{{\\([^}]+\\)}}$" s)
7166 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
7167 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
7168 (setq key (match-string 1 a) value (match-string 2 a)
7170 attr (plist-put attr (intern key) value))))
7171 (org-add-props s nil 'org-attr attr))
7174 (defun org-attributes-to-string (plist)
7175 "Format a property list into an HTML attribute list."
7176 (let ((s "") key value)
7178 (setq key (pop plist) value (pop plist))
7180 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
7183 ;;; Opening/following a link
7185 (defvar org-link-search-failed nil)
7187 (defun org-next-link ()
7188 "Move forward to the next link.
7189 If the link is in hidden text, expose it."
7191 (when (and org-link-search-failed (eq this-command last-command))
7192 (goto-char (point-min))
7193 (message "Link search wrapped back to beginning of buffer"))
7194 (setq org-link-search-failed nil)
7195 (let* ((pos (point))
7197 (a (assoc :link ct)))
7198 (if a (goto-char (nth 2 a)))
7199 (if (re-search-forward org-any-link-re nil t)
7201 (goto-char (match-beginning 0))
7202 (if (org-invisible-p) (org-show-context)))
7204 (setq org-link-search-failed t)
7205 (error "No further link found"))))
7207 (defun org-previous-link ()
7208 "Move backward to the previous link.
7209 If the link is in hidden text, expose it."
7211 (when (and org-link-search-failed (eq this-command last-command))
7212 (goto-char (point-max))
7213 (message "Link search wrapped back to end of buffer"))
7214 (setq org-link-search-failed nil)
7215 (let* ((pos (point))
7217 (a (assoc :link ct)))
7218 (if a (goto-char (nth 1 a)))
7219 (if (re-search-backward org-any-link-re nil t)
7221 (goto-char (match-beginning 0))
7222 (if (org-invisible-p) (org-show-context)))
7224 (setq org-link-search-failed t)
7225 (error "No further link found"))))
7227 (defun org-translate-link (s)
7228 "Translate a link string if a translation function has been defined."
7229 (if (and org-link-translation-function
7230 (fboundp org-link-translation-function)
7231 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
7233 (setq s (funcall org-link-translation-function
7234 (match-string 1) (match-string 2)))
7235 (concat (car s) ":" (cdr s)))
7238 (defun org-translate-link-from-planner (type path)
7239 "Translate a link from Emacs Planner syntax so that Org can follow it.
7240 This is still an experimental function, your mileage may vary."
7242 ((member type '("http" "https" "news" "ftp"))
7243 ;; standard Internet links are the same.
7245 ((and (equal type "irc") (string-match "^//" path))
7246 ;; Planner has two / at the beginning of an irc link, we have 1.
7247 ;; We should have zero, actually....
7248 (setq path (substring path 1)))
7249 ((and (equal type "lisp") (string-match "^/" path))
7250 ;; Planner has a slash, we do not.
7251 (setq type "elisp" path (substring path 1)))
7252 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
7253 ;; A typical message link. Planner has the id after the fina slash,
7254 ;; we separate it with a hash mark
7255 (setq path (concat (match-string 1 path) "#"
7256 (org-remove-angle-brackets (match-string 2 path)))))
7260 (defun org-find-file-at-mouse (ev)
7261 "Open file link or URL at mouse."
7263 (mouse-set-point ev)
7264 (org-open-at-point 'in-emacs))
7266 (defun org-open-at-mouse (ev)
7267 "Open file link or URL at mouse."
7269 (mouse-set-point ev)
7270 (if (eq major-mode 'org-agenda-mode)
7271 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
7272 (org-open-at-point))
7274 (defvar org-window-config-before-follow-link nil
7275 "The window configuration before following a link.
7276 This is saved in case the need arises to restore it.")
7278 (defvar org-open-link-marker (make-marker)
7279 "Marker pointing to the location where `org-open-at-point; was called.")
7282 (defun org-open-at-point-global ()
7283 "Follow a link like Org-mode does.
7284 This command can be called in any mode to follow a link that has
7287 (org-run-like-in-org-mode 'org-open-at-point))
7290 (defun org-open-link-from-string (s &optional arg)
7291 "Open a link in the string S, as if it was in Org-mode."
7292 (interactive "sLink: \nP")
7294 (let ((org-inhibit-startup t))
7297 (goto-char (point-min))
7298 (org-open-at-point arg))))
7300 (defun org-open-at-point (&optional in-emacs)
7301 "Open link at or after point.
7302 If there is no link at point, this function will search forward up to
7303 the end of the current subtree.
7304 Normally, files will be opened by an appropriate application. If the
7305 optional argument IN-EMACS is non-nil, Emacs will visit the file.
7306 With a double prefix argument, try to open outside of Emacs, in the
7307 application the system uses for this file type."
7309 (org-load-modules-maybe)
7310 (move-marker org-open-link-marker (point))
7311 (setq org-window-config-before-follow-link (current-window-configuration))
7312 (org-remove-occur-highlights nil nil t)
7314 ((org-at-timestamp-p t) (org-follow-timestamp-link))
7315 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
7316 (org-footnote-action))
7318 (let (type path link line search (pos (point)))
7321 (skip-chars-forward "^]\n\r")
7322 (when (org-in-regexp org-bracket-link-regexp)
7323 (setq link (org-extract-attributes
7324 (org-link-unescape (org-match-string-no-properties 1))))
7325 (while (string-match " *\n *" link)
7326 (setq link (replace-match " " t t link)))
7327 (setq link (org-link-expand-abbrev link))
7329 ((or (file-name-absolute-p link)
7330 (string-match "^\\.\\.?/" link))
7331 (setq type "file" path link))
7332 ((string-match org-link-re-with-space3 link)
7333 (setq type (match-string 1 link) path (match-string 2 link)))
7334 (t (setq type "thisfile" path link)))
7337 (when (get-text-property (point) 'org-linked-text)
7338 (setq type "thisfile"
7339 pos (if (get-text-property (1+ (point)) 'org-linked-text)
7340 (1+ (point)) (point))
7341 path (buffer-substring
7342 (previous-single-property-change pos 'org-linked-text)
7343 (next-single-property-change pos 'org-linked-text)))
7347 (when (or (org-in-regexp org-angle-link-re)
7348 (org-in-regexp org-plain-link-re))
7349 (setq type (match-string 1) path (match-string 2))
7351 (when (org-in-regexp "\\<\\([^><\n]+\\)\\>")
7352 (setq type "tree-match"
7353 path (match-string 1))
7356 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
7358 path (match-string 1))
7359 (while (string-match ":" path)
7360 (setq path (replace-match "+" t t path)))
7363 (error "No link found"))
7364 ;; Remove any trailing spaces in path
7365 (if (string-match " +\\'" path)
7366 (setq path (replace-match "" t t path)))
7367 (if (and org-link-translation-function
7368 (fboundp org-link-translation-function))
7369 ;; Check if we need to translate the link
7370 (let ((tmp (funcall org-link-translation-function type path)))
7371 (setq type (car tmp) path (cdr tmp))))
7375 ((assoc type org-link-protocols)
7376 (funcall (nth 1 (assoc type org-link-protocols)) path))
7378 ((equal type "mailto")
7379 (let ((cmd (car org-link-mailto-program))
7380 (args (cdr org-link-mailto-program)) args1
7381 (address path) (subject "") a)
7382 (if (string-match "\\(.*\\)::\\(.*\\)" path)
7383 (setq address (match-string 1 path)
7384 subject (org-link-escape (match-string 2 path))))
7387 ((not (stringp (car args))) (push (pop args) args1))
7388 (t (setq a (pop args))
7389 (if (string-match "%a" a)
7390 (setq a (replace-match address t t a)))
7391 (if (string-match "%s" a)
7392 (setq a (replace-match subject t t a)))
7394 (apply cmd (nreverse args1))))
7396 ((member type '("http" "https" "ftp" "news"))
7397 (browse-url (concat type ":" (org-link-escape
7398 path org-link-escape-chars-browser))))
7400 ((member type '("message"))
7401 (browse-url (concat type ":" path)))
7403 ((string= type "tags")
7404 (org-tags-view in-emacs path))
7405 ((string= type "thisfile")
7407 (switch-to-buffer-other-window
7408 (org-get-buffer-for-internal-link (current-buffer)))
7409 (org-mark-ring-push))
7410 (let ((cmd `(org-link-search
7412 ,(cond ((equal in-emacs '(4)) 'occur)
7413 ((equal in-emacs '(16)) 'org-occur)
7416 (condition-case nil (eval cmd)
7417 (error (progn (widen) (eval cmd))))))
7419 ((string= type "tree-match")
7420 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
7422 ((string= type "file")
7423 (if (string-match "::\\([0-9]+\\)\\'" path)
7424 (setq line (string-to-number (match-string 1 path))
7425 path (substring path 0 (match-beginning 0)))
7426 (if (string-match "::\\(.+\\)\\'" path)
7427 (setq search (match-string 1 path)
7428 path (substring path 0 (match-beginning 0)))))
7429 (if (string-match "[*?{]" (file-name-nondirectory path))
7431 (org-open-file path in-emacs line search)))
7433 ((string= type "news")
7435 (org-gnus-follow-link path))
7437 ((string= type "shell")
7439 (if (or (not org-confirm-shell-link-function)
7440 (funcall org-confirm-shell-link-function
7441 (format "Execute \"%s\" in shell? "
7442 (org-add-props cmd nil
7443 'face 'org-warning))))
7445 (message "Executing %s" cmd)
7446 (shell-command cmd))
7449 ((string= type "elisp")
7451 (if (or (not org-confirm-elisp-link-function)
7452 (funcall org-confirm-elisp-link-function
7453 (format "Execute \"%s\" as elisp? "
7454 (org-add-props cmd nil
7455 'face 'org-warning))))
7456 (message "%s => %s" cmd
7457 (if (equal (string-to-char cmd) ?\()
7459 (call-interactively (read cmd))))
7463 (browse-url-at-point))))))
7464 (move-marker org-open-link-marker nil)
7465 (run-hook-with-args 'org-follow-link-hook))
7469 (defun org-get-effort (&optional pom)
7470 "Get the effort estimate for the current entry."
7471 (org-entry-get pom org-effort-property))
7475 (defvar org-create-file-search-functions nil
7476 "List of functions to construct the right search string for a file link.
7477 These functions are called in turn with point at the location to
7478 which the link should point.
7480 A function in the hook should first test if it would like to
7481 handle this file type, for example by checking the major-mode or
7482 the file extension. If it decides not to handle this file, it
7483 should just return nil to give other functions a chance. If it
7484 does handle the file, it must return the search string to be used
7485 when following the link. The search string will be part of the
7486 file link, given after a double colon, and `org-open-at-point'
7487 will automatically search for it. If special measures must be
7488 taken to make the search successful, another function should be
7489 added to the companion hook `org-execute-file-search-functions',
7492 A function in this hook may also use `setq' to set the variable
7493 `description' to provide a suggestion for the descriptive text to
7494 be used for this link when it gets inserted into an Org-mode
7495 buffer with \\[org-insert-link].")
7497 (defvar org-execute-file-search-functions nil
7498 "List of functions to execute a file search triggered by a link.
7500 Functions added to this hook must accept a single argument, the
7501 search string that was part of the file link, the part after the
7502 double colon. The function must first check if it would like to
7503 handle this search, for example by checking the major-mode or the
7504 file extension. If it decides not to handle this search, it
7505 should just return nil to give other functions a chance. If it
7506 does handle the search, it must return a non-nil value to keep
7507 other functions from trying.
7509 Each function can access the current prefix argument through the
7510 variable `current-prefix-argument'. Note that a single prefix is
7511 used to force opening a link in Emacs, so it may be good to only
7512 use a numeric or double prefix to guide the search function.
7514 In case this is needed, a function in this hook can also restore
7515 the window configuration before `org-open-at-point' was called using:
7517 (set-window-configuration org-window-config-before-follow-link)")
7519 (defun org-link-search (s &optional type avoid-pos)
7520 "Search for a link search option.
7521 If S is surrounded by forward slashes, it is interpreted as a
7522 regular expression. In org-mode files, this will create an `org-occur'
7523 sparse tree. In ordinary files, `occur' will be used to list matches.
7524 If the current buffer is in `dired-mode', grep will be used to search
7525 in all files. If AVOID-POS is given, ignore matches near that position."
7526 (let ((case-fold-search t)
7527 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
7528 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
7529 (append '(("") (" ") ("\t") ("\n"))
7533 (pre nil) (post nil)
7534 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
7536 ;; First check if there are any special
7537 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
7538 ;; Now try the builtin stuff
7540 (goto-char (point-min))
7543 (concat "<<" (regexp-quote s0) ">>") nil t)
7544 (setq type 'dedicated
7545 pos (match-beginning 0))))
7546 ;; There is an exact target for this
7548 ((and (string-match "^(\\(.*\\))$" s0)
7550 (goto-char (point-min))
7553 (concat "[^[]" (regexp-quote
7554 (format org-coderef-label-format
7555 (match-string 1 s0))))
7557 (setq type 'dedicated
7558 pos (1+ (match-beginning 0))))))
7559 ;; There is a coderef target for this
7561 ((string-match "^/\\(.*\\)/$" s)
7562 ;; A regular expression
7565 (org-occur (match-string 1 s)))
7566 ;;((eq major-mode 'dired-mode)
7567 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
7568 (t (org-do-occur (match-string 1 s)))))
7570 ;; A normal search strings
7571 (when (equal (string-to-char s) ?*)
7572 ;; Anchor on headlines, post may include tags.
7573 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
7574 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
7576 (remove-text-properties
7578 '(face nil mouse-face nil keymap nil fontified nil) s)
7579 ;; Make a series of regular expressions to find a match
7580 (setq words (org-split-string s "[ \n\r\t]+")
7582 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
7583 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
7585 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
7586 re2a (concat "[ \t\r\n]" re2a_)
7587 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
7588 re4 (concat "[^a-zA-Z_]" re4_)
7590 re1 (concat pre re2 post)
7591 re3 (concat pre (if pre re4_ re4) post)
7592 re5 (concat pre ".*" re4)
7593 re2 (concat pre re2)
7594 re2a (concat pre (if pre re2a_ re2a))
7595 re4 (concat pre (if pre re4_ re4))
7596 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
7597 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
7601 ((eq type 'org-occur) (org-occur reall))
7602 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
7603 (t (goto-char (point-min))
7605 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
7606 (org-search-not-self 1 re1 nil t)
7607 (org-search-not-self 1 re2 nil t)
7608 (org-search-not-self 1 re2a nil t)
7609 (org-search-not-self 1 re3 nil t)
7610 (org-search-not-self 1 re4 nil t)
7611 (org-search-not-self 1 re5 nil t)
7613 (goto-char (match-beginning 1))
7615 (error "No match")))))
7617 ;; Normal string-search
7618 (goto-char (point-min))
7619 (if (search-forward s nil t)
7620 (goto-char (match-beginning 0))
7621 (error "No match"))))
7622 (and (org-mode-p) (org-show-context 'link-search))
7625 (defun org-search-not-self (group &rest args)
7626 "Execute `re-search-forward', but only accept matches that do not
7627 enclose the position of `org-open-link-marker'."
7628 (let ((m org-open-link-marker))
7630 (while (apply 're-search-forward args)
7631 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
7632 (goto-char (match-end group))
7633 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
7634 (> (match-beginning 0) (marker-position m))
7635 (< (match-end 0) (marker-position m)))
7637 (or (not (org-in-regexp
7638 org-bracket-link-analytic-regexp 1))
7639 (not (match-end 4)) ; no description
7640 (and (<= (match-beginning 4) (point))
7641 (>= (match-end 4) (point))))))
7642 (throw 'exit (point))))))))
7644 (defun org-get-buffer-for-internal-link (buffer)
7645 "Return a buffer to be used for displaying the link target of internal links."
7647 ((not org-display-internal-link-with-indirect-buffer)
7649 ((string-match "(Clone)$" (buffer-name buffer))
7650 (message "Buffer is already a clone, not making another one")
7651 ;; we also do not modify visibility in this case
7653 (t ; make a new indirect buffer for displaying the link
7654 (let* ((bn (buffer-name buffer))
7655 (ibn (concat bn "(Clone)"))
7656 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
7657 (with-current-buffer ib (org-overview))
7660 (defun org-do-occur (regexp &optional cleanup)
7661 "Call the Emacs command `occur'.
7662 If CLEANUP is non-nil, remove the printout of the regular expression
7663 in the *Occur* buffer. This is useful if the regex is long and not useful
7667 (let ((cwin (selected-window)) win beg end)
7668 (when (setq win (get-buffer-window "*Occur*"))
7669 (select-window win))
7670 (goto-char (point-min))
7671 (when (re-search-forward "match[a-z]+" nil t)
7672 (setq beg (match-end 0))
7673 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
7674 (setq end (1- (match-beginning 0)))))
7675 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
7676 (goto-char (point-min))
7677 (select-window cwin))))
7679 ;;; The mark ring for links jumps
7681 (defvar org-mark-ring nil
7682 "Mark ring for positions before jumps in Org-mode.")
7683 (defvar org-mark-ring-last-goto nil
7684 "Last position in the mark ring used to go back.")
7685 ;; Fill and close the ring
7686 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
7687 (loop for i from 1 to org-mark-ring-length do
7688 (push (make-marker) org-mark-ring))
7689 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
7692 (defun org-mark-ring-push (&optional pos buffer)
7693 "Put the current position or POS into the mark ring and rotate it."
7695 (setq pos (or pos (point)))
7696 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
7697 (move-marker (car org-mark-ring)
7699 (or buffer (current-buffer)))
7701 (substitute-command-keys
7702 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
7704 (defun org-mark-ring-goto (&optional n)
7705 "Jump to the previous position in the mark ring.
7706 With prefix arg N, jump back that many stored positions. When
7707 called several times in succession, walk through the entire ring.
7708 Org-mode commands jumping to a different position in the current file,
7709 or to another Org-mode file, automatically push the old position
7713 (if (eq last-command this-command)
7714 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
7715 (setq p org-mark-ring))
7716 (setq org-mark-ring-last-goto p)
7718 (switch-to-buffer (marker-buffer m))
7720 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
7722 (defun org-remove-angle-brackets (s)
7723 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
7724 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
7726 (defun org-add-angle-brackets (s)
7727 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
7728 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
7730 (defun org-remove-double-quotes (s)
7731 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
7732 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
7735 ;;; Following specific links
7737 (defun org-follow-timestamp-link ()
7739 ((org-at-date-range-p t)
7740 (let ((org-agenda-start-on-weekday)
7741 (t1 (match-string 1))
7742 (t2 (match-string 2)))
7743 (setq t1 (time-to-days (org-time-string-to-time t1))
7744 t2 (time-to-days (org-time-string-to-time t2)))
7745 (org-agenda-list nil t1 (1+ (- t2 t1)))))
7746 ((org-at-timestamp-p t)
7747 (org-agenda-list nil (time-to-days (org-time-string-to-time
7748 (substring (match-string 1) 0 10)))
7750 (t (error "This should not happen"))))
7753 ;;; Following file links
7754 (defvar org-wait nil)
7755 (defun org-open-file (path &optional in-emacs line search)
7756 "Open the file at PATH.
7757 First, this expands any special file name abbreviations. Then the
7758 configuration variable `org-file-apps' is checked if it contains an
7759 entry for this file type, and if yes, the corresponding command is launched.
7761 If no application is found, Emacs simply visits the file.
7763 With optional prefix argument IN-EMACS, Emacs will visit the file.
7764 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
7765 and o use an external application to visit the file.
7767 Optional LINE specifies a line to go to, optional SEARCH a string to
7768 search for. If LINE or SEARCH is given, the file will always be
7770 If the file does not exist, an error is thrown."
7771 (setq in-emacs (or in-emacs line search))
7772 (let* ((file (if (equal path "")
7774 (substitute-in-file-name (expand-file-name path))))
7775 (apps (append org-file-apps (org-default-apps)))
7776 (remp (and (assq 'remote apps) (org-file-remote-p file)))
7777 (dirp (if remp nil (file-directory-p file)))
7778 (file (if (and dirp org-open-directory-means-index-dot-org)
7779 (concat (file-name-as-directory file) "index.org")
7781 (a-m-a-p (assq 'auto-mode apps))
7782 (dfile (downcase file))
7783 (old-buffer (current-buffer))
7785 (old-mode major-mode)
7787 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
7788 (setq ext (match-string 1 dfile))
7789 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
7790 (setq ext (match-string 1 dfile))))
7792 ((equal in-emacs '(16))
7793 (setq cmd (cdr (assoc 'system apps))))
7794 (in-emacs (setq cmd 'emacs))
7796 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
7797 (and dirp (cdr (assoc 'directory apps)))
7798 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
7800 (cdr (assoc ext apps))
7801 (cdr (assoc t apps))))))
7802 (when (eq cmd 'system)
7803 (setq cmd (cdr (assoc 'system apps))))
7804 (when (eq cmd 'default)
7805 (setq cmd (cdr (assoc t apps))))
7806 (when (eq cmd 'mailcap)
7808 (mailcap-parse-mailcaps)
7809 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
7810 (command (mailcap-mime-info mime-type)))
7811 (if (stringp command)
7813 (setq cmd 'emacs))))
7814 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
7815 (not (file-exists-p file))
7816 (not org-open-non-existing-files))
7817 (error "No such file: %s" file))
7819 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
7820 ;; Remove quotes around the file name - we'll use shell-quote-argument.
7821 (while (string-match "['\"]%s['\"]" cmd)
7822 (setq cmd (replace-match "%s" t t cmd)))
7823 (while (string-match "%s" cmd)
7824 (setq cmd (replace-match
7826 (shell-quote-argument
7827 (convert-standard-filename file)))
7829 (save-window-excursion
7830 (start-process-shell-command cmd nil cmd)
7831 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
7835 (funcall (cdr (assq 'file org-link-frame-setup)) file)
7837 (if line (goto-line line)
7838 (if search (org-link-search search))))
7840 (let ((file (convert-standard-filename file)))
7842 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
7843 (and (org-mode-p) (eq old-mode 'org-mode)
7844 (or (not (equal old-buffer (current-buffer)))
7845 (not (equal old-pos (point))))
7846 (org-mark-ring-push old-pos old-buffer))))
7848 (defun org-default-apps ()
7849 "Return the default applications for this operating system."
7851 ((eq system-type 'darwin)
7852 org-file-apps-defaults-macosx)
7853 ((eq system-type 'windows-nt)
7854 org-file-apps-defaults-windowsnt)
7855 (t org-file-apps-defaults-gnu)))
7857 (defun org-apps-regexp-alist (list &optional add-auto-mode)
7858 "Convert extensions to regular expressions in the cars of LIST.
7859 Also, weed out any non-string entries, because the return value is used
7860 only for regexp matching.
7861 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
7862 point to the symbol `emacs', indicating that the file should
7863 be opened in Emacs."
7867 (if (not (stringp (car x)))
7869 (if (string-match "\\W" (car x))
7871 (cons (concat "\\." (car x) "\\'") (cdr x)))))
7874 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
7876 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
7877 (defun org-file-remote-p (file)
7878 "Test whether FILE specifies a location on a remote system.
7879 Return non-nil if the location is indeed remote.
7881 For example, the filename \"/user@host:/foo\" specifies a location
7882 on the system \"/user@host:\"."
7883 (cond ((fboundp 'file-remote-p)
7884 (file-remote-p file))
7885 ((fboundp 'tramp-handle-file-remote-p)
7886 (tramp-handle-file-remote-p file))
7887 ((and (boundp 'ange-ftp-name-format)
7888 (string-match (car ange-ftp-name-format) file))
7895 (defun org-get-org-file ()
7896 "Read a filename, with default directory `org-directory'."
7897 (let ((default (or org-default-notes-file remember-data-file)))
7898 (read-file-name (format "File name [%s]: " default)
7899 (file-name-as-directory org-directory)
7902 (defun org-notes-order-reversed-p ()
7903 "Check if the current file should receive notes in reversed order."
7905 ((not org-reverse-note-order) nil)
7906 ((eq t org-reverse-note-order) t)
7907 ((not (listp org-reverse-note-order)) nil)
7909 (let ((all org-reverse-note-order)
7911 (while (setq entry (pop all))
7912 (if (string-match (car entry) buffer-file-name)
7913 (throw 'exit (cdr entry))))
7916 (defvar org-refile-target-table nil
7917 "The list of refile targets, created by `org-refile'.")
7919 (defvar org-agenda-new-buffers nil
7920 "Buffers created to visit agenda files.")
7922 (defun org-get-refile-targets (&optional default-buffer)
7923 "Produce a table with refile targets."
7924 (let ((entries (or org-refile-targets '((nil . (:level . 1)))))
7925 targets txt re files f desc descre fast-path-p level)
7926 (message "Getting targets...")
7927 (with-current-buffer (or default-buffer (current-buffer))
7928 (while (setq entry (pop entries))
7929 (setq files (car entry) desc (cdr entry))
7930 (setq fast-path-p nil)
7932 ((null files) (setq files (list (current-buffer))))
7933 ((eq files 'org-agenda-files)
7934 (setq files (org-agenda-files 'unrestricted)))
7935 ((and (symbolp files) (fboundp files))
7936 (setq files (funcall files)))
7937 ((and (symbolp files) (boundp files))
7938 (setq files (symbol-value files))))
7939 (if (stringp files) (setq files (list files)))
7941 ((eq (car desc) :tag)
7942 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
7943 ((eq (car desc) :todo)
7944 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
7945 ((eq (car desc) :regexp)
7946 (setq descre (cdr desc)))
7947 ((eq (car desc) :level)
7948 (setq descre (concat "^\\*\\{" (number-to-string
7949 (if org-odd-levels-only
7950 (1- (* 2 (cdr desc)))
7953 ((eq (car desc) :maxlevel)
7954 (setq fast-path-p t)
7955 (setq descre (concat "^\\*\\{1," (number-to-string
7956 (if org-odd-levels-only
7957 (1- (* 2 (cdr desc)))
7960 (t (error "Bad refiling target description %s" desc)))
7961 (while (setq f (pop files))
7963 (set-buffer (if (bufferp f) f (org-get-agenda-file-buffer f)))
7964 (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
7965 (setq f (expand-file-name f))
7969 (goto-char (point-min))
7970 (while (re-search-forward descre nil t)
7971 (goto-char (point-at-bol))
7972 (when (looking-at org-complex-heading-regexp)
7973 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
7974 txt (org-link-display-format (match-string 4))
7975 re (concat "^" (regexp-quote
7976 (buffer-substring (match-beginning 1)
7978 (if (match-end 5) (setq re (concat re "[ \t]+"
7980 (match-string 5)))))
7981 (setq re (concat re "[ \t]*$"))
7982 (when org-refile-use-outline-path
7983 (setq txt (mapconcat 'org-protect-slash
7985 (if (eq org-refile-use-outline-path 'file)
7986 (list (file-name-nondirectory
7987 (buffer-file-name (buffer-base-buffer))))
7988 (if (eq org-refile-use-outline-path 'full-file-path)
7989 (list (buffer-file-name (buffer-base-buffer)))))
7990 (org-get-outline-path fast-path-p level txt)
7993 (push (list txt f re (point)) targets))
7994 (goto-char (point-at-eol))))))))
7995 (message "Getting targets...done")
7996 (nreverse targets))))
7998 (defun org-protect-slash (s)
7999 (while (string-match "/" s)
8000 (setq s (replace-match "\\" t t s)))
8003 (defvar org-olpa (make-vector 20 nil))
8005 (defun org-get-outline-path (&optional fastp level heading)
8006 "Return the outline path to the current entry, as a list."
8010 (error "Outline path failure, more than 19 levels."))
8011 (loop for i from level upto 19 do
8012 (aset org-olpa i nil))
8014 (delq nil (append org-olpa nil))
8015 (aset org-olpa level heading)))
8018 (while (org-up-heading-safe)
8019 (when (looking-at org-complex-heading-regexp)
8020 (push (org-match-string-no-properties 4) rtn)))
8023 (defvar org-refile-history nil
8024 "History for refiling operations.")
8026 (defun org-refile (&optional goto default-buffer)
8027 "Move the entry at point to another heading.
8028 The list of target headings is compiled using the information in
8029 `org-refile-targets', which see. This list is created before each use
8030 and will therefore always be up-to-date.
8032 At the target location, the entry is filed as a subitem of the target heading.
8033 Depending on `org-reverse-note-order', the new subitem will either be the
8034 first or the last subitem.
8036 If there is an active region, all entries in that region will be moved.
8037 However, the region must fulfil the requirement that the first heading
8038 is the first one sets the top-level of the moved text - at most siblings
8039 below it are allowed.
8041 With prefix arg GOTO, the command will only visit the target location,
8042 not actually move anything.
8043 With a double prefix `C-u C-u', go to the location where the last refiling
8044 operation has put the subtree."
8046 (let* ((cbuf (current-buffer))
8047 (regionp (org-region-active-p))
8048 (region-start (and regionp (region-beginning)))
8049 (region-end (and regionp (region-end)))
8050 (region-length (and regionp (- region-end region-start)))
8051 (filename (buffer-file-name (buffer-base-buffer cbuf)))
8052 pos it nbuf file re level reversed)
8053 (when regionp (goto-char region-start)
8054 (unless (org-kill-is-subtree-p
8055 (buffer-substring region-start region-end))
8056 (error "The region is not a (sequence of) subtree(s)")))
8057 (if (equal goto '(16))
8058 (org-refile-goto-last-stored)
8059 (when (setq it (org-refile-get-location
8060 (if goto "Goto: " "Refile to: ") default-buffer))
8061 (setq file (nth 1 it)
8064 (if (and (equal (buffer-file-name) file)
8066 (and (>= pos region-start)
8067 (<= pos region-end))
8068 (and (>= pos (point))
8069 (< pos (save-excursion
8070 (org-end-of-subtree t t))))))
8071 (error "Cannot refile to position inside the tree or region"))
8073 (setq nbuf (or (find-buffer-visiting file)
8074 (find-file-noselect file)))
8077 (switch-to-buffer nbuf)
8079 (org-show-context 'org-goto))
8082 (kill-new (buffer-substring region-start region-end))
8083 (org-save-markers-in-region region-start region-end))
8084 (org-copy-subtree 1 nil t))
8086 (set-buffer (setq nbuf (or (find-buffer-visiting file)
8087 (find-file-noselect file))))
8088 (setq reversed (org-notes-order-reversed-p))
8093 (looking-at outline-regexp)
8094 (setq level (org-get-valid-level (funcall outline-level) 1))
8097 (or (outline-next-heading) (point-max))
8098 (or (save-excursion (outline-get-next-sibling))
8099 (org-end-of-subtree t t)
8101 (if (not (bolp)) (newline))
8102 (bookmark-set "org-refile-last-stored")
8103 (org-paste-subtree level))))
8105 (delete-region (point) (+ (point) region-length))
8107 (setq org-markers-to-move nil)
8108 (message "Refiled to \"%s\"" (car it)))))))
8110 (defun org-refile-goto-last-stored ()
8111 "Go to the location where the last refile was stored."
8113 (bookmark-jump "org-refile-last-stored")
8114 (message "This is the location of the last refile"))
8116 (defun org-refile-get-location (&optional prompt default-buffer)
8117 "Prompt the user for a refile location, using PROMPT."
8118 (let ((org-refile-targets org-refile-targets)
8119 (org-refile-use-outline-path org-refile-use-outline-path))
8120 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
8121 (unless org-refile-target-table
8122 (error "No refile targets"))
8123 (let* ((cbuf (current-buffer))
8124 (partial-completion-mode nil)
8125 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
8126 (cfunc (if (and org-refile-use-outline-path
8127 org-outline-path-complete-in-steps)
8128 'org-olpath-completing-read
8129 'org-ido-completing-read))
8130 (extra (if org-refile-use-outline-path "/" ""))
8131 (filename (and cfn (expand-file-name cfn)))
8134 (if (not (equal filename (nth 1 x)))
8135 (cons (concat (car x) extra " ("
8136 (file-name-nondirectory (nth 1 x)) ")")
8138 (cons (concat (car x) extra) (cdr x))))
8139 org-refile-target-table))
8140 (completion-ignore-case t))
8141 (assoc (funcall cfunc prompt tbl nil t nil 'org-refile-history)
8144 (defun org-olpath-completing-read (prompt collection &rest args)
8145 "Read an outline path like a file name."
8146 (let ((thetable collection)
8147 (org-completion-use-ido nil)) ; does not work with ido.
8149 'org-ido-completing-read prompt
8150 (lambda (string predicate &optional flag)
8151 (let (rtn r f (l (length string)))
8155 (try-completion string thetable))
8158 (setq rtn (all-completions string thetable predicate))
8161 (setq r (substring x l))
8162 (if (string-match " ([^)]*)$" x)
8163 (setq f (match-string 0 x))
8165 (if (string-match "/" r)
8166 (concat string (substring r 0 (match-end 0)) f)
8171 (assoc string thetable)))
8177 (defun org-find-dblock (name)
8178 "Find the first dynamic block with name NAME in the buffer.
8179 If not found, stay at current position and return nil."
8182 (goto-char (point-min))
8183 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
8185 (match-beginning 0))))
8186 (if pos (goto-char pos))
8189 (defconst org-dblock-start-re
8190 "^#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
8191 "Matches the startline of a dynamic block, with parameters.")
8193 (defconst org-dblock-end-re "^#\\+END\\([: \t\r\n]\\|$\\)"
8194 "Matches the end of a dynamic block.")
8196 (defun org-create-dblock (plist)
8197 "Create a dynamic block section, with parameters taken from PLIST.
8198 PLIST must contain a :name entry which is used as name of the block."
8199 (unless (bolp) (newline))
8200 (let ((name (plist-get plist :name)))
8201 (insert "#+BEGIN: " name)
8203 (if (eq (car plist) :name)
8204 (setq plist (cddr plist))
8205 (insert " " (prin1-to-string (pop plist)))))
8206 (insert "\n\n#+END:\n")
8207 (beginning-of-line -2)))
8209 (defun org-prepare-dblock ()
8210 "Prepare dynamic block for refresh.
8211 This empties the block, puts the cursor at the insert position and returns
8212 the property list including an extra property :name with the block name."
8213 (unless (looking-at org-dblock-start-re)
8214 (error "Not at a dynamic block"))
8215 (let* ((begdel (1+ (match-end 0)))
8216 (name (org-no-properties (match-string 1)))
8217 (params (append (list :name name)
8218 (read (concat "(" (match-string 3) ")")))))
8219 (unless (re-search-forward org-dblock-end-re nil t)
8220 (error "Dynamic block not terminated"))
8223 (list :content (buffer-substring
8224 begdel (match-beginning 0)))))
8225 (delete-region begdel (match-beginning 0))
8230 (defun org-map-dblocks (&optional command)
8231 "Apply COMMAND to all dynamic blocks in the current buffer.
8232 If COMMAND is not given, use `org-update-dblock'."
8233 (let ((cmd (or command 'org-update-dblock))
8236 (goto-char (point-min))
8237 (while (re-search-forward org-dblock-start-re nil t)
8238 (goto-char (setq pos (match-beginning 0)))
8241 (error (message "Error during update of dynamic block")))
8243 (unless (re-search-forward org-dblock-end-re nil t)
8244 (error "Dynamic block not terminated"))))))
8246 (defun org-dblock-update (&optional arg)
8247 "User command for updating dynamic blocks.
8248 Update the dynamic block at point. With prefix ARG, update all dynamic
8249 blocks in the buffer."
8252 (org-update-all-dblocks)
8253 (or (looking-at org-dblock-start-re)
8254 (org-beginning-of-dblock))
8255 (org-update-dblock)))
8257 (defun org-update-dblock ()
8258 "Update the dynamic block at point
8259 This means to empty the block, parse for parameters and then call
8260 the correct writing function."
8261 (save-window-excursion
8262 (let* ((pos (point))
8263 (line (org-current-line))
8264 (params (org-prepare-dblock))
8265 (name (plist-get params :name))
8266 (cmd (intern (concat "org-dblock-write:" name))))
8267 (message "Updating dynamic block `%s' at line %d..." name line)
8268 (funcall cmd params)
8269 (message "Updating dynamic block `%s' at line %d...done" name line)
8272 (defun org-beginning-of-dblock ()
8273 "Find the beginning of the dynamic block at point.
8274 Error if there is no such block at point."
8278 (if (and (re-search-backward org-dblock-start-re nil t)
8279 (setq beg (match-beginning 0))
8280 (re-search-forward org-dblock-end-re nil t)
8281 (> (match-end 0) pos))
8284 (error "Not in a dynamic block"))))
8286 (defun org-update-all-dblocks ()
8287 "Update all dynamic blocks in the buffer.
8288 This function can be used in a hook."
8290 (org-map-dblocks 'org-update-dblock)))
8295 (defconst org-additional-option-like-keywords
8296 '("BEGIN_HTML" "BEGIN_LaTeX" "END_HTML" "END_LaTeX"
8297 "ORGTBL" "HTML:" "LaTeX:" "BEGIN:" "END:" "TBLFM"
8298 "BEGIN_EXAMPLE" "END_EXAMPLE"
8299 "BEGIN_QUOTE" "END_QUOTE"
8300 "BEGIN_VERSE" "END_VERSE"
8301 "BEGIN_SRC" "END_SRC"
8302 "CAPTION" "LABEL" "ATTR_HTML" "ATTR_LaTeX"))
8304 (defcustom org-structure-template-alist
8306 ("s" "#+begin_src ?\n\n#+end_src"
8307 "<src lang=\"?\">\n\n</src>")
8308 ("e" "#+begin_example\n?\n#+end_example"
8309 "<example>\n?\n</example>")
8310 ("q" "#+begin_quote\n?\n#+end_quote"
8311 "<quote>\n?\n</quote>")
8312 ("v" "#+begin_verse\n?\n#+end_verse"
8313 "<verse>\n?\n/verse>")
8314 ("l" "#+begin_latex\n?\n#+end_latex"
8315 "<literal style=\"latex\">\n?\n</literal>")
8317 "<literal style=\"latex\">?</literal>")
8318 ("h" "#+begin_html\n?\n#+end_html"
8319 "<literal style=\"html\">\n?\n</literal>")
8321 "<literal style=\"html\">?</literal>")
8322 ("a" "#+begin_ascii\n?\n#+end_ascii")
8324 ("i" "#+include %file ?"
8325 "<include file=%file markup=\"?\">")
8327 "Structure completion elements.
8328 This is a list of abbreviation keys and values. The value gets inserted
8329 it you type @samp{.} followed by the key and then the completion key,
8330 usually `M-TAB'. %file will be replaced by a file name after prompting
8331 for the file using completion.
8332 There are two templates for each key, the first uses the original Org syntax,
8333 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
8334 the default when the /org-mtags.el/ module has been loaded. See also the
8335 variable `org-mtags-prefer-muse-templates'.
8336 This is an experimental feature, it is undecided if it is going to stay in."
8337 :group 'org-completion
8340 (string :tag "Template")
8341 (string :tag "Muse Template")))
8343 (defun org-try-structure-completion ()
8344 "Try to complete a structure template before point.
8345 This looks for strings like \"<e\" on an otherwise empty line and
8347 (let ((l (buffer-substring (point-at-bol) (point)))
8349 (when (and (looking-at "[ \t]*$")
8350 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
8351 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
8352 (org-complete-expand-structure-template (+ -1 (point-at-bol)
8353 (match-beginning 1)) a)
8356 (defun org-complete-expand-structure-template (start cell)
8357 "Expand a structure template."
8358 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
8359 (rpl (nth (if musep 2 1) cell)))
8360 (delete-region start (point))
8361 (when (string-match "\\`#\\+" rpl)
8364 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
8365 (delete-region (point-at-bol) (point)))
8367 (setq start (point))
8368 (if (string-match "%file" rpl)
8369 (setq rpl (replace-match
8373 (abbreviate-file-name (read-file-name "Include file: ")))
8377 (if (re-search-backward "\\?" start t) (delete-char 1))))
8380 (defun org-complete (&optional arg)
8381 "Perform completion on word at point.
8382 At the beginning of a headline, this completes TODO keywords as given in
8383 `org-todo-keywords'.
8384 If the current word is preceded by a backslash, completes the TeX symbols
8385 that are supported for HTML support.
8386 If the current word is preceded by \"#+\", completes special words for
8387 setting file options.
8388 In the line after \"#+STARTUP:, complete valid keywords.\"
8389 At all other locations, this simply calls the value of
8390 `org-completion-fallback-command'."
8392 (org-without-partial-completion
8396 (beg1 (save-excursion
8397 (skip-chars-backward (org-re "[:alnum:]_@"))
8399 (beg (save-excursion
8400 (skip-chars-backward "a-zA-Z0-9_:$")
8402 (confirm (lambda (x) (stringp (car x))))
8403 (searchhead (equal (char-before beg) ?*))
8405 (when (and (member (char-before beg1) '(?. ?<))
8406 (setq a (assoc (buffer-substring beg1 (point))
8407 org-structure-template-alist)))
8408 (org-complete-expand-structure-template (1- beg1) a)
8410 (tag (and (equal (char-before beg1) ?:)
8411 (equal (char-after (point-at-bol)) ?*)))
8412 (prop (and (equal (char-before beg1) ?:)
8413 (not (equal (char-after (point-at-bol)) ?*))))
8414 (texp (equal (char-before beg) ?\\))
8415 (link (equal (char-before beg) ?\[))
8416 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
8419 (startup (string-match "^#\\+STARTUP:.*"
8420 (buffer-substring (point-at-bol) (point))))
8421 (completion-ignore-case opt)
8431 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8432 (cons (match-string 2 x) (match-string 1 x)))
8433 (org-split-string (org-get-current-options) "\n"))
8434 (mapcar 'list org-additional-option-like-keywords)))
8436 (setq type :startup)
8437 org-startup-options)
8438 (link (append org-link-abbrev-alist-local
8439 org-link-abbrev-alist))
8443 ((string-match "\\`\\*+[ \t]+\\'"
8444 (buffer-substring (point-at-bol) beg))
8446 (mapcar 'list org-todo-keywords-1))
8448 (setq type :searchhead)
8450 (goto-char (point-min))
8451 (while (re-search-forward org-todo-line-regexp nil t)
8453 (org-make-org-heading-search-string
8454 (match-string 3) t))
8457 (tag (setq type :tag beg beg1)
8458 (or org-tag-alist (org-get-buffer-tags)))
8459 (prop (setq type :prop beg beg1)
8460 (mapcar 'list (org-buffer-property-keys nil t t)))
8462 (call-interactively org-completion-fallback-command)
8463 (throw 'exit nil)))))
8464 (pattern (buffer-substring-no-properties beg end))
8465 (completion (try-completion pattern table confirm)))
8466 (cond ((eq completion t)
8467 (if (not (assoc (upcase pattern) table))
8468 (message "Already complete")
8469 (if (and (equal type :opt)
8470 (not (member (car (assoc (upcase pattern) table))
8471 org-additional-option-like-keywords)))
8472 (insert (substring (cdr (assoc (upcase pattern) table))
8474 (if (memq type '(:tag :prop)) (insert ":")))))
8476 (message "Can't find completion for \"%s\"" pattern)
8478 ((not (string= pattern completion))
8479 (delete-region beg end)
8480 (if (string-match " +$" completion)
8481 (setq completion (replace-match "" t t completion)))
8483 (if (get-buffer-window "*Completions*")
8484 (delete-window (get-buffer-window "*Completions*")))
8485 (if (assoc completion table)
8486 (if (eq type :todo) (insert " ")
8487 (if (memq type '(:tag :prop)) (insert ":"))))
8488 (if (and (equal type :opt) (assoc completion table))
8489 (message "%s" (substitute-command-keys
8490 "Press \\[org-complete] again to insert example settings"))))
8492 (message "Making completion list...")
8493 (let ((list (sort (all-completions pattern table confirm)
8495 (with-output-to-temp-buffer "*Completions*"
8497 ;; Protection needed for XEmacs and emacs 21
8498 (display-completion-list list pattern)
8499 (error (display-completion-list list)))))
8500 (message "Making completion list...%s" "done")))))))
8502 ;;;; TODO, DEADLINE, Comments
8504 (defun org-toggle-comment ()
8505 "Change the COMMENT state of an entry."
8508 (org-back-to-heading)
8509 (let (case-fold-search)
8510 (if (looking-at (concat outline-regexp
8511 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
8512 (replace-match "" t t nil 1)
8513 (if (looking-at outline-regexp)
8515 (goto-char (match-end 0))
8516 (insert org-comment-string " ")))))))
8518 (defvar org-last-todo-state-is-todo nil
8519 "This is non-nil when the last TODO state change led to a TODO state.
8520 If the last change removed the TODO tag or switched to DONE, then
8523 (defvar org-setting-tags nil) ; dynamically skipped
8525 (defun org-parse-local-options (string var)
8526 "Parse STRING for startup setting relevant for variable VAR."
8527 (let ((rtn (symbol-value var))
8530 (if (or (not string) (not (string-match "\\S-" string)))
8532 (setq opts (delq nil (mapcar (lambda (x)
8533 (setq e (assoc x org-startup-options))
8534 (if (eq (nth 1 e) var) e nil))
8535 (org-split-string string "[ \t]+"))))
8539 (while (setq e (pop opts))
8541 (setq rtn (nth 2 e))
8542 (if (not (listp rtn)) (setq rtn nil))
8543 (push (nth 2 e) rtn)))
8546 (defvar org-todo-setup-filter-hook nil
8547 "Hook for functions that pre-filter todo specs.
8549 Each function takes a todo spec and returns either `nil' or the spec
8550 transformed into canonical form." )
8552 (defvar org-todo-get-default-hook nil
8553 "Hook for functions that get a default item for todo.
8555 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
8556 `nil' or a string to be used for the todo mark." )
8558 (defvar org-agenda-headline-snapshot-before-repeat)
8559 (defun org-todo (&optional arg)
8560 "Change the TODO state of an item.
8561 The state of an item is given by a keyword at the start of the heading,
8563 *** TODO Write paper
8566 The different keywords are specified in the variable `org-todo-keywords'.
8567 By default the available states are \"TODO\" and \"DONE\".
8568 So for this example: when the item starts with TODO, it is changed to DONE.
8569 When it starts with DONE, the DONE is removed. And when neither TODO nor
8570 DONE are present, add TODO at the beginning of the heading.
8572 With C-u prefix arg, use completion to determine the new state.
8573 With numeric prefix arg, switch to that state.
8574 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
8575 With a tripple C-u prefix, circumvent any state blocking.
8577 For calling through lisp, arg is also interpreted in the following way:
8578 'none -> empty state
8579 \"\"(empty string) -> switch to empty state
8580 'done -> switch to DONE
8581 'nextset -> switch to the next set of keywords
8582 'previousset -> switch to the previous set of keywords
8583 \"WAITING\" -> switch to the specified keyword, but only if it
8584 really is a member of `org-todo-keywords'."
8586 (if (equal arg '(16)) (setq arg 'nextset))
8587 (let ((org-blocker-hook org-blocker-hook))
8588 (when (equal arg '(64))
8589 (setq arg nil org-blocker-hook nil))
8592 (org-back-to-heading)
8593 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
8594 (or (looking-at (concat " +" org-todo-regexp " *"))
8596 (let* ((match-data (match-data))
8597 (startpos (point-at-bol))
8598 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
8599 (org-log-done org-log-done)
8600 (org-log-repeat org-log-repeat)
8601 (org-todo-log-states org-todo-log-states)
8602 (this (match-string 1))
8603 (hl-pos (match-beginning 0))
8604 (head (org-get-todo-sequence-head this))
8605 (ass (assoc head org-todo-kwd-alist))
8606 (interpret (nth 1 ass))
8607 (done-word (nth 3 ass))
8608 (final-done-word (nth 4 ass))
8609 (last-state (or this ""))
8610 (completion-ignore-case t)
8611 (member (member this org-todo-keywords-1))
8614 ((and org-todo-key-trigger
8615 (or (and (equal arg '(4))
8616 (eq org-use-fast-todo-selection 'prefix))
8617 (and (not arg) org-use-fast-todo-selection
8618 (not (eq org-use-fast-todo-selection
8620 ;; Use fast selection
8621 (org-fast-todo-selection))
8622 ((and (equal arg '(4))
8623 (or (not org-use-fast-todo-selection)
8624 (not org-todo-key-trigger)))
8625 ;; Read a state with completion
8626 (org-ido-completing-read
8627 "State: " (mapcar (lambda(x) (list x))
8628 org-todo-keywords-1)
8632 (if tail (car tail) nil)
8633 (car org-todo-keywords-1)))
8635 (if (equal member org-todo-keywords-1)
8638 (nth (- (length org-todo-keywords-1)
8640 org-todo-keywords-1)
8641 (org-last org-todo-keywords-1))))
8642 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
8643 (setq arg nil))) ; hack to fall back to cycling
8645 ;; user or caller requests a specific state
8647 ((equal arg "") nil)
8648 ((eq arg 'none) nil)
8649 ((eq arg 'done) (or done-word (car org-done-keywords)))
8651 (or (car (cdr (member head org-todo-heads)))
8652 (car org-todo-heads)))
8653 ((eq arg 'previousset)
8654 (let ((org-todo-heads (reverse org-todo-heads)))
8655 (or (car (cdr (member head org-todo-heads)))
8656 (car org-todo-heads))))
8657 ((car (member arg org-todo-keywords-1)))
8658 ((nth (1- (prefix-numeric-value arg))
8659 org-todo-keywords-1))))
8660 ((null member) (or head (car org-todo-keywords-1)))
8661 ((equal this final-done-word) nil) ;; -> make empty
8662 ((null tail) nil) ;; -> first entry
8663 ((memq interpret '(type priority))
8664 (if (eq this-command last-command)
8666 (if (> (length tail) 0)
8667 (or done-word (car org-done-keywords))
8672 (run-hook-with-args-until-success
8673 'org-todo-get-default-hook state last-state)
8675 (next (if state (concat " " state " ") " "))
8676 (change-plist (list :type 'todo-state-change :from this :to state
8677 :position startpos))
8679 (when org-blocker-hook
8680 (setq org-last-todo-state-is-todo
8681 (not (member this org-done-keywords)))
8682 (unless (save-excursion
8684 (run-hook-with-args-until-failure
8685 'org-blocker-hook change-plist)))
8687 (error "TODO state change from %s to %s blocked" this state)
8689 (message "TODO state change from %s to %s blocked" this state)
8690 (throw 'exit nil))))
8691 (store-match-data match-data)
8692 (replace-match next t t)
8693 (unless (pos-visible-in-window-p hl-pos)
8694 (message "TODO state changed to %s" (org-trim next)))
8696 (setq head (org-get-todo-sequence-head state)
8697 ass (assoc head org-todo-kwd-alist)
8698 interpret (nth 1 ass)
8699 done-word (nth 3 ass)
8700 final-done-word (nth 4 ass)))
8701 (when (memq arg '(nextset previousset))
8702 (message "Keyword-Set %d/%d: %s"
8703 (- (length org-todo-sets) -1
8704 (length (memq (assoc state org-todo-sets) org-todo-sets)))
8705 (length org-todo-sets)
8706 (mapconcat 'identity (assoc state org-todo-sets) " ")))
8707 (setq org-last-todo-state-is-todo
8708 (not (member state org-done-keywords)))
8709 (setq now-done-p (and (member state org-done-keywords)
8710 (not (member this org-done-keywords))))
8711 (and logging (org-local-logging logging))
8712 (when (and (or org-todo-log-states org-log-done)
8713 (not (memq arg '(nextset previousset))))
8714 ;; we need to look at recording a time and note
8715 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
8716 (nth 2 (assoc this org-todo-log-states))))
8718 (member state org-not-done-keywords)
8719 (not (member this org-not-done-keywords)))
8720 ;; This is now a todo state and was not one before
8721 ;; If there was a CLOSED time stamp, get rid of it.
8722 (org-add-planning-info nil nil 'closed))
8723 (when (and now-done-p org-log-done)
8724 ;; It is now done, and it was not done before
8725 (org-add-planning-info 'closed (org-current-time))
8726 (if (and (not dolog) (eq 'note org-log-done))
8727 (org-add-log-setup 'done state this 'findpos 'note)))
8728 (when (and state dolog)
8729 ;; This is a non-nil state, and we need to log it
8730 (org-add-log-setup 'state state this 'findpos dolog)))
8731 ;; Fixup tag positioning
8732 (org-todo-trigger-tag-changes state)
8733 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
8734 (when org-provide-todo-statistics
8735 (org-update-parent-todo-statistics))
8736 (run-hooks 'org-after-todo-state-change-hook)
8737 (if (and arg (not (member state org-done-keywords)))
8738 (setq head (org-get-todo-sequence-head state)))
8739 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
8740 ;; Do we need to trigger a repeat?
8742 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
8743 ;; This is for the agenda, take a snapshot of the headline.
8745 (setq org-agenda-headline-snapshot-before-repeat
8746 (org-get-heading))))
8747 (org-auto-repeat-maybe state))
8748 ;; Fixup cursor location if close to the keyword
8749 (if (and (outline-on-heading-p)
8751 (save-excursion (beginning-of-line 1)
8752 (looking-at org-todo-line-regexp))
8753 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
8755 (goto-char (or (match-end 2) (match-end 1)))
8757 (when org-trigger-hook
8759 (run-hook-with-args 'org-trigger-hook change-plist))))))))
8761 (defun org-block-todo-from-children-or-siblings (change-plist)
8762 "Block turning an entry into a TODO, using the hierarchy.
8763 This checks whether the current task should be blocked from state
8764 changes. Such blocking occurs when:
8766 1. The task has children which are not all in a completed state.
8768 2. A task has a parent with the property :ORDERED:, and there
8769 are siblings prior to the current task with incomplete
8772 ;; If this is not a todo state change, or if this entry is already DONE,
8774 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
8775 (member (plist-get change-plist :from)
8776 (cons 'done org-done-keywords))
8777 (member (plist-get change-plist :to)
8778 (cons 'todo org-not-done-keywords)))
8779 (throw 'dont-block t))
8780 ;; If this task has children, and any are undone, it's blocked
8782 (org-back-to-heading t)
8783 (let ((this-level (funcall outline-level)))
8784 (outline-next-heading)
8785 (let ((child-level (funcall outline-level)))
8786 (while (and (not (eobp))
8787 (> child-level this-level))
8788 ;; this todo has children, check whether they are all
8790 (if (and (not (org-entry-is-done-p))
8791 (org-entry-is-todo-p))
8792 (throw 'dont-block nil))
8793 (outline-next-heading)
8794 (setq child-level (funcall outline-level))))))
8795 ;; Otherwise, if the task's parent has the :ORDERED: property, and
8796 ;; any previous siblings are undone, it's blocked
8798 (org-back-to-heading t)
8799 (when (save-excursion
8801 (org-up-heading-all 1)
8802 (org-entry-get (point) "ORDERED")))
8803 (let* ((this-level (funcall outline-level))
8804 (current-level this-level))
8805 (while (and (not (bobp))
8806 (= current-level this-level))
8807 (outline-previous-heading)
8808 (setq current-level (funcall outline-level))
8809 (if (= current-level this-level)
8810 ;; this todo has children, check whether they are all
8812 (if (and (not (org-entry-is-done-p))
8813 (org-entry-is-todo-p))
8814 (throw 'dont-block nil)))))))
8817 (defcustom org-track-ordered-property-with-tag nil
8818 "Should the ORDERED property also be shown as a tag?
8819 The ORDERED property decides if an entry should require subtasks to be
8820 completed in sequence. Since a property is not very visible, setting
8821 this option means that toggling the ORDERED property with the command
8822 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
8823 not relevant for the behavior, but it makes things more visible.
8825 Note that toggling the tag with tags commands will not change the property
8826 and therefore not influence behavior!
8828 This can be t, meaning the tag ORDERED should be used, It can also be a
8829 string to select a different tag for this task."
8832 (const :tag "No tracking" nil)
8833 (const :tag "Track with ORDERED tag" t)
8834 (string :tag "Use other tag")))
8836 (defun org-toggle-ordered-property ()
8837 "Toggle the ORDERED property of the current entry.
8838 For better visibility, you can track the value of this property with a tag.
8839 See variable `org-track-ordered-property-with-tag'."
8841 (let* ((t1 org-track-ordered-property-with-tag)
8842 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
8844 (org-back-to-heading)
8845 (if (org-entry-get nil "ORDERED")
8847 (org-delete-property "ORDERED")
8848 (and tag (org-toggle-tag tag 'off))
8849 (message "Subtasks can be completed in arbitrary order"))
8850 (org-entry-put nil "ORDERED" "t")
8851 (and tag (org-toggle-tag tag 'on))
8852 (message "Subtasks must be completed in sequence")))))
8854 (defvar org-blocked-by-checkboxes) ; dynamically scoped
8855 (defun org-block-todo-from-checkboxes (change-plist)
8856 "Block turning an entry into a TODO, using checkboxes.
8857 This checks whether the current task should be blocked from state
8858 changes because there are uncheckd boxes in this entry."
8860 ;; If this is not a todo state change, or if this entry is already DONE,
8862 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
8863 (member (plist-get change-plist :from)
8864 (cons 'done org-done-keywords))
8865 (member (plist-get change-plist :to)
8866 (cons 'todo org-not-done-keywords)))
8867 (throw 'dont-block t))
8868 ;; If this task has checkboxes that are not checked, it's blocked
8870 (org-back-to-heading t)
8871 (let ((beg (point)) end)
8872 (outline-next-heading)
8875 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
8878 (if (boundp 'org-blocked-by-checkboxes)
8879 (setq org-blocked-by-checkboxes t))
8880 (throw 'dont-block nil)))))
8883 (defun org-update-parent-todo-statistics ()
8884 "Update any statistics cookie in the parent of the current headline."
8886 (let ((box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
8887 level (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
8890 (setq level (org-up-heading-safe))
8893 (while (re-search-forward box-re (point-at-eol) t)
8894 (setq cnt-all 0 cnt-done 0 cookie-present t)
8895 (setq is-percent (match-end 2))
8897 (unless (outline-next-heading) (throw 'exit nil))
8898 (while (looking-at org-todo-line-regexp)
8899 (setq kwd (match-string 2))
8900 (and kwd (setq cnt-all (1+ cnt-all)))
8901 (and (member kwd org-done-keywords)
8902 (setq cnt-done (1+ cnt-done)))
8904 (org-forward-same-level 1)
8905 (error (end-of-line 1)))))
8908 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
8909 (format "[%d/%d]" cnt-done cnt-all))))
8910 (when cookie-present
8911 (run-hook-with-args 'org-after-todo-statistics-hook
8912 cnt-done (- cnt-all cnt-done)))))))
8914 (defvar org-after-todo-statistics-hook nil
8915 "Hook that is called after a TODO statistics cookie has been updated.
8916 Each function is called with two arguments: the number of not-done entries
8917 and the number of done entries.
8919 For example, the following function, when added to this hook, will switch
8920 an entry to DONE when all children are done, and back to TODO when new
8921 entries are set to a TODO status. Note that this hook is only called
8922 when there is a statistics cookie in the headline!
8924 (defun org-summary-todo (n-done n-not-done)
8925 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
8926 (let (org-log-done org-log-states) ; turn off logging
8927 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
8930 (defun org-todo-trigger-tag-changes (state)
8931 "Apply the changes defined in `org-todo-state-tags-triggers'."
8932 (let ((l org-todo-state-tags-triggers)
8934 (when (or (not state) (equal state ""))
8935 (setq changes (append changes (cdr (assoc "" l)))))
8936 (when (and (stringp state) (> (length state) 0))
8937 (setq changes (append changes (cdr (assoc state l)))))
8938 (when (member state org-not-done-keywords)
8939 (setq changes (append changes (cdr (assoc 'todo l)))))
8940 (when (member state org-done-keywords)
8941 (setq changes (append changes (cdr (assoc 'done l)))))
8943 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
8945 (defun org-local-logging (value)
8946 "Get logging settings from a property VALUE."
8948 ;; directly set the variables, they are already local.
8949 (setq org-log-done nil
8951 org-todo-log-states nil)
8952 (setq words (org-split-string value))
8953 (while (setq w (pop words))
8955 ((setq a (assoc w org-startup-options))
8956 (and (member (nth 1 a) '(org-log-done org-log-repeat))
8957 (set (nth 1 a) (nth 2 a))))
8958 ((setq a (org-extract-log-state-settings w))
8959 (and (member (car a) org-todo-keywords-1)
8960 (push a org-todo-log-states)))))))
8962 (defun org-get-todo-sequence-head (kwd)
8963 "Return the head of the TODO sequence to which KWD belongs.
8964 If KWD is not set, check if there is a text property remembering the
8969 (or (get-text-property (point-at-bol) 'org-todo-head)
8971 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
8972 nil (point-at-eol)))
8973 (get-text-property p 'org-todo-head))))
8974 ((not (member kwd org-todo-keywords-1))
8975 (car org-todo-keywords-1))
8976 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
8978 (defun org-fast-todo-selection ()
8979 "Fast TODO keyword selection with single keys.
8980 Returns the new TODO keyword, or nil if no state change should occur."
8981 (let* ((fulltable org-todo-key-alist)
8982 (done-keywords org-done-keywords) ;; needed for the faces.
8983 (maxlen (apply 'max (mapcar
8985 (if (stringp (car x)) (string-width (car x)) 0))
8988 (fwidth (+ maxlen 3 1 3))
8989 (ncol (/ (- (window-width) 4) fwidth))
8993 (save-window-excursion
8995 (set-buffer (get-buffer-create " *Org todo*"))
8996 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
8998 (org-set-local 'org-done-keywords done-keywords)
8999 (setq tbl fulltable cnt 0)
9000 (while (setq e (pop tbl))
9002 ((equal e '(:startgroup))
9003 (push '() groups) (setq ingroup t)
9004 (when (not (= cnt 0))
9008 ((equal e '(:endgroup))
9009 (setq ingroup nil cnt 0)
9011 ((equal e '(:newline))
9012 (when (not (= cnt 0))
9016 (while (equal (car tbl) '(:newline))
9018 (setq tbl (cdr tbl)))))
9020 (setq tg (car e) c (cdr e))
9021 (if ingroup (push tg (car groups)))
9022 (setq tg (org-add-props tg nil 'face
9023 (org-get-todo-face tg)))
9024 (if (and (= cnt 0) (not ingroup)) (insert " "))
9025 (insert "[" c "] " tg (make-string
9026 (- fwidth 4 (length tg)) ?\ ))
9027 (when (= (setq cnt (1+ cnt)) ncol)
9029 (if ingroup (insert " "))
9032 (goto-char (point-min))
9033 (if (not expert) (org-fit-window-to-buffer))
9034 (message "[a-z..]:Set [SPC]:clear")
9035 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
9038 (and (= c ?q) (not (rassoc c fulltable))))
9041 ((setq e (rassoc c fulltable) tg (car e))
9043 (t (setq quit-flag t)))))))
9045 (defun org-entry-is-todo-p ()
9046 (member (org-get-todo-state) org-not-done-keywords))
9048 (defun org-entry-is-done-p ()
9049 (member (org-get-todo-state) org-done-keywords))
9051 (defun org-get-todo-state ()
9053 (org-back-to-heading t)
9054 (and (looking-at org-todo-line-regexp)
9058 (defun org-at-date-range-p (&optional inactive-ok)
9059 "Is the cursor inside a date range?"
9063 (let ((pos (point)))
9064 (skip-chars-backward "^[<\r\n")
9065 (skip-chars-backward "<[")
9066 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
9067 (>= (match-end 0) pos)
9069 (skip-chars-backward "^<[\r\n")
9070 (skip-chars-backward "<[")
9071 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
9072 (>= (match-end 0) pos)
9076 (defun org-get-repeat ()
9077 "Check if there is a deadline/schedule with repeater in this entry."
9080 (org-back-to-heading t)
9081 (if (re-search-forward
9082 org-repeat-re (save-excursion (outline-next-heading) (point)) t)
9083 (match-string 1)))))
9085 (defvar org-last-changed-timestamp)
9086 (defvar org-last-inserted-timestamp)
9087 (defvar org-log-post-message)
9088 (defvar org-log-note-purpose)
9089 (defvar org-log-note-how)
9090 (defvar org-log-note-extra)
9091 (defun org-auto-repeat-maybe (done-word)
9092 "Check if the current headline contains a repeated deadline/schedule.
9093 If yes, set TODO state back to what it was and change the base date
9094 of repeating deadline/scheduled time stamps to new date.
9095 This function is run automatically after each state change to a DONE state."
9096 ;; last-state is dynamically scoped into this function
9097 (let* ((repeat (org-get-repeat))
9098 (aa (assoc last-state org-todo-kwd-alist))
9099 (interpret (nth 1 aa))
9101 (whata '(("d" . day) ("m" . month) ("y" . year)))
9102 (msg "Entry repeats: ")
9104 (org-todo-log-states nil)
9105 (nshiftmax 10) (nshift 0)
9106 re type n what ts time)
9108 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
9109 (org-todo (if (eq interpret 'type) last-state head))
9110 (when org-log-repeat
9111 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
9112 (memq 'org-add-log-note post-command-hook))
9113 ;; OK, we are already setup for some record
9114 (if (eq org-log-repeat 'note)
9115 ;; make sure we take a note, not only a time stamp
9116 (setq org-log-note-how 'note))
9117 ;; Set up for taking a record
9118 (org-add-log-setup 'state (or done-word (car org-done-keywords))
9120 'findpos org-log-repeat)))
9121 (org-back-to-heading t)
9122 (org-add-planning-info nil nil 'closed)
9123 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
9124 org-deadline-time-regexp "\\)\\|\\("
9125 org-ts-regexp "\\)"))
9126 (while (re-search-forward
9127 re (save-excursion (outline-next-heading) (point)) t)
9128 (setq type (if (match-end 1) org-scheduled-string
9129 (if (match-end 3) org-deadline-string "Plain:"))
9130 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
9131 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
9132 (setq n (string-to-number (match-string 2 ts))
9133 what (match-string 3 ts))
9134 (if (equal what "w") (setq n (* n 7) what "d"))
9135 ;; Preparation, see if we need to modify the start date for the change
9137 (setq time (save-match-data (org-time-string-to-time ts)))
9139 ((equal (match-string 1 ts) ".")
9140 ;; Shift starting date to today
9141 (org-timestamp-change
9142 (- (time-to-days (current-time)) (time-to-days time))
9144 ((equal (match-string 1 ts) "+")
9145 (while (or (= nshift 0)
9146 (<= (time-to-days time) (time-to-days (current-time))))
9147 (when (= (incf nshift) nshiftmax)
9148 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
9150 (org-timestamp-change n (cdr (assoc what whata)))
9151 (org-at-timestamp-p t)
9152 (setq ts (match-string 1))
9153 (setq time (save-match-data (org-time-string-to-time ts))))
9154 (org-timestamp-change (- n) (cdr (assoc what whata)))
9155 ;; rematch, so that we have everything in place for the real shift
9156 (org-at-timestamp-p t)
9157 (setq ts (match-string 1))
9158 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
9159 (org-timestamp-change n (cdr (assoc what whata)))
9160 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
9161 (setq org-log-post-message msg)
9162 (message "%s" msg))))
9164 (defun org-show-todo-tree (arg)
9165 "Make a compact tree which shows all headlines marked with TODO.
9166 The tree will show the lines where the regexp matches, and all higher
9167 headlines above the match.
9168 With a \\[universal-argument] prefix, also show the DONE entries.
9169 With a numeric prefix N, construct a sparse tree for the Nth element
9170 of `org-todo-keywords-1'."
9172 (let ((case-fold-search nil)
9174 (cond ((null arg) org-not-done-regexp)
9176 (let ((kwd (org-ido-completing-read "Keyword (or KWD1|KWD2|...): "
9177 (mapcar 'list org-todo-keywords-1))))
9179 (mapconcat 'identity (org-split-string kwd "|") "\\|")
9181 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
9182 (regexp-quote (nth (1- (prefix-numeric-value arg))
9183 org-todo-keywords-1)))
9184 (t (error "Invalid prefix argument: %s" arg)))))
9185 (message "%d TODO entries found"
9186 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
9188 (defun org-deadline (&optional remove time)
9189 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
9190 With argument REMOVE, remove any deadline from the item.
9191 When TIME is set, it should be an internal time specification, and the
9192 scheduling will use the corresponding date."
9196 (org-remove-timestamp-with-keyword org-deadline-string)
9197 (message "Item no longer has a deadline."))
9198 (if (org-get-repeat)
9199 (error "Cannot change deadline on task with repeater, please do that by hand")
9200 (org-add-planning-info 'deadline time 'closed)
9201 (message "Deadline on %s" org-last-inserted-timestamp))))
9203 (defun org-schedule (&optional remove time)
9204 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
9205 With argument REMOVE, remove any scheduling date from the item.
9206 When TIME is set, it should be an internal time specification, and the
9207 scheduling will use the corresponding date."
9211 (org-remove-timestamp-with-keyword org-scheduled-string)
9212 (message "Item is no longer scheduled."))
9213 (if (org-get-repeat)
9214 (error "Cannot reschedule task with repeater, please do that by hand")
9215 (org-add-planning-info 'scheduled time 'closed)
9216 (message "Scheduled to %s" org-last-inserted-timestamp))))
9218 (defun org-get-scheduled-time (pom &optional inherit)
9219 "Get the scheduled time as a time tuple, of a format suitable
9220 for calling org-schedule with, or if there is no scheduling,
9222 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
9224 (apply 'encode-time (org-parse-time-string time)))))
9226 (defun org-get-deadline-time (pom &optional inherit)
9227 "Get the deadine as a time tuple, of a format suitable for
9228 calling org-deadlin with, or if there is no scheduling, returns
9230 (let ((time (org-entry-get pom "DEADLINE" inherit)))
9232 (apply 'encode-time (org-parse-time-string time)))))
9234 (defun org-remove-timestamp-with-keyword (keyword)
9235 "Remove all time stamps with KEYWORD in the current entry."
9236 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
9239 (org-back-to-heading t)
9241 (org-end-of-subtree t t)
9242 (while (re-search-backward re beg t)
9244 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
9245 (equal (char-before) ?\ ))
9246 (backward-delete-char 1)
9247 (if (string-match "^[ \t]*$" (buffer-substring
9248 (point-at-bol) (point-at-eol)))
9249 (delete-region (point-at-bol)
9250 (min (point-max) (1+ (point-at-eol))))))))))
9252 (defun org-add-planning-info (what &optional time &rest remove)
9253 "Insert new timestamp with keyword in the line directly after the headline.
9254 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
9255 If non is given, the user is prompted for a date.
9256 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
9259 (let (org-time-was-given org-end-time-was-given ts
9260 end default-time default-input)
9263 (when (and (not time) (memq what '(scheduled deadline)))
9264 ;; Try to get a default date/time from existing timestamp
9266 (org-back-to-heading t)
9267 (setq end (save-excursion (outline-next-heading) (point)))
9268 (when (re-search-forward (if (eq what 'scheduled)
9269 org-scheduled-time-regexp
9270 org-deadline-time-regexp)
9272 (setq ts (match-string 1)
9274 (apply 'encode-time (org-parse-time-string ts))
9275 default-input (and ts (org-get-compact-tod ts))))))
9277 ;; If necessary, get the time from the user
9278 (setq time (or time (org-read-date nil 'to-time nil nil
9279 default-time default-input))))
9281 (when (and org-insert-labeled-timestamps-at-point
9282 (member what '(scheduled deadline)))
9284 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
9285 (org-insert-time-stamp time org-time-was-given
9286 nil nil nil (list org-end-time-was-given))
9290 (let (col list elt ts buffer-invisibility-spec)
9291 (org-back-to-heading t)
9292 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
9293 (goto-char (match-end 1))
9294 (setq col (current-column))
9295 (goto-char (match-end 0))
9296 (if (eobp) (insert "\n") (forward-char 1))
9297 (when (and (not what)
9298 (not (looking-at org-keyword-time-not-clock-regexp)))
9299 ;; Nothing to add, nothing to remove...... :-)
9301 (if (and (not (looking-at outline-regexp))
9302 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
9304 (not (equal (match-string 1) org-clock-string)))
9305 (narrow-to-region (match-beginning 0) (match-end 0))
9306 (insert-before-markers "\n")
9308 (narrow-to-region (point) (point))
9309 (and org-adapt-indentation (org-indent-to-column col)))
9310 ;; Check if we have to remove something.
9311 (setq list (cons what remove))
9313 (setq elt (pop list))
9314 (goto-char (point-min))
9315 (when (or (and (eq elt 'scheduled)
9316 (re-search-forward org-scheduled-time-regexp nil t))
9317 (and (eq elt 'deadline)
9318 (re-search-forward org-deadline-time-regexp nil t))
9319 (and (eq elt 'closed)
9320 (re-search-forward org-closed-time-regexp nil t)))
9322 (if (looking-at "--+<[^>]+>") (replace-match ""))
9323 (if (looking-at " +") (replace-match ""))))
9324 (goto-char (point-max))
9327 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
9328 (cond ((eq what 'scheduled) org-scheduled-string)
9329 ((eq what 'deadline) org-deadline-string)
9330 ((eq what 'closed) org-closed-string))
9332 (setq ts (org-insert-time-stamp
9334 (or org-time-was-given
9335 (and (eq what 'closed) org-log-done-with-time))
9337 nil nil (list org-end-time-was-given)))
9339 (goto-char (point-min))
9341 (if (and (looking-at "[ \t]+\n")
9342 (equal (char-before) ?\n))
9343 (delete-region (1- (point)) (point-at-eol)))
9346 (defvar org-log-note-marker (make-marker))
9347 (defvar org-log-note-purpose nil)
9348 (defvar org-log-note-state nil)
9349 (defvar org-log-note-previous-state nil)
9350 (defvar org-log-note-how nil)
9351 (defvar org-log-note-extra nil)
9352 (defvar org-log-note-window-configuration nil)
9353 (defvar org-log-note-return-to (make-marker))
9354 (defvar org-log-post-message nil
9355 "Message to be displayed after a log note has been stored.
9356 The auto-repeater uses this.")
9358 (defun org-add-note ()
9359 "Add a note to the current entry.
9360 This is done in the same way as adding a state change note."
9362 (org-add-log-setup 'note nil nil 'findpos nil))
9364 (defvar org-property-end-re)
9365 (defun org-add-log-setup (&optional purpose state prev-state
9366 findpos how &optional extra)
9367 "Set up the post command hook to take a note.
9368 If this is about to TODO state change, the new state is expected in STATE.
9369 When FINDPOS is non-nil, find the correct position for the note in
9370 the current entry. If not, assume that it can be inserted at point.
9371 HOW is an indicator what kind of note should be created.
9372 EXTRA is additional text that will be inserted into the notes buffer."
9373 (let ((drawer (cond ((stringp org-log-into-drawer)
9374 org-log-into-drawer)
9375 (org-log-into-drawer "LOGBOOK")
9380 (org-back-to-heading t)
9381 (narrow-to-region (point) (save-excursion
9382 (outline-next-heading) (point)))
9383 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
9384 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
9386 (goto-char (match-end 0))
9389 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
9392 (goto-char (match-end 0))
9393 (or org-log-states-order-reversed
9394 (and (re-search-forward org-property-end-re nil t)
9395 (goto-char (1- (match-beginning 0))))))
9396 (insert "\n:" drawer ":\n:END:")
9397 (beginning-of-line 0)
9398 (org-indent-line-function)
9399 (beginning-of-line 2)
9400 (org-indent-line-function)
9402 ((and org-log-state-notes-insert-after-drawers
9404 (forward-line) (looking-at org-drawer-regexp)))
9406 (while (looking-at org-drawer-regexp)
9407 (goto-char (match-end 0))
9408 (re-search-forward org-property-end-re (point-max) t)
9411 (unless org-log-states-order-reversed
9412 (and (= (char-after) ?\n) (forward-char 1))
9413 (org-skip-over-state-notes)
9414 (skip-chars-backward " \t\n\r")))
9415 (move-marker org-log-note-marker (point))
9416 (setq org-log-note-purpose purpose
9417 org-log-note-state state
9418 org-log-note-previous-state prev-state
9419 org-log-note-how how
9420 org-log-note-extra extra)
9421 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
9423 (defun org-skip-over-state-notes ()
9424 "Skip past the list of State notes in an entry."
9425 (if (looking-at "\n[ \t]*- State") (forward-char 1))
9426 (while (looking-at "[ \t]*- State")
9429 (error (org-end-of-item)))))
9431 (defun org-add-log-note (&optional purpose)
9432 "Pop up a window for taking a note, and add this note later at point."
9433 (remove-hook 'post-command-hook 'org-add-log-note)
9434 (setq org-log-note-window-configuration (current-window-configuration))
9435 (delete-other-windows)
9436 (move-marker org-log-note-return-to (point))
9437 (switch-to-buffer (marker-buffer org-log-note-marker))
9438 (goto-char org-log-note-marker)
9439 (org-switch-to-buffer-other-window "*Org Note*")
9441 (if (memq org-log-note-how '(time state))
9442 (let (current-prefix-arg) (org-store-log-note))
9443 (let ((org-inhibit-startup t)) (org-mode))
9444 (insert (format "# Insert note for %s.
9445 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
9447 ((eq org-log-note-purpose 'clock-out) "stopped clock")
9448 ((eq org-log-note-purpose 'done) "closed todo item")
9449 ((eq org-log-note-purpose 'state)
9450 (format "state change from \"%s\" to \"%s\""
9451 (or org-log-note-previous-state "")
9452 (or org-log-note-state "")))
9453 ((eq org-log-note-purpose 'note)
9455 (t (error "This should not happen")))))
9456 (if org-log-note-extra (insert org-log-note-extra))
9457 (org-set-local 'org-finish-function 'org-store-log-note)))
9459 (defvar org-note-abort nil) ; dynamically scoped
9460 (defun org-store-log-note ()
9461 "Finish taking a log note, and insert it to where it belongs."
9462 (let ((txt (buffer-string))
9463 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
9465 (kill-buffer (current-buffer))
9466 (while (string-match "\\`#.*\n[ \t\n]*" txt)
9467 (setq txt (replace-match "" t t txt)))
9468 (if (string-match "\\s-+\\'" txt)
9469 (setq txt (replace-match "" t t txt)))
9470 (setq lines (org-split-string txt "\n"))
9471 (when (and note (string-match "\\S-" note))
9473 (org-replace-escapes
9475 (list (cons "%u" (user-login-name))
9476 (cons "%U" user-full-name)
9477 (cons "%t" (format-time-string
9478 (org-time-stamp-format 'long 'inactive)
9480 (cons "%s" (if org-log-note-state
9481 (concat "\"" org-log-note-state "\"")
9483 (cons "%S" (if org-log-note-previous-state
9484 (concat "\"" org-log-note-previous-state "\"")
9486 (if lines (setq note (concat note " \\\\")))
9488 (when (or current-prefix-arg org-note-abort) (setq lines nil))
9491 (set-buffer (marker-buffer org-log-note-marker))
9493 (goto-char org-log-note-marker)
9494 (move-marker org-log-note-marker nil)
9496 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
9497 (insert "- " (pop lines))
9498 (org-indent-line-function)
9499 (beginning-of-line 1)
9500 (looking-at "[ \t]*")
9501 (setq ind (concat (match-string 0) " "))
9503 (while lines (insert "\n" ind (pop lines)))
9504 (message "Note stored")
9505 (org-back-to-heading t)
9506 (org-cycle-hide-drawers 'children)))))
9507 (set-window-configuration org-log-note-window-configuration)
9508 (with-current-buffer (marker-buffer org-log-note-return-to)
9509 (goto-char org-log-note-return-to))
9510 (move-marker org-log-note-return-to nil)
9511 (and org-log-post-message (message "%s" org-log-post-message)))
9513 (defun org-sparse-tree (&optional arg)
9514 "Create a sparse tree, prompt for the details.
9515 This command can create sparse trees. You first need to select the type
9516 of match used to create the tree:
9518 t Show entries with a specific TODO keyword.
9519 m Show entries selected by a tags/property match.
9520 p Enter a property name and its value (both with completion on existing
9521 names/values) and show entries with that property.
9522 r Show entries matching a regular expression
9523 d Show deadlines due within `org-deadline-warning-days'."
9525 (let (ans kwd value)
9526 (message "Sparse tree: [/]regexp [t]odo-kwd [m]atch [p]roperty [d]eadlines [b]efore-date")
9527 (setq ans (read-char-exclusive))
9530 (call-interactively 'org-check-deadlines))
9532 (call-interactively 'org-check-before-date))
9534 (org-show-todo-tree '(4)))
9535 ((member ans '(?T ?m))
9536 (call-interactively 'org-match-sparse-tree))
9537 ((member ans '(?p ?P))
9538 (setq kwd (org-ido-completing-read "Property: "
9539 (mapcar 'list (org-buffer-property-keys))))
9540 (setq value (org-ido-completing-read "Value: "
9541 (mapcar 'list (org-property-values kwd))))
9542 (unless (string-match "\\`{.*}\\'" value)
9543 (setq value (concat "\"" value "\"")))
9544 (org-match-sparse-tree arg (concat kwd "=" value)))
9545 ((member ans '(?r ?R ?/))
9546 (call-interactively 'org-occur))
9547 (t (error "No such sparse tree command \"%c\"" ans)))))
9549 (defvar org-occur-highlights nil
9550 "List of overlays used for occur matches.")
9551 (make-variable-buffer-local 'org-occur-highlights)
9552 (defvar org-occur-parameters nil
9553 "Parameters of the active org-occur calls.
9554 This is a list, each call to org-occur pushes as cons cell,
9555 containing the regular expression and the callback, onto the list.
9556 The list can contain several entries if `org-occur' has been called
9557 several time with the KEEP-PREVIOUS argument. Otherwise, this list
9558 will only contain one set of parameters. When the highlights are
9559 removed (for example with `C-c C-c', or with the next edit (depending
9560 on `org-remove-highlights-with-change'), this variable is emptied
9562 (make-variable-buffer-local 'org-occur-parameters)
9564 (defun org-occur (regexp &optional keep-previous callback)
9565 "Make a compact tree which shows all matches of REGEXP.
9566 The tree will show the lines where the regexp matches, and all higher
9567 headlines above the match. It will also show the heading after the match,
9568 to make sure editing the matching entry is easy.
9569 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
9570 call to `org-occur' will be kept, to allow stacking of calls to this
9572 If CALLBACK is non-nil, it is a function which is called to confirm
9573 that the match should indeed be shown."
9574 (interactive "sRegexp: \nP")
9575 (unless keep-previous
9576 (org-remove-occur-highlights nil nil t))
9577 (push (cons regexp callback) org-occur-parameters)
9580 (goto-char (point-min))
9581 (if (or (not keep-previous) ; do not want to keep
9582 (not org-occur-highlights)) ; no previous matches
9585 (while (re-search-forward regexp nil t)
9586 (when (or (not callback)
9587 (save-match-data (funcall callback)))
9589 (when org-highlight-sparse-tree-matches
9590 (org-highlight-new-match (match-beginning 0) (match-end 0)))
9591 (org-show-context 'occur-tree))))
9592 (when org-remove-highlights-with-change
9593 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
9595 (unless org-sparse-tree-open-archived-trees
9596 (org-hide-archived-subtrees (point-min) (point-max)))
9597 (run-hooks 'org-occur-hook)
9599 (message "%d match(es) for regexp %s" cnt regexp))
9602 (defun org-show-context (&optional key)
9603 "Make sure point and context and visible.
9604 How much context is shown depends upon the variables
9605 `org-show-hierarchy-above', `org-show-following-heading'. and
9606 `org-show-siblings'."
9607 (let ((heading-p (org-on-heading-p t))
9608 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
9609 (following-p (org-get-alist-option org-show-following-heading key))
9610 (entry-p (org-get-alist-option org-show-entry-below key))
9611 (siblings-p (org-get-alist-option org-show-siblings key)))
9613 ;; Show heading or entry text
9614 (if (and heading-p (not entry-p))
9615 (org-flag-heading nil) ; only show the heading
9616 (and (or entry-p (org-invisible-p) (org-invisible-p2))
9617 (org-show-hidden-entry))) ; show entire entry
9619 ;; Show next sibling, or heading below text
9621 (and (if heading-p (org-goto-sibling) (outline-next-heading))
9622 (org-flag-heading nil))))
9623 (when siblings-p (org-show-siblings))
9625 ;; show all higher headings, possibly with siblings
9627 (while (and (condition-case nil
9628 (progn (org-up-heading-all 1) t)
9631 (org-flag-heading nil)
9632 (when siblings-p (org-show-siblings))))))))
9634 (defun org-reveal (&optional siblings)
9635 "Show current entry, hierarchy above it, and the following headline.
9636 This can be used to show a consistent set of context around locations
9637 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
9638 not t for the search context.
9640 With optional argument SIBLINGS, on each level of the hierarchy all
9641 siblings are shown. This repairs the tree structure to what it would
9642 look like when opened with hierarchical calls to `org-cycle'."
9644 (let ((org-show-hierarchy-above t)
9645 (org-show-following-heading t)
9646 (org-show-siblings (if siblings t org-show-siblings)))
9647 (org-show-context nil)))
9649 (defun org-highlight-new-match (beg end)
9650 "Highlight from BEG to END and mark the highlight is an occur headline."
9651 (let ((ov (org-make-overlay beg end)))
9652 (org-overlay-put ov 'face 'secondary-selection)
9653 (push ov org-occur-highlights)))
9655 (defun org-remove-occur-highlights (&optional beg end noremove)
9656 "Remove the occur highlights from the buffer.
9657 BEG and END are ignored. If NOREMOVE is nil, remove this function
9658 from the `before-change-functions' in the current buffer."
9660 (unless org-inhibit-highlight-removal
9661 (mapc 'org-delete-overlay org-occur-highlights)
9662 (setq org-occur-highlights nil)
9663 (setq org-occur-parameters nil)
9665 (remove-hook 'before-change-functions
9666 'org-remove-occur-highlights 'local))))
9670 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
9671 "Regular expression matching the priority indicator.")
9673 (defvar org-remove-priority-next-time nil)
9675 (defun org-priority-up ()
9676 "Increase the priority of the current item."
9680 (defun org-priority-down ()
9681 "Decrease the priority of the current item."
9683 (org-priority 'down))
9685 (defun org-priority (&optional action)
9686 "Change the priority of an item by ARG.
9687 ACTION can be `set', `up', `down', or a character."
9689 (setq action (or action 'set))
9690 (let (current new news have remove)
9692 (org-back-to-heading t)
9693 (if (looking-at org-priority-regexp)
9694 (setq current (string-to-char (match-string 2))
9696 (setq current org-default-priority))
9698 ((or (eq action 'set)
9699 (if (featurep 'xemacs) (characterp action) (integerp action)))
9700 (if (not (eq action 'set))
9702 (message "Priority %c-%c, SPC to remove: "
9703 org-highest-priority org-lowest-priority)
9704 (setq new (read-char-exclusive)))
9705 (if (and (= (upcase org-highest-priority) org-highest-priority)
9706 (= (upcase org-lowest-priority) org-lowest-priority))
9707 (setq new (upcase new)))
9708 (cond ((equal new ?\ ) (setq remove t))
9709 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
9710 (error "Priority must be between `%c' and `%c'"
9711 org-highest-priority org-lowest-priority))))
9713 (if (and (not have) (eq last-command this-command))
9714 (setq new org-lowest-priority)
9715 (setq new (if (and org-priority-start-cycle-with-default (not have))
9716 org-default-priority (1- current)))))
9718 (if (and (not have) (eq last-command this-command))
9719 (setq new org-highest-priority)
9720 (setq new (if (and org-priority-start-cycle-with-default (not have))
9721 org-default-priority (1+ current)))))
9722 (t (error "Invalid action")))
9723 (if (or (< (upcase new) org-highest-priority)
9724 (> (upcase new) org-lowest-priority))
9726 (setq news (format "%c" new))
9729 (replace-match "" t t nil 1)
9730 (replace-match news t t nil 2))
9732 (error "No priority cookie found in line")
9733 (looking-at org-todo-line-regexp)
9736 (goto-char (match-end 2))
9737 (insert " [#" news "]"))
9738 (goto-char (match-beginning 3))
9739 (insert "[#" news "] ")))))
9740 (org-preserve-lc (org-set-tags nil 'align))
9742 (message "Priority removed")
9743 (message "Priority of current item set to %s" news))))
9746 (defun org-get-priority (s)
9747 "Find priority cookie and return priority."
9749 (if (not (string-match org-priority-regexp s))
9750 (* 1000 (- org-lowest-priority org-default-priority))
9751 (* 1000 (- org-lowest-priority
9752 (string-to-char (match-string 2 s)))))))
9756 (defvar org-agenda-archives-mode)
9757 (defun org-scan-tags (action matcher &optional todo-only)
9758 "Scan headline tags with inheritance and produce output ACTION.
9760 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
9761 or `agenda' to produce an entry list for an agenda view. It can also be
9762 a Lisp form or a function that should be called at each matched headline, in
9763 this case the return value is a list of all return values from these calls.
9765 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
9766 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
9767 only lines with a TODO keyword are included in the output."
9768 (require 'org-agenda)
9769 (let* ((re (concat "[\n\r]" outline-regexp " *\\(\\<\\("
9770 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
9772 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
9773 (props (list 'face 'default
9774 'done-face 'org-done
9775 'undone-face 'default
9776 'mouse-face 'highlight
9777 'org-not-done-regexp org-not-done-regexp
9778 'org-todo-regexp org-todo-regexp
9779 'keymap org-agenda-keymap
9781 (format "mouse-2 or RET jump to org file %s"
9782 (abbreviate-file-name
9783 (or (buffer-file-name (buffer-base-buffer))
9784 (buffer-name (buffer-base-buffer)))))))
9785 (case-fold-search nil)
9786 lspos tags tags-list
9787 (tags-alist (list (cons 0 (mapcar 'downcase org-file-tags))))
9788 (llast 0) rtn rtn1 level category i txt
9789 todo marker entry priority)
9790 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
9791 (setq action (list 'lambda nil action)))
9793 (goto-char (point-min))
9794 (when (eq action 'sparse-tree)
9796 (org-remove-occur-highlights))
9797 (while (re-search-forward re nil t)
9799 (setq todo (if (match-end 1) (match-string 2))
9800 tags (if (match-end 4) (match-string 4)))
9801 (goto-char (setq lspos (1+ (match-beginning 0))))
9802 (setq level (org-reduced-level (funcall outline-level))
9803 category (org-get-category))
9804 (setq i llast llast level)
9805 ;; remove tag lists from same and sublevels
9807 (when (setq entry (assoc i tags-alist))
9808 (setq tags-alist (delete entry tags-alist)))
9810 ;; add the next tags
9812 (setq tags (mapcar 'downcase (org-split-string tags ":"))
9814 (cons (cons level tags) tags-alist)))
9815 ;; compile tags for current headline
9817 (if org-use-tag-inheritance
9818 (apply 'append (mapcar 'cdr (reverse tags-alist)))
9820 (when org-use-tag-inheritance
9821 (setcdr (car tags-alist)
9823 (setq x (copy-sequence x))
9824 (org-add-prop-inherited x))
9825 (cdar tags-alist))))
9826 (when (and tags org-use-tag-inheritance
9827 (not (eq t org-use-tag-inheritance)))
9828 ;; selective inheritance, remove uninherited ones
9829 (setcdr (car tags-alist)
9830 (org-remove-uniherited-tags (cdar tags-alist))))
9831 (when (and (or (not todo-only)
9832 (and (member todo org-not-done-keywords)
9833 (or (not org-agenda-tags-todo-honor-ignore-options)
9834 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
9835 (let ((case-fold-search t)) (eval matcher))
9837 (not (member org-archive-tag tags-list))
9838 ;; we have an archive tag, should we use this anyway?
9839 (or (not org-agenda-skip-archived-trees)
9840 (and (eq action 'agenda) org-agenda-archives-mode))))
9841 (unless (eq action 'sparse-tree) (org-agenda-skip))
9843 ;; select this headline
9846 ((eq action 'sparse-tree)
9847 (and org-highlight-sparse-tree-matches
9848 (org-get-heading) (match-end 0)
9849 (org-highlight-new-match
9850 (match-beginning 0) (match-beginning 1)))
9851 (org-show-context 'tags-tree))
9852 ((eq action 'agenda)
9853 (setq txt (org-format-agenda-item
9856 (if org-tags-match-list-sublevels
9857 (make-string (1- level) ?.) "")
9859 category (org-get-tags-at))
9860 priority (org-get-priority txt))
9862 (setq marker (org-agenda-new-marker))
9863 (org-add-props txt props
9864 'org-marker marker 'org-hd-marker marker 'org-category category
9866 'priority priority 'type "tagsmatch")
9870 (setq rtn1 (funcall action))
9872 (goto-char (point-at-eol)))
9873 (t (error "Invalid action")))
9875 ;; if we are to skip sublevels, jump to end of subtree
9876 (or org-tags-match-list-sublevels (org-end-of-subtree t))))))
9877 (when (and (eq action 'sparse-tree)
9878 (not org-sparse-tree-open-archived-trees))
9879 (org-hide-archived-subtrees (point-min) (point-max)))
9882 (defun org-remove-uniherited-tags (tags)
9883 "Remove all tags that are not inherited from the list TAGS."
9885 ((eq org-use-tag-inheritance t)
9886 (if org-tags-exclude-from-inheritance
9887 (org-delete-all org-tags-exclude-from-inheritance tags)
9889 ((not org-use-tag-inheritance) nil)
9890 ((stringp org-use-tag-inheritance)
9893 (if (and (string-match org-use-tag-inheritance x)
9894 (not (member x org-tags-exclude-from-inheritance)))
9897 ((listp org-use-tag-inheritance)
9900 (if (member x org-use-tag-inheritance) x nil))
9903 (defvar todo-only) ;; dynamically scoped
9905 (defun org-match-sparse-tree (&optional todo-only match)
9906 "Create a sparse tree according to tags string MATCH.
9907 MATCH can contain positive and negative selection of tags, like
9908 \"+WORK+URGENT-WITHBOSS\".
9909 If optional argument TODO-ONLY is non-nil, only select lines that are
9912 (org-prepare-agenda-buffers (list (current-buffer)))
9913 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
9915 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
9917 (defvar org-cached-props nil)
9918 (defun org-cached-entry-get (pom property)
9919 (if (or (eq t org-use-property-inheritance)
9920 (and (stringp org-use-property-inheritance)
9921 (string-match org-use-property-inheritance property))
9922 (and (listp org-use-property-inheritance)
9923 (member property org-use-property-inheritance)))
9924 ;; Caching is not possible, check it directly
9925 (org-entry-get pom property 'inherit)
9926 ;; Get all properties, so that we can do complicated checks easily
9927 (cdr (assoc property (or org-cached-props
9928 (setq org-cached-props
9929 (org-entry-properties pom)))))))
9931 (defun org-global-tags-completion-table (&optional files)
9932 "Return the list of all tags in all agenda buffer/files."
9939 (set-buffer (find-file-noselect file))
9940 (append (org-get-buffer-tags)
9941 (mapcar (lambda (x) (if (stringp (car-safe x))
9942 (list (car-safe x)) nil))
9944 (if (and files (car files))
9946 (org-agenda-files))))))))
9948 (defun org-make-tags-matcher (match)
9949 "Create the TAGS//TODO matcher form for the selection string MATCH."
9950 ;; todo-only is scoped dynamically into this function, and the function
9951 ;; may change it if the matcher asks for it.
9953 ;; Get a new match request, with completion
9954 (let ((org-last-tags-completion-table
9955 (org-global-tags-completion-table)))
9956 (setq match (org-completing-read-no-ido
9957 "Match: " 'org-tags-completion-function nil nil nil
9958 'org-tags-history))))
9960 ;; Parse the string and create a lisp form
9961 (let ((match0 match)
9962 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
9964 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
9965 orterms term orlist re-p str-p level-p level-op time-p
9966 prop-p pn pv po cat-p gv rest)
9967 (if (string-match "/+" match)
9968 ;; match contains also a todo-matching request
9970 (setq tagsmatch (substring match 0 (match-beginning 0))
9971 todomatch (substring match (match-end 0)))
9972 (if (string-match "^!" todomatch)
9973 (setq todo-only t todomatch (substring todomatch 1)))
9974 (if (string-match "^\\s-*$" todomatch)
9975 (setq todomatch nil)))
9976 ;; only matching tags
9977 (setq tagsmatch match todomatch nil))
9979 ;; Make the tags matcher
9980 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
9981 (setq tagsmatcher t)
9982 (setq orterms (org-split-string tagsmatch "|") orlist nil)
9983 (while (setq term (pop orterms))
9984 (while (and (equal (substring term -1) "\\") orterms)
9985 (setq term (concat term "|" (pop orterms)))) ; repair bad split
9986 (while (string-match re term)
9987 (setq rest (substring term (match-end 0))
9988 minus (and (match-end 1)
9989 (equal (match-string 1 term) "-"))
9990 tag (match-string 2 term)
9991 re-p (equal (string-to-char tag) ?{)
9992 level-p (match-end 4)
9993 prop-p (match-end 5)
9995 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
9997 (setq level-op (org-op-to-function (match-string 3 term)))
9998 `(,level-op level ,(string-to-number
9999 (match-string 4 term))))
10001 (setq pn (match-string 5 term)
10002 po (match-string 6 term)
10003 pv (match-string 7 term)
10004 cat-p (equal pn "CATEGORY")
10005 re-p (equal (string-to-char pv) ?{)
10006 str-p (equal (string-to-char pv) ?\")
10007 time-p (save-match-data
10008 (string-match "^\"[[<].*[]>]\"$" pv))
10009 pv (if (or re-p str-p) (substring pv 1 -1) pv))
10010 (if time-p (setq pv (org-matcher-time pv)))
10011 (setq po (org-op-to-function po (if time-p 'time str-p)))
10013 ((equal pn "CATEGORY")
10014 (setq gv '(get-text-property (point) 'org-category)))
10018 (setq gv `(org-cached-entry-get nil ,pn))))
10021 `(not (string-match ,pv (or ,gv "")))
10022 `(string-match ,pv (or ,gv "")))
10024 `(,po (or ,gv "") ,pv)
10025 `(,po (string-to-number (or ,gv ""))
10026 ,(string-to-number pv) ))))
10027 (t `(member ,(downcase tag) tags-list)))
10028 mm (if minus (list 'not mm) mm)
10030 (push mm tagsmatcher))
10031 (push (if (> (length tagsmatcher) 1)
10032 (cons 'and tagsmatcher)
10035 (setq tagsmatcher nil))
10036 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
10038 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
10039 ;; Make the todo matcher
10040 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
10041 (setq todomatcher t)
10042 (setq orterms (org-split-string todomatch "|") orlist nil)
10043 (while (setq term (pop orterms))
10044 (while (string-match re term)
10045 (setq minus (and (match-end 1)
10046 (equal (match-string 1 term) "-"))
10047 kwd (match-string 2 term)
10048 re-p (equal (string-to-char kwd) ?{)
10049 term (substring term (match-end 0))
10051 `(string-match ,(substring kwd 1 -1) todo)
10052 (list 'equal 'todo kwd))
10053 mm (if minus (list 'not mm) mm))
10054 (push mm todomatcher))
10055 (push (if (> (length todomatcher) 1)
10056 (cons 'and todomatcher)
10059 (setq todomatcher nil))
10060 (setq todomatcher (if (> (length orlist) 1)
10061 (cons 'or orlist) (car orlist))))
10063 ;; Return the string and lisp forms of the matcher
10064 (setq matcher (if todomatcher
10065 (list 'and tagsmatcher todomatcher)
10067 (cons match0 matcher)))
10069 (defun org-op-to-function (op &optional stringp)
10070 "Turn an operator into the appropriate function."
10073 ((equal op "<" ) '(< string< org-time<))
10074 ((equal op ">" ) '(> org-string> org-time>))
10075 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
10076 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
10077 ((member op '("=" "==")) '(= string= org-time=))
10078 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
10079 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
10081 (defun org<> (a b) (not (= a b)))
10082 (defun org-string<= (a b) (or (string= a b) (string< a b)))
10083 (defun org-string>= (a b) (not (string< a b)))
10084 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
10085 (defun org-string<> (a b) (not (string= a b)))
10086 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
10087 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
10088 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
10089 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
10090 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
10091 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
10093 "Convert S to a floating point time.
10094 If S is already a number, just return it. If it is a string, parse
10095 it as a time string and apply `float-time' to it. If S is nil, just return 0."
10099 (condition-case nil
10100 (float-time (apply 'encode-time (org-parse-time-string s)))
10104 (defun org-time-today ()
10105 "Time in seconds today at 0:00.
10106 Returns the float number of seconds since the beginning of the
10107 epoch to the beginning of today (00:00)."
10108 (float-time (apply 'encode-time
10109 (append '(0 0 0) (nthcdr 3 (decode-time))))))
10111 (defun org-matcher-time (s)
10112 "Interpret a time comparison value."
10115 ((string= s "<now>") (float-time))
10116 ((string= s "<today>") (org-time-today))
10117 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
10118 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
10119 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
10120 (+ (org-time-today)
10121 (* (string-to-number (match-string 1 s))
10122 (cdr (assoc (match-string 2 s)
10123 '(("d" . 86400.0) ("w" . 604800.0)
10124 ("m" . 2678400.0) ("y" . 31557600.0)))))))
10127 (defun org-match-any-p (re list)
10128 "Does re match any element of list?"
10129 (setq list (mapcar (lambda (x) (string-match re x)) list))
10132 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
10133 (defvar org-tags-overlay (org-make-overlay 1 1))
10134 (org-detach-overlay org-tags-overlay)
10136 (defun org-get-local-tags-at (&optional pos)
10137 "Get a list of tags defined in the current headline."
10138 (org-get-tags-at pos 'local))
10140 (defun org-get-local-tags ()
10141 "Get a list of tags defined in the current headline."
10142 (org-get-tags-at nil 'local))
10144 (defun org-get-tags-at (&optional pos local)
10145 "Get a list of all headline tags applicable at POS.
10146 POS defaults to point. If tags are inherited, the list contains
10147 the targets in the same sequence as the headlines appear, i.e.
10148 the tags of the current headline come last.
10149 When LOCAL is non-nil, only return tags from the current headline,
10150 ignore inherited ones."
10152 (let (tags ltags lastpos parent)
10156 (goto-char (or pos (point)))
10159 (condition-case nil
10161 (org-back-to-heading t)
10162 (while (not (equal lastpos (point)))
10163 (setq lastpos (point))
10164 (when (looking-at (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
10165 (setq ltags (org-split-string
10166 (org-match-string-no-properties 1) ":"))
10168 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
10171 (org-remove-uniherited-tags ltags)
10174 (or org-use-tag-inheritance (throw 'done t))
10175 (if local (throw 'done t))
10176 (org-up-heading-all 1)
10179 (append (org-remove-uniherited-tags org-file-tags) tags))))
10181 (defun org-add-prop-inherited (s)
10182 (add-text-properties 0 (length s) '(inherited t) s)
10185 (defun org-toggle-tag (tag &optional onoff)
10186 "Toggle the tag TAG for the current line.
10187 If ONOFF is `on' or `off', don't toggle but set to this state."
10190 (org-back-to-heading t)
10191 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
10194 (setq current (match-string 1))
10195 (replace-match ""))
10197 (setq current (nreverse (org-split-string current ":")))
10201 (or (member tag current) (push tag current)))
10203 (or (not (member tag current)) (setq current (delete tag current))))
10204 (t (if (member tag current)
10205 (setq current (delete tag current))
10207 (push tag current))))
10211 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
10212 (org-set-tags nil t))
10213 (delete-horizontal-space))
10214 (run-hooks 'org-after-tags-change-hook))
10217 (defun org-align-tags-here (to-col)
10218 ;; Assumes that this is a headline
10219 (let ((pos (point)) (col (current-column)) ncol tags-l p)
10220 (beginning-of-line 1)
10221 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
10222 (< pos (match-beginning 2)))
10224 (setq tags-l (- (match-end 2) (match-beginning 2)))
10225 (goto-char (match-beginning 1))
10227 (delete-region (point) (1+ (match-beginning 2)))
10228 (setq ncol (max (1+ (current-column))
10232 (- (abs to-col) tags-l))))
10234 (insert (make-string (- ncol (current-column)) ?\ ))
10235 (setq ncol (current-column))
10236 (when indent-tabs-mode (tabify p (point-at-eol)))
10237 (org-move-to-column (min ncol col) t))
10240 (defun org-set-tags-command (&optional arg just-align)
10241 "Call the set-tags command for the current entry."
10243 (if (org-on-heading-p)
10244 (org-set-tags arg just-align)
10246 (org-back-to-heading t)
10247 (org-set-tags arg just-align))))
10249 (defun org-set-tags (&optional arg just-align)
10250 "Set the tags for the current headline.
10251 With prefix ARG, realign all tags in headings in the current buffer."
10253 (let* ((re (concat "^" outline-regexp))
10254 (current (org-get-tags-string))
10255 (col (current-column))
10256 (org-setting-tags t)
10257 table current-tags inherited-tags ; computed below when needed
10261 (goto-char (point-min))
10262 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
10263 (while (re-search-forward re nil t)
10264 (org-set-tags nil t)
10266 (message "All tags realigned to column %d" org-tags-column))
10268 (setq tags current)
10269 ;; Get a new set of tags from the user
10271 (setq table (append org-tag-persistent-alist
10272 (or org-tag-alist (org-get-buffer-tags)))
10273 org-last-tags-completion-table table
10274 current-tags (org-split-string current ":")
10275 inherited-tags (nreverse
10276 (nthcdr (length current-tags)
10277 (nreverse (org-get-tags-at))))
10279 (if (or (eq t org-use-fast-tag-selection)
10280 (and org-use-fast-tag-selection
10281 (delq nil (mapcar 'cdr table))))
10282 (org-fast-tag-selection
10283 current-tags inherited-tags table
10284 (if org-fast-tag-selection-include-todo org-todo-key-alist))
10285 (let ((org-add-colon-after-tag-completion t))
10287 (org-without-partial-completion
10288 (org-ido-completing-read "Tags: " 'org-tags-completion-function
10289 nil nil current 'org-tags-history)))))))
10290 (while (string-match "[-+&]+" tags)
10291 ;; No boolean logic, just a list
10292 (setq tags (replace-match ":" t t tags))))
10294 (if (string-match "\\`[\t ]*\\'" tags)
10296 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
10297 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
10299 ;; Insert new tags at the correct column
10300 (beginning-of-line 1)
10302 ((and (equal current "") (equal tags "")))
10303 ((re-search-forward
10304 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
10306 (if (equal tags "")
10308 (goto-char (match-beginning 0))
10309 (setq c0 (current-column) p0 (point)
10310 c1 (max (1+ c0) (if (> org-tags-column 0)
10312 (- (- org-tags-column) (length tags))))
10313 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
10314 (replace-match rpl t t)
10315 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
10317 (t (error "Tags alignment failed")))
10318 (org-move-to-column col)
10320 (run-hooks 'org-after-tags-change-hook)))))
10322 (defun org-change-tag-in-region (beg end tag off)
10323 "Add or remove TAG for each entry in the region.
10324 This works in the agenda, and also in an org-mode buffer."
10326 (list (region-beginning) (region-end)
10327 (let ((org-last-tags-completion-table
10329 (org-get-buffer-tags)
10330 (org-global-tags-completion-table))))
10331 (org-ido-completing-read
10332 "Tag: " 'org-tags-completion-function nil nil nil
10333 'org-tags-history))
10335 (message "[s]et or [r]emove? ")
10336 (equal (read-char-exclusive) ?r))))
10337 (if (fboundp 'deactivate-mark) (deactivate-mark))
10338 (let ((agendap (equal major-mode 'org-agenda-mode))
10339 l1 l2 m buf pos newhead (cnt 0))
10341 (setq l2 (1- (org-current-line)))
10343 (setq l1 (org-current-line))
10344 (loop for l from l1 to l2 do
10346 (setq m (get-text-property (point) 'org-hd-marker))
10347 (when (or (and (org-mode-p) (org-on-heading-p))
10349 (setq buf (if agendap (marker-buffer m) (current-buffer))
10350 pos (if agendap m (point)))
10351 (with-current-buffer buf
10355 (setq cnt (1+ cnt))
10356 (org-toggle-tag tag (if off 'off 'on))
10357 (setq newhead (org-get-heading)))))
10358 (and agendap (org-agenda-change-all-lines newhead m))))
10359 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
10361 (defun org-tags-completion-function (string predicate &optional flag)
10362 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
10363 (confirm (lambda (x) (stringp (car x)))))
10364 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
10365 (setq s1 (match-string 1 string)
10366 s2 (match-string 2 string))
10367 (setq s1 "" s2 string))
10371 (setq rtn (try-completion s2 ctable confirm))
10374 (concat s1 s2 (substring rtn (length s2))
10375 (if (and org-add-colon-after-tag-completion
10376 (assoc rtn ctable))
10381 (all-completions s2 ctable confirm)
10385 (assoc s2 ctable)))
10388 (defun org-fast-tag-insert (kwd tags face &optional end)
10389 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
10390 (insert (format "%-12s" (concat kwd ":"))
10391 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
10394 (defun org-fast-tag-show-exit (flag)
10397 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
10398 (replace-match ""))
10401 (org-move-to-column (- (window-width) 19) t)
10402 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
10404 (defun org-set-current-tags-overlay (current prefix)
10405 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
10406 (if (featurep 'xemacs)
10407 (org-overlay-display org-tags-overlay (concat prefix s)
10408 'secondary-selection)
10409 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
10410 (org-overlay-display org-tags-overlay (concat prefix s)))))
10412 (defun org-fast-tag-selection (current inherited table &optional todo-table)
10413 "Fast tag selection with single keys.
10414 CURRENT is the current list of tags in the headline, INHERITED is the
10415 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
10416 possibly with grouping information. TODO-TABLE is a similar table with
10417 TODO keywords, should these have keys assigned to them.
10418 If the keys are nil, a-z are automatically assigned.
10419 Returns the new tags string, or nil to not change the current settings."
10420 (let* ((fulltable (append table todo-table))
10421 (maxlen (apply 'max (mapcar
10423 (if (stringp (car x)) (string-width (car x)) 0))
10425 (buf (current-buffer))
10426 (expert (eq org-fast-tag-selection-single-key 'expert))
10428 (fwidth (+ maxlen 3 1 3))
10429 (ncol (/ (- (window-width) 4) fwidth))
10432 tg cnt e c char c1 c2 ntable tbl rtn
10433 ov-start ov-end ov-prefix
10434 (exit-after-next org-fast-tag-selection-single-key)
10435 (done-keywords org-done-keywords)
10438 (beginning-of-line 1)
10440 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
10441 (setq ov-start (match-beginning 1)
10442 ov-end (match-end 1)
10444 (setq ov-start (1- (point-at-eol))
10445 ov-end (1+ ov-start))
10446 (skip-chars-forward "^\n\r")
10449 (buffer-substring (1- (point)) (point))
10450 (if (> (current-column) org-tags-column)
10452 (make-string (- org-tags-column (current-column)) ?\ ))))))
10453 (org-move-overlay org-tags-overlay ov-start ov-end)
10454 (save-window-excursion
10456 (set-buffer (get-buffer-create " *Org tags*"))
10457 (delete-other-windows)
10458 (split-window-vertically)
10459 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
10461 (org-set-local 'org-done-keywords done-keywords)
10462 (org-fast-tag-insert "Inherited" inherited i-face "\n")
10463 (org-fast-tag-insert "Current" current c-face "\n\n")
10464 (org-fast-tag-show-exit exit-after-next)
10465 (org-set-current-tags-overlay current ov-prefix)
10466 (setq tbl fulltable char ?a cnt 0)
10467 (while (setq e (pop tbl))
10469 ((equal e '(:startgroup))
10470 (push '() groups) (setq ingroup t)
10471 (when (not (= cnt 0))
10475 ((equal e '(:endgroup))
10476 (setq ingroup nil cnt 0)
10478 ((equal e '(:newline))
10479 (when (not (= cnt 0))
10483 (while (equal (car tbl) '(:newline))
10485 (setq tbl (cdr tbl)))))
10487 (setq tg (car e) c2 nil)
10490 ;; automatically assign a character.
10491 (setq c1 (string-to-char
10492 (downcase (substring
10493 tg (if (= (string-to-char tg) ?@) 1 0)))))
10494 (if (or (rassoc c1 ntable) (rassoc c1 table))
10495 (while (or (rassoc char ntable) (rassoc char table))
10496 (setq char (1+ char)))
10498 (setq c (or c2 char)))
10499 (if ingroup (push tg (car groups)))
10500 (setq tg (org-add-props tg nil 'face
10502 ((not (assoc tg table))
10503 (org-get-todo-face tg))
10504 ((member tg current) c-face)
10505 ((member tg inherited) i-face)
10507 (if (and (= cnt 0) (not ingroup)) (insert " "))
10508 (insert "[" c "] " tg (make-string
10509 (- fwidth 4 (length tg)) ?\ ))
10510 (push (cons tg c) ntable)
10511 (when (= (setq cnt (1+ cnt)) ncol)
10513 (if ingroup (insert " "))
10515 (setq ntable (nreverse ntable))
10517 (goto-char (point-min))
10518 (if (not expert) (org-fit-window-to-buffer))
10522 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free%s%s"
10523 (if groups " [!] no groups" " [!]groups")
10524 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
10525 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
10527 ((= c ?\r) (throw 'exit t))
10529 (setq groups (not groups))
10530 (goto-char (point-min))
10531 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
10534 (org-fast-tag-show-exit
10535 (setq exit-after-next (not exit-after-next)))
10537 (delete-other-windows)
10538 (split-window-vertically)
10539 (org-switch-to-buffer-other-window " *Org tags*")
10540 (org-fit-window-to-buffer)))
10542 (and (= c ?q) (not (rassoc c ntable))))
10543 (org-detach-overlay org-tags-overlay)
10544 (setq quit-flag t))
10547 (if exit-after-next (setq exit-after-next 'now)))
10549 (condition-case nil
10550 (setq tg (org-ido-completing-read
10553 (with-current-buffer buf
10554 (org-get-buffer-tags)))))
10555 (quit (setq tg "")))
10556 (when (string-match "\\S-" tg)
10557 (add-to-list 'buffer-tags (list tg))
10558 (if (member tg current)
10559 (setq current (delete tg current))
10560 (push tg current)))
10561 (if exit-after-next (setq exit-after-next 'now)))
10562 ((setq e (rassoc c todo-table) tg (car e))
10563 (with-current-buffer buf
10564 (save-excursion (org-todo tg)))
10565 (if exit-after-next (setq exit-after-next 'now)))
10566 ((setq e (rassoc c ntable) tg (car e))
10567 (if (member tg current)
10568 (setq current (delete tg current))
10569 (loop for g in groups do
10572 (setq current (delete x current)))
10575 (if exit-after-next (setq exit-after-next 'now))))
10577 ;; Create a sorted list
10581 (assoc b (cdr (memq (assoc a ntable) ntable))))))
10582 (if (eq exit-after-next 'now) (throw 'exit t))
10583 (goto-char (point-min))
10584 (beginning-of-line 2)
10585 (delete-region (point) (point-at-eol))
10586 (org-fast-tag-insert "Current" current c-face)
10587 (org-set-current-tags-overlay current ov-prefix)
10588 (while (re-search-forward
10589 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
10590 (setq tg (match-string 1))
10591 (add-text-properties
10592 (match-beginning 1) (match-end 1)
10595 ((member tg current) c-face)
10596 ((member tg inherited) i-face)
10597 (t (get-text-property (match-beginning 1) 'face))))))
10598 (goto-char (point-min)))))
10599 (org-detach-overlay org-tags-overlay)
10601 (mapconcat 'identity current ":")
10604 (defun org-get-tags-string ()
10605 "Get the TAGS string in the current headline."
10606 (unless (org-on-heading-p t)
10607 (error "Not on a heading"))
10609 (beginning-of-line 1)
10610 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
10611 (org-match-string-no-properties 1)
10614 (defun org-get-tags ()
10615 "Get the list of tags specified in the current headline."
10616 (org-split-string (org-get-tags-string) ":"))
10618 (defun org-get-buffer-tags ()
10619 "Get a table of all tags used in the buffer, for completion."
10622 (goto-char (point-min))
10623 (while (re-search-forward
10624 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
10625 (when (equal (char-after (point-at-bol 0)) ?*)
10626 (mapc (lambda (x) (add-to-list 'tags x))
10627 (org-split-string (org-match-string-no-properties 1) ":")))))
10628 (mapcar 'list tags)))
10630 ;;;; The mapping API
10633 (defun org-map-entries (func &optional match scope &rest skip)
10634 "Call FUNC at each headline selected by MATCH in SCOPE.
10636 FUNC is a function or a lisp form. The function will be called without
10637 arguments, with the cursor positioned at the beginning of the headline.
10638 The return values of all calls to the function will be collected and
10639 returned as a list.
10641 MATCH is a tags/property/todo match as it is used in the agenda tags view.
10642 Only headlines that are matched by this query will be considered during
10643 the iteration. When MATCH is nil or t, all headlines will be
10644 visited by the iteration.
10646 SCOPE determines the scope of this command. It can be any of:
10648 nil The current buffer, respecting the restriction if any
10649 tree The subtree started with the entry at point
10650 file The current buffer, without restriction
10652 The current buffer, and any archives associated with it
10653 agenda All agenda files
10654 agenda-with-archives
10655 All agenda files with any archive files associated with them
10657 If this is a list, all files in the list will be scanned
10659 The remaining args are treated as settings for the skipping facilities of
10660 the scanner. The following items can be given here:
10662 archive skip trees with the archive tag.
10663 comment skip trees with the COMMENT keyword
10664 function or Emacs Lisp form:
10665 will be used as value for `org-agenda-skip-function', so whenever
10666 the the function returns t, FUNC will not be called for that
10667 entry and search will continue from the point where the
10668 function leaves it."
10669 (let* ((org-agenda-archives-mode nil) ; just to make sure
10670 (org-agenda-skip-archived-trees (memq 'archive skip))
10671 (org-agenda-skip-comment-trees (memq 'comment skip))
10672 (org-agenda-skip-function
10673 (car (org-delete-all '(comment archive) skip)))
10674 (org-tags-match-list-sublevels t)
10676 org-todo-keywords-for-agenda
10677 org-done-keywords-for-agenda
10678 org-todo-keyword-alist-for-agenda
10679 org-tag-alist-for-agenda)
10682 ((eq match t) (setq matcher t))
10683 ((eq match nil) (setq matcher t))
10684 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
10688 (when (eq scope 'tree)
10689 (org-back-to-heading t)
10690 (org-narrow-to-subtree)
10695 (org-prepare-agenda-buffers
10696 (list (buffer-file-name (current-buffer))))
10697 (setq res (org-scan-tags func matcher)))
10698 ;; Get the right scope
10700 ((and scope (listp scope) (symbolp (car scope)))
10701 (setq scope (eval scope)))
10702 ((eq scope 'agenda)
10703 (setq scope (org-agenda-files t)))
10704 ((eq scope 'agenda-with-archives)
10705 (setq scope (org-agenda-files t))
10706 (setq scope (org-add-archive-files scope)))
10708 (setq scope (list (buffer-file-name))))
10709 ((eq scope 'file-with-archives)
10710 (setq scope (org-add-archive-files (list (buffer-file-name))))))
10711 (org-prepare-agenda-buffers scope)
10712 (while (setq file (pop scope))
10713 (with-current-buffer (org-find-base-buffer-visiting file)
10717 (goto-char (point-min))
10718 (setq res (append res (org-scan-tags func matcher))))))))))
10723 ;;; Setting and retrieving properties
10725 (defconst org-special-properties
10726 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
10727 "TIMESTAMP" "TIMESTAMP_IA")
10728 "The special properties valid in Org-mode.
10730 These are properties that are not defined in the property drawer,
10731 but in some other way.")
10733 (defconst org-default-properties
10734 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION"
10735 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
10736 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
10737 "EXPORT_FILE_NAME" "EXPORT_TITLE" "ORDERED")
10738 "Some properties that are used by Org-mode for various purposes.
10739 Being in this list makes sure that they are offered for completion.")
10741 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
10742 "Regular expression matching the first line of a property drawer.")
10744 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
10745 "Regular expression matching the first line of a property drawer.")
10747 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
10748 "Regular expression matching the first line of a property drawer.")
10750 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
10751 "Regular expression matching the first line of a property drawer.")
10753 (defconst org-property-drawer-re
10754 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
10755 org-property-end-re "\\)\n?")
10756 "Matches an entire property drawer.")
10758 (defconst org-clock-drawer-re
10759 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
10760 org-property-end-re "\\)\n?")
10761 "Matches an entire clock drawer.")
10763 (defun org-property-action ()
10764 "Do an action on properties."
10767 (org-at-property-p)
10768 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
10769 (setq c (read-char-exclusive))
10772 (call-interactively 'org-set-property))
10774 (call-interactively 'org-delete-property))
10776 (call-interactively 'org-delete-property-globally))
10778 (call-interactively 'org-compute-property-at-point))
10779 (t (error "No such property action %c" c)))))
10781 (defun org-at-property-p ()
10782 "Is the cursor in a property line?"
10783 ;; FIXME: Does not check if we are actually in the drawer.
10784 ;; FIXME: also returns true on any drawers.....
10785 ;; This is used by C-c C-c for property action.
10787 (beginning-of-line 1)
10788 (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))))
10790 (defun org-get-property-block (&optional beg end force)
10791 "Return the (beg . end) range of the body of the property drawer.
10792 BEG and END can be beginning and end of subtree, if not given
10793 they will be found.
10794 If the drawer does not exist and FORCE is non-nil, create the drawer."
10797 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
10798 (end (or end (progn (outline-next-heading) (point)))))
10800 (if (re-search-forward org-property-start-re end t)
10801 (setq beg (1+ (match-end 0)))
10804 (org-insert-property-drawer)
10805 (setq end (progn (outline-next-heading) (point))))
10808 (if (re-search-forward org-property-start-re end t)
10809 (setq beg (1+ (match-end 0)))))
10810 (if (re-search-forward org-property-end-re end t)
10811 (setq end (match-beginning 0))
10812 (or force (throw 'exit nil))
10815 (org-indent-line-function)
10816 (insert ":END:\n"))
10819 (defun org-entry-properties (&optional pom which)
10820 "Get all properties of the entry at point-or-marker POM.
10821 This includes the TODO keyword, the tags, time strings for deadline,
10822 scheduled, and clocking, and any additional properties defined in the
10823 entry. The return value is an alist, keys may occur multiple times
10824 if the property key was used several times.
10825 POM may also be nil, in which case the current entry is used.
10826 If WHICH is nil or `all', get all properties. If WHICH is
10827 `special' or `standard', only get that subclass."
10828 (setq which (or which 'all))
10829 (org-with-point-at pom
10830 (let ((clockstr (substring org-clock-string 0 -1))
10831 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY"))
10832 beg end range props sum-props key value string clocksum)
10834 (when (condition-case nil
10835 (and (org-mode-p) (org-back-to-heading t))
10838 (setq sum-props (get-text-property (point) 'org-summaries))
10839 (setq clocksum (get-text-property (point) :org-clock-minutes))
10840 (outline-next-heading)
10842 (when (memq which '(all special))
10843 ;; Get the special properties, like TODO and tags
10845 (when (and (looking-at org-todo-line-regexp) (match-end 2))
10846 (push (cons "TODO" (org-match-string-no-properties 2)) props))
10847 (when (looking-at org-priority-regexp)
10848 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
10849 (when (and (setq value (org-get-tags-string))
10850 (string-match "\\S-" value))
10851 (push (cons "TAGS" value) props))
10852 (when (setq value (org-get-tags-at))
10853 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":") ":"))
10855 (while (re-search-forward org-maybe-keyword-time-regexp end t)
10856 (setq key (if (match-end 1) (substring (org-match-string-no-properties 1) 0 -1))
10857 string (if (equal key clockstr)
10861 (match-beginning 3) (goto-char (point-at-eol)))))
10862 (substring (org-match-string-no-properties 3) 1 -1)))
10864 (if (= (char-after (match-beginning 3)) ?\[)
10865 (setq key "TIMESTAMP_IA")
10866 (setq key "TIMESTAMP")))
10867 (when (or (equal key clockstr) (not (assoc key props)))
10868 (push (cons key string) props)))
10872 (when (memq which '(all standard))
10873 ;; Get the standard properties, like :PORP: ...
10874 (setq range (org-get-property-block beg end))
10876 (goto-char (car range))
10877 (while (re-search-forward
10878 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
10880 (setq key (org-match-string-no-properties 1)
10881 value (org-trim (or (org-match-string-no-properties 2) "")))
10882 (unless (member key excluded)
10883 (push (cons key (or value "")) props)))))
10885 (push (cons "CLOCKSUM"
10886 (org-columns-number-to-string (/ (float clocksum) 60.)
10889 (unless (assoc "CATEGORY" props)
10890 (setq value (or (org-get-category)
10891 (progn (org-refresh-category-properties)
10892 (org-get-category))))
10893 (push (cons "CATEGORY" value) props))
10894 (append sum-props (nreverse props)))))))
10896 (defun org-entry-get (pom property &optional inherit)
10897 "Get value of PROPERTY for entry at point-or-marker POM.
10898 If INHERIT is non-nil and the entry does not have the property,
10899 then also check higher levels of the hierarchy.
10900 If INHERIT is the symbol `selective', use inheritance only if the setting
10901 in `org-use-property-inheritance' selects PROPERTY for inheritance.
10902 If the property is present but empty, the return value is the empty string.
10903 If the property is not present at all, nil is returned."
10904 (org-with-point-at pom
10905 (if (and inherit (if (eq inherit 'selective)
10906 (org-property-inherit-p property)
10908 (org-entry-get-with-inheritance property)
10909 (if (member property org-special-properties)
10910 ;; We need a special property. Use brute force, get all properties.
10911 (cdr (assoc property (org-entry-properties nil 'special)))
10912 (let ((range (org-get-property-block)))
10914 (goto-char (car range))
10916 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
10918 ;; Found the property, return it.
10920 (org-match-string-no-properties 1)
10923 (defun org-property-or-variable-value (var &optional inherit)
10924 "Check if there is a property fixing the value of VAR.
10925 If yes, return this value. If not, return the current value of the variable."
10926 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
10927 (if (and prop (stringp prop) (string-match "\\S-" prop))
10929 (symbol-value var))))
10931 (defun org-entry-delete (pom property)
10932 "Delete the property PROPERTY from entry at point-or-marker POM."
10933 (org-with-point-at pom
10934 (if (member property org-special-properties)
10935 nil ; cannot delete these properties.
10936 (let ((range (org-get-property-block)))
10938 (goto-char (car range))
10940 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
10943 (delete-region (match-beginning 0) (1+ (point-at-eol)))
10947 ;; Multi-values properties are properties that contain multiple values
10948 ;; These values are assumed to be single words, separated by whitespace.
10949 (defun org-entry-add-to-multivalued-property (pom property value)
10950 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
10951 (let* ((old (org-entry-get pom property))
10952 (values (and old (org-split-string old "[ \t]"))))
10953 (setq value (org-entry-protect-space value))
10954 (unless (member value values)
10955 (setq values (cons value values))
10956 (org-entry-put pom property
10957 (mapconcat 'identity values " ")))))
10959 (defun org-entry-remove-from-multivalued-property (pom property value)
10960 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
10961 (let* ((old (org-entry-get pom property))
10962 (values (and old (org-split-string old "[ \t]"))))
10963 (setq value (org-entry-protect-space value))
10964 (when (member value values)
10965 (setq values (delete value values))
10966 (org-entry-put pom property
10967 (mapconcat 'identity values " ")))))
10969 (defun org-entry-member-in-multivalued-property (pom property value)
10970 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
10971 (let* ((old (org-entry-get pom property))
10972 (values (and old (org-split-string old "[ \t]"))))
10973 (setq value (org-entry-protect-space value))
10974 (member value values)))
10976 (defun org-entry-get-multivalued-property (pom property)
10977 "Return a list of values in a multivalued property."
10978 (let* ((value (org-entry-get pom property))
10979 (values (and value (org-split-string value "[ \t]"))))
10980 (mapcar 'org-entry-restore-space values)))
10982 (defun org-entry-put-multivalued-property (pom property &rest values)
10983 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
10984 VALUES should be a list of strings. Spaces will be protected."
10985 (org-entry-put pom property
10986 (mapconcat 'org-entry-protect-space values " "))
10987 (let* ((value (org-entry-get pom property))
10988 (values (and value (org-split-string value "[ \t]"))))
10989 (mapcar 'org-entry-restore-space values)))
10991 (defun org-entry-protect-space (s)
10992 "Protect spaces and newline in string S."
10993 (while (string-match " " s)
10994 (setq s (replace-match "%20" t t s)))
10995 (while (string-match "\n" s)
10996 (setq s (replace-match "%0A" t t s)))
10999 (defun org-entry-restore-space (s)
11000 "Restore spaces and newline in string S."
11001 (while (string-match "%20" s)
11002 (setq s (replace-match " " t t s)))
11003 (while (string-match "%0A" s)
11004 (setq s (replace-match "\n" t t s)))
11007 (defvar org-entry-property-inherited-from (make-marker)
11008 "Marker pointing to the entry from where a property was inherited.
11009 Each call to `org-entry-get-with-inheritance' will set this marker to the
11010 location of the entry where the inheritance search matched. If there was
11011 no match, the marker will point nowhere.
11012 Note that also `org-entry-get' calls this function, if the INHERIT flag
11015 (defun org-entry-get-with-inheritance (property)
11016 "Get entry property, and search higher levels if not present."
11017 (move-marker org-entry-property-inherited-from nil)
11024 (when (setq tmp (org-entry-get nil property))
11025 (org-back-to-heading t)
11026 (move-marker org-entry-property-inherited-from (point))
11028 (or (org-up-heading-safe) (throw 'ex nil)))))
11030 (cdr (assoc property org-file-properties))
11031 (cdr (assoc property org-global-properties))
11032 (cdr (assoc property org-global-properties-fixed))))))
11034 (defun org-entry-put (pom property value)
11035 "Set PROPERTY to VALUE for entry at point-or-marker POM."
11036 (org-with-point-at pom
11037 (org-back-to-heading t)
11038 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
11041 ((equal property "TODO")
11042 (when (and (stringp value) (string-match "\\S-" value)
11043 (not (member value org-todo-keywords-1)))
11044 (error "\"%s\" is not a valid TODO state" value))
11045 (if (or (not value)
11046 (not (string-match "\\S-" value)))
11047 (setq value 'none))
11049 (org-set-tags nil 'align))
11050 ((equal property "PRIORITY")
11051 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
11052 (string-to-char value) ?\ ))
11053 (org-set-tags nil 'align))
11054 ((equal property "SCHEDULED")
11055 (if (re-search-forward org-scheduled-time-regexp end t)
11057 ((eq value 'earlier) (org-timestamp-change -1 'day))
11058 ((eq value 'later) (org-timestamp-change 1 'day))
11059 (t (call-interactively 'org-schedule)))
11060 (call-interactively 'org-schedule)))
11061 ((equal property "DEADLINE")
11062 (if (re-search-forward org-deadline-time-regexp end t)
11064 ((eq value 'earlier) (org-timestamp-change -1 'day))
11065 ((eq value 'later) (org-timestamp-change 1 'day))
11066 (t (call-interactively 'org-deadline)))
11067 (call-interactively 'org-deadline)))
11068 ((member property org-special-properties)
11069 (error "The %s property can not yet be set with `org-entry-put'"
11071 (t ; a non-special property
11072 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
11073 (setq range (org-get-property-block beg end 'force))
11074 (goto-char (car range))
11075 (if (re-search-forward
11076 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
11078 (delete-region (match-beginning 1) (match-end 1))
11079 (goto-char (match-beginning 1)))
11080 (goto-char (cdr range))
11083 (org-indent-line-function)
11084 (insert ":" property ":"))
11085 (and value (insert " " value))
11086 (org-indent-line-function)))))))
11088 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
11089 "Get all property keys in the current buffer.
11090 With INCLUDE-SPECIALS, also list the special properties that reflect things
11091 like tags and TODO state.
11092 With INCLUDE-DEFAULTS, also include properties that has special meaning
11093 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
11094 With INCLUDE-COLUMNS, also include property names given in COLUMN
11095 formats in the current buffer."
11096 (let (rtn range cfmt s p)
11100 (goto-char (point-min))
11101 (while (re-search-forward org-property-start-re nil t)
11102 (setq range (org-get-property-block))
11103 (goto-char (car range))
11104 (while (re-search-forward
11105 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
11107 (add-to-list 'rtn (org-match-string-no-properties 1)))
11108 (outline-next-heading))))
11110 (when include-specials
11111 (setq rtn (append org-special-properties rtn)))
11113 (when include-defaults
11114 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties))
11116 (when include-columns
11120 (goto-char (point-min))
11121 (while (re-search-forward
11122 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
11124 (setq cfmt (match-string 2) s 0)
11125 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
11127 (setq s (match-end 0)
11128 p (match-string 1 cfmt))
11129 (unless (or (equal p "ITEM")
11130 (member p org-special-properties))
11131 (add-to-list 'rtn (match-string 1 cfmt))))))))
11133 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
11135 (defun org-property-values (key)
11136 "Return a list of all values of property KEY."
11140 (goto-char (point-min))
11141 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
11143 (while (re-search-forward re nil t)
11144 (add-to-list 'values (org-trim (match-string 1))))
11145 (delete "" values)))))
11147 (defun org-insert-property-drawer ()
11148 "Insert a property drawer into the current entry."
11150 (org-back-to-heading t)
11151 (looking-at outline-regexp)
11152 (let ((indent (- (match-end 0)(match-beginning 0)))
11154 (re (concat "^[ \t]*" org-keyword-time-regexp))
11156 (outline-next-heading)
11159 (while (re-search-forward re end t))
11160 (setq hiddenp (org-invisible-p))
11162 (and (equal (char-after) ?\n) (forward-char 1))
11163 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
11164 (if (member (match-string 1) '("CLOCK:" ":END:"))
11165 ;; just skip this line
11166 (beginning-of-line 2)
11167 ;; Drawer start, find the end
11168 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
11169 (beginning-of-line 1)))
11170 (org-skip-over-state-notes)
11171 (skip-chars-backward " \t\n\r")
11172 (if (eq (char-before) ?*) (forward-char 1))
11173 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
11174 (beginning-of-line 0)
11175 (org-indent-to-column indent)
11176 (beginning-of-line 2)
11177 (org-indent-to-column indent)
11178 (beginning-of-line 0)
11181 (org-back-to-heading t)
11183 (org-flag-drawer t))))
11185 (defun org-set-property (property value)
11186 "In the current entry, set PROPERTY to VALUE.
11187 When called interactively, this will prompt for a property name, offering
11188 completion on existing and default properties. And then it will prompt
11189 for a value, offering completion either on allowed values (via an inherited
11190 xxx_ALL property) or on existing values in other instances of this property
11191 in the current file."
11193 (let* ((completion-ignore-case t)
11194 (keys (org-buffer-property-keys nil t t))
11195 (prop0 (org-ido-completing-read "Property: " (mapcar 'list keys)))
11196 (prop (if (member prop0 keys)
11198 (or (cdr (assoc (downcase prop0)
11199 (mapcar (lambda (x) (cons (downcase x) x))
11202 (cur (org-entry-get nil prop))
11203 (allowed (org-property-get-allowed-values nil prop 'table))
11204 (existing (mapcar 'list (org-property-values prop)))
11206 (org-completing-read "Value: " allowed nil 'req-match)
11207 (let (org-completion-use-ido)
11208 (org-completing-read
11209 (concat "Value" (if (and cur (string-match "\\S-" cur))
11210 (concat "[" cur "]") "")
11212 existing nil nil "" nil cur)))))
11213 (list prop (if (equal val "") cur val))))
11214 (unless (equal (org-entry-get nil property) value)
11215 (org-entry-put nil property value)))
11217 (defun org-delete-property (property)
11218 "In the current entry, delete PROPERTY."
11220 (let* ((completion-ignore-case t)
11221 (prop (org-ido-completing-read
11222 "Property: " (org-entry-properties nil 'standard))))
11224 (message "Property %s %s" property
11225 (if (org-entry-delete nil property)
11227 "was not present in the entry")))
11229 (defun org-delete-property-globally (property)
11230 "Remove PROPERTY globally, from all entries."
11232 (let* ((completion-ignore-case t)
11233 (prop (org-ido-completing-read
11234 "Globally remove property: "
11235 (mapcar 'list (org-buffer-property-keys)))))
11240 (goto-char (point-min))
11242 (while (re-search-forward
11243 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
11245 (setq cnt (1+ cnt))
11246 (replace-match ""))
11247 (message "Property \"%s\" removed from %d entries" property cnt)))))
11249 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
11251 (defun org-compute-property-at-point ()
11252 "Compute the property at point.
11253 This looks for an enclosing column format, extracts the operator and
11254 then applies it to the property in the column format's scope."
11256 (unless (org-at-property-p)
11257 (error "Not at a property"))
11258 (let ((prop (org-match-string-no-properties 2)))
11259 (org-columns-get-format-and-top-level)
11260 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
11261 (error "No operator defined for property %s" prop))
11262 (org-columns-compute prop)))
11264 (defun org-property-get-allowed-values (pom property &optional table)
11265 "Get allowed values for the property PROPERTY.
11266 When TABLE is non-nil, return an alist that can directly be used for
11270 ((equal property "TODO")
11271 (setq vals (org-with-point-at pom
11272 (append org-todo-keywords-1 '("")))))
11273 ((equal property "PRIORITY")
11274 (let ((n org-lowest-priority))
11275 (while (>= n org-highest-priority)
11276 (push (char-to-string n) vals)
11278 ((member property org-special-properties))
11280 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
11282 (when (and vals (string-match "\\S-" vals))
11283 (setq vals (car (read-from-string (concat "(" vals ")"))))
11284 (setq vals (mapcar (lambda (x)
11285 (cond ((stringp x) x)
11286 ((numberp x) (number-to-string x))
11287 ((symbolp x) (symbol-name x))
11290 (if table (mapcar 'list vals) vals)))
11292 (defun org-property-previous-allowed-value (&optional previous)
11293 "Switch to the next allowed value for this property."
11295 (org-property-next-allowed-value t))
11297 (defun org-property-next-allowed-value (&optional previous)
11298 "Switch to the next allowed value for this property."
11300 (unless (org-at-property-p)
11301 (error "Not at a property"))
11302 (let* ((key (match-string 2))
11303 (value (match-string 3))
11304 (allowed (or (org-property-get-allowed-values (point) key)
11305 (and (member value '("[ ]" "[-]" "[X]"))
11309 (error "Allowed values for this property have not been defined"))
11310 (if previous (setq allowed (reverse allowed)))
11311 (if (member value allowed)
11312 (setq nval (car (cdr (member value allowed)))))
11313 (setq nval (or nval (car allowed)))
11314 (if (equal nval value)
11315 (error "Only one allowed value for this property"))
11316 (org-at-property-p)
11317 (replace-match (concat " :" key ": " nval) t t)
11318 (org-indent-line-function)
11319 (beginning-of-line 1)
11320 (skip-chars-forward " \t")))
11322 (defun org-find-entry-with-id (ident)
11323 "Locate the entry that contains the ID property with exact value IDENT.
11324 IDENT can be a string, a symbol or a number, this function will search for
11325 the string representation of it.
11326 Return the position where this entry starts, or nil if there is no such entry."
11327 (interactive "sID: ")
11329 ((stringp ident) ident)
11330 ((symbol-name ident) (symbol-name ident))
11331 ((numberp ident) (number-to-string ident))
11332 (t (error "IDENT %s must be a string, symbol or number" ident))))
11333 (case-fold-search nil))
11337 (goto-char (point-min))
11338 (when (re-search-forward
11339 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
11341 (org-back-to-heading)
11346 (defvar org-last-changed-timestamp nil)
11347 (defvar org-last-inserted-timestamp nil
11348 "The last time stamp inserted with `org-insert-time-stamp'.")
11349 (defvar org-time-was-given) ; dynamically scoped parameter
11350 (defvar org-end-time-was-given) ; dynamically scoped parameter
11351 (defvar org-ts-what) ; dynamically scoped parameter
11353 (defun org-time-stamp (arg &optional inactive)
11354 "Prompt for a date/time and insert a time stamp.
11355 If the user specifies a time like HH:MM, or if this command is called
11356 with a prefix argument, the time stamp will contain date and time.
11357 Otherwise, only the date will be included. All parts of a date not
11358 specified by the user will be filled in from the current date/time.
11359 So if you press just return without typing anything, the time stamp
11360 will represent the current date/time. If there is already a timestamp
11361 at the cursor, it will be modified."
11365 ;; Default time is either today, or, when entering a range,
11366 ;; the range start.
11367 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
11369 (re-search-backward
11370 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
11371 (- (point) 20) t)))
11372 (apply 'encode-time (org-parse-time-string (match-string 1)))
11374 (default-input (and ts (org-get-compact-tod ts)))
11375 org-time-was-given org-end-time-was-given time)
11377 ((and (org-at-timestamp-p t)
11378 (memq last-command '(org-time-stamp org-time-stamp-inactive))
11379 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
11381 (setq time (let ((this-command this-command))
11382 (org-read-date arg 'totime nil nil
11383 default-time default-input)))
11384 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
11385 ((org-at-timestamp-p t)
11386 (setq time (let ((this-command this-command))
11387 (org-read-date arg 'totime nil nil default-time default-input)))
11388 (when (org-at-timestamp-p t) ; just to get the match data
11389 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
11391 (setq org-last-changed-timestamp
11392 (org-insert-time-stamp
11393 time (or org-time-was-given arg)
11394 inactive nil nil (list org-end-time-was-given))))
11395 (message "Timestamp updated"))
11397 (setq time (let ((this-command this-command))
11398 (org-read-date arg 'totime nil nil default-time default-input)))
11399 (org-insert-time-stamp time (or org-time-was-given arg) inactive
11400 nil nil (list org-end-time-was-given))))))
11402 ;; FIXME: can we use this for something else, like computing time differences?
11403 (defun org-get-compact-tod (s)
11404 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
11405 (let* ((t1 (match-string 1 s))
11406 (h1 (string-to-number (match-string 2 s)))
11407 (m1 (string-to-number (match-string 3 s)))
11408 (t2 (and (match-end 4) (match-string 5 s)))
11409 (h2 (and t2 (string-to-number (match-string 6 s))))
11410 (m2 (and t2 (string-to-number (match-string 7 s))))
11414 (setq dh (- h2 h1) dm (- m2 m1))
11415 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
11416 (concat t1 "+" (number-to-string dh)
11417 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
11419 (defun org-time-stamp-inactive (&optional arg)
11420 "Insert an inactive time stamp.
11421 An inactive time stamp is enclosed in square brackets instead of angle
11422 brackets. It is inactive in the sense that it does not trigger agenda entries,
11423 does not link to the calendar and cannot be changed with the S-cursor keys.
11424 So these are more for recording a certain time/date."
11426 (org-time-stamp arg 'inactive))
11428 (defvar org-date-ovl (org-make-overlay 1 1))
11429 (org-overlay-put org-date-ovl 'face 'org-warning)
11430 (org-detach-overlay org-date-ovl)
11432 (defvar org-ans1) ; dynamically scoped parameter
11433 (defvar org-ans2) ; dynamically scoped parameter
11435 (defvar org-plain-time-of-day-regexp) ; defined below
11437 (defvar org-overriding-default-time nil) ; dynamically scoped
11438 (defvar org-read-date-overlay nil)
11439 (defvar org-dcst nil) ; dynamically scoped
11441 (defun org-read-date (&optional with-time to-time from-string prompt
11442 default-time default-input)
11443 "Read a date, possibly a time, and make things smooth for the user.
11444 The prompt will suggest to enter an ISO date, but you can also enter anything
11445 which will at least partially be understood by `parse-time-string'.
11446 Unrecognized parts of the date will default to the current day, month, year,
11447 hour and minute. If this command is called to replace a timestamp at point,
11448 of to enter the second timestamp of a range, the default time is taken from the
11449 existing stamp. For example,
11450 3-2-5 --> 2003-02-05
11451 feb 15 --> currentyear-02-15
11452 sep 12 9 --> 2009-09-12
11453 12:45 --> today 12:45
11454 22 sept 0:34 --> currentyear-09-22 0:34
11455 12 --> currentyear-currentmonth-12
11456 Fri --> nearest Friday (today or later)
11459 Furthermore you can specify a relative date by giving, as the *first* thing
11460 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
11461 change in days weeks, months, years.
11462 With a single plus or minus, the date is relative to today. With a double
11463 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
11464 +4d --> four days from today
11465 +4 --> same as above
11466 +2w --> two weeks from today
11467 ++5 --> five days from default date
11469 The function understands only English month and weekday abbreviations,
11470 but this can be configured with the variables `parse-time-months' and
11471 `parse-time-weekdays'.
11473 While prompting, a calendar is popped up - you can also select the
11474 date with the mouse (button 1). The calendar shows a period of three
11475 months. To scroll it to other months, use the keys `>' and `<'.
11476 If you don't like the calendar, turn it off with
11477 \(setq org-read-date-popup-calendar nil)
11479 With optional argument TO-TIME, the date will immediately be converted
11480 to an internal time.
11481 With an optional argument WITH-TIME, the prompt will suggest to also
11482 insert a time. Note that when WITH-TIME is not set, you can still
11483 enter a time, and this function will inform the calling routine about
11484 this change. The calling routine may then choose to change the format
11485 used to insert the time stamp into the buffer to include the time.
11486 With optional argument FROM-STRING, read from this string instead from
11487 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
11488 the time/date that is used for everything that is not specified by the
11490 (require 'parse-time)
11491 (let* ((org-time-stamp-rounding-minutes
11492 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
11493 (org-dcst org-display-custom-times)
11494 (ct (org-current-time))
11495 (def (or org-overriding-default-time default-time ct))
11496 (defdecode (decode-time def))
11498 (when (< (nth 2 defdecode) org-extend-today-until)
11499 (setcar (nthcdr 2 defdecode) -1)
11500 (setcar (nthcdr 1 defdecode) 59)
11501 (setq def (apply 'encode-time defdecode)
11502 defdecode (decode-time def)))))
11503 (calendar-move-hook nil)
11504 (calendar-view-diary-initially-flag nil)
11505 (view-diary-entries-initially nil)
11506 (calendar-view-holidays-initially-flag nil)
11507 (view-calendar-holidays-initially nil)
11508 (timestr (format-time-string
11509 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
11510 (prompt (concat (if prompt (concat prompt " ") "")
11511 (format "Date+time [%s]: " timestr)))
11512 ans (org-ans0 "") org-ans1 org-ans2 final)
11515 (from-string (setq ans from-string))
11516 (org-read-date-popup-calendar
11518 (save-window-excursion
11520 (calendar-forward-day (- (time-to-days def)
11521 (calendar-absolute-from-gregorian
11522 (calendar-current-date))))
11523 (org-eval-in-calendar nil t)
11524 (let* ((old-map (current-local-map))
11525 (map (copy-keymap calendar-mode-map))
11526 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
11527 (org-defkey map (kbd "RET") 'org-calendar-select)
11528 (org-defkey map (if (featurep 'xemacs) [button1] [mouse-1])
11529 'org-calendar-select-mouse)
11530 (org-defkey map (if (featurep 'xemacs) [button2] [mouse-2
])
11531 'org-calendar-select-mouse
)
11532 (org-defkey minibuffer-local-map
[(meta shift left
)]
11533 (lambda () (interactive)
11534 (org-eval-in-calendar '(calendar-backward-month 1))))
11535 (org-defkey minibuffer-local-map
[(meta shift right
)]
11536 (lambda () (interactive)
11537 (org-eval-in-calendar '(calendar-forward-month 1))))
11538 (org-defkey minibuffer-local-map
[(meta shift up
)]
11539 (lambda () (interactive)
11540 (org-eval-in-calendar '(calendar-backward-year 1))))
11541 (org-defkey minibuffer-local-map
[(meta shift down
)]
11542 (lambda () (interactive)
11543 (org-eval-in-calendar '(calendar-forward-year 1))))
11544 (org-defkey minibuffer-local-map
[(shift up
)]
11545 (lambda () (interactive)
11546 (org-eval-in-calendar '(calendar-backward-week 1))))
11547 (org-defkey minibuffer-local-map
[(shift down
)]
11548 (lambda () (interactive)
11549 (org-eval-in-calendar '(calendar-forward-week 1))))
11550 (org-defkey minibuffer-local-map
[(shift left
)]
11551 (lambda () (interactive)
11552 (org-eval-in-calendar '(calendar-backward-day 1))))
11553 (org-defkey minibuffer-local-map
[(shift right
)]
11554 (lambda () (interactive)
11555 (org-eval-in-calendar '(calendar-forward-day 1))))
11556 (org-defkey minibuffer-local-map
">"
11557 (lambda () (interactive)
11558 (org-eval-in-calendar '(scroll-calendar-left 1))))
11559 (org-defkey minibuffer-local-map
"<"
11560 (lambda () (interactive)
11561 (org-eval-in-calendar '(scroll-calendar-right 1))))
11564 (use-local-map map
)
11565 (add-hook 'post-command-hook
'org-read-date-display
)
11566 (setq org-ans0
(read-string prompt default-input nil nil
))
11567 ;; org-ans0: from prompt
11568 ;; org-ans1: from mouse click
11569 ;; org-ans2: from calendar motion
11570 (setq ans
(concat org-ans0
" " (or org-ans1 org-ans2
))))
11571 (remove-hook 'post-command-hook
'org-read-date-display
)
11572 (use-local-map old-map
)
11573 (when org-read-date-overlay
11574 (org-delete-overlay org-read-date-overlay
)
11575 (setq org-read-date-overlay nil
)))))))
11577 (t ; Naked prompt only
11579 (setq ans
(read-string prompt default-input nil timestr
))
11580 (when org-read-date-overlay
11581 (org-delete-overlay org-read-date-overlay
)
11582 (setq org-read-date-overlay nil
)))))
11584 (setq final
(org-read-date-analyze ans def defdecode
))
11587 (apply 'encode-time final
)
11588 (if (and (boundp 'org-time-was-given
) org-time-was-given
)
11589 (format "%04d-%02d-%02d %02d:%02d"
11590 (nth 5 final
) (nth 4 final
) (nth 3 final
)
11591 (nth 2 final
) (nth 1 final
))
11592 (format "%04d-%02d-%02d" (nth 5 final
) (nth 4 final
) (nth 3 final
))))))
11596 (defun org-read-date-display ()
11597 "Display the current date prompt interpretation in the minibuffer."
11598 (when org-read-date-display-live
11599 (when org-read-date-overlay
11600 (org-delete-overlay org-read-date-overlay
))
11603 (while (not (equal (buffer-substring
11604 (max (point-min) (- (point) 4)) (point))
11608 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
11609 " " (or org-ans1 org-ans2
)))
11610 (org-end-time-was-given nil
)
11611 (f (org-read-date-analyze ans def defdecode
))
11613 org-time-stamp-custom-formats
11614 org-time-stamp-formats
))
11615 (fmt (if (or with-time
11616 (and (boundp 'org-time-was-given
) org-time-was-given
))
11619 (txt (concat "=> " (format-time-string fmt
(apply 'encode-time f
)))))
11620 (when (and org-end-time-was-given
11621 (string-match org-plain-time-of-day-regexp txt
))
11622 (setq txt
(concat (substring txt
0 (match-end 0)) "-"
11623 org-end-time-was-given
11624 (substring txt
(match-end 0)))))
11625 (setq org-read-date-overlay
11626 (org-make-overlay (1- (point-at-eol)) (point-at-eol)))
11627 (org-overlay-display org-read-date-overlay txt
'secondary-selection
))))
11629 (defun org-read-date-analyze (ans def defdecode
)
11630 "Analyse the combined answer of the date prompt."
11631 ;; FIXME: cleanup and comment
11632 (let (delta deltan deltaw deltadef year month day
11633 hour minute second wday pm h2 m2 tl wday1
11634 iso-year iso-weekday iso-week iso-year iso-date
)
11636 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans
)
11639 (when (setq delta
(org-read-date-get-relative ans
(current-time) def
))
11640 (setq ans
(replace-match "" t t ans
)
11642 deltaw
(nth 1 delta
)
11643 deltadef
(nth 2 delta
)))
11645 ;; Check if there is an iso week date in there
11646 ;; If yes, sore the info and postpone interpreting it until the rest
11647 ;; of the parsing is done
11648 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans
)
11649 (setq iso-year
(if (match-end 1) (org-small-year-to-year (string-to-number (match-string 1 ans
))))
11650 iso-weekday
(if (match-end 3) (string-to-number (match-string 3 ans
)))
11651 iso-week
(string-to-number (match-string 2 ans
)))
11652 (setq ans
(replace-match "" t t ans
)))
11654 ;; Help matching ISO dates with single digit month ot day, like 2006-8-11.
11655 (when (string-match
11656 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans
)
11657 (setq year
(if (match-end 2)
11658 (string-to-number (match-string 2 ans
))
11659 (string-to-number (format-time-string "%Y")))
11660 month
(string-to-number (match-string 3 ans
))
11661 day
(string-to-number (match-string 4 ans
)))
11662 (if (< year
100) (setq year
(+ 2000 year
)))
11663 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
11665 ;; Help matching am/pm times, because `parse-time-string' does not do that.
11666 ;; If there is a time with am/pm, and *no* time without it, we convert
11667 ;; so that matching will be successful.
11668 (loop for i from
1 to
2 do
; twice, for end time as well
11669 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans
))
11670 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans
))
11671 (setq hour
(string-to-number (match-string 1 ans
))
11672 minute
(if (match-end 3)
11673 (string-to-number (match-string 3 ans
))
11676 (string-to-char (downcase (match-string 4 ans
)))))
11677 (if (and (= hour
12) (not pm
))
11679 (if (and pm
(< hour
12)) (setq hour
(+ 12 hour
))))
11680 (setq ans
(replace-match (format "%02d:%02d" hour minute
)
11683 ;; Check if a time range is given as a duration
11684 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans
)
11685 (setq hour
(string-to-number (match-string 1 ans
))
11686 h2
(+ hour
(string-to-number (match-string 3 ans
)))
11687 minute
(string-to-number (match-string 2 ans
))
11688 m2
(+ minute
(if (match-end 5) (string-to-number
11689 (match-string 5 ans
))0)))
11690 (if (>= m2
60) (setq h2
(1+ h2
) m2
(- m2
60)))
11691 (setq ans
(replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2
)
11694 ;; Check if there is a time range
11695 (when (boundp 'org-end-time-was-given
)
11696 (setq org-time-was-given nil
)
11697 (when (and (string-match org-plain-time-of-day-regexp ans
)
11699 (setq org-end-time-was-given
(match-string 8 ans
))
11700 (setq ans
(concat (substring ans
0 (match-beginning 7))
11701 (substring ans
(match-end 7))))))
11703 (setq tl
(parse-time-string ans
)
11704 day
(or (nth 3 tl
) (nth 3 defdecode
))
11705 month
(or (nth 4 tl
)
11706 (if (and org-read-date-prefer-future
11707 (nth 3 tl
) (< (nth 3 tl
) (nth 3 defdecode
)))
11708 (1+ (nth 4 defdecode
))
11709 (nth 4 defdecode
)))
11710 year
(or (nth 5 tl
)
11711 (if (and org-read-date-prefer-future
11712 (nth 4 tl
) (< (nth 4 tl
) (nth 4 defdecode
)))
11713 (1+ (nth 5 defdecode
))
11714 (nth 5 defdecode
)))
11715 hour
(or (nth 2 tl
) (nth 2 defdecode
))
11716 minute
(or (nth 1 tl
) (nth 1 defdecode
))
11717 second
(or (nth 0 tl
) 0)
11720 ;; Special date definitions below
11723 ;; There was an iso week
11724 (setq year
(or iso-year year
)
11725 day
(or iso-weekday wday
1)
11726 wday nil
; to make sure that the trigger below does not match
11727 iso-date
(calendar-gregorian-from-absolute
11728 (calendar-absolute-from-iso
11729 (list iso-week day year
))))
11730 ; FIXME: Should we also push ISO weeks into the future?
11731 ; (when (and org-read-date-prefer-future
11733 ; (< (calendar-absolute-from-gregorian iso-date)
11734 ; (time-to-days (current-time))))
11735 ; (setq year (1+ year)
11736 ; iso-date (calendar-gregorian-from-absolute
11737 ; (calendar-absolute-from-iso
11738 ; (list iso-week day year)))))
11739 (setq month
(car iso-date
)
11740 year
(nth 2 iso-date
)
11741 day
(nth 1 iso-date
)))
11744 (let ((now (decode-time (current-time))))
11745 (setq day
(nth 3 now
) month
(nth 4 now
) year
(nth 5 now
))))
11746 (cond ((member deltaw
'("d" "")) (setq day
(+ day deltan
)))
11747 ((equal deltaw
"w") (setq day
(+ day
(* 7 deltan
))))
11748 ((equal deltaw
"m") (setq month
(+ month deltan
)))
11749 ((equal deltaw
"y") (setq year
(+ year deltan
)))))
11750 ((and wday
(not (nth 3 tl
)))
11751 ;; Weekday was given, but no day, so pick that day in the week
11752 ;; on or after the derived date.
11753 (setq wday1
(nth 6 (decode-time (encode-time 0 0 0 day month year
))))
11754 (unless (equal wday wday1
)
11755 (setq day
(+ day
(%
(- wday wday1 -
7) 7))))))
11756 (if (and (boundp 'org-time-was-given
)
11758 (setq org-time-was-given t
))
11759 (if (< year
100) (setq year
(+ 2000 year
)))
11760 (if (< year
1970) (setq year
(nth 5 defdecode
))) ; not representable
11761 (list second minute hour day month year
)))
11763 (defvar parse-time-weekdays
)
11765 (defun org-read-date-get-relative (s today default
)
11766 "Check string S for special relative date string.
11767 TODAY and DEFAULT are internal times, for today and for a default.
11768 Return shift list (N what def-flag)
11769 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
11770 N is the number of WHATs to shift.
11771 DEF-FLAG is t when a double ++ or -- indicates shift relative to
11772 the DEFAULT date rather than TODAY."
11776 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
11778 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays
"\\|") "\\)\\)?"
11779 "\\([ \t]\\|$\\)") s
)
11780 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
11781 (let* ((dir (if (> (match-end 1) (match-beginning 1))
11782 (string-to-char (substring (match-string 1 s
) -
1))
11784 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
11785 (n (if (match-end 2) (string-to-number (match-string 2 s
)) 1))
11786 (what (if (match-end 3) (match-string 3 s
) "d"))
11787 (wday1 (cdr (assoc (downcase what
) parse-time-weekdays
)))
11788 (date (if rel default today
))
11789 (wday (nth 6 (decode-time date
)))
11793 (setq delta
(mod (+ 7 (- wday1 wday
)) 7))
11794 (if (= dir ?-
) (setq delta
(- delta
7)))
11795 (if (> n
1) (setq delta
(+ delta
(* (1- n
) (if (= dir ?-
) -
7 7)))))
11796 (list delta
"d" rel
))
11797 (list (* n
(if (= dir ?-
) -
1 1)) what rel
)))))
11799 (defun org-eval-in-calendar (form &optional keepdate
)
11800 "Eval FORM in the calendar window and return to current window.
11801 Also, store the cursor date in variable org-ans2."
11802 (let ((sw (selected-window)))
11803 (select-window (get-buffer-window "*Calendar*"))
11805 (when (and (not keepdate
) (calendar-cursor-to-date))
11806 (let* ((date (calendar-cursor-to-date))
11807 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
11808 (setq org-ans2
(format-time-string "%Y-%m-%d" time
))))
11809 (org-move-overlay org-date-ovl
(1- (point)) (1+ (point)) (current-buffer))
11810 (select-window sw
)))
11812 (defun org-calendar-select ()
11813 "Return to `org-read-date' with the date currently selected.
11814 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
11816 (when (calendar-cursor-to-date)
11817 (let* ((date (calendar-cursor-to-date))
11818 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
11819 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
11820 (if (active-minibuffer-window) (exit-minibuffer))))
11822 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra
)
11823 "Insert a date stamp for the date given by the internal TIME.
11824 WITH-HM means, use the stamp format that includes the time of the day.
11825 INACTIVE means use square brackets instead of angular ones, so that the
11826 stamp will not contribute to the agenda.
11827 PRE and POST are optional strings to be inserted before and after the
11829 The command returns the inserted time stamp."
11830 (let ((fmt (funcall (if with-hm
'cdr
'car
) org-time-stamp-formats
))
11832 (if inactive
(setq fmt
(concat "[" (substring fmt
1 -
1) "]")))
11833 (insert-before-markers (or pre
""))
11834 (insert-before-markers (setq stamp
(format-time-string fmt time
)))
11835 (when (listp extra
)
11836 (setq extra
(car extra
))
11837 (if (and (stringp extra
)
11838 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra
))
11839 (setq extra
(format "-%02d:%02d"
11840 (string-to-number (match-string 1 extra
))
11841 (string-to-number (match-string 2 extra
))))
11845 (insert-before-markers extra
)
11847 (insert-before-markers (or post
""))
11848 (setq org-last-inserted-timestamp stamp
)))
11850 (defun org-toggle-time-stamp-overlays ()
11851 "Toggle the use of custom time stamp formats."
11853 (setq org-display-custom-times
(not org-display-custom-times
))
11854 (unless org-display-custom-times
11855 (let ((p (point-min)) (bmp (buffer-modified-p)))
11856 (while (setq p
(next-single-property-change p
'display
))
11857 (if (and (get-text-property p
'display
)
11858 (eq (get-text-property p
'face
) 'org-date
))
11859 (remove-text-properties
11860 p
(setq p
(next-single-property-change p
'display
))
11862 (set-buffer-modified-p bmp
)))
11863 (if (featurep 'xemacs
)
11864 (remove-text-properties (point-min) (point-max) '(end-glyph t
)))
11865 (org-restart-font-lock)
11866 (setq org-table-may-need-update t
)
11867 (if org-display-custom-times
11868 (message "Time stamps are overlayed with custom format")
11869 (message "Time stamp overlays removed")))
11871 (defun org-display-custom-time (beg end
)
11872 "Overlay modified time stamp format over timestamp between BEG and END."
11873 (let* ((ts (buffer-substring beg end
))
11874 t1 w1 with-hm tf time str w2
(off 0))
11876 (setq t1
(org-parse-time-string ts t
))
11877 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\)?\\'" ts
)
11878 (setq off
(- (match-end 0) (match-beginning 0)))))
11879 (setq end
(- end off
))
11880 (setq w1
(- end beg
)
11881 with-hm
(and (nth 1 t1
) (nth 2 t1
))
11882 tf
(funcall (if with-hm
'cdr
'car
) org-time-stamp-custom-formats
)
11883 time
(org-fix-decoded-time t1
)
11885 (format-time-string
11886 (substring tf
1 -
1) (apply 'encode-time time
))
11887 nil
'mouse-face
'highlight
)
11889 (if (not (= w2 w1
))
11890 (add-text-properties (1+ beg
) (+ 2 beg
)
11891 (list 'org-dwidth t
'org-dwidth-n
(- w1 w2
))))
11892 (if (featurep 'xemacs
)
11894 (put-text-property beg end
'invisible t
)
11895 (put-text-property beg end
'end-glyph
(make-glyph str
)))
11896 (put-text-property beg end
'display str
))))
11898 (defun org-translate-time (string)
11899 "Translate all timestamps in STRING to custom format.
11900 But do this only if the variable `org-display-custom-times' is set."
11901 (when org-display-custom-times
11904 (re org-ts-regexp-both
)
11905 t1 with-hm inactive tf time str beg end
)
11906 (while (setq start
(string-match re string start
))
11907 (setq beg
(match-beginning 0)
11909 t1
(save-match-data
11910 (org-parse-time-string (substring string beg end
) t
))
11911 with-hm
(and (nth 1 t1
) (nth 2 t1
))
11912 inactive
(equal (substring string beg
(1+ beg
)) "[")
11913 tf
(funcall (if with-hm
'cdr
'car
)
11914 org-time-stamp-custom-formats
)
11915 time
(org-fix-decoded-time t1
)
11916 str
(format-time-string
11918 (if inactive
"[" "<") (substring tf
1 -
1)
11919 (if inactive
"]" ">"))
11920 (apply 'encode-time time
))
11921 string
(replace-match str t t string
)
11922 start
(+ start
(length str
)))))))
11925 (defun org-fix-decoded-time (time)
11926 "Set 0 instead of nil for the first 6 elements of time.
11927 Don't touch the rest."
11929 (mapcar (lambda (x) (if (< (setq n
(1+ n
)) 7) (or x
0) x
)) time
)))
11931 (defun org-days-to-time (timestamp-string)
11932 "Difference between TIMESTAMP-STRING and now in days."
11933 (- (time-to-days (org-time-string-to-time timestamp-string
))
11934 (time-to-days (current-time))))
11936 (defun org-deadline-close (timestamp-string &optional ndays
)
11937 "Is the time in TIMESTAMP-STRING close to the current date?"
11938 (setq ndays
(or ndays
(org-get-wdays timestamp-string
)))
11939 (and (< (org-days-to-time timestamp-string
) ndays
)
11940 (not (org-entry-is-done-p))))
11942 (defun org-get-wdays (ts)
11943 "Get the deadline lead time appropriate for timestring TS."
11945 ((<= org-deadline-warning-days
0)
11946 ;; 0 or negative, enforce this value no matter what
11947 (- org-deadline-warning-days
))
11948 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts
)
11949 ;; lead time is specified.
11950 (floor (* (string-to-number (match-string 1 ts
))
11951 (cdr (assoc (match-string 2 ts
)
11952 '(("d" .
1) ("w" .
7)
11953 ("m" .
30.4) ("y" .
365.25)))))))
11954 ;; go for the default.
11955 (t org-deadline-warning-days
)))
11957 (defun org-calendar-select-mouse (ev)
11958 "Return to `org-read-date' with the date currently selected.
11959 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
11961 (mouse-set-point ev
)
11962 (when (calendar-cursor-to-date)
11963 (let* ((date (calendar-cursor-to-date))
11964 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
11965 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
11966 (if (active-minibuffer-window) (exit-minibuffer))))
11968 (defun org-check-deadlines (ndays)
11969 "Check if there are any deadlines due or past due.
11970 A deadline is considered due if it happens within `org-deadline-warning-days'
11971 days from today's date. If the deadline appears in an entry marked DONE,
11972 it is not shown. The prefix arg NDAYS can be used to test that many
11973 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
11975 (let* ((org-warn-days
11977 ((equal ndays
'(4)) 100000)
11978 (ndays (prefix-numeric-value ndays
))
11979 (t (abs org-deadline-warning-days
))))
11980 (case-fold-search nil
)
11981 (regexp (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>"))
11983 (lambda () (org-deadline-close (match-string 1) org-warn-days
))))
11985 (message "%d deadlines past-due or due within %d days"
11986 (org-occur regexp nil callback
)
11989 (defun org-check-before-date (date)
11990 "Check if there are deadlines or scheduled entries before DATE."
11991 (interactive (list (org-read-date)))
11992 (let ((case-fold-search nil
)
11993 (regexp (concat "\\<\\(" org-deadline-string
11994 "\\|" org-scheduled-string
11995 "\\) *<\\([^>]+\\)>"))
11997 (lambda () (time-less-p
11998 (org-time-string-to-time (match-string 2))
11999 (org-time-string-to-time date
)))))
12000 (message "%d entries before %s"
12001 (org-occur regexp nil callback
) date
)))
12003 (defun org-evaluate-time-range (&optional to-buffer
)
12004 "Evaluate a time range by computing the difference between start and end.
12005 Normally the result is just printed in the echo area, but with prefix arg
12006 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
12007 If the time range is actually in a table, the result is inserted into the
12009 For time difference computation, a year is assumed to be exactly 365
12010 days in order to avoid rounding problems."
12013 (org-clock-update-time-maybe)
12015 (unless (org-at-date-range-p t
)
12016 (goto-char (point-at-bol))
12017 (re-search-forward org-tr-regexp-both
(point-at-eol) t
))
12018 (if (not (org-at-date-range-p t
))
12019 (error "Not at a time-stamp range, and none found in current line")))
12020 (let* ((ts1 (match-string 1))
12021 (ts2 (match-string 2))
12022 (havetime (or (> (length ts1
) 15) (> (length ts2
) 15)))
12023 (match-end (match-end 0))
12024 (time1 (org-time-string-to-time ts1
))
12025 (time2 (org-time-string-to-time ts2
))
12026 (t1 (time-to-seconds time1
))
12027 (t2 (time-to-seconds time2
))
12028 (diff (abs (- t2 t1
)))
12029 (negative (< (- t2 t1
) 0))
12030 ;; (ys (floor (* 365 24 60 60)))
12033 (fy "%dy %dd %02d:%02d")
12035 (fd "%dd %02d:%02d")
12040 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
12042 d
(floor (/ diff ds
)) diff
(mod diff ds
)
12043 h
(floor (/ diff hs
)) diff
(mod diff hs
)
12044 m
(floor (/ diff
60)))
12045 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
12047 d
(floor (+ (/ diff ds
) 0.5))
12049 (if (not to-buffer
)
12050 (message "%s" (org-make-tdiff-string y d h m
))
12051 (if (org-at-table-p)
12053 (goto-char match-end
)
12055 (and (looking-at " *|") (goto-char (match-end 0))))
12056 (goto-char match-end
))
12058 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
12059 (replace-match ""))
12060 (if negative
(insert " -"))
12061 (if (> y
0) (insert " " (format (if havetime fy fy1
) y d h m
))
12062 (if (> d
0) (insert " " (format (if havetime fd fd1
) d h m
))
12063 (insert " " (format fh h m
))))
12064 (if align
(org-table-align))
12065 (message "Time difference inserted")))))
12067 (defun org-make-tdiff-string (y d h m
)
12070 (if (> y
0) (setq fmt
(concat fmt
"%d year" (if (> y
1) "s" "") " ")
12072 (if (> d
0) (setq fmt
(concat fmt
"%d day" (if (> d
1) "s" "") " ")
12074 (if (> h
0) (setq fmt
(concat fmt
"%d hour" (if (> h
1) "s" "") " ")
12076 (if (> m
0) (setq fmt
(concat fmt
"%d minute" (if (> m
1) "s" "") " ")
12078 (apply 'format fmt
(nreverse l
))))
12080 (defun org-time-string-to-time (s)
12081 (apply 'encode-time
(org-parse-time-string s
)))
12083 (defun org-time-string-to-absolute (s &optional daynr prefer show-all
)
12084 "Convert a time stamp to an absolute day number.
12085 If there is a specifyer for a cyclic time stamp, get the closest date to
12087 PREFER and SHOW-ALL are passed through to `org-closest-date'."
12089 ((and daynr
(string-match "\\`%%\\((.*)\\)" s
))
12090 (if (org-diary-sexp-entry (match-string 1 s
) "" date
)
12093 ((and daynr
(string-match "\\+[0-9]+[dwmy]" s
))
12094 (org-closest-date s
(if (and (boundp 'daynr
) (integerp daynr
)) daynr
12095 (time-to-days (current-time))) (match-string 0 s
)
12097 (t (time-to-days (apply 'encode-time
(org-parse-time-string s
))))))
12099 (defun org-days-to-iso-week (days)
12100 "Return the iso week number."
12102 (car (calendar-iso-from-absolute days
)))
12104 (defun org-small-year-to-year (year)
12105 "Convert 2-digit years into 4-digit years.
12106 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
12107 The year 2000 cannot be abbreviated. Any year larger than 99
12108 is returned unchanged."
12110 (setq year
(+ 2000 year
))
12112 (setq year
(+ 1900 year
))))
12115 (defun org-time-from-absolute (d)
12116 "Return the time corresponding to date D.
12117 D may be an absolute day number, or a calendar-type list (month day year)."
12118 (if (numberp d
) (setq d
(calendar-gregorian-from-absolute d
)))
12119 (encode-time 0 0 0 (nth 1 d
) (car d
) (nth 2 d
)))
12121 (defun org-calendar-holiday ()
12122 "List of holidays, for Diary display in Org-mode."
12123 (require 'holidays
)
12125 (if (fboundp 'calendar-check-holidays
)
12126 'calendar-check-holidays
'check-calendar-holidays
) date
)))
12127 (if hl
(mapconcat 'identity hl
"; "))))
12129 (defun org-diary-sexp-entry (sexp entry date
)
12130 "Process a SEXP diary ENTRY for DATE."
12131 (require 'diary-lib
)
12132 (let ((result (if calendar-debug-sexp
12133 (let ((stack-trace-on-error t
))
12134 (eval (car (read-from-string sexp
))))
12135 (condition-case nil
12136 (eval (car (read-from-string sexp
)))
12139 (message "Bad sexp at line %d in %s: %s"
12141 (buffer-file-name) sexp
)
12143 (cond ((stringp result
) result
)
12144 ((and (consp result
)
12145 (stringp (cdr result
))) (cdr result
))
12149 (defun org-diary-to-ical-string (frombuf)
12150 "Get iCalendar entries from diary entries in buffer FROMBUF.
12151 This uses the icalendar.el library."
12152 (let* ((tmpdir (if (featurep 'xemacs
)
12154 temporary-file-directory
))
12155 (tmpfile (make-temp-name
12156 (expand-file-name "orgics" tmpdir
)))
12159 (set-buffer frombuf
)
12160 (icalendar-export-region (point-min) (point-max) tmpfile
)
12161 (setq buf
(find-buffer-visiting tmpfile
))
12163 (goto-char (point-min))
12164 (if (re-search-forward "^BEGIN:VEVENT" nil t
)
12165 (setq b
(match-beginning 0)))
12166 (goto-char (point-max))
12167 (if (re-search-backward "^END:VEVENT" nil t
)
12168 (setq e
(match-end 0)))
12169 (setq rtn
(if (and b e
) (concat (buffer-substring b e
) "\n") "")))
12171 (delete-file tmpfile
)
12174 (defun org-closest-date (start current change prefer show-all
)
12175 "Find the date closest to CURRENT that is consistent with START and CHANGE.
12176 When PREFER is `past' return a date that is either CURRENT or past.
12177 When PREFER is `future', return a date that is either CURRENT or future.
12178 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
12179 ;; Make the proper lists from the dates
12181 (let ((a1 '(("d" . day
) ("w" . week
) ("m" . month
) ("y" . year
)))
12182 dn dw sday cday n1 n2 n0
12183 d m y y1 y2 date1 date2 nmonths nm ny m2
)
12185 (setq start
(org-date-to-gregorian start
)
12186 current
(org-date-to-gregorian
12189 (time-to-days (current-time))))
12190 sday
(calendar-absolute-from-gregorian start
)
12191 cday
(calendar-absolute-from-gregorian current
))
12193 (if (<= cday sday
) (throw 'exit sday
))
12195 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change
)
12196 (setq dn
(string-to-number (match-string 1 change
))
12197 dw
(cdr (assoc (match-string 2 change
) a1
)))
12198 (error "Invalid change specifyer: %s" change
))
12199 (if (eq dw
'week
) (setq dw
'day dn
(* 7 dn
)))
12202 (setq n1
(+ sday
(* dn
(floor (/ (- cday sday
) dn
))))
12205 (setq d
(nth 1 start
) m
(car start
) y1
(nth 2 start
) y2
(nth 2 current
))
12206 (setq y1
(+ (* (floor (/ (- y2 y1
) dn
)) dn
) y1
))
12207 (setq date1
(list m d y1
)
12208 n1
(calendar-absolute-from-gregorian date1
)
12209 date2
(list m d
(+ y1
(* (if (< n1 cday
) 1 -
1) dn
)))
12210 n2
(calendar-absolute-from-gregorian date2
)))
12212 ;; approx number of month between the two dates
12213 (setq nmonths
(floor (/ (- cday sday
) 30.436875)))
12214 ;; How often does dn fit in there?
12215 (setq d
(nth 1 start
) m
(car start
) y
(nth 2 start
)
12216 nm
(* dn
(max 0 (1- (floor (/ nmonths dn
)))))
12218 ny
(floor (/ m
12))
12221 (while (> m
12) (setq m
(- m
12) y
(1+ y
)))
12222 (setq n1
(calendar-absolute-from-gregorian (list m d y
)))
12223 (setq m2
(+ m dn
) y2 y
)
12224 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
12225 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
)))
12226 (while (<= n2 cday
)
12227 (setq n1 n2 m m2 y y2
)
12228 (setq m2
(+ m dn
) y2 y
)
12229 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
12230 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
))))))
12231 ;; Make sure n1 is the earlier date
12232 (setq n0 n1 n1
(min n1 n2
) n2
(max n0 n2
))
12235 ((eq prefer
'past
) n1
)
12236 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
12237 (t (if (> (abs (- cday n1
)) (abs (- cday n2
))) n2 n1
)))
12239 ((eq prefer
'past
) n1
)
12240 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
12241 (t (if (= cday n1
) n1 n2
)))))))
12243 (defun org-date-to-gregorian (date)
12244 "Turn any specification of DATE into a gregorian date for the calendar."
12245 (cond ((integerp date
) (calendar-gregorian-from-absolute date
))
12246 ((and (listp date
) (= (length date
) 3)) date
)
12248 (setq date
(org-parse-time-string date
))
12249 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))
12251 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))))
12253 (defun org-parse-time-string (s &optional nodefault
)
12254 "Parse the standard Org-mode time string.
12255 This should be a lot faster than the normal `parse-time-string'.
12256 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
12257 hour and minute fields will be nil if not given."
12258 (if (string-match org-ts-regexp0 s
)
12260 (if (or (match-beginning 8) (not nodefault
))
12261 (string-to-number (or (match-string 8 s
) "0")))
12262 (if (or (match-beginning 7) (not nodefault
))
12263 (string-to-number (or (match-string 7 s
) "0")))
12264 (string-to-number (match-string 4 s
))
12265 (string-to-number (match-string 3 s
))
12266 (string-to-number (match-string 2 s
))
12270 (defun org-timestamp-up (&optional arg
)
12271 "Increase the date item at the cursor by one.
12272 If the cursor is on the year, change the year. If it is on the month or
12273 the day, change that.
12274 With prefix ARG, change by that many units."
12276 (org-timestamp-change (prefix-numeric-value arg
)))
12278 (defun org-timestamp-down (&optional arg
)
12279 "Decrease the date item at the cursor by one.
12280 If the cursor is on the year, change the year. If it is on the month or
12281 the day, change that.
12282 With prefix ARG, change by that many units."
12284 (org-timestamp-change (- (prefix-numeric-value arg
))))
12286 (defun org-timestamp-up-day (&optional arg
)
12287 "Increase the date in the time stamp by one day.
12288 With prefix ARG, change that many days."
12290 (if (and (not (org-at-timestamp-p t
))
12291 (org-on-heading-p))
12293 (org-timestamp-change (prefix-numeric-value arg
) 'day
)))
12295 (defun org-timestamp-down-day (&optional arg
)
12296 "Decrease the date in the time stamp by one day.
12297 With prefix ARG, change that many days."
12299 (if (and (not (org-at-timestamp-p t
))
12300 (org-on-heading-p))
12302 (org-timestamp-change (- (prefix-numeric-value arg
)) 'day
)))
12304 (defun org-at-timestamp-p (&optional inactive-ok
)
12305 "Determine if the cursor is in or at a timestamp."
12307 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2
))
12309 (ans (or (looking-at tsr
)
12311 (skip-chars-backward "^[<\n\r\t")
12312 (if (> (point) (point-min)) (backward-char 1))
12313 (and (looking-at tsr
)
12314 (> (- (match-end 0) pos
) -
1))))))
12316 (boundp 'org-ts-what
)
12319 ((= pos
(match-beginning 0)) 'bracket
)
12320 ((= pos
(1- (match-end 0))) 'bracket
)
12321 ((org-pos-in-match-range pos
2) 'year
)
12322 ((org-pos-in-match-range pos
3) 'month
)
12323 ((org-pos-in-match-range pos
7) 'hour
)
12324 ((org-pos-in-match-range pos
8) 'minute
)
12325 ((or (org-pos-in-match-range pos
4)
12326 (org-pos-in-match-range pos
5)) 'day
)
12327 ((and (> pos
(or (match-end 8) (match-end 5)))
12328 (< pos
(match-end 0)))
12329 (- pos
(or (match-end 8) (match-end 5))))
12333 (defun org-toggle-timestamp-type ()
12334 "Toggle the type (<active> or [inactive]) of a time stamp."
12336 (when (org-at-timestamp-p t
)
12337 (let ((beg (match-beginning 0)) (end (match-end 0))
12338 (map '((?\
[ .
"<") (?\
] .
">") (?
< .
"[") (?
> .
"]"))))
12341 (while (re-search-forward "[][<>]" end t
)
12342 (replace-match (cdr (assoc (char-after (match-beginning 0)) map
))
12344 (message "Timestamp is now %sactive"
12345 (if (equal (char-after beg
) ?
<) "" "in")))))
12347 (defun org-timestamp-change (n &optional what
)
12348 "Change the date in the time stamp at point.
12349 The date will be changed by N times WHAT. WHAT can be `day', `month',
12350 `year', `minute', `second'. If WHAT is not given, the cursor position
12351 in the timestamp determines what will be changed."
12352 (let ((pos (point))
12354 (dm (max (nth 1 org-time-stamp-rounding-minutes
) 1))
12358 (if (not (org-at-timestamp-p t
))
12359 (error "Not at a timestamp"))
12360 (if (and (not what
) (eq org-ts-what
'bracket
))
12361 (org-toggle-timestamp-type)
12362 (if (and (not what
) (not (eq org-ts-what
'day
))
12363 org-display-custom-times
12364 (get-text-property (point) 'display
)
12365 (not (get-text-property (1- (point)) 'display
)))
12366 (setq org-ts-what
'day
))
12367 (setq org-ts-what
(or what org-ts-what
)
12368 inactive
(= (char-after (match-beginning 0)) ?\
[)
12369 ts
(match-string 0))
12372 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\)*\\)[]>]"
12374 (setq extra
(match-string 1 ts
)))
12375 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts
)
12377 (setq time0
(org-parse-time-string ts
))
12378 (when (and (eq org-ts-what
'minute
)
12379 (eq current-prefix-arg nil
))
12380 (setq n
(* dm
(cond ((> n
0) 1) ((< n
0) -
1) (t 0))))
12381 (when (not (= 0 (setq rem
(%
(nth 1 time0
) dm
))))
12382 (setcar (cdr time0
) (+ (nth 1 time0
)
12383 (if (> n
0) (- rem
) (- dm rem
))))))
12385 (encode-time (or (car time0
) 0)
12386 (+ (if (eq org-ts-what
'minute
) n
0) (nth 1 time0
))
12387 (+ (if (eq org-ts-what
'hour
) n
0) (nth 2 time0
))
12388 (+ (if (eq org-ts-what
'day
) n
0) (nth 3 time0
))
12389 (+ (if (eq org-ts-what
'month
) n
0) (nth 4 time0
))
12390 (+ (if (eq org-ts-what
'year
) n
0) (nth 5 time0
))
12392 (when (integerp org-ts-what
)
12393 (setq extra
(org-modify-ts-extra extra org-ts-what n dm
)))
12394 (if (eq what
'calendar
)
12395 (let ((cal-date (org-get-date-from-calendar)))
12396 (setcar (nthcdr 4 time0
) (nth 0 cal-date
)) ; month
12397 (setcar (nthcdr 3 time0
) (nth 1 cal-date
)) ; day
12398 (setcar (nthcdr 5 time0
) (nth 2 cal-date
)) ; year
12399 (setcar time0
(or (car time0
) 0))
12400 (setcar (nthcdr 1 time0
) (or (nth 1 time0
) 0))
12401 (setcar (nthcdr 2 time0
) (or (nth 2 time0
) 0))
12402 (setq time
(apply 'encode-time time0
))))
12403 (setq org-last-changed-timestamp
12404 (org-insert-time-stamp time with-hm inactive nil nil extra
))
12405 (org-clock-update-time-maybe)
12407 ;; Try to recenter the calendar window, if any
12408 (if (and org-calendar-follow-timestamp-change
12409 (get-buffer-window "*Calendar*" t
)
12410 (memq org-ts-what
'(day month year
)))
12411 (org-recenter-calendar (time-to-days time
))))))
12413 (defun org-modify-ts-extra (s pos n dm
)
12414 "Change the different parts of the lead-time and repeat fields in timestamp."
12415 (let ((idx '(("d" .
0) ("w" .
1) ("m" .
2) ("y" .
3) ("d" . -
1) ("y" .
4)))
12417 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s
)
12419 ((or (org-pos-in-match-range pos
2)
12420 (org-pos-in-match-range pos
3))
12421 (setq m
(string-to-number (match-string 3 s
))
12422 h
(string-to-number (match-string 2 s
)))
12423 (if (org-pos-in-match-range pos
2)
12425 (setq n
(* dm
(org-no-warnings (signum n
))))
12426 (when (not (= 0 (setq rem
(% m dm
))))
12427 (setq m
(+ m
(if (> n
0) (- rem
) (- dm rem
)))))
12429 (if (< m
0) (setq m
(+ m
60) h
(1- h
)))
12430 (if (> m
59) (setq m
(- m
60) h
(1+ h
)))
12431 (setq h
(min 24 (max 0 h
)))
12432 (setq ng
1 new
(format "-%02d:%02d" h m
)))
12433 ((org-pos-in-match-range pos
6)
12434 (setq ng
6 new
(car (rassoc (+ n
(cdr (assoc (match-string 6 s
) idx
))) idx
))))
12435 ((org-pos-in-match-range pos
5)
12436 (setq ng
5 new
(format "%d" (max 1 (+ n
(string-to-number (match-string 5 s
)))))))
12438 ((org-pos-in-match-range pos
9)
12439 (setq ng
9 new
(car (rassoc (+ n
(cdr (assoc (match-string 9 s
) idx
))) idx
))))
12440 ((org-pos-in-match-range pos
8)
12441 (setq ng
8 new
(format "%d" (max 0 (+ n
(string-to-number (match-string 8 s
))))))))
12445 (substring s
0 (match-beginning ng
))
12447 (substring s
(match-end ng
))))))
12450 (defun org-recenter-calendar (date)
12451 "If the calendar is visible, recenter it to DATE."
12452 (let* ((win (selected-window))
12453 (cwin (get-buffer-window "*Calendar*" t
))
12454 (calendar-move-hook nil
))
12456 (select-window cwin
)
12457 (calendar-goto-date (if (listp date
) date
12458 (calendar-gregorian-from-absolute date
)))
12459 (select-window win
))))
12461 (defun org-goto-calendar (&optional arg
)
12462 "Go to the Emacs calendar at the current date.
12463 If there is a time stamp in the current line, go to that date.
12464 A prefix ARG can be used to force the current date."
12466 (let ((tsr org-ts-regexp
) diff
12467 (calendar-move-hook nil
)
12468 (calendar-view-holidays-initially-flag nil
)
12469 (view-calendar-holidays-initially nil
)
12470 (calendar-view-diary-initially-flag nil
)
12471 (view-diary-entries-initially nil
))
12472 (if (or (org-at-timestamp-p)
12474 (beginning-of-line 1)
12475 (looking-at (concat ".*" tsr
))))
12476 (let ((d1 (time-to-days (current-time)))
12478 (org-time-string-to-time (match-string 1)))))
12479 (setq diff
(- d2 d1
))))
12481 (calendar-goto-today)
12482 (if (and diff
(not arg
)) (calendar-forward-day diff
))))
12484 (defun org-get-date-from-calendar ()
12485 "Return a list (month day year) of date at point in calendar."
12486 (with-current-buffer "*Calendar*"
12488 (calendar-cursor-to-date))))
12490 (defun org-date-from-calendar ()
12491 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
12492 If there is already a time stamp at the cursor position, update it."
12494 (if (org-at-timestamp-p t
)
12495 (org-timestamp-change 0 'calendar
)
12496 (let ((cal-date (org-get-date-from-calendar)))
12497 (org-insert-time-stamp
12498 (encode-time 0 0 0 (nth 1 cal-date
) (car cal-date
) (nth 2 cal-date
))))))
12500 (defun org-minutes-to-hh:mm-string
(m)
12501 "Compute H:MM from a number of minutes."
12502 (let ((h (/ m
60)))
12503 (setq m
(- m
(* 60 h
)))
12504 (format org-time-clocksum-format h m
)))
12506 (defun org-hh:mm-string-to-minutes
(s)
12507 "Convert a string H:MM to a number of minutes."
12508 (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s
)
12509 (+ (* (string-to-number (match-string 1 s
)) 60)
12510 (string-to-number (match-string 2 s
)))
12515 (defun org-save-all-org-buffers ()
12516 "Save all Org-mode buffers without user confirmation."
12518 (message "Saving all Org-mode buffers...")
12519 (save-some-buffers t
'org-mode-p
)
12520 (when (featurep 'org-id
) (org-id-locations-save))
12521 (message "Saving all Org-mode buffers... done"))
12523 (defun org-revert-all-org-buffers ()
12524 "Revert all Org-mode buffers.
12525 Prompt for confirmation when there are unsaved changes.
12526 Be sure you know what you are doing before letting this function
12527 overwrite your changes.
12529 This function is useful in a setup where one tracks org files
12530 with a version control system, to revert on one machine after pulling
12531 changes from another. I believe the procedure must be like this:
12533 1. M-x org-save-all-org-buffers
12534 2. Pull changes from the other machine, resolve conflicts
12535 3. M-x org-revert-all-org-buffers"
12537 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
12540 (save-window-excursion
12543 (when (and (with-current-buffer b
(org-mode-p))
12544 (with-current-buffer b buffer-file-name
))
12545 (switch-to-buffer b
)
12546 (revert-buffer t
'no-confirm
)))
12548 (when (and (featurep 'org-id
) org-id-track-globally
)
12549 (org-id-locations-load)))))
12554 (defun org-iswitchb (&optional arg
)
12555 "Use `iswitchb-read-buffer' to prompt for an Org buffer to switch to.
12556 With a prefix argument, restrict available to files.
12557 With two prefix arguments, restrict available buffers to agenda files.
12559 Due to some yet unresolved reason, the global function
12560 `iswitchb-mode' needs to be active for this function to work."
12562 (require 'iswitchb
)
12563 (let ((enabled iswitchb-mode
) blist
)
12564 (or enabled
(iswitchb-mode 1))
12565 (setq blist
(cond ((equal arg
'(4)) (org-buffer-list 'files
))
12566 ((equal arg
'(16)) (org-buffer-list 'agenda
))
12567 (t (org-buffer-list))))
12569 (let ((iswitchb-make-buflist-hook
12571 (setq iswitchb-temp-buflist
12572 (mapcar 'buffer-name blist
)))))
12574 (iswitchb-read-buffer
12575 "Switch-to: " nil t
))
12576 (or enabled
(iswitchb-mode -
1))))))
12579 (defun org-ido-switchb (&optional arg
)
12580 "Use `org-ido-completing-read' to prompt for an Org buffer to switch to.
12581 With a prefix argument, restrict available to files.
12582 With two prefix arguments, restrict available buffers to agenda files."
12584 (let ((blist (cond ((equal arg
'(4)) (org-buffer-list 'files
))
12585 ((equal arg
'(16)) (org-buffer-list 'agenda
))
12586 (t (org-buffer-list)))))
12588 (org-ido-completing-read "Org buffer: "
12589 (mapcar 'buffer-name blist
)
12592 (defun org-buffer-list (&optional predicate exclude-tmp
)
12593 "Return a list of Org buffers.
12594 PREDICATE can be `export', `files' or `agenda'.
12596 export restrict the list to Export buffers.
12597 files restrict the list to buffers visiting Org files.
12598 agenda restrict the list to buffers visiting agenda files.
12600 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
12602 (agenda-files (and (eq predicate
'agenda
)
12603 (mapcar 'file-truename
(org-agenda-files t
))))
12606 ((eq predicate
'files
)
12607 (lambda (b) (with-current-buffer b
(eq major-mode
'org-mode
))))
12608 ((eq predicate
'export
)
12609 (lambda (b) (string-match "\*Org .*Export" (buffer-name b
))))
12610 ((eq predicate
'agenda
)
12612 (with-current-buffer b
12613 (and (eq major-mode
'org-mode
)
12614 (setq bfn
(buffer-file-name b
))
12615 (member (file-truename bfn
) agenda-files
)))))
12616 (t (lambda (b) (with-current-buffer b
12617 (or (eq major-mode
'org-mode
)
12618 (string-match "\*Org .*Export"
12619 (buffer-name b
)))))))))
12623 (if (and (funcall filter b
)
12624 (or (not exclude-tmp
)
12625 (not (string-match "tmp" (buffer-name b
)))))
12630 (defun org-agenda-files (&optional unrestricted archives
)
12631 "Get the list of agenda files.
12632 Optional UNRESTRICTED means return the full list even if a restriction
12633 is currently in place.
12634 When ARCHIVES is t, include all archive files hat are really being
12635 used by the agenda files. If ARCHIVE is `ifmode', do this only if
12636 `org-agenda-archives-mode' is t."
12639 ((and (not unrestricted
) (get 'org-agenda-files
'org-restrict
)))
12640 ((stringp org-agenda-files
) (org-read-agenda-file-list))
12641 ((listp org-agenda-files
) org-agenda-files
)
12642 (t (error "Invalid value of `org-agenda-files'")))))
12643 (setq files
(apply 'append
12644 (mapcar (lambda (f)
12645 (if (file-directory-p f
)
12647 f t org-agenda-file-regexp
)
12650 (when org-agenda-skip-unavailable-files
12651 (setq files
(delq nil
12654 (and (file-readable-p file
) file
)))
12656 (when (or (eq archives t
)
12657 (and (eq archives
'ifmode
) (eq org-agenda-archives-mode t
)))
12658 (setq files
(org-add-archive-files files
)))
12661 (defun org-edit-agenda-file-list ()
12662 "Edit the list of agenda files.
12663 Depending on setup, this either uses customize to edit the variable
12664 `org-agenda-files', or it visits the file that is holding the list. In the
12665 latter case, the buffer is set up in a way that saving it automatically kills
12666 the buffer and restores the previous window configuration."
12668 (if (stringp org-agenda-files
)
12669 (let ((cw (current-window-configuration)))
12670 (find-file org-agenda-files
)
12671 (org-set-local 'org-window-configuration cw
)
12672 (org-add-hook 'after-save-hook
12674 (set-window-configuration
12675 (prog1 org-window-configuration
12676 (kill-buffer (current-buffer))))
12677 (org-install-agenda-files-menu)
12678 (message "New agenda file list installed"))
12680 (message "%s" (substitute-command-keys
12681 "Edit list and finish with \\[save-buffer]")))
12682 (customize-variable 'org-agenda-files
)))
12684 (defun org-store-new-agenda-file-list (list)
12685 "Set new value for the agenda file list and save it correctly."
12686 (if (stringp org-agenda-files
)
12687 (let ((f org-agenda-files
) b
)
12688 (while (setq b
(find-buffer-visiting f
)) (kill-buffer b
))
12690 (insert (mapconcat 'identity list
"\n") "\n")))
12691 (let ((org-mode-hook nil
) (default-major-mode 'fundamental-mode
))
12692 (setq org-agenda-files list
)
12693 (customize-save-variable 'org-agenda-files org-agenda-files
))))
12695 (defun org-read-agenda-file-list ()
12696 "Read the list of agenda files from a file."
12697 (when (file-directory-p org-agenda-files
)
12698 (error "`org-agenda-files' cannot be a single directory"))
12699 (when (stringp org-agenda-files
)
12701 (insert-file-contents org-agenda-files
)
12702 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*"))))
12706 (defun org-cycle-agenda-files ()
12707 "Cycle through the files in `org-agenda-files'.
12708 If the current buffer visits an agenda file, find the next one in the list.
12709 If the current buffer does not, find the first agenda file."
12711 (let* ((fs (org-agenda-files t
))
12712 (files (append fs
(list (car fs
))))
12713 (tcf (if buffer-file-name
(file-truename buffer-file-name
)))
12715 (unless files
(error "No agenda files"))
12717 (while (setq file
(pop files
))
12718 (if (equal (file-truename file
) tcf
)
12720 (find-file (car files
))
12722 (find-file (car fs
)))
12723 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
12725 (defun org-agenda-file-to-front (&optional to-end
)
12726 "Move/add the current file to the top of the agenda file list.
12727 If the file is not present in the list, it is added to the front. If it is
12728 present, it is moved there. With optional argument TO-END, add/move to the
12731 (let ((org-agenda-skip-unavailable-files nil
)
12732 (file-alist (mapcar (lambda (x)
12733 (cons (file-truename x
) x
))
12734 (org-agenda-files t
)))
12735 (ctf (file-truename buffer-file-name
))
12737 (setq x
(assoc ctf file-alist
) had x
)
12739 (if (not x
) (setq x
(cons ctf
(abbreviate-file-name buffer-file-name
))))
12741 (setq file-alist
(append (delq x file-alist
) (list x
)))
12742 (setq file-alist
(cons x
(delq x file-alist
))))
12743 (org-store-new-agenda-file-list (mapcar 'cdr file-alist
))
12744 (org-install-agenda-files-menu)
12745 (message "File %s to %s of agenda file list"
12746 (if had
"moved" "added") (if to-end
"end" "front"))))
12748 (defun org-remove-file (&optional file
)
12749 "Remove current file from the list of files in variable `org-agenda-files'.
12750 These are the files which are being checked for agenda entries.
12751 Optional argument FILE means, use this file instead of the current."
12753 (let* ((org-agenda-skip-unavailable-files nil
)
12754 (file (or file buffer-file-name
))
12755 (true-file (file-truename file
))
12756 (afile (abbreviate-file-name file
))
12757 (files (delq nil
(mapcar
12759 (if (equal true-file
12762 (org-agenda-files t
)))))
12763 (if (not (= (length files
) (length (org-agenda-files t
))))
12765 (org-store-new-agenda-file-list files
)
12766 (org-install-agenda-files-menu)
12767 (message "Removed file: %s" afile
))
12768 (message "File was not in list: %s (not removed)" afile
))))
12770 (defun org-file-menu-entry (file)
12771 (vector file
(list 'find-file file
) t
))
12773 (defun org-check-agenda-file (file)
12774 "Make sure FILE exists. If not, ask user what to do."
12775 (when (not (file-exists-p file
))
12776 (message "non-existent file %s. [R]emove from list or [A]bort?"
12777 (abbreviate-file-name file
))
12778 (let ((r (downcase (read-char-exclusive))))
12781 (org-remove-file file
)
12782 (throw 'nextfile t
))
12783 (t (error "Abort"))))))
12785 (defun org-get-agenda-file-buffer (file)
12786 "Get a buffer visiting FILE. If the buffer needs to be created, add
12787 it to the list of buffers which might be released later."
12788 (let ((buf (org-find-base-buffer-visiting file
)))
12790 buf
; just return it
12791 ;; Make a new buffer and remember it
12792 (setq buf
(find-file-noselect file
))
12793 (if buf
(push buf org-agenda-new-buffers
))
12796 (defun org-release-buffers (blist)
12797 "Release all buffers in list, asking the user for confirmation when needed.
12798 When a buffer is unmodified, it is just killed. When modified, it is saved
12799 \(if the user agrees) and then killed."
12801 (while (setq buf
(pop blist
))
12802 (setq file
(buffer-file-name buf
))
12803 (when (and (buffer-modified-p buf
)
12805 (y-or-n-p (format "Save file %s? " file
)))
12806 (with-current-buffer buf
(save-buffer)))
12807 (kill-buffer buf
))))
12809 (defun org-prepare-agenda-buffers (files)
12810 "Create buffers for all agenda files, protect archived trees and comments."
12812 (let ((pa '(:org-archived t
))
12813 (pc '(:org-comment t
))
12814 (pall '(:org-archived t
:org-comment t
))
12815 (inhibit-read-only t
)
12816 (rea (concat ":" org-archive-tag
":"))
12820 (while (setq file
(pop files
))
12823 (org-check-agenda-file file
)
12824 (set-buffer (org-get-agenda-file-buffer file
)))
12826 (setq bmp
(buffer-modified-p))
12827 (org-refresh-category-properties)
12828 (setq org-todo-keywords-for-agenda
12829 (append org-todo-keywords-for-agenda org-todo-keywords-1
))
12830 (setq org-done-keywords-for-agenda
12831 (append org-done-keywords-for-agenda org-done-keywords
))
12832 (setq org-todo-keyword-alist-for-agenda
12833 (append org-todo-keyword-alist-for-agenda org-todo-key-alist
))
12834 (setq org-tag-alist-for-agenda
12835 (append org-tag-alist-for-agenda org-tag-alist
))
12838 (remove-text-properties (point-min) (point-max) pall
)
12839 (when org-agenda-skip-archived-trees
12840 (goto-char (point-min))
12841 (while (re-search-forward rea nil t
)
12842 (if (org-on-heading-p t
)
12843 (add-text-properties (point-at-bol) (org-end-of-subtree t
) pa
))))
12844 (goto-char (point-min))
12845 (setq re
(concat "^\\*+ +" org-comment-string
"\\>"))
12846 (while (re-search-forward re nil t
)
12847 (add-text-properties
12848 (match-beginning 0) (org-end-of-subtree t
) pc
)))
12849 (set-buffer-modified-p bmp
))))
12850 (setq org-todo-keyword-alist-for-agenda
12851 (org-uniquify org-todo-keyword-alist-for-agenda
)
12852 org-tag-alist-for-agenda
(org-uniquify org-tag-alist-for-agenda
))))
12854 ;;;; Embedded LaTeX
12856 (defvar org-cdlatex-mode-map
(make-sparse-keymap)
12857 "Keymap for the minor `org-cdlatex-mode'.")
12859 (org-defkey org-cdlatex-mode-map
"_" 'org-cdlatex-underscore-caret
)
12860 (org-defkey org-cdlatex-mode-map
"^" 'org-cdlatex-underscore-caret
)
12861 (org-defkey org-cdlatex-mode-map
"`" 'cdlatex-math-symbol
)
12862 (org-defkey org-cdlatex-mode-map
"'" 'org-cdlatex-math-modify
)
12863 (org-defkey org-cdlatex-mode-map
"\C-c{" 'cdlatex-environment
)
12865 (defvar org-cdlatex-texmathp-advice-is-done nil
12866 "Flag remembering if we have applied the advice to texmathp already.")
12868 (define-minor-mode org-cdlatex-mode
12869 "Toggle the minor `org-cdlatex-mode'.
12870 This mode supports entering LaTeX environment and math in LaTeX fragments
12872 \\{org-cdlatex-mode-map}"
12874 (when org-cdlatex-mode
(require 'cdlatex
))
12875 (unless org-cdlatex-texmathp-advice-is-done
12876 (setq org-cdlatex-texmathp-advice-is-done t
)
12877 (defadvice texmathp
(around org-math-always-on activate
)
12878 "Always return t in org-mode buffers.
12879 This is because we want to insert math symbols without dollars even outside
12880 the LaTeX math segments. If Orgmode thinks that point is actually inside
12881 an embedded LaTeX fragment, let texmathp do its job.
12882 \\[org-cdlatex-mode-map]"
12886 ((not (org-mode-p)) ad-do-it
)
12887 ((eq this-command
'cdlatex-math-symbol
)
12888 (setq ad-return-value t
12889 texmathp-why
'("cdlatex-math-symbol in org-mode" .
0)))
12891 (let ((p (org-inside-LaTeX-fragment-p)))
12892 (if (and p
(member (car p
) (plist-get org-format-latex-options
:matchers
)))
12893 (setq ad-return-value t
12894 texmathp-why
'("Org-mode embedded math" .
0))
12895 (if p ad-do-it
)))))))))
12897 (defun turn-on-org-cdlatex ()
12898 "Unconditionally turn on `org-cdlatex-mode'."
12899 (org-cdlatex-mode 1))
12901 (defun org-inside-LaTeX-fragment-p ()
12902 "Test if point is inside a LaTeX fragment.
12903 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
12904 sequence appearing also before point.
12905 Even though the matchers for math are configurable, this function assumes
12906 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
12907 delimiters are skipped when they have been removed by customization.
12908 The return value is nil, or a cons cell with the delimiter and
12909 and the position of this delimiter.
12911 This function does a reasonably good job, but can locally be fooled by
12912 for example currency specifications. For example it will assume being in
12913 inline math after \"$22.34\". The LaTeX fragment formatter will only format
12914 fragments that are properly closed, but during editing, we have to live
12915 with the uncertainty caused by missing closing delimiters. This function
12916 looks only before point, not after."
12918 (let ((pos (point))
12919 (dodollar (member "$" (plist-get org-format-latex-options
:matchers
)))
12921 (re-search-backward (concat "^\\(" paragraph-start
"\\)") nil t
)
12923 dd-on str
(start 0) m re
)
12926 (setq str
(concat (buffer-substring lim
(point)) "\000 X$.")
12927 re
(nth 1 (assoc "$" org-latex-regexps
)))
12928 (while (string-match re str start
)
12930 ((= (match-end 0) (length str
))
12931 (throw 'exit
(cons "$" (+ lim
(match-beginning 0) 1))))
12932 ((= (match-end 0) (- (length str
) 5))
12934 (t (setq start
(match-end 0))))))
12935 (when (setq m
(re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t
))
12937 (and (match-beginning 1) (throw 'exit
(cons (match-string 1) m
)))
12938 (and (match-beginning 2) (throw 'exit nil
))
12940 (while (re-search-backward "\\$\\$" lim t
)
12941 (setq dd-on
(not dd-on
)))
12943 (if dd-on
(cons "$$" m
))))))
12946 (defun org-try-cdlatex-tab ()
12947 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
12948 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
12949 - inside a LaTeX fragment, or
12950 - after the first word in a line, where an abbreviation expansion could
12951 insert a LaTeX environment."
12952 (when org-cdlatex-mode
12955 (skip-chars-backward "a-zA-Z0-9*")
12956 (skip-chars-backward " \t")
12959 ((org-inside-LaTeX-fragment-p)
12963 (defun org-cdlatex-underscore-caret (&optional arg
)
12964 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
12965 Revert to the normal definition outside of these fragments."
12967 (if (org-inside-LaTeX-fragment-p)
12968 (call-interactively 'cdlatex-sub-superscript
)
12969 (let (org-cdlatex-mode)
12970 (call-interactively (key-binding (vector last-input-event
))))))
12972 (defun org-cdlatex-math-modify (&optional arg
)
12973 "Execute `cdlatex-math-modify' in LaTeX fragments.
12974 Revert to the normal definition outside of these fragments."
12976 (if (org-inside-LaTeX-fragment-p)
12977 (call-interactively 'cdlatex-math-modify
)
12978 (let (org-cdlatex-mode)
12979 (call-interactively (key-binding (vector last-input-event
))))))
12981 (defvar org-latex-fragment-image-overlays nil
12982 "List of overlays carrying the images of latex fragments.")
12983 (make-variable-buffer-local 'org-latex-fragment-image-overlays
)
12985 (defun org-remove-latex-fragment-image-overlays ()
12986 "Remove all overlays with LaTeX fragment images in current buffer."
12987 (mapc 'org-delete-overlay org-latex-fragment-image-overlays
)
12988 (setq org-latex-fragment-image-overlays nil
))
12990 (defun org-preview-latex-fragment (&optional subtree
)
12991 "Preview the LaTeX fragment at point, or all locally or globally.
12992 If the cursor is in a LaTeX fragment, create the image and overlay
12993 it over the source code. If there is no fragment at point, display
12994 all fragments in the current text, from one headline to the next. With
12995 prefix SUBTREE, display all fragments in the current subtree. With a
12996 double prefix `C-u C-u', or when the cursor is before the first headline,
12997 display all fragments in the buffer.
12998 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
13000 (org-remove-latex-fragment-image-overlays)
13003 (let (beg end at msg
)
13005 ((or (equal subtree
'(16))
13006 (not (save-excursion
13007 (re-search-backward (concat "^" outline-regexp
) nil t
))))
13008 (setq beg
(point-min) end
(point-max)
13009 msg
"Creating images for buffer...%s"))
13010 ((equal subtree
'(4))
13011 (org-back-to-heading)
13012 (setq beg
(point) end
(org-end-of-subtree t
)
13013 msg
"Creating images for subtree...%s"))
13015 (if (setq at
(org-inside-LaTeX-fragment-p))
13016 (goto-char (max (point-min) (- (cdr at
) 2)))
13017 (org-back-to-heading))
13018 (setq beg
(point) end
(progn (outline-next-heading) (point))
13019 msg
(if at
"Creating image...%s"
13020 "Creating images for entry...%s"))))
13022 (narrow-to-region beg end
)
13025 (concat "ltxpng/" (file-name-sans-extension
13026 (file-name-nondirectory
13027 buffer-file-name
)))
13028 default-directory
'overlays msg at
'forbuffer
)
13029 (message msg
"done. Use `C-c C-c' to remove images.")))))
13031 (defvar org-latex-regexps
13032 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t
)
13033 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
13034 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
13035 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
13036 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
13037 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil
)
13038 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 t
)
13039 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 t
))
13040 "Regular expressions for matching embedded LaTeX.")
13042 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer
)
13043 "Replace LaTeX fragments with links to an image, and produce images."
13044 (if (and overlays
(fboundp 'clear-image-cache
)) (clear-image-cache))
13045 (let* ((prefixnodir (file-name-nondirectory prefix
))
13046 (absprefix (expand-file-name prefix dir
))
13047 (todir (file-name-directory absprefix
))
13048 (opt org-format-latex-options
)
13049 (matchers (plist-get opt
:matchers
))
13050 (re-list org-latex-regexps
)
13051 (cnt 0) txt link beg end re e checkdir
13052 m n block linkfile movefile ov
)
13053 ;; Check if there are old images files with this prefix, and remove them
13054 (when (file-directory-p todir
)
13058 (concat (regexp-quote prefixnodir
) "_[0-9]+\\.png$"))))
13059 ;; Check the different regular expressions
13060 (while (setq e
(pop re-list
))
13061 (setq m
(car e
) re
(nth 1 e
) n
(nth 2 e
)
13062 block
(if (nth 3 e
) "\n\n" ""))
13063 (when (member m matchers
)
13064 (goto-char (point-min))
13065 (while (re-search-forward re nil t
)
13066 (when (and (or (not at
) (equal (cdr at
) (match-beginning n
)))
13067 (not (get-text-property (match-beginning n
)
13069 (setq txt
(match-string n
)
13070 beg
(match-beginning n
) end
(match-end n
)
13072 linkfile
(format "%s_%04d.png" prefix cnt
)
13073 movefile
(format "%s_%04d.png" absprefix cnt
)
13074 link
(concat block
"[[file:" linkfile
"]]" block
))
13075 (if msg
(message msg cnt
))
13077 (unless checkdir
; make sure the directory exists
13079 (or (file-directory-p todir
) (make-directory todir
)))
13080 (org-create-formula-image
13081 txt movefile opt forbuffer
)
13084 (setq ov
(org-make-overlay beg end
))
13085 (if (featurep 'xemacs
)
13087 (org-overlay-put ov
'invisible t
)
13090 (make-glyph (vector 'png
:file movefile
))))
13093 (list 'image
:type
'png
:file movefile
:ascent
'center
)))
13094 (push ov org-latex-fragment-image-overlays
)
13096 (delete-region beg end
)
13097 (insert link
))))))))
13099 ;; This function borrows from Ganesh Swami's latex2png.el
13100 (defun org-create-formula-image (string tofile options buffer
)
13101 (let* ((tmpdir (if (featurep 'xemacs
)
13103 temporary-file-directory
))
13104 (texfilebase (make-temp-name
13105 (expand-file-name "orgtex" tmpdir
)))
13106 (texfile (concat texfilebase
".tex"))
13107 (dvifile (concat texfilebase
".dvi"))
13108 (pngfile (concat texfilebase
".png"))
13109 (fnh (if (featurep 'xemacs
)
13110 (font-height (get-face-font 'default
))
13111 (face-attribute 'default
:height nil
)))
13112 (scale (or (plist-get options
(if buffer
:scale
:html-scale
)) 1.0))
13113 (dpi (number-to-string (* scale
(floor (* 0.9 (if buffer fnh
140.
))))))
13114 (fg (or (plist-get options
(if buffer
:foreground
:html-foreground
))
13116 (bg (or (plist-get options
(if buffer
:background
:html-background
))
13118 (if (eq fg
'default
) (setq fg
(org-dvipng-color :foreground
)))
13119 (if (eq bg
'default
) (setq bg
(org-dvipng-color :background
)))
13120 (with-temp-file texfile
13121 (insert org-format-latex-header
13122 "\n\\begin{document}\n" string
"\n\\end{document}\n"))
13123 (let ((dir default-directory
))
13124 (condition-case nil
13127 (call-process "latex" nil nil nil texfile
))
13130 (if (not (file-exists-p dvifile
))
13131 (progn (message "Failed to create dvi file from %s" texfile
) nil
)
13132 (condition-case nil
13133 (call-process "dvipng" nil nil nil
13134 "-E" "-fg" fg
"-bg" bg
13136 ;;"-x" scale "-y" scale
13141 (if (not (file-exists-p pngfile
))
13142 (progn (message "Failed to create png file from %s" texfile
) nil
)
13143 ;; Use the requested file name and clean up
13144 (copy-file pngfile tofile
'replace
)
13145 (loop for e in
'(".dvi" ".tex" ".aux" ".log" ".png") do
13146 (delete-file (concat texfilebase e
)))
13149 (defun org-dvipng-color (attr)
13150 "Return an rgb color specification for dvipng."
13151 (apply 'format
"rgb %s %s %s"
13152 (mapcar 'org-normalize-color
13153 (color-values (face-attribute 'default attr nil
)))))
13155 (defun org-normalize-color (value)
13156 "Return string to be used as color value for an RGB component."
13157 (format "%g" (/ value
65535.0)))
13161 ;; Make `C-c C-x' a prefix key
13162 (org-defkey org-mode-map
"\C-c\C-x" (make-sparse-keymap))
13164 ;; TAB key with modifiers
13165 (org-defkey org-mode-map
"\C-i" 'org-cycle
)
13166 (org-defkey org-mode-map
[(tab)] 'org-cycle
)
13167 (org-defkey org-mode-map
[(control tab
)] 'org-force-cycle-archived
)
13168 (org-defkey org-mode-map
[(meta tab
)] 'org-complete
)
13169 (org-defkey org-mode-map
"\M-\t" 'org-complete
)
13170 (org-defkey org-mode-map
"\M-\C-i" 'org-complete
)
13171 ;; The following line is necessary under Suse GNU/Linux
13172 (unless (featurep 'xemacs
)
13173 (org-defkey org-mode-map
[S-iso-lefttab
] 'org-shifttab
))
13174 (org-defkey org-mode-map
[(shift tab
)] 'org-shifttab
)
13175 (define-key org-mode-map
[backtab] 'org-shifttab)
13177 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
13178 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
13179 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
13181 ;; Cursor keys with modifiers
13182 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
13183 (org-defkey org-mode-map [(meta right)] 'org-metaright)
13184 (org-defkey org-mode-map [(meta up)] 'org-metaup)
13185 (org-defkey org-mode-map [(meta down)] 'org-metadown)
13187 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
13188 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
13189 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
13190 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
13192 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
13193 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
13194 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
13195 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
13197 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
13198 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
13200 ;;; Extra keys for tty access.
13201 ;; We only set them when really needed because otherwise the
13202 ;; menus don't show the simple keys
13204 (when (or org-use-extra-keys
13205 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
13206 (not window-system))
13207 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
13208 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
13209 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
13210 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
13211 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
13212 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
13213 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
13214 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
13215 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
13216 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
13217 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
13218 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
13219 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
13220 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
13221 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
13222 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
13223 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
13224 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
13225 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
13226 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
13227 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
13228 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft))
13230 ;; All the other keys
13232 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
13233 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
13234 (if (boundp 'narrow-map)
13235 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
13236 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
13237 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
13238 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
13239 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-toggle-archive-tag)
13240 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
13241 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
13242 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
13243 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
13244 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
13245 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
13246 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
13247 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
13248 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
13249 (org-defkey org-mode-map "\C-c\C-v" 'org-show-todo-tree)
13250 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
13251 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
13252 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
13253 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
13254 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
13255 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
13256 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
13257 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
13258 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
13259 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
13260 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
13261 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
13262 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
13263 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
13264 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
13265 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
13266 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
13267 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
13268 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
13269 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
13270 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
13271 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
13272 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
13273 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
13274 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
13275 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
13276 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
13277 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
13278 (org-defkey org-mode-map "\C-c^" 'org-sort)
13279 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
13280 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
13281 (org-defkey org-mode-map "\C-c#" 'org-update-checkbox-count)
13282 (org-defkey org-mode-map "\C-m" 'org-return)
13283 (org-defkey org-mode-map "\C-j" 'org-return-indent)
13284 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
13285 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
13286 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
13287 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
13288 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
13289 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
13290 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
13291 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
13292 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
13293 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
13294 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
13295 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
13296 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
13297 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
13298 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
13299 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
13301 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
13302 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
13303 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
13304 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
13306 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
13307 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
13308 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
13309 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
13310 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
13311 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
13312 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
13313 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
13314 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
13315 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
13316 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
13317 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
13318 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
13320 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
13321 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
13322 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
13323 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
13325 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
13327 (define-key org-mode-map "\C-c\C-xr" 'org-reload)
13329 (when (featurep 'xemacs)
13330 (org-defkey org-mode-map 'button3 'popup-mode-menu))
13333 (defvar org-self-insert-command-undo-counter 0)
13335 (defvar org-table-auto-blank-field) ; defined in org-table.el
13336 (defun org-self-insert-command (N)
13337 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
13338 If the cursor is in a table looking at whitespace, the whitespace is
13339 overwritten, and the table is not marked as requiring realignment."
13344 ;; check if we blank the field, and if that triggers align
13345 (and (featurep 'org-table) org-table-auto-blank-field
13346 (member last-command
13347 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c))
13348 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
13349 ;; got extra space, this field does not determine column width
13350 (let (org-table-may-need-update) (org-table-blank-field))
13351 ;; no extra space, this field may determine column width
13352 (org-table-blank-field)))
13355 (looking-at "[^|\n]* |"))
13356 (let (org-table-may-need-update)
13357 (goto-char (1- (match-end 0)))
13358 (delete-backward-char 1)
13359 (goto-char (match-beginning 0))
13360 (self-insert-command N))
13361 (setq org-table-may-need-update t)
13362 (self-insert-command N)
13363 (org-fix-tags-on-the-fly)
13364 (if org-self-insert-cluster-for-undo
13365 (if (not (eq last-command 'org-self-insert-command))
13366 (setq org-self-insert-command-undo-counter 1)
13367 (if (>= org-self-insert-command-undo-counter 20)
13368 (setq org-self-insert-command-undo-counter 1)
13369 (and (> org-self-insert-command-undo-counter 0)
13371 (not (cadr buffer-undo-list)) ; remove nil entry
13372 (setcdr buffer-undo-list (cddr buffer-undo-list)))
13373 (setq org-self-insert-command-undo-counter
13374 (1+ org-self-insert-command-undo-counter)))))))
13376 (defun org-fix-tags-on-the-fly ()
13377 (when (and (equal (char-after (point-at-bol)) ?*)
13378 (org-on-heading-p))
13379 (org-align-tags-here org-tags-column)))
13381 (defun org-delete-backward-char (N)
13382 "Like `delete-backward-char', insert whitespace at field end in tables.
13383 When deleting backwards, in tables this function will insert whitespace in
13384 front of the next \"|\" separator, to keep the table aligned. The table will
13385 still be marked for re-alignment if the field did fill the entire column,
13386 because, in this case the deletion might narrow the column."
13388 (if (and (org-table-p)
13390 (string-match "|" (buffer-substring (point-at-bol) (point)))
13391 (looking-at ".*?|"))
13392 (let ((pos (point))
13393 (noalign (looking-at "[^|\n\r]* |"))
13394 (c org-table-may-need-update))
13395 (backward-delete-char N)
13396 (skip-chars-forward "^|")
13398 (goto-char (1- pos))
13399 ;; noalign: if there were two spaces at the end, this field
13400 ;; does not determine the width of the column.
13401 (if noalign (setq org-table-may-need-update c)))
13402 (backward-delete-char N)
13403 (org-fix-tags-on-the-fly)))
13405 (defun org-delete-char (N)
13406 "Like `delete-char', but insert whitespace at field end in tables.
13407 When deleting characters, in tables this function will insert whitespace in
13408 front of the next \"|\" separator, to keep the table aligned. The table will
13409 still be marked for re-alignment if the field did fill the entire column,
13410 because, in this case the deletion might narrow the column."
13412 (if (and (org-table-p)
13414 (not (= (char-after) ?|))
13416 (if (looking-at ".*?|")
13417 (let ((pos (point))
13418 (noalign (looking-at "[^|\n\r]* |"))
13419 (c org-table-may-need-update))
13420 (replace-match (concat
13421 (substring (match-string 0) 1 -1)
13424 ;; noalign: if there were two spaces at the end, this field
13425 ;; does not determine the width of the column.
13426 (if noalign (setq org-table-may-need-update c)))
13429 (org-fix-tags-on-the-fly)))
13431 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
13432 (put 'org-self-insert-command 'delete-selection t)
13433 (put 'orgtbl-self-insert-command 'delete-selection t)
13434 (put 'org-delete-char 'delete-selection 'supersede)
13435 (put 'org-delete-backward-char 'delete-selection 'supersede)
13436 (put 'org-yank 'delete-selection 'yank)
13438 ;; Make `flyspell-mode' delay after some commands
13439 (put 'org-self-insert-command 'flyspell-delayed t)
13440 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
13441 (put 'org-delete-char 'flyspell-delayed t)
13442 (put 'org-delete-backward-char 'flyspell-delayed t)
13444 ;; Make pabbrev-mode expand after org-mode commands
13445 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
13446 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
13448 ;; How to do this: Measure non-white length of current string
13449 ;; If equal to column width, we should realign.
13451 (defun org-remap (map &rest commands)
13452 "In MAP, remap the functions given in COMMANDS.
13453 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
13456 (setq old (pop commands) new (pop commands))
13457 (if (fboundp 'command-remapping)
13458 (org-defkey map (vector 'remap old) new)
13459 (substitute-key-definition old new map global-map)))))
13461 (when (eq org-enable-table-editor 'optimized)
13462 ;; If the user wants maximum table support, we need to hijack
13463 ;; some standard editing functions
13464 (org-remap org-mode-map
13465 'self-insert-command 'org-self-insert-command
13466 'delete-char 'org-delete-char
13467 'delete-backward-char 'org-delete-backward-char)
13468 (org-defkey org-mode-map "|" 'org-force-self-insert))
13470 (defvar org-ctrl-c-ctrl-c-hook nil
13471 "Hook for functions attaching themselves to `C-c C-c'.
13472 This can be used to add additional functionality to the C-c C-c key which
13473 executes context-dependent commands.
13474 Each function will be called with no arguments. The function must check
13475 if the context is appropriate for it to act. If yes, it should do its
13476 thing and then return a non-nil value. If the context is wrong,
13479 (defvar org-metaleft-hook nil
13480 "Hook for functions attaching themselves to `M-left'.
13481 See `org-ctrl-c-ctrl-c-hook' for more information.")
13482 (defvar org-metaright-hook nil
13483 "Hook for functions attaching themselves to `M-right'.
13484 See `org-ctrl-c-ctrl-c-hook' for more information.")
13485 (defvar org-metaup-hook nil
13486 "Hook for functions attaching themselves to `M-up'.
13487 See `org-ctrl-c-ctrl-c-hook' for more information.")
13488 (defvar org-metadown-hook nil
13489 "Hook for functions attaching themselves to `M-down'.
13490 See `org-ctrl-c-ctrl-c-hook' for more information.")
13491 (defvar org-shiftmetaleft-hook nil
13492 "Hook for functions attaching themselves to `M-S-left'.
13493 See `org-ctrl-c-ctrl-c-hook' for more information.")
13494 (defvar org-shiftmetaright-hook nil
13495 "Hook for functions attaching themselves to `M-S-right'.
13496 See `org-ctrl-c-ctrl-c-hook' for more information.")
13497 (defvar org-shiftmetaup-hook nil
13498 "Hook for functions attaching themselves to `M-S-up'.
13499 See `org-ctrl-c-ctrl-c-hook' for more information.")
13500 (defvar org-shiftmetadown-hook nil
13501 "Hook for functions attaching themselves to `M-S-down'.
13502 See `org-ctrl-c-ctrl-c-hook' for more information.")
13503 (defvar org-metareturn-hook nil
13504 "Hook for functions attaching themselves to `M-RET'.
13505 See `org-ctrl-c-ctrl-c-hook' for more information.")
13507 (defun org-modifier-cursor-error ()
13508 "Throw an error, a modified cursor command was applied in wrong context."
13509 (error "This command is active in special context like tables, headlines or items"))
13511 (defun org-shiftselect-error ()
13512 "Throw an error because Shift-Cursor command was applied in wrong context."
13513 (if (and (boundp 'shift-select-mode) shift-select-mode)
13514 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'.")
13515 (error "This command works only in special context like headlines or timestamps.")))
13517 (defun org-call-for-shift-select (cmd)
13518 (let ((this-command-keys-shift-translated t))
13519 (call-interactively cmd)))
13521 (defun org-shifttab (&optional arg)
13522 "Global visibility cycling or move to previous table field.
13523 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
13525 See the individual commands for more information."
13528 ((org-at-table-p) (call-interactively 'org-table-previous-field))
13530 (message "Content view to level: %d" arg)
13531 (org-content (prefix-numeric-value arg))
13532 (setq org-cycle-global-status 'overview))
13533 (t (call-interactively 'org-global-cycle))))
13535 (defun org-shiftmetaleft ()
13536 "Promote subtree or delete table column.
13537 Calls `org-promote-subtree', `org-outdent-item',
13538 or `org-table-delete-column', depending on context.
13539 See the individual commands for more information."
13542 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
13543 ((org-at-table-p) (call-interactively 'org-table-delete-column))
13544 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
13545 ((org-at-item-p) (call-interactively 'org-outdent-item))
13546 (t (org-modifier-cursor-error))))
13548 (defun org-shiftmetaright ()
13549 "Demote subtree or insert table column.
13550 Calls `org-demote-subtree', `org-indent-item',
13551 or `org-table-insert-column', depending on context.
13552 See the individual commands for more information."
13555 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
13556 ((org-at-table-p) (call-interactively 'org-table-insert-column))
13557 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
13558 ((org-at-item-p) (call-interactively 'org-indent-item))
13559 (t (org-modifier-cursor-error))))
13561 (defun org-shiftmetaup (&optional arg)
13562 "Move subtree up or kill table row.
13563 Calls `org-move-subtree-up' or `org-table-kill-row' or
13564 `org-move-item-up' depending on context. See the individual commands
13565 for more information."
13568 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
13569 ((org-at-table-p) (call-interactively 'org-table-kill-row))
13570 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
13571 ((org-at-item-p) (call-interactively 'org-move-item-up))
13572 (t (org-modifier-cursor-error))))
13574 (defun org-shiftmetadown (&optional arg)
13575 "Move subtree down or insert table row.
13576 Calls `org-move-subtree-down' or `org-table-insert-row' or
13577 `org-move-item-down', depending on context. See the individual
13578 commands for more information."
13581 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
13582 ((org-at-table-p) (call-interactively 'org-table-insert-row))
13583 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
13584 ((org-at-item-p) (call-interactively 'org-move-item-down))
13585 (t (org-modifier-cursor-error))))
13587 (defun org-metaleft (&optional arg)
13588 "Promote heading or move table column to left.
13589 Calls `org-do-promote' or `org-table-move-column', depending on context.
13590 With no specific context, calls the Emacs default `backward-word'.
13591 See the individual commands for more information."
13594 ((run-hook-with-args-until-success 'org-metaleft-hook))
13595 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
13596 ((or (org-on-heading-p)
13597 (and (org-region-active-p)
13599 (goto-char (region-beginning))
13600 (org-on-heading-p))))
13601 (call-interactively 'org-do-promote))
13602 ((or (org-at-item-p)
13603 (and (org-region-active-p)
13605 (goto-char (region-beginning))
13607 (call-interactively 'org-outdent-item))
13608 (t (call-interactively 'backward-word))))
13610 (defun org-metaright (&optional arg)
13611 "Demote subtree or move table column to right.
13612 Calls `org-do-demote' or `org-table-move-column', depending on context.
13613 With no specific context, calls the Emacs default `forward-word'.
13614 See the individual commands for more information."
13617 ((run-hook-with-args-until-success 'org-metaright-hook))
13618 ((org-at-table-p) (call-interactively 'org-table-move-column))
13619 ((or (org-on-heading-p)
13620 (and (org-region-active-p)
13622 (goto-char (region-beginning))
13623 (org-on-heading-p))))
13624 (call-interactively 'org-do-demote))
13625 ((or (org-at-item-p)
13626 (and (org-region-active-p)
13628 (goto-char (region-beginning))
13630 (call-interactively 'org-indent-item))
13631 (t (call-interactively 'forward-word))))
13633 (defun org-metaup (&optional arg)
13634 "Move subtree up or move table row up.
13635 Calls `org-move-subtree-up' or `org-table-move-row' or
13636 `org-move-item-up', depending on context. See the individual commands
13637 for more information."
13640 ((run-hook-with-args-until-success 'org-metaup-hook))
13641 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
13642 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
13643 ((org-at-item-p) (call-interactively 'org-move-item-up))
13644 (t (transpose-lines 1) (beginning-of-line -1))))
13646 (defun org-metadown (&optional arg)
13647 "Move subtree down or move table row down.
13648 Calls `org-move-subtree-down' or `org-table-move-row' or
13649 `org-move-item-down', depending on context. See the individual
13650 commands for more information."
13653 ((run-hook-with-args-until-success 'org-metadown-hook))
13654 ((org-at-table-p) (call-interactively 'org-table-move-row))
13655 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
13656 ((org-at-item-p) (call-interactively 'org-move-item-down))
13657 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
13659 (defun org-shiftup (&optional arg)
13660 "Increase item in timestamp or increase priority of current headline.
13661 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
13662 depending on context. See the individual commands for more information."
13665 ((and org-support-shift-select (org-region-active-p))
13666 (org-call-for-shift-select 'previous-line))
13667 ((org-at-timestamp-p t)
13668 (call-interactively (if org-edit-timestamp-down-means-later
13669 'org-timestamp-down 'org-timestamp-up)))
13670 ((and (not (eq org-support-shift-select 'always))
13671 (org-on-heading-p))
13672 (call-interactively 'org-priority-up))
13673 ((and (not org-support-shift-select) (org-at-item-p))
13674 (call-interactively 'org-previous-item))
13675 ((org-clocktable-try-shift 'up arg))
13676 (org-support-shift-select
13677 (org-call-for-shift-select 'previous-line))
13678 (t (org-shiftselect-error))))
13680 (defun org-shiftdown (&optional arg)
13681 "Decrease item in timestamp or decrease priority of current headline.
13682 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
13683 depending on context. See the individual commands for more information."
13686 ((and org-support-shift-select (org-region-active-p))
13687 (org-call-for-shift-select 'next-line))
13688 ((org-at-timestamp-p t)
13689 (call-interactively (if org-edit-timestamp-down-means-later
13690 'org-timestamp-up 'org-timestamp-down)))
13691 ((and (not (eq org-support-shift-select 'always))
13692 (org-on-heading-p))
13693 (call-interactively 'org-priority-down))
13694 ((and (not org-support-shift-select) (org-at-item-p))
13695 (call-interactively 'org-next-item))
13696 ((org-clocktable-try-shift 'down arg))
13697 (org-support-shift-select
13698 (org-call-for-shift-select 'next-line))
13699 (t (org-shiftselect-error))))
13701 (defun org-shiftright (&optional arg)
13702 "Cycle the thing at point or in the current line, depending on context.
13703 Depending on context, this does one of the following:
13705 - switch a timestamp at point one day into the future
13706 - on a headline, switch to the next TODO keyword.
13707 - on an item, switch entire list to the next bullet type
13708 - on a property line, switch to the next allowed value
13709 - on a clocktable definition line, move time block into the future"
13712 ((and org-support-shift-select (org-region-active-p))
13713 (org-call-for-shift-select 'forward-char))
13714 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
13715 ((and (not (eq org-support-shift-select 'always))
13716 (org-on-heading-p))
13717 (org-call-with-arg 'org-todo 'right))
13718 ((or (and org-support-shift-select
13719 (not (eq org-support-shift-select 'always))
13720 (org-at-item-bullet-p))
13721 (and (not org-support-shift-select) (org-at-item-p)))
13722 (org-call-with-arg 'org-cycle-list-bullet nil))
13723 ((and (not (eq org-support-shift-select 'always))
13724 (org-at-property-p))
13725 (call-interactively 'org-property-next-allowed-value))
13726 ((org-clocktable-try-shift 'right arg))
13727 (org-support-shift-select
13728 (org-call-for-shift-select 'forward-char))
13729 (t (org-shiftselect-error))))
13731 (defun org-shiftleft (&optional arg)
13732 "Cycle the thing at point or in the current line, depending on context.
13733 Depending on context, this does one of the following:
13735 - switch a timestamp at point one day into the past
13736 - on a headline, switch to the previous TODO keyword.
13737 - on an item, switch entire list to the previous bullet type
13738 - on a property line, switch to the previous allowed value
13739 - on a clocktable definition line, move time block into the past"
13742 ((and org-support-shift-select (org-region-active-p))
13743 (org-call-for-shift-select 'backward-char))
13744 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
13745 ((and (not (eq org-support-shift-select 'always))
13746 (org-on-heading-p))
13747 (org-call-with-arg 'org-todo 'left))
13748 ((or (and org-support-shift-select
13749 (not (eq org-support-shift-select 'always))
13750 (org-at-item-bullet-p))
13751 (and (not org-support-shift-select) (org-at-item-p)))
13752 (org-call-with-arg 'org-cycle-list-bullet 'previous))
13753 ((and (not (eq org-support-shift-select 'always))
13754 (org-at-property-p))
13755 (call-interactively 'org-property-previous-allowed-value))
13756 ((org-clocktable-try-shift 'left arg))
13757 (org-support-shift-select
13758 (org-call-for-shift-select 'backward-char))
13759 (t (org-shiftselect-error))))
13761 (defun org-shiftcontrolright ()
13762 "Switch to next TODO set."
13765 ((and org-support-shift-select (org-region-active-p))
13766 (org-call-for-shift-select 'forward-word))
13767 ((and (not (eq org-support-shift-select 'always))
13768 (org-on-heading-p))
13769 (org-call-with-arg 'org-todo 'nextset))
13770 (org-support-shift-select
13771 (org-call-for-shift-select 'forward-word))
13772 (t (org-shiftselect-error))))
13774 (defun org-shiftcontrolleft ()
13775 "Switch to previous TODO set."
13778 ((and org-support-shift-select (org-region-active-p))
13779 (org-call-for-shift-select 'backward-word))
13780 ((and (not (eq org-support-shift-select 'always))
13781 (org-on-heading-p))
13782 (org-call-with-arg 'org-todo 'previousset))
13783 (org-support-shift-select
13784 (org-call-for-shift-select 'backward-word))
13785 (t (org-shiftselect-error))))
13787 (defun org-ctrl-c-ret ()
13788 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
13791 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
13792 (t (call-interactively 'org-insert-heading))))
13794 (defun org-copy-special ()
13795 "Copy region in table or copy current subtree.
13796 Calls `org-table-copy' or `org-copy-subtree', depending on context.
13797 See the individual commands for more information."
13799 (call-interactively
13800 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
13802 (defun org-cut-special ()
13803 "Cut region in table or cut current subtree.
13804 Calls `org-table-copy' or `org-cut-subtree', depending on context.
13805 See the individual commands for more information."
13807 (call-interactively
13808 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
13810 (defun org-paste-special (arg)
13811 "Paste rectangular region into table, or past subtree relative to level.
13812 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
13813 See the individual commands for more information."
13815 (if (org-at-table-p)
13816 (org-table-paste-rectangle)
13817 (org-paste-subtree arg)))
13819 (defun org-edit-special ()
13820 "Call a special editor for the stuff at point.
13821 When at a table, call the formula editor with `org-table-edit-formulas'.
13822 When at the first line of an src example, call `org-edit-src-code'.
13823 When in an #+include line, visit the include file. Otherwise call
13824 `ffap' to visit the file at point."
13828 (call-interactively 'org-table-edit-formulas))
13830 (beginning-of-line 1)
13831 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
13832 (find-file (org-trim (match-string 1))))
13833 ((org-edit-src-code))
13834 ((org-edit-fixed-width-region))
13835 (t (call-interactively 'ffap))))
13838 (defun org-ctrl-c-ctrl-c (&optional arg)
13839 "Set tags in headline, or update according to changed information at point.
13841 This command does many different things, depending on context:
13843 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
13844 this is what we do.
13846 - If the cursor is in a headline, prompt for tags and insert them
13847 into the current line, aligned to `org-tags-column'. When called
13848 with prefix arg, realign all tags in the current buffer.
13850 - If the cursor is in one of the special #+KEYWORD lines, this
13851 triggers scanning the buffer for these lines and updating the
13854 - If the cursor is inside a table, realign the table. This command
13855 works even if the automatic table editor has been turned off.
13857 - If the cursor is on a #+TBLFM line, re-apply the formulas to
13860 - If the cursor is at a footnote reference or definition, jump to
13861 the corresponding definition or references, respectively.
13863 - If the cursor is a the beginning of a dynamic block, update it.
13865 - If the cursor is inside a table created by the table.el package,
13866 activate that table.
13868 - If the current buffer is a remember buffer, close note and file
13869 it. A prefix argument of 1 files to the default location
13870 without further interaction. A prefix argument of 2 files to
13871 the currently clocking task.
13873 - If the cursor is on a <<<target>>>, update radio targets and corresponding
13874 links in this buffer.
13876 - If the cursor is on a numbered item in a plain list, renumber the
13879 - If the cursor is on a checkbox, toggle it."
13881 (let ((org-enable-table-editor t))
13883 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
13884 org-occur-highlights
13885 org-latex-fragment-image-overlays)
13886 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
13887 (org-remove-occur-highlights)
13888 (org-remove-latex-fragment-image-overlays)
13889 (message "Temporary highlights/overlays removed from current buffer"))
13890 ((and (local-variable-p 'org-finish-function (current-buffer))
13891 (fboundp org-finish-function))
13892 (funcall org-finish-function))
13893 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
13894 ((org-at-property-p)
13895 (call-interactively 'org-property-action))
13896 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
13897 ((org-on-heading-p) (call-interactively 'org-set-tags))
13898 ((org-at-table.el-p)
13900 (beginning-of-line 1)
13901 (re-search-forward "|" (save-excursion (end-of-line 2) (point)))
13902 (call-interactively 'table-recognize-table))
13904 (org-table-maybe-eval-formula)
13906 (call-interactively 'org-table-recalculate)
13907 (org-table-maybe-recalculate-line))
13908 (call-interactively 'org-table-align))
13909 ((or (org-footnote-at-reference-p)
13910 (org-footnote-at-definition-p))
13911 (call-interactively 'org-footnote-action))
13912 ((org-at-item-checkbox-p)
13913 (call-interactively 'org-toggle-checkbox))
13916 (call-interactively 'org-toggle-checkbox)
13917 (call-interactively 'org-maybe-renumber-ordered-list)))
13918 ((save-excursion (beginning-of-line 1) (looking-at "#\\+BEGIN:"))
13920 (beginning-of-line 1)
13921 (save-excursion (org-update-dblock)))
13922 ((save-excursion (beginning-of-line 1) (looking-at "#\\+\\([A-Z]+\\)"))
13924 ((equal (match-string 1) "TBLFM")
13925 ;; Recalculate the table before this line
13927 (beginning-of-line 1)
13928 (skip-chars-backward " \r\n\t")
13929 (if (org-at-table-p)
13930 (org-call-with-arg 'org-table-recalculate t))))
13932 ; (org-set-regexps-and-options)
13933 ; (org-restart-font-lock)
13934 (let ((org-inhibit-startup t)) (org-mode-restart))
13935 (message "Local setup has been refreshed"))))
13936 (t (error "C-c C-c can do nothing useful at this location.")))))
13938 (defun org-mode-restart ()
13939 "Restart Org-mode, to scan again for special lines.
13940 Also updates the keyword regular expressions."
13943 (message "Org-mode restarted"))
13945 (defun org-kill-note-or-show-branches ()
13946 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
13948 (if (not org-finish-function)
13949 (call-interactively 'show-branches)
13950 (let ((org-note-abort t))
13951 (funcall org-finish-function))))
13953 (defun org-return (&optional indent)
13954 "Goto next table row or insert a newline.
13955 Calls `org-table-next-row' or `newline', depending on context.
13956 See the individual commands for more information."
13959 ((bobp) (if indent (newline-and-indent) (newline)))
13961 (org-table-justify-field-maybe)
13962 (call-interactively 'org-table-next-row))
13963 ((and org-return-follows-link
13964 (eq (get-text-property (point) 'face) 'org-link))
13965 (call-interactively 'org-open-at-point))
13966 ((and (org-at-heading-p)
13968 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
13972 (t (if indent (newline-and-indent) (newline)))))
13974 (defun org-return-indent ()
13975 "Goto next table row or insert a newline and indent.
13976 Calls `org-table-next-row' or `newline-and-indent', depending on
13977 context. See the individual commands for more information."
13981 (defun org-ctrl-c-star ()
13982 "Compute table, or change heading status of lines.
13983 Calls `org-table-recalculate' or `org-toggle-heading',
13984 depending on context."
13988 (call-interactively 'org-table-recalculate))
13990 ;; Convert all lines in region to list items
13991 (call-interactively 'org-toggle-heading))))
13993 (defun org-ctrl-c-minus ()
13994 "Insert separator line in table or modify bullet status of line.
13995 Also turns a plain line or a region of lines into list items.
13996 Calls `org-table-insert-hline', `org-toggle-item', or
13997 `org-cycle-list-bullet', depending on context."
14001 (call-interactively 'org-table-insert-hline))
14002 ((org-region-active-p)
14003 (call-interactively 'org-toggle-item))
14005 (call-interactively 'org-cycle-list-bullet))
14007 (call-interactively 'org-toggle-item))))
14009 (defun org-toggle-item ()
14010 "Convert headings or normal lines to items, items to normal lines.
14011 If there is no active region, only the current line is considered.
14013 If the first line in the region is a headline, convert all headlines to items.
14015 If the first line in the region is an item, convert all items to normal lines.
14017 If the first line is normal text, add an item bullet to each line."
14019 (let (l2 l beg end)
14020 (if (org-region-active-p)
14021 (setq beg (region-beginning) end (region-end))
14022 (setq beg (point-at-bol)
14023 end (min (1+ (point-at-eol)) (point-max))))
14026 (setq l2 (org-current-line))
14028 (beginning-of-line 1)
14029 (setq l (1- (org-current-line)))
14030 (if (org-at-item-p)
14031 ;; We already have items, de-itemize
14032 (while (< (setq l (1+ l)) l2)
14033 (when (org-at-item-p)
14034 (goto-char (match-beginning 2))
14035 (delete-region (match-beginning 2) (match-end 2))
14036 (and (looking-at "[ \t]+") (replace-match "")))
14037 (beginning-of-line 2))
14038 (if (org-on-heading-p)
14039 ;; Headings, convert to items
14040 (while (< (setq l (1+ l)) l2)
14041 (if (looking-at org-outline-regexp)
14042 (replace-match "- " t t))
14043 (beginning-of-line 2))
14044 ;; normal lines, turn them into items
14045 (while (< (setq l (1+ l)) l2)
14046 (unless (org-at-item-p)
14047 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
14048 (replace-match "\\1- \\2")))
14049 (beginning-of-line 2)))))))
14051 (defun org-toggle-heading (&optional nstars)
14052 "Convert headings to normal text, or items or text to headings.
14053 If there is no active region, only the current line is considered.
14055 If the first line is a heading, remove the stars from all headlines
14058 If the first line is a plain list item, turn all plain list items into
14061 If the first line is a normal line, turn each and every line in the region
14064 When converting a line into a heading, the number of stars is chosen
14065 such that the lines become children of the current entry. However, when
14066 a prefix argument is given, its value determines the number of stars to add."
14068 (let (l2 l itemp beg end)
14069 (if (org-region-active-p)
14070 (setq beg (region-beginning) end (region-end))
14071 (setq beg (point-at-bol)
14072 end (min (1+ (point-at-eol)) (point-max))))
14075 (setq l2 (org-current-line))
14077 (beginning-of-line 1)
14078 (setq l (1- (org-current-line)))
14079 (if (org-on-heading-p)
14080 ;; We already have headlines, de-star them
14081 (while (< (setq l (1+ l)) l2)
14082 (when (org-on-heading-p t)
14083 (and (looking-at outline-regexp) (replace-match "")))
14084 (beginning-of-line 2))
14085 (setq itemp (org-at-item-p))
14088 (make-string (prefix-numeric-value current-prefix-arg)
14091 (re-search-backward org-complex-heading-regexp nil t)
14092 (or (match-string 1) "*"))))
14093 (add-stars (if nstars "" (if org-odd-levels-only "**" "*")))
14094 (rpl (concat stars add-stars " ")))
14095 (while (< (setq l (1+ l)) l2)
14097 (and (org-at-item-p) (replace-match rpl t t))
14098 (unless (org-on-heading-p)
14099 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
14100 (replace-match (concat rpl (match-string 2))))))
14101 (beginning-of-line 2)))))))
14103 (defun org-meta-return (&optional arg)
14104 "Insert a new heading or wrap a region in a table.
14105 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
14106 See the individual commands for more information."
14109 ((run-hook-with-args-until-success 'org-metareturn-hook))
14111 (call-interactively 'org-table-wrap-region))
14112 (t (call-interactively 'org-insert-heading))))
14116 ;; Define the Org-mode menus
14117 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
14119 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
14120 ["Next Field" org-cycle (org-at-table-p)]
14121 ["Previous Field" org-shifttab (org-at-table-p)]
14122 ["Next Row" org-return (org-at-table-p)]
14124 ["Blank Field" org-table-blank-field (org-at-table-p)]
14125 ["Edit Field" org-table-edit-field (org-at-table-p)]
14126 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
14129 ["Move Column Left" org-metaleft (org-at-table-p)]
14130 ["Move Column Right" org-metaright (org-at-table-p)]
14131 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
14132 ["Insert Column" org-shiftmetaright (org-at-table-p)])
14134 ["Move Row Up" org-metaup (org-at-table-p)]
14135 ["Move Row Down" org-metadown (org-at-table-p)]
14136 ["Delete Row" org-shiftmetaup (org-at-table-p)]
14137 ["Insert Row" org-shiftmetadown (org-at-table-p)]
14138 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
14140 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
14142 ["Copy Rectangle" org-copy-special (org-at-table-p)]
14143 ["Cut Rectangle" org-cut-special (org-at-table-p)]
14144 ["Paste Rectangle" org-paste-special (org-at-table-p)]
14145 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
14148 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
14149 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
14150 ["Edit Formulas" org-edit-special (org-at-table-p)]
14152 ["Recalculate line" org-table-recalculate (org-at-table-p)]
14153 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
14154 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
14156 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
14158 ["Sum Column/Rectangle" org-table-sum
14159 (or (org-at-table-p) (org-region-active-p))]
14160 ["Which Column?" org-table-current-column (org-at-table-p)])
14162 org-table-toggle-formula-debugger
14163 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
14164 ["Show Col/Row Numbers"
14165 org-table-toggle-coordinate-overlays
14167 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
14169 ["Create" org-table-create (and (not (org-at-table-p))
14170 org-enable-table-editor)]
14171 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
14172 ["Import from File" org-table-import (not (org-at-table-p))]
14173 ["Export to File" org-table-export (org-at-table-p)]
14175 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
14177 (easy-menu-define org-org-menu org-mode-map "Org menu"
14180 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
14181 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
14182 ["Sparse Tree..." org-sparse-tree t]
14183 ["Reveal Context" org-reveal t]
14184 ["Show All" show-all t]
14186 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
14188 ["New Heading" org-insert-heading t]
14189 ("Navigate Headings"
14190 ["Up" outline-up-heading t]
14191 ["Next" outline-next-visible-heading t]
14192 ["Previous" outline-previous-visible-heading t]
14193 ["Next Same Level" outline-forward-same-level t]
14194 ["Previous Same Level" outline-backward-same-level t]
14196 ["Jump" org-goto t])
14198 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
14199 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
14201 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
14202 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
14203 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
14205 ["Promote Heading" org-metaleft (not (org-at-table-p))]
14206 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
14207 ["Demote Heading" org-metaright (not (org-at-table-p))]
14208 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
14210 ["Sort Region/Children" org-sort (not (org-at-table-p))]
14212 ["Convert to odd levels" org-convert-to-odd-levels t]
14213 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
14215 ["Emphasis..." org-emphasize t]
14216 ["Edit Source Example" org-edit-special t]
14218 ["Footnote new/jump" org-footnote-action t]
14219 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
14221 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
14222 ; ["Check and Tag Children" (org-toggle-archive-tag (4))
14223 ; :active t :keys "C-u C-c C-x C-a"]
14224 ["Sparse trees open ARCHIVE trees"
14225 (setq org-sparse-tree-open-archived-trees
14226 (not org-sparse-tree-open-archived-trees))
14227 :style toggle :selected org-sparse-tree-open-archived-trees]
14228 ["Cycling opens ARCHIVE trees"
14229 (setq org-cycle-open-archived-trees (not org-cycle-open-archived-trees))
14230 :style toggle :selected org-cycle-open-archived-trees]
14232 ["Move subtree to archive sibling" org-archive-to-archive-sibling t]
14233 ["Move Subtree to Archive" org-advertized-archive-subtree t]
14234 ; ["Check and Move Children" (org-archive-subtree '(4))
14235 ; :active t :keys "C-u C-c C-x C-s"]
14239 ["TODO/DONE/-" org-todo t]
14241 ["Next keyword" org-shiftright (org-on-heading-p)]
14242 ["Previous keyword" org-shiftleft (org-on-heading-p)]
14243 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
14244 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
14245 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
14246 ["Show TODO Tree" org-show-todo-tree t]
14247 ["Global TODO list" org-todo-list t]
14249 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
14250 :selected org-enforce-todo-dependencies :style toggle :active t]
14251 "Settings for tree at point"
14252 ["Do Children sequentially" org-toggle-ordered-property :style radio
14253 :selected (ignore-errors (org-entry-get nil "ORDERED"))
14254 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
14255 ["Do Children parallel" org-toggle-ordered-property :style radio
14256 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
14257 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
14259 ["Set Priority" org-priority t]
14260 ["Priority Up" org-shiftup t]
14261 ["Priority Down" org-shiftdown t])
14262 ("TAGS and Properties"
14263 ["Set Tags" org-set-tags-command t]
14264 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
14266 ["Set property" org-set-property t]
14267 ["Column view of properties" org-columns t]
14268 ["Insert Column View DBlock" org-insert-columns-dblock t])
14269 ("Dates and Scheduling"
14270 ["Timestamp" org-time-stamp t]
14271 ["Timestamp (inactive)" org-time-stamp-inactive t]
14273 ["1 Day Later" org-shiftright t]
14274 ["1 Day Earlier" org-shiftleft t]
14275 ["1 ... Later" org-shiftup t]
14276 ["1 ... Earlier" org-shiftdown t])
14277 ["Compute Time Range" org-evaluate-time-range t]
14278 ["Schedule Item" org-schedule t]
14279 ["Deadline" org-deadline t]
14281 ["Custom time format" org-toggle-time-stamp-overlays
14282 :style radio :selected org-display-custom-times]
14284 ["Goto Calendar" org-goto-calendar t]
14285 ["Date from Calendar" org-date-from-calendar t]
14287 ["Start/Restart Timer" org-timer-start t]
14288 ["Pause/Continue Timer" org-timer-pause-or-continue t]
14289 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
14290 ["Insert Timer String" org-timer t]
14291 ["Insert Timer Item" org-timer-item t])
14293 ["Clock in" org-clock-in t]
14294 ["Clock out" org-clock-out t]
14295 ["Clock cancel" org-clock-cancel t]
14296 ["Goto running clock" org-clock-goto t]
14297 ["Display times" org-clock-display t]
14298 ["Create clock table" org-clock-report t]
14300 ["Record DONE time"
14301 (progn (setq org-log-done (not org-log-done))
14302 (message "Switching to %s will %s record a timestamp"
14303 (car org-done-keywords)
14304 (if org-log-done "automatically" "not")))
14305 :style toggle :selected org-log-done])
14307 ["Agenda Command..." org-agenda t]
14308 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
14309 ("File List for Agenda")
14310 ("Special views current file"
14311 ["TODO Tree" org-show-todo-tree t]
14312 ["Check Deadlines" org-check-deadlines t]
14313 ["Timeline" org-timeline t]
14314 ["Tags/Property tree" org-match-sparse-tree t])
14317 ["Store Link (Global)" org-store-link t]
14318 ["Insert Link" org-insert-link t]
14319 ["Follow Link" org-open-at-point t]
14321 ["Next link" org-next-link t]
14322 ["Previous link" org-previous-link t]
14324 ["Descriptive Links"
14325 (progn (org-add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
14327 :selected (member '(org-link) buffer-invisibility-spec)]
14330 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
14332 :selected (not (member '(org-link) buffer-invisibility-spec))])
14334 ["Export/Publish..." org-export t]
14336 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
14337 :selected org-cdlatex-mode]
14338 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
14339 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
14340 ["Modify math symbol" org-cdlatex-math-modify
14341 (org-inside-LaTeX-fragment-p)]
14342 ["Export LaTeX fragments as images"
14343 (if (featurep 'org-exp)
14344 (setq org-export-with-LaTeX-fragments
14345 (not org-export-with-LaTeX-fragments))
14346 (require 'org-exp))
14347 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
14348 org-export-with-LaTeX-fragments)])
14351 ["Show Version" org-version t]
14352 ["Info Documentation" org-info t])
14354 ["Browse Org Group" org-customize t]
14356 ["Expand This Menu" org-create-customize-menu
14357 (fboundp 'customize-menu-create)])
14360 ["Refresh setup current buffer" org-mode-restart t]
14361 ["Reload Org (after update)" org-reload t]
14362 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
14365 (defun org-info (&optional node)
14366 "Read documentation for Org-mode in the info system.
14367 With optional NODE, go directly to that node."
14369 (info (format "(org)%s" (or node ""))))
14371 (defun org-install-agenda-files-menu ()
14372 (let ((bl (buffer-list)))
14375 (set-buffer (pop bl))
14376 (if (org-mode-p) (setq bl nil)))
14379 '("Org") "File List for Agenda"
14382 ["Edit File List" (org-edit-agenda-file-list) t]
14383 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
14384 ["Remove Current File from List" org-remove-file t]
14385 ["Cycle through agenda files" org-cycle-agenda-files t]
14386 ["Occur in all agenda files" org-occur-in-agenda-files t]
14388 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
14393 (defun org-require-autoloaded-modules ()
14396 '(org-agenda org-archive org-attach org-clock org-colview
14397 org-exp org-id org-export-latex org-publish
14398 org-remember org-table org-timer)))
14401 (defun org-reload (&optional uncompiled)
14402 "Reload all org lisp files.
14403 With prefix arg UNCOMPILED, load the uncompiled versions."
14405 (require 'find-func)
14406 (let* ((dir (file-name-directory (find-library-name "org")))
14407 (files (directory-files dir t "\\.el\\'"))
14408 (remove-re (concat (if (featurep 'xemacs)
14409 "org-colview" "org-colview-xemacs")
14411 (setq files (mapcar 'file-name-sans-extension files))
14412 (setq files (mapcar
14413 (lambda (x) (if (string-match remove-re x) nil x))
14415 (setq files (delq nil files))
14418 (if (and (not uncompiled)
14419 (file-exists-p (concat f ".elc")))
14420 (load (concat f ".elc") nil nil t)
14421 (load (concat f ".el") nil nil t)))
14425 (defun org-customize ()
14426 "Call the customize function with org as argument."
14428 (org-load-modules-maybe)
14429 (org-require-autoloaded-modules)
14430 (customize-browse 'org))
14432 (defun org-create-customize-menu ()
14433 "Create a full customization menu for Org-mode, insert it into the menu."
14435 (org-load-modules-maybe)
14436 (org-require-autoloaded-modules)
14437 (if (fboundp 'customize-menu-create)
14440 '("Org") "Customize"
14441 `(["Browse Org group" org-customize t]
14443 ,(customize-menu-create 'org)
14444 ["Set" Custom-set t]
14445 ["Save" Custom-save t]
14446 ["Reset to Current" Custom-reset-current t]
14447 ["Reset to Saved" Custom-reset-saved t]
14448 ["Reset to Standard Settings" Custom-reset-standard t]))
14449 (message "\"Org\"-menu now contains full customization menu"))
14450 (error "Cannot expand menu (outdated version of cus-edit.el)")))
14452 ;;;; Miscellaneous stuff
14454 ;;; Generally useful functions
14456 (defun org-find-text-property-in-string (prop s)
14457 "Return the first non-nil value of property PROP in string S."
14458 (or (get-text-property 0 prop s)
14459 (get-text-property (or (next-single-property-change 0 prop s) 0)
14462 (defun org-display-warning (message) ;; Copied from Emacs-Muse
14463 "Display the given MESSAGE as a warning."
14464 (if (fboundp 'display-warning)
14465 (display-warning 'org message
14466 (if (featurep 'xemacs)
14469 (let ((buf (get-buffer-create "*Org warnings*")))
14470 (with-current-buffer buf
14471 (goto-char (point-max))
14472 (insert "Warning (Org): " message)
14475 (display-buffer buf)
14478 (defun org-goto-marker-or-bmk (marker &optional bookmark)
14479 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
14480 (if (and marker (marker-buffer marker)
14481 (buffer-live-p (marker-buffer marker)))
14483 (switch-to-buffer (marker-buffer marker))
14484 (if (or (> marker (point-max)) (< marker (point-min)))
14487 (org-show-context 'org-goto))
14489 (bookmark-jump bookmark)
14490 (error "Cannot find location"))))
14492 (defun org-quote-csv-field (s)
14493 "Quote field for inclusion in CSV material."
14494 (if (string-match "[\",]" s)
14495 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
14498 (defun org-plist-delete (plist property)
14499 "Delete PROPERTY from PLIST.
14500 This is in contrast to merely setting it to 0."
14503 (if (not (eq property (car plist)))
14504 (setq p (plist-put p (car plist) (nth 1 plist))))
14505 (setq plist (cddr plist)))
14508 (defun org-force-self-insert (N)
14509 "Needed to enforce self-insert under remapping."
14511 (self-insert-command N))
14513 (defun org-string-width (s)
14514 "Compute width of string, ignoring invisible characters.
14515 This ignores character with invisibility property `org-link', and also
14516 characters with property `org-cwidth', because these will become invisible
14517 upon the next fontification round."
14519 (when (or (eq t buffer-invisibility-spec)
14520 (assq 'org-link buffer-invisibility-spec))
14521 (while (setq b (text-property-any 0 (length s)
14522 'invisible 'org-link s))
14523 (setq s (concat (substring s 0 b)
14524 (substring s (or (next-single-property-change
14525 b 'invisible s) (length s)))))))
14526 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
14527 (setq s (concat (substring s 0 b)
14528 (substring s (or (next-single-property-change
14529 b 'org-cwidth s) (length s))))))
14530 (setq l (string-width s) b -1)
14531 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
14532 (setq l (- l (get-text-property b 'org-dwidth-n s))))
14535 (defun org-get-indentation (&optional line)
14536 "Get the indentation of the current line, interpreting tabs.
14537 When LINE is given, assume it represents a line and compute its indentation."
14539 (if (string-match "^ *" (org-remove-tabs line))
14542 (beginning-of-line 1)
14543 (skip-chars-forward " \t")
14544 (current-column))))
14546 (defun org-remove-tabs (s &optional width)
14547 "Replace tabulators in S with spaces.
14548 Assumes that s is a single line, starting in column 0."
14549 (setq width (or width tab-width))
14550 (while (string-match "\t" s)
14551 (setq s (replace-match
14553 (- (* width (/ (+ (match-beginning 0) width) width))
14554 (match-beginning 0)) ?\ )
14558 (defun org-fix-indentation (line ind)
14559 "Fix indentation in LINE.
14560 IND is a cons cell with target and minimum indentation.
14561 If the current indentation in LINE is smaller than the minimum,
14562 leave it alone. If it is larger than ind, set it to the target."
14563 (let* ((l (org-remove-tabs line))
14564 (i (org-get-indentation l))
14565 (i1 (car ind)) (i2 (cdr ind)))
14566 (if (>= i i2) (setq l (substring line i2)))
14568 (concat (make-string i1 ?\ ) l)
14571 (defun org-base-buffer (buffer)
14572 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
14575 (or (buffer-base-buffer buffer)
14578 (defun org-trim (s)
14579 "Remove whitespace at beginning and end of string."
14580 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
14581 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
14584 (defun org-wrap (string &optional width lines)
14585 "Wrap string to either a number of lines, or a width in characters.
14586 If WIDTH is non-nil, the string is wrapped to that width, however many lines
14587 that costs. If there is a word longer than WIDTH, the text is actually
14588 wrapped to the length of that word.
14589 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
14590 many lines, whatever width that takes.
14591 The return value is a list of lines, without newlines at the end."
14592 (let* ((words (org-split-string string "[ \t\n]+"))
14593 (maxword (apply 'max (mapcar 'org-string-width words)))
14596 (org-do-wrap words (max maxword width)))
14599 (setq ll (org-do-wrap words maxword))
14600 (if (<= (length ll) lines)
14603 (while (> (length ll) lines)
14605 (setq ll (org-do-wrap words w)))
14607 (t (error "Cannot wrap this")))))
14609 (defun org-do-wrap (words width)
14610 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
14613 (setq line (pop words))
14614 (while (and words (< (+ (length line) (length (car words))) width))
14615 (setq line (concat line " " (pop words))))
14616 (setq lines (push line lines)))
14619 (defun org-split-string (string &optional separators)
14620 "Splits STRING into substrings at SEPARATORS.
14621 No empty strings are returned if there are matches at the beginning
14622 and end of string."
14623 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
14627 (while (and (string-match rexp string
14629 (= start (match-beginning 0))
14630 (< start (length string)))
14632 (< (match-beginning 0) (length string)))
14634 (or (eq (match-beginning 0) 0)
14635 (and (eq (match-beginning 0) (match-end 0))
14636 (eq (match-beginning 0) start))
14638 (cons (substring string start (match-beginning 0))
14640 (setq start (match-end 0)))
14641 (or (eq start (length string))
14643 (cons (substring string start)
14647 (defun org-uuidgen-p (s)
14648 "Is S an ID created by UUIDGEN?"
14649 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
14651 (defun org-context ()
14652 "Return a list of contexts of the current cursor position.
14653 If several contexts apply, all are returned.
14654 Each context entry is a list with a symbol naming the context, and
14655 two positions indicating start and end of the context. Possible
14658 :headline anywhere in a headline
14659 :headline-stars on the leading stars in a headline
14660 :todo-keyword on a TODO keyword (including DONE) in a headline
14661 :tags on the TAGS in a headline
14662 :priority on the priority cookie in a headline
14663 :item on the first line of a plain list item
14664 :item-bullet on the bullet/number of a plain list item
14665 :checkbox on the checkbox in a plain list item
14666 :table in an org-mode table
14667 :table-special on a special filed in a table
14668 :table-table in a table.el table
14669 :link on a hyperlink
14670 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
14671 :target on a <<target>>
14672 :radio-target on a <<<radio-target>>>
14673 :latex-fragment on a LaTeX fragment
14674 :latex-preview on a LaTeX fragment with overlayed preview image
14676 This function expects the position to be visible because it uses font-lock
14677 faces as a help to recognize the following contexts: :table-special, :link,
14679 (let* ((f (get-text-property (point) 'face))
14680 (faces (if (listp f) f (list f)))
14681 (p (point)) clist o)
14682 ;; First the large context
14684 ((org-on-heading-p t)
14685 (push (list :headline (point-at-bol) (point-at-eol)) clist)
14687 (beginning-of-line 1)
14688 (looking-at org-todo-line-tags-regexp))
14689 (push (org-point-in-group p 1 :headline-stars) clist)
14690 (push (org-point-in-group p 2 :todo-keyword) clist)
14691 (push (org-point-in-group p 4 :tags) clist))
14693 (skip-chars-backward "^[\n\r \t") (or (eobp) (backward-char 1))
14694 (if (looking-at "\\[#[A-Z0-9]\\]")
14695 (push (org-point-in-group p 0 :priority) clist)))
14698 (push (org-point-in-group p 2 :item-bullet) clist)
14699 (push (list :item (point-at-bol)
14700 (save-excursion (org-end-of-item) (point)))
14702 (and (org-at-item-checkbox-p)
14703 (push (org-point-in-group p 0 :checkbox) clist)))
14706 (push (list :table (org-table-begin) (org-table-end)) clist)
14707 (if (memq 'org-formula faces)
14708 (push (list :table-special
14709 (previous-single-property-change p 'face)
14710 (next-single-property-change p 'face)) clist)))
14711 ((org-at-table-p 'any)
14712 (push (list :table-table) clist)))
14715 ;; Now the small context
14717 ((org-at-timestamp-p)
14718 (push (org-point-in-group p 0 :timestamp) clist))
14719 ((memq 'org-link faces)
14721 (previous-single-property-change p 'face)
14722 (next-single-property-change p 'face)) clist))
14723 ((memq 'org-special-keyword faces)
14724 (push (list :keyword
14725 (previous-single-property-change p 'face)
14726 (next-single-property-change p 'face)) clist))
14728 (push (org-point-in-group p 0 :target) clist)
14729 (goto-char (1- (match-beginning 0)))
14730 (if (looking-at org-radio-target-regexp)
14731 (push (org-point-in-group p 0 :radio-target) clist))
14733 ((setq o (car (delq nil
14736 (if (memq x org-latex-fragment-image-overlays) x))
14737 (org-overlays-at (point))))))
14738 (push (list :latex-fragment
14739 (org-overlay-start o) (org-overlay-end o)) clist)
14740 (push (list :latex-preview
14741 (org-overlay-start o) (org-overlay-end o)) clist))
14742 ((org-inside-LaTeX-fragment-p)
14743 ;; FIXME: positions wrong.
14744 (push (list :latex-fragment (point) (point)) clist)))
14746 (setq clist (nreverse (delq nil clist)))
14749 ;; FIXME: Compare with at-regexp-p Do we need both?
14750 (defun org-in-regexp (re &optional nlines visually)
14751 "Check if point is inside a match of regexp.
14752 Normally only the current line is checked, but you can include NLINES extra
14753 lines both before and after point into the search.
14754 If VISUALLY is set, require that the cursor is not after the match but
14755 really on, so that the block visually is on the match."
14757 (let ((pos (point))
14758 (eol (point-at-eol (+ 1 (or nlines 0))))
14759 (inc (if visually 1 0)))
14761 (beginning-of-line (- 1 (or nlines 0)))
14762 (while (re-search-forward re eol t)
14763 (if (and (<= (match-beginning 0) pos)
14764 (>= (+ inc (match-end 0)) pos))
14765 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
14767 (defun org-at-regexp-p (regexp)
14768 "Is point inside a match of REGEXP in the current line?"
14771 (let ((pos (point)) (end (point-at-eol)))
14772 (beginning-of-line 1)
14773 (while (re-search-forward regexp end t)
14774 (if (and (<= (match-beginning 0) pos)
14775 (>= (match-end 0) pos))
14779 (defun org-occur-in-agenda-files (regexp &optional nlines)
14780 "Call `multi-occur' with buffers for all agenda files."
14781 (interactive "sOrg-files matching: \np")
14782 (let* ((files (org-agenda-files))
14783 (tnames (mapcar 'file-truename files))
14784 (extra org-agenda-text-search-extra-files)
14786 (when (eq (car extra) 'agenda-archives)
14787 (setq extra (cdr extra))
14788 (setq files (org-add-archive-files files)))
14789 (while (setq f (pop extra))
14790 (unless (member (file-truename f) tnames)
14791 (add-to-list 'files f 'append)
14792 (add-to-list 'tnames (file-truename f) 'append)))
14794 (mapcar (lambda (x) (or (get-file-buffer x) (find-file-noselect x))) files)
14797 (if (boundp 'occur-mode-find-occurrence-hook)
14799 (add-hook 'occur-mode-find-occurrence-hook
14804 (defadvice occur-mode-goto-occurrence
14805 (after org-occur-reveal activate)
14806 (and (org-mode-p) (org-reveal)))
14807 (defadvice occur-mode-goto-occurrence-other-window
14808 (after org-occur-reveal activate)
14809 (and (org-mode-p) (org-reveal)))
14810 (defadvice occur-mode-display-occurrence
14811 (after org-occur-reveal activate)
14813 (let ((pos (occur-mode-find-occurrence)))
14814 (with-current-buffer (marker-buffer pos)
14819 (defun org-uniquify (list)
14820 "Remove duplicate elements from LIST."
14822 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
14825 (defun org-delete-all (elts list)
14826 "Remove all elements in ELTS from LIST."
14828 (setq list (delete (pop elts) list)))
14831 (defun org-back-over-empty-lines ()
14832 "Move backwards over whitespace, to the beginning of the first empty line.
14833 Returns the number of empty lines passed."
14834 (let ((pos (point)))
14835 (skip-chars-backward " \t\n\r")
14836 (beginning-of-line 2)
14837 (goto-char (min (point) pos))
14838 (count-lines (point) pos)))
14840 (defun org-skip-whitespace ()
14841 (skip-chars-forward " \t\n\r"))
14843 (defun org-point-in-group (point group &optional context)
14844 "Check if POINT is in match-group GROUP.
14845 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
14846 match. If the match group does ot exist or point is not inside it,
14848 (and (match-beginning group)
14849 (>= point (match-beginning group))
14850 (<= point (match-end group))
14852 (list context (match-beginning group) (match-end group))
14855 (defun org-switch-to-buffer-other-window (&rest args)
14856 "Switch to buffer in a second window on the current frame.
14857 In particular, do not allow pop-up frames."
14858 (let (pop-up-frames special-display-buffer-names special-display-regexps
14859 special-display-function)
14860 (apply 'switch-to-buffer-other-window args)))
14862 (defun org-combine-plists (&rest plists)
14863 "Create a single property list from all plists in PLISTS.
14864 The process starts by copying the first list, and then setting properties
14865 from the other lists. Settings in the last list are the most significant
14866 ones and overrule settings in the other lists."
14867 (let ((rtn (copy-sequence (pop plists)))
14870 (setq ls (pop plists))
14872 (setq p (pop ls) v (pop ls))
14873 (setq rtn (plist-put rtn p v))))
14876 (defun org-move-line-down (arg)
14877 "Move the current line down. With prefix argument, move it past ARG lines."
14879 (let ((col (current-column))
14881 (beginning-of-line 1) (setq beg (point))
14882 (beginning-of-line 2) (setq end (point))
14883 (beginning-of-line (+ 1 arg))
14884 (setq pos (move-marker (make-marker) (point)))
14885 (insert (delete-and-extract-region beg end))
14887 (org-move-to-column col)))
14889 (defun org-move-line-up (arg)
14890 "Move the current line up. With prefix argument, move it past ARG lines."
14892 (let ((col (current-column))
14894 (beginning-of-line 1) (setq beg (point))
14895 (beginning-of-line 2) (setq end (point))
14896 (beginning-of-line (- arg))
14897 (setq pos (move-marker (make-marker) (point)))
14898 (insert (delete-and-extract-region beg end))
14900 (org-move-to-column col)))
14902 (defun org-replace-escapes (string table)
14903 "Replace %-escapes in STRING with values in TABLE.
14904 TABLE is an association list with keys like \"%a\" and string values.
14905 The sequences in STRING may contain normal field width and padding information,
14906 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
14907 so values can contain further %-escapes if they are define later in TABLE."
14908 (let ((case-fold-search nil)
14910 (while (setq e (pop table))
14911 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
14912 (while (string-match re string)
14913 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
14915 (setq string (replace-match rpl t t string))))
14919 (defun org-sublist (list start end)
14920 "Return a section of LIST, from START to END.
14921 Counting starts at 1."
14922 (let (rtn (c start))
14923 (setq list (nthcdr (1- start) list))
14924 (while (and list (<= c end))
14925 (push (pop list) rtn)
14929 (defun org-find-base-buffer-visiting (file)
14930 "Like `find-buffer-visiting' but alway return the base buffer and
14931 not an indirect buffer."
14932 (let ((buf (find-buffer-visiting file)))
14934 (or (buffer-base-buffer buf) buf)
14937 (defun org-image-file-name-regexp (&optional extensions)
14938 "Return regexp matching the file names of images.
14939 If EXTENSIONS is given, only match these."
14940 (if (and (not extensions) (fboundp 'image-file-name-regexp))
14941 (image-file-name-regexp)
14942 (let ((image-file-name-extensions
14944 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
14945 "xbm" "xpm" "pbm" "pgm" "ppm"))))
14947 (regexp-opt (nconc (mapcar 'upcase
14948 image-file-name-extensions)
14949 image-file-name-extensions)
14953 (defun org-file-image-p (file &optional extensions)
14954 "Return non-nil if FILE is an image."
14956 (string-match (org-image-file-name-regexp extensions) file)))
14958 (defun org-get-cursor-date ()
14959 "Return the date at cursor in as a time.
14960 This works in the calendar and in the agenda, anywhere else it just
14961 returns the current time."
14962 (let (date day defd)
14964 ((eq major-mode 'calendar-mode)
14965 (setq date (calendar-cursor-to-date)
14966 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14967 ((eq major-mode 'org-agenda-mode)
14968 (setq day (get-text-property (point) 'day))
14970 (setq date (calendar-gregorian-from-absolute day)
14971 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
14973 (or defd (current-time))))
14975 (defvar org-agenda-action-marker (make-marker)
14976 "Marker pointing to the entry for the next agenda action.")
14978 (defun org-mark-entry-for-agenda-action ()
14979 "Mark the current entry as target of an agenda action.
14980 Agenda actions are actions executed from the agenda with the key `k',
14981 which make use of the date at the cursor."
14983 (move-marker org-agenda-action-marker
14984 (save-excursion (org-back-to-heading t) (point))
14987 "Entry marked for action; press `k' at desired date in agenda or calendar"))
14989 ;;; Paragraph filling stuff.
14990 ;; We want this to be just right, so use the full arsenal.
14992 (defun org-indent-line-function ()
14993 "Indent line like previous, but further if previous was headline or item."
14995 (let* ((pos (point))
14996 (itemp (org-at-item-p))
14997 (org-drawer-regexp (or org-drawer-regexp "\000"))
14998 column bpos bcol tpos tcol bullet btype bullet-type)
14999 ;; Find the previous relevant line
15000 (beginning-of-line 1)
15002 ((looking-at "#") (setq column 0))
15003 ((looking-at "\\*+ ") (setq column 0))
15004 ((and (looking-at "[ \t]*:END:")
15005 (save-excursion (re-search-backward org-drawer-regexp nil t)))
15007 (goto-char (1- (match-beginning 1)))
15008 (setq column (current-column))))
15010 (beginning-of-line 0)
15011 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
15012 (not (looking-at "[ \t]*:END:"))
15013 (not (looking-at org-drawer-regexp)))
15014 (beginning-of-line 0))
15016 ((looking-at "\\*+[ \t]+")
15017 (if (not org-adapt-indentation)
15019 (goto-char (match-end 0))
15020 (setq column (current-column))))
15021 ((looking-at org-drawer-regexp)
15022 (goto-char (1- (match-beginning 1)))
15023 (setq column (current-column)))
15024 ((looking-at "\\([ \t]*\\):END:")
15025 (goto-char (match-end 1))
15026 (setq column (current-column)))
15028 (org-beginning-of-item)
15029 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
15030 (setq bpos (match-beginning 1) tpos (match-end 0)
15031 bcol (progn (goto-char bpos) (current-column))
15032 tcol (progn (goto-char tpos) (current-column))
15033 bullet (match-string 1)
15034 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
15035 (if (> tcol (+ bcol org-description-max-indent))
15036 (setq tcol (+ bcol 5)))
15040 (beginning-of-line 1)
15041 (if (looking-at "\\S-")
15043 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
15044 (setq bullet (match-string 1)
15045 btype (if (string-match "[0-9]" bullet) "n" bullet))
15046 (setq column (if (equal btype bullet-type) bcol tcol)))
15047 (setq column (org-get-indentation)))))
15048 (t (setq column (org-get-indentation))))))
15050 (if (<= (current-column) (current-indentation))
15051 (org-indent-line-to column)
15052 (save-excursion (org-indent-line-to column)))
15053 (setq column (current-column))
15054 (beginning-of-line 1)
15056 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
15057 (replace-match (concat "\\1" (format org-property-format
15058 (match-string 2) (match-string 3)))
15060 (org-move-to-column column)))
15062 (defun org-set-autofill-regexps ()
15064 ;; In the paragraph separator we include headlines, because filling
15065 ;; text in a line directly attached to a headline would otherwise
15066 ;; fill the headline as well.
15067 (org-set-local 'comment-start-skip "^#+[ \t]*")
15068 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|]")
15069 ;; The paragraph starter includes hand-formatted lists.
15070 (org-set-local 'paragraph-start
15071 "\f\\|[ ]*$\\|\\*+ \\|\f\\|[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)\\|[ \t]*[:|]")
15072 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
15073 ;; But only if the user has not turned off tables or fixed-width regions
15075 'auto-fill-inhibit-regexp
15076 (concat "\\*+ \\|#\\+"
15077 "\\|[ \t]*" org-keyword-time-regexp
15078 (if (or org-enable-table-editor org-enable-fixed-width-editor)
15081 (if org-enable-table-editor "|" "")
15082 (if org-enable-fixed-width-editor ":" "")
15084 ;; We use our own fill-paragraph function, to make sure that tables
15085 ;; and fixed-width regions are not wrapped. That function will pass
15086 ;; through to `fill-paragraph' when appropriate.
15087 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
15088 ; Adaptive filling: To get full control, first make sure that
15089 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
15090 (org-set-local 'adaptive-fill-regexp "\000")
15091 (org-set-local 'adaptive-fill-function
15092 'org-adaptive-fill-function)
15094 'align-mode-rules-list
15095 '((org-in-buffer-settings
15096 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
15097 (modes . '(org-mode))))))
15099 (defun org-fill-paragraph (&optional justify)
15100 "Re-align a table, pass through to fill-paragraph if no table."
15101 (let ((table-p (org-at-table-p))
15102 (table.el-p (org-at-table.el-p)))
15103 (cond ((and (equal (char-after (point-at-bol)) ?*)
15104 (save-excursion (goto-char (point-at-bol))
15105 (looking-at outline-regexp)))
15106 t) ; skip headlines
15107 (table.el-p t) ; skip table.el tables
15108 (table-p (org-table-align) t) ; align org-mode tables
15109 (t nil)))) ; call paragraph-fill
15111 ;; For reference, this is the default value of adaptive-fill-regexp
15112 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
15114 (defun org-adaptive-fill-function ()
15115 "Return a fill prefix for org-mode files.
15116 In particular, this makes sure hanging paragraphs for hand-formatted lists
15118 (cond ((looking-at "#[ \t]+")
15120 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
15122 (if (> (match-end 1) (+ (match-beginning 1)
15123 org-description-max-indent))
15124 (goto-char (+ (match-beginning 1) 5))
15125 (goto-char (match-end 0)))
15126 (make-string (current-column) ?\ )))
15127 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)?")
15129 (goto-char (match-end 0))
15130 (make-string (current-column) ?\ )))
15135 (defun org-toggle-fixed-width-section (arg)
15136 "Toggle the fixed-width export.
15137 If there is no active region, the QUOTE keyword at the current headline is
15138 inserted or removed. When present, it causes the text between this headline
15139 and the next to be exported as fixed-width text, and unmodified.
15140 If there is an active region, this command adds or removes a colon as the
15141 first character of this line. If the first character of a line is a colon,
15142 this line is also exported in fixed-width font."
15145 (regionp (org-region-active-p))
15146 (beg (if regionp (region-beginning) (point)))
15147 (end (if regionp (region-end)))
15148 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
15149 (case-fold-search nil)
15150 (re "[ \t]*\\(:\\)")
15155 (setq cc (current-column))
15156 (beginning-of-line 1)
15157 (setq off (looking-at re))
15158 (while (> nlines 0)
15159 (setq nlines (1- nlines))
15160 (beginning-of-line 1)
15163 (org-move-to-column cc t)
15166 ((and off (looking-at re))
15167 (replace-match "" t t nil 1))
15168 ((not off) (org-move-to-column cc t) (insert ":")))
15171 (org-back-to-heading)
15172 (if (looking-at (concat outline-regexp
15173 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
15174 (replace-match "" t t nil 1)
15175 (if (looking-at outline-regexp)
15177 (goto-char (match-end 0))
15178 (insert org-quote-string " "))))))))
15180 ;;;; Functions extending outline functionality
15182 (defun org-beginning-of-line (&optional arg)
15183 "Go to the beginning of the current line. If that is invisible, continue
15184 to a visible line beginning. This makes the function of C-a more intuitive.
15185 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
15186 first attempt, and only move to after the tags when the cursor is already
15187 beyond the end of the headline."
15189 (let ((pos (point))
15190 (special (if (consp org-special-ctrl-a/e)
15191 (car org-special-ctrl-a/e)
15192 org-special-ctrl-a/e))
15194 (beginning-of-line 1)
15195 (if (and arg (fboundp 'move-beginning-of-line))
15196 (call-interactively 'move-beginning-of-line)
15200 (if (org-invisible-p)
15201 (while (and (not (bobp)) (org-invisible-p))
15203 (beginning-of-line 1))
15204 (forward-char 1))))
15207 ((and (looking-at org-complex-heading-regexp)
15208 (= (char-after (match-end 1)) ?\ ))
15209 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
15213 (cond ((> pos refpos) refpos)
15214 ((= pos (point)) refpos)
15216 (cond ((> pos (point)) (point))
15217 ((not (eq last-command this-command)) (point))
15222 (cond ((> pos (match-end 4)) (match-end 4))
15223 ((= pos (point)) (match-end 4))
15225 (cond ((> pos (point)) (point))
15226 ((not (eq last-command this-command)) (point))
15227 (t (match-end 4))))))))
15229 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
15231 (defun org-end-of-line (&optional arg)
15232 "Go to the end of the line.
15233 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
15234 first attempt, and only move to after the tags when the cursor is already
15235 beyond the end of the headline."
15237 (let ((special (if (consp org-special-ctrl-a/e)
15238 (cdr org-special-ctrl-a/e)
15239 org-special-ctrl-a/e)))
15240 (if (or (not special)
15241 (not (org-on-heading-p))
15243 (call-interactively (if (fboundp 'move-end-of-line)
15246 (let ((pos (point)))
15247 (beginning-of-line 1)
15248 (if (looking-at (org-re ".*?\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
15250 (if (or (< pos (match-beginning 1))
15251 (= pos (match-end 0)))
15252 (goto-char (match-beginning 1))
15253 (goto-char (match-end 0)))
15254 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
15255 (goto-char (match-end 0))
15256 (goto-char (match-beginning 1))))
15257 (call-interactively (if (fboundp 'move-end-of-line)
15261 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
15263 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
15264 (define-key org-mode-map "\C-e" 'org-end-of-line)
15266 (defun org-kill-line (&optional arg)
15267 "Kill line, to tags or end of line."
15270 ((or (not org-special-ctrl-k)
15272 (not (org-on-heading-p)))
15273 (call-interactively 'kill-line))
15274 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
15275 (kill-region (point) (match-beginning 1))
15276 (org-set-tags nil t))
15277 (t (kill-region (point) (point-at-eol)))))
15279 (define-key org-mode-map "\C-k" 'org-kill-line)
15281 (defun org-yank (&optional arg)
15282 "Yank. If the kill is a subtree, treat it specially.
15283 This command will look at the current kill and check if is a single
15284 subtree, or a series of subtrees[1]. If it passes the test, and if the
15285 cursor is at the beginning of a line or after the stars of a currently
15286 empty headline, then the yank is handled specially. How exactly depends
15287 on the value of the following variables, both set by default.
15289 org-yank-folded-subtrees
15290 When set, the subtree(s) will be folded after insertion, but only
15291 if doing so would now swallow text after the yanked text.
15293 org-yank-adjusted-subtrees
15294 When set, the subtree will be promoted or demoted in order to
15295 fit into the local outline tree structure, which means that the level
15296 will be adjusted so that it becomes the smaller one of the two
15297 *visible* surrounding headings.
15299 Any prefix to this command will cause `yank' to be called directly with
15300 no special treatment. In particular, a simple `C-u' prefix will just
15301 plainly yank the text as it is.
15303 \[1] Basically, the test checks if the first non-white line is a heading
15304 and if there are no other headings with fewer stars."
15306 (setq this-command 'yank)
15308 (call-interactively 'yank)
15309 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
15310 (and (org-kill-is-subtree-p)
15312 (and (looking-at "[ \t]*$")
15315 (buffer-substring (point-at-bol) (point)))))))
15318 ((and subtreep org-yank-folded-subtrees)
15319 (let ((beg (point))
15321 (if (and subtreep org-yank-adjusted-subtrees)
15322 (org-paste-subtree nil nil 'for-yank)
15323 (call-interactively 'yank))
15326 (when (and (bolp) subtreep
15327 (not (setq swallowp
15328 (org-yank-folding-would-swallow-text beg end))))
15329 (or (looking-at outline-regexp)
15330 (re-search-forward (concat "^" outline-regexp) end t))
15331 (while (and (< (point) end) (looking-at outline-regexp))
15333 (org-cycle-show-empty-lines 'folded)
15334 (condition-case nil
15335 (outline-forward-same-level 1)
15336 (error (goto-char end)))))
15339 "Yanked text not folded because that would swallow text"))
15341 (skip-chars-forward " \t\n\r")
15342 (beginning-of-line 1)
15343 (push-mark beg 'nomsg)))
15344 ((and subtreep org-yank-adjusted-subtrees)
15345 (let ((beg (point-at-bol)))
15346 (org-paste-subtree nil nil 'for-yank)
15347 (push-mark beg 'nomsg)))
15349 (call-interactively 'yank))))))
15351 (defun org-yank-folding-would-swallow-text (beg end)
15352 "Would hide-subtree at BEG swallow any text after END?"
15356 (when (or (looking-at outline-regexp)
15357 (re-search-forward (concat "^" outline-regexp) end t))
15358 (setq level (org-outline-level)))
15360 (skip-chars-forward " \t\r\n\v\f")
15362 (and (bolp) (looking-at org-outline-regexp)
15363 (<= (org-outline-level) level)))
15364 nil ; Nothing would be swallowed
15365 t)))) ; something would swallow
15367 (define-key org-mode-map "\C-y" 'org-yank)
15369 (defun org-invisible-p ()
15370 "Check if point is at a character currently not visible."
15371 ;; Early versions of noutline don't have `outline-invisible-p'.
15372 (if (fboundp 'outline-invisible-p)
15373 (outline-invisible-p)
15374 (get-char-property (point) 'invisible)))
15376 (defun org-invisible-p2 ()
15377 "Check if point is at a character currently not visible."
15379 (if (and (eolp) (not (bobp))) (backward-char 1))
15380 ;; Early versions of noutline don't have `outline-invisible-p'.
15381 (if (fboundp 'outline-invisible-p)
15382 (outline-invisible-p)
15383 (get-char-property (point) 'invisible))))
15385 (defun org-back-to-heading (&optional invisible-ok)
15386 "Call `outline-back-to-heading', but provide a better error message."
15387 (condition-case nil
15388 (outline-back-to-heading invisible-ok)
15389 (error (error "Before first headline at position %d in buffer %s"
15390 (point) (current-buffer)))))
15392 (defun org-before-first-heading-p ()
15393 "Before first heading?"
15395 (null (re-search-backward "^\\*+ " nil t))))
15397 (defalias 'org-on-heading-p 'outline-on-heading-p)
15398 (defalias 'org-at-heading-p 'outline-on-heading-p)
15399 (defun org-at-heading-or-item-p ()
15400 (or (org-on-heading-p) (org-at-item-p)))
15402 (defun org-on-target-p ()
15403 (or (org-in-regexp org-radio-target-regexp)
15404 (org-in-regexp org-target-regexp)))
15406 (defun org-up-heading-all (arg)
15407 "Move to the heading line of which the present line is a subheading.
15408 This function considers both visible and invisible heading lines.
15409 With argument, move up ARG levels."
15410 (if (fboundp 'outline-up-heading-all)
15411 (outline-up-heading-all arg) ; emacs 21 version of outline.el
15412 (outline-up-heading arg t))) ; emacs 22 version of outline.el
15414 (defun org-up-heading-safe ()
15415 "Move to the heading line of which the present line is a subheading.
15416 This version will not throw an error. It will return the level of the
15417 headline found, or nil if no higher level is found."
15418 (let (start-level re)
15419 (org-back-to-heading t)
15420 (setq start-level (funcall outline-level))
15421 (if (equal start-level 1)
15423 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
15424 (if (re-search-backward re nil t)
15425 (funcall outline-level)))))
15427 (defun org-first-sibling-p ()
15428 "Is this heading the first child of its parents?"
15430 (let ((re (concat "^" outline-regexp))
15432 (unless (org-at-heading-p t)
15433 (error "Not at a heading"))
15434 (setq level (funcall outline-level))
15436 (if (not (re-search-backward re nil t))
15438 (setq l (funcall outline-level))
15441 (defun org-goto-sibling (&optional previous)
15442 "Goto the next sibling, even if it is invisible.
15443 When PREVIOUS is set, go to the previous sibling instead. Returns t
15444 when a sibling was found. When none is found, return nil and don't
15446 (let ((fun (if previous 're-search-backward 're-search-forward))
15448 (re (concat "^" outline-regexp))
15450 (when (condition-case nil (org-back-to-heading t) (error nil))
15451 (setq level (funcall outline-level))
15453 (or previous (forward-char 1))
15454 (while (funcall fun re nil t)
15455 (setq l (funcall outline-level))
15456 (when (< l level) (goto-char pos) (throw 'exit nil))
15457 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
15461 (defun org-show-siblings ()
15462 "Show all siblings of the current headline."
15464 (while (org-goto-sibling) (org-flag-heading nil)))
15466 (while (org-goto-sibling 'previous)
15467 (org-flag-heading nil))))
15469 (defun org-show-hidden-entry ()
15470 "Show an entry where even the heading is hidden."
15474 (defun org-flag-heading (flag &optional entry)
15475 "Flag the current heading. FLAG non-nil means make invisible.
15476 When ENTRY is non-nil, show the entire entry."
15478 (org-back-to-heading t)
15479 ;; Check if we should show the entire entry
15484 (and (outline-next-heading)
15485 (org-flag-heading nil))))
15486 (outline-flag-region (max (point-min) (1- (point)))
15487 (save-excursion (outline-end-of-heading) (point))
15490 (defun org-forward-same-level (arg)
15491 "Move forward to the ARG'th subheading at same level as this one.
15492 Stop at the first and last subheadings of a superior heading.
15493 This is like outline-forward-same-level, but invisible headings are ok."
15495 (org-back-to-heading t)
15497 (let ((point-to-move-to (save-excursion
15498 (org-get-next-sibling))))
15499 (if point-to-move-to
15501 (goto-char point-to-move-to)
15502 (setq arg (1- arg)))
15505 (error "No following same-level heading"))))))
15507 (defun org-get-next-sibling ()
15508 "Move to next heading of the same level, and return point.
15509 If there is no such heading, return nil.
15510 This is like outline-next-sibling, but invisible headings are ok."
15511 (let ((level (funcall outline-level)))
15512 (outline-next-heading)
15513 (while (and (not (eobp)) (> (funcall outline-level) level))
15514 (outline-next-heading))
15515 (if (or (eobp) (< (funcall outline-level) level))
15519 (defun org-end-of-subtree (&optional invisible-OK to-heading)
15520 ;; This is an exact copy of the original function, but it uses
15521 ;; `org-back-to-heading', to make it work also in invisible
15522 ;; trees. And is uses an invisible-OK argument.
15523 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
15524 (org-back-to-heading invisible-OK)
15526 (level (funcall outline-level)))
15527 (while (and (not (eobp))
15528 (or first (> (funcall outline-level) level)))
15530 (outline-next-heading))
15532 (if (memq (preceding-char) '(?\n ?\^M))
15534 ;; Go to end of line before heading
15536 (if (memq (preceding-char) '(?\n ?\^M))
15537 ;; leave blank line before heading
15538 (forward-char -1))))))
15541 (defun org-show-subtree ()
15542 "Show everything after this heading at deeper levels."
15543 (outline-flag-region
15546 (outline-end-of-subtree) (outline-next-heading) (point))
15549 (defun org-show-entry ()
15550 "Show the body directly following this heading.
15551 Show the heading too, if it is currently invisible."
15554 (condition-case nil
15556 (org-back-to-heading t)
15557 (outline-flag-region
15558 (max (point-min) (1- (point)))
15560 (if (re-search-forward
15561 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
15562 (match-beginning 1)
15567 (defun org-make-options-regexp (kwds &optional extra)
15568 "Make a regular expression for keyword lines."
15572 (mapconcat 'regexp-quote kwds "\\|")
15573 (if extra (concat "\\|" extra))
15577 ;; Make isearch reveal the necessary context
15578 (defun org-isearch-end ()
15579 "Reveal context after isearch exits."
15580 (when isearch-success ; only if search was successful
15581 (if (featurep 'xemacs)
15582 ;; Under XEmacs, the hook is run in the correct place,
15583 ;; we directly show the context.
15584 (org-show-context 'isearch)
15585 ;; In Emacs the hook runs *before* restoring the overlays.
15586 ;; So we have to use a one-time post-command-hook to do this.
15587 ;; (Emacs 22 has a special variable, see function `org-mode')
15588 (unless (and (boundp 'isearch-mode-end-hook-quit)
15589 isearch-mode-end-hook-quit)
15590 ;; Only when the isearch was not quitted.
15591 (org-add-hook 'post-command-hook 'org-isearch-post-command
15592 'append 'local)))))
15594 (defun org-isearch-post-command ()
15595 "Remove self from hook, and show context."
15596 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
15597 (org-show-context 'isearch))
15600 ;;;; Integration with and fixes for other packages
15604 (defvar org-imenu-markers nil
15605 "All markers currently used by Imenu.")
15606 (make-variable-buffer-local 'org-imenu-markers)
15608 (defun org-imenu-new-marker (&optional pos)
15609 "Return a new marker for use by Imenu, and remember the marker."
15610 (let ((m (make-marker)))
15611 (move-marker m (or pos (point)))
15612 (push m org-imenu-markers)
15615 (defun org-imenu-get-tree ()
15616 "Produce the index for Imenu."
15617 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
15618 (setq org-imenu-markers nil)
15619 (let* ((n org-imenu-depth)
15620 (re (concat "^" outline-regexp))
15621 (subs (make-vector (1+ n) nil))
15627 (goto-char (point-max))
15628 (while (re-search-backward re nil t)
15629 (setq level (org-reduced-level (funcall outline-level)))
15631 (looking-at org-complex-heading-regexp)
15632 (setq head (org-link-display-format
15633 (org-match-string-no-properties 4))
15634 m (org-imenu-new-marker))
15635 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
15636 (if (>= level last-level)
15637 (push (cons head m) (aref subs level))
15638 (push (cons head (aref subs (1+ level))) (aref subs level))
15639 (loop for i from (1+ level) to n do (aset subs i nil)))
15640 (setq last-level level)))))
15643 (eval-after-load "imenu"
15645 (add-hook 'imenu-after-jump-hook
15647 (if (eq major-mode 'org-mode)
15648 (org-show-context 'org-goto))))))
15650 (defun org-link-display-format (link)
15651 "Replace a link with either the description, or the link target
15652 if no description is present"
15654 (if (string-match org-bracket-link-analytic-regexp link)
15655 (replace-match (or (match-string 5 link)
15656 (concat (match-string 1 link)
15657 (match-string 3 link)))
15661 ;; Speedbar support
15663 (defvar org-speedbar-restriction-lock-overlay (org-make-overlay 1 1)
15664 "Overlay marking the agenda restriction line in speedbar.")
15665 (org-overlay-put org-speedbar-restriction-lock-overlay
15666 'face 'org-agenda-restriction-lock)
15667 (org-overlay-put org-speedbar-restriction-lock-overlay
15668 'help-echo "Agendas are currently limited to this item.")
15669 (org-detach-overlay org-speedbar-restriction-lock-overlay)
15671 (defun org-speedbar-set-agenda-restriction ()
15672 "Restrict future agenda commands to the location at point in speedbar.
15673 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
15675 (require 'org-agenda)
15676 (let (p m tp np dir txt)
15678 ((setq p (text-property-any (point-at-bol) (point-at-eol)
15680 (setq m (get-text-property p 'org-imenu-marker))
15683 (set-buffer (marker-buffer m))
15685 (org-agenda-set-restriction-lock 'subtree))))
15686 ((setq p (text-property-any (point-at-bol) (point-at-eol)
15687 'speedbar-function 'speedbar-find-file))
15688 (setq tp (previous-single-property-change
15689 (1+ p) 'speedbar-function)
15690 np (next-single-property-change
15691 tp 'speedbar-function)
15692 dir (speedbar-line-directory)
15693 txt (buffer-substring-no-properties (or tp (point-min))
15694 (or np (point-max))))
15697 (set-buffer (find-file-noselect
15698 (let ((default-directory dir))
15699 (expand-file-name txt))))
15700 (unless (org-mode-p)
15701 (error "Cannot restrict to non-Org-mode file"))
15702 (org-agenda-set-restriction-lock 'file))))
15703 (t (error "Don't know how to restrict Org-mode's agenda")))
15704 (org-move-overlay org-speedbar-restriction-lock-overlay
15705 (point-at-bol) (point-at-eol))
15706 (setq current-prefix-arg nil)
15707 (org-agenda-maybe-redo)))
15709 (eval-after-load "speedbar"
15711 (speedbar-add-supported-extension ".org")
15712 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
15713 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
15714 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
15715 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
15716 (add-hook 'speedbar-visiting-tag-hook
15717 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
15720 ;;; Fixes and Hacks for problems with other packages
15722 ;; Make flyspell not check words in links, to not mess up our keymap
15723 (defun org-mode-flyspell-verify ()
15724 "Don't let flyspell put overlays at active buttons."
15725 (not (get-text-property (point) 'keymap)))
15727 ;; Make `bookmark-jump' show the jump location if it was hidden.
15728 (eval-after-load "bookmark"
15729 '(if (boundp 'bookmark-after-jump-hook)
15730 ;; We can use the hook
15731 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
15732 ;; Hook not available, use advice
15733 (defadvice bookmark-jump (after org-make-visible activate)
15734 "Make the position visible."
15735 (org-bookmark-jump-unhide))))
15737 ;; Make sure saveplace show the location if it was hidden
15738 (eval-after-load "saveplace"
15739 '(defadvice save-place-find-file-hook (after org-make-visible activate)
15740 "Make the position visible."
15741 (org-bookmark-jump-unhide)))
15743 (defun org-bookmark-jump-unhide ()
15744 "Unhide the current position, to show the bookmark location."
15746 (or (org-invisible-p)
15747 (save-excursion (goto-char (max (point-min) (1- (point))))
15748 (org-invisible-p)))
15749 (org-show-context 'bookmark-jump)))
15751 ;; Make session.el ignore our circular variable
15752 (eval-after-load "session"
15753 '(add-to-list 'session-globals-exclude 'org-mark-ring))
15755 ;;;; Experimental code
15757 (defun org-closed-in-range ()
15758 "Sparse tree of items closed in a certain time range.
15759 Still experimental, may disappear in the future."
15761 ;; Get the time interval from the user.
15762 (let* ((time1 (time-to-seconds
15763 (org-read-date nil 'to-time nil "Starting date: ")))
15764 (time2 (time-to-seconds
15765 (org-read-date nil 'to-time nil "End date:")))
15766 ;; callback function
15767 (callback (lambda ()
15770 (apply 'encode-time
15771 (org-parse-time-string
15772 (match-string 1))))))
15773 ;; check if time in interval
15774 (and (>= time time1) (<= time time2))))))
15775 ;; make tree, check each match with the callback
15776 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
15783 (run-hooks 'org-load-hook)
15785 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
15787 ;;; org.el ends here