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
))
88 (require 'org-entities
)
93 (require 'org-footnote
)
95 ;;;; Customization variables
99 (defconst org-version
"6.34trans"
100 "The version number of the file org.el.")
102 (defun org-version (&optional here
)
103 "Show the org-mode version in the echo area.
104 With prefix arg HERE, insert it at point."
106 (let* ((origin default-directory
)
107 (version org-version
)
109 (dir (concat (file-name-directory (locate-library "org")) "../" )))
110 (when (and (file-exists-p (expand-file-name ".git" dir
))
111 (executable-find "git"))
115 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
116 (with-current-buffer "*Shell Command Output*"
117 (goto-char (point-min))
118 (setq git-version
(buffer-substring (point) (point-at-eol))))
119 (subst-char-in-string ?- ?. git-version t
)
120 (when (string-match "\\S-"
121 (shell-command-to-string
122 "git diff-index --name-only HEAD --"))
123 (setq git-version
(concat git-version
".dirty")))
124 (setq version
(concat version
" (" git-version
")"))))
126 (setq version
(format "Org-mode version %s" version
))
127 (if here
(insert version
))
130 ;;; Compatibility constants
132 ;;; The custom variables
135 "Outline-based notes management and organizer."
140 (defcustom org-mode-hook nil
141 "Mode hook for Org-mode, run after the mode was turned on."
145 (defcustom org-load-hook nil
146 "Hook that is run after org.el has been loaded."
150 (defvar org-modules
) ; defined below
151 (defvar org-modules-loaded nil
152 "Have the modules been loaded already?")
154 (defun org-load-modules-maybe (&optional force
)
155 "Load all extensions listed in `org-modules'."
156 (when (or force
(not org-modules-loaded
))
158 (condition-case nil
(require ext
)
159 (error (message "Problems while trying to load feature `%s'" ext
))))
161 (setq org-modules-loaded t
)))
163 (defun org-set-modules (var value
)
164 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
166 (when (featurep 'org
)
167 (org-load-modules-maybe 'force
)))
169 (when (org-bound-and-true-p org-modules
)
170 (let ((a (member 'org-infojs org-modules
)))
171 (and a
(setcar a
'org-jsinfo
))))
173 (defcustom org-modules
'(org-bbdb org-bibtex org-docview org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-w3m org-wl
)
174 "Modules that should always be loaded together with org.el.
175 If a description starts with <C>, the file is not part of Emacs
176 and loading it will require that you have downloaded and properly installed
177 the org-mode distribution.
179 You can also use this system to load external packages (i.e. neither Org
180 core modules, nor modules from the CONTRIB directory). Just add symbols
181 to the end of the list. If the package is called org-xyz.el, then you need
182 to add the symbol `xyz', and the package must have a call to
186 :set
'org-set-modules
189 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
190 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
191 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
192 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
193 (const :tag
" docview: Links to doc-view buffers" org-docview
)
194 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
195 (const :tag
" id: Global IDs for identifying entries" org-id
)
196 (const :tag
" info: Links to Info nodes" org-info
)
197 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
198 (const :tag
" habit: Track your consistency with habits" org-habit
)
199 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
200 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
201 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
202 (const :tag
" mew Links to Mew folders/messages" org-mew
)
203 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
204 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
205 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
206 (const :tag
" vm: Links to VM folders/messages" org-vm
)
207 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
208 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
209 (const :tag
" mouse: Additional mouse support" org-mouse
)
211 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
212 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
213 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
214 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
215 (const :tag
"C collector: Collect properties into tables" org-collector
)
216 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
217 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
218 (const :tag
"C eval: Include command output as text" org-eval
)
219 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
220 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
221 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
222 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
223 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
225 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
227 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
228 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
229 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
230 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
231 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
232 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
233 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
234 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
235 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
236 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
237 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
238 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
239 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
240 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
241 (const :tag
"C track: Keep up with Org-mode development" org-track
)
242 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
244 (defcustom org-support-shift-select nil
245 "Non-nil means make shift-cursor commands select text when possible.
247 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
248 selecting a region, or enlarge thusly regions started in this way.
249 In Org-mode, in special contexts, these same keys are used for other
250 purposes, important enough to compete with shift selection. Org tries
251 to balance these needs by supporting `shift-select-mode' outside these
252 special contexts, under control of this variable.
254 The default of this variable is nil, to avoid confusing behavior. Shifted
255 cursor keys will then execute Org commands in the following contexts:
256 - on a headline, changing TODO state (left/right) and priority (up/down)
257 - on a time stamp, changing the time
258 - in a plain list item, changing the bullet type
259 - in a property definition line, switching between allowed values
260 - in the BEGIN line of a clock table (changing the time block).
261 Outside these contexts, the commands will throw an error.
263 When this variable is t and the cursor is not in a special context,
264 Org-mode will support shift-selection for making and enlarging regions.
265 To make this more effective, the bullet cycling will no longer happen
266 anywhere in an item line, but only if the cursor is exactly on the bullet.
268 If you set this variable to the symbol `always', then the keys
269 will not be special in headlines, property lines, and item lines, to make
270 shift selection work there as well. If this is what you want, you can
271 use the following alternative commands: `C-c C-t' and `C-c ,' to
272 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
273 TODO sets, `C-c -' to cycle item bullet types, and properties can be
274 edited by hand or in column view.
276 However, when the cursor is on a timestamp, shift-cursor commands
277 will still edit the time stamp - this is just too good to give up.
279 XEmacs user should have this variable set to nil, because shift-select-mode
283 (const :tag
"Never" nil
)
284 (const :tag
"When outside special context" t
)
285 (const :tag
"Everywhere except timestamps" always
)))
287 (defgroup org-startup nil
288 "Options concerning startup of Org-mode."
292 (defcustom org-startup-folded t
293 "Non-nil means entering Org-mode will switch to OVERVIEW.
294 This can also be configured on a per-file basis by adding one of
295 the following lines anywhere in the buffer:
297 #+STARTUP: fold (or `overview', this is equivalent)
298 #+STARTUP: nofold (or `showall', this is equivalent)
300 #+STARTUP: showeverything"
303 (const :tag
"nofold: show all" nil
)
304 (const :tag
"fold: overview" t
)
305 (const :tag
"content: all headlines" content
)
306 (const :tag
"show everything, even drawers" showeverything
)))
308 (defcustom org-startup-truncated t
309 "Non-nil means entering Org-mode will set `truncate-lines'.
310 This is useful since some lines containing links can be very long and
311 uninteresting. Also tables look terrible when wrapped."
315 (defcustom org-startup-indented nil
316 "Non-nil means turn on `org-indent-mode' on startup.
317 This can also be configured on a per-file basis by adding one of
318 the following lines anywhere in the buffer:
322 :group
'org-structure
324 (const :tag
"Not" nil
)
325 (const :tag
"Globally (slow on startup in large files)" t
)))
327 (defcustom org-startup-with-beamer-mode nil
328 "Non-nil means turn on `org-beamer-mode' on startup.
329 This can also be configured on a per-file basis by adding one of
330 the following lines anywhere in the buffer:
336 (defcustom org-startup-align-all-tables nil
337 "Non-nil means align all tables when visiting a file.
338 This is useful when the column width in tables is forced with <N> cookies
339 in table fields. Such tables will look correct only after the first re-align.
340 This can also be configured on a per-file basis by adding one of
341 the following lines anywhere in the buffer:
347 (defcustom org-insert-mode-line-in-empty-file nil
348 "Non-nil means insert the first line setting Org-mode in empty files.
349 When the function `org-mode' is called interactively in an empty file, this
350 normally means that the file name does not automatically trigger Org-mode.
351 To ensure that the file will always be in Org-mode in the future, a
352 line enforcing Org-mode will be inserted into the buffer, if this option
357 (defcustom org-replace-disputed-keys nil
358 "Non-nil means use alternative key bindings for some keys.
359 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
360 These keys are also used by other packages like shift-selection-mode'
361 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
362 If you want to use Org-mode together with one of these other modes,
363 or more generally if you would like to move some Org-mode commands to
364 other keys, set this variable and configure the keys with the variable
367 This option is only relevant at load-time of Org-mode, and must be set
368 *before* org.el is loaded. Changing it requires a restart of Emacs to
373 (defcustom org-use-extra-keys nil
374 "Non-nil means use extra key sequence definitions for certain
375 commands. This happens automatically if you run XEmacs or if
376 window-system is nil. This variable lets you do the same
377 manually. You must set it before loading org.
379 Example: on Carbon Emacs 22 running graphically, with an external
380 keyboard on a Powerbook, the default way of setting M-left might
381 not work for either Alt or ESC. Setting this variable will make
386 (if (fboundp 'defvaralias
)
387 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
389 (defcustom org-disputed-keys
390 '(([(shift up
)] .
[(meta p
)])
391 ([(shift down
)] .
[(meta n
)])
392 ([(shift left
)] .
[(meta -
)])
393 ([(shift right
)] .
[(meta +)])
394 ([(control shift right
)] .
[(meta shift
+)])
395 ([(control shift left
)] .
[(meta shift -
)]))
396 "Keys for which Org-mode and other modes compete.
397 This is an alist, cars are the default keys, second element specifies
398 the alternative to use when `org-replace-disputed-keys' is t.
400 Keys can be specified in any syntax supported by `define-key'.
401 The value of this option takes effect only at Org-mode's startup,
402 therefore you'll have to restart Emacs to apply it after changing."
407 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
408 Or return the original if not disputed."
409 (if org-replace-disputed-keys
410 (let* ((nkey (key-description key
))
411 (x (org-find-if (lambda (x)
412 (equal (key-description (car x
)) nkey
))
417 (defun org-find-if (predicate seq
)
420 (if (funcall predicate
(car seq
))
421 (throw 'exit
(car seq
))
424 (defun org-defkey (keymap key def
)
425 "Define a key, possibly translated, as returned by `org-key'."
426 (define-key keymap
(org-key key
) def
))
428 (defcustom org-ellipsis nil
429 "The ellipsis to use in the Org-mode outline.
430 When nil, just use the standard three dots. When a string, use that instead,
431 When a face, use the standard 3 dots, but with the specified face.
432 The change affects only Org-mode (which will then use its own display table).
433 Changing this requires executing `M-x org-mode' in a buffer to become
436 :type
'(choice (const :tag
"Default" nil
)
437 (face :tag
"Face" :value org-warning
)
438 (string :tag
"String" :value
"...#")))
440 (defvar org-display-table nil
441 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
443 (defgroup org-keywords nil
444 "Keywords in Org-mode."
448 (defcustom org-deadline-string
"DEADLINE:"
449 "String to mark deadline entries.
450 A deadline is this string, followed by a time stamp. Should be a word,
451 terminated by a colon. You can insert a schedule keyword and
452 a timestamp with \\[org-deadline].
453 Changes become only effective after restarting Emacs."
457 (defcustom org-scheduled-string
"SCHEDULED:"
458 "String to mark scheduled TODO entries.
459 A schedule is this string, followed by a time stamp. Should be a word,
460 terminated by a colon. You can insert a schedule keyword and
461 a timestamp with \\[org-schedule].
462 Changes become only effective after restarting Emacs."
466 (defcustom org-closed-string
"CLOSED:"
467 "String used as the prefix for timestamps logging closing a TODO entry."
471 (defcustom org-clock-string
"CLOCK:"
472 "String used as prefix for timestamps clocking work hours on an item."
476 (defcustom org-comment-string
"COMMENT"
477 "Entries starting with this keyword will never be exported.
478 An entry can be toggled between COMMENT and normal with
479 \\[org-toggle-comment].
480 Changes become only effective after restarting Emacs."
484 (defcustom org-quote-string
"QUOTE"
485 "Entries starting with this keyword will be exported in fixed-width font.
486 Quoting applies only to the text in the entry following the headline, and does
487 not extend beyond the next headline, even if that is lower level.
488 An entry can be toggled between QUOTE and normal with
489 \\[org-toggle-fixed-width-section]."
493 (defconst org-repeat-re
494 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
495 "Regular expression for specifying repeated events.
496 After a match, group 1 contains the repeat expression.")
498 (defgroup org-structure nil
499 "Options concerning the general structure of Org-mode files."
503 (defgroup org-reveal-location nil
504 "Options about how to make context of a location visible."
505 :tag
"Org Reveal Location"
506 :group
'org-structure
)
508 (defconst org-context-choice
510 (const :tag
"Always" t
)
511 (const :tag
"Never" nil
)
512 (repeat :greedy t
:tag
"Individual contexts"
514 (choice :tag
"Context"
521 (const bookmark-jump
)
525 "Contexts for the reveal options.")
527 (defcustom org-show-hierarchy-above
'((default . t
))
528 "Non-nil means show full hierarchy when revealing a location.
529 Org-mode often shows locations in an org-mode file which might have
530 been invisible before. When this is set, the hierarchy of headings
531 above the exposed location is shown.
532 Turning this off for example for sparse trees makes them very compact.
533 Instead of t, this can also be an alist specifying this option for different
534 contexts. Valid contexts are
535 agenda when exposing an entry from the agenda
536 org-goto when using the command `org-goto' on key C-c C-j
537 occur-tree when using the command `org-occur' on key C-c /
538 tags-tree when constructing a sparse tree based on tags matches
539 link-search when exposing search matches associated with a link
540 mark-goto when exposing the jump goal of a mark
541 bookmark-jump when exposing a bookmark location
542 isearch when exiting from an incremental search
543 default default for all contexts not set explicitly"
544 :group
'org-reveal-location
545 :type org-context-choice
)
547 (defcustom org-show-following-heading
'((default . nil
))
548 "Non-nil means show following heading when revealing a location.
549 Org-mode often shows locations in an org-mode file which might have
550 been invisible before. When this is set, the heading following the
552 Turning this off for example for sparse trees makes them very compact,
553 but makes it harder to edit the location of the match. In such a case,
554 use the command \\[org-reveal] to show more context.
555 Instead of t, this can also be an alist specifying this option for different
556 contexts. See `org-show-hierarchy-above' for valid contexts."
557 :group
'org-reveal-location
558 :type org-context-choice
)
560 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
561 "Non-nil means show all sibling heading when revealing a location.
562 Org-mode often shows locations in an org-mode file which might have
563 been invisible before. When this is set, the sibling of the current entry
564 heading are all made visible. If `org-show-hierarchy-above' is t,
565 the same happens on each level of the hierarchy above the current entry.
567 By default this is on for the isearch context, off for all other contexts.
568 Turning this off for example for sparse trees makes them very compact,
569 but makes it harder to edit the location of the match. In such a case,
570 use the command \\[org-reveal] to show more context.
571 Instead of t, this can also be an alist specifying this option for different
572 contexts. See `org-show-hierarchy-above' for valid contexts."
573 :group
'org-reveal-location
574 :type org-context-choice
)
576 (defcustom org-show-entry-below
'((default . nil
))
577 "Non-nil means show the entry below a headline when revealing a location.
578 Org-mode often shows locations in an org-mode file which might have
579 been invisible before. When this is set, the text below the headline that is
580 exposed is also shown.
582 By default this is off for all contexts.
583 Instead of t, this can also be an alist specifying this option for different
584 contexts. See `org-show-hierarchy-above' for valid contexts."
585 :group
'org-reveal-location
586 :type org-context-choice
)
588 (defcustom org-indirect-buffer-display
'other-window
589 "How should indirect tree buffers be displayed?
590 This applies to indirect buffers created with the commands
591 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
593 current-window Display in the current window
594 other-window Just display in another window.
595 dedicated-frame Create one new frame, and re-use it each time.
596 new-frame Make a new frame each time. Note that in this case
597 previously-made indirect buffers are kept, and you need to
598 kill these buffers yourself."
599 :group
'org-structure
600 :group
'org-agenda-windows
602 (const :tag
"In current window" current-window
)
603 (const :tag
"In current frame, other window" other-window
)
604 (const :tag
"Each time a new frame" new-frame
)
605 (const :tag
"One dedicated frame" dedicated-frame
)))
607 (defcustom org-use-speed-commands nil
608 "Non-nil means activate single letter commands at beginning of a headline.
609 This may also be a function to test for appropriate locations where speed
610 commands should be active."
611 :group
'org-structure
613 (const :tag
"Never" nil
)
614 (const :tag
"At beginning of headline stars" t
)
617 (defcustom org-speed-commands-user nil
618 "Alist of additional speed commands.
619 This list will be checked before `org-speed-commands-default'
620 when the variable `org-use-speed-commands' is non-nil
621 and when the cursor is at the beginning of a headline.
622 The car if each entry is a string with a single letter, which must
623 be assigned to `self-insert-command' in the global map.
624 The cdr is either a command to be called interactively, a function
625 to be called, or a form to be evaluated.
626 An entry that is just a list with a single string will be interpreted
627 as a descriptive headline that will be added when listing the speed
628 copmmands in the Help buffer using the `?' speed command."
629 :group
'org-structure
630 :type
'(repeat :value
("k" . ignore
)
631 (choice :value
("k" . ignore
)
632 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
633 (cons :tag
"Letter and Command"
634 (string :tag
"Command letter")
639 (defgroup org-cycle nil
640 "Options concerning visibility cycling in Org-mode."
642 :group
'org-structure
)
644 (defcustom org-cycle-skip-children-state-if-no-children t
645 "Non-nil means skip CHILDREN state in entries that don't have any."
649 (defcustom org-cycle-max-level nil
650 "Maximum level which should still be subject to visibility cycling.
651 Levels higher than this will, for cycling, be treated as text, not a headline.
652 When `org-odd-levels-only' is set, a value of N in this variable actually
653 means 2N-1 stars as the limiting headline.
654 When nil, cycle all levels.
655 Note that the limiting level of cycling is also influenced by
656 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
657 `org-inlinetask-min-level' is, cycling will be limited to levels one less
661 (const :tag
"No limit" nil
)
662 (integer :tag
"Maximum level")))
664 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
665 "Names of drawers. Drawers are not opened by cycling on the headline above.
666 Drawers only open with a TAB on the drawer line itself. A drawer looks like
671 The drawer \"PROPERTIES\" is special for capturing properties through
674 Drawers can be defined on the per-file basis with a line like:
676 #+DRAWERS: HIDDEN STATE PROPERTIES"
677 :group
'org-structure
679 :type
'(repeat (string :tag
"Drawer Name")))
681 (defcustom org-hide-block-startup nil
682 "Non-nil means entering Org-mode will fold all blocks.
683 This can also be set in on a per-file basis with
685 #+STARTUP: hideblocks
686 #+STARTUP: showblocks"
691 (defcustom org-cycle-global-at-bob nil
692 "Cycle globally if cursor is at beginning of buffer and not at a headline.
693 This makes it possible to do global cycling without having to use S-TAB or
694 C-u TAB. For this special case to work, the first line of the buffer
695 must not be a headline - it may be empty or some other text. When used in
696 this way, `org-cycle-hook' is disables temporarily, to make sure the
697 cursor stays at the beginning of the buffer.
698 When this option is nil, don't do anything special at the beginning
703 (defcustom org-cycle-level-after-item
/entry-creation t
704 "Non-nil means cycle entry level or item indentation in new empty entries.
706 When the cursor is at the end of an empty headline, i.e with only stars
707 and maybe a TODO keyword, TAB will then switch the entry to become a child,
708 and then all possible anchestor states, before returning to the original state.
709 This makes data entry extremely fast: M-RET to create a new headline,
710 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
712 When the cursor is at the end of an empty plain list item, one TAB will
713 make it a subitem, two or more tabs will back up to make this an item
714 higher up in the item hierarchy."
718 (defcustom org-cycle-emulate-tab t
719 "Where should `org-cycle' emulate TAB.
721 white Only in completely white lines
722 whitestart Only at the beginning of lines, before the first non-white char
723 t Everywhere except in headlines
724 exc-hl-bol Everywhere except at the start of a headline
725 If TAB is used in a place where it does not emulate TAB, the current subtree
726 visibility is cycled."
728 :type
'(choice (const :tag
"Never" nil
)
729 (const :tag
"Only in completely white lines" white
)
730 (const :tag
"Before first char in a line" whitestart
)
731 (const :tag
"Everywhere except in headlines" t
)
732 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
735 (defcustom org-cycle-separator-lines
2
736 "Number of empty lines needed to keep an empty line between collapsed trees.
737 If you leave an empty line between the end of a subtree and the following
738 headline, this empty line is hidden when the subtree is folded.
739 Org-mode will leave (exactly) one empty line visible if the number of
740 empty lines is equal or larger to the number given in this variable.
741 So the default 2 means at least 2 empty lines after the end of a subtree
742 are needed to produce free space between a collapsed subtree and the
745 If the number is negative, and the number of empty lines is at least -N,
746 all empty lines are shown.
748 Special case: when 0, never leave empty lines in collapsed view."
751 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
753 (defcustom org-pre-cycle-hook nil
754 "Hook that is run before visibility cycling is happening.
755 The function(s) in this hook must accept a single argument which indicates
756 the new state that will be set right after running this hook. The
757 argument is a symbol. Before a global state change, it can have the values
758 `overview', `content', or `all'. Before a local state change, it can have
759 the values `folded', `children', or `subtree'."
763 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
764 org-cycle-hide-drawers
765 org-cycle-show-empty-lines
766 org-optimize-window-after-visibility-change
)
767 "Hook that is run after `org-cycle' has changed the buffer visibility.
768 The function(s) in this hook must accept a single argument which indicates
769 the new state that was set by the most recent `org-cycle' command. The
770 argument is a symbol. After a global state change, it can have the values
771 `overview', `content', or `all'. After a local state change, it can have
772 the values `folded', `children', or `subtree'."
776 (defgroup org-edit-structure nil
777 "Options concerning structure editing in Org-mode."
778 :tag
"Org Edit Structure"
779 :group
'org-structure
)
781 (defcustom org-odd-levels-only nil
782 "Non-nil means skip even levels and only use odd levels for the outline.
783 This has the effect that two stars are being added/taken away in
784 promotion/demotion commands. It also influences how levels are
785 handled by the exporters.
786 Changing it requires restart of `font-lock-mode' to become effective
787 for fontification also in regions already fontified.
788 You may also set this on a per-file basis by adding one of the following
793 :group
'org-edit-structure
794 :group
'org-appearance
797 (defcustom org-adapt-indentation t
798 "Non-nil means adapt indentation to outline node level.
800 When this variable is set, Org assumes that you write outlines by
801 indenting text in each node to align with the headline (after the stars).
802 The following issues are influenced by this variable:
804 - When this is set and the *entire* text in an entry is indented, the
805 indentation is increased by one space in a demotion command, and
806 decreased by one in a promotion command. If any line in the entry
807 body starts with text at column 0, indentation is not changed at all.
809 - Property drawers and planning information is inserted indented when
810 this variable s set. When nil, they will not be indented.
812 - TAB indents a line relative to context. The lines below a headline
813 will be indented when this variable is set.
815 Note that this is all about true indentation, by adding and removing
816 space characters. See also `org-indent.el' which does level-dependent
817 indentation in a virtual way, i.e. at display time in Emacs."
818 :group
'org-edit-structure
821 (defcustom org-special-ctrl-a
/e nil
822 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
824 When t, `C-a' will bring back the cursor to the beginning of the
825 headline text, i.e. after the stars and after a possible TODO keyword.
826 In an item, this will be the position after the bullet.
827 When the cursor is already at that position, another `C-a' will bring
828 it to the beginning of the line.
830 `C-e' will jump to the end of the headline, ignoring the presence of tags
831 in the headline. A second `C-e' will then jump to the true end of the
832 line, after any tags. This also means that, when this variable is
833 non-nil, `C-e' also will never jump beyond the end of the heading of a
834 folded section, i.e. not after the ellipses.
836 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
837 going to the true line boundary first. Only a directly following, identical
838 keypress will bring the cursor to the special positions.
840 This may also be a cons cell where the behavior for `C-a' and `C-e' is
842 :group
'org-edit-structure
844 (const :tag
"off" nil
)
845 (const :tag
"on: after stars/bullet and before tags first" t
)
846 (const :tag
"reversed: true line boundary first" reversed
)
847 (cons :tag
"Set C-a and C-e separately"
848 (choice :tag
"Special C-a"
849 (const :tag
"off" nil
)
850 (const :tag
"on: after stars/bullet first" t
)
851 (const :tag
"reversed: before stars/bullet first" reversed
))
852 (choice :tag
"Special C-e"
853 (const :tag
"off" nil
)
854 (const :tag
"on: before tags first" t
)
855 (const :tag
"reversed: after tags first" reversed
)))))
856 (if (fboundp 'defvaralias
)
857 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
859 (defcustom org-special-ctrl-k nil
860 "Non-nil means `C-k' will behave specially in headlines.
861 When nil, `C-k' will call the default `kill-line' command.
862 When t, the following will happen while the cursor is in the headline:
864 - When the cursor is at the beginning of a headline, kill the entire
865 line and possible the folded subtree below the line.
866 - When in the middle of the headline text, kill the headline up to the tags.
867 - When after the headline text, kill the tags."
868 :group
'org-edit-structure
871 (defcustom org-yank-folded-subtrees t
872 "Non-nil means when yanking subtrees, fold them.
873 If the kill is a single subtree, or a sequence of subtrees, i.e. if
874 it starts with a heading and all other headings in it are either children
875 or siblings, then fold all the subtrees. However, do this only if no
876 text after the yank would be swallowed into a folded tree by this action."
877 :group
'org-edit-structure
880 (defcustom org-yank-adjusted-subtrees nil
881 "Non-nil means when yanking subtrees, adjust the level.
882 With this setting, `org-paste-subtree' is used to insert the subtree, see
883 this function for details."
884 :group
'org-edit-structure
887 (defcustom org-M-RET-may-split-line
'((default . t
))
888 "Non-nil means M-RET will split the line at the cursor position.
889 When nil, it will go to the end of the line before making a
891 You may also set this option in a different way for different
892 contexts. Valid contexts are:
894 headline when creating a new headline
895 item when creating a new item
896 table in a table field
897 default the value to be used for all contexts not explicitly
899 :group
'org-structure
902 (const :tag
"Always" t
)
903 (const :tag
"Never" nil
)
904 (repeat :greedy t
:tag
"Individual contexts"
906 (choice :tag
"Context"
914 (defcustom org-insert-heading-respect-content nil
915 "Non-nil means insert new headings after the current subtree.
916 When nil, the new heading is created directly after the current line.
917 The commands \\[org-insert-heading-respect-content] and
918 \\[org-insert-todo-heading-respect-content] turn this variable on
919 for the duration of the command."
920 :group
'org-structure
923 (defcustom org-blank-before-new-entry
'((heading . auto
)
924 (plain-list-item . auto
))
925 "Should `org-insert-heading' leave a blank line before new heading/item?
926 The value is an alist, with `heading' and `plain-list-item' as car,
927 and a boolean flag as cdr. For plain lists, if the variable
928 `org-empty-line-terminates-plain-lists' is set, the setting here
929 is ignored and no empty line is inserted, to keep the list in tact."
930 :group
'org-edit-structure
932 (cons (const heading
)
933 (choice (const :tag
"Never" nil
)
934 (const :tag
"Always" t
)
935 (const :tag
"Auto" auto
)))
936 (cons (const plain-list-item
)
937 (choice (const :tag
"Never" nil
)
938 (const :tag
"Always" t
)
939 (const :tag
"Auto" auto
)))))
941 (defcustom org-insert-heading-hook nil
942 "Hook being run after inserting a new heading."
943 :group
'org-edit-structure
946 (defcustom org-enable-fixed-width-editor t
947 "Non-nil means lines starting with \":\" are treated as fixed-width.
948 This currently only means they are never auto-wrapped.
949 When nil, such lines will be treated like ordinary lines.
950 See also the QUOTE keyword."
951 :group
'org-edit-structure
955 (defcustom org-goto-auto-isearch t
956 "Non-nil means typing characters in org-goto starts incremental search."
957 :group
'org-edit-structure
960 (defgroup org-sparse-trees nil
961 "Options concerning sparse trees in Org-mode."
962 :tag
"Org Sparse Trees"
963 :group
'org-structure
)
965 (defcustom org-highlight-sparse-tree-matches t
966 "Non-nil means highlight all matches that define a sparse tree.
967 The highlights will automatically disappear the next time the buffer is
968 changed by an edit command."
969 :group
'org-sparse-trees
972 (defcustom org-remove-highlights-with-change t
973 "Non-nil means any change to the buffer will remove temporary highlights.
974 Such highlights are created by `org-occur' and `org-clock-display'.
975 When nil, `C-c C-c needs to be used to get rid of the highlights.
976 The highlights created by `org-preview-latex-fragment' always need
977 `C-c C-c' to be removed."
978 :group
'org-sparse-trees
983 (defcustom org-occur-hook
'(org-first-headline-recenter)
984 "Hook that is run after `org-occur' has constructed a sparse tree.
985 This can be used to recenter the window to show as much of the structure
987 :group
'org-sparse-trees
990 (defgroup org-imenu-and-speedbar nil
991 "Options concerning imenu and speedbar in Org-mode."
992 :tag
"Org Imenu and Speedbar"
993 :group
'org-structure
)
995 (defcustom org-imenu-depth
2
996 "The maximum level for Imenu access to Org-mode headlines.
997 This also applied for speedbar access."
998 :group
'org-imenu-and-speedbar
1001 (defgroup org-table nil
1002 "Options concerning tables in Org-mode."
1006 (defcustom org-enable-table-editor
'optimized
1007 "Non-nil means lines starting with \"|\" are handled by the table editor.
1008 When nil, such lines will be treated like ordinary lines.
1010 When equal to the symbol `optimized', the table editor will be optimized to
1012 - Automatic overwrite mode in front of whitespace in table fields.
1013 This makes the structure of the table stay in tact as long as the edited
1014 field does not exceed the column width.
1015 - Minimize the number of realigns. Normally, the table is aligned each time
1016 TAB or RET are pressed to move to another field. With optimization this
1017 happens only if changes to a field might have changed the column width.
1018 Optimization requires replacing the functions `self-insert-command',
1019 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1020 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1021 very good at guessing when a re-align will be necessary, but you can always
1022 force one with \\[org-ctrl-c-ctrl-c].
1024 If you would like to use the optimized version in Org-mode, but the
1025 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1027 This variable can be used to turn on and off the table editor during a session,
1028 but in order to toggle optimization, a restart is required.
1030 See also the variable `org-table-auto-blank-field'."
1033 (const :tag
"off" nil
)
1035 (const :tag
"on, optimized" optimized
)))
1037 (defcustom org-self-insert-cluster-for-undo t
1038 "Non-nil means cluster self-insert commands for undo when possible.
1039 If this is set, then, like in the Emacs command loop, 20 consecutive
1040 characters will be undone together.
1041 This is configurable, because there is some impact on typing performance."
1045 (defcustom org-table-tab-recognizes-table.el t
1046 "Non-nil means TAB will automatically notice a table.el table.
1047 When it sees such a table, it moves point into it and - if necessary -
1048 calls `table-recognize-table'."
1049 :group
'org-table-editing
1052 (defgroup org-link nil
1053 "Options concerning links in Org-mode."
1057 (defvar org-link-abbrev-alist-local nil
1058 "Buffer-local version of `org-link-abbrev-alist', which see.
1059 The value of this is taken from the #+LINK lines.")
1060 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1062 (defcustom org-link-abbrev-alist nil
1063 "Alist of link abbreviations.
1064 The car of each element is a string, to be replaced at the start of a link.
1065 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1066 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1068 [[linkkey:tag][description]]
1070 The 'linkkey' must be a word word, starting with a letter, followed
1071 by letters, numbers, '-' or '_'.
1073 If REPLACE is a string, the tag will simply be appended to create the link.
1074 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1075 the placeholder \"%h\" will cause a url-encoded version of the tag to
1076 be inserted at that point (see the function `url-hexify-string').
1078 REPLACE may also be a function that will be called with the tag as the
1079 only argument to create the link, which should be returned as a string.
1081 See the manual for examples."
1085 (string :tag
"Protocol")
1087 (string :tag
"Format")
1090 (defcustom org-descriptive-links t
1091 "Non-nil means hide link part and only show description of bracket links.
1092 Bracket links are like [[link][description]]. This variable sets the initial
1093 state in new org-mode buffers. The setting can then be toggled on a
1094 per-buffer basis from the Org->Hyperlinks menu."
1098 (defcustom org-link-file-path-type
'adaptive
1099 "How the path name in file links should be stored.
1102 relative Relative to the current directory, i.e. the directory of the file
1103 into which the link is being inserted.
1104 absolute Absolute path, if possible with ~ for home directory.
1105 noabbrev Absolute path, no abbreviation of home directory.
1106 adaptive Use relative path for files in the current directory and sub-
1107 directories of it. For other files, use an absolute path."
1115 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1116 "Types of links that should be activated in Org-mode files.
1117 This is a list of symbols, each leading to the activation of a certain link
1118 type. In principle, it does not hurt to turn on most link types - there may
1119 be a small gain when turning off unused link types. The types are:
1121 bracket The recommended [[link][description]] or [[link]] links with hiding.
1122 angular Links in angular brackets that may contain whitespace like
1123 <bbdb:Carsten Dominik>.
1124 plain Plain links in normal text, no whitespace, like http://google.com.
1125 radio Text that is matched by a radio target, see manual for details.
1126 tag Tag settings in a headline (link to tag search).
1127 date Time stamps (link to calendar).
1128 footnote Footnote labels.
1130 Changing this variable requires a restart of Emacs to become effective."
1132 :type
'(set :greedy t
1133 (const :tag
"Double bracket links (new style)" bracket
)
1134 (const :tag
"Angular bracket links (old style)" angular
)
1135 (const :tag
"Plain text links" plain
)
1136 (const :tag
"Radio target matches" radio
)
1137 (const :tag
"Tags" tag
)
1138 (const :tag
"Timestamps" date
)
1139 (const :tag
"Footnotes" footnote
)))
1141 (defcustom org-make-link-description-function nil
1142 "Function to use to generate link descriptions from links. If
1143 nil the link location will be used. This function must take two
1144 parameters; the first is the link and the second the description
1145 org-insert-link has generated, and should return the description
1150 (defgroup org-link-store nil
1151 "Options concerning storing links in Org-mode."
1152 :tag
"Org Store Link"
1155 (defcustom org-email-link-description-format
"Email %c: %.30s"
1156 "Format of the description part of a link to an email or usenet message.
1157 The following %-escapes will be replaced by corresponding information:
1159 %F full \"From\" field
1160 %f name, taken from \"From\" field, address if no name
1161 %T full \"To\" field
1162 %t first name in \"To\" field, address if no name
1163 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1164 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1168 You may use normal field width specification between the % and the letter.
1169 This is for example useful to limit the length of the subject.
1171 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1172 :group
'org-link-store
1175 (defcustom org-from-is-user-regexp
1177 (when (and user-mail-address
(not (string= user-mail-address
"")))
1178 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1179 (when (and user-full-name
(not (string= user-full-name
"")))
1180 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1181 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1182 "Regexp matched against the \"From:\" header of an email or usenet message.
1183 It should match if the message is from the user him/herself."
1184 :group
'org-link-store
1187 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1188 "Non-nil means storing a link to an Org file will use entry IDs.
1190 Note that before this variable is even considered, org-id must be loaded,
1191 so please customize `org-modules' and turn it on.
1193 The variable can have the following values:
1195 t Create an ID if needed to make a link to the current entry.
1197 create-if-interactive
1198 If `org-store-link' is called directly (interactively, as a user
1199 command), do create an ID to support the link. But when doing the
1200 job for remember, only use the ID if it already exists. The
1201 purpose of this setting is to avoid proliferation of unwanted
1202 IDs, just because you happen to be in an Org file when you
1203 call `org-remember' that automatically and preemptively
1204 creates a link. If you do want to get an ID link in a remember
1205 template to an entry not having an ID, create it first by
1206 explicitly creating a link to it, using `C-c C-l' first.
1208 create-if-interactive-and-no-custom-id
1209 Like create-if-interactive, but do not create an ID if there is
1210 a CUSTOM_ID property defined in the entry. This is the default.
1213 Use existing ID, do not create one.
1215 nil Never use an ID to make a link, instead link using a text search for
1217 :group
'org-link-store
1219 (const :tag
"Create ID to make link" t
)
1220 (const :tag
"Create if storing link interactively"
1221 create-if-interactive
)
1222 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1223 create-if-interactive-and-no-custom-id
)
1224 (const :tag
"Only use existing" use-existing
)
1225 (const :tag
"Do not use ID to create link" nil
)))
1227 (defcustom org-context-in-file-links t
1228 "Non-nil means file links from `org-store-link' contain context.
1229 A search string will be added to the file name with :: as separator and
1230 used to find the context when the link is activated by the command
1231 `org-open-at-point'.
1232 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1233 negates this setting for the duration of the command."
1234 :group
'org-link-store
1237 (defcustom org-keep-stored-link-after-insertion nil
1238 "Non-nil means keep link in list for entire session.
1240 The command `org-store-link' adds a link pointing to the current
1241 location to an internal list. These links accumulate during a session.
1242 The command `org-insert-link' can be used to insert links into any
1243 Org-mode file (offering completion for all stored links). When this
1244 option is nil, every link which has been inserted once using \\[org-insert-link]
1245 will be removed from the list, to make completing the unused links
1247 :group
'org-link-store
1250 (defgroup org-link-follow nil
1251 "Options concerning following links in Org-mode."
1252 :tag
"Org Follow Link"
1255 (defcustom org-link-translation-function nil
1256 "Function to translate links with different syntax to Org syntax.
1257 This can be used to translate links created for example by the Planner
1258 or emacs-wiki packages to Org syntax.
1259 The function must accept two parameters, a TYPE containing the link
1260 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1261 which is everything after the link protocol. It should return a cons
1262 with possibly modified values of type and path.
1263 Org contains a function for this, so if you set this variable to
1264 `org-translate-link-from-planner', you should be able follow many
1265 links created by planner."
1266 :group
'org-link-follow
1269 (defcustom org-follow-link-hook nil
1270 "Hook that is run after a link has been followed."
1271 :group
'org-link-follow
1274 (defcustom org-tab-follows-link nil
1275 "Non-nil means on links TAB will follow the link.
1276 Needs to be set before org.el is loaded.
1277 This really should not be used, it does not make sense, and the
1278 implementation is bad."
1279 :group
'org-link-follow
1282 (defcustom org-return-follows-link nil
1283 "Non-nil means on links RET will follow the link.
1284 Needs to be set before org.el is loaded."
1285 :group
'org-link-follow
1288 (defcustom org-mouse-1-follows-link
1289 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1290 "Non-nil means mouse-1 on a link will follow the link.
1291 A longer mouse click will still set point. Does not work on XEmacs.
1292 Needs to be set before org.el is loaded."
1293 :group
'org-link-follow
1296 (defcustom org-mark-ring-length
4
1297 "Number of different positions to be recorded in the ring
1298 Changing this requires a restart of Emacs to work correctly."
1299 :group
'org-link-follow
1302 (defcustom org-link-frame-setup
1303 '((vm . vm-visit-folder-other-frame
)
1304 (gnus . gnus-other-frame
)
1305 (file . find-file-other-window
))
1306 "Setup the frame configuration for following links.
1307 When following a link with Emacs, it may often be useful to display
1308 this link in another window or frame. This variable can be used to
1309 set this up for the different types of links.
1312 `vm-visit-folder-other-frame'
1313 For Gnus, use any of
1316 `org-gnus-no-new-news'
1317 For FILE, use any of
1319 `find-file-other-window'
1320 `find-file-other-frame'
1321 For the calendar, use the variable `calendar-setup'.
1322 For BBDB, it is currently only possible to display the matches in
1324 :group
'org-link-follow
1328 (const vm-visit-folder
)
1329 (const vm-visit-folder-other-window
)
1330 (const vm-visit-folder-other-frame
)))
1334 (const gnus-other-frame
)
1335 (const org-gnus-no-new-news
)))
1339 (const find-file-other-window
)
1340 (const find-file-other-frame
)))))
1342 (defcustom org-display-internal-link-with-indirect-buffer nil
1343 "Non-nil means use indirect buffer to display infile links.
1344 Activating internal links (from one location in a file to another location
1345 in the same file) normally just jumps to the location. When the link is
1346 activated with a C-u prefix (or with mouse-3), the link is displayed in
1347 another window. When this option is set, the other window actually displays
1348 an indirect buffer clone of the current buffer, to avoid any visibility
1349 changes to the current buffer."
1350 :group
'org-link-follow
1353 (defcustom org-open-non-existing-files nil
1354 "Non-nil means `org-open-file' will open non-existing files.
1355 When nil, an error will be generated.
1356 This variable applies only to external applications because they
1357 might choke on non-existing files. If the link is to a file that
1358 will be opened in Emacs, the variable is ignored."
1359 :group
'org-link-follow
1362 (defcustom org-open-directory-means-index-dot-org nil
1363 "Non-nil means a link to a directory really means to index.org.
1364 When nil, following a directory link will run dired or open a finder/explorer
1365 window on that directory."
1366 :group
'org-link-follow
1369 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1370 "Function and arguments to call for following mailto links.
1371 This is a list with the first element being a lisp function, and the
1372 remaining elements being arguments to the function. In string arguments,
1373 %a will be replaced by the address, and %s will be replaced by the subject
1374 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1375 :group
'org-link-follow
1377 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1378 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1379 (const :tag
"message-mail" (message-mail "%a" "%s"))
1380 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1382 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1383 "Non-nil means ask for confirmation before executing shell links.
1384 Shell links can be dangerous: just think about a link
1386 [[shell:rm -rf ~/*][Google Search]]
1388 This link would show up in your Org-mode document as \"Google Search\",
1389 but really it would remove your entire home directory.
1390 Therefore we advise against setting this variable to nil.
1391 Just change it to `y-or-n-p' if you want to confirm with a
1392 single keystroke rather than having to type \"yes\"."
1393 :group
'org-link-follow
1395 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1396 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1397 (const :tag
"no confirmation (dangerous)" nil
)))
1399 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1400 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1401 Elisp links can be dangerous: just think about a link
1403 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1405 This link would show up in your Org-mode document as \"Google Search\",
1406 but really it would remove your entire home directory.
1407 Therefore we advise against setting this variable to nil.
1408 Just change it to `y-or-n-p' if you want to confirm with a
1409 single keystroke rather than having to type \"yes\"."
1410 :group
'org-link-follow
1412 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1413 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1414 (const :tag
"no confirmation (dangerous)" nil
)))
1416 (defconst org-file-apps-defaults-gnu
1420 "Default file applications on a UNIX or GNU/Linux system.
1421 See `org-file-apps'.")
1423 (defconst org-file-apps-defaults-macosx
1426 (system .
"open %s")
1428 ("eps.gz" .
"gv %s")
1430 ("fig" .
"xfig %s"))
1431 "Default file applications on a MacOS X system.
1432 The system \"open\" is known as a default, but we use X11 applications
1433 for some files for which the OS does not have a good default.
1434 See `org-file-apps'.")
1436 (defconst org-file-apps-defaults-windowsnt
1440 (list (if (featurep 'xemacs
)
1441 'mswindows-shell-execute
1445 (list (if (featurep 'xemacs
)
1446 'mswindows-shell-execute
1449 "Default file applications on a Windows NT system.
1450 The system \"open\" is used for most files.
1451 See `org-file-apps'.")
1453 (defcustom org-file-apps
1456 ("\\.mm\\'" . default
)
1457 ("\\.x?html?\\'" . default
)
1458 ("\\.pdf\\'" . default
)
1460 "External applications for opening `file:path' items in a document.
1461 Org-mode uses system defaults for different file types, but
1462 you can use this variable to set the application for a given file
1463 extension. The entries in this list are cons cells where the car identifies
1464 files and the cdr the corresponding command. Possible values for the
1466 \"regex\" Regular expression matched against the file: link. For
1467 backward compatibility, this can also be a string with only
1468 alphanumeric characters, which is then interpreted as an
1470 `directory' Matches a directory
1471 `remote' Matches a remote file, accessible through tramp or efs.
1472 Remote files most likely should be visited through Emacs
1473 because external applications cannot handle such paths.
1474 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1475 so all files Emacs knows how to handle. Using this with
1476 command `emacs' will open most files in Emacs. Beware that this
1477 will also open html files inside Emacs, unless you add
1478 (\"html\" . default) to the list as well.
1479 t Default for files not matched by any of the other options.
1480 `system' The system command to open files, like `open' on Windows
1481 and Mac OS X, and mailcap under GNU/Linux. This is the command
1482 that will be selected if you call `C-c C-o' with a double
1485 Possible values for the command are:
1486 `emacs' The file will be visited by the current Emacs process.
1487 `default' Use the default application for this file type, which is the
1488 association for t in the list, most likely in the system-specific
1490 This can be used to overrule an unwanted setting in the
1491 system-specific variable.
1492 `system' Use the system command for opening files, like \"open\".
1493 This command is specified by the entry whose car is `system'.
1494 Most likely, the system-specific version of this variable
1495 does define this command, but you can overrule/replace it
1497 string A command to be executed by a shell; %s will be replaced
1498 by the path to the file. If the file identifier is a regex,
1499 %n will be replaced by the match of the nth match group.
1500 sexp A Lisp form which will be evaluated. The file path will
1501 be available in the Lisp variable `file', the link itself
1502 in the Lisp variable `link'. If the file identifier is a regex,
1503 the original match data will be restored, so subexpression
1504 matches are accessible using (match-string n link).
1505 For more examples, see the system specific constants
1506 `org-file-apps-defaults-macosx'
1507 `org-file-apps-defaults-windowsnt'
1508 `org-file-apps-defaults-gnu'."
1509 :group
'org-link-follow
1511 (cons (choice :value
""
1512 (string :tag
"Extension")
1513 (const :tag
"System command to open files" system
)
1514 (const :tag
"Default for unrecognized files" t
)
1515 (const :tag
"Remote file" remote
)
1516 (const :tag
"Links to a directory" directory
)
1517 (const :tag
"Any files that have Emacs modes"
1520 (const :tag
"Visit with Emacs" emacs
)
1521 (const :tag
"Use default" default
)
1522 (const :tag
"Use the system command" system
)
1523 (string :tag
"Command")
1524 (sexp :tag
"Lisp form")))))
1526 (defgroup org-refile nil
1527 "Options concerning refiling entries in Org-mode."
1531 (defcustom org-directory
"~/org"
1532 "Directory with org files.
1533 This is just a default location to look for Org files. There is no need
1534 at all to put your files into this directory. It is only used in the
1535 following situations:
1537 1. When a remember template specifies a target file that is not an
1538 absolute path. The path will then be interpreted relative to
1540 2. When a remember note is filed away in an interactive way (when exiting the
1541 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1542 with `org-directory' as the default path."
1544 :group
'org-remember
1547 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1548 "Default target for storing notes.
1549 Used by the hooks for remember.el. This can be a string, or nil to mean
1550 the value of `remember-data-file'.
1551 You can set this on a per-template basis with the variable
1552 `org-remember-templates'."
1554 :group
'org-remember
1556 (const :tag
"Default from remember-data-file" nil
)
1559 (defcustom org-goto-interface
'outline
1560 "The default interface to be used for `org-goto'.
1562 outline The interface shows an outline of the relevant file
1563 and the correct heading is found by moving through
1564 the outline or by searching with incremental search.
1565 outline-path-completion Headlines in the current buffer are offered via
1566 completion. This is the interface also used by
1567 the refile command."
1570 (const :tag
"Outline" outline
)
1571 (const :tag
"Outline-path-completion" outline-path-completion
)))
1573 (defcustom org-goto-max-level
5
1574 "Maximum level to be considered when running org-goto with refile interface."
1578 (defcustom org-reverse-note-order nil
1579 "Non-nil means store new notes at the beginning of a file or entry.
1580 When nil, new notes will be filed to the end of a file or entry.
1581 This can also be a list with cons cells of regular expressions that
1582 are matched against file names, and values."
1583 :group
'org-remember
1586 (const :tag
"Reverse always" t
)
1587 (const :tag
"Reverse never" nil
)
1588 (repeat :tag
"By file name regexp"
1589 (cons regexp boolean
))))
1591 (defcustom org-log-refile nil
1592 "Information to record when a task is refiled.
1594 Possible values are:
1596 nil Don't add anything
1597 time Add a time stamp to the task
1598 note Prompt for a note and add it with template `org-log-note-headings'
1600 This option can also be set with on a per-file-basis with
1602 #+STARTUP: nologrefile
1603 #+STARTUP: logrefile
1604 #+STARTUP: lognoterefile
1606 You can have local logging settings for a subtree by setting the LOGGING
1607 property to one or more of these keywords.
1609 When bulk-refiling from the agenda, the value `note' is forbidden and
1610 will temporarily be changed to `time'."
1612 :group
'org-progress
1614 (const :tag
"No logging" nil
)
1615 (const :tag
"Record timestamp" time
)
1616 (const :tag
"Record timestamp with note." note
)))
1618 (defcustom org-refile-targets nil
1619 "Targets for refiling entries with \\[org-refile].
1620 This is list of cons cells. Each cell contains:
1621 - a specification of the files to be considered, either a list of files,
1622 or a symbol whose function or variable value will be used to retrieve
1623 a file name or a list of file names. If you use `org-agenda-files' for
1624 that, all agenda files will be scanned for targets. Nil means consider
1625 headings in the current buffer.
1626 - A specification of how to find candidate refile targets. This may be
1628 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1629 This tag has to be present in all target headlines, inheritance will
1631 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1633 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1634 headlines that are refiling targets.
1635 - a cons cell (:level . N). Any headline of level N is considered a target.
1636 Note that, when `org-odd-levels-only' is set, level corresponds to
1637 order in hierarchy, not to the number of stars.
1638 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1639 Note that, when `org-odd-levels-only' is set, level corresponds to
1640 order in hierarchy, not to the number of stars.
1642 You can set the variable `org-refile-target-verify-function' to a function
1643 to verify each headline found by the simple critery above.
1645 When this variable is nil, all top-level headlines in the current buffer
1646 are used, equivalent to the value `((nil . (:level . 1))'."
1650 (choice :value org-agenda-files
1651 (const :tag
"All agenda files" org-agenda-files
)
1652 (const :tag
"Current buffer" nil
)
1653 (function) (variable) (file))
1654 (choice :tag
"Identify target headline by"
1655 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1656 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1657 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1658 (cons :tag
"Level number" (const :value
:level
) (integer))
1659 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1661 (defcustom org-refile-target-verify-function nil
1662 "Function to verify if the headline at point should be a refile target.
1663 The function will be called without arguments, with point at the
1664 beginning of the headline. It should return t and leave point
1665 where it is if the headline is a valid target for refiling.
1667 If the target should not be selected, the function must return nil.
1668 In addition to this, it may move point to a place from where the search
1669 should be continued. For example, the function may decide that the entire
1670 subtree of the current entry should be excluded and move point to the end
1675 (defcustom org-refile-use-outline-path nil
1676 "Non-nil means provide refile targets as paths.
1677 So a level 3 headline will be available as level1/level2/level3.
1679 When the value is `file', also include the file name (without directory)
1680 into the path. In this case, you can also stop the completion after
1681 the file name, to get entries inserted as top level in the file.
1683 When `full-file-path', include the full file path."
1686 (const :tag
"Not" nil
)
1687 (const :tag
"Yes" t
)
1688 (const :tag
"Start with file name" file
)
1689 (const :tag
"Start with full file path" full-file-path
)))
1691 (defcustom org-outline-path-complete-in-steps t
1692 "Non-nil means complete the outline path in hierarchical steps.
1693 When Org-mode uses the refile interface to select an outline path
1694 \(see variable `org-refile-use-outline-path'), the completion of
1695 the path can be done is a single go, or if can be done in steps down
1696 the headline hierarchy. Going in steps is probably the best if you
1697 do not use a special completion package like `ido' or `icicles'.
1698 However, when using these packages, going in one step can be very
1699 fast, while still showing the whole path to the entry."
1703 (defcustom org-refile-allow-creating-parent-nodes nil
1704 "Non-nil means allow to create new nodes as refile targets.
1705 New nodes are then created by adding \"/new node name\" to the completion
1706 of an existing node. When the value of this variable is `confirm',
1707 new node creation must be confirmed by the user (recommended)
1708 When nil, the completion must match an existing entry.
1710 Note that, if the new heading is not seen by the criteria
1711 listed in `org-refile-targets', multiple instances of the same
1712 heading would be created by trying again to file under the new
1716 (const :tag
"Never" nil
)
1717 (const :tag
"Always" t
)
1718 (const :tag
"Prompt for confirmation" confirm
)))
1720 (defgroup org-todo nil
1721 "Options concerning TODO items in Org-mode."
1725 (defgroup org-progress nil
1726 "Options concerning Progress logging in Org-mode."
1730 (defvar org-todo-interpretation-widgets
1732 (:tag
"Sequence (cycling hits every state)" sequence
)
1733 (:tag
"Type (cycling directly to DONE)" type
))
1734 "The available interpretation symbols for customizing
1735 `org-todo-keywords'.
1736 Interested libraries should add to this list.")
1738 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1739 "List of TODO entry keyword sequences and their interpretation.
1740 \\<org-mode-map>This is a list of sequences.
1742 Each sequence starts with a symbol, either `sequence' or `type',
1743 indicating if the keywords should be interpreted as a sequence of
1744 action steps, or as different types of TODO items. The first
1745 keywords are states requiring action - these states will select a headline
1746 for inclusion into the global TODO list Org-mode produces. If one of
1747 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1748 signify that no further action is necessary. If \"|\" is not found,
1749 the last keyword is treated as the only DONE state of the sequence.
1751 The command \\[org-todo] cycles an entry through these states, and one
1752 additional state where no keyword is present. For details about this
1753 cycling, see the manual.
1755 TODO keywords and interpretation can also be set on a per-file basis with
1756 the special #+SEQ_TODO and #+TYP_TODO lines.
1758 Each keyword can optionally specify a character for fast state selection
1759 \(in combination with the variable `org-use-fast-todo-selection')
1760 and specifiers for state change logging, using the same syntax
1761 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1762 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1763 indicates to record a time stamp each time this state is selected.
1765 Each keyword may also specify if a timestamp or a note should be
1766 recorded when entering or leaving the state, by adding additional
1767 characters in the parenthesis after the keyword. This looks like this:
1768 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1769 record only the time of the state change. With X and Y being either
1770 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1771 Y when leaving the state if and only if the *target* state does not
1772 define X. You may omit any of the fast-selection key or X or /Y,
1773 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1775 For backward compatibility, this variable may also be just a list
1776 of keywords - in this case the interpretation (sequence or type) will be
1777 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1779 :group
'org-keywords
1781 (repeat :tag
"Old syntax, just keywords"
1782 (string :tag
"Keyword"))
1783 (repeat :tag
"New syntax"
1786 :tag
"Interpretation"
1787 ;;Quick and dirty way to see
1788 ;;`org-todo-interpretations'. This takes the
1789 ;;place of item arguments
1797 org-todo-interpretation-widgets
))
1800 (string :tag
"Keyword"))))))
1802 (defvar org-todo-keywords-1 nil
1803 "All TODO and DONE keywords active in a buffer.")
1804 (make-variable-buffer-local 'org-todo-keywords-1
)
1805 (defvar org-todo-keywords-for-agenda nil
)
1806 (defvar org-done-keywords-for-agenda nil
)
1807 (defvar org-drawers-for-agenda nil
)
1808 (defvar org-todo-keyword-alist-for-agenda nil
)
1809 (defvar org-tag-alist-for-agenda nil
)
1810 (defvar org-agenda-contributing-files nil
)
1811 (defvar org-not-done-keywords nil
)
1812 (make-variable-buffer-local 'org-not-done-keywords
)
1813 (defvar org-done-keywords nil
)
1814 (make-variable-buffer-local 'org-done-keywords
)
1815 (defvar org-todo-heads nil
)
1816 (make-variable-buffer-local 'org-todo-heads
)
1817 (defvar org-todo-sets nil
)
1818 (make-variable-buffer-local 'org-todo-sets
)
1819 (defvar org-todo-log-states nil
)
1820 (make-variable-buffer-local 'org-todo-log-states
)
1821 (defvar org-todo-kwd-alist nil
)
1822 (make-variable-buffer-local 'org-todo-kwd-alist
)
1823 (defvar org-todo-key-alist nil
)
1824 (make-variable-buffer-local 'org-todo-key-alist
)
1825 (defvar org-todo-key-trigger nil
)
1826 (make-variable-buffer-local 'org-todo-key-trigger
)
1828 (defcustom org-todo-interpretation
'sequence
1829 "Controls how TODO keywords are interpreted.
1830 This variable is in principle obsolete and is only used for
1831 backward compatibility, if the interpretation of todo keywords is
1832 not given already in `org-todo-keywords'. See that variable for
1835 :group
'org-keywords
1836 :type
'(choice (const sequence
)
1839 (defcustom org-use-fast-todo-selection t
1840 "Non-nil means use the fast todo selection scheme with C-c C-t.
1841 This variable describes if and under what circumstances the cycling
1842 mechanism for TODO keywords will be replaced by a single-key, direct
1845 When nil, fast selection is never used.
1847 When the symbol `prefix', it will be used when `org-todo' is called with
1848 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1849 in an agenda buffer.
1851 When t, fast selection is used by default. In this case, the prefix
1852 argument forces cycling instead.
1854 In all cases, the special interface is only used if access keys have actually
1855 been assigned by the user, i.e. if keywords in the configuration are followed
1856 by a letter in parenthesis, like TODO(t)."
1859 (const :tag
"Never" nil
)
1860 (const :tag
"By default" t
)
1861 (const :tag
"Only with C-u C-c C-t" prefix
)))
1863 (defcustom org-provide-todo-statistics t
1864 "Non-nil means update todo statistics after insert and toggle.
1865 ALL-HEADLINES means update todo statistics by including headlines
1866 with no TODO keyword as well, counting them as not done.
1867 A list of TODO keywords means the same, but skip keywords that are
1870 When this is set, todo statistics is updated in the parent of the
1871 current entry each time a todo state is changed."
1874 (const :tag
"Yes, only for TODO entries" t
)
1875 (const :tag
"Yes, including all entries" 'all-headlines
)
1876 (repeat :tag
"Yes, for TODOs in this list"
1877 (string :tag
"TODO keyword"))
1878 (other :tag
"No TODO statistics" nil
)))
1880 (defcustom org-hierarchical-todo-statistics t
1881 "Non-nil means TODO statistics covers just direct children.
1882 When nil, all entries in the subtree are considered.
1883 This has only an effect if `org-provide-todo-statistics' is set.
1884 To set this to nil for only a single subtree, use a COOKIE_DATA
1885 property and include the word \"recursive\" into the value."
1889 (defcustom org-after-todo-state-change-hook nil
1890 "Hook which is run after the state of a TODO item was changed.
1891 The new state (a string with a TODO keyword, or nil) is available in the
1892 Lisp variable `state'."
1896 (defvar org-blocker-hook nil
1897 "Hook for functions that are allowed to block a state change.
1899 Each function gets as its single argument a property list, see
1900 `org-trigger-hook' for more information about this list.
1902 If any of the functions in this hook returns nil, the state change
1905 (defvar org-trigger-hook nil
1906 "Hook for functions that are triggered by a state change.
1908 Each function gets as its single argument a property list with at least
1909 the following elements:
1911 (:type type-of-change :position pos-at-entry-start
1912 :from old-state :to new-state)
1914 Depending on the type, more properties may be present.
1916 This mechanism is currently implemented for:
1920 :type todo-state-change
1921 :from previous state (keyword as a string), or nil, or a symbol
1922 'todo' or 'done', to indicate the general type of state.
1923 :to new state, like in :from")
1925 (defcustom org-enforce-todo-dependencies nil
1926 "Non-nil means undone TODO entries will block switching the parent to DONE.
1927 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1928 be blocked if any prior sibling is not yet done.
1929 Finally, if the parent is blocked because of ordered siblings of its own,
1930 the child will also be blocked.
1931 This variable needs to be set before org.el is loaded, and you need to
1932 restart Emacs after a change to make the change effective. The only way
1933 to change is while Emacs is running is through the customize interface."
1934 :set
(lambda (var val
)
1937 (add-hook 'org-blocker-hook
1938 'org-block-todo-from-children-or-siblings-or-parent
)
1939 (remove-hook 'org-blocker-hook
1940 'org-block-todo-from-children-or-siblings-or-parent
)))
1944 (defcustom org-enforce-todo-checkbox-dependencies nil
1945 "Non-nil means unchecked boxes will block switching the parent to DONE.
1946 When this is nil, checkboxes have no influence on switching TODO states.
1947 When non-nil, you first need to check off all check boxes before the TODO
1948 entry can be switched to DONE.
1949 This variable needs to be set before org.el is loaded, and you need to
1950 restart Emacs after a change to make the change effective. The only way
1951 to change is while Emacs is running is through the customize interface."
1952 :set
(lambda (var val
)
1955 (add-hook 'org-blocker-hook
1956 'org-block-todo-from-checkboxes
)
1957 (remove-hook 'org-blocker-hook
1958 'org-block-todo-from-checkboxes
)))
1962 (defcustom org-treat-insert-todo-heading-as-state-change nil
1963 "Non-nil means inserting a TODO heading is treated as state change.
1964 So when the command \\[org-insert-todo-heading] is used, state change
1965 logging will apply if appropriate. When nil, the new TODO item will
1966 be inserted directly, and no logging will take place."
1970 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
1971 "Non-nil means switching TODO states with S-cursor counts as state change.
1972 This is the default behavior. However, setting this to nil allows a
1973 convenient way to select a TODO state and bypass any logging associated
1978 (defcustom org-todo-state-tags-triggers nil
1979 "Tag changes that should be triggered by TODO state changes.
1980 This is a list. Each entry is
1982 (state-change (tag . flag) .......)
1984 State-change can be a string with a state, and empty string to indicate the
1985 state that has no TODO keyword, or it can be one of the symbols `todo'
1986 or `done', meaning any not-done or done state, respectively."
1990 (cons (choice :tag
"When changing to"
1991 (const :tag
"Not-done state" todo
)
1992 (const :tag
"Done state" done
)
1993 (string :tag
"State"))
1995 (cons :tag
"Tag action"
1997 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
1999 (defcustom org-log-done nil
2000 "Information to record when a task moves to the DONE state.
2002 Possible values are:
2004 nil Don't add anything, just change the keyword
2005 time Add a time stamp to the task
2006 note Prompt for a note and add it with template `org-log-note-headings'
2008 This option can also be set with on a per-file-basis with
2010 #+STARTUP: nologdone
2012 #+STARTUP: lognotedone
2014 You can have local logging settings for a subtree by setting the LOGGING
2015 property to one or more of these keywords."
2017 :group
'org-progress
2019 (const :tag
"No logging" nil
)
2020 (const :tag
"Record CLOSED timestamp" time
)
2021 (const :tag
"Record CLOSED timestamp with note." note
)))
2023 ;; Normalize old uses of org-log-done.
2025 ((eq org-log-done t
) (setq org-log-done
'time
))
2026 ((and (listp org-log-done
) (memq 'done org-log-done
))
2027 (setq org-log-done
'note
)))
2029 (defcustom org-log-reschedule nil
2030 "Information to record when the scheduling date of a tasks is modified.
2032 Possible values are:
2034 nil Don't add anything, just change the date
2035 time Add a time stamp to the task
2036 note Prompt for a note and add it with template `org-log-note-headings'
2038 This option can also be set with on a per-file-basis with
2040 #+STARTUP: nologreschedule
2041 #+STARTUP: logreschedule
2042 #+STARTUP: lognotereschedule"
2044 :group
'org-progress
2046 (const :tag
"No logging" nil
)
2047 (const :tag
"Record timestamp" time
)
2048 (const :tag
"Record timestamp with note." note
)))
2050 (defcustom org-log-redeadline nil
2051 "Information to record when the deadline date of a tasks is modified.
2053 Possible values are:
2055 nil Don't add anything, just change the date
2056 time Add a time stamp to the task
2057 note Prompt for a note and add it with template `org-log-note-headings'
2059 This option can also be set with on a per-file-basis with
2061 #+STARTUP: nologredeadline
2062 #+STARTUP: logredeadline
2063 #+STARTUP: lognoteredeadline
2065 You can have local logging settings for a subtree by setting the LOGGING
2066 property to one or more of these keywords."
2068 :group
'org-progress
2070 (const :tag
"No logging" nil
)
2071 (const :tag
"Record timestamp" time
)
2072 (const :tag
"Record timestamp with note." note
)))
2074 (defcustom org-log-note-clock-out nil
2075 "Non-nil means record a note when clocking out of an item.
2076 This can also be configured on a per-file basis by adding one of
2077 the following lines anywhere in the buffer:
2079 #+STARTUP: lognoteclock-out
2080 #+STARTUP: nolognoteclock-out"
2082 :group
'org-progress
2085 (defcustom org-log-done-with-time t
2086 "Non-nil means the CLOSED time stamp will contain date and time.
2087 When nil, only the date will be recorded."
2088 :group
'org-progress
2091 (defcustom org-log-note-headings
2092 '((done .
"CLOSING NOTE %t")
2093 (state .
"State %-12s from %-12S %t")
2094 (note .
"Note taken on %t")
2095 (reschedule .
"Rescheduled from %S on %t")
2096 (delschedule .
"Not scheduled, was %S on %t")
2097 (redeadline .
"New deadline from %S on %t")
2098 (deldeadline .
"Removed deadline, was %S on %t")
2099 (refile .
"Refiled on %t")
2101 "Headings for notes added to entries.
2102 The value is an alist, with the car being a symbol indicating the note
2103 context, and the cdr is the heading to be used. The heading may also be the
2105 %t in the heading will be replaced by a time stamp.
2106 %s will be replaced by the new TODO state, in double quotes.
2107 %S will be replaced by the old TODO state, in double quotes.
2108 %u will be replaced by the user name.
2109 %U will be replaced by the full user name.
2111 In fact, it is not a good idea to change the `state' entry, because
2112 agenda log mode depends on the format of these entries."
2114 :group
'org-progress
2115 :type
'(list :greedy t
2116 (cons (const :tag
"Heading when closing an item" done
) string
)
2118 "Heading when changing todo state (todo sequence only)"
2120 (cons (const :tag
"Heading when just taking a note" note
) string
)
2121 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2122 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2123 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2124 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2125 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2126 (cons (const :tag
"Heading when refiling" refile
) string
)))
2128 (unless (assq 'note org-log-note-headings
)
2129 (push '(note .
"%t") org-log-note-headings
))
2131 (defcustom org-log-into-drawer nil
2132 "Non-nil means insert state change notes and time stamps into a drawer.
2133 When nil, state changes notes will be inserted after the headline and
2134 any scheduling and clock lines, but not inside a drawer.
2136 The value of this variable should be the name of the drawer to use.
2137 LOGBOOK is proposed at the default drawer for this purpose, you can
2138 also set this to a string to define the drawer of your choice.
2140 A value of t is also allowed, representing \"LOGBOOK\".
2142 If this variable is set, `org-log-state-notes-insert-after-drawers'
2145 You can set the property LOG_INTO_DRAWER to overrule this setting for
2148 :group
'org-progress
2150 (const :tag
"Not into a drawer" nil
)
2151 (const :tag
"LOGBOOK" t
)
2152 (string :tag
"Other")))
2154 (if (fboundp 'defvaralias
)
2155 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2157 (defun org-log-into-drawer ()
2158 "Return the value of `org-log-into-drawer', but let properties overrule.
2159 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2160 used instead of the default value."
2161 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2163 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2164 ((equal p
"t") "LOGBOOK")
2167 (defcustom org-log-state-notes-insert-after-drawers nil
2168 "Non-nil means insert state change notes after any drawers in entry.
2169 Only the drawers that *immediately* follow the headline and the
2170 deadline/scheduled line are skipped.
2171 When nil, insert notes right after the heading and perhaps the line
2172 with deadline/scheduling if present.
2174 This variable will have no effect if `org-log-into-drawer' is
2177 :group
'org-progress
2180 (defcustom org-log-states-order-reversed t
2181 "Non-nil means the latest state note will be directly after heading.
2182 When nil, the state change notes will be ordered according to time."
2184 :group
'org-progress
2187 (defcustom org-log-repeat
'time
2188 "Non-nil means record moving through the DONE state when triggering repeat.
2189 An auto-repeating task is immediately switched back to TODO when
2190 marked DONE. If you are not logging state changes (by adding \"@\"
2191 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2192 record a closing note, there will be no record of the task moving
2193 through DONE. This variable forces taking a note anyway.
2195 nil Don't force a record
2196 time Record a time stamp
2199 This option can also be set with on a per-file-basis with
2201 #+STARTUP: logrepeat
2202 #+STARTUP: lognoterepeat
2203 #+STARTUP: nologrepeat
2205 You can have local logging settings for a subtree by setting the LOGGING
2206 property to one or more of these keywords."
2208 :group
'org-progress
2210 (const :tag
"Don't force a record" nil
)
2211 (const :tag
"Force recording the DONE state" time
)
2212 (const :tag
"Force recording a note with the DONE state" note
)))
2215 (defgroup org-priorities nil
2216 "Priorities in Org-mode."
2217 :tag
"Org Priorities"
2220 (defcustom org-enable-priority-commands t
2221 "Non-nil means priority commands are active.
2222 When nil, these commands will be disabled, so that you never accidentally
2224 :group
'org-priorities
2227 (defcustom org-highest-priority ?A
2228 "The highest priority of TODO items. A character like ?A, ?B etc.
2229 Must have a smaller ASCII number than `org-lowest-priority'."
2230 :group
'org-priorities
2233 (defcustom org-lowest-priority ?C
2234 "The lowest priority of TODO items. A character like ?A, ?B etc.
2235 Must have a larger ASCII number than `org-highest-priority'."
2236 :group
'org-priorities
2239 (defcustom org-default-priority ?B
2240 "The default priority of TODO items.
2241 This is the priority an item get if no explicit priority is given."
2242 :group
'org-priorities
2245 (defcustom org-priority-start-cycle-with-default t
2246 "Non-nil means start with default priority when starting to cycle.
2247 When this is nil, the first step in the cycle will be (depending on the
2248 command used) one higher or lower that the default priority."
2249 :group
'org-priorities
2252 (defgroup org-time nil
2253 "Options concerning time stamps and deadlines in Org-mode."
2257 (defcustom org-insert-labeled-timestamps-at-point nil
2258 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2259 When nil, these labeled time stamps are forces into the second line of an
2260 entry, just after the headline. When scheduling from the global TODO list,
2261 the time stamp will always be forced into the second line."
2265 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2266 "Formats for `format-time-string' which are used for time stamps.
2267 It is not recommended to change this constant.")
2269 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2270 "Number of minutes to round time stamps to.
2271 These are two values, the first applies when first creating a time stamp.
2272 The second applies when changing it with the commands `S-up' and `S-down'.
2273 When changing the time stamp, this means that it will change in steps
2274 of N minutes, as given by the second value.
2276 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2277 numbers should be factors of 60, so for example 5, 10, 15.
2279 When this is larger than 1, you can still force an exact time-stamp by using
2280 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2281 and by using a prefix arg to `S-up/down' to specify the exact number
2282 of minutes to shift."
2284 :get
'(lambda (var) ; Make sure all entries have 5 elements
2285 (if (integerp (default-value var
))
2286 (list (default-value var
) 5)
2287 (default-value var
)))
2289 (integer :tag
"when inserting times")
2290 (integer :tag
"when modifying times")))
2292 ;; Normalize old customizations of this variable.
2293 (when (integerp org-time-stamp-rounding-minutes
)
2294 (setq org-time-stamp-rounding-minutes
2295 (list org-time-stamp-rounding-minutes
2296 org-time-stamp-rounding-minutes
)))
2298 (defcustom org-display-custom-times nil
2299 "Non-nil means overlay custom formats over all time stamps.
2300 The formats are defined through the variable `org-time-stamp-custom-formats'.
2301 To turn this on on a per-file basis, insert anywhere in the file:
2302 #+STARTUP: customtime"
2306 (make-variable-buffer-local 'org-display-custom-times
)
2308 (defcustom org-time-stamp-custom-formats
2309 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2310 "Custom formats for time stamps. See `format-time-string' for the syntax.
2311 These are overlayed over the default ISO format if the variable
2312 `org-display-custom-times' is set. Time like %H:%M should be at the
2313 end of the second format. The custom formats are also honored by export
2314 commands, if custom time display is turned on at the time of export."
2318 (defun org-time-stamp-format (&optional long inactive
)
2319 "Get the right format for a time string."
2320 (let ((f (if long
(cdr org-time-stamp-formats
)
2321 (car org-time-stamp-formats
))))
2323 (concat "[" (substring f
1 -
1) "]")
2326 (defcustom org-time-clocksum-format
"%d:%02d"
2327 "The format string used when creating CLOCKSUM lines, or when
2328 org-mode generates a time duration."
2332 (defcustom org-time-clocksum-use-fractional nil
2333 "If non-nil, \\[org-clock-display] uses fractional times.
2334 org-mode generates a time duration."
2338 (defcustom org-time-clocksum-fractional-format
"%.2f"
2339 "The format string used when creating CLOCKSUM lines, or when
2340 org-mode generates a time duration."
2344 (defcustom org-deadline-warning-days
14
2345 "No. of days before expiration during which a deadline becomes active.
2346 This variable governs the display in sparse trees and in the agenda.
2347 When 0 or negative, it means use this number (the absolute value of it)
2348 even if a deadline has a different individual lead time specified.
2350 Custom commands can set this variable in the options section."
2352 :group
'org-agenda-daily
/weekly
2355 (defcustom org-read-date-prefer-future t
2356 "Non-nil means assume future for incomplete date input from user.
2357 This affects the following situations:
2358 1. The user gives a month but not a year.
2359 For example, if it is april and you enter \"feb 2\", this will be read
2360 as feb 2, *next* year. \"May 5\", however, will be this year.
2361 2. The user gives a day, but no month.
2362 For example, if today is the 15th, and you enter \"3\", Org-mode will
2363 read this as the third of *next* month. However, if you enter \"17\",
2364 it will be considered as *this* month.
2366 If you set this variable to the symbol `time', then also the following
2369 3. If the user gives a time, but no day. If the time is before now,
2370 to will be interpreted as tomorrow.
2372 Currently none of this works for ISO week specifications.
2374 When this option is nil, the current day, month and year will always be
2378 (const :tag
"Never" nil
)
2379 (const :tag
"Check month and day" t
)
2380 (const :tag
"Check month, day, and time" time
)))
2382 (defcustom org-read-date-display-live t
2383 "Non-nil means display current interpretation of date prompt live.
2384 This display will be in an overlay, in the minibuffer."
2388 (defcustom org-read-date-popup-calendar t
2389 "Non-nil means pop up a calendar when prompting for a date.
2390 In the calendar, the date can be selected with mouse-1. However, the
2391 minibuffer will also be active, and you can simply enter the date as well.
2392 When nil, only the minibuffer will be available."
2395 (if (fboundp 'defvaralias
)
2396 (defvaralias 'org-popup-calendar-for-date-prompt
2397 'org-read-date-popup-calendar
))
2399 (defcustom org-read-date-minibuffer-setup-hook nil
2400 "Hook to be used to set up keys for the date/time interface.
2401 Add key definitions to `minibuffer-local-map', which will be a temporary
2406 (defcustom org-extend-today-until
0
2407 "The hour when your day really ends. Must be an integer.
2408 This has influence for the following applications:
2409 - When switching the agenda to \"today\". It it is still earlier than
2410 the time given here, the day recognized as TODAY is actually yesterday.
2411 - When a date is read from the user and it is still before the time given
2412 here, the current date and time will be assumed to be yesterday, 23:59.
2413 Also, timestamps inserted in remember templates follow this rule.
2415 IMPORTANT: This is a feature whose implementation is and likely will
2416 remain incomplete. Really, it is only here because past midnight seems to
2417 be the favorite working time of John Wiegley :-)"
2421 (defcustom org-edit-timestamp-down-means-later nil
2422 "Non-nil means S-down will increase the time in a time stamp.
2423 When nil, S-up will increase."
2427 (defcustom org-calendar-follow-timestamp-change t
2428 "Non-nil means make the calendar window follow timestamp changes.
2429 When a timestamp is modified and the calendar window is visible, it will be
2430 moved to the new date."
2434 (defgroup org-tags nil
2435 "Options concerning tags in Org-mode."
2439 (defcustom org-tag-alist nil
2440 "List of tags allowed in Org-mode files.
2441 When this list is nil, Org-mode will base TAG input on what is already in the
2443 The value of this variable is an alist, the car of each entry must be a
2444 keyword as a string, the cdr may be a character that is used to select
2445 that tag through the fast-tag-selection interface.
2446 See the manual for details."
2450 (cons (string :tag
"Tag name")
2451 (character :tag
"Access char"))
2452 (list :tag
"Start radio group"
2454 (option (string :tag
"Group description")))
2455 (list :tag
"End radio group"
2457 (option (string :tag
"Group description")))
2458 (const :tag
"New line" (:newline
)))))
2460 (defcustom org-tag-persistent-alist nil
2461 "List of tags that will always appear in all Org-mode files.
2462 This is in addition to any in buffer settings or customizations
2464 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2465 The value of this variable is an alist, the car of each entry must be a
2466 keyword as a string, the cdr may be a character that is used to select
2467 that tag through the fast-tag-selection interface.
2468 See the manual for details.
2469 To disable these tags on a per-file basis, insert anywhere in the file:
2474 (cons (string :tag
"Tag name")
2475 (character :tag
"Access char"))
2476 (const :tag
"Start radio group" (:startgroup
))
2477 (const :tag
"End radio group" (:endgroup
))
2478 (const :tag
"New line" (:newline
)))))
2480 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2481 "If non-nil, always offer completion for all tags of all agenda files.
2482 Instead of customizing this variable directly, you might want to
2483 set it locally for remember buffers, because there no list of
2484 tags in that file can be created dynamically (there are none).
2486 (add-hook 'org-remember-mode-hook
2488 (set (make-local-variable
2489 'org-complete-tags-always-offer-all-agenda-tags)
2494 (defvar org-file-tags nil
2495 "List of tags that can be inherited by all entries in the file.
2496 The tags will be inherited if the variable `org-use-tag-inheritance'
2497 says they should be.
2498 This variable is populated from #+FILETAGS lines.")
2500 (defcustom org-use-fast-tag-selection
'auto
2501 "Non-nil means use fast tag selection scheme.
2502 This is a special interface to select and deselect tags with single keys.
2503 When nil, fast selection is never used.
2504 When the symbol `auto', fast selection is used if and only if selection
2505 characters for tags have been configured, either through the variable
2506 `org-tag-alist' or through a #+TAGS line in the buffer.
2507 When t, fast selection is always used and selection keys are assigned
2508 automatically if necessary."
2511 (const :tag
"Always" t
)
2512 (const :tag
"Never" nil
)
2513 (const :tag
"When selection characters are configured" 'auto
)))
2515 (defcustom org-fast-tag-selection-single-key nil
2516 "Non-nil means fast tag selection exits after first change.
2517 When nil, you have to press RET to exit it.
2518 During fast tag selection, you can toggle this flag with `C-c'.
2519 This variable can also have the value `expert'. In this case, the window
2520 displaying the tags menu is not even shown, until you press C-c again."
2523 (const :tag
"No" nil
)
2524 (const :tag
"Yes" t
)
2525 (const :tag
"Expert" expert
)))
2527 (defvar org-fast-tag-selection-include-todo nil
2528 "Non-nil means fast tags selection interface will also offer TODO states.
2529 This is an undocumented feature, you should not rely on it.")
2531 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2532 "The column to which tags should be indented in a headline.
2533 If this number is positive, it specifies the column. If it is negative,
2534 it means that the tags should be flushright to that column. For example,
2535 -80 works well for a normal 80 character screen."
2539 (defcustom org-auto-align-tags t
2540 "Non-nil means realign tags after pro/demotion of TODO state change.
2541 These operations change the length of a headline and therefore shift
2542 the tags around. With this options turned on, after each such operation
2543 the tags are again aligned to `org-tags-column'."
2547 (defcustom org-use-tag-inheritance t
2548 "Non-nil means tags in levels apply also for sublevels.
2549 When nil, only the tags directly given in a specific line apply there.
2550 This may also be a list of tags that should be inherited, or a regexp that
2551 matches tags that should be inherited. Additional control is possible
2552 with the variable `org-tags-exclude-from-inheritance' which gives an
2553 explicit list of tags to be excluded from inheritance., even if the value of
2554 `org-use-tag-inheritance' would select it for inheritance.
2556 If this option is t, a match early-on in a tree can lead to a large
2557 number of matches in the subtree when constructing the agenda or creating
2558 a sparse tree. If you only want to see the first match in a tree during
2559 a search, check out the variable `org-tags-match-list-sublevels'."
2562 (const :tag
"Not" nil
)
2563 (const :tag
"Always" t
)
2564 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2565 (regexp :tag
"Tags matched by regexp")))
2567 (defcustom org-tags-exclude-from-inheritance nil
2568 "List of tags that should never be inherited.
2569 This is a way to exclude a few tags from inheritance. For way to do
2570 the opposite, to actively allow inheritance for selected tags,
2571 see the variable `org-use-tag-inheritance'."
2573 :type
'(repeat (string :tag
"Tag")))
2575 (defun org-tag-inherit-p (tag)
2576 "Check if TAG is one that should be inherited."
2578 ((member tag org-tags-exclude-from-inheritance
) nil
)
2579 ((eq org-use-tag-inheritance t
) t
)
2580 ((not org-use-tag-inheritance
) nil
)
2581 ((stringp org-use-tag-inheritance
)
2582 (string-match org-use-tag-inheritance tag
))
2583 ((listp org-use-tag-inheritance
)
2584 (member tag org-use-tag-inheritance
))
2585 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2587 (defcustom org-tags-match-list-sublevels t
2588 "Non-nil means list also sublevels of headlines matching a search.
2589 This variable applies to tags/property searches, and also to stuck
2590 projects because this search is based on a tags match as well.
2592 When set to the symbol `indented', sublevels are indented with
2595 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2596 the sublevels of a headline matching a tag search often also match
2597 the same search. Listing all of them can create very long lists.
2598 Setting this variable to nil causes subtrees of a match to be skipped.
2600 This variable is semi-obsolete and probably should always be true. It
2601 is better to limit inheritance to certain tags using the variables
2602 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2605 (const :tag
"No, don't list them" nil
)
2606 (const :tag
"Yes, do list them" t
)
2607 (const :tag
"List them, indented with leading dots" indented
)))
2609 (defcustom org-tags-sort-function nil
2610 "When set, tags are sorted using this function as a comparator"
2613 (const :tag
"No sorting" nil
)
2614 (const :tag
"Alphabetical" string
<)
2615 (const :tag
"Reverse alphabetical" string
>)
2616 (function :tag
"Custom function" nil
)))
2618 (defvar org-tags-history nil
2619 "History of minibuffer reads for tags.")
2620 (defvar org-last-tags-completion-table nil
2621 "The last used completion table for tags.")
2622 (defvar org-after-tags-change-hook nil
2623 "Hook that is run after the tags in a line have changed.")
2625 (defgroup org-properties nil
2626 "Options concerning properties in Org-mode."
2627 :tag
"Org Properties"
2630 (defcustom org-property-format
"%-10s %s"
2631 "How property key/value pairs should be formatted by `indent-line'.
2632 When `indent-line' hits a property definition, it will format the line
2633 according to this format, mainly to make sure that the values are
2634 lined-up with respect to each other."
2635 :group
'org-properties
2638 (defcustom org-use-property-inheritance nil
2639 "Non-nil means properties apply also for sublevels.
2641 This setting is chiefly used during property searches. Turning it on can
2642 cause significant overhead when doing a search, which is why it is not
2645 When nil, only the properties directly given in the current entry count.
2646 When t, every property is inherited. The value may also be a list of
2647 properties that should have inheritance, or a regular expression matching
2648 properties that should be inherited.
2650 However, note that some special properties use inheritance under special
2651 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2652 and the properties ending in \"_ALL\" when they are used as descriptor
2653 for valid values of a property.
2655 Note for programmers:
2656 When querying an entry with `org-entry-get', you can control if inheritance
2657 should be used. By default, `org-entry-get' looks only at the local
2658 properties. You can request inheritance by setting the inherit argument
2659 to t (to force inheritance) or to `selective' (to respect the setting
2661 :group
'org-properties
2663 (const :tag
"Not" nil
)
2664 (const :tag
"Always" t
)
2665 (repeat :tag
"Specific properties" (string :tag
"Property"))
2666 (regexp :tag
"Properties matched by regexp")))
2668 (defun org-property-inherit-p (property)
2669 "Check if PROPERTY is one that should be inherited."
2671 ((eq org-use-property-inheritance t
) t
)
2672 ((not org-use-property-inheritance
) nil
)
2673 ((stringp org-use-property-inheritance
)
2674 (string-match org-use-property-inheritance property
))
2675 ((listp org-use-property-inheritance
)
2676 (member property org-use-property-inheritance
))
2677 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2679 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2680 "The default column format, if no other format has been defined.
2681 This variable can be set on the per-file basis by inserting a line
2683 #+COLUMNS: %25ITEM ....."
2684 :group
'org-properties
2687 (defcustom org-columns-ellipses
".."
2688 "The ellipses to be used when a field in column view is truncated.
2689 When this is the empty string, as many characters as possible are shown,
2690 but then there will be no visual indication that the field has been truncated.
2691 When this is a string of length N, the last N characters of a truncated
2692 field are replaced by this string. If the column is narrower than the
2693 ellipses string, only part of the ellipses string will be shown."
2694 :group
'org-properties
2697 (defcustom org-columns-modify-value-for-display-function nil
2698 "Function that modifies values for display in column view.
2699 For example, it can be used to cut out a certain part from a time stamp.
2700 The function must take 2 arguments:
2702 column-title The title of the column (*not* the property name)
2703 value The value that should be modified.
2705 The function should return the value that should be displayed,
2706 or nil if the normal value should be used."
2707 :group
'org-properties
2710 (defcustom org-effort-property
"Effort"
2711 "The property that is being used to keep track of effort estimates.
2712 Effort estimates given in this property need to have the format H:MM."
2713 :group
'org-properties
2714 :group
'org-progress
2715 :type
'(string :tag
"Property"))
2717 (defconst org-global-properties-fixed
2718 '(("VISIBILITY_ALL" .
"folded children content all")
2719 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2720 "List of property/value pairs that can be inherited by any entry.
2722 These are fixed values, for the preset properties. The user variable
2723 that can be used to add to this list is `org-global-properties'.
2725 The entries in this list are cons cells where the car is a property
2726 name and cdr is a string with the value. If the value represents
2727 multiple items like an \"_ALL\" property, separate the items by
2730 (defcustom org-global-properties nil
2731 "List of property/value pairs that can be inherited by any entry.
2733 This list will be combined with the constant `org-global-properties-fixed'.
2735 The entries in this list are cons cells where the car is a property
2736 name and cdr is a string with the value.
2738 You can set buffer-local values for the same purpose in the variable
2739 `org-file-properties' this by adding lines like
2741 #+PROPERTY: NAME VALUE"
2742 :group
'org-properties
2744 (cons (string :tag
"Property")
2745 (string :tag
"Value"))))
2747 (defvar org-file-properties nil
2748 "List of property/value pairs that can be inherited by any entry.
2749 Valid for the current buffer.
2750 This variable is populated from #+PROPERTY lines.")
2751 (make-variable-buffer-local 'org-file-properties
)
2753 (defgroup org-agenda nil
2754 "Options concerning agenda views in Org-mode."
2758 (defvar org-category nil
2759 "Variable used by org files to set a category for agenda display.
2760 Such files should use a file variable to set it, for example
2762 # -*- mode: org; org-category: \"ELisp\"
2764 or contain a special line
2768 If the file does not specify a category, then file's base name
2770 (make-variable-buffer-local 'org-category
)
2771 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2773 (defcustom org-agenda-files nil
2774 "The files to be used for agenda display.
2775 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2776 \\[org-remove-file]. You can also use customize to edit the list.
2778 If an entry is a directory, all files in that directory that are matched by
2779 `org-agenda-file-regexp' will be part of the file list.
2781 If the value of the variable is not a list but a single file name, then
2782 the list of agenda files is actually stored and maintained in that file, one
2783 agenda file per line. In this file paths can be given relative to
2784 `org-directory'. Tilde expansion and environment variable substitution
2788 (repeat :tag
"List of files and directories" file
)
2789 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2791 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2792 "Regular expression to match files for `org-agenda-files'.
2793 If any element in the list in that variable contains a directory instead
2794 of a normal file, all files in that directory that are matched by this
2795 regular expression will be included."
2799 (defcustom org-agenda-text-search-extra-files nil
2800 "List of extra files to be searched by text search commands.
2801 These files will be search in addition to the agenda files by the
2802 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2803 Note that these files will only be searched for text search commands,
2804 not for the other agenda views like todo lists, tag searches or the weekly
2805 agenda. This variable is intended to list notes and possibly archive files
2806 that should also be searched by these two commands.
2807 In fact, if the first element in the list is the symbol `agenda-archives',
2808 than all archive files of all agenda files will be added to the search
2811 :type
'(set :greedy t
2812 (const :tag
"Agenda Archives" agenda-archives
)
2813 (repeat :inline t
(file))))
2815 (if (fboundp 'defvaralias
)
2816 (defvaralias 'org-agenda-multi-occur-extra-files
2817 'org-agenda-text-search-extra-files
))
2819 (defcustom org-agenda-skip-unavailable-files nil
2820 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2821 A nil value means to remove them, after a query, from the list."
2825 (defcustom org-calendar-to-agenda-key
[?c
]
2826 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2827 The command `org-calendar-goto-agenda' will be bound to this key. The
2828 default is the character `c' because then `c' can be used to switch back and
2829 forth between agenda and calendar."
2833 (defcustom org-calendar-agenda-action-key
[?k
]
2834 "The key to be installed in `calendar-mode-map' for agenda-action.
2835 The command `org-agenda-action' will be bound to this key. The
2836 default is the character `k' because we use the same key in the agenda."
2840 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2841 "The key to be installed in `calendar-mode-map' for adding diary entries.
2842 This option is irrelevant until `org-agenda-diary-file' has been configured
2843 to point to an Org-mode file. When that is the case, the command
2844 `org-agenda-diary-entry' will be bound to the key given here, by default
2845 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2846 if you want to continue doing this, you need to change this to a different
2851 (defcustom org-agenda-diary-file
'diary-file
2852 "File to which to add new entries with the `i' key in agenda and calendar.
2853 When this is the symbol `diary-file', the functionality in the Emacs
2854 calendar will be used to add entries to the `diary-file'. But when this
2855 points to a file, `org-agenda-diary-entry' will be used instead."
2858 (const :tag
"The standard Emacs diary file" diary-file
)
2859 (file :tag
"Special Org file diary entries")))
2861 (eval-after-load "calendar"
2863 (org-defkey calendar-mode-map org-calendar-to-agenda-key
2864 'org-calendar-goto-agenda
)
2865 (org-defkey calendar-mode-map org-calendar-agenda-action-key
2867 (add-hook 'calendar-mode-hook
2869 (unless (eq org-agenda-diary-file
'diary-file
)
2870 (define-key calendar-mode-map
2871 org-calendar-insert-diary-entry-key
2872 'org-agenda-diary-entry
))))))
2874 (defgroup org-latex nil
2875 "Options for embedding LaTeX code into Org-mode."
2879 (defcustom org-format-latex-options
2880 '(:foreground default
:background default
:scale
1.0
2881 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
2882 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
2883 "Options for creating images from LaTeX fragments.
2884 This is a property list with the following properties:
2885 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
2886 `default' means use the foreground of the default face.
2887 :background the background color, or \"Transparent\".
2888 `default' means use the background of the default face.
2889 :scale a scaling factor for the size of the images.
2890 :html-foreground, :html-background, :html-scale
2891 the same numbers for HTML export.
2892 :matchers a list indicating which matchers should be used to
2893 find LaTeX fragments. Valid members of this list are:
2894 \"begin\" find environments
2895 \"$1\" find single characters surrounded by $.$
2896 \"$\" find math expressions surrounded by $...$
2897 \"$$\" find math expressions surrounded by $$....$$
2898 \"\\(\" find math expressions surrounded by \\(...\\)
2899 \"\\ [\" find math expressions surrounded by \\ [...\\]"
2903 (defcustom org-format-latex-signal-error t
2904 "Non-nil means signal an error when image creation of LaTeX snippets fails.
2905 When nil, just push out a message."
2909 (defcustom org-format-latex-header
"\\documentclass{article}
2910 \\usepackage[usenames]{color}
2911 \\usepackage{amsmath}
2912 \\usepackage[mathscr]{eucal}
2913 \\pagestyle{empty} % do not remove
2914 % The settings below are copied from fullpage.sty
2915 \\setlength{\\textwidth}{\\paperwidth}
2916 \\addtolength{\\textwidth}{-3cm}
2917 \\setlength{\\oddsidemargin}{1.5cm}
2918 \\addtolength{\\oddsidemargin}{-2.54cm}
2919 \\setlength{\\evensidemargin}{\\oddsidemargin}
2920 \\setlength{\\textheight}{\\paperheight}
2921 \\addtolength{\\textheight}{-\\headheight}
2922 \\addtolength{\\textheight}{-\\headsep}
2923 \\addtolength{\\textheight}{-\\footskip}
2924 \\addtolength{\\textheight}{-3cm}
2925 \\setlength{\\topmargin}{1.5cm}
2926 \\addtolength{\\topmargin}{-2.54cm}"
2927 "The document header used for processing LaTeX fragments.
2928 It is imperative that this header make sure that no page number
2929 appears on the page."
2933 (defvar org-format-latex-header-extra nil
)
2935 ;; The following variables are defined here because is it also used
2936 ;; when formatting latex fragments. Originally it was part of the
2937 ;; LaTeX exporter, which is why the name includes "export".
2938 (defcustom org-export-latex-default-packages-alist
2939 '(("AUTO" "inputenc")
2953 "Alist of default packages to be inserted in the header.
2954 Change this only if one of the packages here causes an incompatibility
2955 with another package you are using.
2956 The packages in this list are needed by one part or another of Org-mode
2957 to function properly.
2959 - inputenc, fontenc, t1enc: for basic font and character selection
2960 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
2961 for interpreting the entities in `org-entities'. You can skip some of these
2962 packages if you don't use any of the symbols in it.
2963 - graphicx: for including images
2964 - float, wrapfig: for figure placement
2965 - longtable: for long tables
2966 - hyperref: for cross references
2968 Therefore you should not modify this variable unless you know what you
2969 are doing. The one reason to change it anyway is that you might be loading
2970 some other package that conflicts with one of the default packages.
2971 Each cell is of the format \( \"options\" \"package\" \)."
2972 :group
'org-export-latex
2975 (string :tag
"options")
2976 (string :tag
"package"))))
2978 (defcustom org-export-latex-packages-alist nil
2979 "Alist of packages to be inserted in the header.
2980 These will be inserted after `org-export-latex-default-packages-alist'.
2981 Each cell is of the format \( \"options\" \"package\" \)."
2982 :group
'org-export-latex
2985 (string :tag
"options")
2986 (string :tag
"package"))))
2988 (defgroup org-appearance nil
2989 "Settings for Org-mode appearance."
2990 :tag
"Org Appearance"
2993 (defcustom org-level-color-stars-only nil
2994 "Non-nil means fontify only the stars in each headline.
2995 When nil, the entire headline is fontified.
2996 Changing it requires restart of `font-lock-mode' to become effective
2997 also in regions already fontified."
2998 :group
'org-appearance
3001 (defcustom org-hide-leading-stars nil
3002 "Non-nil means hide the first N-1 stars in a headline.
3003 This works by using the face `org-hide' for these stars. This
3004 face is white for a light background, and black for a dark
3005 background. You may have to customize the face `org-hide' to
3007 Changing it requires restart of `font-lock-mode' to become effective
3008 also in regions already fontified.
3009 You may also set this on a per-file basis by adding one of the following
3010 lines to the buffer:
3012 #+STARTUP: hidestars
3013 #+STARTUP: showstars"
3014 :group
'org-appearance
3017 (defcustom org-hidden-keywords nil
3018 "List of keywords that should be hidden when typed in the org buffer.
3019 For example, add #+TITLE to this list in order to make the
3020 document title appear in the buffer without the initial #+TITLE:
3022 :group
'org-appearance
3023 :type
'(set (const :tag
"#+AUTHOR" author
)
3024 (const :tag
"#+DATE" date
)
3025 (const :tag
"#+EMAIL" email
)
3026 (const :tag
"#+TITLE" title
)))
3028 (defcustom org-fontify-done-headline nil
3029 "Non-nil means change the face of a headline if it is marked DONE.
3030 Normally, only the TODO/DONE keyword indicates the state of a headline.
3031 When this is non-nil, the headline after the keyword is set to the
3032 `org-headline-done' as an additional indication."
3033 :group
'org-appearance
3036 (defcustom org-fontify-emphasized-text t
3037 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3038 Changing this variable requires a restart of Emacs to take effect."
3039 :group
'org-appearance
3042 (defcustom org-fontify-whole-heading-line nil
3043 "Non-nil means fontify the whole line for headings.
3044 This is useful when setting a background color for the
3046 :group
'org-appearance
3049 (defcustom org-highlight-latex-fragments-and-specials nil
3050 "Non-nil means fontify what is treated specially by the exporters."
3051 :group
'org-appearance
3054 (defcustom org-hide-emphasis-markers nil
3055 "Non-nil mean font-lock should hide the emphasis marker characters."
3056 :group
'org-appearance
3059 (defvar org-emph-re nil
3060 "Regular expression for matching emphasis.")
3061 (defvar org-verbatim-re nil
3062 "Regular expression for matching verbatim text.")
3063 (defvar org-emphasis-regexp-components
) ; defined just below
3064 (defvar org-emphasis-alist
) ; defined just below
3065 (defun org-set-emph-re (var val
)
3066 "Set variable and compute the emphasis regular expression."
3068 (when (and (boundp 'org-emphasis-alist
)
3069 (boundp 'org-emphasis-regexp-components
)
3070 org-emphasis-alist org-emphasis-regexp-components
)
3071 (let* ((e org-emphasis-regexp-components
)
3077 (body1 (concat body
"*?"))
3078 (markers (mapconcat 'car org-emphasis-alist
""))
3079 (vmarkers (mapconcat
3080 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3081 org-emphasis-alist
"")))
3082 ;; make sure special characters appear at the right position in the class
3083 (if (string-match "\\^" markers
)
3084 (setq markers
(concat (replace-match "" t t markers
) "^")))
3085 (if (string-match "-" markers
)
3086 (setq markers
(concat (replace-match "" t t markers
) "-")))
3087 (if (string-match "\\^" vmarkers
)
3088 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3089 (if (string-match "-" vmarkers
)
3090 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3092 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3093 (int-to-string nl
) "\\}")))
3096 (concat "\\([" pre
"]\\|^\\)"
3098 "\\([" markers
"]\\)"
3106 "\\([" post
"]\\|$\\)"))
3107 (setq org-verbatim-re
3108 (concat "\\([" pre
"]\\|^\\)"
3110 "\\([" vmarkers
"]\\)"
3118 "\\([" post
"]\\|$\\)")))))
3120 (defcustom org-emphasis-regexp-components
3121 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3122 "Components used to build the regular expression for emphasis.
3123 This is a list with 6 entries. Terminology: In an emphasis string
3124 like \" *strong word* \", we call the initial space PREMATCH, the final
3125 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3126 and \"trong wor\" is the body. The different components in this variable
3127 specify what is allowed/forbidden in each part:
3129 pre Chars allowed as prematch. Beginning of line will be allowed too.
3130 post Chars allowed as postmatch. End of line will be allowed too.
3131 border The chars *forbidden* as border characters.
3132 body-regexp A regexp like \".\" to match a body character. Don't use
3133 non-shy groups here, and don't allow newline here.
3134 newline The maximum number of newlines allowed in an emphasis exp.
3136 Use customize to modify this, or restart Emacs after changing it."
3137 :group
'org-appearance
3138 :set
'org-set-emph-re
3140 (sexp :tag
"Allowed chars in pre ")
3141 (sexp :tag
"Allowed chars in post ")
3142 (sexp :tag
"Forbidden chars in border ")
3143 (sexp :tag
"Regexp for body ")
3144 (integer :tag
"number of newlines allowed")
3145 (option (boolean :tag
"Please ignore this button"))))
3147 (defcustom org-emphasis-alist
3148 `(("*" bold
"<b>" "</b>")
3149 ("/" italic
"<i>" "</i>")
3150 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3151 ("=" org-code
"<code>" "</code>" verbatim
)
3152 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3153 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3156 "Special syntax for emphasized text.
3157 Text starting and ending with a special character will be emphasized, for
3158 example *bold*, _underlined_ and /italic/. This variable sets the marker
3159 characters, the face to be used by font-lock for highlighting in Org-mode
3160 Emacs buffers, and the HTML tags to be used for this.
3161 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3162 Use customize to modify this, or restart Emacs after changing it."
3163 :group
'org-appearance
3164 :set
'org-set-emph-re
3167 (string :tag
"Marker character")
3169 (face :tag
"Font-lock-face")
3170 (plist :tag
"Face property list"))
3171 (string :tag
"HTML start tag")
3172 (string :tag
"HTML end tag")
3173 (option (const verbatim
)))))
3175 (defvar org-protecting-blocks
3176 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3177 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3178 This is needed for font-lock setup.")
3180 ;;; Miscellaneous options
3182 (defgroup org-completion nil
3183 "Completion in Org-mode."
3184 :tag
"Org Completion"
3187 (defcustom org-completion-use-ido nil
3188 "Non-nil means use ido completion wherever possible.
3189 Note that `ido-mode' must be active for this variable to be relevant.
3190 If you decide to turn this variable on, you might well want to turn off
3191 `org-outline-path-complete-in-steps'.
3192 See also `org-completion-use-iswitchb'."
3193 :group
'org-completion
3196 (defcustom org-completion-use-iswitchb nil
3197 "Non-nil means use iswitchb completion wherever possible.
3198 Note that `iswitchb-mode' must be active for this variable to be relevant.
3199 If you decide to turn this variable on, you might well want to turn off
3200 `org-outline-path-complete-in-steps'.
3201 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3202 :group
'org-completion
3205 (defcustom org-completion-fallback-command
'hippie-expand
3206 "The expansion command called by \\[org-complete] in normal context.
3207 Normal means no org-mode-specific context."
3208 :group
'org-completion
3211 ;;; Functions and variables from their packages
3212 ;; Declared here to avoid compiler warnings
3215 (defvar outline-mode-menu-heading
)
3216 (defvar outline-mode-menu-show
)
3217 (defvar outline-mode-menu-hide
)
3218 (defvar zmacs-regions
) ; XEmacs regions
3221 (defvar mark-active
)
3224 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3225 (declare-function calendar-forward-day
"cal-move" (arg))
3226 (declare-function calendar-goto-date
"cal-move" (date))
3227 (declare-function calendar-goto-today
"cal-move" ())
3228 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3229 (defvar calc-embedded-close-formula
)
3230 (defvar calc-embedded-open-formula
)
3231 (declare-function cdlatex-tab
"ext:cdlatex" ())
3232 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3233 (defvar font-lock-unfontify-region-function
)
3234 (declare-function iswitchb-read-buffer
"iswitchb"
3235 (prompt &optional default require-match start matches-set
))
3236 (defvar iswitchb-temp-buflist
)
3237 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3238 (defvar org-agenda-tags-todo-honor-ignore-options
)
3239 (declare-function org-agenda-skip
"org-agenda" ())
3241 org-format-agenda-item
"org-agenda"
3242 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3243 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3244 (declare-function org-agenda-change-all-lines
"org-agenda"
3245 (newhead hdmarker
&optional fixface just-this
))
3246 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3247 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3248 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3250 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3251 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3252 "org-agenda" (&optional end
))
3253 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3254 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3255 (declare-function parse-time-string
"parse-time" (string))
3256 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3257 (defvar remember-data-file
)
3258 (defvar texmathp-why
)
3259 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3260 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3262 (defvar w3m-current-url
)
3263 (defvar w3m-current-title
)
3265 (defvar org-latex-regexps
)
3267 ;;; Autoload and prepare some org modules
3269 ;; Some table stuff that needs to be defined here, because it is used
3270 ;; by the functions setting up org-mode or checking for table context.
3272 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3273 "Detects an org-type or table-type table.")
3274 (defconst org-table-line-regexp
"^[ \t]*|"
3275 "Detects an org-type table line.")
3276 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3277 "Detects an org-type table line.")
3278 (defconst org-table-hline-regexp
"^[ \t]*|-"
3279 "Detects an org-type table hline.")
3280 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3281 "Detects a table-type table hline.")
3282 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3283 "Searching from within a table (any type) this finds the first line
3284 outside the table.")
3286 ;; Autoload the functions in org-table.el that are needed by functions here.
3289 (org-autoload "org-table"
3290 '(org-table-align org-table-begin org-table-blank-field
3291 org-table-convert org-table-convert-region org-table-copy-down
3292 org-table-copy-region org-table-create
3293 org-table-create-or-convert-from-region
3294 org-table-create-with-table.el org-table-current-dline
3295 org-table-cut-region org-table-delete-column org-table-edit-field
3296 org-table-edit-formulas org-table-end org-table-eval-formula
3297 org-table-export org-table-field-info
3298 org-table-get-stored-formulas org-table-goto-column
3299 org-table-hline-and-move org-table-import org-table-insert-column
3300 org-table-insert-hline org-table-insert-row org-table-iterate
3301 org-table-justify-field-maybe org-table-kill-row
3302 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3303 org-table-move-column org-table-move-column-left
3304 org-table-move-column-right org-table-move-row
3305 org-table-move-row-down org-table-move-row-up
3306 org-table-next-field org-table-next-row org-table-paste-rectangle
3307 org-table-previous-field org-table-recalculate
3308 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3309 org-table-toggle-coordinate-overlays
3310 org-table-toggle-formula-debugger org-table-wrap-region
3311 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3313 (defun org-at-table-p (&optional table-type
)
3314 "Return t if the cursor is inside an org-type table.
3315 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3316 (if org-enable-table-editor
3318 (beginning-of-line 1)
3319 (looking-at (if table-type org-table-any-line-regexp
3320 org-table-line-regexp
)))
3322 (defsubst org-table-p
() (org-at-table-p))
3324 (defun org-at-table.el-p
()
3325 "Return t if and only if we are at a table.el table."
3326 (and (org-at-table-p 'any
)
3328 (goto-char (org-table-begin 'any
))
3329 (looking-at org-table1-hline-regexp
))))
3330 (defun org-table-recognize-table.el
()
3331 "If there is a table.el table nearby, recognize it and move into it."
3332 (if org-table-tab-recognizes-table.el
3333 (if (org-at-table.el-p
)
3335 (beginning-of-line 1)
3336 (if (looking-at org-table-dataline-regexp
)
3338 (if (looking-at org-table1-hline-regexp
)
3340 (beginning-of-line 2)
3341 (if (looking-at org-table-any-border-regexp
)
3342 (beginning-of-line -
1)))))
3343 (if (re-search-forward "|" (org-table-end t
) t
)
3346 (if (table--at-cell-p (point))
3348 (message "recognizing table.el table...")
3349 (table-recognize-table)
3350 (message "recognizing table.el table...done")))
3351 (error "This should not happen..."))
3356 (defun org-at-table-hline-p ()
3357 "Return t if the cursor is inside a hline in a table."
3358 (if org-enable-table-editor
3360 (beginning-of-line 1)
3361 (looking-at org-table-hline-regexp
))
3364 (defvar org-table-clean-did-remove-column nil
)
3366 (defun org-table-map-tables (function)
3367 "Apply FUNCTION to the start of all tables in the buffer."
3371 (goto-char (point-min))
3372 (while (re-search-forward org-table-any-line-regexp nil t
)
3373 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
3374 (beginning-of-line 1)
3375 (when (looking-at org-table-line-regexp
)
3376 (save-excursion (funcall function
))
3377 (or (looking-at org-table-line-regexp
)
3379 (re-search-forward org-table-any-border-regexp nil
1))))
3380 (message "Mapping tables: done"))
3382 ;; Declare and autoload functions from org-exp.el & Co
3384 (declare-function org-default-export-plist
"org-exp")
3385 (declare-function org-infile-export-plist
"org-exp")
3386 (declare-function org-get-current-options
"org-exp")
3388 (org-autoload "org-exp"
3389 '(org-export org-export-visible
3390 org-insert-export-options-template
3391 org-table-clean-before-export
))
3392 (org-autoload "org-ascii"
3393 '(org-export-as-ascii org-export-ascii-preprocess
3394 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3395 org-export-region-as-ascii
))
3396 (org-autoload "org-latex"
3397 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3398 org-replace-region-by-latex org-export-region-as-latex
3399 org-export-as-latex org-export-as-pdf
3400 org-export-as-pdf-and-open
))
3401 (org-autoload "org-html"
3402 '(org-export-as-html-and-open
3403 org-export-as-html-batch org-export-as-html-to-buffer
3404 org-replace-region-by-html org-export-region-as-html
3405 org-export-as-html
))
3406 (org-autoload "org-docbook"
3407 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3408 org-replace-region-by-docbook org-export-region-as-docbook
3409 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3410 org-export-as-docbook
))
3411 (org-autoload "org-icalendar"
3412 '(org-export-icalendar-this-file
3413 org-export-icalendar-all-agenda-files
3414 org-export-icalendar-combine-agenda-files
))
3415 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3416 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3418 ;; Declare and autoload functions from org-agenda.el
3421 (org-autoload "org-agenda"
3422 '(org-agenda org-agenda-list org-search-view
3423 org-todo-list org-tags-view org-agenda-list-stuck-projects
3424 org-diary org-agenda-to-appt
3425 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3427 ;; Autoload org-remember
3430 (org-autoload "org-remember"
3431 '(org-remember-insinuate org-remember-annotation
3432 org-remember-apply-template org-remember org-remember-handler
)))
3434 ;; Autoload org-clock.el
3437 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3439 (declare-function org-clock-update-mode-line
"org-clock" ())
3440 (declare-function org-resolve-clocks
"org-clock"
3441 (&optional also-non-dangling-p prompt last-valid
))
3442 (defvar org-clock-start-time
)
3443 (defvar org-clock-marker
(make-marker)
3444 "Marker recording the last clock-in.")
3445 (defvar org-clock-hd-marker
(make-marker)
3446 "Marker recording the last clock-in, but the headline position.")
3447 (defvar org-clock-heading
""
3448 "The heading of the current clock entry.")
3449 (defun org-clock-is-active ()
3450 "Return non-nil if clock is currently running.
3451 The return value is actually the clock marker."
3452 (marker-buffer org-clock-marker
))
3457 '(org-clock-in org-clock-out org-clock-cancel
3458 org-clock-goto org-clock-sum org-clock-display
3459 org-clock-remove-overlays org-clock-report
3460 org-clocktable-shift org-dblock-write
:clocktable
3461 org-get-clocktable org-resolve-clocks
)))
3463 (defun org-clock-update-time-maybe ()
3464 "If this is a CLOCK line, update it and return t.
3465 Otherwise, return nil."
3468 (beginning-of-line 1)
3469 (skip-chars-forward " \t")
3470 (when (looking-at org-clock-string
)
3471 (let ((re (concat "[ \t]*" org-clock-string
3472 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3473 "\\([ \t]*=>.*\\)?\\)?"))
3476 ((not (looking-at re
))
3478 ((not (match-end 2))
3479 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3480 (> org-clock-marker
(point))
3481 (<= org-clock-marker
(point-at-eol)))
3482 ;; The clock is running here
3483 (setq org-clock-start-time
3485 (org-parse-time-string (match-string 1))))
3486 (org-clock-update-mode-line)))
3488 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3490 (setq ts
(match-string 1)
3491 te
(match-string 3))
3492 (setq s
(- (org-float-time
3493 (apply 'encode-time
(org-parse-time-string te
)))
3495 (apply 'encode-time
(org-parse-time-string ts
))))
3498 h
(floor (/ s
3600))
3502 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3505 (defun org-check-running-clock ()
3506 "Check if the current buffer contains the running clock.
3507 If yes, offer to stop it and to save the buffer with the changes."
3508 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3509 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3512 (when (y-or-n-p "Save changed buffer?")
3515 (defun org-clocktable-try-shift (dir n
)
3516 "Check if this line starts a clock table, if yes, shift the time block."
3517 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3518 (org-clocktable-shift dir n
)))
3520 ;; Autoload org-timer.el
3525 '(org-timer-start org-timer org-timer-item
3526 org-timer-change-times-in-region
3528 org-timer-reset-timers
3529 org-timer-show-remaining-time
)))
3531 ;; Autoload org-feed.el
3536 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3539 ;; Autoload org-indent.el
3541 ;; Define the variable already here, to make sure we have it.
3542 (defvar org-indent-mode nil
3543 "Non-nil if Org-Indent mode is enabled.
3544 Use the command `org-indent-mode' to change this variable.")
3549 '(org-indent-mode)))
3551 ;; Autoload org-mobile.el
3556 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3558 ;; Autoload archiving code
3559 ;; The stuff that is needed for cycling and tags has to be defined here.
3561 (defgroup org-archive nil
3562 "Options concerning archiving in Org-mode."
3564 :group
'org-structure
)
3566 (defcustom org-archive-location
"%s_archive::"
3567 "The location where subtrees should be archived.
3569 The value of this variable is a string, consisting of two parts,
3570 separated by a double-colon. The first part is a filename and
3571 the second part is a headline.
3573 When the filename is omitted, archiving happens in the same file.
3574 %s in the filename will be replaced by the current file
3575 name (without the directory part). Archiving to a different file
3576 is useful to keep archived entries from contributing to the
3579 The archived entries will be filed as subtrees of the specified
3580 headline. When the headline is omitted, the subtrees are simply
3581 filed away at the end of the file, as top-level entries. Also in
3582 the heading you can use %s to represent the file name, this can be
3583 useful when using the same archive for a number of different files.
3585 Here are a few examples:
3587 If the current file is Projects.org, archive in file
3588 Projects.org_archive, as top-level trees. This is the default.
3590 \"::* Archived Tasks\"
3591 Archive in the current file, under the top-level headline
3592 \"* Archived Tasks\".
3594 \"~/org/archive.org::\"
3595 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3597 \"~/org/archive.org::From %s\"
3598 Archive in file ~/org/archive.org (absolute path), under headlines
3599 \"From FILENAME\" where file name is the current file name.
3601 \"basement::** Finished Tasks\"
3602 Archive in file ./basement (relative path), as level 3 trees
3603 below the level 2 heading \"** Finished Tasks\".
3605 You may set this option on a per-file basis by adding to the buffer a
3608 #+ARCHIVE: basement::** Finished Tasks
3610 You may also define it locally for a subtree by setting an ARCHIVE property
3611 in the entry. If such a property is found in an entry, or anywhere up
3612 the hierarchy, it will be used."
3616 (defcustom org-archive-tag
"ARCHIVE"
3617 "The tag that marks a subtree as archived.
3618 An archived subtree does not open during visibility cycling, and does
3619 not contribute to the agenda listings.
3620 After changing this, font-lock must be restarted in the relevant buffers to
3621 get the proper fontification."
3623 :group
'org-keywords
3626 (defcustom org-agenda-skip-archived-trees t
3627 "Non-nil means the agenda will skip any items located in archived trees.
3628 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3629 variable is no longer recommended, you should leave it at the value t.
3630 Instead, use the key `v' to cycle the archives-mode in the agenda."
3632 :group
'org-agenda-skip
3635 (defcustom org-columns-skip-archived-trees t
3636 "Non-nil means ignore archived trees when creating column view."
3638 :group
'org-properties
3641 (defcustom org-cycle-open-archived-trees nil
3642 "Non-nil means `org-cycle' will open archived trees.
3643 An archived tree is a tree marked with the tag ARCHIVE.
3644 When nil, archived trees will stay folded. You can still open them with
3645 normal outline commands like `show-all', but not with the cycling commands."
3650 (defcustom org-sparse-tree-open-archived-trees nil
3651 "Non-nil means sparse tree construction shows matches in archived trees.
3652 When nil, matches in these trees are highlighted, but the trees are kept in
3655 :group
'org-sparse-trees
3658 (defun org-cycle-hide-archived-subtrees (state)
3659 "Re-hide all archived subtrees after a visibility state change."
3660 (when (and (not org-cycle-open-archived-trees
)
3661 (not (memq state
'(overview folded
))))
3663 (let* ((globalp (memq state
'(contents all
)))
3664 (beg (if globalp
(point-min) (point)))
3665 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3666 (org-hide-archived-subtrees beg end
)
3668 (if (looking-at (concat ".*:" org-archive-tag
":"))
3669 (message "%s" (substitute-command-keys
3670 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3672 (defun org-force-cycle-archived ()
3673 "Cycle subtree even if it is archived."
3675 (setq this-command
'org-cycle
)
3676 (let ((org-cycle-open-archived-trees t
))
3677 (call-interactively 'org-cycle
)))
3679 (defun org-hide-archived-subtrees (beg end
)
3680 "Re-hide all archived subtrees after a visibility state change."
3682 (let* ((re (concat ":" org-archive-tag
":")))
3684 (while (re-search-forward re end t
)
3685 (when (org-on-heading-p)
3686 (org-flag-subtree t
)
3687 (org-end-of-subtree t
))))))
3689 (defun org-flag-subtree (flag)
3691 (org-back-to-heading t
)
3692 (outline-end-of-heading)
3693 (outline-flag-region (point)
3694 (progn (org-end-of-subtree t
) (point))
3697 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3700 (org-autoload "org-archive"
3701 '(org-add-archive-files org-archive-subtree
3702 org-archive-to-archive-sibling org-toggle-archive-tag
3703 org-archive-subtree-default
3704 org-archive-subtree-default-with-confirmation
)))
3706 ;; Autoload Column View Code
3708 (declare-function org-columns-number-to-string
"org-colview")
3709 (declare-function org-columns-get-format-and-top-level
"org-colview")
3710 (declare-function org-columns-compute
"org-colview")
3712 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3713 '(org-columns-number-to-string org-columns-get-format-and-top-level
3714 org-columns-compute org-agenda-columns org-columns-remove-overlays
3715 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3719 (declare-function org-id-store-link
"org-id")
3720 (declare-function org-id-locations-load
"org-id")
3721 (declare-function org-id-locations-save
"org-id")
3722 (defvar org-id-track-globally
)
3723 (org-autoload "org-id"
3724 '(org-id-get-create org-id-new org-id-copy org-id-get
3725 org-id-get-with-outline-path-completion
3726 org-id-get-with-outline-drilling
3727 org-id-goto org-id-find org-id-store-link
))
3729 ;; Autoload Plotting Code
3731 (org-autoload "org-plot"
3732 '(org-plot/gnuplot
))
3734 ;;; Variables for pre-computed regular expressions, all buffer local
3736 (defvar org-drawer-regexp nil
3737 "Matches first line of a hidden block.")
3738 (make-variable-buffer-local 'org-drawer-regexp
)
3739 (defvar org-todo-regexp nil
3740 "Matches any of the TODO state keywords.")
3741 (make-variable-buffer-local 'org-todo-regexp
)
3742 (defvar org-not-done-regexp nil
3743 "Matches any of the TODO state keywords except the last one.")
3744 (make-variable-buffer-local 'org-not-done-regexp
)
3745 (defvar org-not-done-heading-regexp nil
3746 "Matches a TODO headline that is not done.")
3747 (make-variable-buffer-local 'org-not-done-regexp
)
3748 (defvar org-todo-line-regexp nil
3749 "Matches a headline and puts TODO state into group 2 if present.")
3750 (make-variable-buffer-local 'org-todo-line-regexp
)
3751 (defvar org-complex-heading-regexp nil
3752 "Matches a headline and puts everything into groups:
3754 group 2: The todo keyword, maybe
3755 group 3: Priority cookie
3756 group 4: True headline
3758 (make-variable-buffer-local 'org-complex-heading-regexp
)
3759 (defvar org-complex-heading-regexp-format nil
)
3760 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3761 (defvar org-todo-line-tags-regexp nil
3762 "Matches a headline and puts TODO state into group 2 if present.
3763 Also put tags into group 4 if tags are present.")
3764 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3765 (defvar org-nl-done-regexp nil
3766 "Matches newline followed by a headline with the DONE keyword.")
3767 (make-variable-buffer-local 'org-nl-done-regexp
)
3768 (defvar org-looking-at-done-regexp nil
3769 "Matches the DONE keyword a point.")
3770 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3771 (defvar org-ds-keyword-length
12
3772 "Maximum length of the Deadline and SCHEDULED keywords.")
3773 (make-variable-buffer-local 'org-ds-keyword-length
)
3774 (defvar org-deadline-regexp nil
3775 "Matches the DEADLINE keyword.")
3776 (make-variable-buffer-local 'org-deadline-regexp
)
3777 (defvar org-deadline-time-regexp nil
3778 "Matches the DEADLINE keyword together with a time stamp.")
3779 (make-variable-buffer-local 'org-deadline-time-regexp
)
3780 (defvar org-deadline-line-regexp nil
3781 "Matches the DEADLINE keyword and the rest of the line.")
3782 (make-variable-buffer-local 'org-deadline-line-regexp
)
3783 (defvar org-scheduled-regexp nil
3784 "Matches the SCHEDULED keyword.")
3785 (make-variable-buffer-local 'org-scheduled-regexp
)
3786 (defvar org-scheduled-time-regexp nil
3787 "Matches the SCHEDULED keyword together with a time stamp.")
3788 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3789 (defvar org-closed-time-regexp nil
3790 "Matches the CLOSED keyword together with a time stamp.")
3791 (make-variable-buffer-local 'org-closed-time-regexp
)
3793 (defvar org-keyword-time-regexp nil
3794 "Matches any of the 4 keywords, together with the time stamp.")
3795 (make-variable-buffer-local 'org-keyword-time-regexp
)
3796 (defvar org-keyword-time-not-clock-regexp nil
3797 "Matches any of the 3 keywords, together with the time stamp.")
3798 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
3799 (defvar org-maybe-keyword-time-regexp nil
3800 "Matches a timestamp, possibly preceeded by a keyword.")
3801 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
3802 (defvar org-planning-or-clock-line-re nil
3803 "Matches a line with planning or clock info.")
3804 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
3805 (defvar org-all-time-keywords nil
3806 "List of time keywords.")
3807 (make-variable-buffer-local 'org-all-time-keywords
)
3809 (defconst org-plain-time-of-day-regexp
3812 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3815 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3817 "Regular expression to match a plain time or time range.
3818 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3819 groups carry important information:
3821 1 the first time, range or not
3822 8 the second time, if it is a range.")
3824 (defconst org-plain-time-extension-regexp
3827 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3828 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3829 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3830 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3831 groups carry important information:
3834 9 minutes of duration")
3836 (defconst org-stamp-time-of-day-regexp
3838 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3839 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3841 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3842 "Regular expression to match a timestamp time or time range.
3843 After a match, the following groups carry important information:
3845 1 date plus weekday, for back referencing to make sure both times are on the same day
3846 2 the first time, range or not
3847 4 the second time, if it is a range.")
3849 (defconst org-startup-options
3850 '(("fold" org-startup-folded t
)
3851 ("overview" org-startup-folded t
)
3852 ("nofold" org-startup-folded nil
)
3853 ("showall" org-startup-folded nil
)
3854 ("showeverything" org-startup-folded showeverything
)
3855 ("content" org-startup-folded content
)
3856 ("indent" org-startup-indented t
)
3857 ("noindent" org-startup-indented nil
)
3858 ("hidestars" org-hide-leading-stars t
)
3859 ("showstars" org-hide-leading-stars nil
)
3860 ("odd" org-odd-levels-only t
)
3861 ("oddeven" org-odd-levels-only nil
)
3862 ("align" org-startup-align-all-tables t
)
3863 ("noalign" org-startup-align-all-tables nil
)
3864 ("customtime" org-display-custom-times t
)
3865 ("logdone" org-log-done time
)
3866 ("lognotedone" org-log-done note
)
3867 ("nologdone" org-log-done nil
)
3868 ("lognoteclock-out" org-log-note-clock-out t
)
3869 ("nolognoteclock-out" org-log-note-clock-out nil
)
3870 ("logrepeat" org-log-repeat state
)
3871 ("lognoterepeat" org-log-repeat note
)
3872 ("nologrepeat" org-log-repeat nil
)
3873 ("logreschedule" org-log-reschedule time
)
3874 ("lognotereschedule" org-log-reschedule note
)
3875 ("nologreschedule" org-log-reschedule nil
)
3876 ("logredeadline" org-log-redeadline time
)
3877 ("lognoteredeadline" org-log-redeadline note
)
3878 ("nologredeadline" org-log-redeadline nil
)
3879 ("logrefile" org-log-refile time
)
3880 ("lognoterefile" org-log-refile note
)
3881 ("nologrefile" org-log-refile nil
)
3882 ("fninline" org-footnote-define-inline t
)
3883 ("nofninline" org-footnote-define-inline nil
)
3884 ("fnlocal" org-footnote-section nil
)
3885 ("fnauto" org-footnote-auto-label t
)
3886 ("fnprompt" org-footnote-auto-label nil
)
3887 ("fnconfirm" org-footnote-auto-label confirm
)
3888 ("fnplain" org-footnote-auto-label plain
)
3889 ("fnadjust" org-footnote-auto-adjust t
)
3890 ("nofnadjust" org-footnote-auto-adjust nil
)
3891 ("constcgs" constants-unit-system cgs
)
3892 ("constSI" constants-unit-system SI
)
3893 ("noptag" org-tag-persistent-alist nil
)
3894 ("hideblocks" org-hide-block-startup t
)
3895 ("nohideblocks" org-hide-block-startup nil
)
3896 ("beamer" org-startup-with-beamer-mode t
))
3897 "Variable associated with STARTUP options for org-mode.
3898 Each element is a list of three items: The startup options as written
3899 in the #+STARTUP line, the corresponding variable, and the value to
3900 set this variable to if the option is found. An optional forth element PUSH
3901 means to push this value onto the list in the variable.")
3903 (defun org-set-regexps-and-options ()
3904 "Precompute regular expressions for current buffer."
3906 (org-set-local 'org-todo-kwd-alist nil
)
3907 (org-set-local 'org-todo-key-alist nil
)
3908 (org-set-local 'org-todo-key-trigger nil
)
3909 (org-set-local 'org-todo-keywords-1 nil
)
3910 (org-set-local 'org-done-keywords nil
)
3911 (org-set-local 'org-todo-heads nil
)
3912 (org-set-local 'org-todo-sets nil
)
3913 (org-set-local 'org-todo-log-states nil
)
3914 (org-set-local 'org-file-properties nil
)
3915 (org-set-local 'org-file-tags nil
)
3916 (let ((re (org-make-options-regexp
3917 '("CATEGORY" "TODO" "COLUMNS"
3918 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
3919 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS")
3920 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
3922 kwds kws0 kwsa key log value cat arch tags const links hw dws
3923 tail sep kws1 prio props ftags drawers beamer-p
3924 ext-setup-or-nil setup-contents
(start 0))
3928 (goto-char (point-min))
3929 (while (or (and ext-setup-or-nil
3930 (string-match re ext-setup-or-nil start
)
3931 (setq start
(match-end 0)))
3932 (and (setq ext-setup-or-nil nil start
0)
3933 (re-search-forward re nil t
)))
3934 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
3935 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
3937 ((equal key
"CATEGORY")
3938 (if (string-match "[ \t]+$" value
)
3939 (setq value
(replace-match "" t t value
)))
3941 ((member key
'("SEQ_TODO" "TODO"))
3942 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
3943 ((equal key
"TYP_TODO")
3944 (push (cons 'type
(org-split-string value splitre
)) kwds
))
3945 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
3946 ;; general TODO-like setup
3947 (push (cons (intern (downcase (match-string 1 key
)))
3948 (org-split-string value splitre
)) kwds
))
3950 (setq tags
(append tags
(if tags
'("\\n") nil
)
3951 (org-split-string value splitre
))))
3952 ((equal key
"COLUMNS")
3953 (org-set-local 'org-columns-default-format value
))
3955 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
3956 (push (cons (match-string 1 value
)
3957 (org-trim (match-string 2 value
)))
3959 ((equal key
"PRIORITIES")
3960 (setq prio
(org-split-string value
" +")))
3961 ((equal key
"PROPERTY")
3962 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
3963 (push (cons (match-string 1 value
) (match-string 2 value
))
3965 ((equal key
"FILETAGS")
3966 (when (string-match "\\S-" value
)
3971 (mapcar (lambda (x) (org-split-string x
":"))
3972 (org-split-string value
)))))))
3973 ((equal key
"DRAWERS")
3974 (setq drawers
(org-split-string value splitre
)))
3975 ((equal key
"CONSTANTS")
3976 (setq const
(append const
(org-split-string value splitre
))))
3977 ((equal key
"STARTUP")
3978 (let ((opts (org-split-string value splitre
))
3980 (while (setq l
(pop opts
))
3981 (when (setq l
(assoc l org-startup-options
))
3982 (setq var
(nth 1 l
) val
(nth 2 l
))
3984 (set (make-local-variable var
) val
)
3985 (if (not (listp (symbol-value var
)))
3986 (set (make-local-variable var
) nil
))
3987 (set (make-local-variable var
) (symbol-value var
))
3988 (add-to-list var val
))))))
3989 ((equal key
"ARCHIVE")
3990 (string-match " *$" value
)
3991 (setq arch
(replace-match "" t t value
))
3992 (remove-text-properties 0 (length arch
)
3993 '(face t fontified t
) arch
))
3994 ((equal key
"LATEX_CLASS")
3995 (setq beamer-p
(equal value
"beamer")))
3996 ((equal key
"SETUPFILE")
3997 (setq setup-contents
(org-file-contents
3999 (org-remove-double-quotes value
))
4001 (if (not ext-setup-or-nil
)
4002 (setq ext-setup-or-nil setup-contents start
0)
4003 (setq ext-setup-or-nil
4004 (concat (substring ext-setup-or-nil
0 start
)
4005 "\n" setup-contents
"\n"
4006 (substring ext-setup-or-nil start
)))))
4009 (org-set-local 'org-category
(intern cat
))
4010 (push (cons "CATEGORY" cat
) props
))
4012 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4013 (setq prio
(mapcar 'string-to-char prio
))
4014 (org-set-local 'org-highest-priority
(nth 0 prio
))
4015 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4016 (org-set-local 'org-default-priority
(nth 2 prio
)))
4017 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4018 (and ftags
(org-set-local 'org-file-tags
4019 (mapcar 'org-add-prop-inherited ftags
)))
4020 (and drawers
(org-set-local 'org-drawers drawers
))
4021 (and arch
(org-set-local 'org-archive-location arch
))
4022 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4023 ;; Process the TODO keywords
4025 ;; Use the global values as if they had been given locally.
4026 (setq kwds
(default-value 'org-todo-keywords
))
4027 (if (stringp (car kwds
))
4028 (setq kwds
(list (cons org-todo-interpretation
4029 (default-value 'org-todo-keywords
)))))
4030 (setq kwds
(reverse kwds
)))
4031 (setq kwds
(nreverse kwds
))
4033 (while (setq kws
(pop kwds
))
4035 (run-hook-with-args-until-success
4036 'org-todo-setup-filter-hook kws
)
4038 (setq inter
(pop kws
) sep
(member "|" kws
)
4039 kws0
(delete "|" (copy-sequence kws
))
4044 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4046 (setq kw
(match-string 1 x
)
4047 key
(and (match-end 2) (match-string 2 x
))
4048 log
(org-extract-log-state-settings x
))
4049 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4050 (and log
(push log org-todo-log-states
))
4052 (error "Invalid TODO keyword %s" x
)))
4054 kwsa
(if kwsa
(append '((:startgroup
))
4058 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4059 tail
(list inter hw
(car dws
) (org-last dws
))))
4060 (add-to-list 'org-todo-heads hw
'append
)
4061 (push kws1 org-todo-sets
)
4062 (setq org-done-keywords
(append org-done-keywords dws nil
))
4063 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4064 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4065 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4066 (setq org-todo-sets
(nreverse org-todo-sets
)
4067 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4068 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4069 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4070 ;; Process the constants
4073 (while (setq e
(pop const
))
4074 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4075 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4076 (setq org-table-formula-constants-local cst
)))
4078 ;; Process the tags.
4081 (while (setq e
(pop tags
))
4083 ((equal e
"{") (push '(:startgroup
) tgs
))
4084 ((equal e
"}") (push '(:endgroup
) tgs
))
4085 ((equal e
"\\n") (push '(:newline
) tgs
))
4086 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4087 (push (cons (match-string 1 e
)
4088 (string-to-char (match-string 2 e
)))
4090 (t (push (list e
) tgs
))))
4091 (org-set-local 'org-tag-alist nil
)
4092 (while (setq e
(pop tgs
))
4093 (or (and (stringp (car e
))
4094 (assoc (car e
) org-tag-alist
))
4095 (push e org-tag-alist
)))))
4097 ;; Compute the regular expressions and other local variables
4098 (if (not org-done-keywords
)
4099 (setq org-done-keywords
(and org-todo-keywords-1
4100 (list (org-last org-todo-keywords-1
)))))
4101 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4102 (length org-scheduled-string
)
4103 (length org-clock-string
)
4104 (length org-closed-string
)))
4106 (concat "^[ \t]*:\\("
4107 (mapconcat 'regexp-quote org-drawers
"\\|")
4109 org-not-done-keywords
4110 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4112 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4116 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4118 org-not-done-heading-regexp
4119 (concat "^\\(\\*+\\)[ \t]+\\("
4120 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4122 org-todo-line-regexp
4123 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4124 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4125 "\\)\\>\\)?[ \t]*\\(.*\\)")
4126 org-complex-heading-regexp
4127 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4128 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4129 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4130 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4131 org-complex-heading-regexp-format
4132 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4133 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4134 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(%s\\)"
4135 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4137 (concat "\n\\*+[ \t]+"
4138 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4140 org-todo-line-tags-regexp
4141 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4142 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4144 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4145 org-looking-at-done-regexp
4147 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4149 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4150 org-deadline-time-regexp
4151 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4152 org-deadline-line-regexp
4153 (concat "\\<\\(" org-deadline-string
"\\).*")
4154 org-scheduled-regexp
4155 (concat "\\<" org-scheduled-string
)
4156 org-scheduled-time-regexp
4157 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4158 org-closed-time-regexp
4159 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4160 org-keyword-time-regexp
4161 (concat "\\<\\(" org-scheduled-string
4162 "\\|" org-deadline-string
4163 "\\|" org-closed-string
4164 "\\|" org-clock-string
"\\)"
4165 " *[[<]\\([^]>]+\\)[]>]")
4166 org-keyword-time-not-clock-regexp
4167 (concat "\\<\\(" org-scheduled-string
4168 "\\|" org-deadline-string
4169 "\\|" org-closed-string
4171 " *[[<]\\([^]>]+\\)[]>]")
4172 org-maybe-keyword-time-regexp
4173 (concat "\\(\\<\\(" org-scheduled-string
4174 "\\|" org-deadline-string
4175 "\\|" org-closed-string
4176 "\\|" org-clock-string
"\\)\\)?"
4177 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4178 org-planning-or-clock-line-re
4179 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4180 "\\|" org-deadline-string
4181 "\\|" org-closed-string
"\\|" org-clock-string
4183 org-all-time-keywords
4184 (mapcar (lambda (w) (substring w
0 -
1))
4185 (list org-scheduled-string org-deadline-string
4186 org-clock-string org-closed-string
))
4188 (org-compute-latex-and-specials-regexp)
4189 (org-set-font-lock-defaults))))
4191 (defun org-file-contents (file &optional noerror
)
4192 "Return the contents of FILE, as a string."
4194 (not (file-readable-p file
)))
4197 (message "Cannot read file %s" file
)
4200 (error "Cannot read file %s" file
))
4202 (insert-file-contents file
)
4205 (defun org-extract-log-state-settings (x)
4206 "Extract the log state setting from a TODO keyword string.
4207 This will extract info from a string like \"WAIT(w@/!)\"."
4208 (let (kw key log1 log2
)
4209 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4210 (setq kw
(match-string 1 x
)
4211 key
(and (match-end 2) (match-string 2 x
))
4212 log1
(and (match-end 3) (match-string 3 x
))
4213 log2
(and (match-end 4) (match-string 4 x
)))
4216 (and log1
(if (equal log1
"!") 'time
'note
))
4217 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4219 (defun org-remove-keyword-keys (list)
4220 "Remove a pair of parenthesis at the end of each string in LIST."
4222 (if (string-match "(.*)$" x
)
4223 (substring x
0 (match-beginning 0))
4227 (defun org-assign-fast-keys (alist)
4228 "Assign fast keys to a keyword-key alist.
4229 Respect keys that are already there."
4230 (let (new e
(alt ?
0))
4231 (while (setq e
(pop alist
))
4232 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4233 (cdr e
)) ;; Key already assigned.
4235 (let ((clist (string-to-list (downcase (car e
))))
4236 (used (append new alist
)))
4237 (when (= (car clist
) ?
@)
4239 (while (and clist
(rassoc (car clist
) used
))
4242 (while (rassoc alt used
)
4244 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4247 ;;; Some variables used in various places
4249 (defvar org-window-configuration nil
4250 "Used in various places to store a window configuration.")
4251 (defvar org-selected-window nil
4252 "Used in various places to store a window configuration.")
4253 (defvar org-finish-function nil
4254 "Function to be called when `C-c C-c' is used.
4255 This is for getting out of special buffers like remember.")
4258 ;; FIXME: Occasionally check by commenting these, to make sure
4259 ;; no other functions uses these, forgetting to let-bind them.
4264 ;; Defined somewhere in this file, but used before definition.
4265 (defvar org-entities
) ;; defined in org-entities.el
4266 (defvar org-struct-menu
)
4267 (defvar org-org-menu
)
4268 (defvar org-tbl-menu
)
4270 ;;;; Define the Org-mode
4272 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4273 (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."))
4276 ;; We use a before-change function to check if a table might need
4278 (defvar org-table-may-need-update t
4279 "Indicates that a table might need an update.
4280 This variable is set by `org-before-change-function'.
4281 `org-table-align' sets it back to nil.")
4282 (defun org-before-change-function (beg end
)
4283 "Every change indicates that a table might need an update."
4284 (setq org-table-may-need-update t
))
4285 (defvar org-mode-map
)
4286 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4287 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4288 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4289 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4290 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4291 (defvar org-table-buffer-is-an nil
)
4292 (defconst org-outline-regexp
"\\*+ ")
4295 (define-derived-mode org-mode outline-mode
"Org"
4296 "Outline-based notes management and organizer, alias
4297 \"Carsten's outline-mode for keeping track of everything.\"
4299 Org-mode develops organizational tasks around a NOTES file which
4300 contains information about projects as plain text. Org-mode is
4301 implemented on top of outline-mode, which is ideal to keep the content
4302 of large files well structured. It supports ToDo items, deadlines and
4303 time stamps, which magically appear in the diary listing of the Emacs
4304 calendar. Tables are easily created with a built-in table editor.
4305 Plain text URL-like links connect to websites, emails (VM), Usenet
4306 messages (Gnus), BBDB entries, and any files related to the project.
4307 For printing and sharing of notes, an Org-mode file (or a part of it)
4308 can be exported as a structured ASCII or HTML file.
4310 The following commands are available:
4314 ;; Get rid of Outline menus, they are not needed
4315 ;; Need to do this here because define-derived-mode sets up
4316 ;; the keymap so late. Still, it is a waste to call this each time
4317 ;; we switch another buffer into org-mode.
4318 (if (featurep 'xemacs
)
4319 (when (boundp 'outline-mode-menu-heading
)
4320 ;; Assume this is Greg's port, it used easymenu
4321 (easy-menu-remove outline-mode-menu-heading
)
4322 (easy-menu-remove outline-mode-menu-show
)
4323 (easy-menu-remove outline-mode-menu-hide
))
4324 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4325 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4326 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4328 (org-load-modules-maybe)
4329 (easy-menu-add org-org-menu
)
4330 (easy-menu-add org-tbl-menu
)
4331 (org-install-agenda-files-menu)
4332 (if org-descriptive-links
(org-add-to-invisibility-spec '(org-link)))
4333 (org-add-to-invisibility-spec '(org-cwidth))
4334 (org-add-to-invisibility-spec '(org-hide-block . t
))
4335 (when (featurep 'xemacs
)
4336 (org-set-local 'line-move-ignore-invisible t
))
4337 (org-set-local 'outline-regexp org-outline-regexp
)
4338 (org-set-local 'outline-level
'org-outline-level
)
4339 (when (and org-ellipsis
4340 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4341 (fboundp 'make-glyph-code
))
4342 (unless org-display-table
4343 (setq org-display-table
(make-display-table)))
4344 (set-display-table-slot
4347 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4349 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4350 (setq buffer-display-table org-display-table
))
4351 (org-set-regexps-and-options)
4352 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4353 ;; tag faces set outside customize.... force initialization.
4354 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4356 (org-set-local 'calc-embedded-open-mode
"# ")
4357 (modify-syntax-entry ?
# "<")
4358 (modify-syntax-entry ?
@ "w")
4359 (if org-startup-truncated
(setq truncate-lines t
))
4360 (org-set-local 'font-lock-unfontify-region-function
4361 'org-unfontify-region
)
4362 ;; Activate before-change-function
4363 (org-set-local 'org-table-may-need-update t
)
4364 (org-add-hook 'before-change-functions
'org-before-change-function nil
4366 ;; Check for running clock before killing a buffer
4367 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4368 ;; Paragraphs and auto-filling
4369 (org-set-autofill-regexps)
4370 (setq indent-line-function
'org-indent-line-function
)
4371 (org-update-radio-target-regexp)
4372 ;; Make sure dependence stuff works reliably, even for users who set it
4374 (if org-enforce-todo-dependencies
4375 (add-hook 'org-blocker-hook
4376 'org-block-todo-from-children-or-siblings-or-parent
)
4377 (remove-hook 'org-blocker-hook
4378 'org-block-todo-from-children-or-siblings-or-parent
))
4379 (if org-enforce-todo-checkbox-dependencies
4380 (add-hook 'org-blocker-hook
4381 'org-block-todo-from-checkboxes
)
4382 (remove-hook 'org-blocker-hook
4383 'org-block-todo-from-checkboxes
))
4385 ;; Comment characters
4386 ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
4387 (org-set-local 'comment-padding
" ")
4389 ;; Align options lines
4391 'align-mode-rules-list
4392 '((org-in-buffer-settings
4393 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4394 (modes .
'(org-mode)))))
4397 (org-set-local 'imenu-create-index-function
4398 'org-imenu-get-tree
)
4400 ;; Make isearch reveal context
4401 (if (or (featurep 'xemacs
)
4402 (not (boundp 'outline-isearch-open-invisible-function
)))
4403 ;; Emacs 21 and XEmacs make use of the hook
4404 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4405 ;; Emacs 22 deals with this through a special variable
4406 (org-set-local 'outline-isearch-open-invisible-function
4407 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4409 ;; Turn on org-beamer-mode?
4410 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4412 ;; If empty file that did not turn on org-mode automatically, make it to.
4413 (if (and org-insert-mode-line-in-empty-file
4415 (= (point-min) (point-max)))
4416 (insert "# -*- mode: org -*-\n\n"))
4417 (unless org-inhibit-startup
4418 (when org-startup-align-all-tables
4419 (let ((bmp (buffer-modified-p)))
4420 (org-table-map-tables 'org-table-align
)
4421 (set-buffer-modified-p bmp
)))
4422 (when org-startup-indented
4423 (require 'org-indent
)
4424 (org-indent-mode 1))
4425 (unless org-inhibit-startup-visibility-stuff
4426 (org-set-startup-visibility))))
4428 (when (fboundp 'abbrev-table-put
)
4429 (abbrev-table-put org-mode-abbrev-table
4430 :parents
(list text-mode-abbrev-table
)))
4432 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4434 (defun org-current-time ()
4435 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4436 (if (> (car org-time-stamp-rounding-minutes
) 1)
4437 (let ((r (car org-time-stamp-rounding-minutes
))
4438 (time (decode-time)))
4440 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4444 ;;;; Font-Lock stuff, including the activators
4446 (defvar org-mouse-map
(make-sparse-keymap))
4447 (org-defkey org-mouse-map
4448 (if (featurep 'xemacs
) [button2] [mouse-2]) 'org-open-at-mouse)
4449 (org-defkey org-mouse-map
4450 (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
4451 (when org-mouse-1-follows-link
4452 (org-defkey org-mouse-map [follow-link] 'mouse-face))
4453 (when org-tab-follows-link
4454 (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
4455 (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
4457 (require 'font-lock)
4459 (defconst org-non-link-chars "]\t\n\r<>")
4460 (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
4462 (defvar org-link-types-re nil
4463 "Matches a link that has a url-like prefix like \"http:\"")
4464 (defvar org-link-re-with-space nil
4465 "Matches a link with spaces, optional angular brackets around it.")
4466 (defvar org-link-re-with-space2 nil
4467 "Matches a link with spaces, optional angular brackets around it.")
4468 (defvar org-link-re-with-space3 nil
4469 "Matches a link with spaces, only for internal part in bracket links.")
4470 (defvar org-angle-link-re nil
4471 "Matches link with angular brackets, spaces are allowed.")
4472 (defvar org-plain-link-re nil
4473 "Matches plain link, without spaces.")
4474 (defvar org-bracket-link-regexp nil
4475 "Matches a link in double brackets.")
4476 (defvar org-bracket-link-analytic-regexp nil
4477 "Regular expression used to analyze links.
4478 Here is what the match groups contain after a match:
4484 (defvar org-bracket-link-analytic-regexp++ nil
4485 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4486 (defvar org-any-link-re nil
4487 "Regular expression matching any link.")
4489 (defun org-make-link-regexps ()
4490 "Update the link regular expressions.
4491 This should be called after the variable `org-link-types' has changed."
4492 (setq org-link-types-re
4494 "\\`\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):")
4495 org-link-re-with-space
4497 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4498 "\\([^" org-non-link-chars " ]"
4499 "[^" org-non-link-chars "]*"
4500 "[^" org-non-link-chars " ]\\)>?")
4501 org-link-re-with-space2
4503 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4504 "\\([^" org-non-link-chars " ]"
4506 "[^" org-non-link-chars " ]\\)>?")
4507 org-link-re-with-space3
4509 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4510 "\\([^" org-non-link-chars " ]"
4514 "<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4515 "\\([^" org-non-link-chars " ]"
4516 "[^" org-non-link-chars "]*"
4520 "\\<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4521 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4522 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4523 org-bracket-link-regexp
4524 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4525 org-bracket-link-analytic-regexp
4528 "\\(\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):\\)?"
4531 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4533 org-bracket-link-analytic-regexp++
4536 "\\(\\(" (mapconcat 'regexp-quote (cons "coderef" org-link-types) "\\|") "\\):\\)?"
4539 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4542 (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
4543 org-angle-link-re "\\)\\|\\("
4544 org-plain-link-re "\\)")))
4546 (org-make-link-regexps)
4548 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4549 "Regular expression for fast time stamp matching.")
4550 (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4551 "Regular expression for fast time stamp matching.")
4552 (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4553 "Regular expression matching time strings for analysis.
4554 This one does not require the space after the date, so it can be used
4555 on a string that terminates immediately after the date.")
4556 (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4557 "Regular expression matching time strings for analysis.")
4558 (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
4559 "Regular expression matching time stamps, with groups.")
4560 (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
4561 "Regular expression matching time stamps (also [..]), with groups.")
4562 (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
4563 "Regular expression matching a time stamp range.")
4564 (defconst org-tr-regexp-both
4565 (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
4566 "Regular expression matching a time stamp range.")
4567 (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
4568 org-ts-regexp "\\)?")
4569 "Regular expression matching a time stamp or time stamp range.")
4570 (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
4571 org-ts-regexp-both "\\)?")
4572 "Regular expression matching a time stamp or time stamp range.
4573 The time stamps may be either active or inactive.")
4575 (defvar org-emph-face nil)
4577 (defun org-do-emphasis-faces (limit)
4578 "Run through the buffer and add overlays to links."
4580 (while (and (not rtn) (re-search-forward org-emph-re limit t))
4581 (if (not (= (char-after (match-beginning 3))
4582 (char-after (match-beginning 4))))
4585 (setq a (assoc (match-string 3) org-emphasis-alist))
4586 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4590 (org-remove-flyspell-overlays-in
4591 (match-beginning 0) (match-end 0)))
4592 (add-text-properties (match-beginning 2) (match-end 2)
4593 '(font-lock-multiline t))
4594 (when org-hide-emphasis-markers
4595 (add-text-properties (match-end 4) (match-beginning 5)
4596 '(invisible org-link))
4597 (add-text-properties (match-beginning 3) (match-end 3)
4598 '(invisible org-link)))))
4602 (defun org-emphasize (&optional char)
4603 "Insert or change an emphasis, i.e. a font like bold or italic.
4604 If there is an active region, change that region to a new emphasis.
4605 If there is no region, just insert the marker characters and position
4606 the cursor between them.
4607 CHAR should be either the marker character, or the first character of the
4608 HTML tag associated with that emphasis. If CHAR is a space, the means
4609 to remove the emphasis of the selected region.
4610 If char is not given (for example in an interactive call) it
4611 will be prompted for."
4613 (let ((eal org-emphasis-alist) e det
4614 (erc org-emphasis-regexp-components)
4616 (string "") beg end move tag c s)
4617 (if (org-region-active-p)
4618 (setq beg (region-beginning) end (region-end)
4619 string (buffer-substring beg end))
4622 (while (setq e (pop eal))
4623 (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
4625 (push (cons c (string-to-char (car e))) det)
4626 (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
4627 (substring tag 1)))))
4628 (setq det (nreverse det))
4630 (message "%s" (concat "Emphasis marker or tag:" prompt))
4631 (setq char (read-char-exclusive)))
4632 (setq char (or (cdr (assoc char det)) char))
4633 (if (equal char ?\ )
4634 (setq s "" move nil)
4635 (unless (assoc (char-to-string char) org-emphasis-alist)
4636 (error "No such emphasis marker: \"%c\"" char))
4637 (setq s (char-to-string char)))
4638 (while (and (> (length string) 1)
4639 (equal (substring string 0 1) (substring string -1))
4640 (assoc (substring string 0 1) org-emphasis-alist))
4641 (setq string (substring string 1 -1)))
4642 (setq string (concat s string s))
4643 (if beg (delete-region beg end))
4645 (string-match (concat "[" (nth 0 erc) "\n]")
4646 (char-to-string (char-before (point)))))
4649 (string-match (concat "[" (nth 1 erc) "\n]")
4650 (char-to-string (char-after (point)))))
4651 (insert " ") (backward-char 1))
4653 (and move (backward-char 1))))
4655 (defconst org-nonsticky-props
4656 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
4658 (defsubst org-rear-nonsticky-at (pos)
4659 (add-text-properties (1- pos) pos (list 'rear-nonsticky org-nonsticky-props)))
4661 (defun org-activate-plain-links (limit)
4662 "Run through the buffer and add overlays to links."
4665 (if (re-search-forward org-plain-link-re limit t)
4667 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4668 (setq f (get-text-property (match-beginning 0) 'face))
4669 (if (or (eq f 'org-tag)
4670 (and (listp f) (memq 'org-tag f)))
4672 (add-text-properties (match-beginning 0) (match-end 0)
4673 (list 'mouse-face 'highlight
4675 'keymap org-mouse-map))
4676 (org-rear-nonsticky-at (match-end 0)))
4679 (defun org-activate-code (limit)
4680 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
4682 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4683 (remove-text-properties (match-beginning 0) (match-end 0)
4684 '(display t invisible t intangible t))
4687 (defun org-fontify-meta-lines-and-blocks (limit)
4688 "Fontify #+ lines and blocks, in the correct ways."
4689 (let ((case-fold-search t))
4690 (if (re-search-forward
4691 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4693 (let ((beg (match-beginning 0))
4694 (beg1 (line-beginning-position 2))
4695 (dc1 (downcase (match-string 2)))
4696 (dc3 (downcase (match-string 3)))
4697 end end1 quoting block-type)
4699 ((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
4700 ;; a single line of backend-specific content
4701 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4702 (remove-text-properties (match-beginning 0) (match-end 0)
4703 '(display t invisible t intangible t))
4704 (add-text-properties (match-beginning 1) (match-end 3)
4705 '(font-lock-fontified t face org-meta-line))
4706 (add-text-properties (match-beginning 6) (match-end 6)
4707 '(font-lock-fontified t face org-block))
4709 ((and (match-end 4) (equal dc3 "begin"))
4711 (setq block-type (downcase (match-string 5))
4712 quoting (member block-type org-protecting-blocks))
4713 (when (re-search-forward
4714 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4715 nil t) ;; on purpose, we look further than LIMIT
4716 (setq end (match-end 0) end1 (1- (match-beginning 0)))
4718 (remove-text-properties beg end
4719 '(display t invisible t intangible t)))
4720 (add-text-properties
4722 '(font-lock-fontified t font-lock-multiline t))
4723 (add-text-properties beg beg1 '(face org-meta-line))
4724 (add-text-properties end1 end '(face org-meta-line))
4727 (add-text-properties beg1 end1 '(face org-block)))
4728 ((not org-fontify-quote-and-verse-blocks))
4729 ((string= block-type "quote")
4730 (add-text-properties beg1 end1 '(face org-quote)))
4731 ((string= block-type "verse")
4732 (add-text-properties beg1 end1 '(face org-verse))))
4734 ((member dc1 '("title:" "author:" "email:" "date:"))
4735 (add-text-properties
4737 (if (member (intern (substring dc1 0 -1)) org-hidden-keywords)
4738 '(font-lock-fontified t invisible t)
4739 '(font-lock-fontified t face org-document-info-keyword)))
4740 (add-text-properties
4741 (match-beginning 6) (match-end 6)
4742 (if (string-equal dc1 "title:")
4743 '(font-lock-fontified t face org-document-title)
4744 '(font-lock-fontified t face org-document-info))))
4745 ((not (member (char-after beg) '(?\ ?\t)))
4746 ;; just any other in-buffer setting, but not indented
4747 (add-text-properties
4749 '(font-lock-fontified t face org-meta-line))
4751 ((or (member dc1 '("begin:" "end:" "caption:" "label:"
4752 "orgtbl:" "tblfm:" "tblname:"))
4753 (and (match-end 4) (equal dc3 "attr")))
4754 (add-text-properties
4756 '(font-lock-fontified t face org-meta-line))
4758 ((member dc3 '(" " ""))
4759 (add-text-properties
4761 '(font-lock-fontified t face font-lock-comment-face)))
4764 (defun org-activate-angle-links (limit)
4765 "Run through the buffer and add overlays to links."
4766 (if (re-search-forward org-angle-link-re limit t)
4768 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4769 (add-text-properties (match-beginning 0) (match-end 0)
4770 (list 'mouse-face 'highlight
4771 'keymap org-mouse-map))
4772 (org-rear-nonsticky-at (match-end 0))
4775 (defun org-activate-footnote-links (limit)
4776 "Run through the buffer and add overlays to links."
4777 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
4780 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4781 (add-text-properties (match-beginning 2) (match-end 2)
4782 (list 'mouse-face 'highlight
4783 'keymap org-mouse-map
4785 (if (= (point-at-bol) (match-beginning 2))
4786 "Footnote definition"
4787 "Footnote reference")
4789 (org-rear-nonsticky-at (match-end 2))
4792 (defun org-activate-bracket-links (limit)
4793 "Run through the buffer and add overlays to bracketed links."
4794 (if (re-search-forward org-bracket-link-regexp limit t)
4795 (let* ((help (concat "LINK: "
4796 (org-match-string-no-properties 1)))
4797 ;; FIXME: above we should remove the escapes.
4798 ;; but that requires another match, protecting match data,
4799 ;; a lot of overhead for font-lock.
4800 (ip (org-maybe-intangible
4801 (list 'invisible 'org-link
4802 'keymap org-mouse-map 'mouse-face 'highlight
4803 'font-lock-multiline t 'help-echo help)))
4804 (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
4805 'font-lock-multiline t 'help-echo help)))
4806 ;; We need to remove the invisible property here. Table narrowing
4807 ;; may have made some of this invisible.
4808 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4809 (remove-text-properties (match-beginning 0) (match-end 0)
4813 (add-text-properties (match-beginning 0) (match-beginning 3) ip)
4814 (org-rear-nonsticky-at (match-beginning 3))
4815 (add-text-properties (match-beginning 3) (match-end 3) vp)
4816 (org-rear-nonsticky-at (match-end 3))
4817 (add-text-properties (match-end 3) (match-end 0) ip)
4818 (org-rear-nonsticky-at (match-end 0)))
4819 (add-text-properties (match-beginning 0) (match-beginning 1) ip)
4820 (org-rear-nonsticky-at (match-beginning 1))
4821 (add-text-properties (match-beginning 1) (match-end 1) vp)
4822 (org-rear-nonsticky-at (match-end 1))
4823 (add-text-properties (match-end 1) (match-end 0) ip)
4824 (org-rear-nonsticky-at (match-end 0)))
4827 (defun org-activate-dates (limit)
4828 "Run through the buffer and add overlays to dates."
4829 (if (re-search-forward org-tsr-regexp-both limit t)
4831 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4832 (add-text-properties (match-beginning 0) (match-end 0)
4833 (list 'mouse-face 'highlight
4834 'keymap org-mouse-map))
4835 (org-rear-nonsticky-at (match-end 0))
4836 (when org-display-custom-times
4838 (org-display-custom-time (match-beginning 3) (match-end 3)))
4839 (org-display-custom-time (match-beginning 1) (match-end 1)))
4842 (defvar org-target-link-regexp nil
4843 "Regular expression matching radio targets in plain text.")
4844 (make-variable-buffer-local 'org-target-link-regexp)
4845 (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
4846 "Regular expression matching a link target.")
4847 (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
4848 "Regular expression matching a radio target.")
4849 (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
4850 "Regular expression matching any target.")
4852 (defun org-activate-target-links (limit)
4853 "Run through the buffer and add overlays to target matches."
4854 (when org-target-link-regexp
4855 (let ((case-fold-search t))
4856 (if (re-search-forward org-target-link-regexp limit t)
4858 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4859 (add-text-properties (match-beginning 0) (match-end 0)
4860 (list 'mouse-face 'highlight
4861 'keymap org-mouse-map
4862 'help-echo "Radio target link"
4863 'org-linked-text t))
4864 (org-rear-nonsticky-at (match-end 0))
4867 (defun org-update-radio-target-regexp ()
4868 "Find all radio targets in this file and update the regular expression."
4870 (when (memq 'radio org-activate-links)
4871 (setq org-target-link-regexp
4872 (org-make-target-link-regexp (org-all-targets 'radio)))
4873 (org-restart-font-lock)))
4875 (defun org-hide-wide-columns (limit)
4877 (setq s (text-property-any (point) (or limit (point-max))
4880 (setq e (next-single-property-change s 'org-cwidth))
4881 (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
4885 (defvar org-latex-and-specials-regexp nil
4886 "Regular expression for highlighting export special stuff.")
4887 (defvar org-match-substring-regexp)
4888 (defvar org-match-substring-with-braces-regexp)
4890 ;; This should be with the exporter code, but we also use if for font-locking
4891 (defconst org-export-html-special-string-regexps
4892 '(("\\\\-" . "­")
4893 ("---\\([^-]\\)" . "—\\1")
4894 ("--\\([^-]\\)" . "–\\1")
4895 ("\\.\\.\\." . "…"))
4896 "Regular expressions for special string conversion.")
4899 (defun org-compute-latex-and-specials-regexp ()
4900 "Compute regular expression for stuff treated specially by exporters."
4901 (if (not org-highlight-latex-fragments-and-specials)
4902 (org-set-local 'org-latex-and-specials-regexp nil)
4905 ((matchers (plist-get org-format-latex-options :matchers))
4906 (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
4907 org-latex-regexps)))
4908 (org-export-allow-BIND nil)
4909 (options (org-combine-plists (org-default-export-plist)
4910 (org-infile-export-plist)))
4911 (org-export-with-sub-superscripts (plist-get options :sub-superscript))
4912 (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
4913 (org-export-with-TeX-macros (plist-get options :TeX-macros))
4914 (org-export-html-expand (plist-get options :expand-quoted-html))
4915 (org-export-with-special-strings (plist-get options :special-strings))
4918 ((equal org-export-with-sub-superscripts '{})
4919 (list org-match-substring-with-braces-regexp))
4920 (org-export-with-sub-superscripts
4921 (list org-match-substring-regexp))
4924 (if org-export-with-LaTeX-fragments
4925 (mapcar (lambda (x) (nth 1 x)) latexs)))
4927 (if org-export-with-TeX-macros
4928 (list (concat "\\\\"
4930 (append (mapcar 'car (append org-entities-user
4932 (if (boundp 'org-latex-entities)
4934 (or (car-safe x) x))
4939 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
4940 (re-special (if org-export-with-special-strings
4941 (mapcar (lambda (x) (car x))
4942 org-export-html-special-string-regexps)))
4946 (if org-export-html-expand "@<[^>\n]+>")
4949 'org-latex-and-specials-regexp
4950 (mapconcat 'identity (append re-latex re-sub re-macros re-special
4953 (defun org-do-latex-and-special-faces (limit)
4954 "Run through the buffer and add overlays to links."
4955 (when org-latex-and-specials-regexp
4957 (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
4959 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
4961 '(org-code org-verbatim underline)))
4964 d (cond ((member (char-after (1+ (match-beginning 0)))
4967 (font-lock-prepend-text-property
4968 (+ d (match-beginning 0)) (match-end 0)
4969 'face 'org-latex-and-export-specials)
4970 (add-text-properties (+ d (match-beginning 0)) (match-end 0)
4971 '(font-lock-multiline t)))))
4974 (defun org-restart-font-lock ()
4975 "Restart font-lock-mode, to force refontification."
4976 (when (and (boundp 'font-lock-mode) font-lock-mode)
4978 (font-lock-mode 1)))
4980 (defun org-all-targets (&optional radio)
4981 "Return a list of all targets in this file.
4982 With optional argument RADIO, only find radio targets."
4983 (let ((re (if radio org-radio-target-regexp org-target-regexp))
4986 (goto-char (point-min))
4987 (while (re-search-forward re nil t)
4988 (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
4991 (defun org-make-target-link-regexp (targets)
4992 "Make regular expression matching all strings in TARGETS.
4993 The regular expression finds the targets also if there is a line break
5000 (while (string-match " +" x)
5001 (setq x (replace-match "\\s-+" t t x)))
5007 (defun org-activate-tags (limit)
5008 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
5010 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5011 (add-text-properties (match-beginning 1) (match-end 1)
5012 (list 'mouse-face 'highlight
5013 'keymap org-mouse-map))
5014 (org-rear-nonsticky-at (match-end 1))
5017 (defun org-outline-level ()
5018 "Compute the outline level of the heading at point.
5019 This function assumes that the cursor is at the beginning of a line matched
5020 by outline-regexp. Otherwise it returns garbage.
5021 If this is called at a normal headline, the level is the number of stars.
5022 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5023 For plain list items, if they are matched by `outline-regexp', this returns
5024 1000 plus the line indentation."
5026 (looking-at outline-regexp)
5027 (if (match-beginning 1)
5028 (+ (org-get-string-indentation (match-string 1)) 1000)
5029 (1- (- (match-end 0) (match-beginning 0))))))
5031 (defvar org-font-lock-keywords nil)
5033 (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5034 "Regular expression matching a property line.")
5036 (defvar org-font-lock-hook nil
5037 "Functions to be called for special font lock stuff.")
5039 (defun org-font-lock-hook (limit)
5040 (run-hook-with-args 'org-font-lock-hook limit))
5042 (defun org-set-font-lock-defaults ()
5043 (let* ((em org-fontify-emphasized-text)
5044 (lk org-activate-links)
5045 (org-font-lock-extra-keywords
5048 '(org-font-lock-hook)
5050 `(,(if org-fontify-whole-heading-line
5051 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5052 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5053 (1 (org-get-level-face 1))
5054 (2 (org-get-level-face 2))
5055 (3 (org-get-level-face 3)))
5057 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5060 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
5061 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
5062 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
5063 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t))
5065 (list org-drawer-regexp '(0 'org-special-keyword t))
5066 (list "^[ \t]*:END:" '(0 'org-special-keyword t))
5068 (list org-property-re
5069 '(1 'org-special-keyword t)
5070 '(3 'org-property-value t))
5072 (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
5073 (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
5074 (if (memq 'plain lk) '(org-activate-plain-links))
5075 (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
5076 (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
5077 (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
5078 (if (memq 'footnote lk) '(org-activate-footnote-links
5079 (2 'org-footnote t)))
5080 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
5081 '(org-hide-wide-columns (0 nil append))
5083 (list (concat "^\\*+[ \t]+" org-todo-regexp "\\([ \t]\\|$\\)")
5084 '(1 (org-get-todo-face 1) t))
5086 (if org-fontify-done-headline
5087 (list (concat "^[*]+ +\\<\\("
5088 (mapconcat 'regexp-quote org-done-keywords "\\|")
5090 '(2 'org-headline-done t))
5093 '(org-font-lock-add-priority-faces)
5095 '(org-font-lock-add-tag-faces)
5097 (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
5098 (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
5099 (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
5100 (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
5103 (if (featurep 'xemacs)
5104 '(org-do-emphasis-faces (0 nil append))
5105 '(org-do-emphasis-faces)))
5107 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5108 2 'org-checkbox prepend)
5109 (if org-provide-checkbox-statistics
5110 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5111 (0 (org-get-checkbox-statistics-face) t)))
5112 ;; Description list items
5113 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5115 ;; ARCHIVEd headings
5116 (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
5117 '(1 'org-archived prepend))
5119 '(org-do-latex-and-special-faces)
5121 '(org-activate-code (1 'org-code t))
5123 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5124 "\\|" org-quote-string "\\)\\>")
5125 '(1 'org-special-keyword t))
5126 '("^#.*" (0 'font-lock-comment-face t))
5127 ;; Blocks and meta lines
5128 '(org-fontify-meta-lines-and-blocks)
5130 (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
5131 ;; Now set the full font-lock-keywords
5132 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
5133 (org-set-local 'font-lock-defaults
5134 '(org-font-lock-keywords t nil nil backward-paragraph))
5135 (kill-local-variable 'font-lock-keywords) nil))
5137 (defun org-fontify-like-in-org-mode (s &optional odd-levels)
5138 "Fontify string S like in Org-mode"
5141 (let ((org-odd-levels-only odd-levels))
5143 (font-lock-fontify-buffer)
5149 (defun org-get-level-face (n)
5150 "Get the right face for match N in font-lock matching of headlines."
5151 (setq org-l (- (match-end 2) (match-beginning 1) 1))
5152 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
5153 (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
5155 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
5157 (t (if org-level-color-stars-only nil org-f))))
5159 (defun org-get-todo-face (kwd)
5160 "Get the right face for a TODO keyword KWD.
5161 If KWD is a number, get the corresponding match group."
5162 (if (numberp kwd) (setq kwd (match-string kwd)))
5163 (or (org-face-from-face-or-color
5164 'todo 'org-todo (cdr (assoc kwd org-todo-keyword-faces)))
5165 (and (member kwd org-done-keywords) 'org-done)
5168 (defun org-face-from-face-or-color (context inherit face-or-color)
5169 "Create a face list that inherits INHERIT, but sets the foreground color.
5170 When FACE-OR-COLOR is not a string, just return it."
5171 (if (stringp face-or-color)
5172 (list :inherit inherit
5173 (cdr (assoc context org-faces-easy-properties))
5177 (defun org-font-lock-add-tag-faces (limit)
5178 "Add the special tag faces."
5179 (when (and org-tag-faces org-tags-special-faces-re)
5180 (while (re-search-forward org-tags-special-faces-re limit t)
5181 (add-text-properties (match-beginning 1) (match-end 1)
5182 (list 'face (org-get-tag-face 1)
5183 'font-lock-fontified t))
5184 (backward-char 1))))
5186 (defun org-font-lock-add-priority-faces (limit)
5187 "Add the special priority faces."
5188 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t)
5189 (add-text-properties
5190 (match-beginning 0) (match-end 0)
5191 (list 'face (or (org-face-from-face-or-color
5192 'priority 'org-special-keyword
5193 (cdr (assoc (char-after (match-beginning 1))
5194 org-priority-faces)))
5195 'org-special-keyword)
5196 'font-lock-fontified t))))
5198 (defun org-get-tag-face (kwd)
5199 "Get the right face for a TODO keyword KWD.
5200 If KWD is a number, get the corresponding match group."
5201 (if (numberp kwd) (setq kwd (match-string kwd)))
5202 (or (org-face-from-face-or-color
5203 'tag 'org-tag (cdr (assoc kwd org-tag-faces)))
5206 (defun org-unfontify-region (beg end &optional maybe_loudly)
5207 "Remove fontification and activation overlays from links."
5208 (font-lock-default-unfontify-region beg end)
5209 (let* ((buffer-undo-list t)
5210 (inhibit-read-only t) (inhibit-point-motion-hooks t)
5211 (inhibit-modification-hooks t)
5212 deactivate-mark buffer-file-name buffer-file-truename)
5213 (remove-text-properties
5216 ;; also remove line-prefix and wrap-prefix properties
5217 '(mouse-face t keymap t org-linked-text t
5218 invisible t intangible t
5219 line-prefix t wrap-prefix t
5221 '(mouse-face t keymap t org-linked-text t
5222 invisible t intangible t
5223 org-no-flyspell t)))))
5225 ;;;; Visibility cycling, including org-goto and indirect buffer
5229 (defvar org-cycle-global-status nil)
5230 (make-variable-buffer-local 'org-cycle-global-status)
5231 (defvar org-cycle-subtree-status nil)
5232 (make-variable-buffer-local 'org-cycle-subtree-status)
5236 (defvar org-inlinetask-min-level)
5238 (defun org-cycle (&optional arg)
5239 "TAB-action and visibility cycling for Org-mode.
5241 This is the command invoked in Org-mode by the TAB key. Its main purpose
5242 is outline visibility cycling, but it also invokes other actions
5243 in special contexts.
5245 - When this function is called with a prefix argument, rotate the entire
5246 buffer through 3 states (global cycling)
5247 1. OVERVIEW: Show only top-level headlines.
5248 2. CONTENTS: Show all headlines of all levels, but no body text.
5249 3. SHOW ALL: Show everything.
5250 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5251 determined by the variable `org-startup-folded', and by any VISIBILITY
5252 properties in the buffer.
5253 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5254 including any drawers.
5256 - When inside a table, re-align the table and move to the next field.
5258 - When point is at the beginning of a headline, rotate the subtree started
5259 by this line through 3 different states (local cycling)
5260 1. FOLDED: Only the main headline is shown.
5261 2. CHILDREN: The main headline and the direct children are shown.
5262 From this state, you can move to one of the children
5263 and zoom in further.
5264 3. SUBTREE: Show the entire subtree, including body text.
5265 If there is no subtree, switch directly from CHILDREN to FOLDED.
5267 - When point is at the beginning of an empty headline and the variable
5268 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5269 of the headline by demoting and promoting it to likely levels. This
5270 speeds up creation document structure by presing TAB once or several
5271 times right after creating a new headline.
5273 - When there is a numeric prefix, go up to a heading with level ARG, do
5274 a `show-subtree' and return to the previous cursor position. If ARG
5275 is negative, go up that many levels.
5277 - When point is not at the beginning of a headline, execute the global
5278 binding for TAB, which is re-indenting the line. See the option
5279 `org-cycle-emulate-tab' for details.
5281 - Special case: if point is at the beginning of the buffer and there is
5282 no headline in line 1, this function will act as if called with prefix arg.
5283 But only if also the variable `org-cycle-global-at-bob' is t."
5285 (org-load-modules-maybe)
5286 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook)
5287 (and org-cycle-level-after-item/entry-creation
5288 (or (org-cycle-level)
5289 (org-cycle-item-indentation))))
5291 (or org-cycle-max-level
5292 (and (boundp 'org-inlinetask-min-level)
5293 org-inlinetask-min-level
5294 (1- org-inlinetask-min-level))))
5295 (nstars (and limit-level
5296 (if org-odd-levels-only
5297 (and limit-level (1- (* limit-level 2)))
5301 ((not (org-mode-p)) outline-regexp)
5302 ((or (eq org-cycle-include-plain-lists 'integrate)
5303 (and org-cycle-include-plain-lists (org-at-item-p)))
5305 (if nstars (format "\\{1,%d\\}" nstars) "+")
5306 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5307 (t (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))))
5308 (bob-special (and org-cycle-global-at-bob (bobp)
5309 (not (looking-at outline-regexp))))
5312 (delq 'org-optimize-window-after-visibility-change
5313 (copy-sequence org-cycle-hook))
5317 (if (or bob-special (equal arg '(4)))
5318 ;; special case: use global cycling
5324 (org-set-startup-visibility)
5325 (message "Startup visibility, plus VISIBILITY properties"))
5329 (message "Entire buffer visible, including drawers"))
5331 ((org-at-table-p 'any)
5332 ;; Enter the table or move to the next field in the table
5333 (if (org-at-table.el-p)
5334 (message "Use C-c ' to edit table.el tables")
5335 (if arg (org-table-edit-field t)
5336 (org-table-justify-field-maybe)
5337 (call-interactively 'org-table-next-field))))
5339 ((run-hook-with-args-until-success
5340 'org-tab-after-check-for-table-hook))
5342 ((eq arg t) ;; Global cycling
5343 (org-cycle-internal-global))
5345 ((and org-drawers org-drawer-regexp
5347 (beginning-of-line 1)
5348 (looking-at org-drawer-regexp)))
5349 ;; Toggle block visibility
5351 (not (get-char-property (match-end 0) 'invisible))))
5354 ;; Show-subtree, ARG levels up from here.
5356 (org-back-to-heading)
5357 (outline-up-heading (if (< arg 0) (- arg)
5358 (- (funcall outline-level) arg)))
5359 (org-show-subtree)))
5361 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
5362 (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
5364 (org-cycle-internal-local))
5366 ;; TAB emulation and template completion
5367 (buffer-read-only (org-back-to-heading))
5369 ((run-hook-with-args-until-success
5370 'org-tab-after-check-for-cycling-hook))
5372 ((org-try-structure-completion))
5374 ((org-try-cdlatex-tab))
5376 ((run-hook-with-args-until-success
5377 'org-tab-before-tab-emulation-hook))
5379 ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
5381 (not (looking-at outline-regexp))))
5382 (call-interactively (global-key-binding "\t")))
5384 ((if (and (memq org-cycle-emulate-tab '(white whitestart))
5385 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5386 (or (and (eq org-cycle-emulate-tab 'white)
5387 (= (match-end 0) (point-at-eol)))
5388 (and (eq org-cycle-emulate-tab 'whitestart)
5389 (>= (match-end 0) pos))))
5391 (eq org-cycle-emulate-tab t))
5392 (call-interactively (global-key-binding "\t")))
5395 (org-back-to-heading)
5398 (defun org-cycle-internal-global ()
5399 "Do the global cycling action."
5401 ((and (eq last-command this-command)
5402 (eq org-cycle-global-status 'overview))
5403 ;; We just created the overview - now do table of contents
5404 ;; This can be slow in very large buffers, so indicate action
5405 (run-hook-with-args 'org-pre-cycle-hook 'contents)
5406 (message "CONTENTS...")
5408 (message "CONTENTS...done")
5409 (setq org-cycle-global-status 'contents)
5410 (run-hook-with-args 'org-cycle-hook 'contents))
5412 ((and (eq last-command this-command)
5413 (eq org-cycle-global-status 'contents))
5414 ;; We just showed the table of contents - now show everything
5415 (run-hook-with-args 'org-pre-cycle-hook 'all)
5417 (message "SHOW ALL")
5418 (setq org-cycle-global-status 'all)
5419 (run-hook-with-args 'org-cycle-hook 'all))
5422 ;; Default action: go to overview
5423 (run-hook-with-args 'org-pre-cycle-hook 'overview)
5425 (message "OVERVIEW")
5426 (setq org-cycle-global-status 'overview)
5427 (run-hook-with-args 'org-cycle-hook 'overview))))
5429 (defun org-cycle-internal-local ()
5430 "Do the local cycling action."
5431 (org-back-to-heading)
5432 (let ((goal-column 0) eoh eol eos level has-children children-skipped)
5433 ;; First, some boundaries
5435 (org-back-to-heading)
5436 (setq level (funcall outline-level))
5438 (beginning-of-line 2)
5439 (if (or (featurep 'xemacs) (<= emacs-major-version 21))
5440 ; XEmacs does not have `next-single-char-property-change'
5441 ; I'm not sure about Emacs 21.
5442 (while (and (not (eobp)) ;; this is like `next-line'
5443 (get-char-property (1- (point)) 'invisible))
5444 (beginning-of-line 2))
5445 (while (and (not (eobp)) ;; this is like `next-line'
5446 (get-char-property (1- (point)) 'invisible))
5447 (goto-char (next-single-char-property-change (point) 'invisible))
5448 ;;;??? (or (bolp) (beginning-of-line 2))))
5449 (and (eolp) (beginning-of-line 2))))
5451 (outline-end-of-heading) (setq eoh (point))
5453 (outline-next-heading)
5454 (setq has-children (and (org-at-heading-p t)
5455 (> (funcall outline-level) level))))
5456 (org-end-of-subtree t)
5458 (skip-chars-forward " \t\n")
5459 (beginning-of-line 1) ; in case this is an item
5461 (setq eos (if (eobp) (point) (1- (point)))))
5462 ;; Find out what to do next and set `this-command'
5465 ;; Nothing is hidden behind this heading
5466 (run-hook-with-args 'org-pre-cycle-hook 'empty)
5467 (message "EMPTY ENTRY")
5468 (setq org-cycle-subtree-status nil)
5471 (outline-next-heading)
5472 (if (org-invisible-p) (org-flag-heading nil))))
5473 ((and (or (>= eol eos)
5474 (not (string-match "\\S-" (buffer-substring eol eos))))
5476 (not (setq children-skipped
5477 org-cycle-skip-children-state-if-no-children))))
5478 ;; Entire subtree is hidden in one line: children view
5479 (run-hook-with-args 'org-pre-cycle-hook 'children)
5482 (message "CHILDREN")
5485 (outline-next-heading)
5486 (if (org-invisible-p) (org-flag-heading nil)))
5487 (setq org-cycle-subtree-status 'children)
5488 (run-hook-with-args 'org-cycle-hook 'children))
5489 ((or children-skipped
5490 (and (eq last-command this-command)
5491 (eq org-cycle-subtree-status 'children)))
5492 ;; We just showed the children, or no children are there,
5493 ;; now show everything.
5494 (run-hook-with-args 'org-pre-cycle-hook 'subtree)
5496 (message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
5497 (setq org-cycle-subtree-status 'subtree)
5498 (run-hook-with-args 'org-cycle-hook 'subtree))
5500 ;; Default action: hide the subtree.
5501 (run-hook-with-args 'org-pre-cycle-hook 'folded)
5504 (setq org-cycle-subtree-status 'folded)
5505 (run-hook-with-args 'org-cycle-hook 'folded)))))
5508 (defun org-global-cycle (&optional arg)
5509 "Cycle the global visibility. For details see `org-cycle'.
5510 With C-u prefix arg, switch to startup visibility.
5511 With a numeric prefix, show all headlines up to that level."
5513 (let ((org-cycle-include-plain-lists
5514 (if (org-mode-p) org-cycle-include-plain-lists nil)))
5518 (hide-sublevels arg)
5519 (setq org-cycle-global-status 'contents))
5521 (org-set-startup-visibility)
5522 (message "Startup visibility, plus VISIBILITY properties."))
5524 (org-cycle '(4))))))
5526 (defun org-set-startup-visibility ()
5527 "Set the visibility required by startup options and properties."
5529 ((eq org-startup-folded t)
5531 ((eq org-startup-folded 'content)
5532 (let ((this-command 'org-cycle) (last-command 'org-cycle))
5533 (org-cycle '(4)) (org-cycle '(4)))))
5534 (unless (eq org-startup-folded 'showeverything)
5535 (if org-hide-block-startup (org-hide-block-all))
5536 (org-set-visibility-according-to-property 'no-cleanup)
5537 (org-cycle-hide-archived-subtrees 'all)
5538 (org-cycle-hide-drawers 'all)
5539 (org-cycle-show-empty-lines 'all)))
5541 (defun org-set-visibility-according-to-property (&optional no-cleanup)
5542 "Switch subtree visibilities according to :VISIBILITY: property."
5544 (let (org-show-entry-below state)
5546 (goto-char (point-min))
5547 (while (re-search-forward
5548 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5550 (setq state (match-string 1))
5552 (org-back-to-heading t)
5556 ((equal state '("fold" "folded"))
5558 ((equal state "children")
5559 (org-show-hidden-entry)
5561 ((equal state "content")
5564 (org-narrow-to-subtree)
5566 ((member state '("all" "showall"))
5569 (org-cycle-hide-archived-subtrees 'all)
5570 (org-cycle-hide-drawers 'all)
5571 (org-cycle-show-empty-lines 'all)))))
5573 (defun org-overview ()
5574 "Switch to overview mode, showing only top-level headlines.
5575 Really, this shows all headlines with level equal or greater than the level
5576 of the first headline in the buffer. This is important, because if the
5577 first headline is not level one, then (hide-sublevels 1) gives confusing
5580 (let ((level (save-excursion
5581 (goto-char (point-min))
5582 (if (re-search-forward (concat "^" outline-regexp) nil t)
5584 (goto-char (match-beginning 0))
5585 (funcall outline-level))))))
5586 (and level (hide-sublevels level))))
5588 (defun org-content (&optional arg)
5589 "Show all headlines in the buffer, like a table of contents.
5590 With numerical argument N, show content up to level N."
5593 ;; Visit all headings and show their offspring
5594 (and (integerp arg) (org-overview))
5595 (goto-char (point-max))
5597 (while (and (progn (condition-case nil
5598 (outline-previous-visible-heading 1)
5599 (error (goto-char (point-min))))
5601 (looking-at outline-regexp))
5603 (show-children (1- arg))
5605 (if (bobp) (throw 'exit nil))))))
5608 (defun org-optimize-window-after-visibility-change (state)
5609 "Adjust the window after a change in outline visibility.
5610 This function is the default value of the hook `org-cycle-hook'."
5611 (when (get-buffer-window (current-buffer))
5613 ((eq state 'content) nil)
5614 ((eq state 'all) nil)
5615 ((eq state 'folded) nil)
5616 ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
5617 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
5619 (defun org-remove-empty-overlays-at (pos)
5620 "Remove outline overlays that do not contain non-white stuff."
5623 (and (eq 'outline (org-overlay-get o 'invisible))
5624 (not (string-match "\\S-" (buffer-substring (org-overlay-start o)
5625 (org-overlay-end o))))
5626 (org-delete-overlay o)))
5627 (org-overlays-at pos)))
5629 (defun org-clean-visibility-after-subtree-move ()
5630 "Fix visibility issues after moving a subtree."
5631 ;; First, find a reasonable region to look at:
5632 ;; Start two siblings above, end three below
5633 (let* ((beg (save-excursion
5634 (and (org-get-last-sibling)
5635 (org-get-last-sibling))
5637 (end (save-excursion
5638 (and (org-get-next-sibling)
5639 (org-get-next-sibling)
5640 (org-get-next-sibling))
5641 (if (org-at-heading-p)
5644 (level (looking-at "\\*+"))
5645 (re (if level (concat "^" (regexp-quote (match-string 0)) " "))))
5648 (narrow-to-region beg end)
5650 ;; Properly fold already folded siblings
5651 (goto-char (point-min))
5652 (while (re-search-forward re nil t)
5653 (if (and (not (org-invisible-p))
5655 (goto-char (point-at-eol)) (org-invisible-p)))
5657 (org-cycle-show-empty-lines 'overview)
5658 (org-cycle-hide-drawers 'overview)))))
5660 (defun org-cycle-show-empty-lines (state)
5661 "Show empty lines above all visible headlines.
5662 The region to be covered depends on STATE when called through
5663 `org-cycle-hook'. Lisp program can use t for STATE to get the
5664 entire buffer covered. Note that an empty line is only shown if there
5665 are at least `org-cycle-separator-lines' empty lines before the headline."
5666 (when (not (= org-cycle-separator-lines 0))
5668 (let* ((n (abs org-cycle-separator-lines))
5670 ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
5671 ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
5672 (t (let ((ns (number-to-string (- n 2))))
5673 (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
5674 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
5677 ((memq state '(overview contents t))
5678 (setq beg (point-min) end (point-max)))
5679 ((memq state '(children folded))
5680 (setq beg (point) end (progn (org-end-of-subtree t t)
5681 (beginning-of-line 2)
5685 (while (re-search-forward re end t)
5686 (unless (get-char-property (match-end 1) 'invisible)
5687 (setq e (match-end 1))
5688 (if (< org-cycle-separator-lines 0)
5689 (setq b (save-excursion
5690 (goto-char (match-beginning 0))
5691 (org-back-over-empty-lines)
5693 (goto-char (max (point-min) (1- (point))))
5697 (setq b (match-beginning 1)))
5698 (outline-flag-region b e nil)))))))
5699 ;; Never hide empty lines at the end of the file.
5701 (goto-char (point-max))
5702 (outline-previous-heading)
5703 (outline-end-of-heading)
5704 (if (and (looking-at "[ \t\n]+")
5705 (= (match-end 0) (point-max)))
5706 (outline-flag-region (point) (match-end 0) nil))))
5708 (defun org-show-empty-lines-in-parent ()
5709 "Move to the parent and re-show empty lines before visible headlines."
5711 (let ((context (if (org-up-heading-safe) 'children 'overview)))
5712 (org-cycle-show-empty-lines context))))
5714 (defun org-files-list ()
5715 "Return `org-agenda-files' list, plus all open org-mode files.
5716 This is useful for operations that need to scan all of a user's
5717 open and agenda-wise Org files."
5718 (let ((files (mapcar 'expand-file-name (org-agenda-files))))
5719 (dolist (buf (buffer-list))
5720 (with-current-buffer buf
5721 (if (and (eq major-mode 'org-mode) (buffer-file-name))
5722 (let ((file (expand-file-name (buffer-file-name))))
5723 (unless (member file files)
5724 (push file files))))))
5727 (defsubst org-entry-beginning-position ()
5728 "Return the beginning position of the current entry."
5729 (save-excursion (outline-back-to-heading t) (point)))
5731 (defsubst org-entry-end-position ()
5732 "Return the end position of the current entry."
5733 (save-excursion (outline-next-heading) (point)))
5735 (defun org-cycle-hide-drawers (state)
5736 "Re-hide all drawers after a visibility state change."
5737 (when (and (org-mode-p)
5738 (not (memq state '(overview folded contents))))
5740 (let* ((globalp (memq state '(contents all)))
5741 (beg (if globalp (point-min) (point)))
5742 (end (if globalp (point-max)
5743 (if (eq state 'children)
5744 (save-excursion (outline-next-heading) (point))
5745 (org-end-of-subtree t)))))
5747 (while (re-search-forward org-drawer-regexp end t)
5748 (org-flag-drawer t))))))
5750 (defun org-flag-drawer (flag)
5752 (beginning-of-line 1)
5753 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
5754 (let ((b (match-end 0))
5755 (outline-regexp org-outline-regexp))
5756 (if (re-search-forward
5758 (save-excursion (outline-next-heading) (point)) t)
5759 (outline-flag-region b (point-at-eol) flag)
5760 (error ":END: line missing at position %s" b))))))
5762 (defun org-subtree-end-visible-p ()
5763 "Is the end of the current subtree visible?"
5764 (pos-visible-in-window-p
5765 (save-excursion (org-end-of-subtree t) (point))))
5767 (defun org-first-headline-recenter (&optional N)
5768 "Move cursor to the first headline and recenter the headline.
5769 Optional argument N means put the headline into the Nth line of the window."
5770 (goto-char (point-min))
5771 (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
5773 (recenter (prefix-numeric-value N))))
5775 ;;; Saving and restoring visibility
5777 (defun org-outline-overlay-data (&optional use-markers)
5778 "Return a list of the locations of all outline overlays.
5779 The are overlays with the `invisible' property value `outline'.
5780 The return valus is a list of cons cells, with start and stop
5781 positions for each overlay.
5782 If USE-MARKERS is set, return the positions as markers."
5789 (when (eq (org-overlay-get o 'invisible) 'outline)
5790 (setq beg (org-overlay-start o)
5791 end (org-overlay-end o))
5792 (and beg end (> end beg)
5794 (cons (move-marker (make-marker) beg)
5795 (move-marker (make-marker) end))
5797 (org-overlays-in (point-min) (point-max))))))))
5799 (defun org-set-outline-overlay-data (data)
5800 "Create visibility overlays for all positions in DATA.
5801 DATA should have been made by `org-outline-overlay-data'."
5808 (setq o (org-make-overlay (car c) (cdr c)))
5809 (org-overlay-put o 'invisible 'outline))
5812 (defmacro org-save-outline-visibility (use-markers &rest body)
5813 "Save and restore outline visibility around BODY.
5814 If USE-MARKERS is non-nil, use markers for the positions.
5815 This means that the buffer may change while running BODY,
5816 but it also means that the buffer should stay alive
5817 during the operation, because otherwise all these markers will
5819 `(let ((data (org-outline-overlay-data ,use-markers)))
5823 (org-set-outline-overlay-data data))
5826 (and (markerp (car c)) (move-marker (car c) nil))
5827 (and (markerp (cdr c)) (move-marker (cdr c) nil)))
5831 ;;; Folding of blocks
5833 (defconst org-block-regexp
5835 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
5836 "Regular expression for hiding blocks.")
5838 (defvar org-hide-block-overlays nil
5839 "Overlays hiding blocks.")
5840 (make-variable-buffer-local 'org-hide-block-overlays)
5842 (defun org-block-map (function &optional start end)
5843 "Call func at the head of all source blocks in the current
5844 buffer. Optional arguments START and END can be used to limit
5846 (let ((start (or start (point-min)))
5847 (end (or end (point-max))))
5850 (while (and (< (point) end) (re-search-forward org-block-regexp end t))
5853 (goto-char (match-beginning 0))
5854 (funcall function)))))))
5856 (defun org-hide-block-toggle-all ()
5857 "Toggle the visibility of all blocks in the current buffer."
5858 (org-block-map #'org-hide-block-toggle))
5860 (defun org-hide-block-all ()
5861 "Fold all blocks in the current buffer."
5863 (org-show-block-all)
5864 (org-block-map #'org-hide-block-toggle-maybe))
5866 (defun org-show-block-all ()
5867 "Unfold all blocks in the current buffer."
5868 (mapc 'org-delete-overlay org-hide-block-overlays)
5869 (setq org-hide-block-overlays nil))
5871 (defun org-hide-block-toggle-maybe ()
5872 "Toggle visibility of block at point."
5874 (let ((case-fold-search t))
5876 (beginning-of-line 1)
5877 (looking-at org-block-regexp))
5878 (progn (org-hide-block-toggle)
5879 t) ;; to signal that we took action
5880 nil))) ;; to signal that we did not
5882 (defun org-hide-block-toggle (&optional force)
5883 "Toggle the visibility of the current block."
5887 (if (re-search-forward org-block-regexp nil t)
5888 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
5889 (end (match-end 0)) ;; end of entire body
5891 (if (memq t (mapcar (lambda (overlay)
5892 (eq (org-overlay-get overlay 'invisible)
5894 (org-overlays-at start)))
5895 (if (or (not force) (eq force 'off))
5897 (when (member ov org-hide-block-overlays)
5898 (setq org-hide-block-overlays
5899 (delq ov org-hide-block-overlays)))
5900 (when (eq (org-overlay-get ov 'invisible)
5902 (org-delete-overlay ov)))
5903 (org-overlays-at start)))
5904 (setq ov (org-make-overlay start end))
5905 (org-overlay-put ov 'invisible 'org-hide-block)
5906 ;; make the block accessible to isearch
5908 ov 'isearch-open-invisible
5910 (when (member ov org-hide-block-overlays)
5911 (setq org-hide-block-overlays
5912 (delq ov org-hide-block-overlays)))
5913 (when (eq (org-overlay-get ov 'invisible)
5915 (org-delete-overlay ov))))
5916 (push ov org-hide-block-overlays)))
5917 (error "Not looking at a source block"))))
5919 ;; org-tab-after-check-for-cycling-hook
5920 (add-hook 'org-tab-first-hook 'org-hide-block-toggle-maybe)
5921 ;; Remove overlays when changing major mode
5922 (add-hook 'org-mode-hook
5923 (lambda () (org-add-hook 'change-major-mode-hook
5924 'org-show-block-all 'append 'local)))
5928 (defvar org-goto-window-configuration nil)
5929 (defvar org-goto-marker nil)
5930 (defvar org-goto-map
5931 (let ((map (make-sparse-keymap)))
5932 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
5933 (while (setq cmd (pop cmds))
5934 (substitute-key-definition cmd cmd map global-map)))
5935 (suppress-keymap map)
5936 (org-defkey map "\C-m" 'org-goto-ret)
5937 (org-defkey map [(return)] 'org-goto-ret)
5938 (org-defkey map [(left)] 'org-goto-left)
5939 (org-defkey map [(right)] 'org-goto-right)
5940 (org-defkey map [(control ?g)] 'org-goto-quit)
5941 (org-defkey map "\C-i" 'org-cycle)
5942 (org-defkey map [(tab)] 'org-cycle)
5943 (org-defkey map [(down)] 'outline-next-visible-heading)
5944 (org-defkey map [(up)] 'outline-previous-visible-heading)
5945 (if org-goto-auto-isearch
5946 (if (fboundp 'define-key-after)
5947 (define-key-after map [t] 'org-goto-local-auto-isearch)
5949 (org-defkey map "q" 'org-goto-quit)
5950 (org-defkey map "n" 'outline-next-visible-heading)
5951 (org-defkey map "p" 'outline-previous-visible-heading)
5952 (org-defkey map "f" 'outline-forward-same-level)
5953 (org-defkey map "b" 'outline-backward-same-level)
5954 (org-defkey map "u" 'outline-up-heading))
5955 (org-defkey map "/" 'org-occur)
5956 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
5957 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
5958 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
5959 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
5960 (org-defkey map "\C-c\C-u" 'outline-up-heading)
5963 (defconst org-goto-help
5964 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
5965 RET=jump to location [Q]uit and return to previous location
5966 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
5968 (defvar org-goto-start-pos) ; dynamically scoped parameter
5970 ;; FIXME: Docstring does not mention both interfaces
5971 (defun org-goto (&optional alternative-interface)
5972 "Look up a different location in the current file, keeping current visibility.
5974 When you want look-up or go to a different location in a document, the
5975 fastest way is often to fold the entire buffer and then dive into the tree.
5976 This method has the disadvantage, that the previous location will be folded,
5977 which may not be what you want.
5979 This command works around this by showing a copy of the current buffer
5980 in an indirect buffer, in overview mode. You can dive into the tree in
5981 that copy, use org-occur and incremental search to find a location.
5982 When pressing RET or `Q', the command returns to the original buffer in
5983 which the visibility is still unchanged. After RET is will also jump to
5984 the location selected in the indirect buffer and expose the
5985 the headline hierarchy above."
5987 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
5988 (org-refile-use-outline-path t)
5989 (org-refile-target-verify-function nil)
5991 (if (not alternative-interface)
5993 (if (eq org-goto-interface 'outline)
5994 'outline-path-completion
5996 (org-goto-start-pos (point))
5998 (if (eq interface 'outline)
5999 (car (org-get-location (current-buffer) org-goto-help))
6000 (nth 3 (org-refile-get-location "Goto: ")))))
6003 (org-mark-ring-push org-goto-start-pos)
6004 (goto-char selected-point)
6005 (if (or (org-invisible-p) (org-invisible-p2))
6006 (org-show-context 'org-goto)))
6009 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6010 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6011 (defvar org-goto-local-auto-isearch-map) ; defined below
6013 (defun org-get-location (buf help)
6014 "Let the user select a location in the Org-mode buffer BUF.
6015 This function uses a recursive edit. It returns the selected position
6017 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6018 (isearch-hide-immediately nil)
6019 (isearch-search-fun-function
6020 (lambda () 'org-goto-local-search-headings))
6021 (org-goto-selected-point org-goto-exit-command)
6023 (special-display-buffer-names nil)
6024 (special-display-regexps nil)
6025 (special-display-function nil))
6027 (save-window-excursion
6028 (delete-other-windows)
6029 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6032 (make-indirect-buffer (current-buffer) "*org-goto*")
6033 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6034 (with-output-to-temp-buffer "*Help*"
6036 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6037 (setq buffer-read-only nil)
6038 (let ((org-startup-truncated t)
6039 (org-startup-folded nil)
6040 (org-startup-align-all-tables nil))
6043 (setq buffer-read-only t)
6044 (if (and (boundp 'org-goto-start-pos)
6045 (integer-or-marker-p org-goto-start-pos))
6046 (let ((org-show-hierarchy-above t)
6047 (org-show-siblings t)
6048 (org-show-following-heading t))
6049 (goto-char org-goto-start-pos)
6050 (and (org-invisible-p) (org-show-context)))
6051 (goto-char (point-min)))
6052 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6053 (message "Select location and press RET")
6054 (use-local-map org-goto-map)
6057 (kill-buffer "*org-goto*")
6058 (cons org-goto-selected-point org-goto-exit-command)))
6060 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6061 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6062 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6063 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6065 (defun org-goto-local-search-headings (string bound noerror)
6066 "Search and make sure that any matches are in headlines."
6068 (while (if isearch-forward
6069 (search-forward string bound noerror)
6070 (search-backward string bound noerror))
6071 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6072 (and (member :headline context)
6073 (not (member :tags context))))
6074 (throw 'return (point))))))
6076 (defun org-goto-local-auto-isearch ()
6079 (goto-char (point-min))
6080 (let ((keys (this-command-keys)))
6081 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6083 (isearch-process-search-char (string-to-char keys)))))
6085 (defun org-goto-ret (&optional arg)
6086 "Finish `org-goto' by going to the new location."
6088 (setq org-goto-selected-point (point)
6089 org-goto-exit-command 'return)
6092 (defun org-goto-left ()
6093 "Finish `org-goto' by going to the new location."
6095 (if (org-on-heading-p)
6097 (beginning-of-line 1)
6098 (setq org-goto-selected-point (point)
6099 org-goto-exit-command 'left)
6101 (error "Not on a heading")))
6103 (defun org-goto-right ()
6104 "Finish `org-goto' by going to the new location."
6106 (if (org-on-heading-p)
6108 (setq org-goto-selected-point (point)
6109 org-goto-exit-command 'right)
6111 (error "Not on a heading")))
6113 (defun org-goto-quit ()
6114 "Finish `org-goto' without cursor motion."
6116 (setq org-goto-selected-point nil)
6117 (setq org-goto-exit-command 'quit)
6120 ;;; Indirect buffer display of subtrees
6122 (defvar org-indirect-dedicated-frame nil
6123 "This is the frame being used for indirect tree display.")
6124 (defvar org-last-indirect-buffer nil)
6126 (defun org-tree-to-indirect-buffer (&optional arg)
6127 "Create indirect buffer and narrow it to current subtree.
6128 With numerical prefix ARG, go up to this level and then take that tree.
6129 If ARG is negative, go up that many levels.
6130 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6131 indirect buffer previously made with this command, to avoid proliferation of
6132 indirect buffers. However, when you call the command with a `C-u' prefix, or
6133 when `org-indirect-buffer-display' is `new-frame', the last buffer
6134 is kept so that you can work with several indirect buffers at the same time.
6135 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6136 requests that a new frame be made for the new buffer, so that the dedicated
6137 frame is not changed."
6139 (let ((cbuf (current-buffer))
6140 (cwin (selected-window))
6142 beg end level heading ibuf)
6144 (org-back-to-heading t)
6146 (setq level (org-outline-level))
6147 (if (< arg 0) (setq arg (+ level arg)))
6148 (while (> (setq level (org-outline-level)) arg)
6149 (outline-up-heading 1 t)))
6151 heading (org-get-heading))
6152 (org-end-of-subtree t t)
6153 (if (org-on-heading-p) (backward-char 1))
6155 (if (and (buffer-live-p org-last-indirect-buffer)
6156 (not (eq org-indirect-buffer-display 'new-frame))
6158 (kill-buffer org-last-indirect-buffer))
6159 (setq ibuf (org-get-indirect-buffer cbuf)
6160 org-last-indirect-buffer ibuf)
6162 ((or (eq org-indirect-buffer-display 'new-frame)
6163 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6164 (select-frame (make-frame))
6165 (delete-other-windows)
6166 (switch-to-buffer ibuf)
6167 (org-set-frame-title heading))
6168 ((eq org-indirect-buffer-display 'dedicated-frame)
6170 (select-frame (or (and org-indirect-dedicated-frame
6171 (frame-live-p org-indirect-dedicated-frame)
6172 org-indirect-dedicated-frame)
6173 (setq org-indirect-dedicated-frame (make-frame)))))
6174 (delete-other-windows)
6175 (switch-to-buffer ibuf)
6176 (org-set-frame-title (concat "Indirect: " heading)))
6177 ((eq org-indirect-buffer-display 'current-window)
6178 (switch-to-buffer ibuf))
6179 ((eq org-indirect-buffer-display 'other-window)
6180 (pop-to-buffer ibuf))
6181 (t (error "Invalid value")))
6182 (if (featurep 'xemacs)
6183 (save-excursion (org-mode) (turn-on-font-lock)))
6184 (narrow-to-region beg end)
6187 (and (window-live-p cwin) (select-window cwin))))
6189 (defun org-get-indirect-buffer (&optional buffer)
6190 (setq buffer (or buffer (current-buffer)))
6191 (let ((n 1) (base (buffer-name buffer)) bname)
6192 (while (buffer-live-p
6193 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6196 (make-indirect-buffer buffer bname 'clone)
6197 (error (make-indirect-buffer buffer bname)))))
6199 (defun org-set-frame-title (title)
6200 "Set the title of the current frame to the string TITLE."
6201 ;; FIXME: how to name a single frame in XEmacs???
6202 (unless (featurep 'xemacs)
6203 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6205 ;;;; Structure editing
6207 ;;; Inserting headlines
6209 (defun org-previous-line-empty-p ()
6212 (or (beginning-of-line 0) t)
6214 (looking-at "[ \t]*$")))))
6216 (defun org-insert-heading (&optional force-heading invisible-ok)
6217 "Insert a new heading or item with same depth at point.
6218 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6219 If point is at the beginning of a headline, insert a sibling before the
6220 current headline. If point is not at the beginning, do not split the line,
6221 but create the new headline after the current line.
6222 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6223 This is important for non-interactive uses of the command."
6225 (if (or (= (buffer-size) 0)
6226 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6227 (org-on-heading-p))))
6228 (not (org-in-item-p))))
6230 (when (or force-heading (not (org-insert-item)))
6231 (let* ((empty-line-p nil)
6232 (head (save-excursion
6235 (org-back-to-heading invisible-ok)
6236 (setq empty-line-p (org-previous-line-empty-p))
6239 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6240 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6241 pos hide-previous previous-pos)
6243 ((and (org-on-heading-p) (bolp)
6245 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6246 ;; insert before the current line
6247 (open-line (if blank 2 1)))
6249 (not org-insert-heading-respect-content)
6252 (backward-char 1) (not (org-invisible-p)))))
6253 ;; insert right here
6256 ;; somewhere in the line
6258 (setq previous-pos (point-at-bol))
6260 (setq hide-previous (org-invisible-p)))
6261 (and org-insert-heading-respect-content (org-show-subtree))
6263 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6266 (goto-char (point-at-bol))
6267 (and (looking-at org-complex-heading-regexp)
6268 (> p (match-beginning 4)))))))
6271 (org-insert-heading-respect-content
6272 (org-end-of-subtree nil t)
6273 (or (bolp) (newline))
6274 (or (org-previous-line-empty-p)
6275 (and blank (newline)))
6281 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6282 (setq tags (and (match-end 2) (match-string 2)))
6284 (delete-region (match-beginning 1) (match-end 1)))
6285 (setq pos (point-at-bol))
6286 (or split (end-of-line 1))
6287 (delete-horizontal-space)
6288 (if (string-match "\\`\\*+\\'"
6289 (buffer-substring (point-at-bol) (point)))
6291 (newline (if blank 2 1))
6297 (org-set-tags nil 'align))))
6299 (or split (end-of-line 1))
6300 (newline (if blank 2 1)))))))
6301 (insert head) (just-one-space)
6304 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6305 (when (and org-insert-heading-respect-content hide-previous)
6307 (goto-char previous-pos)
6309 (run-hooks 'org-insert-heading-hook)))))
6311 (defun org-get-heading (&optional no-tags)
6312 "Return the heading of the current entry, without the stars."
6314 (org-back-to-heading t)
6317 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6318 "\\*+[ \t]+\\([^\r\n]*\\)"))
6319 (match-string 1) "")))
6321 (defun org-heading-components ()
6322 "Return the components of the current heading.
6323 This is a list with the following elements:
6324 - the level as an integer
6325 - the reduced level, different if `org-odd-levels-only' is set.
6326 - the TODO keyword, or nil
6327 - the priority character, like ?A, or nil if no priority is given
6328 - the headline text itself, or the tags string if no headline text
6329 - the tags string, or nil."
6331 (org-back-to-heading t)
6332 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6333 (list (length (match-string 1))
6334 (org-reduced-level (length (match-string 1)))
6335 (org-match-string-no-properties 2)
6336 (and (match-end 3) (aref (match-string 3) 2))
6337 (org-match-string-no-properties 4)
6338 (org-match-string-no-properties 5)))))
6340 (defun org-get-entry ()
6341 "Get the entry text, after heading, entire subtree."
6343 (org-back-to-heading t)
6344 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6346 (defun org-insert-heading-after-current ()
6347 "Insert a new heading with same level as current, after current subtree."
6349 (org-back-to-heading)
6350 (org-insert-heading)
6351 (org-move-subtree-down)
6354 (defun org-insert-heading-respect-content ()
6356 (let ((org-insert-heading-respect-content t))
6357 (org-insert-heading t)))
6359 (defun org-insert-todo-heading-respect-content (&optional force-state)
6361 (let ((org-insert-heading-respect-content t))
6362 (org-insert-todo-heading force-state t)))
6364 (defun org-insert-todo-heading (arg &optional force-heading)
6365 "Insert a new heading with the same level and TODO state as current heading.
6366 If the heading has no TODO state, or if the state is DONE, use the first
6367 state (TODO by default). Also with prefix arg, force first state."
6369 (when (or force-heading (not (org-insert-item 'checkbox)))
6370 (org-insert-heading force-heading)
6372 (org-back-to-heading)
6373 (outline-previous-heading)
6374 (looking-at org-todo-line-regexp))
6378 (not (match-beginning 2))
6379 (member (match-string 2) org-done-keywords))
6380 (car org-todo-keywords-1)
6384 (run-hook-with-args-until-success
6385 'org-todo-get-default-hook new-mark-x nil)
6387 (beginning-of-line 1)
6388 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6389 (if org-treat-insert-todo-heading-as-state-change
6391 (insert new-mark " "))))
6392 (when org-provide-todo-statistics
6393 (org-update-parent-todo-statistics))))
6395 (defun org-insert-subheading (arg)
6396 "Insert a new subheading and demote it.
6397 Works for outline headings and for plain lists alike."
6399 (org-insert-heading arg)
6401 ((org-on-heading-p) (org-do-demote))
6402 ((org-at-item-p) (org-indent-item 1))))
6404 (defun org-insert-todo-subheading (arg)
6405 "Insert a new subheading with TODO keyword or checkbox and demote it.
6406 Works for outline headings and for plain lists alike."
6408 (org-insert-todo-heading arg)
6410 ((org-on-heading-p) (org-do-demote))
6411 ((org-at-item-p) (org-indent-item 1))))
6413 ;;; Promotion and Demotion
6415 (defvar org-after-demote-entry-hook nil
6416 "Hook run after an entry has been demoted.
6417 The cursor will be at the beginning of the entry.
6418 When a subtree is being demoted, the hook will be called for each node.")
6420 (defvar org-after-promote-entry-hook nil
6421 "Hook run after an entry has been promoted.
6422 The cursor will be at the beginning of the entry.
6423 When a subtree is being promoted, the hook will be called for each node.")
6425 (defun org-promote-subtree ()
6426 "Promote the entire subtree.
6427 See also `org-promote'."
6430 (org-map-tree 'org-promote))
6431 (org-fix-position-after-promote))
6433 (defun org-demote-subtree ()
6434 "Demote the entire subtree. See `org-demote'.
6435 See also `org-promote'."
6438 (org-map-tree 'org-demote))
6439 (org-fix-position-after-promote))
6442 (defun org-do-promote ()
6443 "Promote the current heading higher up the tree.
6444 If the region is active in `transient-mark-mode', promote all headings
6448 (if (org-region-active-p)
6449 (org-map-region 'org-promote (region-beginning) (region-end))
6451 (org-fix-position-after-promote))
6453 (defun org-do-demote ()
6454 "Demote the current heading lower down the tree.
6455 If the region is active in `transient-mark-mode', demote all headings
6459 (if (org-region-active-p)
6460 (org-map-region 'org-demote (region-beginning) (region-end))
6462 (org-fix-position-after-promote))
6464 (defun org-fix-position-after-promote ()
6465 "Make sure that after pro/demotion cursor position is right."
6466 (let ((pos (point)))
6467 (when (save-excursion
6468 (beginning-of-line 1)
6469 (looking-at org-todo-line-regexp)
6470 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6471 (cond ((eobp) (insert " "))
6472 ((eolp) (insert " "))
6473 ((equal (char-after) ?\ ) (forward-char 1))))))
6475 (defun org-current-level ()
6476 "Return the level of the current entry, or nil if before the first headline.
6477 The level is the number of stars at the beginning of the headline."
6481 (org-back-to-heading t)
6482 (funcall outline-level))
6485 (defun org-get-previous-line-level ()
6486 "Return the outline depth of the last headline before the current line.
6487 Returns 0 for the first headline in the buffer, and nil if before the
6489 (let ((current-level (org-current-level))
6490 (prev-level (when (> (line-number-at-pos) 1)
6492 (beginning-of-line 0)
6493 (org-current-level)))))
6494 (cond ((null current-level) nil) ; Before first headline
6495 ((null prev-level) 0) ; At first headline
6498 (defun org-reduced-level (l)
6499 "Compute the effective level of a heading.
6500 This takes into account the setting of `org-odd-levels-only'."
6501 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6503 (defun org-level-increment ()
6504 "Return the number of stars that will be added or removed at a
6505 time to headlines when structure editing, based on the value of
6506 `org-odd-levels-only'."
6507 (if org-odd-levels-only 2 1))
6509 (defun org-get-valid-level (level &optional change)
6510 "Rectify a level change under the influence of `org-odd-levels-only'
6511 LEVEL is a current level, CHANGE is by how much the level should be
6512 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6513 even level numbers will become the next higher odd number."
6514 (if org-odd-levels-only
6515 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6516 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6517 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6518 (max 1 (+ level (or change 0)))))
6520 (if (boundp 'define-obsolete-function-alias)
6521 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6522 (define-obsolete-function-alias 'org-get-legal-level
6523 'org-get-valid-level)
6524 (define-obsolete-function-alias 'org-get-legal-level
6525 'org-get-valid-level "23.1")))
6527 (defun org-promote ()
6528 "Promote the current heading higher up the tree.
6529 If the region is active in `transient-mark-mode', promote all headings
6531 (org-back-to-heading t)
6532 (let* ((level (save-match-data (funcall outline-level)))
6533 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6534 (diff (abs (- level (length up-head) -1))))
6535 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6536 (replace-match up-head nil t)
6537 ;; Fixup tag positioning
6538 (and org-auto-align-tags (org-set-tags nil t))
6539 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6540 (run-hooks 'org-after-promote-entry-hook)))
6542 (defun org-demote ()
6543 "Demote the current heading lower down the tree.
6544 If the region is active in `transient-mark-mode', demote all headings
6546 (org-back-to-heading t)
6547 (let* ((level (save-match-data (funcall outline-level)))
6548 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6549 (diff (abs (- level (length down-head) -1))))
6550 (replace-match down-head nil t)
6551 ;; Fixup tag positioning
6552 (and org-auto-align-tags (org-set-tags nil t))
6553 (if org-adapt-indentation (org-fixup-indentation diff))
6554 (run-hooks 'org-after-demote-entry-hook)))
6556 (defun org-cycle-level ()
6557 "Cycle the level of an empty headline through possible states.
6558 This goes first to child, then to parent, level, then up the hierarchy.
6559 After top level, it switches back to sibling level."
6561 (let ((org-adapt-indentation nil))
6562 (when (org-point-at-end-of-empty-headline)
6563 (setq this-command 'org-cycle-level) ; Only needed for caching
6564 (let ((cur-level (org-current-level))
6565 (prev-level (org-get-previous-line-level)))
6567 ;; If first headline in file, promote to top-level.
6569 (loop repeat (/ (- cur-level 1) (org-level-increment))
6570 do (org-do-promote)))
6571 ;; If same level as prev, demote one.
6572 ((= prev-level cur-level)
6574 ;; If parent is top-level, promote to top level if not already.
6576 (loop repeat (/ (- cur-level 1) (org-level-increment))
6577 do (org-do-promote)))
6578 ;; If top-level, return to prev-level.
6580 (loop repeat (/ (- prev-level 1) (org-level-increment))
6581 do (org-do-demote)))
6582 ;; If less than prev-level, promote one.
6583 ((< cur-level prev-level)
6585 ;; If deeper than prev-level, promote until higher than
6587 ((> cur-level prev-level)
6588 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6589 do (org-do-promote))))
6592 (defun org-map-tree (fun)
6593 "Call FUN for every heading underneath the current one."
6594 (org-back-to-heading)
6595 (let ((level (funcall outline-level)))
6599 (outline-next-heading)
6600 (> (funcall outline-level) level))
6604 (defun org-map-region (fun beg end)
6605 "Call FUN for every heading between BEG and END."
6606 (let ((org-ignore-region t))
6608 (setq end (copy-marker end))
6610 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6614 (outline-next-heading)
6619 (defun org-fixup-indentation (diff)
6620 "Change the indentation in the current entry by DIFF
6621 However, if any line in the current entry has no indentation, or if it
6622 would end up with no indentation after the change, nothing at all is done."
6624 (let ((end (save-excursion (outline-next-heading)
6626 (prohibit (if (> diff 0)
6628 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6630 (unless (save-excursion (end-of-line 1)
6631 (re-search-forward prohibit end t))
6632 (while (and (< (point) end)
6633 (re-search-forward "^[ \t]+" end t))
6634 (goto-char (match-end 0))
6635 (setq col (current-column))
6636 (if (< diff 0) (replace-match ""))
6637 (org-indent-to-column (+ diff col))))
6638 (move-marker end nil))))
6640 (defun org-convert-to-odd-levels ()
6641 "Convert an org-mode file with all levels allowed to one with odd levels.
6642 This will leave level 1 alone, convert level 2 to level 3, level 3 to
6645 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
6646 (let ((outline-regexp org-outline-regexp)
6647 (outline-level 'org-outline-level)
6648 (org-odd-levels-only nil) n)
6650 (goto-char (point-min))
6651 (while (re-search-forward "^\\*\\*+ " nil t)
6652 (setq n (- (length (match-string 0)) 2))
6653 (while (>= (setq n (1- n)) 0)
6655 (end-of-line 1))))))
6657 (defun org-convert-to-oddeven-levels ()
6658 "Convert an org-mode file with only odd levels to one with odd and even levels.
6659 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
6660 section with an even level, conversion would destroy the structure of the file. An error
6661 is signaled in this case."
6663 (goto-char (point-min))
6664 ;; First check if there are no even levels
6665 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
6666 (org-show-context t)
6667 (error "Not all levels are odd in this file. Conversion not possible"))
6668 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
6669 (let ((outline-regexp org-outline-regexp)
6670 (outline-level 'org-outline-level)
6671 (org-odd-levels-only nil) n)
6673 (goto-char (point-min))
6674 (while (re-search-forward "^\\*\\*+ " nil t)
6675 (setq n (/ (1- (length (match-string 0))) 2))
6676 (while (>= (setq n (1- n)) 0)
6678 (end-of-line 1))))))
6680 (defun org-tr-level (n)
6681 "Make N odd if required."
6682 (if org-odd-levels-only (1+ (/ n 2)) n))
6684 ;;; Vertical tree motion, cutting and pasting of subtrees
6686 (defun org-move-subtree-up (&optional arg)
6687 "Move the current subtree up past ARG headlines of the same level."
6689 (org-move-subtree-down (- (prefix-numeric-value arg))))
6691 (defun org-move-subtree-down (&optional arg)
6692 "Move the current subtree down past ARG headlines of the same level."
6694 (setq arg (prefix-numeric-value arg))
6695 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
6696 'org-get-last-sibling))
6697 (ins-point (make-marker))
6699 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
6701 (org-back-to-heading)
6704 (setq ne-beg (org-back-over-empty-lines))
6707 (save-excursion (outline-end-of-heading)
6708 (setq folded (org-invisible-p)))
6709 (outline-end-of-subtree))
6710 (outline-next-heading)
6711 (setq ne-end (org-back-over-empty-lines))
6714 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
6715 ;; include less whitespace
6718 (forward-line (- ne-beg ne-end))
6719 (setq beg (point))))
6720 ;; Find insertion point, with error handling
6722 (or (and (funcall movfunc) (looking-at outline-regexp))
6723 (progn (goto-char beg0)
6724 (error "Cannot move past superior level or buffer limit")))
6725 (setq cnt (1- cnt)))
6727 ;; Moving forward - still need to move over subtree
6728 (progn (org-end-of-subtree t t)
6730 (org-back-over-empty-lines)
6731 (or (bolp) (newline)))))
6732 (setq ne-ins (org-back-over-empty-lines))
6733 (move-marker ins-point (point))
6734 (setq txt (buffer-substring beg end))
6735 (org-save-markers-in-region beg end)
6736 (delete-region beg end)
6737 (org-remove-empty-overlays-at beg)
6738 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
6739 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
6740 (and (not (bolp)) (looking-at "\n") (forward-char 1))
6741 (let ((bbb (point)))
6742 (insert-before-markers txt)
6743 (org-reinstall-markers-in-region bbb)
6744 (move-marker ins-point bbb))
6745 (or (bolp) (insert "\n"))
6746 (setq ins-end (point))
6747 (goto-char ins-point)
6748 (org-skip-whitespace)
6749 (when (and (< arg 0)
6750 (org-first-sibling-p)
6752 ;; Move whitespace back to beginning
6755 (let ((kill-whole-line t))
6756 (kill-line (- ne-ins ne-beg)) (point)))
6757 (insert (make-string (- ne-ins ne-beg) ?\n)))
6758 (move-marker ins-point nil)
6763 (org-cycle-hide-drawers 'children))
6764 (org-clean-visibility-after-subtree-move)))
6766 (defvar org-subtree-clip ""
6767 "Clipboard for cut and paste of subtrees.
6768 This is actually only a copy of the kill, because we use the normal kill
6769 ring. We need it to check if the kill was created by `org-copy-subtree'.")
6771 (defvar org-subtree-clip-folded nil
6772 "Was the last copied subtree folded?
6773 This is used to fold the tree back after pasting.")
6775 (defun org-cut-subtree (&optional n)
6776 "Cut the current subtree into the clipboard.
6777 With prefix arg N, cut this many sequential subtrees.
6778 This is a short-hand for marking the subtree and then cutting it."
6780 (org-copy-subtree n 'cut))
6782 (defun org-copy-subtree (&optional n cut force-store-markers)
6783 "Cut the current subtree into the clipboard.
6784 With prefix arg N, cut this many sequential subtrees.
6785 This is a short-hand for marking the subtree and then copying it.
6786 If CUT is non-nil, actually cut the subtree.
6787 If FORCE-STORE-MARKERS is non-nil, store the relative locations
6788 of some markers in the region, even if CUT is non-nil. This is
6789 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
6791 (let (beg end folded (beg0 (point)))
6793 (org-back-to-heading nil) ; take what looks like a subtree
6794 (org-back-to-heading t)) ; take what is really there
6795 (org-back-over-empty-lines)
6797 (skip-chars-forward " \t\r\n")
6799 (save-excursion (outline-end-of-heading)
6800 (setq folded (org-invisible-p)))
6802 (org-forward-same-level (1- n) t)
6804 (org-end-of-subtree t t))
6805 (org-back-over-empty-lines)
6809 (setq org-subtree-clip-folded folded)
6810 (when (or cut force-store-markers)
6811 (org-save-markers-in-region beg end))
6812 (if cut (kill-region beg end) (copy-region-as-kill beg end))
6813 (setq org-subtree-clip (current-kill 0))
6814 (message "%s: Subtree(s) with %d characters"
6815 (if cut "Cut" "Copied")
6816 (length org-subtree-clip)))))
6818 (defun org-paste-subtree (&optional level tree for-yank)
6819 "Paste the clipboard as a subtree, with modification of headline level.
6820 The entire subtree is promoted or demoted in order to match a new headline
6823 If the cursor is at the beginning of a headline, the same level as
6824 that headline is used to paste the tree
6826 If not, the new level is derived from the *visible* headings
6827 before and after the insertion point, and taken to be the inferior headline
6828 level of the two. So if the previous visible heading is level 3 and the
6829 next is level 4 (or vice versa), level 4 will be used for insertion.
6830 This makes sure that the subtree remains an independent subtree and does
6831 not swallow low level entries.
6833 You can also force a different level, either by using a numeric prefix
6834 argument, or by inserting the heading marker by hand. For example, if the
6835 cursor is after \"*****\", then the tree will be shifted to level 5.
6837 If optional TREE is given, use this text instead of the kill ring.
6839 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
6840 move back over whitespace before inserting, and move point to the end of
6841 the inserted text when done."
6843 (setq tree (or tree (and kill-ring (current-kill 0))))
6844 (unless (org-kill-is-subtree-p tree)
6846 (substitute-command-keys
6847 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
6848 (let* ((visp (not (org-invisible-p)))
6850 (^re (concat "^\\(" outline-regexp "\\)"))
6851 (re (concat "\\(" outline-regexp "\\)"))
6852 (^re_ (concat "\\(\\*+\\)[ \t]*"))
6854 (old-level (if (string-match ^re txt)
6855 (- (match-end 0) (match-beginning 0) 1)
6857 (force-level (cond (level (prefix-numeric-value level))
6858 ((and (looking-at "[ \t]*$")
6860 ^re_ (buffer-substring
6861 (point-at-bol) (point))))
6862 (- (match-end 1) (match-beginning 1)))
6864 (looking-at org-outline-regexp))
6865 (- (match-end 0) (point) 1))
6867 (previous-level (save-excursion
6870 (outline-previous-visible-heading 1)
6872 (- (match-end 0) (match-beginning 0) 1)
6875 (next-level (save-excursion
6878 (or (looking-at outline-regexp)
6879 (outline-next-visible-heading 1))
6881 (- (match-end 0) (match-beginning 0) 1)
6884 (new-level (or force-level (max previous-level next-level)))
6885 (shift (if (or (= old-level -1)
6887 (= old-level new-level))
6889 (- new-level old-level)))
6890 (delta (if (> shift 0) -1 1))
6891 (func (if (> shift 0) 'org-demote 'org-promote))
6892 (org-odd-levels-only nil)
6894 ;; Remove the forced level indicator
6896 (delete-region (point-at-bol) (point)))
6898 (beginning-of-line 1)
6899 (unless for-yank (org-back-over-empty-lines))
6901 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
6902 (insert-before-markers txt)
6903 (unless (string-match "\n\\'" txt) (insert "\n"))
6904 (setq newend (point))
6905 (org-reinstall-markers-in-region beg)
6908 (skip-chars-forward " \t\n\r")
6910 (if (and (org-invisible-p) visp)
6911 (save-excursion (outline-show-heading)))
6912 ;; Shift if necessary
6915 (narrow-to-region beg end)
6916 (while (not (= shift 0))
6917 (org-map-region func (point-min) (point-max))
6918 (setq shift (+ delta shift)))
6919 (goto-char (point-min))
6920 (setq newend (point-max))))
6921 (when (or (interactive-p) for-yank)
6922 (message "Clipboard pasted as level %d subtree" new-level))
6923 (if (and (not for-yank) ; in this case, org-yank will decide about folding
6925 (eq org-subtree-clip (current-kill 0))
6926 org-subtree-clip-folded)
6927 ;; The tree was folded before it was killed/copied
6929 (and for-yank (goto-char newend))))
6931 (defun org-kill-is-subtree-p (&optional txt)
6932 "Check if the current kill is an outline subtree, or a set of trees.
6933 Returns nil if kill does not start with a headline, or if the first
6934 headline level is not the largest headline level in the tree.
6935 So this will actually accept several entries of equal levels as well,
6936 which is OK for `org-paste-subtree'.
6937 If optional TXT is given, check this string instead of the current kill."
6938 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
6939 (start-level (and kill
6940 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
6941 org-outline-regexp "\\)")
6943 (- (match-end 2) (match-beginning 2) 1)))
6944 (re (concat "^" org-outline-regexp))
6945 (start (1+ (or (match-beginning 2) -1))))
6946 (if (not start-level)
6948 nil) ;; does not even start with a heading
6950 (while (setq start (string-match re kill (1+ start)))
6951 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
6955 (defvar org-markers-to-move nil
6956 "Markers that should be moved with a cut-and-paste operation.
6957 Those markers are stored together with their positions relative to
6958 the start of the region.")
6960 (defun org-save-markers-in-region (beg end)
6961 "Check markers in region.
6962 If these markers are between BEG and END, record their position relative
6963 to BEG, so that after moving the block of text, we can put the markers back
6965 This function gets called just before an entry or tree gets cut from the
6966 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
6967 called immediately, to move the markers with the entries."
6968 (setq org-markers-to-move nil)
6969 (when (featurep 'org-clock)
6970 (org-clock-save-markers-for-cut-and-paste beg end))
6971 (when (featurep 'org-agenda)
6972 (org-agenda-save-markers-for-cut-and-paste beg end)))
6974 (defun org-check-and-save-marker (marker beg end)
6975 "Check if MARKER is between BEG and END.
6976 If yes, remember the marker and the distance to BEG."
6977 (when (and (marker-buffer marker)
6978 (equal (marker-buffer marker) (current-buffer)))
6979 (if (and (>= marker beg) (< marker end))
6980 (push (cons marker (- marker beg)) org-markers-to-move))))
6982 (defun org-reinstall-markers-in-region (beg)
6983 "Move all remembered markers to their position relative to BEG."
6985 (move-marker (car x) (+ beg (cdr x))))
6986 org-markers-to-move)
6987 (setq org-markers-to-move nil))
6989 (defun org-narrow-to-subtree ()
6990 "Narrow buffer to the current subtree."
6995 (progn (org-back-to-heading t) (point))
6996 (progn (org-end-of-subtree t t)
6997 (if (org-on-heading-p) (backward-char 1))
7000 (defun org-clone-subtree-with-time-shift (n &optional shift)
7001 "Clone the task (subtree) at point N times.
7002 The clones will be inserted as siblings.
7004 In interactive use, the user will be prompted for the number of clones
7005 to be produced, and for a time SHIFT, which may be a repeater as used
7006 in time stamps, for example `+3d'.
7008 When a valid repeater is given and the entry contains any time stamps,
7009 the clones will become a sequence in time, with time stamps in the
7010 subtree shifted for each clone produced. If SHIFT is nil or the
7011 empty string, time stamps will be left alone.
7013 If the original subtree did contain time stamps with a repeater,
7014 the following will happen:
7015 - the repeater will be removed in each clone
7016 - an additional clone will be produced, with the current, unshifted
7017 date(s) in the entry.
7018 - the original entry will be placed *after* all the clones, with
7020 - the start days in the repeater in the original entry will be shifted
7021 to past the last clone.
7022 I this way you can spell out a number of instances of a repeating task,
7023 and still retain the repeater to cover future instances of the task."
7024 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7025 (let (beg end template task
7026 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7027 (if (not (and (integerp n) (> n 0)))
7028 (error "Invalid number of replications %s" n))
7029 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7030 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7032 (error "Invalid shift specification %s" shift))
7034 (setq shift-n (string-to-number (match-string 1 shift))
7035 shift-what (cdr (assoc (match-string 2 shift)
7036 '(("d" . day) ("w" . week)
7037 ("m" . month) ("y" . year))))))
7038 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7039 (setq nmin 1 nmax n)
7040 (org-back-to-heading t)
7042 (org-end-of-subtree t t)
7043 (or (bolp) (insert "\n"))
7045 (setq template (buffer-substring beg end))
7047 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7048 (delete-region beg end)
7050 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7052 (loop for n from nmin to nmax do
7054 (setq task template)
7058 (goto-char (point-min))
7059 (while (re-search-forward org-ts-regexp-both nil t)
7060 (org-timestamp-change (* n shift-n) shift-what))
7061 (unless (= n n-no-remove)
7062 (goto-char (point-min))
7063 (while (re-search-forward org-ts-regexp nil t)
7065 (goto-char (match-beginning 0))
7066 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7067 (delete-region (match-beginning 1) (match-end 1))))))
7068 (setq task (buffer-string))))
7074 (defun org-sort (with-case)
7075 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7076 Optional argument WITH-CASE means sort case-sensitively.
7077 With a double prefix argument, also remove duplicate entries."
7079 (if (org-at-table-p)
7080 (org-call-with-arg 'org-table-sort-lines with-case)
7081 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7083 (defun org-sort-remove-invisible (s)
7084 (remove-text-properties 0 (length s) org-rm-props s)
7085 (while (string-match org-bracket-link-regexp s)
7086 (setq s (replace-match (if (match-end 2)
7088 (match-string 1 s)) t t s)))
7091 (defvar org-priority-regexp) ; defined later in the file
7093 (defvar org-after-sorting-entries-or-items-hook nil
7094 "Hook that is run after a bunch of entries or items have been sorted.
7095 When children are sorted, the cursor is in the parent line when this
7096 hook gets called. When a region or a plain list is sorted, the cursor
7097 will be in the first entry of the sorted region/list.")
7099 (defun org-sort-entries-or-items
7100 (&optional with-case sorting-type getkey-func compare-func property)
7101 "Sort entries on a certain level of an outline tree, or plain list items.
7102 If there is an active region, the entries in the region are sorted.
7103 Else, if the cursor is before the first entry, sort the top-level items.
7104 Else, the children of the entry at point are sorted.
7105 If the cursor is at the first item in a plain list, the list items will be
7108 Sorting can be alphabetically, numerically, by date/time as given by
7109 a time stamp, by a property or by priority.
7111 The command prompts for the sorting type unless it has been given to the
7112 function through the SORTING-TYPE argument, which needs to a character,
7113 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7114 precise meaning of each character:
7116 n Numerically, by converting the beginning of the entry/item to a number.
7117 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7118 t By date/time, either the first active time stamp in the entry, or, if
7119 none exist, by the first inactive one.
7120 In items, only the first line will be checked.
7121 s By the scheduled date/time.
7122 d By deadline date/time.
7123 c By creation time, which is assumed to be the first inactive time stamp
7124 at the beginning of a line.
7125 p By priority according to the cookie.
7126 r By the value of a property.
7128 Capital letters will reverse the sort order.
7130 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7131 called with point at the beginning of the record. It must return either
7132 a string or a number that should serve as the sorting key for that record.
7134 Comparing entries ignores case by default. However, with an optional argument
7135 WITH-CASE, the sorting considers case as well."
7137 (let ((case-func (if with-case 'identity 'downcase))
7138 start beg end stars re re2
7139 txt what tmp plain-list-p)
7140 ;; Find beginning and end of region to sort
7142 ((org-region-active-p)
7143 ;; we will sort the region
7144 (setq end (region-end)
7146 (goto-char (region-beginning))
7147 (if (not (org-on-heading-p)) (outline-next-heading))
7148 (setq start (point)))
7150 ;; we will sort this plain list
7151 (org-beginning-of-item-list) (setq start (point))
7152 (org-end-of-item-list)
7153 (or (bolp) (insert "\n"))
7156 (setq plain-list-p t
7158 ((or (org-on-heading-p)
7159 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7160 ;; we will sort the children of the current headline
7161 (org-back-to-heading)
7163 end (progn (org-end-of-subtree t t)
7164 (or (bolp) (insert "\n"))
7165 (org-back-over-empty-lines)
7170 (outline-next-heading))
7172 ;; we will sort the top-level entries in this file
7173 (goto-char (point-min))
7174 (or (org-on-heading-p) (outline-next-heading))
7175 (setq start (point))
7176 (goto-char (point-max))
7177 (beginning-of-line 1)
7178 (when (looking-at ".*?\\S-")
7179 ;; File ends in a non-white line
7182 (setq end (point-max))
7183 (setq what "top-level")
7188 (if (>= beg end) (error "Nothing to sort"))
7190 (unless plain-list-p
7191 (looking-at "\\(\\*+\\)")
7192 (setq stars (match-string 1)
7193 re (concat "^" (regexp-quote stars) " +")
7194 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7195 txt (buffer-substring beg end))
7196 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7197 (if (and (not (equal stars "*")) (string-match re2 txt))
7198 (error "Region to sort contains a level above the first entry")))
7200 (unless sorting-type
7203 "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
7204 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7205 [t]ime [s]cheduled [d]eadline [c]reated
7206 A/N/T/S/D/C/P/O/F means reversed:")
7208 (setq sorting-type (read-char-exclusive))
7210 (and (= (downcase sorting-type) ?f)
7212 (org-icompleting-read "Sort using function: "
7213 obarray 'fboundp t nil nil))
7214 (setq getkey-func (intern getkey-func)))
7216 (and (= (downcase sorting-type) ?r)
7218 (org-icompleting-read "Property: "
7219 (mapcar 'list (org-buffer-property-keys t))
7222 (message "Sorting entries...")
7225 (narrow-to-region start end)
7227 (let ((dcst (downcase sorting-type))
7228 (case-fold-search nil)
7229 (now (current-time)))
7231 (/= dcst sorting-type)
7232 ;; This function moves to the beginning character of the "record" to
7236 (if (org-at-item-p) t (goto-char (point-max))))
7238 (if (re-search-forward re nil t)
7239 (goto-char (match-beginning 0))
7240 (goto-char (point-max)))))
7241 ;; This function moves to the last character of the "record" being
7248 (outline-forward-same-level 1)
7250 (goto-char (point-max)))))))
7252 ;; This function returns the value that gets sorted against.
7255 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7258 (string-to-number (buffer-substring (match-end 0)
7261 (buffer-substring (match-end 0) (point-at-eol)))
7263 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7264 (re-search-forward org-ts-regexp-both
7266 (org-time-string-to-seconds (match-string 0))
7267 (org-float-time now)))
7271 (setq tmp (funcall getkey-func))
7272 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7274 (error "Invalid key function `%s'" getkey-func)))
7275 (t (error "Invalid sorting type `%c'" sorting-type)))))
7279 (if (looking-at org-complex-heading-regexp)
7280 (string-to-number (match-string 4))
7283 (if (looking-at org-complex-heading-regexp)
7284 (funcall case-func (match-string 4))
7287 (let ((end (save-excursion (outline-next-heading) (point))))
7288 (if (or (re-search-forward org-ts-regexp end t)
7289 (re-search-forward org-ts-regexp-both end t))
7290 (org-time-string-to-seconds (match-string 0))
7291 (org-float-time now))))
7293 (let ((end (save-excursion (outline-next-heading) (point))))
7294 (if (re-search-forward
7295 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7297 (org-time-string-to-seconds (match-string 0))
7298 (org-float-time now))))
7300 (let ((end (save-excursion (outline-next-heading) (point))))
7301 (if (re-search-forward org-scheduled-time-regexp end t)
7302 (org-time-string-to-seconds (match-string 1))
7303 (org-float-time now))))
7305 (let ((end (save-excursion (outline-next-heading) (point))))
7306 (if (re-search-forward org-deadline-time-regexp end t)
7307 (org-time-string-to-seconds (match-string 1))
7308 (org-float-time now))))
7310 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7311 (string-to-char (match-string 2))
7312 org-default-priority))
7314 (or (org-entry-get nil property) ""))
7316 (if (looking-at org-complex-heading-regexp)
7317 (- 9999 (length (member (match-string 2)
7318 org-todo-keywords-1)))))
7322 (setq tmp (funcall getkey-func))
7323 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7325 (error "Invalid key function `%s'" getkey-func)))
7326 (t (error "Invalid sorting type `%c'" sorting-type)))))
7329 ((= dcst ?a) 'string<)
7330 ((= dcst ?f) compare-func)
7331 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7333 (run-hooks 'org-after-sorting-entries-or-items-hook)
7334 (message "Sorting entries...done")))
7336 (defun org-do-sort (table what &optional with-case sorting-type)
7337 "Sort TABLE of WHAT according to SORTING-TYPE.
7338 The user will be prompted for the SORTING-TYPE if the call to this
7339 function does not specify it. WHAT is only for the prompt, to indicate
7340 what is being sorted. The sorting key will be extracted from
7341 the car of the elements of the table.
7342 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7343 (unless sorting-type
7345 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
7347 (setq sorting-type (read-char-exclusive)))
7348 (let ((dcst (downcase sorting-type))
7349 extractfun comparefun)
7350 ;; Define the appropriate functions
7353 (setq extractfun 'string-to-number
7354 comparefun (if (= dcst sorting-type) '< '>)))
7356 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7357 (lambda(x) (downcase (org-sort-remove-invisible x))))
7358 comparefun (if (= dcst sorting-type)
7360 (lambda (a b) (and (not (string< a b))
7361 (not (string= a b)))))))
7365 (if (or (string-match org-ts-regexp x)
7366 (string-match org-ts-regexp-both x))
7368 (org-time-string-to-time (match-string 0 x)))
7370 comparefun (if (= dcst sorting-type) '< '>)))
7371 (t (error "Invalid sorting type `%c'" sorting-type)))
7373 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7375 (lambda (a b) (funcall comparefun (car a) (car b))))))
7378 ;;; The orgstruct minor mode
7380 ;; Define a minor mode which can be used in other modes in order to
7381 ;; integrate the org-mode structure editing commands.
7383 ;; This is really a hack, because the org-mode structure commands use
7384 ;; keys which normally belong to the major mode. Here is how it
7385 ;; works: The minor mode defines all the keys necessary to operate the
7386 ;; structure commands, but wraps the commands into a function which
7387 ;; tests if the cursor is currently at a headline or a plain list
7388 ;; item. If that is the case, the structure command is used,
7389 ;; temporarily setting many Org-mode variables like regular
7390 ;; expressions for filling etc. However, when any of those keys is
7391 ;; used at a different location, function uses `key-binding' to look
7392 ;; up if the key has an associated command in another currently active
7393 ;; keymap (minor modes, major mode, global), and executes that
7394 ;; command. There might be problems if any of the keys is otherwise
7395 ;; used as a prefix key.
7397 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7398 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7399 ;; addresses this by checking explicitly for both bindings.
7401 (defvar orgstruct-mode-map (make-sparse-keymap)
7402 "Keymap for the minor `orgstruct-mode'.")
7404 (defvar org-local-vars nil
7405 "List of local variables, for use by `orgstruct-mode'")
7408 (define-minor-mode orgstruct-mode
7409 "Toggle the minor more `orgstruct-mode'.
7410 This mode is for using Org-mode structure commands in other modes.
7411 The following key behave as if Org-mode was active, if the cursor
7412 is on a headline, or on a plain list item (both in the definition
7415 M-up Move entry/item up
7416 M-down Move entry/item down
7419 M-S-up Move entry/item up
7420 M-S-down Move entry/item down
7421 M-S-left Promote subtree
7422 M-S-right Demote subtree
7423 M-q Fill paragraph and items like in Org-mode
7425 C-c - Cycle list bullet
7426 TAB Cycle item visibility
7427 M-RET Insert new heading/item
7428 S-M-RET Insert new TODO heading / Checkbox item
7429 C-c C-c Set tags / toggle checkbox"
7430 nil " OrgStruct" nil
7431 (org-load-modules-maybe)
7432 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7435 (defun turn-on-orgstruct ()
7436 "Unconditionally turn on `orgstruct-mode'."
7439 (defun orgstruct++-mode (&optional arg)
7440 "Toggle `orgstruct-mode', the enhanced version of it.
7441 In addition to setting orgstruct-mode, this also exports all indentation
7442 and autofilling variables from org-mode into the buffer. It will also
7443 recognize item context in multiline items.
7444 Note that turning off orgstruct-mode will *not* remove the
7445 indentation/paragraph settings. This can only be done by refreshing the
7446 major mode, for example with \\[normal-mode]."
7448 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7456 "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7457 (symbol-name (car x)))
7458 (setq var (car x) val (nth 1 x))
7459 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7461 (org-set-local 'orgstruct-is-++ t))))
7463 (defvar orgstruct-is-++ nil
7464 "Is orgstruct-mode in ++ version in the current-buffer?")
7465 (make-variable-buffer-local 'orgstruct-is-++)
7468 (defun turn-on-orgstruct++ ()
7469 "Unconditionally turn on `orgstruct++-mode'."
7470 (orgstruct++-mode 1))
7472 (defun orgstruct-error ()
7473 "Error when there is no default binding for a structure key."
7475 (error "This key has no function outside structure elements"))
7477 (defun orgstruct-setup ()
7478 "Setup orgstruct keymaps."
7482 '([(meta up)] org-metaup)
7483 '([(meta down)] org-metadown)
7484 '([(meta left)] org-metaleft)
7485 '([(meta right)] org-metaright)
7486 '([(meta shift up)] org-shiftmetaup)
7487 '([(meta shift down)] org-shiftmetadown)
7488 '([(meta shift left)] org-shiftmetaleft)
7489 '([(meta shift right)] org-shiftmetaright)
7490 '([?\e (up)] org-metaup)
7491 '([?\e (down)] org-metadown)
7492 '([?\e (left)] org-metaleft)
7493 '([?\e (right)] org-metaright)
7494 '([?\e (shift up)] org-shiftmetaup)
7495 '([?\e (shift down)] org-shiftmetadown)
7496 '([?\e (shift left)] org-shiftmetaleft)
7497 '([?\e (shift right)] org-shiftmetaright)
7498 '([(shift up)] org-shiftup)
7499 '([(shift down)] org-shiftdown)
7500 '([(shift left)] org-shiftleft)
7501 '([(shift right)] org-shiftright)
7502 '("\C-c\C-c" org-ctrl-c-ctrl-c)
7503 '("\M-q" fill-paragraph)
7505 '("\C-c-" org-cycle-list-bullet)))
7507 (while (setq elt (pop bindings))
7508 (setq nfunc (1+ nfunc))
7509 (setq key (org-key (car elt))
7511 cmd (orgstruct-make-binding fun nfunc key))
7512 (org-defkey orgstruct-mode-map key cmd))
7514 ;; Special treatment needed for TAB and RET
7515 (org-defkey orgstruct-mode-map [(tab)]
7516 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
7517 (org-defkey orgstruct-mode-map "\C-i"
7518 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
7520 (org-defkey orgstruct-mode-map "\M-\C-m"
7521 (orgstruct-make-binding 'org-insert-heading 105
7522 "\M-\C-m" [(meta return)]))
7523 (org-defkey orgstruct-mode-map [(meta return)]
7524 (orgstruct-make-binding 'org-insert-heading 106
7525 [(meta return)] "\M-\C-m"))
7527 (org-defkey orgstruct-mode-map [(shift meta return)]
7528 (orgstruct-make-binding 'org-insert-todo-heading 107
7529 [(meta return)] "\M-\C-m"))
7531 (org-defkey orgstruct-mode-map "\e\C-m"
7532 (orgstruct-make-binding 'org-insert-heading 108
7533 "\e\C-m" [?\e (return)]))
7534 (org-defkey orgstruct-mode-map [?\e (return)]
7535 (orgstruct-make-binding 'org-insert-heading 109
7536 [?\e (return)] "\e\C-m"))
7537 (org-defkey orgstruct-mode-map [?\e (shift return)]
7538 (orgstruct-make-binding 'org-insert-todo-heading 110
7539 [?\e (return)] "\e\C-m"))
7541 (unless org-local-vars
7542 (setq org-local-vars (org-get-local-variables)))
7546 (defun orgstruct-make-binding (fun n &rest keys)
7547 "Create a function for binding in the structure minor mode.
7548 FUN is the command to call inside a table. N is used to create a unique
7549 command name. KEYS are keys that should be checked in for a command
7550 to execute outside of tables."
7553 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
7555 (concat "In Structure, run `" (symbol-name fun) "'.\n"
7556 "Outside of structure, run the binding of `"
7557 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
7561 `(org-context-p 'headline 'item
7562 (and orgstruct-is-++
7563 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7565 (list 'org-run-like-in-org-mode (list 'quote fun))
7566 (list 'let '(orgstruct-mode)
7567 (list 'call-interactively
7570 (list 'key-binding k))
7572 '('orgstruct-error))))))))
7574 (defun org-context-p (&rest contexts)
7575 "Check if local context is any of CONTEXTS.
7576 Possible values in the list of contexts are `table', `headline', and `item'."
7577 (let ((pos (point)))
7578 (goto-char (point-at-bol))
7579 (prog1 (or (and (memq 'table contexts)
7580 (looking-at "[ \t]*|"))
7581 (and (memq 'headline contexts)
7582 ;;????????? (looking-at "\\*+"))
7583 (looking-at outline-regexp))
7584 (and (memq 'item contexts)
7585 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
7586 (and (memq 'item-body contexts)
7590 (defun org-get-local-variables ()
7591 "Return a list of all local variables in an org-mode buffer."
7593 (with-current-buffer (get-buffer-create "*Org tmp*")
7596 (setq varlist (buffer-local-variables)))
7597 (kill-buffer "*Org tmp*")
7604 (list (car x) (list 'quote (cdr x)))))
7606 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7607 (symbol-name (car x)))
7612 (defun org-run-like-in-org-mode (cmd)
7613 "Run a command, pretending that the current buffer is in Org-mode.
7614 This will temporarily bind local variables that are typically bound in
7615 Org-mode to the values they have in Org-mode, and then interactively
7617 (org-load-modules-maybe)
7618 (unless org-local-vars
7619 (setq org-local-vars (org-get-local-variables)))
7620 (eval (list 'let org-local-vars
7621 (list 'call-interactively (list 'quote cmd)))))
7625 (defun org-get-category (&optional pos)
7626 "Get the category applying to position POS."
7627 (get-text-property (or pos (point)) 'org-category))
7629 (defun org-refresh-category-properties ()
7630 "Refresh category text properties in the buffer."
7631 (let ((def-cat (cond
7632 ((null org-category)
7633 (if buffer-file-name
7634 (file-name-sans-extension
7635 (file-name-nondirectory buffer-file-name))
7637 ((symbolp org-category) (symbol-name org-category))
7639 beg end cat pos optionp)
7644 (goto-char (point-min))
7645 (put-text-property (point) (point-max) 'org-category def-cat)
7646 (while (re-search-forward
7647 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
7648 (setq pos (match-end 0)
7649 optionp (equal (char-after (match-beginning 0)) ?#)
7650 cat (org-trim (match-string 2)))
7652 (setq beg (point-at-bol) end (point-max))
7653 (org-back-to-heading t)
7654 (setq beg (point) end (org-end-of-subtree t t)))
7655 (put-text-property beg end 'org-category cat)
7656 (goto-char pos)))))))
7661 ;;; Link abbreviations
7663 (defun org-link-expand-abbrev (link)
7664 "Apply replacements as defined in `org-link-abbrev-alist."
7665 (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
7666 (let* ((key (match-string 1 link))
7667 (as (or (assoc key org-link-abbrev-alist-local)
7668 (assoc key org-link-abbrev-alist)))
7669 (tag (and (match-end 2) (match-string 3 link)))
7675 ((symbolp rpl) (funcall rpl tag))
7676 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
7677 ((string-match "%h" rpl)
7678 (replace-match (url-hexify-string (or tag "")) t t rpl))
7679 (t (concat rpl tag)))))
7682 ;;; Storing and inserting links
7684 (defvar org-insert-link-history nil
7685 "Minibuffer history for links inserted with `org-insert-link'.")
7687 (defvar org-stored-links nil
7688 "Contains the links stored with `org-store-link'.")
7690 (defvar org-store-link-plist nil
7691 "Plist with info about the most recently link created with `org-store-link'.")
7693 (defvar org-link-protocols nil
7694 "Link protocols added to Org-mode using `org-add-link-type'.")
7696 (defvar org-store-link-functions nil
7697 "List of functions that are called to create and store a link.
7698 Each function will be called in turn until one returns a non-nil
7699 value. Each function should check if it is responsible for creating
7700 this link (for example by looking at the major mode).
7701 If not, it must exit and return nil.
7702 If yes, it should return a non-nil value after a calling
7703 `org-store-link-props' with a list of properties and values.
7704 Special properties are:
7706 :type The link prefix. like \"http\". This must be given.
7707 :link The link, like \"http://www.astro.uva.nl/~dominik\".
7708 This is obligatory as well.
7709 :description Optional default description for the second pair
7710 of brackets in an Org-mode link. The user can still change
7711 this when inserting this link into an Org-mode buffer.
7713 In addition to these, any additional properties can be specified
7714 and then used in remember templates.")
7716 (defun org-add-link-type (type &optional follow export)
7717 "Add TYPE to the list of `org-link-types'.
7718 Re-compute all regular expressions depending on `org-link-types'
7720 FOLLOW and EXPORT are two functions.
7722 FOLLOW should take the link path as the single argument and do whatever
7723 is necessary to follow the link, for example find a file or display
7726 EXPORT should format the link path for export to one of the export formats.
7727 It should be a function accepting three arguments:
7729 path the path of the link, the text after the prefix (like \"http:\")
7730 desc the description of the link, if any, nil if there was no description
7731 format the export format, a symbol like `html' or `latex'.
7733 The function may use the FORMAT information to return different values
7734 depending on the format. The return value will be put literally into
7736 Org-mode has a built-in default for exporting links. If you are happy with
7737 this default, there is no need to define an export function for the link
7738 type. For a simple example of an export function, see `org-bbdb.el'."
7739 (add-to-list 'org-link-types type t)
7740 (org-make-link-regexps)
7741 (if (assoc type org-link-protocols)
7742 (setcdr (assoc type org-link-protocols) (list follow export))
7743 (push (list type follow export) org-link-protocols)))
7745 (defvar org-agenda-buffer-name)
7748 (defun org-store-link (arg)
7749 "\\<org-mode-map>Store an org-link to the current location.
7750 This link is added to `org-stored-links' and can later be inserted
7751 into an org-buffer with \\[org-insert-link].
7753 For some link types, a prefix arg is interpreted:
7754 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
7755 For file links, arg negates `org-context-in-file-links'."
7757 (org-load-modules-maybe)
7758 (setq org-store-link-plist nil) ; reset
7759 (let ((outline-regexp (org-get-limited-outline-regexp))
7760 link cpltxt desc description search txt custom-id)
7763 ((run-hook-with-args-until-success 'org-store-link-functions)
7764 (setq link (plist-get org-store-link-plist :link)
7765 desc (or (plist-get org-store-link-plist :description) link)))
7767 ((equal (buffer-name) "*Org Edit Src Example*")
7769 (while (or (not label)
7773 (goto-char (point-min))
7775 (regexp-quote (format org-coderef-label-format label))
7777 (when label (message "Label exists already") (sit-for 2))
7778 (setq label (read-string "Code line label: " label)))
7780 (setq link (format org-coderef-label-format label))
7781 (setq gc (- 79 (length link)))
7782 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
7784 (setq link (concat "(" label ")") desc nil)))
7786 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
7787 ;; We are in the agenda, link to referenced location
7788 (let ((m (or (get-text-property (point) 'org-hd-marker)
7789 (get-text-property (point) 'org-marker))))
7791 (org-with-point-at m
7792 (call-interactively 'org-store-link)))))
7794 ((eq major-mode 'calendar-mode)
7795 (let ((cd (calendar-cursor-to-date)))
7798 (car org-time-stamp-formats)
7800 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
7802 (org-store-link-props :type "calendar" :date cd)))
7804 ((eq major-mode 'w3-mode)
7805 (setq cpltxt (if (and (buffer-name)
7806 (not (string-match "Untitled" (buffer-name))))
7809 link (org-make-link (url-view-url t)))
7810 (org-store-link-props :type "w3" :url (url-view-url t)))
7812 ((eq major-mode 'w3m-mode)
7813 (setq cpltxt (or w3m-current-title w3m-current-url)
7814 link (org-make-link w3m-current-url))
7815 (org-store-link-props :type "w3m" :url (url-view-url t)))
7817 ((setq search (run-hook-with-args-until-success
7818 'org-create-file-search-functions))
7819 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
7821 (setq cpltxt (or description link)))
7823 ((eq major-mode 'image-mode)
7824 (setq cpltxt (concat "file:"
7825 (abbreviate-file-name buffer-file-name))
7826 link (org-make-link cpltxt))
7827 (org-store-link-props :type "image" :file buffer-file-name))
7829 ((eq major-mode 'dired-mode)
7830 ;; link to the file in the current line
7831 (let ((file (dired-get-filename nil t)))
7833 (abbreviate-file-name
7834 (expand-file-name (dired-get-filename nil t)))
7835 ;; otherwise, no file so use current directory.
7837 (setq cpltxt (concat "file:" file)
7838 link (org-make-link cpltxt))))
7840 ((and buffer-file-name (org-mode-p))
7841 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID")))
7843 ((org-in-regexp "<<\\(.*?\\)>>")
7846 (abbreviate-file-name buffer-file-name)
7847 "::" (match-string 1))
7848 link (org-make-link cpltxt)))
7849 ((and (featurep 'org-id)
7850 (or (eq org-link-to-org-use-id t)
7851 (and (eq org-link-to-org-use-id 'create-if-interactive)
7853 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
7856 (and org-link-to-org-use-id
7858 (org-entry-get nil "ID")
7860 ;; We can make a link using the ID.
7861 (setq link (condition-case nil
7862 (prog1 (org-id-store-link)
7863 (setq desc (plist-get org-store-link-plist
7866 ;; probably before first headline, link to file only
7868 (abbreviate-file-name buffer-file-name))))))
7870 ;; Just link to current headline
7871 (setq cpltxt (concat "file:"
7872 (abbreviate-file-name buffer-file-name)))
7873 ;; Add a context search string
7874 (when (org-xor org-context-in-file-links arg)
7876 ((org-on-heading-p) nil)
7877 ((org-region-active-p)
7878 (buffer-substring (region-beginning) (region-end)))
7880 (when (or (null txt) (string-match "\\S-" txt))
7884 (org-make-org-heading-search-string txt)
7886 desc (or (nth 4 (ignore-errors
7887 (org-heading-components))) "NONE"))))
7888 (if (string-match "::\\'" cpltxt)
7889 (setq cpltxt (substring cpltxt 0 -2)))
7890 (setq link (org-make-link cpltxt)))))
7892 ((buffer-file-name (buffer-base-buffer))
7893 ;; Just link to this file here.
7894 (setq cpltxt (concat "file:"
7895 (abbreviate-file-name
7896 (buffer-file-name (buffer-base-buffer)))))
7897 ;; Add a context string
7898 (when (org-xor org-context-in-file-links arg)
7899 (setq txt (if (org-region-active-p)
7900 (buffer-substring (region-beginning) (region-end))
7901 (buffer-substring (point-at-bol) (point-at-eol))))
7902 ;; Only use search option if there is some text.
7903 (when (string-match "\\S-" txt)
7905 (concat cpltxt "::" (org-make-org-heading-search-string txt))
7907 (setq link (org-make-link cpltxt)))
7910 (error "Cannot link to a buffer which is not visiting a file"))
7912 (t (setq link nil)))
7914 (if (consp link) (setq cpltxt (car link) link (cdr link)))
7915 (setq link (or link cpltxt)
7916 desc (or desc cpltxt))
7917 (if (equal desc "NONE") (setq desc nil))
7919 (if (and (or (interactive-p) executing-kbd-macro) link)
7921 (setq org-stored-links
7922 (cons (list link desc) org-stored-links))
7923 (message "Stored: %s" (or desc link))
7925 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
7927 (setq org-stored-links
7928 (cons (list link desc) org-stored-links))))
7929 (and link (org-make-link-string link desc)))))
7931 (defun org-store-link-props (&rest plist)
7932 "Store link properties, extract names and addresses."
7934 (when (setq x (plist-get plist :from))
7935 (setq adr (mail-extract-address-components x))
7936 (setq plist (plist-put plist :fromname (car adr)))
7937 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
7938 (when (setq x (plist-get plist :to))
7939 (setq adr (mail-extract-address-components x))
7940 (setq plist (plist-put plist :toname (car adr)))
7941 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
7942 (let ((from (plist-get plist :from))
7943 (to (plist-get plist :to)))
7944 (when (and from to org-from-is-user-regexp)
7946 (plist-put plist :fromto
7947 (if (string-match org-from-is-user-regexp from)
7949 (concat "from %f"))))))
7950 (setq org-store-link-plist plist))
7952 (defun org-add-link-props (&rest plist)
7953 "Add these properties to the link property list."
7956 (setq key (pop plist) value (pop plist))
7957 (setq org-store-link-plist
7958 (plist-put org-store-link-plist key value)))))
7960 (defun org-email-link-description (&optional fmt)
7961 "Return the description part of an email link.
7962 This takes information from `org-store-link-plist' and formats it
7963 according to FMT (default from `org-email-link-description-format')."
7964 (setq fmt (or fmt org-email-link-description-format))
7965 (let* ((p org-store-link-plist)
7966 (to (plist-get p :toaddress))
7967 (from (plist-get p :fromaddress))
7970 (cons "%c" (plist-get p :fromto))
7971 (cons "%F" (plist-get p :from))
7972 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
7973 (cons "%T" (plist-get p :to))
7974 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
7975 (cons "%s" (plist-get p :subject))
7976 (cons "%m" (plist-get p :message-id)))))
7977 (when (string-match "%c" fmt)
7978 ;; Check if the user wrote this message
7979 (if (and org-from-is-user-regexp from to
7980 (save-match-data (string-match org-from-is-user-regexp from)))
7981 (setq fmt (replace-match "to %t" t t fmt))
7982 (setq fmt (replace-match "from %f" t t fmt))))
7983 (org-replace-escapes fmt table)))
7985 (defun org-make-org-heading-search-string (&optional string heading)
7986 "Make search string for STRING or current headline."
7988 (let ((s (or string (org-get-heading))))
7989 (unless (and string (not heading))
7990 ;; We are using a headline, clean up garbage in there.
7991 (if (string-match org-todo-regexp s)
7992 (setq s (replace-match "" t t s)))
7993 (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s)
7994 (setq s (replace-match "" t t s)))
7995 (setq s (org-trim s))
7996 (if (string-match (concat "^\\(" org-quote-string "\\|"
7997 org-comment-string "\\)") s)
7998 (setq s (replace-match "" t t s)))
7999 (while (string-match org-ts-regexp s)
8000 (setq s (replace-match "" t t s))))
8001 (while (string-match "[^a-zA-Z_0-9 \t]+" s)
8002 (setq s (replace-match " " t t s)))
8003 (or string (setq s (concat "*" s))) ; Add * for headlines
8004 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8006 (defun org-make-link (&rest strings)
8007 "Concatenate STRINGS."
8008 (apply 'concat strings))
8010 (defun org-make-link-string (link &optional description)
8011 "Make a link with brackets, consisting of LINK and DESCRIPTION."
8012 (unless (string-match "\\S-" link)
8013 (error "Empty link"))
8014 (when (and description
8015 (stringp description)
8016 (not (string-match "\\S-" description)))
8017 (setq description nil))
8018 (when (stringp description)
8019 ;; Remove brackets from the description, they are fatal.
8020 (while (string-match "\\[" description)
8021 (setq description (replace-match "{" t t description)))
8022 (while (string-match "\\]" description)
8023 (setq description (replace-match "}" t t description))))
8024 (when (equal (org-link-escape link) description)
8025 ;; No description needed, it is identical
8026 (setq description nil))
8027 (when (and (not description)
8028 (not (equal link (org-link-escape link))))
8029 (setq description (org-extract-attributes link)))
8030 (concat "[[" (org-link-escape link) "]"
8031 (if description (concat "[" description "]") "")
8034 (defconst org-link-escape-chars
8038 (?\340 . "%E0") ; `a
8039 (?\342 . "%E2") ; ^a
8040 (?\347 . "%E7") ; ,c
8041 (?\350 . "%E8") ; `e
8042 (?\351 . "%E9") ; 'e
8043 (?\352 . "%EA") ; ^e
8044 (?\356 . "%EE") ; ^i
8045 (?\364 . "%F4") ; ^o
8046 (?\371 . "%F9") ; `u
8047 (?\373 . "%FB") ; ^u
8053 "Association list of escapes for some characters problematic in links.
8054 This is the list that is used for internal purposes.")
8056 (defvar org-url-encoding-use-url-hexify nil)
8058 (defconst org-link-escape-chars-browser
8059 '((?\ . "%20")) ; 32 for the SPC char
8060 "Association list of escapes for some characters problematic in links.
8061 This is the list that is used before handing over to the browser.")
8063 (defun org-link-escape (text &optional table)
8064 "Escape characters in TEXT that are problematic for links."
8065 (if (and org-url-encoding-use-url-hexify (not table))
8066 (url-hexify-string text)
8067 (setq table (or table org-link-escape-chars))
8069 (let ((re (mapconcat (lambda (x) (regexp-quote
8070 (char-to-string (car x))))
8072 (while (string-match re text)
8075 (cdr (assoc (string-to-char (match-string 0 text))
8080 (defun org-link-unescape (text &optional table)
8081 "Reverse the action of `org-link-escape'."
8082 (if (and org-url-encoding-use-url-hexify (not table))
8083 (url-unhex-string text)
8084 (setq table (or table org-link-escape-chars))
8086 (let ((case-fold-search t)
8087 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8089 (while (string-match re text)
8092 (char-to-string (car (rassoc (upcase (match-string 0 text))
8097 (defun org-xor (a b)
8101 (defun org-fixup-message-id-for-http (s)
8102 "Replace special characters in a message id, so it can be used in an http query."
8103 (while (string-match "<" s)
8104 (setq s (replace-match "%3C" t t s)))
8105 (while (string-match ">" s)
8106 (setq s (replace-match "%3E" t t s)))
8107 (while (string-match "@" s)
8108 (setq s (replace-match "%40" t t s)))
8112 (defun org-insert-link-global ()
8113 "Insert a link like Org-mode does.
8114 This command can be called in any mode to insert a link in Org-mode syntax."
8116 (org-load-modules-maybe)
8117 (org-run-like-in-org-mode 'org-insert-link))
8119 (defun org-insert-link (&optional complete-file link-location)
8120 "Insert a link. At the prompt, enter the link.
8122 Completion can be used to insert any of the link protocol prefixes like
8125 The history can be used to select a link previously stored with
8126 `org-store-link'. When the empty string is entered (i.e. if you just
8127 press RET at the prompt), the link defaults to the most recently
8128 stored link. As SPC triggers completion in the minibuffer, you need to
8129 use M-SPC or C-q SPC to force the insertion of a space character.
8131 You will also be prompted for a description, and if one is given, it will
8132 be displayed in the buffer instead of the link.
8134 If there is already a link at point, this command will allow you to edit link
8135 and description parts.
8137 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
8138 be selected using completion. The path to the file will be relative to the
8139 current directory if the file is in the current directory or a subdirectory.
8140 Otherwise, the link will be the absolute path as completed in the minibuffer
8141 \(i.e. normally ~/path/to/file). You can configure this behavior using the
8142 option `org-link-file-path-type'.
8144 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
8145 the current directory or below.
8147 With three \\[universal-argument] prefixes, negate the meaning of
8148 `org-keep-stored-link-after-insertion'.
8150 If `org-make-link-description-function' is non-nil, this function will be
8151 called with the link target, and the result will be the default
8154 If the LINK-LOCATION parameter is non-nil, this value will be
8155 used as the link location instead of reading one interactively."
8157 (let* ((wcf (current-window-configuration))
8158 (region (if (org-region-active-p)
8159 (buffer-substring (region-beginning) (region-end))))
8160 (remove (and region (list (region-beginning) (region-end))))
8162 tmphist ; byte-compile incorrectly complains about this
8163 (link link-location)
8164 entry file all-prefixes)
8166 (link-location) ; specified by arg, just use it.
8167 ((org-in-regexp org-bracket-link-regexp 1)
8168 ;; We do have a link at point, and we are going to edit it.
8169 (setq remove (list (match-beginning 0) (match-end 0)))
8170 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8171 (setq link (read-string "Link: "
8173 (org-match-string-no-properties 1)))))
8174 ((or (org-in-regexp org-angle-link-re)
8175 (org-in-regexp org-plain-link-re))
8176 ;; Convert to bracket link
8177 (setq remove (list (match-beginning 0) (match-end 0))
8178 link (read-string "Link: "
8179 (org-remove-angle-brackets (match-string 0)))))
8180 ((member complete-file '((4) (16)))
8181 ;; Completing read for file names.
8182 (setq link (org-file-complete-link complete-file)))
8184 ;; Read link, with completion for stored links.
8185 (with-output-to-temp-buffer "*Org Links*"
8186 (princ "Insert a link.
8187 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
8188 (when org-stored-links
8189 (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
8192 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8193 (reverse org-stored-links) "\n"))))
8194 (let ((cw (selected-window)))
8195 (select-window (get-buffer-window "*Org Links*"))
8196 (setq truncate-lines t)
8197 (unless (pos-visible-in-window-p (point-max))
8198 (org-fit-window-to-buffer))
8199 (and (window-live-p cw) (select-window cw)))
8200 ;; Fake a link history, containing the stored links.
8201 (setq tmphist (append (mapcar 'car org-stored-links)
8202 org-insert-link-history))
8203 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8204 (mapcar 'car org-link-abbrev-alist)
8209 (let ((org-completion-use-ido nil)
8210 (org-completion-use-iswitchb nil))
8211 (org-completing-read
8214 (mapcar (lambda (x) (list (concat x ":")))
8216 (mapcar 'car org-stored-links))
8219 (car (car org-stored-links)))))
8220 (if (not (string-match "\\S-" link))
8221 (error "No link selected"))
8222 (if (or (member link all-prefixes)
8223 (and (equal ":" (substring link -1))
8224 (member (substring link 0 -1) all-prefixes)
8225 (setq link (substring link 0 -1))))
8226 (setq link (org-link-try-special-completion link))))
8227 (set-window-configuration wcf)
8228 (kill-buffer "*Org Links*"))
8229 (setq entry (assoc link org-stored-links))
8230 (or entry (push link org-insert-link-history))
8231 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8232 (not org-keep-stored-link-after-insertion))
8233 (setq org-stored-links (delq (assoc link org-stored-links)
8235 (setq desc (or desc (nth 1 entry)))))
8237 (if (string-match org-plain-link-re link)
8238 ;; URL-like link, normalize the use of angular brackets.
8239 (setq link (org-make-link (org-remove-angle-brackets link))))
8241 ;; Check if we are linking to the current file with a search option
8242 ;; If yes, simplify the link by using only the search option.
8243 (when (and buffer-file-name
8244 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
8245 (let* ((path (match-string 1 link))
8246 (case-fold-search nil)
8247 (search (match-string 2 link)))
8249 (if (equal (file-truename buffer-file-name) (file-truename path))
8250 ;; We are linking to this same file, with a search option
8251 (setq link search)))))
8253 ;; Check if we can/should use a relative path. If yes, simplify the link
8254 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
8255 (let* ((type (match-string 1 link))
8256 (path (match-string 2 link))
8258 (case-fold-search nil))
8260 ((or (eq org-link-file-path-type 'absolute)
8261 (equal complete-file '(16)))
8262 (setq path (abbreviate-file-name (expand-file-name path))))
8263 ((eq org-link-file-path-type 'noabbrev)
8264 (setq path (expand-file-name path)))
8265 ((eq org-link-file-path-type 'relative)
8266 (setq path (file-relative-name path)))
8269 (if (string-match (concat "^" (regexp-quote
8270 (file-name-as-directory
8271 (expand-file-name "."))))
8272 (expand-file-name path))
8273 ;; We are linking a file with relative path name.
8274 (setq path (substring (expand-file-name path)
8276 (setq path (abbreviate-file-name (expand-file-name path)))))))
8277 (setq link (concat type path))
8278 (if (equal desc origpath)
8281 (if org-make-link-description-function
8282 (setq desc (funcall org-make-link-description-function link desc)))
8284 (setq desc (read-string "Description: " desc))
8285 (unless (string-match "\\S-" desc) (setq desc nil))
8286 (if remove (apply 'delete-region remove))
8287 (insert (org-make-link-string link desc))))
8289 (defun org-link-try-special-completion (type)
8290 "If there is completion support for link type TYPE, offer it."
8291 (let ((fun (intern (concat "org-" type "-complete-link"))))
8294 (read-string "Link (no completion support): " (concat type ":")))))
8296 (defun org-file-complete-link (&optional arg)
8297 "Create a file link using completion."
8299 (setq file (read-file-name "File: "))
8300 (let ((pwd (file-name-as-directory (expand-file-name ".")))
8301 (pwd1 (file-name-as-directory (abbreviate-file-name
8302 (expand-file-name ".")))))
8305 (setq link (org-make-link
8307 (abbreviate-file-name (expand-file-name file)))))
8308 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
8309 (setq link (org-make-link "file:" (match-string 1 file))))
8310 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
8311 (expand-file-name file))
8312 (setq link (org-make-link
8313 "file:" (match-string 1 (expand-file-name file)))))
8314 (t (setq link (org-make-link "file:" file)))))
8317 (defun org-completing-read (&rest args)
8318 "Completing-read with SPACE being a normal character."
8319 (let ((minibuffer-local-completion-map
8320 (copy-keymap minibuffer-local-completion-map)))
8321 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8322 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
8323 (apply 'org-icompleting-read args)))
8325 (defun org-completing-read-no-i (&rest args)
8326 (let (org-completion-use-ido org-completion-use-iswitchb)
8327 (apply 'org-completing-read args)))
8329 (defun org-iswitchb-completing-read (prompt choices &rest args)
8330 "Use iswitch as a completing-read replacement to choose from choices.
8331 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8333 (let* ((iswitchb-use-virtual-buffers nil)
8334 (iswitchb-make-buflist-hook
8336 (setq iswitchb-temp-buflist choices))))
8337 (iswitchb-read-buffer prompt)))
8339 (defun org-icompleting-read (&rest args)
8340 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
8341 (org-without-partial-completion
8342 (if (and org-completion-use-ido
8343 (fboundp 'ido-completing-read)
8344 (boundp 'ido-mode) ido-mode
8345 (listp (second args)))
8346 (let ((ido-enter-matching-directory nil))
8347 (apply 'ido-completing-read (concat (car args))
8348 (if (consp (car (nth 1 args)))
8349 (mapcar (lambda (x) (car x)) (nth 1 args))
8352 (if (and org-completion-use-iswitchb
8353 (boundp 'iswitchb-mode) iswitchb-mode
8354 (listp (second args)))
8355 (apply 'org-iswitchb-completing-read (concat (car args))
8356 (if (consp (car (nth 1 args)))
8357 (mapcar (lambda (x) (car x)) (nth 1 args))
8360 (apply 'completing-read args)))))
8362 (defun org-extract-attributes (s)
8363 "Extract the attributes cookie from a string and set as text property."
8364 (let (a attr (start 0) key value)
8366 (when (string-match "{{\\([^}]+\\)}}$" s)
8367 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8368 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
8369 (setq key (match-string 1 a) value (match-string 2 a)
8371 attr (plist-put attr (intern key) value))))
8372 (org-add-props s nil 'org-attr attr))
8375 (defun org-extract-attributes-from-string (tag)
8376 (let (key value attr)
8377 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
8378 (setq key (match-string 1 tag) value (match-string 2 tag)
8379 tag (replace-match "" t t tag)
8380 attr (plist-put attr (intern key) value)))
8383 (defun org-attributes-to-string (plist)
8384 "Format a property list into an HTML attribute list."
8385 (let ((s "") key value)
8387 (setq key (pop plist) value (pop plist))
8389 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8392 ;;; Opening/following a link
8394 (defvar org-link-search-failed nil)
8396 (defvar org-open-link-functions nil
8397 "Hook for functions finding a plain text link.
8398 These functions must take a single argument, the link content.
8399 They will be called for links that look like [[link text][description]]
8400 when LINK TEXT does not have a protocol like \"http:\" and does not look
8401 like a filename (e.g. \"./blue.png\").
8403 These functions will be called *before* Org attempts to resolve the
8404 link by doing text searches in the current buffer - so if you want a
8405 link \"[[target]]\" to still find \"<<target>>\", your function should
8406 handle this as a special case.
8408 When the function does handle the link, it must return a non-nil value.
8409 If it decides that it is not responsible for this link, it must return
8410 nil to indicate that that Org-mode can continue with other options
8411 like exact and fuzzy text search.")
8413 (defun org-next-link ()
8414 "Move forward to the next link.
8415 If the link is in hidden text, expose it."
8417 (when (and org-link-search-failed (eq this-command last-command))
8418 (goto-char (point-min))
8419 (message "Link search wrapped back to beginning of buffer"))
8420 (setq org-link-search-failed nil)
8421 (let* ((pos (point))
8423 (a (assoc :link ct)))
8424 (if a (goto-char (nth 2 a)))
8425 (if (re-search-forward org-any-link-re nil t)
8427 (goto-char (match-beginning 0))
8428 (if (org-invisible-p) (org-show-context)))
8430 (setq org-link-search-failed t)
8431 (error "No further link found"))))
8433 (defun org-previous-link ()
8434 "Move backward to the previous link.
8435 If the link is in hidden text, expose it."
8437 (when (and org-link-search-failed (eq this-command last-command))
8438 (goto-char (point-max))
8439 (message "Link search wrapped back to end of buffer"))
8440 (setq org-link-search-failed nil)
8441 (let* ((pos (point))
8443 (a (assoc :link ct)))
8444 (if a (goto-char (nth 1 a)))
8445 (if (re-search-backward org-any-link-re nil t)
8447 (goto-char (match-beginning 0))
8448 (if (org-invisible-p) (org-show-context)))
8450 (setq org-link-search-failed t)
8451 (error "No further link found"))))
8453 (defun org-translate-link (s)
8454 "Translate a link string if a translation function has been defined."
8455 (if (and org-link-translation-function
8456 (fboundp org-link-translation-function)
8457 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8459 (setq s (funcall org-link-translation-function
8460 (match-string 1) (match-string 2)))
8461 (concat (car s) ":" (cdr s)))
8464 (defun org-translate-link-from-planner (type path)
8465 "Translate a link from Emacs Planner syntax so that Org can follow it.
8466 This is still an experimental function, your mileage may vary."
8468 ((member type '("http" "https" "news" "ftp"))
8469 ;; standard Internet links are the same.
8471 ((and (equal type "irc") (string-match "^//" path))
8472 ;; Planner has two / at the beginning of an irc link, we have 1.
8473 ;; We should have zero, actually....
8474 (setq path (substring path 1)))
8475 ((and (equal type "lisp") (string-match "^/" path))
8476 ;; Planner has a slash, we do not.
8477 (setq type "elisp" path (substring path 1)))
8478 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8479 ;; A typical message link. Planner has the id after the final slash,
8480 ;; we separate it with a hash mark
8481 (setq path (concat (match-string 1 path) "#"
8482 (org-remove-angle-brackets (match-string 2 path)))))
8486 (defun org-find-file-at-mouse (ev)
8487 "Open file link or URL at mouse."
8489 (mouse-set-point ev)
8490 (org-open-at-point 'in-emacs))
8492 (defun org-open-at-mouse (ev)
8493 "Open file link or URL at mouse."
8495 (mouse-set-point ev)
8496 (if (eq major-mode 'org-agenda-mode)
8497 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8498 (org-open-at-point))
8500 (defvar org-window-config-before-follow-link nil
8501 "The window configuration before following a link.
8502 This is saved in case the need arises to restore it.")
8504 (defvar org-open-link-marker (make-marker)
8505 "Marker pointing to the location where `org-open-at-point; was called.")
8508 (defun org-open-at-point-global ()
8509 "Follow a link like Org-mode does.
8510 This command can be called in any mode to follow a link that has
8513 (org-run-like-in-org-mode 'org-open-at-point))
8516 (defun org-open-link-from-string (s &optional arg reference-buffer)
8517 "Open a link in the string S, as if it was in Org-mode."
8518 (interactive "sLink: \nP")
8519 (let ((reference-buffer (or reference-buffer (current-buffer))))
8521 (let ((org-inhibit-startup t))
8524 (goto-char (point-min))
8525 (when reference-buffer
8526 (setq org-link-abbrev-alist-local
8527 (with-current-buffer reference-buffer
8528 org-link-abbrev-alist-local)))
8529 (org-open-at-point arg reference-buffer)))))
8531 (defun org-open-at-point (&optional in-emacs reference-buffer)
8532 "Open link at or after point.
8533 If there is no link at point, this function will search forward up to
8534 the end of the current line.
8535 Normally, files will be opened by an appropriate application. If the
8536 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8537 With a double prefix argument, try to open outside of Emacs, in the
8538 application the system uses for this file type."
8540 (org-load-modules-maybe)
8541 (move-marker org-open-link-marker (point))
8542 (setq org-window-config-before-follow-link (current-window-configuration))
8543 (org-remove-occur-highlights nil nil t)
8545 ((and (org-on-heading-p)
8547 (concat org-plain-link-re "\\|"
8548 org-bracket-link-regexp "\\|"
8549 org-angle-link-re "\\|"
8550 "[ \t]:[^ \t\n]+:[ \t]*$")))
8551 (not (get-text-property (point) 'org-linked-text)))
8552 (or (org-offer-links-in-entry in-emacs)
8553 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8554 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8555 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8556 (org-footnote-action))
8558 (let (type path link line search (pos (point)))
8561 (skip-chars-forward "^]\n\r")
8562 (when (org-in-regexp org-bracket-link-regexp 1)
8563 (setq link (org-extract-attributes
8564 (org-link-unescape (org-match-string-no-properties 1))))
8565 (while (string-match " *\n *" link)
8566 (setq link (replace-match " " t t link)))
8567 (setq link (org-link-expand-abbrev link))
8569 ((or (file-name-absolute-p link)
8570 (string-match "^\\.\\.?/" link))
8571 (setq type "file" path link))
8572 ((string-match org-link-re-with-space3 link)
8573 (setq type (match-string 1 link) path (match-string 2 link)))
8574 (t (setq type "thisfile" path link)))
8577 (when (get-text-property (point) 'org-linked-text)
8578 (setq type "thisfile"
8579 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8580 (1+ (point)) (point))
8581 path (buffer-substring
8582 (previous-single-property-change pos 'org-linked-text)
8583 (next-single-property-change pos 'org-linked-text)))
8587 (when (or (org-in-regexp org-angle-link-re)
8588 (org-in-regexp org-plain-link-re))
8589 (setq type (match-string 1) path (match-string 2))
8592 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8594 path (match-string 1))
8595 (while (string-match ":" path)
8596 (setq path (replace-match "+" t t path)))
8598 (when (org-in-regexp "<\\([^><\n]+\\)>")
8599 (setq type "tree-match"
8600 path (match-string 1))
8603 (error "No link found"))
8605 ;; switch back to reference buffer
8606 ;; needed when if called in a temporary buffer through
8607 ;; org-open-link-from-string
8608 (with-current-buffer (or reference-buffer (current-buffer))
8610 ;; Remove any trailing spaces in path
8611 (if (string-match " +\\'" path)
8612 (setq path (replace-match "" t t path)))
8613 (if (and org-link-translation-function
8614 (fboundp org-link-translation-function))
8615 ;; Check if we need to translate the link
8616 (let ((tmp (funcall org-link-translation-function type path)))
8617 (setq type (car tmp) path (cdr tmp))))
8621 ((assoc type org-link-protocols)
8622 (funcall (nth 1 (assoc type org-link-protocols)) path))
8624 ((equal type "mailto")
8625 (let ((cmd (car org-link-mailto-program))
8626 (args (cdr org-link-mailto-program)) args1
8627 (address path) (subject "") a)
8628 (if (string-match "\\(.*\\)::\\(.*\\)" path)
8629 (setq address (match-string 1 path)
8630 subject (org-link-escape (match-string 2 path))))
8633 ((not (stringp (car args))) (push (pop args) args1))
8634 (t (setq a (pop args))
8635 (if (string-match "%a" a)
8636 (setq a (replace-match address t t a)))
8637 (if (string-match "%s" a)
8638 (setq a (replace-match subject t t a)))
8640 (apply cmd (nreverse args1))))
8642 ((member type '("http" "https" "ftp" "news"))
8643 (browse-url (concat type ":" (org-link-escape
8644 path org-link-escape-chars-browser))))
8646 ((member type '("message"))
8647 (browse-url (concat type ":" path)))
8649 ((string= type "tags")
8650 (org-tags-view in-emacs path))
8652 ((string= type "tree-match")
8653 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
8655 ((string= type "file")
8656 (if (string-match "::\\([0-9]+\\)\\'" path)
8657 (setq line (string-to-number (match-string 1 path))
8658 path (substring path 0 (match-beginning 0)))
8659 (if (string-match "::\\(.+\\)\\'" path)
8660 (setq search (match-string 1 path)
8661 path (substring path 0 (match-beginning 0)))))
8662 (if (string-match "[*?{]" (file-name-nondirectory path))
8664 (org-open-file path in-emacs line search)))
8666 ((string= type "news")
8668 (org-gnus-follow-link path))
8670 ((string= type "shell")
8672 (if (or (not org-confirm-shell-link-function)
8673 (funcall org-confirm-shell-link-function
8674 (format "Execute \"%s\" in shell? "
8675 (org-add-props cmd nil
8676 'face 'org-warning))))
8678 (message "Executing %s" cmd)
8679 (shell-command cmd))
8682 ((string= type "elisp")
8684 (if (or (not org-confirm-elisp-link-function)
8685 (funcall org-confirm-elisp-link-function
8686 (format "Execute \"%s\" as elisp? "
8687 (org-add-props cmd nil
8688 'face 'org-warning))))
8689 (message "%s => %s" cmd
8690 (if (equal (string-to-char cmd) ?\()
8692 (call-interactively (read cmd))))
8695 ((and (string= type "thisfile")
8696 (run-hook-with-args-until-success
8697 'org-open-link-functions path)))
8699 ((string= type "thisfile")
8701 (switch-to-buffer-other-window
8702 (org-get-buffer-for-internal-link (current-buffer)))
8703 (org-mark-ring-push))
8704 (let ((cmd `(org-link-search
8706 ,(cond ((equal in-emacs '(4)) 'occur)
8707 ((equal in-emacs '(16)) 'org-occur)
8710 (condition-case nil (eval cmd)
8711 (error (progn (widen) (eval cmd))))))
8714 (browse-url-at-point)))))))
8715 (move-marker org-open-link-marker nil)
8716 (run-hook-with-args 'org-follow-link-hook))
8718 (defun org-offer-links-in-entry (&optional nth zero)
8719 "Offer links in the current entry and follow the selected link.
8720 If there is only one link, follow it immediately as well.
8721 If NTH is an integer, immediately pick the NTH link found.
8722 If ZERO is a string, check also this string for a link, and if
8723 there is one, offer it as link number zero."
8724 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
8725 "\\(" org-angle-link-re "\\)\\|"
8726 "\\(" org-plain-link-re "\\)"))
8728 (in-emacs (if (integerp nth) nil nth))
8729 have-zero end links link c)
8730 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
8731 (push (match-string 0 zero) links)
8732 (setq cnt (1- cnt) have-zero t))
8734 (org-back-to-heading t)
8735 (setq end (save-excursion (outline-next-heading) (point)))
8736 (while (re-search-forward re end t)
8737 (push (match-string 0) links))
8738 (setq links (org-uniquify (reverse links))))
8742 (message "No links"))
8743 ((equal (length links) 1)
8744 (setq link (list (car links))))
8745 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
8746 (setq link (nth (if have-zero nth (1- nth)) links)))
8747 (t ; we have to select a link
8749 (save-window-excursion
8750 (delete-other-windows)
8751 (with-output-to-temp-buffer "*Select Link*"
8753 (if (not (string-match org-bracket-link-regexp l))
8754 (princ (format "[%c] %s\n" (incf cnt)
8755 (org-remove-angle-brackets l)))
8757 (princ (format "[%c] %s (%s)\n" (incf cnt)
8758 (match-string 3 l) (match-string 1 l)))
8759 (princ (format "[%c] %s\n" (incf cnt)
8760 (match-string 1 l))))))
8762 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
8763 (message "Select link to open, RET to open all:")
8764 (setq c (read-char-exclusive))
8765 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
8766 (when (equal c ?q) (error "Abort"))
8770 (if have-zero (setq nth (1+ nth)))
8771 (unless (and (integerp nth) (>= (length links) nth))
8772 (error "Invalid link selection"))
8773 (setq link (list (nth (1- nth) links))))))
8775 (let ((buf (current-buffer)))
8777 (org-open-link-from-string l in-emacs buf))
8781 ;; Add special file links that specify the way of opening
8783 (org-add-link-type "file+sys" 'org-open-file-with-system)
8784 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
8785 (defun org-open-file-with-system (path)
8786 "Open file at PATH using the system way of opeing it."
8787 (org-open-file path 'system))
8788 (defun org-open-file-with-emacs (path)
8789 "Open file at PATH in emacs."
8790 (org-open-file path 'emacs))
8791 (defun org-remove-file-link-modifiers ()
8792 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
8793 (goto-char (point-min))
8794 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
8796 (replace-match "file:" t t))))
8797 (eval-after-load "org-exp"
8798 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
8799 'org-remove-file-link-modifiers))
8803 (defun org-get-effort (&optional pom)
8804 "Get the effort estimate for the current entry."
8805 (org-entry-get pom org-effort-property))
8809 (defvar org-create-file-search-functions nil
8810 "List of functions to construct the right search string for a file link.
8811 These functions are called in turn with point at the location to
8812 which the link should point.
8814 A function in the hook should first test if it would like to
8815 handle this file type, for example by checking the major-mode or
8816 the file extension. If it decides not to handle this file, it
8817 should just return nil to give other functions a chance. If it
8818 does handle the file, it must return the search string to be used
8819 when following the link. The search string will be part of the
8820 file link, given after a double colon, and `org-open-at-point'
8821 will automatically search for it. If special measures must be
8822 taken to make the search successful, another function should be
8823 added to the companion hook `org-execute-file-search-functions',
8826 A function in this hook may also use `setq' to set the variable
8827 `description' to provide a suggestion for the descriptive text to
8828 be used for this link when it gets inserted into an Org-mode
8829 buffer with \\[org-insert-link].")
8831 (defvar org-execute-file-search-functions nil
8832 "List of functions to execute a file search triggered by a link.
8834 Functions added to this hook must accept a single argument, the
8835 search string that was part of the file link, the part after the
8836 double colon. The function must first check if it would like to
8837 handle this search, for example by checking the major-mode or the
8838 file extension. If it decides not to handle this search, it
8839 should just return nil to give other functions a chance. If it
8840 does handle the search, it must return a non-nil value to keep
8841 other functions from trying.
8843 Each function can access the current prefix argument through the
8844 variable `current-prefix-argument'. Note that a single prefix is
8845 used to force opening a link in Emacs, so it may be good to only
8846 use a numeric or double prefix to guide the search function.
8848 In case this is needed, a function in this hook can also restore
8849 the window configuration before `org-open-at-point' was called using:
8851 (set-window-configuration org-window-config-before-follow-link)")
8853 (defun org-link-search (s &optional type avoid-pos)
8854 "Search for a link search option.
8855 If S is surrounded by forward slashes, it is interpreted as a
8856 regular expression. In org-mode files, this will create an `org-occur'
8857 sparse tree. In ordinary files, `occur' will be used to list matches.
8858 If the current buffer is in `dired-mode', grep will be used to search
8859 in all files. If AVOID-POS is given, ignore matches near that position."
8860 (let ((case-fold-search t)
8861 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
8862 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
8863 (append '(("") (" ") ("\t") ("\n"))
8867 (pre nil) (post nil)
8868 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
8870 ;; First check if there are any special
8871 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
8872 ;; Now try the builtin stuff
8873 ((and (equal (string-to-char s0) ?#)
8876 (goto-char (point-min))
8879 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
8880 (setq type 'dedicated
8881 pos (match-beginning 0))))
8882 ;; There is an exact target for this
8884 (org-back-to-heading t)))
8886 (goto-char (point-min))
8889 (concat "<<" (regexp-quote s0) ">>") nil t)
8890 (setq type 'dedicated
8891 pos (match-beginning 0))))
8892 ;; There is an exact target for this
8894 ((and (string-match "^(\\(.*\\))$" s0)
8896 (goto-char (point-min))
8899 (concat "[^[]" (regexp-quote
8900 (format org-coderef-label-format
8901 (match-string 1 s0))))
8903 (setq type 'dedicated
8904 pos (1+ (match-beginning 0))))))
8905 ;; There is a coderef target for this
8907 ((string-match "^/\\(.*\\)/$" s)
8908 ;; A regular expression
8911 (org-occur (match-string 1 s)))
8912 ;;((eq major-mode 'dired-mode)
8913 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
8914 (t (org-do-occur (match-string 1 s)))))
8916 ;; A normal search strings
8917 (when (equal (string-to-char s) ?*)
8918 ;; Anchor on headlines, post may include tags.
8919 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
8920 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
8922 (remove-text-properties
8924 '(face nil mouse-face nil keymap nil fontified nil) s)
8925 ;; Make a series of regular expressions to find a match
8926 (setq words (org-split-string s "[ \n\r\t]+")
8928 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
8929 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
8931 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
8932 re2a (concat "[ \t\r\n]" re2a_)
8933 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
8934 re4 (concat "[^a-zA-Z_]" re4_)
8936 re1 (concat pre re2 post)
8937 re3 (concat pre (if pre re4_ re4) post)
8938 re5 (concat pre ".*" re4)
8939 re2 (concat pre re2)
8940 re2a (concat pre (if pre re2a_ re2a))
8941 re4 (concat pre (if pre re4_ re4))
8942 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
8943 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
8947 ((eq type 'org-occur) (org-occur reall))
8948 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
8949 (t (goto-char (point-min))
8951 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
8952 (org-search-not-self 1 re1 nil t)
8953 (org-search-not-self 1 re2 nil t)
8954 (org-search-not-self 1 re2a nil t)
8955 (org-search-not-self 1 re3 nil t)
8956 (org-search-not-self 1 re4 nil t)
8957 (org-search-not-self 1 re5 nil t)
8959 (goto-char (match-beginning 1))
8961 (error "No match")))))
8963 ;; Normal string-search
8964 (goto-char (point-min))
8965 (if (search-forward s nil t)
8966 (goto-char (match-beginning 0))
8967 (error "No match"))))
8968 (and (org-mode-p) (org-show-context 'link-search))
8971 (defun org-search-not-self (group &rest args)
8972 "Execute `re-search-forward', but only accept matches that do not
8973 enclose the position of `org-open-link-marker'."
8974 (let ((m org-open-link-marker))
8976 (while (apply 're-search-forward args)
8977 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
8978 (goto-char (match-end group))
8979 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
8980 (> (match-beginning 0) (marker-position m))
8981 (< (match-end 0) (marker-position m)))
8983 (or (not (org-in-regexp
8984 org-bracket-link-analytic-regexp 1))
8985 (not (match-end 4)) ; no description
8986 (and (<= (match-beginning 4) (point))
8987 (>= (match-end 4) (point))))))
8988 (throw 'exit (point))))))))
8990 (defun org-get-buffer-for-internal-link (buffer)
8991 "Return a buffer to be used for displaying the link target of internal links."
8993 ((not org-display-internal-link-with-indirect-buffer)
8995 ((string-match "(Clone)$" (buffer-name buffer))
8996 (message "Buffer is already a clone, not making another one")
8997 ;; we also do not modify visibility in this case
8999 (t ; make a new indirect buffer for displaying the link
9000 (let* ((bn (buffer-name buffer))
9001 (ibn (concat bn "(Clone)"))
9002 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9003 (with-current-buffer ib (org-overview))
9006 (defun org-do-occur (regexp &optional cleanup)
9007 "Call the Emacs command `occur'.
9008 If CLEANUP is non-nil, remove the printout of the regular expression
9009 in the *Occur* buffer. This is useful if the regex is long and not useful
9013 (let ((cwin (selected-window)) win beg end)
9014 (when (setq win (get-buffer-window "*Occur*"))
9015 (select-window win))
9016 (goto-char (point-min))
9017 (when (re-search-forward "match[a-z]+" nil t)
9018 (setq beg (match-end 0))
9019 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9020 (setq end (1- (match-beginning 0)))))
9021 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9022 (goto-char (point-min))
9023 (select-window cwin))))
9025 ;;; The mark ring for links jumps
9027 (defvar org-mark-ring nil
9028 "Mark ring for positions before jumps in Org-mode.")
9029 (defvar org-mark-ring-last-goto nil
9030 "Last position in the mark ring used to go back.")
9031 ;; Fill and close the ring
9032 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9033 (loop for i from 1 to org-mark-ring-length do
9034 (push (make-marker) org-mark-ring))
9035 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9038 (defun org-mark-ring-push (&optional pos buffer)
9039 "Put the current position or POS into the mark ring and rotate it."
9041 (setq pos (or pos (point)))
9042 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9043 (move-marker (car org-mark-ring)
9045 (or buffer (current-buffer)))
9047 (substitute-command-keys
9048 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9050 (defun org-mark-ring-goto (&optional n)
9051 "Jump to the previous position in the mark ring.
9052 With prefix arg N, jump back that many stored positions. When
9053 called several times in succession, walk through the entire ring.
9054 Org-mode commands jumping to a different position in the current file,
9055 or to another Org-mode file, automatically push the old position
9059 (if (eq last-command this-command)
9060 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9061 (setq p org-mark-ring))
9062 (setq org-mark-ring-last-goto p)
9064 (switch-to-buffer (marker-buffer m))
9066 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9068 (defun org-remove-angle-brackets (s)
9069 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9070 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9072 (defun org-add-angle-brackets (s)
9073 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9074 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9076 (defun org-remove-double-quotes (s)
9077 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9078 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9081 ;;; Following specific links
9083 (defun org-follow-timestamp-link ()
9085 ((org-at-date-range-p t)
9086 (let ((org-agenda-start-on-weekday)
9087 (t1 (match-string 1))
9088 (t2 (match-string 2)))
9089 (setq t1 (time-to-days (org-time-string-to-time t1))
9090 t2 (time-to-days (org-time-string-to-time t2)))
9091 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9092 ((org-at-timestamp-p t)
9093 (org-agenda-list nil (time-to-days (org-time-string-to-time
9094 (substring (match-string 1) 0 10)))
9096 (t (error "This should not happen"))))
9099 ;;; Following file links
9100 (defvar org-wait nil)
9101 (defun org-open-file (path &optional in-emacs line search)
9102 "Open the file at PATH.
9103 First, this expands any special file name abbreviations. Then the
9104 configuration variable `org-file-apps' is checked if it contains an
9105 entry for this file type, and if yes, the corresponding command is launched.
9107 If no application is found, Emacs simply visits the file.
9109 With optional prefix argument IN-EMACS, Emacs will visit the file.
9110 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9111 and to use an external application to visit the file.
9113 Optional LINE specifies a line to go to, optional SEARCH a string to
9114 search for. If LINE or SEARCH is given, but IN-EMACS is nil, it will
9115 be assumed that org-open-file was called to open a file: link, and the
9116 original link to match against org-file-apps will be reconstructed
9117 from PATH and whichever of LINE or SEARCH is given.
9119 If the file does not exist, an error is thrown."
9120 (let* ((file (if (equal path "")
9122 (substitute-in-file-name (expand-file-name path))))
9123 (apps (append org-file-apps (org-default-apps)))
9124 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9125 (dirp (if remp nil (file-directory-p file)))
9126 (file (if (and dirp org-open-directory-means-index-dot-org)
9127 (concat (file-name-as-directory file) "index.org")
9129 (a-m-a-p (assq 'auto-mode apps))
9130 (dfile (downcase file))
9131 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9132 (link (cond ((and (eq line nil)
9136 (concat file "::" (number-to-string line)))
9138 (concat file "::" search))))
9139 (dlink (downcase link))
9140 (old-buffer (current-buffer))
9142 (old-mode major-mode)
9143 ext cmd link-match-data)
9144 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9145 (setq ext (match-string 1 dfile))
9146 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9147 (setq ext (match-string 1 dfile))))
9149 ((member in-emacs '((16) system))
9150 (setq cmd (cdr (assoc 'system apps))))
9151 (in-emacs (setq cmd 'emacs))
9153 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9154 (and dirp (cdr (assoc 'directory apps)))
9155 ;; if we find a match in org-file-apps, store the match
9157 (let ((match (assoc-default dlink (org-apps-regexp-alist
9161 (progn (setq link-match-data (match-data))
9164 (cdr (assoc ext apps))
9165 (cdr (assoc t apps))))))
9166 (when (eq cmd 'system)
9167 (setq cmd (cdr (assoc 'system apps))))
9168 (when (eq cmd 'default)
9169 (setq cmd (cdr (assoc t apps))))
9170 (when (eq cmd 'mailcap)
9172 (mailcap-parse-mailcaps)
9173 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9174 (command (mailcap-mime-info mime-type)))
9175 (if (stringp command)
9177 (setq cmd 'emacs))))
9178 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9179 (not (file-exists-p file))
9180 (not org-open-non-existing-files))
9181 (error "No such file: %s" file))
9183 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9184 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9185 (while (string-match "['\"]%s['\"]" cmd)
9186 (setq cmd (replace-match "%s" t t cmd)))
9187 (while (string-match "%s" cmd)
9188 (setq cmd (replace-match
9190 (shell-quote-argument
9191 (convert-standard-filename file)))
9193 ;; Replace "%1", "%2" etc. in command with group matches from regex
9195 (let ((match-index 1)
9196 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9197 (set-match-data link-match-data)
9198 (while (<= match-index number-of-groups)
9199 (let ((regex (concat "%" (number-to-string match-index)))
9200 (replace-with (match-string match-index dlink)))
9201 (while (string-match regex cmd)
9202 (setq cmd (replace-match replace-with t t cmd))))
9203 (setq match-index (+ match-index 1)))))
9205 (save-window-excursion
9206 (start-process-shell-command cmd nil cmd)
9207 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9211 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9213 (if line (org-goto-line line)
9214 (if search (org-link-search search))))
9216 (let ((file (convert-standard-filename file)))
9218 (set-match-data link-match-data)
9220 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9221 (and (org-mode-p) (eq old-mode 'org-mode)
9222 (or (not (equal old-buffer (current-buffer)))
9223 (not (equal old-pos (point))))
9224 (org-mark-ring-push old-pos old-buffer))))
9226 (defun org-default-apps ()
9227 "Return the default applications for this operating system."
9229 ((eq system-type 'darwin)
9230 org-file-apps-defaults-macosx)
9231 ((eq system-type 'windows-nt)
9232 org-file-apps-defaults-windowsnt)
9233 (t org-file-apps-defaults-gnu)))
9235 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9236 "Convert extensions to regular expressions in the cars of LIST.
9237 Also, weed out any non-string entries, because the return value is used
9238 only for regexp matching.
9239 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9240 point to the symbol `emacs', indicating that the file should
9241 be opened in Emacs."
9245 (if (not (stringp (car x)))
9247 (if (string-match "\\W" (car x))
9249 (cons (concat "\\." (car x) "\\(::.*\\)?\\'")
9253 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9255 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9256 (defun org-file-remote-p (file)
9257 "Test whether FILE specifies a location on a remote system.
9258 Return non-nil if the location is indeed remote.
9260 For example, the filename \"/user@host:/foo\" specifies a location
9261 on the system \"/user@host:\"."
9262 (cond ((fboundp 'file-remote-p)
9263 (file-remote-p file))
9264 ((fboundp 'tramp-handle-file-remote-p)
9265 (tramp-handle-file-remote-p file))
9266 ((and (boundp 'ange-ftp-name-format)
9267 (string-match (car ange-ftp-name-format) file))
9274 (defun org-get-org-file ()
9275 "Read a filename, with default directory `org-directory'."
9276 (let ((default (or org-default-notes-file remember-data-file)))
9277 (read-file-name (format "File name [%s]: " default)
9278 (file-name-as-directory org-directory)
9281 (defun org-notes-order-reversed-p ()
9282 "Check if the current file should receive notes in reversed order."
9284 ((not org-reverse-note-order) nil)
9285 ((eq t org-reverse-note-order) t)
9286 ((not (listp org-reverse-note-order)) nil)
9288 (let ((all org-reverse-note-order)
9290 (while (setq entry (pop all))
9291 (if (string-match (car entry) buffer-file-name)
9292 (throw 'exit (cdr entry))))
9295 (defvar org-refile-target-table nil
9296 "The list of refile targets, created by `org-refile'.")
9298 (defvar org-agenda-new-buffers nil
9299 "Buffers created to visit agenda files.")
9301 (defun org-get-refile-targets (&optional default-buffer)
9302 "Produce a table with refile targets."
9303 (let ((case-fold-search nil)
9304 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9305 (entries (or org-refile-targets '((nil . (:level . 1)))))
9306 targets txt re files f desc descre fast-path-p level pos0)
9307 (message "Getting targets...")
9308 (with-current-buffer (or default-buffer (current-buffer))
9309 (while (setq entry (pop entries))
9310 (setq files (car entry) desc (cdr entry))
9311 (setq fast-path-p nil)
9313 ((null files) (setq files (list (current-buffer))))
9314 ((eq files 'org-agenda-files)
9315 (setq files (org-agenda-files 'unrestricted)))
9316 ((and (symbolp files) (fboundp files))
9317 (setq files (funcall files)))
9318 ((and (symbolp files) (boundp files))
9319 (setq files (symbol-value files))))
9320 (if (stringp files) (setq files (list files)))
9322 ((eq (car desc) :tag)
9323 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9324 ((eq (car desc) :todo)
9325 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9326 ((eq (car desc) :regexp)
9327 (setq descre (cdr desc)))
9328 ((eq (car desc) :level)
9329 (setq descre (concat "^\\*\\{" (number-to-string
9330 (if org-odd-levels-only
9331 (1- (* 2 (cdr desc)))
9334 ((eq (car desc) :maxlevel)
9335 (setq fast-path-p t)
9336 (setq descre (concat "^\\*\\{1," (number-to-string
9337 (if org-odd-levels-only
9338 (1- (* 2 (cdr desc)))
9341 (t (error "Bad refiling target description %s" desc)))
9342 (while (setq f (pop files))
9343 (with-current-buffer
9344 (if (bufferp f) f (org-get-agenda-file-buffer f))
9345 (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
9346 (setq f (and f (expand-file-name f)))
9347 (if (eq org-refile-use-outline-path 'file)
9348 (push (list (file-name-nondirectory f) f nil nil) targets))
9352 (goto-char (point-min))
9353 (while (re-search-forward descre nil t)
9354 (goto-char (setq pos0 (point-at-bol)))
9356 (when org-refile-target-verify-function
9358 (or (funcall org-refile-target-verify-function)
9360 (when (looking-at org-complex-heading-regexp)
9361 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
9362 txt (org-link-display-format (match-string 4))
9363 re (concat "^" (regexp-quote
9364 (buffer-substring (match-beginning 1)
9366 (if (match-end 5) (setq re (concat re "[ \t]+"
9368 (match-string 5)))))
9369 (setq re (concat re "[ \t]*$"))
9370 (when org-refile-use-outline-path
9371 (setq txt (mapconcat 'org-protect-slash
9373 (if (eq org-refile-use-outline-path 'file)
9374 (list (file-name-nondirectory
9375 (buffer-file-name (buffer-base-buffer))))
9376 (if (eq org-refile-use-outline-path 'full-file-path)
9377 (list (buffer-file-name (buffer-base-buffer)))))
9378 (org-get-outline-path fast-path-p level txt)
9381 (push (list txt f re (point)) targets)))
9382 (when (= (point) pos0)
9383 ;; verification function has not moved point
9384 (goto-char (point-at-eol))))))))))
9385 (message "Getting targets...done")
9386 (nreverse targets)))
9388 (defun org-protect-slash (s)
9389 (while (string-match "/" s)
9390 (setq s (replace-match "\\" t t s)))
9393 (defvar org-olpa (make-vector 20 nil))
9395 (defun org-get-outline-path (&optional fastp level heading)
9396 "Return the outline path to the current entry, as a list.
9397 The parameters FASTP, LEVEL, and HEADING are for use be a scanner
9398 routine which makes outline path derivations for an entire file,
9399 avoiding backtracing."
9403 (error "Outline path failure, more than 19 levels."))
9404 (loop for i from level upto 19 do
9405 (aset org-olpa i nil))
9407 (delq nil (append org-olpa nil))
9408 (aset org-olpa level heading)))
9409 (let (rtn case-fold-search)
9413 (while (org-up-heading-safe)
9414 (when (looking-at org-complex-heading-regexp)
9415 (push (org-match-string-no-properties 4) rtn)))
9418 (defun org-format-outline-path (path &optional width prefix)
9419 "Format the outlie path PATH for display.
9420 Width is the maximum number of characters that is available.
9421 Prefix is a prefix to be included in the returned string,
9422 such as the file name."
9423 (setq width (or width 79))
9424 (if prefix (setq width (- width (length prefix))))
9427 (let* ((nsteps (length path))
9428 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9429 (maxwidth (if (<= total-width width)
9430 10000 ;; everything fits
9431 ;; we need to shorten the level headings
9432 (/ (- width nsteps) nsteps)))
9433 (org-odd-levels-only nil)
9435 (total (1+ (length prefix))))
9436 (setq maxwidth (max maxwidth 10))
9441 (if (and (= n nsteps) (< maxwidth 10000))
9442 (setq maxwidth (- total-width total)))
9443 (if (< (length h) maxwidth)
9444 (progn (setq total (+ total (length h) 1)) h)
9445 (setq h (substring h 0 (- maxwidth 2))
9446 total (+ total maxwidth 1))
9447 (if (string-match "[ \t]+\\'" h)
9448 (setq h (substring h 0 (match-beginning 0))))
9449 (setq h (concat h "..")))
9450 (org-add-props h nil 'face
9451 (nth (% (1- n) org-n-level-faces)
9456 (defun org-display-outline-path (&optional file current)
9457 "Display the current outline path in the echo area."
9459 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9460 (case-fold-search nil)
9461 (path (and (org-mode-p) (org-get-outline-path))))
9462 (if current (setq path (append path
9464 (org-back-to-heading t)
9465 (if (looking-at org-complex-heading-regexp)
9466 (list (match-string 4)))))))
9468 (org-format-outline-path
9471 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9473 (defvar org-refile-history nil
9474 "History for refiling operations.")
9476 (defvar org-after-refile-insert-hook nil
9477 "Hook run after `org-refile' has inserted its stuff at the new location.
9478 Note that this is still *before* the stuff will be removed from
9479 the *old* location.")
9481 (defun org-refile (&optional goto default-buffer rfloc)
9482 "Move the entry at point to another heading.
9483 The list of target headings is compiled using the information in
9484 `org-refile-targets', which see. This list is created before each use
9485 and will therefore always be up-to-date.
9487 At the target location, the entry is filed as a subitem of the target heading.
9488 Depending on `org-reverse-note-order', the new subitem will either be the
9489 first or the last subitem.
9491 If there is an active region, all entries in that region will be moved.
9492 However, the region must fulfil the requirement that the first heading
9493 is the first one sets the top-level of the moved text - at most siblings
9494 below it are allowed.
9496 With prefix arg GOTO, the command will only visit the target location,
9497 not actually move anything.
9498 With a double prefix `C-u C-u', go to the location where the last refiling
9499 operation has put the subtree.
9500 With a prefix argument of `2', refile to the running clock.
9502 RFLOC can be a refile location obtained in a different way.
9504 See also `org-refile-use-outline-path' and `org-completion-use-ido'"
9506 (let* ((cbuf (current-buffer))
9507 (regionp (org-region-active-p))
9508 (region-start (and regionp (region-beginning)))
9509 (region-end (and regionp (region-end)))
9510 (region-length (and regionp (- region-end region-start)))
9511 (filename (buffer-file-name (buffer-base-buffer cbuf)))
9512 pos it nbuf file re level reversed)
9513 (setq last-command nil)
9515 (goto-char region-start)
9516 (or (bolp) (goto-char (point-at-bol)))
9517 (setq region-start (point))
9518 (unless (org-kill-is-subtree-p
9519 (buffer-substring region-start region-end))
9520 (error "The region is not a (sequence of) subtree(s)")))
9521 (if (equal goto '(16))
9522 (org-refile-goto-last-stored)
9525 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
9527 (setq it (list (or org-clock-heading "running clock")
9529 (marker-buffer org-clock-hd-marker))
9531 (marker-position org-clock-hd-marker)))
9535 (org-refile-get-location
9536 (if goto "Goto: " "Refile to: ") default-buffer
9537 org-refile-allow-creating-parent-nodes)))))
9538 (setq file (nth 1 it)
9543 (equal (buffer-file-name) file)
9545 (and (>= pos region-start)
9546 (<= pos region-end))
9547 (and (>= pos (point))
9548 (< pos (save-excursion
9549 (org-end-of-subtree t t))))))
9550 (error "Cannot refile to position inside the tree or region"))
9552 (setq nbuf (or (find-buffer-visiting file)
9553 (find-file-noselect file)))
9556 (switch-to-buffer nbuf)
9558 (org-show-context 'org-goto))
9561 (org-kill-new (buffer-substring region-start region-end))
9562 (org-save-markers-in-region region-start region-end))
9563 (org-copy-subtree 1 nil t))
9564 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
9565 (find-file-noselect file)))
9566 (setq reversed (org-notes-order-reversed-p))
9573 (looking-at outline-regexp)
9574 (setq level (org-get-valid-level (funcall outline-level) 1))
9577 (or (outline-next-heading) (point-max))
9578 (or (save-excursion (org-get-next-sibling))
9579 (org-end-of-subtree t t)
9583 (goto-char (point-max))
9584 (goto-char (point-min))
9585 (or (outline-next-heading) (goto-char (point-max)))))
9586 (if (not (bolp)) (newline))
9587 (org-paste-subtree level)
9588 (when org-log-refile
9589 (org-add-log-setup 'refile nil nil 'findpos
9591 (unless (eq org-log-refile 'note)
9592 (save-excursion (org-add-log-note))))
9593 (and org-auto-align-tags (org-set-tags nil t))
9594 (bookmark-set "org-refile-last-stored")
9595 (if (fboundp 'deactivate-mark) (deactivate-mark))
9596 (run-hooks 'org-after-refile-insert-hook))))
9598 (delete-region (point) (+ (point) region-length))
9600 (when (featurep 'org-inlinetask)
9601 (org-inlinetask-remove-END-maybe))
9602 (setq org-markers-to-move nil)
9603 (message "Refiled to \"%s\"" (car it))))))
9606 (defun org-refile-goto-last-stored ()
9607 "Go to the location where the last refile was stored."
9609 (bookmark-jump "org-refile-last-stored")
9610 (message "This is the location of the last refile"))
9612 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
9613 "Prompt the user for a refile location, using PROMPT."
9614 (let ((org-refile-targets org-refile-targets)
9615 (org-refile-use-outline-path org-refile-use-outline-path))
9616 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
9617 (unless org-refile-target-table
9618 (error "No refile targets"))
9619 (let* ((cbuf (current-buffer))
9620 (partial-completion-mode nil)
9621 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
9622 (cfunc (if (and org-refile-use-outline-path
9623 org-outline-path-complete-in-steps)
9624 'org-olpath-completing-read
9625 'org-icompleting-read))
9626 (extra (if org-refile-use-outline-path "/" ""))
9627 (filename (and cfn (expand-file-name cfn)))
9630 (if (and (not (member org-refile-use-outline-path
9631 '(file full-file-path)))
9632 (not (equal filename (nth 1 x))))
9633 (cons (concat (car x) extra " ("
9634 (file-name-nondirectory (nth 1 x)) ")")
9636 (cons (concat (car x) extra) (cdr x))))
9637 org-refile-target-table))
9638 (completion-ignore-case t)
9639 pa answ parent-target child parent old-hist)
9640 (setq old-hist org-refile-history)
9641 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
9642 nil 'org-refile-history))
9643 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
9646 (when (or (not org-refile-history)
9647 (not (eq old-hist org-refile-history))
9648 (not (equal (car pa) (car org-refile-history))))
9649 (setq org-refile-history
9650 (cons (car pa) (if (assoc (car org-refile-history) tbl)
9652 (cdr org-refile-history))))
9653 (if (equal (car org-refile-history) (nth 1 org-refile-history))
9654 (pop org-refile-history)))
9656 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
9658 (setq parent (match-string 1 answ)
9659 child (match-string 2 answ))
9660 (setq parent-target (or (assoc parent tbl)
9661 (assoc (concat parent "/") tbl)))
9662 (when (and parent-target
9663 (or (eq new-nodes t)
9664 (and (eq new-nodes 'confirm)
9665 (y-or-n-p (format "Create new node \"%s\"? "
9667 (org-refile-new-child parent-target child)))
9668 (error "Invalid target location")))))
9670 (defun org-refile-new-child (parent-target child)
9671 "Use refile target PARENT-TARGET to add new CHILD below it."
9672 (unless parent-target
9673 (error "Cannot find parent for new node"))
9674 (let ((file (nth 1 parent-target))
9675 (pos (nth 3 parent-target))
9677 (with-current-buffer (or (find-buffer-visiting file)
9678 (find-file-noselect file))
9684 (goto-char (point-max))
9685 (if (not (bolp)) (newline)))
9686 (when (looking-at outline-regexp)
9687 (setq level (funcall outline-level))
9688 (org-end-of-subtree t t))
9689 (org-back-over-empty-lines)
9690 (insert "\n" (make-string
9691 (if pos (org-get-valid-level level 1) 1) ?*)
9693 (beginning-of-line 0)
9694 (list (concat (car parent-target) "/" child) file "" (point)))))))
9696 (defun org-olpath-completing-read (prompt collection &rest args)
9697 "Read an outline path like a file name."
9698 (let ((thetable collection)
9699 (org-completion-use-ido nil) ; does not work with ido.
9700 (org-completion-use-iswitchb nil)) ; or iswitchb
9702 'org-icompleting-read prompt
9703 (lambda (string predicate &optional flag)
9704 (let (rtn r f (l (length string)))
9708 (try-completion string thetable))
9711 (setq rtn (all-completions string thetable predicate))
9714 (setq r (substring x l))
9715 (if (string-match " ([^)]*)$" x)
9716 (setq f (match-string 0 x))
9718 (if (string-match "/" r)
9719 (concat string (substring r 0 (match-end 0)) f)
9724 (assoc string thetable)))
9730 (defun org-find-dblock (name)
9731 "Find the first dynamic block with name NAME in the buffer.
9732 If not found, stay at current position and return nil."
9735 (goto-char (point-min))
9736 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
9738 (match-beginning 0))))
9739 (if pos (goto-char pos))
9742 (defconst org-dblock-start-re
9743 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
9744 "Matches the start line of a dynamic block, with parameters.")
9746 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
9747 "Matches the end of a dynamic block.")
9749 (defun org-create-dblock (plist)
9750 "Create a dynamic block section, with parameters taken from PLIST.
9751 PLIST must contain a :name entry which is used as name of the block."
9752 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
9755 (let ((col (current-column))
9756 (name (plist-get plist :name)))
9757 (insert "#+BEGIN: " name)
9759 (if (eq (car plist) :name)
9760 (setq plist (cddr plist))
9761 (insert " " (prin1-to-string (pop plist)))))
9762 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
9763 (beginning-of-line -2)))
9765 (defun org-prepare-dblock ()
9766 "Prepare dynamic block for refresh.
9767 This empties the block, puts the cursor at the insert position and returns
9768 the property list including an extra property :name with the block name."
9769 (unless (looking-at org-dblock-start-re)
9770 (error "Not at a dynamic block"))
9771 (let* ((begdel (1+ (match-end 0)))
9772 (name (org-no-properties (match-string 1)))
9773 (params (append (list :name name)
9774 (read (concat "(" (match-string 3) ")")))))
9776 (beginning-of-line 1)
9777 (skip-chars-forward " \t")
9778 (setq params (plist-put params :indentation-column (current-column))))
9779 (unless (re-search-forward org-dblock-end-re nil t)
9780 (error "Dynamic block not terminated"))
9783 (list :content (buffer-substring
9784 begdel (match-beginning 0)))))
9785 (delete-region begdel (match-beginning 0))
9790 (defun org-map-dblocks (&optional command)
9791 "Apply COMMAND to all dynamic blocks in the current buffer.
9792 If COMMAND is not given, use `org-update-dblock'."
9793 (let ((cmd (or command 'org-update-dblock)))
9795 (goto-char (point-min))
9796 (while (re-search-forward org-dblock-start-re nil t)
9797 (goto-char (match-beginning 0))
9801 (error (message "Error during update of dynamic block"))))
9802 (unless (re-search-forward org-dblock-end-re nil t)
9803 (error "Dynamic block not terminated"))))))
9805 (defun org-dblock-update (&optional arg)
9806 "User command for updating dynamic blocks.
9807 Update the dynamic block at point. With prefix ARG, update all dynamic
9808 blocks in the buffer."
9811 (org-update-all-dblocks)
9812 (or (looking-at org-dblock-start-re)
9813 (org-beginning-of-dblock))
9814 (org-update-dblock)))
9816 (defun org-update-dblock ()
9817 "Update the dynamic block at point
9818 This means to empty the block, parse for parameters and then call
9819 the correct writing function."
9820 (save-window-excursion
9821 (let* ((pos (point))
9822 (line (org-current-line))
9823 (params (org-prepare-dblock))
9824 (name (plist-get params :name))
9825 (indent (plist-get params :indentation-column))
9826 (cmd (intern (concat "org-dblock-write:" name))))
9827 (message "Updating dynamic block `%s' at line %d..." name line)
9828 (funcall cmd params)
9829 (message "Updating dynamic block `%s' at line %d...done" name line)
9831 (when (and indent (> indent 0))
9832 (setq indent (make-string indent ?\ ))
9834 (org-beginning-of-dblock)
9836 (while (not (looking-at org-dblock-end-re))
9838 (beginning-of-line 2))
9839 (when (looking-at org-dblock-end-re)
9840 (and (looking-at "[ \t]+")
9842 (insert indent)))))))
9844 (defun org-beginning-of-dblock ()
9845 "Find the beginning of the dynamic block at point.
9846 Error if there is no such block at point."
9850 (if (and (re-search-backward org-dblock-start-re nil t)
9851 (setq beg (match-beginning 0))
9852 (re-search-forward org-dblock-end-re nil t)
9853 (> (match-end 0) pos))
9856 (error "Not in a dynamic block"))))
9858 (defun org-update-all-dblocks ()
9859 "Update all dynamic blocks in the buffer.
9860 This function can be used in a hook."
9862 (org-map-dblocks 'org-update-dblock)))
9867 (defconst org-additional-option-like-keywords
9868 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
9869 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
9870 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
9871 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
9873 "ORGTBL" "TBLFM:" "TBLNAME:"
9874 "BEGIN_EXAMPLE" "END_EXAMPLE"
9875 "BEGIN_QUOTE" "END_QUOTE"
9876 "BEGIN_VERSE" "END_VERSE"
9877 "BEGIN_CENTER" "END_CENTER"
9878 "BEGIN_SRC" "END_SRC"
9879 "CATEGORY" "COLUMNS"
9885 (defcustom org-structure-template-alist
9887 ("s" "#+begin_src ?\n\n#+end_src"
9888 "<src lang=\"?\">\n\n</src>")
9889 ("e" "#+begin_example\n?\n#+end_example"
9890 "<example>\n?\n</example>")
9891 ("q" "#+begin_quote\n?\n#+end_quote"
9892 "<quote>\n?\n</quote>")
9893 ("v" "#+begin_verse\n?\n#+end_verse"
9894 "<verse>\n?\n/verse>")
9895 ("c" "#+begin_center\n?\n#+end_center"
9896 "<center>\n?\n/center>")
9897 ("l" "#+begin_latex\n?\n#+end_latex"
9898 "<literal style=\"latex\">\n?\n</literal>")
9900 "<literal style=\"latex\">?</literal>")
9901 ("h" "#+begin_html\n?\n#+end_html"
9902 "<literal style=\"html\">\n?\n</literal>")
9904 "<literal style=\"html\">?</literal>")
9905 ("a" "#+begin_ascii\n?\n#+end_ascii")
9907 ("i" "#+include %file ?"
9908 "<include file=%file markup=\"?\">")
9910 "Structure completion elements.
9911 This is a list of abbreviation keys and values. The value gets inserted
9912 it you type @samp{.} followed by the key and then the completion key,
9913 usually `M-TAB'. %file will be replaced by a file name after prompting
9914 for the file using completion.
9915 There are two templates for each key, the first uses the original Org syntax,
9916 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
9917 the default when the /org-mtags.el/ module has been loaded. See also the
9918 variable `org-mtags-prefer-muse-templates'.
9919 This is an experimental feature, it is undecided if it is going to stay in."
9920 :group 'org-completion
9923 (string :tag "Template")
9924 (string :tag "Muse Template")))
9926 (defun org-try-structure-completion ()
9927 "Try to complete a structure template before point.
9928 This looks for strings like \"<e\" on an otherwise empty line and
9930 (let ((l (buffer-substring (point-at-bol) (point)))
9932 (when (and (looking-at "[ \t]*$")
9933 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
9934 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
9935 (org-complete-expand-structure-template (+ -1 (point-at-bol)
9936 (match-beginning 1)) a)
9939 (defun org-complete-expand-structure-template (start cell)
9940 "Expand a structure template."
9941 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
9942 (rpl (nth (if musep 2 1) cell))
9944 (delete-region start (point))
9945 (when (string-match "\\`#\\+" rpl)
9948 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
9949 (setq ind (buffer-substring (point-at-bol) (point))))
9951 (setq start (point))
9952 (if (string-match "%file" rpl)
9953 (setq rpl (replace-match
9957 (abbreviate-file-name (read-file-name "Include file: ")))
9960 (setq rpl (mapconcat 'identity (split-string rpl "\n")
9963 (if (re-search-backward "\\?" start t) (delete-char 1))))
9966 (defun org-complete (&optional arg)
9967 "Perform completion on word at point.
9968 At the beginning of a headline, this completes TODO keywords as given in
9969 `org-todo-keywords'.
9970 If the current word is preceded by a backslash, completes the TeX symbols
9971 that are supported for HTML support.
9972 If the current word is preceded by \"#+\", completes special words for
9973 setting file options.
9974 In the line after \"#+STARTUP:, complete valid keywords.\"
9975 At all other locations, this simply calls the value of
9976 `org-completion-fallback-command'."
9978 (org-without-partial-completion
9982 (beg1 (save-excursion
9983 (skip-chars-backward (org-re "[:alnum:]_@"))
9985 (beg (save-excursion
9986 (skip-chars-backward "a-zA-Z0-9_:$")
9988 (confirm (lambda (x) (stringp (car x))))
9989 (searchhead (equal (char-before beg) ?*))
9991 (when (and (member (char-before beg1) '(?. ?<))
9992 (setq a (assoc (buffer-substring beg1 (point))
9993 org-structure-template-alist)))
9994 (org-complete-expand-structure-template (1- beg1) a)
9996 (tag (and (equal (char-before beg1) ?:)
9997 (equal (char-after (point-at-bol)) ?*)))
9998 (prop (and (equal (char-before beg1) ?:)
9999 (not (equal (char-after (point-at-bol)) ?*))))
10000 (texp (equal (char-before beg) ?\\))
10001 (link (equal (char-before beg) ?\[))
10002 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10005 (startup (string-match "^#\\+STARTUP:.*"
10006 (buffer-substring (point-at-bol) (point))))
10007 (completion-ignore-case opt)
10019 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10020 (cons (match-string 2 x)
10021 (match-string 1 x))))
10022 (org-split-string (org-get-current-options) "\n")))
10023 (mapcar 'list org-additional-option-like-keywords)))
10025 (setq type :startup)
10026 org-startup-options)
10027 (link (append org-link-abbrev-alist-local
10028 org-link-abbrev-alist))
10031 (append org-entities-user org-entities))
10032 ((string-match "\\`\\*+[ \t]+\\'"
10033 (buffer-substring (point-at-bol) beg))
10035 (mapcar 'list org-todo-keywords-1))
10037 (setq type :searchhead)
10039 (goto-char (point-min))
10040 (while (re-search-forward org-todo-line-regexp nil t)
10042 (org-make-org-heading-search-string
10043 (match-string 3) t))
10046 (tag (setq type :tag beg beg1)
10047 (or org-tag-alist (org-get-buffer-tags)))
10048 (prop (setq type :prop beg beg1)
10049 (mapcar 'list (org-buffer-property-keys nil t t)))
10051 (call-interactively org-completion-fallback-command)
10052 (throw 'exit nil)))))
10053 (pattern (buffer-substring-no-properties beg end))
10054 (completion (try-completion pattern table confirm)))
10055 (cond ((eq completion t)
10056 (if (not (assoc (upcase pattern) table))
10057 (message "Already complete")
10058 (if (and (equal type :opt)
10059 (not (member (car (assoc (upcase pattern) table))
10060 org-additional-option-like-keywords)))
10061 (insert (substring (cdr (assoc (upcase pattern) table))
10063 (if (memq type '(:tag :prop)) (insert ":")))))
10065 (message "Can't find completion for \"%s\"" pattern)
10067 ((not (string= pattern completion))
10068 (delete-region beg end)
10069 (if (string-match " +$" completion)
10070 (setq completion (replace-match "" t t completion)))
10071 (insert completion)
10072 (if (get-buffer-window "*Completions*")
10073 (delete-window (get-buffer-window "*Completions*")))
10074 (if (assoc completion table)
10075 (if (eq type :todo) (insert " ")
10076 (if (memq type '(:tag :prop)) (insert ":"))))
10077 (if (and (equal type :opt) (assoc completion table))
10078 (message "%s" (substitute-command-keys
10079 "Press \\[org-complete] again to insert example settings"))))
10081 (message "Making completion list...")
10082 (let ((list (sort (all-completions pattern table confirm)
10084 (with-output-to-temp-buffer "*Completions*"
10085 (condition-case nil
10086 ;; Protection needed for XEmacs and emacs 21
10087 (display-completion-list list pattern)
10088 (error (display-completion-list list)))))
10089 (message "Making completion list...%s" "done")))))))
10091 ;;;; TODO, DEADLINE, Comments
10093 (defun org-toggle-comment ()
10094 "Change the COMMENT state of an entry."
10097 (org-back-to-heading)
10098 (let (case-fold-search)
10099 (if (looking-at (concat outline-regexp
10100 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10101 (replace-match "" t t nil 1)
10102 (if (looking-at outline-regexp)
10104 (goto-char (match-end 0))
10105 (insert org-comment-string " ")))))))
10107 (defvar org-last-todo-state-is-todo nil
10108 "This is non-nil when the last TODO state change led to a TODO state.
10109 If the last change removed the TODO tag or switched to DONE, then
10112 (defvar org-setting-tags nil) ; dynamically skipped
10114 (defun org-parse-local-options (string var)
10115 "Parse STRING for startup setting relevant for variable VAR."
10116 (let ((rtn (symbol-value var))
10119 (if (or (not string) (not (string-match "\\S-" string)))
10121 (setq opts (delq nil (mapcar (lambda (x)
10122 (setq e (assoc x org-startup-options))
10123 (if (eq (nth 1 e) var) e nil))
10124 (org-split-string string "[ \t]+"))))
10128 (while (setq e (pop opts))
10129 (if (not (nth 3 e))
10130 (setq rtn (nth 2 e))
10131 (if (not (listp rtn)) (setq rtn nil))
10132 (push (nth 2 e) rtn)))
10135 (defvar org-todo-setup-filter-hook nil
10136 "Hook for functions that pre-filter todo specs.
10138 Each function takes a todo spec and returns either `nil' or the spec
10139 transformed into canonical form." )
10141 (defvar org-todo-get-default-hook nil
10142 "Hook for functions that get a default item for todo.
10144 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10145 `nil' or a string to be used for the todo mark." )
10147 (defvar org-agenda-headline-snapshot-before-repeat)
10149 (defun org-todo (&optional arg)
10150 "Change the TODO state of an item.
10151 The state of an item is given by a keyword at the start of the heading,
10153 *** TODO Write paper
10156 The different keywords are specified in the variable `org-todo-keywords'.
10157 By default the available states are \"TODO\" and \"DONE\".
10158 So for this example: when the item starts with TODO, it is changed to DONE.
10159 When it starts with DONE, the DONE is removed. And when neither TODO nor
10160 DONE are present, add TODO at the beginning of the heading.
10162 With C-u prefix arg, use completion to determine the new state.
10163 With numeric prefix arg, switch to that state.
10164 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10165 With a triple C-u prefix, circumvent any state blocking.
10167 For calling through lisp, arg is also interpreted in the following way:
10168 'none -> empty state
10169 \"\"(empty string) -> switch to empty state
10170 'done -> switch to DONE
10171 'nextset -> switch to the next set of keywords
10172 'previousset -> switch to the previous set of keywords
10173 \"WAITING\" -> switch to the specified keyword, but only if it
10174 really is a member of `org-todo-keywords'."
10176 (if (equal arg '(16)) (setq arg 'nextset))
10177 (let ((org-blocker-hook org-blocker-hook)
10178 (case-fold-search nil))
10179 (when (equal arg '(64))
10180 (setq arg nil org-blocker-hook nil))
10181 (when (and org-blocker-hook
10182 (or org-inhibit-blocking
10183 (org-entry-get nil "NOBLOCKING")))
10184 (setq org-blocker-hook nil))
10187 (org-back-to-heading t)
10188 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10189 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10191 (let* ((match-data (match-data))
10192 (startpos (point-at-bol))
10193 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
10194 (org-log-done org-log-done)
10195 (org-log-repeat org-log-repeat)
10196 (org-todo-log-states org-todo-log-states)
10197 (this (match-string 1))
10198 (hl-pos (match-beginning 0))
10199 (head (org-get-todo-sequence-head this))
10200 (ass (assoc head org-todo-kwd-alist))
10201 (interpret (nth 1 ass))
10202 (done-word (nth 3 ass))
10203 (final-done-word (nth 4 ass))
10204 (last-state (or this ""))
10205 (completion-ignore-case t)
10206 (member (member this org-todo-keywords-1))
10207 (tail (cdr member))
10209 ((and org-todo-key-trigger
10210 (or (and (equal arg '(4))
10211 (eq org-use-fast-todo-selection 'prefix))
10212 (and (not arg) org-use-fast-todo-selection
10213 (not (eq org-use-fast-todo-selection
10215 ;; Use fast selection
10216 (org-fast-todo-selection))
10217 ((and (equal arg '(4))
10218 (or (not org-use-fast-todo-selection)
10219 (not org-todo-key-trigger)))
10220 ;; Read a state with completion
10221 (org-icompleting-read
10222 "State: " (mapcar (lambda(x) (list x))
10223 org-todo-keywords-1)
10227 (if tail (car tail) nil)
10228 (car org-todo-keywords-1)))
10230 (if (equal member org-todo-keywords-1)
10233 (nth (- (length org-todo-keywords-1)
10235 org-todo-keywords-1)
10236 (org-last org-todo-keywords-1))))
10237 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10238 (setq arg nil))) ; hack to fall back to cycling
10240 ;; user or caller requests a specific state
10242 ((equal arg "") nil)
10243 ((eq arg 'none) nil)
10244 ((eq arg 'done) (or done-word (car org-done-keywords)))
10246 (or (car (cdr (member head org-todo-heads)))
10247 (car org-todo-heads)))
10248 ((eq arg 'previousset)
10249 (let ((org-todo-heads (reverse org-todo-heads)))
10250 (or (car (cdr (member head org-todo-heads)))
10251 (car org-todo-heads))))
10252 ((car (member arg org-todo-keywords-1)))
10254 (error "State `%s' not valid in this file" arg))
10255 ((nth (1- (prefix-numeric-value arg))
10256 org-todo-keywords-1))))
10257 ((null member) (or head (car org-todo-keywords-1)))
10258 ((equal this final-done-word) nil) ;; -> make empty
10259 ((null tail) nil) ;; -> first entry
10260 ((memq interpret '(type priority))
10261 (if (eq this-command last-command)
10263 (if (> (length tail) 0)
10264 (or done-word (car org-done-keywords))
10269 (run-hook-with-args-until-success
10270 'org-todo-get-default-hook state last-state)
10272 (next (if state (concat " " state " ") " "))
10273 (change-plist (list :type 'todo-state-change :from this :to state
10274 :position startpos))
10276 (when org-blocker-hook
10277 (setq org-last-todo-state-is-todo
10278 (not (member this org-done-keywords)))
10279 (unless (save-excursion
10281 (run-hook-with-args-until-failure
10282 'org-blocker-hook change-plist)))
10283 (if (interactive-p)
10284 (error "TODO state change from %s to %s blocked" this state)
10286 (message "TODO state change from %s to %s blocked" this state)
10287 (throw 'exit nil))))
10288 (store-match-data match-data)
10289 (replace-match next t t)
10290 (unless (pos-visible-in-window-p hl-pos)
10291 (message "TODO state changed to %s" (org-trim next)))
10293 (setq head (org-get-todo-sequence-head state)
10294 ass (assoc head org-todo-kwd-alist)
10295 interpret (nth 1 ass)
10296 done-word (nth 3 ass)
10297 final-done-word (nth 4 ass)))
10298 (when (memq arg '(nextset previousset))
10299 (message "Keyword-Set %d/%d: %s"
10300 (- (length org-todo-sets) -1
10301 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10302 (length org-todo-sets)
10303 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10304 (setq org-last-todo-state-is-todo
10305 (not (member state org-done-keywords)))
10306 (setq now-done-p (and (member state org-done-keywords)
10307 (not (member this org-done-keywords))))
10308 (and logging (org-local-logging logging))
10309 (when (and (or org-todo-log-states org-log-done)
10310 (not (eq org-inhibit-logging t))
10311 (not (memq arg '(nextset previousset))))
10312 ;; we need to look at recording a time and note
10313 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10314 (nth 2 (assoc this org-todo-log-states))))
10315 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10316 (setq dolog 'time))
10318 (member state org-not-done-keywords)
10319 (not (member this org-not-done-keywords)))
10320 ;; This is now a todo state and was not one before
10321 ;; If there was a CLOSED time stamp, get rid of it.
10322 (org-add-planning-info nil nil 'closed))
10323 (when (and now-done-p org-log-done)
10324 ;; It is now done, and it was not done before
10325 (org-add-planning-info 'closed (org-current-time))
10326 (if (and (not dolog) (eq 'note org-log-done))
10327 (org-add-log-setup 'done state this 'findpos 'note)))
10328 (when (and state dolog)
10329 ;; This is a non-nil state, and we need to log it
10330 (org-add-log-setup 'state state this 'findpos dolog)))
10331 ;; Fixup tag positioning
10332 (org-todo-trigger-tag-changes state)
10333 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10334 (when org-provide-todo-statistics
10335 (org-update-parent-todo-statistics))
10336 (run-hooks 'org-after-todo-state-change-hook)
10337 (if (and arg (not (member state org-done-keywords)))
10338 (setq head (org-get-todo-sequence-head state)))
10339 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10340 ;; Do we need to trigger a repeat?
10342 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10343 ;; This is for the agenda, take a snapshot of the headline.
10345 (setq org-agenda-headline-snapshot-before-repeat
10346 (org-get-heading))))
10347 (org-auto-repeat-maybe state))
10348 ;; Fixup cursor location if close to the keyword
10349 (if (and (outline-on-heading-p)
10351 (save-excursion (beginning-of-line 1)
10352 (looking-at org-todo-line-regexp))
10353 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10355 (goto-char (or (match-end 2) (match-end 1)))
10356 (and (looking-at " ") (just-one-space))))
10357 (when org-trigger-hook
10359 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10361 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10362 "Block turning an entry into a TODO, using the hierarchy.
10363 This checks whether the current task should be blocked from state
10364 changes. Such blocking occurs when:
10366 1. The task has children which are not all in a completed state.
10368 2. A task has a parent with the property :ORDERED:, and there
10369 are siblings prior to the current task with incomplete
10372 3. The parent of the task is blocked because it has siblings that should
10373 be done first, or is child of a block grandparent TODO entry."
10375 (if (not org-enforce-todo-dependencies)
10376 t ; if locally turned off don't block
10378 ;; If this is not a todo state change, or if this entry is already DONE,
10380 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10381 (member (plist-get change-plist :from)
10382 (cons 'done org-done-keywords))
10383 (member (plist-get change-plist :to)
10384 (cons 'todo org-not-done-keywords))
10385 (not (plist-get change-plist :to)))
10386 (throw 'dont-block t))
10387 ;; If this task has children, and any are undone, it's blocked
10389 (org-back-to-heading t)
10390 (let ((this-level (funcall outline-level)))
10391 (outline-next-heading)
10392 (let ((child-level (funcall outline-level)))
10393 (while (and (not (eobp))
10394 (> child-level this-level))
10395 ;; this todo has children, check whether they are all
10397 (if (and (not (org-entry-is-done-p))
10398 (org-entry-is-todo-p))
10399 (throw 'dont-block nil))
10400 (outline-next-heading)
10401 (setq child-level (funcall outline-level))))))
10402 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10403 ;; any previous siblings are undone, it's blocked
10405 (org-back-to-heading t)
10406 (let* ((pos (point))
10407 (parent-pos (and (org-up-heading-safe) (point))))
10408 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10409 (when (and (org-entry-get (point) "ORDERED")
10411 (re-search-forward org-not-done-heading-regexp pos t))
10412 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10413 ;; Search further up the hierarchy, to see if an anchestor is blocked
10415 (goto-char parent-pos)
10416 (if (not (looking-at org-not-done-heading-regexp))
10417 (throw 'dont-block t)) ; do not block, parent is not a TODO
10419 (setq parent-pos (and (org-up-heading-safe) (point)))
10420 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10421 (when (and (org-entry-get (point) "ORDERED")
10423 (re-search-forward org-not-done-heading-regexp pos t))
10424 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10426 (defcustom org-track-ordered-property-with-tag nil
10427 "Should the ORDERED property also be shown as a tag?
10428 The ORDERED property decides if an entry should require subtasks to be
10429 completed in sequence. Since a property is not very visible, setting
10430 this option means that toggling the ORDERED property with the command
10431 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10432 not relevant for the behavior, but it makes things more visible.
10434 Note that toggling the tag with tags commands will not change the property
10435 and therefore not influence behavior!
10437 This can be t, meaning the tag ORDERED should be used, It can also be a
10438 string to select a different tag for this task."
10441 (const :tag "No tracking" nil)
10442 (const :tag "Track with ORDERED tag" t)
10443 (string :tag "Use other tag")))
10445 (defun org-toggle-ordered-property ()
10446 "Toggle the ORDERED property of the current entry.
10447 For better visibility, you can track the value of this property with a tag.
10448 See variable `org-track-ordered-property-with-tag'."
10450 (let* ((t1 org-track-ordered-property-with-tag)
10451 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10453 (org-back-to-heading)
10454 (if (org-entry-get nil "ORDERED")
10456 (org-delete-property "ORDERED")
10457 (and tag (org-toggle-tag tag 'off))
10458 (message "Subtasks can be completed in arbitrary order"))
10459 (org-entry-put nil "ORDERED" "t")
10460 (and tag (org-toggle-tag tag 'on))
10461 (message "Subtasks must be completed in sequence")))))
10463 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10464 (defun org-block-todo-from-checkboxes (change-plist)
10465 "Block turning an entry into a TODO, using checkboxes.
10466 This checks whether the current task should be blocked from state
10467 changes because there are unchecked boxes in this entry."
10468 (if (not org-enforce-todo-checkbox-dependencies)
10469 t ; if locally turned off don't block
10471 ;; If this is not a todo state change, or if this entry is already DONE,
10473 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10474 (member (plist-get change-plist :from)
10475 (cons 'done org-done-keywords))
10476 (member (plist-get change-plist :to)
10477 (cons 'todo org-not-done-keywords))
10478 (not (plist-get change-plist :to)))
10479 (throw 'dont-block t))
10480 ;; If this task has checkboxes that are not checked, it's blocked
10482 (org-back-to-heading t)
10483 (let ((beg (point)) end)
10484 (outline-next-heading)
10487 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10490 (if (boundp 'org-blocked-by-checkboxes)
10491 (setq org-blocked-by-checkboxes t))
10492 (throw 'dont-block nil)))))
10493 t))) ; do not block
10495 (defun org-entry-blocked-p ()
10496 "Is the current entry blocked?"
10497 (if (org-entry-get nil "NOBLOCKING")
10498 nil ;; Never block this entry
10500 (run-hook-with-args-until-failure
10502 (list :type 'todo-state-change
10507 (defun org-update-statistics-cookies (all)
10508 "Update the statistics cookie, either from TODO or from checkboxes.
10509 This should be called with the cursor in a line with a statistics cookie."
10513 (org-update-checkbox-count 'all)
10514 (org-map-entries 'org-update-parent-todo-statistics))
10515 (if (not (org-on-heading-p))
10516 (org-update-checkbox-count)
10517 (let ((pos (move-marker (make-marker) (point)))
10519 (ignore-errors (org-back-to-heading t))
10520 (if (not (org-on-heading-p))
10521 (org-update-checkbox-count)
10522 (setq l1 (org-outline-level))
10523 (setq end (save-excursion
10524 (outline-next-heading)
10525 (if (org-on-heading-p) (setq l2 (org-outline-level)))
10527 (if (and (save-excursion
10529 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
10530 (not (save-excursion (re-search-forward
10531 ":COOKIE_DATA:.*\\<todo\\>" end t))))
10532 (org-update-checkbox-count)
10533 (if (and l2 (> l2 l1))
10536 (org-update-parent-todo-statistics))
10538 (beginning-of-line 1)
10539 (while (re-search-forward
10540 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
10542 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
10544 (move-marker pos nil)))))
10546 (defvar org-entry-property-inherited-from) ;; defined below
10547 (defun org-update-parent-todo-statistics ()
10548 "Update any statistics cookie in the parent of the current headline.
10549 When `org-hierarchical-todo-statistics' is nil, statistics will cover
10550 the entire subtree and this will travel up the hierarchy and update
10551 statistics everywhere."
10553 (let* ((lim 0) prop
10554 (recursive (or (not org-hierarchical-todo-statistics)
10557 (or (setq prop (org-entry-get
10558 nil "COOKIE_DATA" 'inherit)) ""))))
10559 (lim (or (and prop (marker-position
10560 org-entry-property-inherited-from))
10563 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
10564 level ltoggle l1 new ndel
10565 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
10568 (beginning-of-line 1)
10569 (if (org-at-heading-p)
10570 (setq ltoggle (funcall outline-level))
10571 (error "This should not happen"))
10572 (while (and (setq level (org-up-heading-safe))
10573 (or recursive first)
10575 (setq first nil cookie-present nil)
10584 (while (re-search-forward box-re (point-at-eol) t)
10585 (setq cnt-all 0 cnt-done 0 cookie-present t)
10586 (setq is-percent (match-end 2))
10588 (unless (outline-next-heading) (throw 'exit nil))
10589 (while (and (looking-at org-complex-heading-regexp)
10590 (> (setq l1 (length (match-string 1))) level))
10591 (setq kwd (and (or recursive (= l1 ltoggle))
10593 (if (or (eq org-provide-todo-statistics 'all-headlines)
10594 (and (listp org-provide-todo-statistics)
10595 (or (member kwd org-provide-todo-statistics)
10596 (member kwd org-done-keywords))))
10597 (setq cnt-all (1+ cnt-all))
10598 (if (eq org-provide-todo-statistics t)
10599 (and kwd (setq cnt-all (1+ cnt-all)))))
10600 (and (member kwd org-done-keywords)
10601 (setq cnt-done (1+ cnt-done)))
10602 (outline-next-heading)))
10605 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
10606 (format "[%d/%d]" cnt-done cnt-all))
10607 ndel (- (match-end 0) (match-beginning 0)))
10608 (goto-char (match-beginning 0))
10610 (delete-region (point) (+ (point) ndel)))
10611 (when cookie-present
10612 (run-hook-with-args 'org-after-todo-statistics-hook
10613 cnt-done (- cnt-all cnt-done))))))
10614 (run-hooks 'org-todo-statistics-hook)))
10616 (defvar org-after-todo-statistics-hook nil
10617 "Hook that is called after a TODO statistics cookie has been updated.
10618 Each function is called with two arguments: the number of not-done entries
10619 and the number of done entries.
10621 For example, the following function, when added to this hook, will switch
10622 an entry to DONE when all children are done, and back to TODO when new
10623 entries are set to a TODO status. Note that this hook is only called
10624 when there is a statistics cookie in the headline!
10626 (defun org-summary-todo (n-done n-not-done)
10627 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
10628 (let (org-log-done org-log-states) ; turn off logging
10629 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
10632 (defvar org-todo-statistics-hook nil
10633 "Hook that is run whenever Org thinks TODO statistics should be updated.
10634 This hook runs even if there is no statistics cookie present, in which case
10635 `org-after-todo-statistics-hook' would not run.")
10637 (defun org-todo-trigger-tag-changes (state)
10638 "Apply the changes defined in `org-todo-state-tags-triggers'."
10639 (let ((l org-todo-state-tags-triggers)
10641 (when (or (not state) (equal state ""))
10642 (setq changes (append changes (cdr (assoc "" l)))))
10643 (when (and (stringp state) (> (length state) 0))
10644 (setq changes (append changes (cdr (assoc state l)))))
10645 (when (member state org-not-done-keywords)
10646 (setq changes (append changes (cdr (assoc 'todo l)))))
10647 (when (member state org-done-keywords)
10648 (setq changes (append changes (cdr (assoc 'done l)))))
10649 (dolist (c changes)
10650 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
10652 (defun org-local-logging (value)
10653 "Get logging settings from a property VALUE."
10655 ;; directly set the variables, they are already local.
10656 (setq org-log-done nil
10658 org-todo-log-states nil)
10659 (setq words (org-split-string value))
10660 (while (setq w (pop words))
10662 ((setq a (assoc w org-startup-options))
10663 (and (member (nth 1 a) '(org-log-done org-log-repeat))
10664 (set (nth 1 a) (nth 2 a))))
10665 ((setq a (org-extract-log-state-settings w))
10666 (and (member (car a) org-todo-keywords-1)
10667 (push a org-todo-log-states)))))))
10669 (defun org-get-todo-sequence-head (kwd)
10670 "Return the head of the TODO sequence to which KWD belongs.
10671 If KWD is not set, check if there is a text property remembering the
10676 (or (get-text-property (point-at-bol) 'org-todo-head)
10678 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
10679 nil (point-at-eol)))
10680 (get-text-property p 'org-todo-head))))
10681 ((not (member kwd org-todo-keywords-1))
10682 (car org-todo-keywords-1))
10683 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
10685 (defun org-fast-todo-selection ()
10686 "Fast TODO keyword selection with single keys.
10687 Returns the new TODO keyword, or nil if no state change should occur."
10688 (let* ((fulltable org-todo-key-alist)
10689 (done-keywords org-done-keywords) ;; needed for the faces.
10690 (maxlen (apply 'max (mapcar
10692 (if (stringp (car x)) (string-width (car x)) 0))
10695 (fwidth (+ maxlen 3 1 3))
10696 (ncol (/ (- (window-width) 4) fwidth))
10700 (save-window-excursion
10702 (set-buffer (get-buffer-create " *Org todo*"))
10703 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
10705 (org-set-local 'org-done-keywords done-keywords)
10706 (setq tbl fulltable cnt 0)
10707 (while (setq e (pop tbl))
10709 ((equal e '(:startgroup))
10710 (push '() groups) (setq ingroup t)
10711 (when (not (= cnt 0))
10715 ((equal e '(:endgroup))
10716 (setq ingroup nil cnt 0)
10718 ((equal e '(:newline))
10719 (when (not (= cnt 0))
10723 (while (equal (car tbl) '(:newline))
10725 (setq tbl (cdr tbl)))))
10727 (setq tg (car e) c (cdr e))
10728 (if ingroup (push tg (car groups)))
10729 (setq tg (org-add-props tg nil 'face
10730 (org-get-todo-face tg)))
10731 (if (and (= cnt 0) (not ingroup)) (insert " "))
10732 (insert "[" c "] " tg (make-string
10733 (- fwidth 4 (length tg)) ?\ ))
10734 (when (= (setq cnt (1+ cnt)) ncol)
10736 (if ingroup (insert " "))
10739 (goto-char (point-min))
10740 (if (not expert) (org-fit-window-to-buffer))
10741 (message "[a-z..]:Set [SPC]:clear")
10742 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
10745 (and (= c ?q) (not (rassoc c fulltable))))
10746 (setq quit-flag t))
10748 ((setq e (rassoc c fulltable) tg (car e))
10750 (t (setq quit-flag t)))))))
10752 (defun org-entry-is-todo-p ()
10753 (member (org-get-todo-state) org-not-done-keywords))
10755 (defun org-entry-is-done-p ()
10756 (member (org-get-todo-state) org-done-keywords))
10758 (defun org-get-todo-state ()
10760 (org-back-to-heading t)
10761 (and (looking-at org-todo-line-regexp)
10763 (match-string 2))))
10765 (defun org-at-date-range-p (&optional inactive-ok)
10766 "Is the cursor inside a date range?"
10770 (let ((pos (point)))
10771 (skip-chars-backward "^[<\r\n")
10772 (skip-chars-backward "<[")
10773 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10774 (>= (match-end 0) pos)
10776 (skip-chars-backward "^<[\r\n")
10777 (skip-chars-backward "<[")
10778 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10779 (>= (match-end 0) pos)
10783 (defun org-get-repeat (&optional tagline)
10784 "Check if there is a deadline/schedule with repeater in this entry."
10787 (org-back-to-heading t)
10788 (and (re-search-forward (if tagline
10789 (concat tagline "\\s-*" org-repeat-re)
10791 (org-entry-end-position) t)
10792 (match-string-no-properties 1)))))
10794 (defvar org-last-changed-timestamp)
10795 (defvar org-last-inserted-timestamp)
10796 (defvar org-log-post-message)
10797 (defvar org-log-note-purpose)
10798 (defvar org-log-note-how)
10799 (defvar org-log-note-extra)
10800 (defun org-auto-repeat-maybe (done-word)
10801 "Check if the current headline contains a repeated deadline/schedule.
10802 If yes, set TODO state back to what it was and change the base date
10803 of repeating deadline/scheduled time stamps to new date.
10804 This function is run automatically after each state change to a DONE state."
10805 ;; last-state is dynamically scoped into this function
10806 (let* ((repeat (org-get-repeat))
10807 (aa (assoc last-state org-todo-kwd-alist))
10808 (interpret (nth 1 aa))
10810 (whata '(("d" . day) ("m" . month) ("y" . year)))
10811 (msg "Entry repeats: ")
10813 (org-todo-log-states nil)
10814 (nshiftmax 10) (nshift 0)
10815 re type n what ts time)
10817 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
10818 (org-todo (if (eq interpret 'type) last-state head))
10819 (org-entry-put nil "LAST_REPEAT" (format-time-string
10820 (org-time-stamp-format t t)))
10821 (when org-log-repeat
10822 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
10823 (memq 'org-add-log-note post-command-hook))
10824 ;; OK, we are already setup for some record
10825 (if (eq org-log-repeat 'note)
10826 ;; make sure we take a note, not only a time stamp
10827 (setq org-log-note-how 'note))
10828 ;; Set up for taking a record
10829 (org-add-log-setup 'state (or done-word (car org-done-keywords))
10831 'findpos org-log-repeat)))
10832 (org-back-to-heading t)
10833 (org-add-planning-info nil nil 'closed)
10834 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
10835 org-deadline-time-regexp "\\)\\|\\("
10836 org-ts-regexp "\\)"))
10837 (while (re-search-forward
10838 re (save-excursion (outline-next-heading) (point)) t)
10839 (setq type (if (match-end 1) org-scheduled-string
10840 (if (match-end 3) org-deadline-string "Plain:"))
10841 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
10842 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
10843 (setq n (string-to-number (match-string 2 ts))
10844 what (match-string 3 ts))
10845 (if (equal what "w") (setq n (* n 7) what "d"))
10846 ;; Preparation, see if we need to modify the start date for the change
10847 (when (match-end 1)
10848 (setq time (save-match-data (org-time-string-to-time ts)))
10850 ((equal (match-string 1 ts) ".")
10851 ;; Shift starting date to today
10852 (org-timestamp-change
10853 (- (time-to-days (current-time)) (time-to-days time))
10855 ((equal (match-string 1 ts) "+")
10856 (while (or (= nshift 0)
10857 (<= (time-to-days time) (time-to-days (current-time))))
10858 (when (= (incf nshift) nshiftmax)
10859 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
10861 (org-timestamp-change n (cdr (assoc what whata)))
10862 (org-at-timestamp-p t)
10863 (setq ts (match-string 1))
10864 (setq time (save-match-data (org-time-string-to-time ts))))
10865 (org-timestamp-change (- n) (cdr (assoc what whata)))
10866 ;; rematch, so that we have everything in place for the real shift
10867 (org-at-timestamp-p t)
10868 (setq ts (match-string 1))
10869 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
10870 (org-timestamp-change n (cdr (assoc what whata)))
10871 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
10872 (setq org-log-post-message msg)
10873 (message "%s" msg))))
10875 (defun org-show-todo-tree (arg)
10876 "Make a compact tree which shows all headlines marked with TODO.
10877 The tree will show the lines where the regexp matches, and all higher
10878 headlines above the match.
10879 With a \\[universal-argument] prefix, prompt for a regexp to match.
10880 With a numeric prefix N, construct a sparse tree for the Nth element
10881 of `org-todo-keywords-1'."
10883 (let ((case-fold-search nil)
10885 (cond ((null arg) org-not-done-regexp)
10887 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
10888 (mapcar 'list org-todo-keywords-1))))
10890 (mapconcat 'identity (org-split-string kwd "|") "\\|")
10892 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
10893 (regexp-quote (nth (1- (prefix-numeric-value arg))
10894 org-todo-keywords-1)))
10895 (t (error "Invalid prefix argument: %s" arg)))))
10896 (message "%d TODO entries found"
10897 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
10899 (defun org-deadline (&optional remove time)
10900 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
10901 With argument REMOVE, remove any deadline from the item.
10902 When TIME is set, it should be an internal time specification, and the
10903 scheduling will use the corresponding date."
10905 (let* ((old-date (org-entry-get nil "DEADLINE"))
10906 (repeater (and old-date
10907 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
10908 (match-string 1 old-date))))
10911 (when (and old-date org-log-redeadline)
10912 (org-add-log-setup 'deldeadline nil old-date 'findpos
10913 org-log-redeadline))
10914 (org-remove-timestamp-with-keyword org-deadline-string)
10915 (message "Item no longer has a deadline."))
10916 (org-add-planning-info 'deadline time 'closed)
10917 (when (and old-date org-log-redeadline
10918 (not (equal old-date
10919 (substring org-last-inserted-timestamp 1 -1))))
10920 (org-add-log-setup 'redeadline nil old-date 'findpos
10921 org-log-redeadline))
10924 (org-back-to-heading t)
10925 (when (re-search-forward (concat org-deadline-string " "
10926 org-last-inserted-timestamp)
10928 (outline-next-heading) (point)) t)
10929 (goto-char (1- (match-end 0)))
10930 (insert " " repeater)
10931 (setq org-last-inserted-timestamp
10932 (concat (substring org-last-inserted-timestamp 0 -1)
10934 (substring org-last-inserted-timestamp -1))))))
10935 (message "Deadline on %s" org-last-inserted-timestamp))))
10937 (defun org-schedule (&optional remove time)
10938 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
10939 With argument REMOVE, remove any scheduling date from the item.
10940 When TIME is set, it should be an internal time specification, and the
10941 scheduling will use the corresponding date."
10943 (let* ((old-date (org-entry-get nil "SCHEDULED"))
10944 (repeater (and old-date
10945 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
10946 (match-string 1 old-date))))
10949 (when (and old-date org-log-reschedule)
10950 (org-add-log-setup 'delschedule nil old-date 'findpos
10951 org-log-reschedule))
10952 (org-remove-timestamp-with-keyword org-scheduled-string)
10953 (message "Item is no longer scheduled."))
10954 (org-add-planning-info 'scheduled time 'closed)
10955 (when (and old-date org-log-reschedule
10956 (not (equal old-date
10957 (substring org-last-inserted-timestamp 1 -1))))
10958 (org-add-log-setup 'reschedule nil old-date 'findpos
10959 org-log-reschedule))
10962 (org-back-to-heading t)
10963 (when (re-search-forward (concat org-scheduled-string " "
10964 org-last-inserted-timestamp)
10966 (outline-next-heading) (point)) t)
10967 (goto-char (1- (match-end 0)))
10968 (insert " " repeater)
10969 (setq org-last-inserted-timestamp
10970 (concat (substring org-last-inserted-timestamp 0 -1)
10972 (substring org-last-inserted-timestamp -1))))))
10973 (message "Scheduled to %s" org-last-inserted-timestamp))))
10975 (defun org-get-scheduled-time (pom &optional inherit)
10976 "Get the scheduled time as a time tuple, of a format suitable
10977 for calling org-schedule with, or if there is no scheduling,
10979 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
10981 (apply 'encode-time (org-parse-time-string time)))))
10983 (defun org-get-deadline-time (pom &optional inherit)
10984 "Get the deadine as a time tuple, of a format suitable for
10985 calling org-deadline with, or if there is no scheduling, returns
10987 (let ((time (org-entry-get pom "DEADLINE" inherit)))
10989 (apply 'encode-time (org-parse-time-string time)))))
10991 (defun org-remove-timestamp-with-keyword (keyword)
10992 "Remove all time stamps with KEYWORD in the current entry."
10993 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
10996 (org-back-to-heading t)
10998 (outline-next-heading)
10999 (while (re-search-backward re beg t)
11001 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11002 (equal (char-before) ?\ ))
11003 (backward-delete-char 1)
11004 (if (string-match "^[ \t]*$" (buffer-substring
11005 (point-at-bol) (point-at-eol)))
11006 (delete-region (point-at-bol)
11007 (min (point-max) (1+ (point-at-eol))))))))))
11009 (defun org-add-planning-info (what &optional time &rest remove)
11010 "Insert new timestamp with keyword in the line directly after the headline.
11011 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11012 If non is given, the user is prompted for a date.
11013 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11016 (let (org-time-was-given org-end-time-was-given ts
11017 end default-time default-input)
11020 (when (and (not time) (memq what '(scheduled deadline)))
11021 ;; Try to get a default date/time from existing timestamp
11023 (org-back-to-heading t)
11024 (setq end (save-excursion (outline-next-heading) (point)))
11025 (when (re-search-forward (if (eq what 'scheduled)
11026 org-scheduled-time-regexp
11027 org-deadline-time-regexp)
11029 (setq ts (match-string 1)
11031 (apply 'encode-time (org-parse-time-string ts))
11032 default-input (and ts (org-get-compact-tod ts))))))
11034 ;; If necessary, get the time from the user
11035 (setq time (or time (org-read-date nil 'to-time nil nil
11036 default-time default-input))))
11038 (when (and org-insert-labeled-timestamps-at-point
11039 (member what '(scheduled deadline)))
11041 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11042 (org-insert-time-stamp time org-time-was-given
11043 nil nil nil (list org-end-time-was-given))
11047 (let (col list elt ts buffer-invisibility-spec)
11048 (org-back-to-heading t)
11049 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11050 (goto-char (match-end 1))
11051 (setq col (current-column))
11052 (goto-char (match-end 0))
11053 (if (eobp) (insert "\n") (forward-char 1))
11054 (when (and (not what)
11057 org-keyword-time-not-clock-regexp))))
11058 ;; Nothing to add, nothing to remove...... :-)
11060 (if (and (not (looking-at outline-regexp))
11061 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11063 (not (equal (match-string 1) org-clock-string)))
11064 (narrow-to-region (match-beginning 0) (match-end 0))
11065 (insert-before-markers "\n")
11067 (narrow-to-region (point) (point))
11068 (and org-adapt-indentation (org-indent-to-column col)))
11069 ;; Check if we have to remove something.
11070 (setq list (cons what remove))
11072 (setq elt (pop list))
11073 (goto-char (point-min))
11074 (when (or (and (eq elt 'scheduled)
11075 (re-search-forward org-scheduled-time-regexp nil t))
11076 (and (eq elt 'deadline)
11077 (re-search-forward org-deadline-time-regexp nil t))
11078 (and (eq elt 'closed)
11079 (re-search-forward org-closed-time-regexp nil t)))
11081 (if (looking-at "--+<[^>]+>") (replace-match ""))
11082 (skip-chars-backward " ")
11083 (if (looking-at " +") (replace-match ""))))
11084 (goto-char (point-max))
11085 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11088 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11089 (cond ((eq what 'scheduled) org-scheduled-string)
11090 ((eq what 'deadline) org-deadline-string)
11091 ((eq what 'closed) org-closed-string))
11093 (setq ts (org-insert-time-stamp
11095 (or org-time-was-given
11096 (and (eq what 'closed) org-log-done-with-time))
11098 nil nil (list org-end-time-was-given)))
11100 (goto-char (point-min))
11102 (if (and (looking-at "[ \t]+\n")
11103 (equal (char-before) ?\n))
11104 (delete-region (1- (point)) (point-at-eol)))
11107 (defvar org-log-note-marker (make-marker))
11108 (defvar org-log-note-purpose nil)
11109 (defvar org-log-note-state nil)
11110 (defvar org-log-note-previous-state nil)
11111 (defvar org-log-note-how nil)
11112 (defvar org-log-note-extra nil)
11113 (defvar org-log-note-window-configuration nil)
11114 (defvar org-log-note-return-to (make-marker))
11115 (defvar org-log-post-message nil
11116 "Message to be displayed after a log note has been stored.
11117 The auto-repeater uses this.")
11119 (defun org-add-note ()
11120 "Add a note to the current entry.
11121 This is done in the same way as adding a state change note."
11123 (org-add-log-setup 'note nil nil 'findpos nil))
11125 (defvar org-property-end-re)
11126 (defun org-add-log-setup (&optional purpose state prev-state
11127 findpos how &optional extra)
11128 "Set up the post command hook to take a note.
11129 If this is about to TODO state change, the new state is expected in STATE.
11130 When FINDPOS is non-nil, find the correct position for the note in
11131 the current entry. If not, assume that it can be inserted at point.
11132 HOW is an indicator what kind of note should be created.
11133 EXTRA is additional text that will be inserted into the notes buffer."
11134 (let* ((org-log-into-drawer (org-log-into-drawer))
11135 (drawer (cond ((stringp org-log-into-drawer)
11136 org-log-into-drawer)
11137 (org-log-into-drawer "LOGBOOK")
11142 (org-back-to-heading t)
11143 (narrow-to-region (point) (save-excursion
11144 (outline-next-heading) (point)))
11145 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11146 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11148 (goto-char (match-end 0))
11151 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11154 (goto-char (match-end 0))
11155 (or org-log-states-order-reversed
11156 (and (re-search-forward org-property-end-re nil t)
11157 (goto-char (1- (match-beginning 0))))))
11158 (insert "\n:" drawer ":\n:END:")
11159 (beginning-of-line 0)
11160 (org-indent-line-function)
11161 (beginning-of-line 2)
11162 (org-indent-line-function)
11164 ((and org-log-state-notes-insert-after-drawers
11166 (forward-line) (looking-at org-drawer-regexp)))
11168 (while (looking-at org-drawer-regexp)
11169 (goto-char (match-end 0))
11170 (re-search-forward org-property-end-re (point-max) t)
11172 (forward-line -1)))
11173 (unless org-log-states-order-reversed
11174 (and (= (char-after) ?\n) (forward-char 1))
11175 (org-skip-over-state-notes)
11176 (skip-chars-backward " \t\n\r")))
11177 (move-marker org-log-note-marker (point))
11178 (setq org-log-note-purpose purpose
11179 org-log-note-state state
11180 org-log-note-previous-state prev-state
11181 org-log-note-how how
11182 org-log-note-extra extra)
11183 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11185 (defun org-skip-over-state-notes ()
11186 "Skip past the list of State notes in an entry."
11187 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11188 (while (looking-at "[ \t]*- State")
11189 (condition-case nil
11191 (error (org-end-of-item)))))
11193 (defun org-add-log-note (&optional purpose)
11194 "Pop up a window for taking a note, and add this note later at point."
11195 (remove-hook 'post-command-hook 'org-add-log-note)
11196 (setq org-log-note-window-configuration (current-window-configuration))
11197 (delete-other-windows)
11198 (move-marker org-log-note-return-to (point))
11199 (switch-to-buffer (marker-buffer org-log-note-marker))
11200 (goto-char org-log-note-marker)
11201 (org-switch-to-buffer-other-window "*Org Note*")
11203 (if (memq org-log-note-how '(time state))
11204 (let (current-prefix-arg) (org-store-log-note))
11205 (let ((org-inhibit-startup t)) (org-mode))
11206 (insert (format "# Insert note for %s.
11207 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11209 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11210 ((eq org-log-note-purpose 'done) "closed todo item")
11211 ((eq org-log-note-purpose 'state)
11212 (format "state change from \"%s\" to \"%s\""
11213 (or org-log-note-previous-state "")
11214 (or org-log-note-state "")))
11215 ((eq org-log-note-purpose 'reschedule)
11217 ((eq org-log-note-purpose 'delschedule)
11218 "no longer scheduled")
11219 ((eq org-log-note-purpose 'redeadline)
11220 "changing deadline")
11221 ((eq org-log-note-purpose 'deldeadline)
11222 "removing deadline")
11223 ((eq org-log-note-purpose 'refile)
11225 ((eq org-log-note-purpose 'note)
11227 (t (error "This should not happen")))))
11228 (if org-log-note-extra (insert org-log-note-extra))
11229 (org-set-local 'org-finish-function 'org-store-log-note)))
11231 (defvar org-note-abort nil) ; dynamically scoped
11232 (defun org-store-log-note ()
11233 "Finish taking a log note, and insert it to where it belongs."
11234 (let ((txt (buffer-string))
11235 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11237 (kill-buffer (current-buffer))
11238 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11239 (setq txt (replace-match "" t t txt)))
11240 (if (string-match "\\s-+\\'" txt)
11241 (setq txt (replace-match "" t t txt)))
11242 (setq lines (org-split-string txt "\n"))
11243 (when (and note (string-match "\\S-" note))
11245 (org-replace-escapes
11247 (list (cons "%u" (user-login-name))
11248 (cons "%U" user-full-name)
11249 (cons "%t" (format-time-string
11250 (org-time-stamp-format 'long 'inactive)
11252 (cons "%s" (if org-log-note-state
11253 (concat "\"" org-log-note-state "\"")
11255 (cons "%S" (if org-log-note-previous-state
11256 (concat "\"" org-log-note-previous-state "\"")
11258 (if lines (setq note (concat note " \\\\")))
11260 (when (or current-prefix-arg org-note-abort)
11261 (when org-log-into-drawer
11262 (org-remove-empty-drawer-at
11263 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11264 org-log-note-marker))
11267 (with-current-buffer (marker-buffer org-log-note-marker)
11269 (goto-char org-log-note-marker)
11270 (move-marker org-log-note-marker nil)
11272 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11273 (insert "- " (pop lines))
11274 (org-indent-line-function)
11275 (beginning-of-line 1)
11276 (looking-at "[ \t]*")
11277 (setq ind (concat (match-string 0) " "))
11279 (while lines (insert "\n" ind (pop lines)))
11280 (message "Note stored")
11281 (org-back-to-heading t)
11282 (org-cycle-hide-drawers 'children)))))
11283 (set-window-configuration org-log-note-window-configuration)
11284 (with-current-buffer (marker-buffer org-log-note-return-to)
11285 (goto-char org-log-note-return-to))
11286 (move-marker org-log-note-return-to nil)
11287 (and org-log-post-message (message "%s" org-log-post-message)))
11289 (defun org-remove-empty-drawer-at (drawer pos)
11290 "Remove an empty drawer DRAWER at position POS.
11291 POS may also be a marker."
11292 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11298 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11299 (replace-match ""))))))
11301 (defun org-sparse-tree (&optional arg)
11302 "Create a sparse tree, prompt for the details.
11303 This command can create sparse trees. You first need to select the type
11304 of match used to create the tree:
11306 t Show entries with a specific TODO keyword.
11307 m Show entries selected by a tags/property match.
11308 p Enter a property name and its value (both with completion on existing
11309 names/values) and show entries with that property.
11310 / Show entries matching a regular expression (`r' can be used as well)
11311 d Show deadlines due within `org-deadline-warning-days'.
11312 b Show deadlines and scheduled items before a date.
11313 a Show deadlines and scheduled items after a date."
11315 (let (ans kwd value)
11316 (message "Sparse tree: [/]regexp [t]odo-kwd [m]atch [p]roperty [d]eadlines [b]efore-date [a]fter-date")
11317 (setq ans (read-char-exclusive))
11320 (call-interactively 'org-check-deadlines))
11322 (call-interactively 'org-check-before-date))
11324 (call-interactively 'org-check-after-date))
11326 (org-show-todo-tree '(4)))
11327 ((member ans '(?T ?m))
11328 (call-interactively 'org-match-sparse-tree))
11329 ((member ans '(?p ?P))
11330 (setq kwd (org-icompleting-read "Property: "
11331 (mapcar 'list (org-buffer-property-keys))))
11332 (setq value (org-icompleting-read "Value: "
11333 (mapcar 'list (org-property-values kwd))))
11334 (unless (string-match "\\`{.*}\\'" value)
11335 (setq value (concat "\"" value "\"")))
11336 (org-match-sparse-tree arg (concat kwd "=" value)))
11337 ((member ans '(?r ?R ?/))
11338 (call-interactively 'org-occur))
11339 (t (error "No such sparse tree command \"%c\"" ans)))))
11341 (defvar org-occur-highlights nil
11342 "List of overlays used for occur matches.")
11343 (make-variable-buffer-local 'org-occur-highlights)
11344 (defvar org-occur-parameters nil
11345 "Parameters of the active org-occur calls.
11346 This is a list, each call to org-occur pushes as cons cell,
11347 containing the regular expression and the callback, onto the list.
11348 The list can contain several entries if `org-occur' has been called
11349 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11350 will only contain one set of parameters. When the highlights are
11351 removed (for example with `C-c C-c', or with the next edit (depending
11352 on `org-remove-highlights-with-change'), this variable is emptied
11354 (make-variable-buffer-local 'org-occur-parameters)
11356 (defun org-occur (regexp &optional keep-previous callback)
11357 "Make a compact tree which shows all matches of REGEXP.
11358 The tree will show the lines where the regexp matches, and all higher
11359 headlines above the match. It will also show the heading after the match,
11360 to make sure editing the matching entry is easy.
11361 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11362 call to `org-occur' will be kept, to allow stacking of calls to this
11364 If CALLBACK is non-nil, it is a function which is called to confirm
11365 that the match should indeed be shown."
11366 (interactive "sRegexp: \nP")
11367 (when (equal regexp "")
11368 (error "Regexp cannot be empty"))
11369 (unless keep-previous
11370 (org-remove-occur-highlights nil nil t))
11371 (push (cons regexp callback) org-occur-parameters)
11374 (goto-char (point-min))
11375 (if (or (not keep-previous) ; do not want to keep
11376 (not org-occur-highlights)) ; no previous matches
11379 (while (re-search-forward regexp nil t)
11380 (when (or (not callback)
11381 (save-match-data (funcall callback)))
11382 (setq cnt (1+ cnt))
11383 (when org-highlight-sparse-tree-matches
11384 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11385 (org-show-context 'occur-tree))))
11386 (when org-remove-highlights-with-change
11387 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11389 (unless org-sparse-tree-open-archived-trees
11390 (org-hide-archived-subtrees (point-min) (point-max)))
11391 (run-hooks 'org-occur-hook)
11392 (if (interactive-p)
11393 (message "%d match(es) for regexp %s" cnt regexp))
11396 (defun org-show-context (&optional key)
11397 "Make sure point and context and visible.
11398 How much context is shown depends upon the variables
11399 `org-show-hierarchy-above', `org-show-following-heading'. and
11400 `org-show-siblings'."
11401 (let ((heading-p (org-on-heading-p t))
11402 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11403 (following-p (org-get-alist-option org-show-following-heading key))
11404 (entry-p (org-get-alist-option org-show-entry-below key))
11405 (siblings-p (org-get-alist-option org-show-siblings key)))
11407 ;; Show heading or entry text
11408 (if (and heading-p (not entry-p))
11409 (org-flag-heading nil) ; only show the heading
11410 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11411 (org-show-hidden-entry))) ; show entire entry
11413 ;; Show next sibling, or heading below text
11415 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11416 (org-flag-heading nil))))
11417 (when siblings-p (org-show-siblings))
11419 ;; show all higher headings, possibly with siblings
11421 (while (and (condition-case nil
11422 (progn (org-up-heading-all 1) t)
11425 (org-flag-heading nil)
11426 (when siblings-p (org-show-siblings))))))))
11428 (defvar org-reveal-start-hook nil
11429 "Hook run before revealing a location.")
11431 (defun org-reveal (&optional siblings)
11432 "Show current entry, hierarchy above it, and the following headline.
11433 This can be used to show a consistent set of context around locations
11434 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11435 not t for the search context.
11437 With optional argument SIBLINGS, on each level of the hierarchy all
11438 siblings are shown. This repairs the tree structure to what it would
11439 look like when opened with hierarchical calls to `org-cycle'.
11440 With double optional argument `C-u C-u', go to the parent and show the
11443 (run-hooks 'org-reveal-start-hook)
11444 (let ((org-show-hierarchy-above t)
11445 (org-show-following-heading t)
11446 (org-show-siblings (if siblings t org-show-siblings)))
11447 (org-show-context nil))
11448 (when (equal siblings '(16))
11450 (when (org-up-heading-safe)
11452 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11454 (defun org-highlight-new-match (beg end)
11455 "Highlight from BEG to END and mark the highlight is an occur headline."
11456 (let ((ov (org-make-overlay beg end)))
11457 (org-overlay-put ov 'face 'secondary-selection)
11458 (push ov org-occur-highlights)))
11460 (defun org-remove-occur-highlights (&optional beg end noremove)
11461 "Remove the occur highlights from the buffer.
11462 BEG and END are ignored. If NOREMOVE is nil, remove this function
11463 from the `before-change-functions' in the current buffer."
11465 (unless org-inhibit-highlight-removal
11466 (mapc 'org-delete-overlay org-occur-highlights)
11467 (setq org-occur-highlights nil)
11468 (setq org-occur-parameters nil)
11470 (remove-hook 'before-change-functions
11471 'org-remove-occur-highlights 'local))))
11475 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11476 "Regular expression matching the priority indicator.")
11478 (defvar org-remove-priority-next-time nil)
11480 (defun org-priority-up ()
11481 "Increase the priority of the current item."
11483 (org-priority 'up))
11485 (defun org-priority-down ()
11486 "Decrease the priority of the current item."
11488 (org-priority 'down))
11490 (defun org-priority (&optional action)
11491 "Change the priority of an item by ARG.
11492 ACTION can be `set', `up', `down', or a character."
11494 (unless org-enable-priority-commands
11495 (error "Priority commands are disabled"))
11496 (setq action (or action 'set))
11497 (let (current new news have remove)
11499 (org-back-to-heading t)
11500 (if (looking-at org-priority-regexp)
11501 (setq current (string-to-char (match-string 2))
11503 (setq current org-default-priority))
11505 ((eq action 'remove)
11506 (setq remove t new ?\ ))
11507 ((or (eq action 'set)
11508 (if (featurep 'xemacs) (characterp action) (integerp action)))
11509 (if (not (eq action 'set))
11511 (message "Priority %c-%c, SPC to remove: "
11512 org-highest-priority org-lowest-priority)
11513 (setq new (read-char-exclusive)))
11514 (if (and (= (upcase org-highest-priority) org-highest-priority)
11515 (= (upcase org-lowest-priority) org-lowest-priority))
11516 (setq new (upcase new)))
11517 (cond ((equal new ?\ ) (setq remove t))
11518 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
11519 (error "Priority must be between `%c' and `%c'"
11520 org-highest-priority org-lowest-priority))))
11522 (if (and (not have) (eq last-command this-command))
11523 (setq new org-lowest-priority)
11524 (setq new (if (and org-priority-start-cycle-with-default (not have))
11525 org-default-priority (1- current)))))
11527 (if (and (not have) (eq last-command this-command))
11528 (setq new org-highest-priority)
11529 (setq new (if (and org-priority-start-cycle-with-default (not have))
11530 org-default-priority (1+ current)))))
11531 (t (error "Invalid action")))
11532 (if (or (< (upcase new) org-highest-priority)
11533 (> (upcase new) org-lowest-priority))
11535 (setq news (format "%c" new))
11538 (replace-match "" t t nil 1)
11539 (replace-match news t t nil 2))
11541 (error "No priority cookie found in line")
11542 (let ((case-fold-search nil))
11543 (looking-at org-todo-line-regexp))
11546 (goto-char (match-end 2))
11547 (insert " [#" news "]"))
11548 (goto-char (match-beginning 3))
11549 (insert "[#" news "] "))))
11550 (org-preserve-lc (org-set-tags nil 'align)))
11552 (message "Priority removed")
11553 (message "Priority of current item set to %s" news))))
11555 (defun org-get-priority (s)
11556 "Find priority cookie and return priority."
11558 (if (not (string-match org-priority-regexp s))
11559 (* 1000 (- org-lowest-priority org-default-priority))
11560 (* 1000 (- org-lowest-priority
11561 (string-to-char (match-string 2 s)))))))
11565 (defvar org-agenda-archives-mode)
11566 (defvar org-map-continue-from nil
11567 "Position from where mapping should continue.
11568 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
11570 (defvar org-scanner-tags nil
11571 "The current tag list while the tags scanner is running.")
11572 (defvar org-trust-scanner-tags nil
11573 "Should `org-get-tags-at' use the tags fro the scanner.
11574 This is for internal dynamical scoping only.
11575 When this is non-nil, the function `org-get-tags-at' will return the value
11576 of `org-scanner-tags' instead of building the list by itself. This
11577 can lead to large speed-ups when the tags scanner is used in a file with
11578 many entries, and when the list of tags is retrieved, for example to
11579 obtain a list of properties. Building the tags list for each entry in such
11580 a file becomes an N^2 operation - but with this variable set, it scales
11583 (defun org-scan-tags (action matcher &optional todo-only)
11584 "Scan headline tags with inheritance and produce output ACTION.
11586 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
11587 or `agenda' to produce an entry list for an agenda view. It can also be
11588 a Lisp form or a function that should be called at each matched headline, in
11589 this case the return value is a list of all return values from these calls.
11591 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
11592 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
11593 only lines with a TODO keyword are included in the output."
11594 (require 'org-agenda)
11595 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
11596 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
11598 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
11599 (props (list 'face 'default
11600 'done-face 'org-agenda-done
11601 'undone-face 'default
11602 'mouse-face 'highlight
11603 'org-not-done-regexp org-not-done-regexp
11604 'org-todo-regexp org-todo-regexp
11606 (format "mouse-2 or RET jump to org file %s"
11607 (abbreviate-file-name
11608 (or (buffer-file-name (buffer-base-buffer))
11609 (buffer-name (buffer-base-buffer)))))))
11610 (case-fold-search nil)
11611 (org-map-continue-from nil)
11612 lspos tags tags-list
11613 (tags-alist (list (cons 0 org-file-tags)))
11614 (llast 0) rtn rtn1 level category i txt
11615 todo marker entry priority)
11616 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
11617 (setq action (list 'lambda nil action)))
11619 (goto-char (point-min))
11620 (when (eq action 'sparse-tree)
11622 (org-remove-occur-highlights))
11623 (while (re-search-forward re nil t)
11625 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
11626 tags (if (match-end 4) (org-match-string-no-properties 4)))
11627 (goto-char (setq lspos (match-beginning 0)))
11628 (setq level (org-reduced-level (funcall outline-level))
11629 category (org-get-category))
11630 (setq i llast llast level)
11631 ;; remove tag lists from same and sublevels
11632 (while (>= i level)
11633 (when (setq entry (assoc i tags-alist))
11634 (setq tags-alist (delete entry tags-alist)))
11636 ;; add the next tags
11638 (setq tags (org-split-string tags ":")
11640 (cons (cons level tags) tags-alist)))
11641 ;; compile tags for current headline
11643 (if org-use-tag-inheritance
11644 (apply 'append (mapcar 'cdr (reverse tags-alist)))
11646 org-scanner-tags tags-list)
11647 (when org-use-tag-inheritance
11648 (setcdr (car tags-alist)
11649 (mapcar (lambda (x)
11650 (setq x (copy-sequence x))
11651 (org-add-prop-inherited x))
11652 (cdar tags-alist))))
11653 (when (and tags org-use-tag-inheritance
11654 (or (not (eq t org-use-tag-inheritance))
11655 org-tags-exclude-from-inheritance))
11656 ;; selective inheritance, remove uninherited ones
11657 (setcdr (car tags-alist)
11658 (org-remove-uniherited-tags (cdar tags-alist))))
11659 (when (and (or (not todo-only)
11660 (and (member todo org-not-done-keywords)
11661 (or (not org-agenda-tags-todo-honor-ignore-options)
11662 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
11663 (let ((case-fold-search t)) (eval matcher))
11665 (not (member org-archive-tag tags-list))
11666 ;; we have an archive tag, should we use this anyway?
11667 (or (not org-agenda-skip-archived-trees)
11668 (and (eq action 'agenda) org-agenda-archives-mode))))
11669 (unless (eq action 'sparse-tree) (org-agenda-skip))
11671 ;; select this headline
11674 ((eq action 'sparse-tree)
11675 (and org-highlight-sparse-tree-matches
11676 (org-get-heading) (match-end 0)
11677 (org-highlight-new-match
11678 (match-beginning 0) (match-beginning 1)))
11679 (org-show-context 'tags-tree))
11680 ((eq action 'agenda)
11681 (setq txt (org-format-agenda-item
11684 (if (eq org-tags-match-list-sublevels 'indented)
11685 (make-string (1- level) ?.) "")
11690 priority (org-get-priority txt))
11692 (setq marker (org-agenda-new-marker))
11693 (org-add-props txt props
11694 'org-marker marker 'org-hd-marker marker 'org-category category
11696 'priority priority 'type "tagsmatch")
11698 ((functionp action)
11699 (setq org-map-continue-from nil)
11701 (setq rtn1 (funcall action))
11703 (t (error "Invalid action")))
11705 ;; if we are to skip sublevels, jump to end of subtree
11706 (unless org-tags-match-list-sublevels
11707 (org-end-of-subtree t)
11708 (backward-char 1))))
11709 ;; Get the correct position from where to continue
11710 (if org-map-continue-from
11711 (goto-char org-map-continue-from)
11712 (and (= (point) lspos) (end-of-line 1)))))
11713 (when (and (eq action 'sparse-tree)
11714 (not org-sparse-tree-open-archived-trees))
11715 (org-hide-archived-subtrees (point-min) (point-max)))
11718 (defun org-remove-uniherited-tags (tags)
11719 "Remove all tags that are not inherited from the list TAGS."
11721 ((eq org-use-tag-inheritance t)
11722 (if org-tags-exclude-from-inheritance
11723 (org-delete-all org-tags-exclude-from-inheritance tags)
11725 ((not org-use-tag-inheritance) nil)
11726 ((stringp org-use-tag-inheritance)
11729 (if (and (string-match org-use-tag-inheritance x)
11730 (not (member x org-tags-exclude-from-inheritance)))
11733 ((listp org-use-tag-inheritance)
11736 (if (member x org-use-tag-inheritance) x nil))
11739 (defvar todo-only) ;; dynamically scoped
11741 (defun org-match-sparse-tree (&optional todo-only match)
11742 "Create a sparse tree according to tags string MATCH.
11743 MATCH can contain positive and negative selection of tags, like
11744 \"+WORK+URGENT-WITHBOSS\".
11745 If optional argument TODO-ONLY is non-nil, only select lines that are
11748 (org-prepare-agenda-buffers (list (current-buffer)))
11749 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
11751 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
11753 (defvar org-cached-props nil)
11754 (defun org-cached-entry-get (pom property)
11755 (if (or (eq t org-use-property-inheritance)
11756 (and (stringp org-use-property-inheritance)
11757 (string-match org-use-property-inheritance property))
11758 (and (listp org-use-property-inheritance)
11759 (member property org-use-property-inheritance)))
11760 ;; Caching is not possible, check it directly
11761 (org-entry-get pom property 'inherit)
11762 ;; Get all properties, so that we can do complicated checks easily
11763 (cdr (assoc property (or org-cached-props
11764 (setq org-cached-props
11765 (org-entry-properties pom)))))))
11767 (defun org-global-tags-completion-table (&optional files)
11768 "Return the list of all tags in all agenda buffer/files."
11775 (set-buffer (find-file-noselect file))
11776 (append (org-get-buffer-tags)
11777 (mapcar (lambda (x) (if (stringp (car-safe x))
11778 (list (car-safe x)) nil))
11780 (if (and files (car files))
11782 (org-agenda-files))))))))
11784 (defun org-make-tags-matcher (match)
11785 "Create the TAGS//TODO matcher form for the selection string MATCH."
11786 ;; todo-only is scoped dynamically into this function, and the function
11787 ;; may change it if the matcher asks for it.
11789 ;; Get a new match request, with completion
11790 (let ((org-last-tags-completion-table
11791 (org-global-tags-completion-table)))
11792 (setq match (org-completing-read-no-i
11793 "Match: " 'org-tags-completion-function nil nil nil
11794 'org-tags-history))))
11796 ;; Parse the string and create a lisp form
11797 (let ((match0 match)
11798 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
11800 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
11801 orterms term orlist re-p str-p level-p level-op time-p
11802 prop-p pn pv po cat-p gv rest)
11803 (if (string-match "/+" match)
11804 ;; match contains also a todo-matching request
11806 (setq tagsmatch (substring match 0 (match-beginning 0))
11807 todomatch (substring match (match-end 0)))
11808 (if (string-match "^!" todomatch)
11809 (setq todo-only t todomatch (substring todomatch 1)))
11810 (if (string-match "^\\s-*$" todomatch)
11811 (setq todomatch nil)))
11812 ;; only matching tags
11813 (setq tagsmatch match todomatch nil))
11815 ;; Make the tags matcher
11816 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
11817 (setq tagsmatcher t)
11818 (setq orterms (org-split-string tagsmatch "|") orlist nil)
11819 (while (setq term (pop orterms))
11820 (while (and (equal (substring term -1) "\\") orterms)
11821 (setq term (concat term "|" (pop orterms)))) ; repair bad split
11822 (while (string-match re term)
11823 (setq rest (substring term (match-end 0))
11824 minus (and (match-end 1)
11825 (equal (match-string 1 term) "-"))
11826 tag (match-string 2 term)
11827 re-p (equal (string-to-char tag) ?{)
11828 level-p (match-end 4)
11829 prop-p (match-end 5)
11831 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
11833 (setq level-op (org-op-to-function (match-string 3 term)))
11834 `(,level-op level ,(string-to-number
11835 (match-string 4 term))))
11837 (setq pn (match-string 5 term)
11838 po (match-string 6 term)
11839 pv (match-string 7 term)
11840 cat-p (equal pn "CATEGORY")
11841 re-p (equal (string-to-char pv) ?{)
11842 str-p (equal (string-to-char pv) ?\")
11843 time-p (save-match-data
11844 (string-match "^\"[[<].*[]>]\"$" pv))
11845 pv (if (or re-p str-p) (substring pv 1 -1) pv))
11846 (if time-p (setq pv (org-matcher-time pv)))
11847 (setq po (org-op-to-function po (if time-p 'time str-p)))
11849 ((equal pn "CATEGORY")
11850 (setq gv '(get-text-property (point) 'org-category)))
11854 (setq gv `(org-cached-entry-get nil ,pn))))
11857 `(not (string-match ,pv (or ,gv "")))
11858 `(string-match ,pv (or ,gv "")))
11860 `(,po (or ,gv "") ,pv)
11861 `(,po (string-to-number (or ,gv ""))
11862 ,(string-to-number pv) ))))
11863 (t `(member ,tag tags-list)))
11864 mm (if minus (list 'not mm) mm)
11866 (push mm tagsmatcher))
11867 (push (if (> (length tagsmatcher) 1)
11868 (cons 'and tagsmatcher)
11871 (setq tagsmatcher nil))
11872 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
11874 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
11875 ;; Make the todo matcher
11876 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
11877 (setq todomatcher t)
11878 (setq orterms (org-split-string todomatch "|") orlist nil)
11879 (while (setq term (pop orterms))
11880 (while (string-match re term)
11881 (setq minus (and (match-end 1)
11882 (equal (match-string 1 term) "-"))
11883 kwd (match-string 2 term)
11884 re-p (equal (string-to-char kwd) ?{)
11885 term (substring term (match-end 0))
11887 `(string-match ,(substring kwd 1 -1) todo)
11888 (list 'equal 'todo kwd))
11889 mm (if minus (list 'not mm) mm))
11890 (push mm todomatcher))
11891 (push (if (> (length todomatcher) 1)
11892 (cons 'and todomatcher)
11895 (setq todomatcher nil))
11896 (setq todomatcher (if (> (length orlist) 1)
11897 (cons 'or orlist) (car orlist))))
11899 ;; Return the string and lisp forms of the matcher
11900 (setq matcher (if todomatcher
11901 (list 'and tagsmatcher todomatcher)
11903 (cons match0 matcher)))
11905 (defun org-op-to-function (op &optional stringp)
11906 "Turn an operator into the appropriate function."
11909 ((equal op "<" ) '(< string< org-time<))
11910 ((equal op ">" ) '(> org-string> org-time>))
11911 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
11912 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
11913 ((member op '("=" "==")) '(= string= org-time=))
11914 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
11915 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
11917 (defun org<> (a b) (not (= a b)))
11918 (defun org-string<= (a b) (or (string= a b) (string< a b)))
11919 (defun org-string>= (a b) (not (string< a b)))
11920 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
11921 (defun org-string<> (a b) (not (string= a b)))
11922 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
11923 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
11924 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
11925 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
11926 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
11927 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
11929 "Convert S to a floating point time.
11930 If S is already a number, just return it. If it is a string, parse
11931 it as a time string and apply `float-time' to it. If S is nil, just return 0."
11935 (condition-case nil
11936 (float-time (apply 'encode-time (org-parse-time-string s)))
11940 (defun org-time-today ()
11941 "Time in seconds today at 0:00.
11942 Returns the float number of seconds since the beginning of the
11943 epoch to the beginning of today (00:00)."
11944 (float-time (apply 'encode-time
11945 (append '(0 0 0) (nthcdr 3 (decode-time))))))
11947 (defun org-matcher-time (s)
11948 "Interpret a time comparison value."
11951 ((string= s "<now>") (float-time))
11952 ((string= s "<today>") (org-time-today))
11953 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
11954 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
11955 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
11956 (+ (org-time-today)
11957 (* (string-to-number (match-string 1 s))
11958 (cdr (assoc (match-string 2 s)
11959 '(("d" . 86400.0) ("w" . 604800.0)
11960 ("m" . 2678400.0) ("y" . 31557600.0)))))))
11963 (defun org-match-any-p (re list)
11964 "Does re match any element of list?"
11965 (setq list (mapcar (lambda (x) (string-match re x)) list))
11968 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
11969 (defvar org-tags-overlay (org-make-overlay 1 1))
11970 (org-detach-overlay org-tags-overlay)
11972 (defun org-get-local-tags-at (&optional pos)
11973 "Get a list of tags defined in the current headline."
11974 (org-get-tags-at pos 'local))
11976 (defun org-get-local-tags ()
11977 "Get a list of tags defined in the current headline."
11978 (org-get-tags-at nil 'local))
11980 (defun org-get-tags-at (&optional pos local)
11981 "Get a list of all headline tags applicable at POS.
11982 POS defaults to point. If tags are inherited, the list contains
11983 the targets in the same sequence as the headlines appear, i.e.
11984 the tags of the current headline come last.
11985 When LOCAL is non-nil, only return tags from the current headline,
11986 ignore inherited ones."
11988 (if (and org-trust-scanner-tags
11989 (or (not pos) (equal pos (point)))
11992 (let (tags ltags lastpos parent)
11996 (goto-char (or pos (point)))
11999 (condition-case nil
12001 (org-back-to-heading t)
12002 (while (not (equal lastpos (point)))
12003 (setq lastpos (point))
12005 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12006 (setq ltags (org-split-string
12007 (org-match-string-no-properties 1) ":"))
12009 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12012 (org-remove-uniherited-tags ltags)
12015 (or org-use-tag-inheritance (throw 'done t))
12016 (if local (throw 'done t))
12017 (or (org-up-heading-safe) (error nil))
12020 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12022 (defun org-add-prop-inherited (s)
12023 (add-text-properties 0 (length s) '(inherited t) s)
12026 (defun org-toggle-tag (tag &optional onoff)
12027 "Toggle the tag TAG for the current line.
12028 If ONOFF is `on' or `off', don't toggle but set to this state."
12031 (org-back-to-heading t)
12032 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12035 (setq current (match-string 1))
12036 (replace-match ""))
12038 (setq current (nreverse (org-split-string current ":")))
12042 (or (member tag current) (push tag current)))
12044 (or (not (member tag current)) (setq current (delete tag current))))
12045 (t (if (member tag current)
12046 (setq current (delete tag current))
12048 (push tag current))))
12052 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12053 (org-set-tags nil t))
12054 (delete-horizontal-space))
12055 (run-hooks 'org-after-tags-change-hook))
12058 (defun org-align-tags-here (to-col)
12059 ;; Assumes that this is a headline
12060 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12061 (beginning-of-line 1)
12062 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12063 (< pos (match-beginning 2)))
12065 (setq tags-l (- (match-end 2) (match-beginning 2)))
12066 (goto-char (match-beginning 1))
12068 (delete-region (point) (1+ (match-beginning 2)))
12069 (setq ncol (max (1+ (current-column))
12073 (- (abs to-col) tags-l))))
12075 (insert (make-string (- ncol (current-column)) ?\ ))
12076 (setq ncol (current-column))
12077 (when indent-tabs-mode (tabify p (point-at-eol)))
12078 (org-move-to-column (min ncol col) t))
12081 (defun org-set-tags-command (&optional arg just-align)
12082 "Call the set-tags command for the current entry."
12084 (if (org-on-heading-p)
12085 (org-set-tags arg just-align)
12087 (org-back-to-heading t)
12088 (org-set-tags arg just-align))))
12090 (defun org-set-tags-to (data)
12091 "Set the tags of the current entry to DATA, replacing the current tags.
12092 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12093 If DATA is nil or the empty string, any tags will be removed."
12094 (interactive "sTags: ")
12098 ((equal data "") "")
12100 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12103 (concat ":" (mapconcat 'identity data ":") ":"))
12107 (org-back-to-heading t)
12108 (when (looking-at org-complex-heading-regexp)
12111 (goto-char (match-beginning 5))
12113 (delete-region (point) (point-at-eol))
12114 (org-set-tags nil 'align))
12115 (goto-char (point-at-eol))
12117 (org-set-tags nil 'align)))
12118 (beginning-of-line 1)
12119 (if (looking-at ".*?\\([ \t]+\\)$")
12120 (delete-region (match-beginning 1) (match-end 1))))))
12122 (defun org-set-tags (&optional arg just-align)
12123 "Set the tags for the current headline.
12124 With prefix ARG, realign all tags in headings in the current buffer."
12126 (let* ((re (concat "^" outline-regexp))
12127 (current (org-get-tags-string))
12128 (col (current-column))
12129 (org-setting-tags t)
12130 table current-tags inherited-tags ; computed below when needed
12134 (goto-char (point-min))
12135 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12136 (while (re-search-forward re nil t)
12137 (org-set-tags nil t)
12139 (message "All tags realigned to column %d" org-tags-column))
12141 (setq tags current)
12142 ;; Get a new set of tags from the user
12144 (setq table (append org-tag-persistent-alist
12145 (or org-tag-alist (org-get-buffer-tags))
12146 (and org-complete-tags-always-offer-all-agenda-tags
12147 (org-global-tags-completion-table (org-agenda-files))))
12148 org-last-tags-completion-table table
12149 current-tags (org-split-string current ":")
12150 inherited-tags (nreverse
12151 (nthcdr (length current-tags)
12152 (nreverse (org-get-tags-at))))
12154 (if (or (eq t org-use-fast-tag-selection)
12155 (and org-use-fast-tag-selection
12156 (delq nil (mapcar 'cdr table))))
12157 (org-fast-tag-selection
12158 current-tags inherited-tags table
12159 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12160 (let ((org-add-colon-after-tag-completion t))
12162 (org-without-partial-completion
12163 (org-icompleting-read "Tags: " 'org-tags-completion-function
12164 nil nil current 'org-tags-history)))))))
12165 (while (string-match "[-+&]+" tags)
12166 ;; No boolean logic, just a list
12167 (setq tags (replace-match ":" t t tags))))
12169 (if org-tags-sort-function
12170 (setq tags (mapconcat 'identity
12171 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12172 org-tags-sort-function) ":")))
12174 (if (string-match "\\`[\t ]*\\'" tags)
12176 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12177 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12179 ;; Insert new tags at the correct column
12180 (beginning-of-line 1)
12182 ((and (equal current "") (equal tags "")))
12183 ((re-search-forward
12184 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12186 (if (equal tags "")
12188 (goto-char (match-beginning 0))
12189 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12190 (1+ (point)) (point))
12191 c1 (max (1+ c0) (if (> org-tags-column 0)
12193 (- (- org-tags-column) (length tags))))
12194 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12195 (replace-match rpl t t)
12196 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12198 (t (error "Tags alignment failed")))
12199 (org-move-to-column col)
12201 (run-hooks 'org-after-tags-change-hook)))))
12203 (defun org-change-tag-in-region (beg end tag off)
12204 "Add or remove TAG for each entry in the region.
12205 This works in the agenda, and also in an org-mode buffer."
12207 (list (region-beginning) (region-end)
12208 (let ((org-last-tags-completion-table
12210 (org-get-buffer-tags)
12211 (org-global-tags-completion-table))))
12212 (org-icompleting-read
12213 "Tag: " 'org-tags-completion-function nil nil nil
12214 'org-tags-history))
12216 (message "[s]et or [r]emove? ")
12217 (equal (read-char-exclusive) ?r))))
12218 (if (fboundp 'deactivate-mark) (deactivate-mark))
12219 (let ((agendap (equal major-mode 'org-agenda-mode))
12220 l1 l2 m buf pos newhead (cnt 0))
12222 (setq l2 (1- (org-current-line)))
12224 (setq l1 (org-current-line))
12225 (loop for l from l1 to l2 do
12227 (setq m (get-text-property (point) 'org-hd-marker))
12228 (when (or (and (org-mode-p) (org-on-heading-p))
12230 (setq buf (if agendap (marker-buffer m) (current-buffer))
12231 pos (if agendap m (point)))
12232 (with-current-buffer buf
12236 (setq cnt (1+ cnt))
12237 (org-toggle-tag tag (if off 'off 'on))
12238 (setq newhead (org-get-heading)))))
12239 (and agendap (org-agenda-change-all-lines newhead m))))
12240 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12242 (defun org-tags-completion-function (string predicate &optional flag)
12243 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12244 (confirm (lambda (x) (stringp (car x)))))
12245 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12246 (setq s1 (match-string 1 string)
12247 s2 (match-string 2 string))
12248 (setq s1 "" s2 string))
12252 (setq rtn (try-completion s2 ctable confirm))
12255 (concat s1 s2 (substring rtn (length s2))
12256 (if (and org-add-colon-after-tag-completion
12257 (assoc rtn ctable))
12262 (all-completions s2 ctable confirm)
12266 (assoc s2 ctable)))
12269 (defun org-fast-tag-insert (kwd tags face &optional end)
12270 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12271 (insert (format "%-12s" (concat kwd ":"))
12272 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12275 (defun org-fast-tag-show-exit (flag)
12278 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12279 (replace-match ""))
12282 (org-move-to-column (- (window-width) 19) t)
12283 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12285 (defun org-set-current-tags-overlay (current prefix)
12286 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12287 (if (featurep 'xemacs)
12288 (org-overlay-display org-tags-overlay (concat prefix s)
12289 'secondary-selection)
12290 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12291 (org-overlay-display org-tags-overlay (concat prefix s)))))
12293 (defvar org-last-tag-selection-key nil)
12294 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12295 "Fast tag selection with single keys.
12296 CURRENT is the current list of tags in the headline, INHERITED is the
12297 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12298 possibly with grouping information. TODO-TABLE is a similar table with
12299 TODO keywords, should these have keys assigned to them.
12300 If the keys are nil, a-z are automatically assigned.
12301 Returns the new tags string, or nil to not change the current settings."
12302 (let* ((fulltable (append table todo-table))
12303 (maxlen (apply 'max (mapcar
12305 (if (stringp (car x)) (string-width (car x)) 0))
12307 (buf (current-buffer))
12308 (expert (eq org-fast-tag-selection-single-key 'expert))
12310 (fwidth (+ maxlen 3 1 3))
12311 (ncol (/ (- (window-width) 4) fwidth))
12314 tg cnt e c char c1 c2 ntable tbl rtn
12315 ov-start ov-end ov-prefix
12316 (exit-after-next org-fast-tag-selection-single-key)
12317 (done-keywords org-done-keywords)
12320 (beginning-of-line 1)
12322 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12323 (setq ov-start (match-beginning 1)
12324 ov-end (match-end 1)
12326 (setq ov-start (1- (point-at-eol))
12327 ov-end (1+ ov-start))
12328 (skip-chars-forward "^\n\r")
12331 (buffer-substring (1- (point)) (point))
12332 (if (> (current-column) org-tags-column)
12334 (make-string (- org-tags-column (current-column)) ?\ ))))))
12335 (org-move-overlay org-tags-overlay ov-start ov-end)
12336 (save-window-excursion
12338 (set-buffer (get-buffer-create " *Org tags*"))
12339 (delete-other-windows)
12340 (split-window-vertically)
12341 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12343 (org-set-local 'org-done-keywords done-keywords)
12344 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12345 (org-fast-tag-insert "Current" current c-face "\n\n")
12346 (org-fast-tag-show-exit exit-after-next)
12347 (org-set-current-tags-overlay current ov-prefix)
12348 (setq tbl fulltable char ?a cnt 0)
12349 (while (setq e (pop tbl))
12351 ((equal (car e) :startgroup)
12352 (push '() groups) (setq ingroup t)
12353 (when (not (= cnt 0))
12356 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12357 ((equal (car e) :endgroup)
12358 (setq ingroup nil cnt 0)
12359 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12360 ((equal e '(:newline))
12361 (when (not (= cnt 0))
12365 (while (equal (car tbl) '(:newline))
12367 (setq tbl (cdr tbl)))))
12369 (setq tg (copy-sequence (car e)) c2 nil)
12372 ;; automatically assign a character.
12373 (setq c1 (string-to-char
12374 (downcase (substring
12375 tg (if (= (string-to-char tg) ?@) 1 0)))))
12376 (if (or (rassoc c1 ntable) (rassoc c1 table))
12377 (while (or (rassoc char ntable) (rassoc char table))
12378 (setq char (1+ char)))
12380 (setq c (or c2 char)))
12381 (if ingroup (push tg (car groups)))
12382 (setq tg (org-add-props tg nil 'face
12384 ((not (assoc tg table))
12385 (org-get-todo-face tg))
12386 ((member tg current) c-face)
12387 ((member tg inherited) i-face)
12389 (if (and (= cnt 0) (not ingroup)) (insert " "))
12390 (insert "[" c "] " tg (make-string
12391 (- fwidth 4 (length tg)) ?\ ))
12392 (push (cons tg c) ntable)
12393 (when (= (setq cnt (1+ cnt)) ncol)
12395 (if ingroup (insert " "))
12397 (setq ntable (nreverse ntable))
12399 (goto-char (point-min))
12400 (if (not expert) (org-fit-window-to-buffer))
12404 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12405 (if (not groups) "no " "")
12406 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12407 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12408 (setq org-last-tag-selection-key c)
12410 ((= c ?\r) (throw 'exit t))
12412 (setq groups (not groups))
12413 (goto-char (point-min))
12414 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12417 (org-fast-tag-show-exit
12418 (setq exit-after-next (not exit-after-next)))
12420 (delete-other-windows)
12421 (split-window-vertically)
12422 (org-switch-to-buffer-other-window " *Org tags*")
12423 (org-fit-window-to-buffer)))
12425 (and (= c ?q) (not (rassoc c ntable))))
12426 (org-detach-overlay org-tags-overlay)
12427 (setq quit-flag t))
12430 (if exit-after-next (setq exit-after-next 'now)))
12432 (condition-case nil
12433 (setq tg (org-icompleting-read
12436 (with-current-buffer buf
12437 (org-get-buffer-tags)))))
12438 (quit (setq tg "")))
12439 (when (string-match "\\S-" tg)
12440 (add-to-list 'buffer-tags (list tg))
12441 (if (member tg current)
12442 (setq current (delete tg current))
12443 (push tg current)))
12444 (if exit-after-next (setq exit-after-next 'now)))
12445 ((setq e (rassoc c todo-table) tg (car e))
12446 (with-current-buffer buf
12447 (save-excursion (org-todo tg)))
12448 (if exit-after-next (setq exit-after-next 'now)))
12449 ((setq e (rassoc c ntable) tg (car e))
12450 (if (member tg current)
12451 (setq current (delete tg current))
12452 (loop for g in groups do
12455 (setq current (delete x current)))
12458 (if exit-after-next (setq exit-after-next 'now))))
12460 ;; Create a sorted list
12464 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12465 (if (eq exit-after-next 'now) (throw 'exit t))
12466 (goto-char (point-min))
12467 (beginning-of-line 2)
12468 (delete-region (point) (point-at-eol))
12469 (org-fast-tag-insert "Current" current c-face)
12470 (org-set-current-tags-overlay current ov-prefix)
12471 (while (re-search-forward
12472 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12473 (setq tg (match-string 1))
12474 (add-text-properties
12475 (match-beginning 1) (match-end 1)
12478 ((member tg current) c-face)
12479 ((member tg inherited) i-face)
12480 (t (get-text-property (match-beginning 1) 'face))))))
12481 (goto-char (point-min)))))
12482 (org-detach-overlay org-tags-overlay)
12484 (mapconcat 'identity current ":")
12487 (defun org-get-tags-string ()
12488 "Get the TAGS string in the current headline."
12489 (unless (org-on-heading-p t)
12490 (error "Not on a heading"))
12492 (beginning-of-line 1)
12493 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12494 (org-match-string-no-properties 1)
12497 (defun org-get-tags ()
12498 "Get the list of tags specified in the current headline."
12499 (org-split-string (org-get-tags-string) ":"))
12501 (defun org-get-buffer-tags ()
12502 "Get a table of all tags used in the buffer, for completion."
12505 (goto-char (point-min))
12506 (while (re-search-forward
12507 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
12508 (when (equal (char-after (point-at-bol 0)) ?*)
12509 (mapc (lambda (x) (add-to-list 'tags x))
12510 (org-split-string (org-match-string-no-properties 1) ":")))))
12511 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
12512 (mapcar 'list tags)))
12514 ;;;; The mapping API
12517 (defun org-map-entries (func &optional match scope &rest skip)
12518 "Call FUNC at each headline selected by MATCH in SCOPE.
12520 FUNC is a function or a lisp form. The function will be called without
12521 arguments, with the cursor positioned at the beginning of the headline.
12522 The return values of all calls to the function will be collected and
12523 returned as a list.
12525 The call to FUNC will be wrapped into a save-excursion form, so FUNC
12526 does not need to preserve point. After evaluation, the cursor will be
12527 moved to the end of the line (presumably of the headline of the
12528 processed entry) and search continues from there. Under some
12529 circumstances, this may not produce the wanted results. For example,
12530 if you have removed (e.g. archived) the current (sub)tree it could
12531 mean that the next entry will be skipped entirely. In such cases, you
12532 can specify the position from where search should continue by making
12533 FUNC set the variable `org-map-continue-from' to the desired buffer
12536 MATCH is a tags/property/todo match as it is used in the agenda tags view.
12537 Only headlines that are matched by this query will be considered during
12538 the iteration. When MATCH is nil or t, all headlines will be
12539 visited by the iteration.
12541 SCOPE determines the scope of this command. It can be any of:
12543 nil The current buffer, respecting the restriction if any
12544 tree The subtree started with the entry at point
12545 file The current buffer, without restriction
12547 The current buffer, and any archives associated with it
12548 agenda All agenda files
12549 agenda-with-archives
12550 All agenda files with any archive files associated with them
12552 If this is a list, all files in the list will be scanned
12554 The remaining args are treated as settings for the skipping facilities of
12555 the scanner. The following items can be given here:
12557 archive skip trees with the archive tag.
12558 comment skip trees with the COMMENT keyword
12559 function or Emacs Lisp form:
12560 will be used as value for `org-agenda-skip-function', so whenever
12561 the function returns t, FUNC will not be called for that
12562 entry and search will continue from the point where the
12563 function leaves it.
12565 If your function needs to retrieve the tags including inherited tags
12566 at the *current* entry, you can use the value of the variable
12567 `org-scanner-tags' which will be much faster than getting the value
12568 with `org-get-tags-at'. If your function gets properties with
12569 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
12570 to t around the call to `org-entry-properties' to get the same speedup.
12571 Note that if your function moves around to retrieve tags and properties at
12572 a *different* entry, you cannot use these techniques."
12573 (let* ((org-agenda-archives-mode nil) ; just to make sure
12574 (org-agenda-skip-archived-trees (memq 'archive skip))
12575 (org-agenda-skip-comment-trees (memq 'comment skip))
12576 (org-agenda-skip-function
12577 (car (org-delete-all '(comment archive) skip)))
12578 (org-tags-match-list-sublevels t)
12580 org-todo-keywords-for-agenda
12581 org-done-keywords-for-agenda
12582 org-todo-keyword-alist-for-agenda
12583 org-drawers-for-agenda
12584 org-tag-alist-for-agenda)
12587 ((eq match t) (setq matcher t))
12588 ((eq match nil) (setq matcher t))
12589 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
12593 (when (eq scope 'tree)
12594 (org-back-to-heading t)
12595 (org-narrow-to-subtree)
12600 (org-prepare-agenda-buffers
12601 (list (buffer-file-name (current-buffer))))
12602 (setq res (org-scan-tags func matcher)))
12603 ;; Get the right scope
12605 ((and scope (listp scope) (symbolp (car scope)))
12606 (setq scope (eval scope)))
12607 ((eq scope 'agenda)
12608 (setq scope (org-agenda-files t)))
12609 ((eq scope 'agenda-with-archives)
12610 (setq scope (org-agenda-files t))
12611 (setq scope (org-add-archive-files scope)))
12613 (setq scope (list (buffer-file-name))))
12614 ((eq scope 'file-with-archives)
12615 (setq scope (org-add-archive-files (list (buffer-file-name))))))
12616 (org-prepare-agenda-buffers scope)
12617 (while (setq file (pop scope))
12618 (with-current-buffer (org-find-base-buffer-visiting file)
12622 (goto-char (point-min))
12623 (setq res (append res (org-scan-tags func matcher))))))))))
12628 ;;; Setting and retrieving properties
12630 (defconst org-special-properties
12631 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
12632 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
12633 "The special properties valid in Org-mode.
12635 These are properties that are not defined in the property drawer,
12636 but in some other way.")
12638 (defconst org-default-properties
12639 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
12640 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
12641 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
12642 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
12643 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER"
12644 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
12645 "Some properties that are used by Org-mode for various purposes.
12646 Being in this list makes sure that they are offered for completion.")
12648 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
12649 "Regular expression matching the first line of a property drawer.")
12651 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
12652 "Regular expression matching the last line of a property drawer.")
12654 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
12655 "Regular expression matching the first line of a property drawer.")
12657 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
12658 "Regular expression matching the first line of a property drawer.")
12660 (defconst org-property-drawer-re
12661 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
12662 org-property-end-re "\\)\n?")
12663 "Matches an entire property drawer.")
12665 (defconst org-clock-drawer-re
12666 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
12667 org-property-end-re "\\)\n?")
12668 "Matches an entire clock drawer.")
12670 (defun org-property-action ()
12671 "Do an action on properties."
12674 (org-at-property-p)
12675 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
12676 (setq c (read-char-exclusive))
12679 (call-interactively 'org-set-property))
12681 (call-interactively 'org-delete-property))
12683 (call-interactively 'org-delete-property-globally))
12685 (call-interactively 'org-compute-property-at-point))
12686 (t (error "No such property action %c" c)))))
12688 (defun org-set-effort (&optional value)
12689 "Set the effort property of the current entry.
12690 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
12693 (if (equal value 0) (setq value 10))
12694 (let* ((completion-ignore-case t)
12695 (prop org-effort-property)
12696 (cur (org-entry-get nil prop))
12697 (allowed (org-property-get-allowed-values nil prop 'table))
12698 (existing (mapcar 'list (org-property-values prop)))
12701 ((stringp value) value)
12702 ((and allowed (integerp value))
12703 (or (car (nth (1- value) allowed))
12704 (car (org-last allowed))))
12706 (message "Select 1-9,0, [RET%s]: %s"
12707 (if cur (concat "=" cur) "")
12708 (mapconcat 'car allowed " "))
12709 (setq rpl (read-char-exclusive))
12710 (if (equal rpl ?\r)
12712 (setq rpl (- rpl ?0))
12713 (if (equal rpl 0) (setq rpl 10))
12714 (if (and (> rpl 0) (<= rpl (length allowed)))
12715 (car (nth (1- rpl) allowed))
12716 (org-completing-read "Effort: " allowed nil))))
12718 (let (org-completion-use-ido org-completion-use-iswitchb)
12719 (org-completing-read
12720 (concat "Effort " (if (and cur (string-match "\\S-" cur))
12721 (concat "[" cur "]") "")
12723 existing nil nil "" nil cur))))))
12724 (unless (equal (org-entry-get nil prop) val)
12725 (org-entry-put nil prop val))
12726 (message "%s is now %s" prop val)))
12728 (defun org-at-property-p ()
12729 "Is cursor inside a property drawer?"
12731 (beginning-of-line 1)
12732 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
12733 (let ((match (match-data)) ;; Keep match-data for use by calling
12734 (p (point)) ;; procedures.
12735 (range (unless (org-before-first-heading-p)
12736 (org-get-property-block))))
12737 (prog1 (and range (<= (car range) p) (< p (cdr range)))
12738 (set-match-data match))))))
12740 (defun org-get-property-block (&optional beg end force)
12741 "Return the (beg . end) range of the body of the property drawer.
12742 BEG and END can be beginning and end of subtree, if not given
12743 they will be found.
12744 If the drawer does not exist and FORCE is non-nil, create the drawer."
12747 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
12748 (end (or end (progn (outline-next-heading) (point)))))
12750 (if (re-search-forward org-property-start-re end t)
12751 (setq beg (1+ (match-end 0)))
12754 (org-insert-property-drawer)
12755 (setq end (progn (outline-next-heading) (point))))
12758 (if (re-search-forward org-property-start-re end t)
12759 (setq beg (1+ (match-end 0)))))
12760 (if (re-search-forward org-property-end-re end t)
12761 (setq end (match-beginning 0))
12762 (or force (throw 'exit nil))
12765 (org-indent-line-function)
12766 (insert ":END:\n"))
12769 (defun org-entry-properties (&optional pom which specific)
12770 "Get all properties of the entry at point-or-marker POM.
12771 This includes the TODO keyword, the tags, time strings for deadline,
12772 scheduled, and clocking, and any additional properties defined in the
12773 entry. The return value is an alist, keys may occur multiple times
12774 if the property key was used several times.
12775 POM may also be nil, in which case the current entry is used.
12776 If WHICH is nil or `all', get all properties. If WHICH is
12777 `special' or `standard', only get that subclass. If WHICH
12778 is a string only get exactly this property. Specific can be a string, the
12779 specific property we are interested in. Specifying it can speed
12780 things up because then unnecessary parsing is avoided."
12781 (setq which (or which 'all))
12782 (org-with-point-at pom
12783 (let ((clockstr (substring org-clock-string 0 -1))
12784 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
12785 (case-fold-search nil)
12786 beg end range props sum-props key value string clocksum)
12788 (when (condition-case nil
12789 (and (org-mode-p) (org-back-to-heading t))
12792 (setq sum-props (get-text-property (point) 'org-summaries))
12793 (setq clocksum (get-text-property (point) :org-clock-minutes))
12794 (outline-next-heading)
12796 (when (memq which '(all special))
12797 ;; Get the special properties, like TODO and tags
12799 (when (and (or (not specific) (string= specific "TODO"))
12800 (looking-at org-todo-line-regexp) (match-end 2))
12801 (push (cons "TODO" (org-match-string-no-properties 2)) props))
12802 (when (and (or (not specific) (string= specific "PRIORITY"))
12803 (looking-at org-priority-regexp))
12804 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
12805 (when (and (or (not specific) (string= specific "TAGS"))
12806 (setq value (org-get-tags-string))
12807 (string-match "\\S-" value))
12808 (push (cons "TAGS" value) props))
12809 (when (and (or (not specific) (string= specific "ALLTAGS"))
12810 (setq value (org-get-tags-at)))
12811 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
12814 (when (or (not specific) (string= specific "BLOCKED"))
12815 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
12816 (when (or (not specific)
12817 (member specific org-all-time-keywords)
12818 (member specific '("TIMESTAMP" "TIMESTAMP_IA")))
12819 (while (re-search-forward org-maybe-keyword-time-regexp end t)
12820 (setq key (if (match-end 1) (substring (org-match-string-no-properties 1) 0 -1))
12821 string (if (equal key clockstr)
12825 (match-beginning 3) (goto-char (point-at-eol)))))
12826 (substring (org-match-string-no-properties 3) 1 -1)))
12828 (if (= (char-after (match-beginning 3)) ?\[)
12829 (setq key "TIMESTAMP_IA")
12830 (setq key "TIMESTAMP")))
12831 (when (or (equal key clockstr) (not (assoc key props)))
12832 (push (cons key string) props))))
12836 (when (memq which '(all standard))
12837 ;; Get the standard properties, like :PROP: ...
12838 (setq range (org-get-property-block beg end))
12840 (goto-char (car range))
12841 (while (re-search-forward
12842 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
12844 (setq key (org-match-string-no-properties 1)
12845 value (org-trim (or (org-match-string-no-properties 2) "")))
12846 (unless (member key excluded)
12847 (push (cons key (or value "")) props)))))
12849 (push (cons "CLOCKSUM"
12850 (org-columns-number-to-string (/ (float clocksum) 60.)
12853 (unless (assoc "CATEGORY" props)
12854 (setq value (or (org-get-category)
12855 (progn (org-refresh-category-properties)
12856 (org-get-category))))
12857 (push (cons "CATEGORY" value) props))
12858 (append sum-props (nreverse props)))))))
12860 (defun org-entry-get (pom property &optional inherit)
12861 "Get value of PROPERTY for entry at point-or-marker POM.
12862 If INHERIT is non-nil and the entry does not have the property,
12863 then also check higher levels of the hierarchy.
12864 If INHERIT is the symbol `selective', use inheritance only if the setting
12865 in `org-use-property-inheritance' selects PROPERTY for inheritance.
12866 If the property is present but empty, the return value is the empty string.
12867 If the property is not present at all, nil is returned."
12868 (org-with-point-at pom
12869 (if (and inherit (if (eq inherit 'selective)
12870 (org-property-inherit-p property)
12872 (org-entry-get-with-inheritance property)
12873 (if (member property org-special-properties)
12874 ;; We need a special property. Use `org-entry-properties' to
12875 ;; retrieve it, but specify the wanted property
12876 (cdr (assoc property (org-entry-properties nil 'special property)))
12877 (let ((range (org-get-property-block)))
12879 (goto-char (car range))
12881 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
12883 ;; Found the property, return it.
12885 (org-match-string-no-properties 1)
12888 (defun org-property-or-variable-value (var &optional inherit)
12889 "Check if there is a property fixing the value of VAR.
12890 If yes, return this value. If not, return the current value of the variable."
12891 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
12892 (if (and prop (stringp prop) (string-match "\\S-" prop))
12894 (symbol-value var))))
12896 (defun org-entry-delete (pom property)
12897 "Delete the property PROPERTY from entry at point-or-marker POM."
12898 (org-with-point-at pom
12899 (if (member property org-special-properties)
12900 nil ; cannot delete these properties.
12901 (let ((range (org-get-property-block)))
12903 (goto-char (car range))
12905 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
12908 (delete-region (match-beginning 0) (1+ (point-at-eol)))
12912 ;; Multi-values properties are properties that contain multiple values
12913 ;; These values are assumed to be single words, separated by whitespace.
12914 (defun org-entry-add-to-multivalued-property (pom property value)
12915 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
12916 (let* ((old (org-entry-get pom property))
12917 (values (and old (org-split-string old "[ \t]"))))
12918 (setq value (org-entry-protect-space value))
12919 (unless (member value values)
12920 (setq values (cons value values))
12921 (org-entry-put pom property
12922 (mapconcat 'identity values " ")))))
12924 (defun org-entry-remove-from-multivalued-property (pom property value)
12925 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
12926 (let* ((old (org-entry-get pom property))
12927 (values (and old (org-split-string old "[ \t]"))))
12928 (setq value (org-entry-protect-space value))
12929 (when (member value values)
12930 (setq values (delete value values))
12931 (org-entry-put pom property
12932 (mapconcat 'identity values " ")))))
12934 (defun org-entry-member-in-multivalued-property (pom property value)
12935 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
12936 (let* ((old (org-entry-get pom property))
12937 (values (and old (org-split-string old "[ \t]"))))
12938 (setq value (org-entry-protect-space value))
12939 (member value values)))
12941 (defun org-entry-get-multivalued-property (pom property)
12942 "Return a list of values in a multivalued property."
12943 (let* ((value (org-entry-get pom property))
12944 (values (and value (org-split-string value "[ \t]"))))
12945 (mapcar 'org-entry-restore-space values)))
12947 (defun org-entry-put-multivalued-property (pom property &rest values)
12948 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
12949 VALUES should be a list of strings. Spaces will be protected."
12950 (org-entry-put pom property
12951 (mapconcat 'org-entry-protect-space values " "))
12952 (let* ((value (org-entry-get pom property))
12953 (values (and value (org-split-string value "[ \t]"))))
12954 (mapcar 'org-entry-restore-space values)))
12956 (defun org-entry-protect-space (s)
12957 "Protect spaces and newline in string S."
12958 (while (string-match " " s)
12959 (setq s (replace-match "%20" t t s)))
12960 (while (string-match "\n" s)
12961 (setq s (replace-match "%0A" t t s)))
12964 (defun org-entry-restore-space (s)
12965 "Restore spaces and newline in string S."
12966 (while (string-match "%20" s)
12967 (setq s (replace-match " " t t s)))
12968 (while (string-match "%0A" s)
12969 (setq s (replace-match "\n" t t s)))
12972 (defvar org-entry-property-inherited-from (make-marker)
12973 "Marker pointing to the entry from where a property was inherited.
12974 Each call to `org-entry-get-with-inheritance' will set this marker to the
12975 location of the entry where the inheritance search matched. If there was
12976 no match, the marker will point nowhere.
12977 Note that also `org-entry-get' calls this function, if the INHERIT flag
12980 (defun org-entry-get-with-inheritance (property)
12981 "Get entry property, and search higher levels if not present."
12982 (move-marker org-entry-property-inherited-from nil)
12989 (when (setq tmp (org-entry-get nil property))
12990 (org-back-to-heading t)
12991 (move-marker org-entry-property-inherited-from (point))
12993 (or (org-up-heading-safe) (throw 'ex nil)))))
12995 (cdr (assoc property org-file-properties))
12996 (cdr (assoc property org-global-properties))
12997 (cdr (assoc property org-global-properties-fixed))))))
12999 (defvar org-property-changed-functions nil
13000 "Hook called when the value of a property has changed.
13001 Each hook function should accept two arguments, the name of the property
13002 and the new value.")
13004 (defun org-entry-put (pom property value)
13005 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13006 (org-with-point-at pom
13007 (org-back-to-heading t)
13008 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13011 ((equal property "TODO")
13012 (when (and (stringp value) (string-match "\\S-" value)
13013 (not (member value org-todo-keywords-1)))
13014 (error "\"%s\" is not a valid TODO state" value))
13015 (if (or (not value)
13016 (not (string-match "\\S-" value)))
13017 (setq value 'none))
13019 (org-set-tags nil 'align))
13020 ((equal property "PRIORITY")
13021 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13022 (string-to-char value) ?\ ))
13023 (org-set-tags nil 'align))
13024 ((equal property "SCHEDULED")
13025 (if (re-search-forward org-scheduled-time-regexp end t)
13027 ((eq value 'earlier) (org-timestamp-change -1 'day))
13028 ((eq value 'later) (org-timestamp-change 1 'day))
13029 (t (call-interactively 'org-schedule)))
13030 (call-interactively 'org-schedule)))
13031 ((equal property "DEADLINE")
13032 (if (re-search-forward org-deadline-time-regexp end t)
13034 ((eq value 'earlier) (org-timestamp-change -1 'day))
13035 ((eq value 'later) (org-timestamp-change 1 'day))
13036 (t (call-interactively 'org-deadline)))
13037 (call-interactively 'org-deadline)))
13038 ((member property org-special-properties)
13039 (error "The %s property can not yet be set with `org-entry-put'"
13041 (t ; a non-special property
13042 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13043 (setq range (org-get-property-block beg end 'force))
13044 (goto-char (car range))
13045 (if (re-search-forward
13046 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13048 (delete-region (match-beginning 1) (match-end 1))
13049 (goto-char (match-beginning 1)))
13050 (goto-char (cdr range))
13053 (org-indent-line-function)
13054 (insert ":" property ":"))
13055 (and value (insert " " value))
13056 (org-indent-line-function)))))
13057 (run-hook-with-args 'org-property-changed-functions property value)))
13059 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13060 "Get all property keys in the current buffer.
13061 With INCLUDE-SPECIALS, also list the special properties that reflect things
13062 like tags and TODO state.
13063 With INCLUDE-DEFAULTS, also include properties that has special meaning
13064 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13065 With INCLUDE-COLUMNS, also include property names given in COLUMN
13066 formats in the current buffer."
13067 (let (rtn range cfmt s p)
13071 (goto-char (point-min))
13072 (while (re-search-forward org-property-start-re nil t)
13073 (setq range (org-get-property-block))
13074 (goto-char (car range))
13075 (while (re-search-forward
13076 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13078 (add-to-list 'rtn (org-match-string-no-properties 1)))
13079 (outline-next-heading))))
13081 (when include-specials
13082 (setq rtn (append org-special-properties rtn)))
13084 (when include-defaults
13085 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13086 (add-to-list 'rtn org-effort-property))
13088 (when include-columns
13092 (goto-char (point-min))
13093 (while (re-search-forward
13094 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13096 (setq cfmt (match-string 2) s 0)
13097 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13099 (setq s (match-end 0)
13100 p (match-string 1 cfmt))
13101 (unless (or (equal p "ITEM")
13102 (member p org-special-properties))
13103 (add-to-list 'rtn (match-string 1 cfmt))))))))
13105 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13107 (defun org-property-values (key)
13108 "Return a list of all values of property KEY."
13112 (goto-char (point-min))
13113 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13115 (while (re-search-forward re nil t)
13116 (add-to-list 'values (org-trim (match-string 1))))
13117 (delete "" values)))))
13119 (defun org-insert-property-drawer ()
13120 "Insert a property drawer into the current entry."
13122 (org-back-to-heading t)
13123 (looking-at outline-regexp)
13124 (let ((indent (if org-adapt-indentation
13125 (- (match-end 0)(match-beginning 0))
13128 (re (concat "^[ \t]*" org-keyword-time-regexp))
13130 (outline-next-heading)
13133 (while (re-search-forward re end t))
13134 (setq hiddenp (org-invisible-p))
13136 (and (equal (char-after) ?\n) (forward-char 1))
13137 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13138 (if (member (match-string 1) '("CLOCK:" ":END:"))
13139 ;; just skip this line
13140 (beginning-of-line 2)
13141 ;; Drawer start, find the end
13142 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13143 (beginning-of-line 1)))
13144 (org-skip-over-state-notes)
13145 (skip-chars-backward " \t\n\r")
13146 (if (eq (char-before) ?*) (forward-char 1))
13147 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13148 (beginning-of-line 0)
13149 (org-indent-to-column indent)
13150 (beginning-of-line 2)
13151 (org-indent-to-column indent)
13152 (beginning-of-line 0)
13155 (org-back-to-heading t)
13157 (org-flag-drawer t))))
13159 (defun org-set-property (property value)
13160 "In the current entry, set PROPERTY to VALUE.
13161 When called interactively, this will prompt for a property name, offering
13162 completion on existing and default properties. And then it will prompt
13163 for a value, offering completion either on allowed values (via an inherited
13164 xxx_ALL property) or on existing values in other instances of this property
13165 in the current file."
13167 (let* ((completion-ignore-case t)
13168 (keys (org-buffer-property-keys nil t t))
13169 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13170 (prop (if (member prop0 keys)
13172 (or (cdr (assoc (downcase prop0)
13173 (mapcar (lambda (x) (cons (downcase x) x))
13176 (cur (org-entry-get nil prop))
13177 (prompt (concat prop " value"
13178 (if (and cur (string-match "\\S-" cur))
13179 (concat " [" cur "]") "") ": "))
13180 (allowed (org-property-get-allowed-values nil prop 'table))
13181 (existing (mapcar 'list (org-property-values prop)))
13183 (org-completing-read prompt allowed nil
13184 (not (get-text-property 0 'org-unrestricted
13186 (let (org-completion-use-ido org-completion-use-iswitchb)
13187 (org-completing-read prompt existing nil nil "" nil cur)))))
13188 (list prop (if (equal val "") cur val))))
13189 (unless (equal (org-entry-get nil property) value)
13190 (org-entry-put nil property value)))
13192 (defun org-delete-property (property)
13193 "In the current entry, delete PROPERTY."
13195 (let* ((completion-ignore-case t)
13196 (prop (org-icompleting-read "Property: " (org-entry-properties nil 'standard))))
13198 (message "Property %s %s" property
13199 (if (org-entry-delete nil property)
13201 "was not present in the entry")))
13203 (defun org-delete-property-globally (property)
13204 "Remove PROPERTY globally, from all entries."
13206 (let* ((completion-ignore-case t)
13207 (prop (org-icompleting-read
13208 "Globally remove property: "
13209 (mapcar 'list (org-buffer-property-keys)))))
13214 (goto-char (point-min))
13216 (while (re-search-forward
13217 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13219 (setq cnt (1+ cnt))
13220 (replace-match ""))
13221 (message "Property \"%s\" removed from %d entries" property cnt)))))
13223 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13225 (defun org-compute-property-at-point ()
13226 "Compute the property at point.
13227 This looks for an enclosing column format, extracts the operator and
13228 then applies it to the property in the column format's scope."
13230 (unless (org-at-property-p)
13231 (error "Not at a property"))
13232 (let ((prop (org-match-string-no-properties 2)))
13233 (org-columns-get-format-and-top-level)
13234 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13235 (error "No operator defined for property %s" prop))
13236 (org-columns-compute prop)))
13238 (defvar org-property-allowed-value-functions nil
13239 "Hook for functions supplying allowed values for a specific property.
13240 The functions must take a single argument, the name of the property, and
13241 return a flat list of allowed values. If \":ETC\" is one of
13242 the values, this means that these values are intended as defaults for
13243 completion, but that other values should be allowed too.
13244 The functions must return nil if they are not responsible for this
13247 (defun org-property-get-allowed-values (pom property &optional table)
13248 "Get allowed values for the property PROPERTY.
13249 When TABLE is non-nil, return an alist that can directly be used for
13253 ((equal property "TODO")
13254 (setq vals (org-with-point-at pom
13255 (append org-todo-keywords-1 '("")))))
13256 ((equal property "PRIORITY")
13257 (let ((n org-lowest-priority))
13258 (while (>= n org-highest-priority)
13259 (push (char-to-string n) vals)
13261 ((member property org-special-properties))
13262 ((setq vals (run-hook-with-args-until-success
13263 'org-property-allowed-value-functions property)))
13265 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13266 (when (and vals (string-match "\\S-" vals))
13267 (setq vals (car (read-from-string (concat "(" vals ")"))))
13268 (setq vals (mapcar (lambda (x)
13269 (cond ((stringp x) x)
13270 ((numberp x) (number-to-string x))
13271 ((symbolp x) (symbol-name x))
13274 (when (member ":ETC" vals)
13275 (setq vals (remove ":ETC" vals))
13276 (org-add-props (car vals) '(org-unrestricted t)))
13277 (if table (mapcar 'list vals) vals)))
13279 (defun org-property-previous-allowed-value (&optional previous)
13280 "Switch to the next allowed value for this property."
13282 (org-property-next-allowed-value t))
13284 (defun org-property-next-allowed-value (&optional previous)
13285 "Switch to the next allowed value for this property."
13287 (unless (org-at-property-p)
13288 (error "Not at a property"))
13289 (let* ((key (match-string 2))
13290 (value (match-string 3))
13291 (allowed (or (org-property-get-allowed-values (point) key)
13292 (and (member value '("[ ]" "[-]" "[X]"))
13296 (error "Allowed values for this property have not been defined"))
13297 (if previous (setq allowed (reverse allowed)))
13298 (if (member value allowed)
13299 (setq nval (car (cdr (member value allowed)))))
13300 (setq nval (or nval (car allowed)))
13301 (if (equal nval value)
13302 (error "Only one allowed value for this property"))
13303 (org-at-property-p)
13304 (replace-match (concat " :" key ": " nval) t t)
13305 (org-indent-line-function)
13306 (beginning-of-line 1)
13307 (skip-chars-forward " \t")
13308 (run-hook-with-args 'org-property-changed-functions key nval)))
13310 (defun org-find-entry-with-id (ident)
13311 "Locate the entry that contains the ID property with exact value IDENT.
13312 IDENT can be a string, a symbol or a number, this function will search for
13313 the string representation of it.
13314 Return the position where this entry starts, or nil if there is no such entry."
13315 (interactive "sID: ")
13317 ((stringp ident) ident)
13318 ((symbol-name ident) (symbol-name ident))
13319 ((numberp ident) (number-to-string ident))
13320 (t (error "IDENT %s must be a string, symbol or number" ident))))
13321 (case-fold-search nil))
13325 (goto-char (point-min))
13326 (when (re-search-forward
13327 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13329 (org-back-to-heading t)
13334 (defvar org-last-changed-timestamp nil)
13335 (defvar org-last-inserted-timestamp nil
13336 "The last time stamp inserted with `org-insert-time-stamp'.")
13337 (defvar org-time-was-given) ; dynamically scoped parameter
13338 (defvar org-end-time-was-given) ; dynamically scoped parameter
13339 (defvar org-ts-what) ; dynamically scoped parameter
13341 (defun org-time-stamp (arg &optional inactive)
13342 "Prompt for a date/time and insert a time stamp.
13343 If the user specifies a time like HH:MM, or if this command is called
13344 with a prefix argument, the time stamp will contain date and time.
13345 Otherwise, only the date will be included. All parts of a date not
13346 specified by the user will be filled in from the current date/time.
13347 So if you press just return without typing anything, the time stamp
13348 will represent the current date/time. If there is already a timestamp
13349 at the cursor, it will be modified."
13353 ;; Default time is either today, or, when entering a range,
13354 ;; the range start.
13355 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13357 (re-search-backward
13358 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13359 (- (point) 20) t)))
13360 (apply 'encode-time (org-parse-time-string (match-string 1)))
13362 (default-input (and ts (org-get-compact-tod ts)))
13363 org-time-was-given org-end-time-was-given time)
13365 ((and (org-at-timestamp-p t)
13366 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13367 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13369 (setq time (let ((this-command this-command))
13370 (org-read-date arg 'totime nil nil
13371 default-time default-input)))
13372 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13373 ((org-at-timestamp-p t)
13374 (setq time (let ((this-command this-command))
13375 (org-read-date arg 'totime nil nil default-time default-input)))
13376 (when (org-at-timestamp-p t) ; just to get the match data
13377 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13379 (setq org-last-changed-timestamp
13380 (org-insert-time-stamp
13381 time (or org-time-was-given arg)
13382 inactive nil nil (list org-end-time-was-given))))
13383 (message "Timestamp updated"))
13385 (setq time (let ((this-command this-command))
13386 (org-read-date arg 'totime nil nil default-time default-input)))
13387 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13388 nil nil (list org-end-time-was-given))))))
13390 ;; FIXME: can we use this for something else, like computing time differences?
13391 (defun org-get-compact-tod (s)
13392 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13393 (let* ((t1 (match-string 1 s))
13394 (h1 (string-to-number (match-string 2 s)))
13395 (m1 (string-to-number (match-string 3 s)))
13396 (t2 (and (match-end 4) (match-string 5 s)))
13397 (h2 (and t2 (string-to-number (match-string 6 s))))
13398 (m2 (and t2 (string-to-number (match-string 7 s))))
13402 (setq dh (- h2 h1) dm (- m2 m1))
13403 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13404 (concat t1 "+" (number-to-string dh)
13405 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13407 (defun org-time-stamp-inactive (&optional arg)
13408 "Insert an inactive time stamp.
13409 An inactive time stamp is enclosed in square brackets instead of angle
13410 brackets. It is inactive in the sense that it does not trigger agenda entries,
13411 does not link to the calendar and cannot be changed with the S-cursor keys.
13412 So these are more for recording a certain time/date."
13414 (org-time-stamp arg 'inactive))
13416 (defvar org-date-ovl (org-make-overlay 1 1))
13417 (org-overlay-put org-date-ovl 'face 'org-warning)
13418 (org-detach-overlay org-date-ovl)
13420 (defvar org-ans1) ; dynamically scoped parameter
13421 (defvar org-ans2) ; dynamically scoped parameter
13423 (defvar org-plain-time-of-day-regexp) ; defined below
13425 (defvar org-overriding-default-time nil) ; dynamically scoped
13426 (defvar org-read-date-overlay nil)
13427 (defvar org-dcst nil) ; dynamically scoped
13428 (defvar org-read-date-history nil)
13429 (defvar org-read-date-final-answer nil)
13431 (defun org-read-date (&optional with-time to-time from-string prompt
13432 default-time default-input)
13433 "Read a date, possibly a time, and make things smooth for the user.
13434 The prompt will suggest to enter an ISO date, but you can also enter anything
13435 which will at least partially be understood by `parse-time-string'.
13436 Unrecognized parts of the date will default to the current day, month, year,
13437 hour and minute. If this command is called to replace a timestamp at point,
13438 of to enter the second timestamp of a range, the default time is taken from the
13439 existing stamp. For example,
13440 3-2-5 --> 2003-02-05
13441 feb 15 --> currentyear-02-15
13442 sep 12 9 --> 2009-09-12
13443 12:45 --> today 12:45
13444 22 sept 0:34 --> currentyear-09-22 0:34
13445 12 --> currentyear-currentmonth-12
13446 Fri --> nearest Friday (today or later)
13449 Furthermore you can specify a relative date by giving, as the *first* thing
13450 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
13451 change in days weeks, months, years.
13452 With a single plus or minus, the date is relative to today. With a double
13453 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
13454 +4d --> four days from today
13455 +4 --> same as above
13456 +2w --> two weeks from today
13457 ++5 --> five days from default date
13459 The function understands only English month and weekday abbreviations,
13460 but this can be configured with the variables `parse-time-months' and
13461 `parse-time-weekdays'.
13463 While prompting, a calendar is popped up - you can also select the
13464 date with the mouse (button 1). The calendar shows a period of three
13465 months. To scroll it to other months, use the keys `>' and `<'.
13466 If you don't like the calendar, turn it off with
13467 \(setq org-read-date-popup-calendar nil)
13469 With optional argument TO-TIME, the date will immediately be converted
13470 to an internal time.
13471 With an optional argument WITH-TIME, the prompt will suggest to also
13472 insert a time. Note that when WITH-TIME is not set, you can still
13473 enter a time, and this function will inform the calling routine about
13474 this change. The calling routine may then choose to change the format
13475 used to insert the time stamp into the buffer to include the time.
13476 With optional argument FROM-STRING, read from this string instead from
13477 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
13478 the time/date that is used for everything that is not specified by the
13480 (require 'parse-time)
13481 (let* ((org-time-stamp-rounding-minutes
13482 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
13483 (org-dcst org-display-custom-times)
13484 (ct (org-current-time))
13485 (def (or org-overriding-default-time default-time ct))
13486 (defdecode (decode-time def))
13488 (when (< (nth 2 defdecode) org-extend-today-until)
13489 (setcar (nthcdr 2 defdecode) -1)
13490 (setcar (nthcdr 1 defdecode) 59)
13491 (setq def (apply 'encode-time defdecode)
13492 defdecode (decode-time def)))))
13493 (calendar-frame-setup nil)
13494 (calendar-move-hook nil)
13495 (calendar-view-diary-initially-flag nil)
13496 (view-diary-entries-initially nil)
13497 (calendar-view-holidays-initially-flag nil)
13498 (view-calendar-holidays-initially nil)
13499 (timestr (format-time-string
13500 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
13501 (prompt (concat (if prompt (concat prompt " ") "")
13502 (format "Date+time [%s]: " timestr)))
13503 ans (org-ans0 "") org-ans1 org-ans2 final)
13506 (from-string (setq ans from-string))
13507 (org-read-date-popup-calendar
13509 (save-window-excursion
13511 (calendar-forward-day (- (time-to-days def)
13512 (calendar-absolute-from-gregorian
13513 (calendar-current-date))))
13514 (org-eval-in-calendar nil t)
13515 (let* ((old-map (current-local-map))
13516 (map (copy-keymap calendar-mode-map))
13517 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
13518 (org-defkey map (kbd "RET") 'org-calendar-select)
13519 (org-defkey map (if (featurep 'xemacs) [button1] [mouse-1])
13520 'org-calendar-select-mouse)
13521 (org-defkey map (if (featurep 'xemacs) [button2] [mouse-2
])
13522 'org-calendar-select-mouse
)
13523 (org-defkey minibuffer-local-map
[(meta shift left
)]
13524 (lambda () (interactive)
13525 (org-eval-in-calendar '(calendar-backward-month 1))))
13526 (org-defkey minibuffer-local-map
[(meta shift right
)]
13527 (lambda () (interactive)
13528 (org-eval-in-calendar '(calendar-forward-month 1))))
13529 (org-defkey minibuffer-local-map
[(meta shift up
)]
13530 (lambda () (interactive)
13531 (org-eval-in-calendar '(calendar-backward-year 1))))
13532 (org-defkey minibuffer-local-map
[(meta shift down
)]
13533 (lambda () (interactive)
13534 (org-eval-in-calendar '(calendar-forward-year 1))))
13535 (org-defkey minibuffer-local-map
[?\e
(shift left
)]
13536 (lambda () (interactive)
13537 (org-eval-in-calendar '(calendar-backward-month 1))))
13538 (org-defkey minibuffer-local-map
[?\e
(shift right
)]
13539 (lambda () (interactive)
13540 (org-eval-in-calendar '(calendar-forward-month 1))))
13541 (org-defkey minibuffer-local-map
[?\e
(shift up
)]
13542 (lambda () (interactive)
13543 (org-eval-in-calendar '(calendar-backward-year 1))))
13544 (org-defkey minibuffer-local-map
[?\e
(shift down
)]
13545 (lambda () (interactive)
13546 (org-eval-in-calendar '(calendar-forward-year 1))))
13547 (org-defkey minibuffer-local-map
[(shift up
)]
13548 (lambda () (interactive)
13549 (org-eval-in-calendar '(calendar-backward-week 1))))
13550 (org-defkey minibuffer-local-map
[(shift down
)]
13551 (lambda () (interactive)
13552 (org-eval-in-calendar '(calendar-forward-week 1))))
13553 (org-defkey minibuffer-local-map
[(shift left
)]
13554 (lambda () (interactive)
13555 (org-eval-in-calendar '(calendar-backward-day 1))))
13556 (org-defkey minibuffer-local-map
[(shift right
)]
13557 (lambda () (interactive)
13558 (org-eval-in-calendar '(calendar-forward-day 1))))
13559 (org-defkey minibuffer-local-map
">"
13560 (lambda () (interactive)
13561 (org-eval-in-calendar '(scroll-calendar-left 1))))
13562 (org-defkey minibuffer-local-map
"<"
13563 (lambda () (interactive)
13564 (org-eval-in-calendar '(scroll-calendar-right 1))))
13565 (run-hooks 'org-read-date-minibuffer-setup-hook
)
13568 (use-local-map map
)
13569 (add-hook 'post-command-hook
'org-read-date-display
)
13570 (setq org-ans0
(read-string prompt default-input
13571 'org-read-date-history nil
))
13572 ;; org-ans0: from prompt
13573 ;; org-ans1: from mouse click
13574 ;; org-ans2: from calendar motion
13575 (setq ans
(concat org-ans0
" " (or org-ans1 org-ans2
))))
13576 (remove-hook 'post-command-hook
'org-read-date-display
)
13577 (use-local-map old-map
)
13578 (when org-read-date-overlay
13579 (org-delete-overlay org-read-date-overlay
)
13580 (setq org-read-date-overlay nil
)))))))
13582 (t ; Naked prompt only
13584 (setq ans
(read-string prompt default-input
13585 'org-read-date-history timestr
))
13586 (when org-read-date-overlay
13587 (org-delete-overlay org-read-date-overlay
)
13588 (setq org-read-date-overlay nil
)))))
13590 (setq final
(org-read-date-analyze ans def defdecode
))
13591 (setq org-read-date-final-answer ans
)
13594 (apply 'encode-time final
)
13595 (if (and (boundp 'org-time-was-given
) org-time-was-given
)
13596 (format "%04d-%02d-%02d %02d:%02d"
13597 (nth 5 final
) (nth 4 final
) (nth 3 final
)
13598 (nth 2 final
) (nth 1 final
))
13599 (format "%04d-%02d-%02d" (nth 5 final
) (nth 4 final
) (nth 3 final
))))))
13604 (defvar org-read-date-analyze-futurep nil
)
13605 (defun org-read-date-display ()
13606 "Display the current date prompt interpretation in the minibuffer."
13607 (when org-read-date-display-live
13608 (when org-read-date-overlay
13609 (org-delete-overlay org-read-date-overlay
))
13612 (while (not (equal (buffer-substring
13613 (max (point-min) (- (point) 4)) (point))
13617 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
13618 " " (or org-ans1 org-ans2
)))
13619 (org-end-time-was-given nil
)
13620 (f (org-read-date-analyze ans def defdecode
))
13622 org-time-stamp-custom-formats
13623 org-time-stamp-formats
))
13624 (fmt (if (or with-time
13625 (and (boundp 'org-time-was-given
) org-time-was-given
))
13628 (txt (concat "=> " (format-time-string fmt
(apply 'encode-time f
)))))
13629 (when (and org-end-time-was-given
13630 (string-match org-plain-time-of-day-regexp txt
))
13631 (setq txt
(concat (substring txt
0 (match-end 0)) "-"
13632 org-end-time-was-given
13633 (substring txt
(match-end 0)))))
13634 (when org-read-date-analyze-futurep
13635 (setq txt
(concat txt
" (=>F)")))
13636 (setq org-read-date-overlay
13637 (org-make-overlay (1- (point-at-eol)) (point-at-eol)))
13638 (org-overlay-display org-read-date-overlay txt
'secondary-selection
))))
13640 (defun org-read-date-analyze (ans def defdecode
)
13641 "Analyse the combined answer of the date prompt."
13642 ;; FIXME: cleanup and comment
13643 (let ((nowdecode (decode-time (current-time)))
13644 delta deltan deltaw deltadef year month day
13645 hour minute second wday pm h2 m2 tl wday1
13646 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year
)
13647 (setq org-read-date-analyze-futurep nil
)
13648 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans
)
13651 (when (setq delta
(org-read-date-get-relative ans
(current-time) def
))
13652 (setq ans
(replace-match "" t t ans
)
13654 deltaw
(nth 1 delta
)
13655 deltadef
(nth 2 delta
)))
13657 ;; Check if there is an iso week date in there
13658 ;; If yes, store the info and postpone interpreting it until the rest
13659 ;; of the parsing is done
13660 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans
)
13661 (setq iso-year
(if (match-end 1)
13662 (org-small-year-to-year
13663 (string-to-number (match-string 1 ans
))))
13664 iso-weekday
(if (match-end 3)
13665 (string-to-number (match-string 3 ans
)))
13666 iso-week
(string-to-number (match-string 2 ans
)))
13667 (setq ans
(replace-match "" t t ans
)))
13669 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
13670 (when (string-match
13671 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans
)
13672 (setq year
(if (match-end 2)
13673 (string-to-number (match-string 2 ans
))
13674 (progn (setq kill-year t
)
13675 (string-to-number (format-time-string "%Y"))))
13676 month
(string-to-number (match-string 3 ans
))
13677 day
(string-to-number (match-string 4 ans
)))
13678 (if (< year
100) (setq year
(+ 2000 year
)))
13679 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
13681 ;; Help matching american dates, like 5/30 or 5/30/7
13682 (when (string-match
13683 "^ *\\([0-3]?[0-9]\\)/\\([0-1]?[0-9]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans
)
13684 (setq year
(if (match-end 4)
13685 (string-to-number (match-string 4 ans
))
13686 (progn (setq kill-year t
)
13687 (string-to-number (format-time-string "%Y"))))
13688 month
(string-to-number (match-string 1 ans
))
13689 day
(string-to-number (match-string 2 ans
)))
13690 (if (< year
100) (setq year
(+ 2000 year
)))
13691 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
13693 ;; Help matching am/pm times, because `parse-time-string' does not do that.
13694 ;; If there is a time with am/pm, and *no* time without it, we convert
13695 ;; so that matching will be successful.
13696 (loop for i from
1 to
2 do
; twice, for end time as well
13697 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans
))
13698 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans
))
13699 (setq hour
(string-to-number (match-string 1 ans
))
13700 minute
(if (match-end 3)
13701 (string-to-number (match-string 3 ans
))
13704 (string-to-char (downcase (match-string 4 ans
)))))
13705 (if (and (= hour
12) (not pm
))
13707 (if (and pm
(< hour
12)) (setq hour
(+ 12 hour
))))
13708 (setq ans
(replace-match (format "%02d:%02d" hour minute
)
13711 ;; Check if a time range is given as a duration
13712 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans
)
13713 (setq hour
(string-to-number (match-string 1 ans
))
13714 h2
(+ hour
(string-to-number (match-string 3 ans
)))
13715 minute
(string-to-number (match-string 2 ans
))
13716 m2
(+ minute
(if (match-end 5) (string-to-number
13717 (match-string 5 ans
))0)))
13718 (if (>= m2
60) (setq h2
(1+ h2
) m2
(- m2
60)))
13719 (setq ans
(replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2
)
13722 ;; Check if there is a time range
13723 (when (boundp 'org-end-time-was-given
)
13724 (setq org-time-was-given nil
)
13725 (when (and (string-match org-plain-time-of-day-regexp ans
)
13727 (setq org-end-time-was-given
(match-string 8 ans
))
13728 (setq ans
(concat (substring ans
0 (match-beginning 7))
13729 (substring ans
(match-end 7))))))
13731 (setq tl
(parse-time-string ans
)
13732 day
(or (nth 3 tl
) (nth 3 defdecode
))
13733 month
(or (nth 4 tl
)
13734 (if (and org-read-date-prefer-future
13735 (nth 3 tl
) (< (nth 3 tl
) (nth 3 nowdecode
)))
13736 (prog1 (1+ (nth 4 nowdecode
)) (setq futurep t
))
13737 (nth 4 defdecode
)))
13738 year
(or (and (not kill-year
) (nth 5 tl
))
13739 (if (and org-read-date-prefer-future
13740 (nth 4 tl
) (< (nth 4 tl
) (nth 4 nowdecode
)))
13741 (prog1 (1+ (nth 5 nowdecode
)) (setq futurep t
))
13742 (nth 5 defdecode
)))
13743 hour
(or (nth 2 tl
) (nth 2 defdecode
))
13744 minute
(or (nth 1 tl
) (nth 1 defdecode
))
13745 second
(or (nth 0 tl
) 0)
13748 (when (and (eq org-read-date-prefer-future
'time
)
13749 (not (nth 3 tl
)) (not (nth 4 tl
)) (not (nth 5 tl
))
13750 (equal day
(nth 3 nowdecode
))
13751 (equal month
(nth 4 nowdecode
))
13752 (equal year
(nth 5 nowdecode
))
13754 (or (< (nth 2 tl
) (nth 2 nowdecode
))
13755 (and (= (nth 2 tl
) (nth 2 nowdecode
))
13757 (< (nth 1 tl
) (nth 1 nowdecode
)))))
13761 ;; Special date definitions below
13764 ;; There was an iso week
13767 (setq year
(or iso-year year
)
13768 day
(or iso-weekday wday
1)
13769 wday nil
; to make sure that the trigger below does not match
13770 iso-date
(calendar-gregorian-from-absolute
13771 (calendar-absolute-from-iso
13772 (list iso-week day year
))))
13773 ; FIXME: Should we also push ISO weeks into the future?
13774 ; (when (and org-read-date-prefer-future
13776 ; (< (calendar-absolute-from-gregorian iso-date)
13777 ; (time-to-days (current-time))))
13778 ; (setq year (1+ year)
13779 ; iso-date (calendar-gregorian-from-absolute
13780 ; (calendar-absolute-from-iso
13781 ; (list iso-week day year)))))
13782 (setq month
(car iso-date
)
13783 year
(nth 2 iso-date
)
13784 day
(nth 1 iso-date
)))
13788 (let ((now (decode-time (current-time))))
13789 (setq day
(nth 3 now
) month
(nth 4 now
) year
(nth 5 now
))))
13790 (cond ((member deltaw
'("d" "")) (setq day
(+ day deltan
)))
13791 ((equal deltaw
"w") (setq day
(+ day
(* 7 deltan
))))
13792 ((equal deltaw
"m") (setq month
(+ month deltan
)))
13793 ((equal deltaw
"y") (setq year
(+ year deltan
)))))
13794 ((and wday
(not (nth 3 tl
)))
13796 ;; Weekday was given, but no day, so pick that day in the week
13797 ;; on or after the derived date.
13798 (setq wday1
(nth 6 (decode-time (encode-time 0 0 0 day month year
))))
13799 (unless (equal wday wday1
)
13800 (setq day
(+ day
(%
(- wday wday1 -
7) 7))))))
13801 (if (and (boundp 'org-time-was-given
)
13803 (setq org-time-was-given t
))
13804 (if (< year
100) (setq year
(+ 2000 year
)))
13805 (if (< year
1970) (setq year
(nth 5 defdecode
))) ; not representable
13806 (setq org-read-date-analyze-futurep futurep
)
13807 (list second minute hour day month year
)))
13809 (defvar parse-time-weekdays
)
13811 (defun org-read-date-get-relative (s today default
)
13812 "Check string S for special relative date string.
13813 TODAY and DEFAULT are internal times, for today and for a default.
13814 Return shift list (N what def-flag)
13815 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
13816 N is the number of WHATs to shift.
13817 DEF-FLAG is t when a double ++ or -- indicates shift relative to
13818 the DEFAULT date rather than TODAY."
13822 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
13824 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays
"\\|") "\\)\\)?"
13825 "\\([ \t]\\|$\\)") s
)
13826 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
13827 (let* ((dir (if (> (match-end 1) (match-beginning 1))
13828 (string-to-char (substring (match-string 1 s
) -
1))
13830 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
13831 (n (if (match-end 2) (string-to-number (match-string 2 s
)) 1))
13832 (what (if (match-end 3) (match-string 3 s
) "d"))
13833 (wday1 (cdr (assoc (downcase what
) parse-time-weekdays
)))
13834 (date (if rel default today
))
13835 (wday (nth 6 (decode-time date
)))
13839 (setq delta
(mod (+ 7 (- wday1 wday
)) 7))
13840 (if (= dir ?-
) (setq delta
(- delta
7)))
13841 (if (> n
1) (setq delta
(+ delta
(* (1- n
) (if (= dir ?-
) -
7 7)))))
13842 (list delta
"d" rel
))
13843 (list (* n
(if (= dir ?-
) -
1 1)) what rel
)))))
13845 (defun org-order-calendar-date-args (arg1 arg2 arg3
)
13846 "Turn a user-specified date into the internal representation.
13847 The internal representation needed by the calendar is (month day year).
13848 This is a wrapper to handle the brain-dead convention in calendar that
13849 user function argument order change dependent on argument order."
13850 (if (boundp 'calendar-date-style
)
13852 ((eq calendar-date-style
'american
)
13853 (list arg1 arg2 arg3
))
13854 ((eq calendar-date-style
'european
)
13855 (list arg2 arg1 arg3
))
13856 ((eq calendar-date-style
'iso
)
13857 (list arg2 arg3 arg1
)))
13858 (if (org-bound-and-true-p european-calendar-style
)
13859 (list arg2 arg1 arg3
)
13860 (list arg1 arg2 arg3
))))
13862 (defun org-eval-in-calendar (form &optional keepdate
)
13863 "Eval FORM in the calendar window and return to current window.
13864 Also, store the cursor date in variable org-ans2."
13865 (let ((sf (selected-frame))
13866 (sw (selected-window)))
13867 (select-window (get-buffer-window "*Calendar*" t
))
13869 (when (and (not keepdate
) (calendar-cursor-to-date))
13870 (let* ((date (calendar-cursor-to-date))
13871 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13872 (setq org-ans2
(format-time-string "%Y-%m-%d" time
))))
13873 (org-move-overlay org-date-ovl
(1- (point)) (1+ (point)) (current-buffer))
13875 (org-select-frame-set-input-focus sf
)))
13877 (defun org-calendar-select ()
13878 "Return to `org-read-date' with the date currently selected.
13879 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
13881 (when (calendar-cursor-to-date)
13882 (let* ((date (calendar-cursor-to-date))
13883 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13884 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
13885 (if (active-minibuffer-window) (exit-minibuffer))))
13887 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra
)
13888 "Insert a date stamp for the date given by the internal TIME.
13889 WITH-HM means use the stamp format that includes the time of the day.
13890 INACTIVE means use square brackets instead of angular ones, so that the
13891 stamp will not contribute to the agenda.
13892 PRE and POST are optional strings to be inserted before and after the
13894 The command returns the inserted time stamp."
13895 (let ((fmt (funcall (if with-hm
'cdr
'car
) org-time-stamp-formats
))
13897 (if inactive
(setq fmt
(concat "[" (substring fmt
1 -
1) "]")))
13898 (insert-before-markers (or pre
""))
13899 (insert-before-markers (setq stamp
(format-time-string fmt time
)))
13900 (when (listp extra
)
13901 (setq extra
(car extra
))
13902 (if (and (stringp extra
)
13903 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra
))
13904 (setq extra
(format "-%02d:%02d"
13905 (string-to-number (match-string 1 extra
))
13906 (string-to-number (match-string 2 extra
))))
13910 (insert-before-markers extra
)
13912 (insert-before-markers (or post
""))
13913 (setq org-last-inserted-timestamp stamp
)))
13915 (defun org-toggle-time-stamp-overlays ()
13916 "Toggle the use of custom time stamp formats."
13918 (setq org-display-custom-times
(not org-display-custom-times
))
13919 (unless org-display-custom-times
13920 (let ((p (point-min)) (bmp (buffer-modified-p)))
13921 (while (setq p
(next-single-property-change p
'display
))
13922 (if (and (get-text-property p
'display
)
13923 (eq (get-text-property p
'face
) 'org-date
))
13924 (remove-text-properties
13925 p
(setq p
(next-single-property-change p
'display
))
13927 (set-buffer-modified-p bmp
)))
13928 (if (featurep 'xemacs
)
13929 (remove-text-properties (point-min) (point-max) '(end-glyph t
)))
13930 (org-restart-font-lock)
13931 (setq org-table-may-need-update t
)
13932 (if org-display-custom-times
13933 (message "Time stamps are overlayed with custom format")
13934 (message "Time stamp overlays removed")))
13936 (defun org-display-custom-time (beg end
)
13937 "Overlay modified time stamp format over timestamp between BEG and END."
13938 (let* ((ts (buffer-substring beg end
))
13939 t1 w1 with-hm tf time str w2
(off 0))
13941 (setq t1
(org-parse-time-string ts t
))
13942 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts
)
13943 (setq off
(- (match-end 0) (match-beginning 0)))))
13944 (setq end
(- end off
))
13945 (setq w1
(- end beg
)
13946 with-hm
(and (nth 1 t1
) (nth 2 t1
))
13947 tf
(funcall (if with-hm
'cdr
'car
) org-time-stamp-custom-formats
)
13948 time
(org-fix-decoded-time t1
)
13950 (format-time-string
13951 (substring tf
1 -
1) (apply 'encode-time time
))
13952 nil
'mouse-face
'highlight
)
13954 (if (not (= w2 w1
))
13955 (add-text-properties (1+ beg
) (+ 2 beg
)
13956 (list 'org-dwidth t
'org-dwidth-n
(- w1 w2
))))
13957 (if (featurep 'xemacs
)
13959 (put-text-property beg end
'invisible t
)
13960 (put-text-property beg end
'end-glyph
(make-glyph str
)))
13961 (put-text-property beg end
'display str
))))
13963 (defun org-translate-time (string)
13964 "Translate all timestamps in STRING to custom format.
13965 But do this only if the variable `org-display-custom-times' is set."
13966 (when org-display-custom-times
13969 (re org-ts-regexp-both
)
13970 t1 with-hm inactive tf time str beg end
)
13971 (while (setq start
(string-match re string start
))
13972 (setq beg
(match-beginning 0)
13974 t1
(save-match-data
13975 (org-parse-time-string (substring string beg end
) t
))
13976 with-hm
(and (nth 1 t1
) (nth 2 t1
))
13977 inactive
(equal (substring string beg
(1+ beg
)) "[")
13978 tf
(funcall (if with-hm
'cdr
'car
)
13979 org-time-stamp-custom-formats
)
13980 time
(org-fix-decoded-time t1
)
13981 str
(format-time-string
13983 (if inactive
"[" "<") (substring tf
1 -
1)
13984 (if inactive
"]" ">"))
13985 (apply 'encode-time time
))
13986 string
(replace-match str t t string
)
13987 start
(+ start
(length str
)))))))
13990 (defun org-fix-decoded-time (time)
13991 "Set 0 instead of nil for the first 6 elements of time.
13992 Don't touch the rest."
13994 (mapcar (lambda (x) (if (< (setq n
(1+ n
)) 7) (or x
0) x
)) time
)))
13996 (defun org-days-to-time (timestamp-string)
13997 "Difference between TIMESTAMP-STRING and now in days."
13998 (- (time-to-days (org-time-string-to-time timestamp-string
))
13999 (time-to-days (current-time))))
14001 (defun org-deadline-close (timestamp-string &optional ndays
)
14002 "Is the time in TIMESTAMP-STRING close to the current date?"
14003 (setq ndays
(or ndays
(org-get-wdays timestamp-string
)))
14004 (and (< (org-days-to-time timestamp-string
) ndays
)
14005 (not (org-entry-is-done-p))))
14007 (defun org-get-wdays (ts)
14008 "Get the deadline lead time appropriate for timestring TS."
14010 ((<= org-deadline-warning-days
0)
14011 ;; 0 or negative, enforce this value no matter what
14012 (- org-deadline-warning-days
))
14013 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts
)
14014 ;; lead time is specified.
14015 (floor (* (string-to-number (match-string 1 ts
))
14016 (cdr (assoc (match-string 2 ts
)
14017 '(("d" .
1) ("w" .
7)
14018 ("m" .
30.4) ("y" .
365.25)))))))
14019 ;; go for the default.
14020 (t org-deadline-warning-days
)))
14022 (defun org-calendar-select-mouse (ev)
14023 "Return to `org-read-date' with the date currently selected.
14024 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14026 (mouse-set-point ev
)
14027 (when (calendar-cursor-to-date)
14028 (let* ((date (calendar-cursor-to-date))
14029 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
14030 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
14031 (if (active-minibuffer-window) (exit-minibuffer))))
14033 (defun org-check-deadlines (ndays)
14034 "Check if there are any deadlines due or past due.
14035 A deadline is considered due if it happens within `org-deadline-warning-days'
14036 days from today's date. If the deadline appears in an entry marked DONE,
14037 it is not shown. The prefix arg NDAYS can be used to test that many
14038 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14040 (let* ((org-warn-days
14042 ((equal ndays
'(4)) 100000)
14043 (ndays (prefix-numeric-value ndays
))
14044 (t (abs org-deadline-warning-days
))))
14045 (case-fold-search nil
)
14046 (regexp (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>"))
14048 (lambda () (org-deadline-close (match-string 1) org-warn-days
))))
14050 (message "%d deadlines past-due or due within %d days"
14051 (org-occur regexp nil callback
)
14054 (defun org-check-before-date (date)
14055 "Check if there are deadlines or scheduled entries before DATE."
14056 (interactive (list (org-read-date)))
14057 (let ((case-fold-search nil
)
14058 (regexp (concat "\\<\\(" org-deadline-string
14059 "\\|" org-scheduled-string
14060 "\\) *<\\([^>]+\\)>"))
14062 (lambda () (time-less-p
14063 (org-time-string-to-time (match-string 2))
14064 (org-time-string-to-time date
)))))
14065 (message "%d entries before %s"
14066 (org-occur regexp nil callback
) date
)))
14068 (defun org-check-after-date (date)
14069 "Check if there are deadlines or scheduled entries after DATE."
14070 (interactive (list (org-read-date)))
14071 (let ((case-fold-search nil
)
14072 (regexp (concat "\\<\\(" org-deadline-string
14073 "\\|" org-scheduled-string
14074 "\\) *<\\([^>]+\\)>"))
14078 (org-time-string-to-time (match-string 2))
14079 (org-time-string-to-time date
))))))
14080 (message "%d entries after %s"
14081 (org-occur regexp nil callback
) date
)))
14083 (defun org-evaluate-time-range (&optional to-buffer
)
14084 "Evaluate a time range by computing the difference between start and end.
14085 Normally the result is just printed in the echo area, but with prefix arg
14086 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14087 If the time range is actually in a table, the result is inserted into the
14089 For time difference computation, a year is assumed to be exactly 365
14090 days in order to avoid rounding problems."
14093 (org-clock-update-time-maybe)
14095 (unless (org-at-date-range-p t
)
14096 (goto-char (point-at-bol))
14097 (re-search-forward org-tr-regexp-both
(point-at-eol) t
))
14098 (if (not (org-at-date-range-p t
))
14099 (error "Not at a time-stamp range, and none found in current line")))
14100 (let* ((ts1 (match-string 1))
14101 (ts2 (match-string 2))
14102 (havetime (or (> (length ts1
) 15) (> (length ts2
) 15)))
14103 (match-end (match-end 0))
14104 (time1 (org-time-string-to-time ts1
))
14105 (time2 (org-time-string-to-time ts2
))
14106 (t1 (org-float-time time1
))
14107 (t2 (org-float-time time2
))
14108 (diff (abs (- t2 t1
)))
14109 (negative (< (- t2 t1
) 0))
14110 ;; (ys (floor (* 365 24 60 60)))
14113 (fy "%dy %dd %02d:%02d")
14115 (fd "%dd %02d:%02d")
14120 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14122 d
(floor (/ diff ds
)) diff
(mod diff ds
)
14123 h
(floor (/ diff hs
)) diff
(mod diff hs
)
14124 m
(floor (/ diff
60)))
14125 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14127 d
(floor (+ (/ diff ds
) 0.5))
14129 (if (not to-buffer
)
14130 (message "%s" (org-make-tdiff-string y d h m
))
14131 (if (org-at-table-p)
14133 (goto-char match-end
)
14135 (and (looking-at " *|") (goto-char (match-end 0))))
14136 (goto-char match-end
))
14138 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14139 (replace-match ""))
14140 (if negative
(insert " -"))
14141 (if (> y
0) (insert " " (format (if havetime fy fy1
) y d h m
))
14142 (if (> d
0) (insert " " (format (if havetime fd fd1
) d h m
))
14143 (insert " " (format fh h m
))))
14144 (if align
(org-table-align))
14145 (message "Time difference inserted")))))
14147 (defun org-make-tdiff-string (y d h m
)
14150 (if (> y
0) (setq fmt
(concat fmt
"%d year" (if (> y
1) "s" "") " ")
14152 (if (> d
0) (setq fmt
(concat fmt
"%d day" (if (> d
1) "s" "") " ")
14154 (if (> h
0) (setq fmt
(concat fmt
"%d hour" (if (> h
1) "s" "") " ")
14156 (if (> m
0) (setq fmt
(concat fmt
"%d minute" (if (> m
1) "s" "") " ")
14158 (apply 'format fmt
(nreverse l
))))
14160 (defun org-time-string-to-time (s)
14161 (apply 'encode-time
(org-parse-time-string s
)))
14162 (defun org-time-string-to-seconds (s)
14163 (org-float-time (org-time-string-to-time s
)))
14165 (defun org-time-string-to-absolute (s &optional daynr prefer show-all
)
14166 "Convert a time stamp to an absolute day number.
14167 If there is a specifyer for a cyclic time stamp, get the closest date to
14169 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14170 the variable date is bound by the calendar when this is called."
14172 ((and daynr
(string-match "\\`%%\\((.*)\\)" s
))
14173 (if (org-diary-sexp-entry (match-string 1 s
) "" date
)
14176 ((and daynr
(string-match "\\+[0-9]+[dwmy]" s
))
14177 (org-closest-date s
(if (and (boundp 'daynr
) (integerp daynr
)) daynr
14178 (time-to-days (current-time))) (match-string 0 s
)
14180 (t (time-to-days (apply 'encode-time
(org-parse-time-string s
))))))
14182 (defun org-days-to-iso-week (days)
14183 "Return the iso week number."
14185 (car (calendar-iso-from-absolute days
)))
14187 (defun org-small-year-to-year (year)
14188 "Convert 2-digit years into 4-digit years.
14189 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14190 The year 2000 cannot be abbreviated. Any year larger than 99
14191 is returned unchanged."
14193 (setq year
(+ 2000 year
))
14195 (setq year
(+ 1900 year
))))
14198 (defun org-time-from-absolute (d)
14199 "Return the time corresponding to date D.
14200 D may be an absolute day number, or a calendar-type list (month day year)."
14201 (if (numberp d
) (setq d
(calendar-gregorian-from-absolute d
)))
14202 (encode-time 0 0 0 (nth 1 d
) (car d
) (nth 2 d
)))
14204 (defun org-calendar-holiday ()
14205 "List of holidays, for Diary display in Org-mode."
14206 (require 'holidays
)
14208 (if (fboundp 'calendar-check-holidays
)
14209 'calendar-check-holidays
'check-calendar-holidays
) date
)))
14210 (if hl
(mapconcat 'identity hl
"; "))))
14212 (defun org-diary-sexp-entry (sexp entry date
)
14213 "Process a SEXP diary ENTRY for DATE."
14214 (require 'diary-lib
)
14215 (let ((result (if calendar-debug-sexp
14216 (let ((stack-trace-on-error t
))
14217 (eval (car (read-from-string sexp
))))
14218 (condition-case nil
14219 (eval (car (read-from-string sexp
)))
14222 (message "Bad sexp at line %d in %s: %s"
14224 (buffer-file-name) sexp
)
14226 (cond ((stringp result
) result
)
14227 ((and (consp result
)
14228 (stringp (cdr result
))) (cdr result
))
14232 (defun org-diary-to-ical-string (frombuf)
14233 "Get iCalendar entries from diary entries in buffer FROMBUF.
14234 This uses the icalendar.el library."
14235 (let* ((tmpdir (if (featurep 'xemacs
)
14237 temporary-file-directory
))
14238 (tmpfile (make-temp-name
14239 (expand-file-name "orgics" tmpdir
)))
14241 (with-current-buffer frombuf
14242 (icalendar-export-region (point-min) (point-max) tmpfile
)
14243 (setq buf
(find-buffer-visiting tmpfile
))
14245 (goto-char (point-min))
14246 (if (re-search-forward "^BEGIN:VEVENT" nil t
)
14247 (setq b
(match-beginning 0)))
14248 (goto-char (point-max))
14249 (if (re-search-backward "^END:VEVENT" nil t
)
14250 (setq e
(match-end 0)))
14251 (setq rtn
(if (and b e
) (concat (buffer-substring b e
) "\n") "")))
14253 (delete-file tmpfile
)
14256 (defun org-closest-date (start current change prefer show-all
)
14257 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14258 When PREFER is `past' return a date that is either CURRENT or past.
14259 When PREFER is `future', return a date that is either CURRENT or future.
14260 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14261 ;; Make the proper lists from the dates
14263 (let ((a1 '(("d" . day
) ("w" . week
) ("m" . month
) ("y" . year
)))
14264 dn dw sday cday n1 n2 n0
14265 d m y y1 y2 date1 date2 nmonths nm ny m2
)
14267 (setq start
(org-date-to-gregorian start
)
14268 current
(org-date-to-gregorian
14271 (time-to-days (current-time))))
14272 sday
(calendar-absolute-from-gregorian start
)
14273 cday
(calendar-absolute-from-gregorian current
))
14275 (if (<= cday sday
) (throw 'exit sday
))
14277 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change
)
14278 (setq dn
(string-to-number (match-string 1 change
))
14279 dw
(cdr (assoc (match-string 2 change
) a1
)))
14280 (error "Invalid change specifyer: %s" change
))
14281 (if (eq dw
'week
) (setq dw
'day dn
(* 7 dn
)))
14284 (setq n1
(+ sday
(* dn
(floor (/ (- cday sday
) dn
))))
14287 (setq d
(nth 1 start
) m
(car start
) y1
(nth 2 start
) y2
(nth 2 current
))
14288 (setq y1
(+ (* (floor (/ (- y2 y1
) dn
)) dn
) y1
))
14289 (setq date1
(list m d y1
)
14290 n1
(calendar-absolute-from-gregorian date1
)
14291 date2
(list m d
(+ y1
(* (if (< n1 cday
) 1 -
1) dn
)))
14292 n2
(calendar-absolute-from-gregorian date2
)))
14294 ;; approx number of month between the two dates
14295 (setq nmonths
(floor (/ (- cday sday
) 30.436875)))
14296 ;; How often does dn fit in there?
14297 (setq d
(nth 1 start
) m
(car start
) y
(nth 2 start
)
14298 nm
(* dn
(max 0 (1- (floor (/ nmonths dn
)))))
14300 ny
(floor (/ m
12))
14303 (while (> m
12) (setq m
(- m
12) y
(1+ y
)))
14304 (setq n1
(calendar-absolute-from-gregorian (list m d y
)))
14305 (setq m2
(+ m dn
) y2 y
)
14306 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
14307 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
)))
14308 (while (<= n2 cday
)
14309 (setq n1 n2 m m2 y y2
)
14310 (setq m2
(+ m dn
) y2 y
)
14311 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
14312 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
))))))
14313 ;; Make sure n1 is the earlier date
14314 (setq n0 n1 n1
(min n1 n2
) n2
(max n0 n2
))
14317 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
14318 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
14319 (t (if (> (abs (- cday n1
)) (abs (- cday n2
))) n2 n1
)))
14321 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
14322 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
14323 (t (if (= cday n1
) n1 n2
)))))))
14325 (defun org-date-to-gregorian (date)
14326 "Turn any specification of DATE into a gregorian date for the calendar."
14327 (cond ((integerp date
) (calendar-gregorian-from-absolute date
))
14328 ((and (listp date
) (= (length date
) 3)) date
)
14330 (setq date
(org-parse-time-string date
))
14331 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))
14333 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))))
14335 (defun org-parse-time-string (s &optional nodefault
)
14336 "Parse the standard Org-mode time string.
14337 This should be a lot faster than the normal `parse-time-string'.
14338 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14339 hour and minute fields will be nil if not given."
14340 (if (string-match org-ts-regexp0 s
)
14342 (if (or (match-beginning 8) (not nodefault
))
14343 (string-to-number (or (match-string 8 s
) "0")))
14344 (if (or (match-beginning 7) (not nodefault
))
14345 (string-to-number (or (match-string 7 s
) "0")))
14346 (string-to-number (match-string 4 s
))
14347 (string-to-number (match-string 3 s
))
14348 (string-to-number (match-string 2 s
))
14350 (error "Not a standard Org-mode time string: %s" s
)))
14352 (defun org-timestamp-up (&optional arg
)
14353 "Increase the date item at the cursor by one.
14354 If the cursor is on the year, change the year. If it is on the month or
14355 the day, change that.
14356 With prefix ARG, change by that many units."
14358 (org-timestamp-change (prefix-numeric-value arg
)))
14360 (defun org-timestamp-down (&optional arg
)
14361 "Decrease the date item at the cursor by one.
14362 If the cursor is on the year, change the year. If it is on the month or
14363 the day, change that.
14364 With prefix ARG, change by that many units."
14366 (org-timestamp-change (- (prefix-numeric-value arg
))))
14368 (defun org-timestamp-up-day (&optional arg
)
14369 "Increase the date in the time stamp by one day.
14370 With prefix ARG, change that many days."
14372 (if (and (not (org-at-timestamp-p t
))
14373 (org-on-heading-p))
14375 (org-timestamp-change (prefix-numeric-value arg
) 'day
)))
14377 (defun org-timestamp-down-day (&optional arg
)
14378 "Decrease the date in the time stamp by one day.
14379 With prefix ARG, change that many days."
14381 (if (and (not (org-at-timestamp-p t
))
14382 (org-on-heading-p))
14384 (org-timestamp-change (- (prefix-numeric-value arg
)) 'day
)))
14386 (defun org-at-timestamp-p (&optional inactive-ok
)
14387 "Determine if the cursor is in or at a timestamp."
14389 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2
))
14391 (ans (or (looking-at tsr
)
14393 (skip-chars-backward "^[<\n\r\t")
14394 (if (> (point) (point-min)) (backward-char 1))
14395 (and (looking-at tsr
)
14396 (> (- (match-end 0) pos
) -
1))))))
14398 (boundp 'org-ts-what
)
14401 ((= pos
(match-beginning 0)) 'bracket
)
14402 ((= pos
(1- (match-end 0))) 'bracket
)
14403 ((org-pos-in-match-range pos
2) 'year
)
14404 ((org-pos-in-match-range pos
3) 'month
)
14405 ((org-pos-in-match-range pos
7) 'hour
)
14406 ((org-pos-in-match-range pos
8) 'minute
)
14407 ((or (org-pos-in-match-range pos
4)
14408 (org-pos-in-match-range pos
5)) 'day
)
14409 ((and (> pos
(or (match-end 8) (match-end 5)))
14410 (< pos
(match-end 0)))
14411 (- pos
(or (match-end 8) (match-end 5))))
14415 (defun org-toggle-timestamp-type ()
14416 "Toggle the type (<active> or [inactive]) of a time stamp."
14418 (when (org-at-timestamp-p t
)
14419 (let ((beg (match-beginning 0)) (end (match-end 0))
14420 (map '((?\
[ .
"<") (?\
] .
">") (?
< .
"[") (?
> .
"]"))))
14423 (while (re-search-forward "[][<>]" end t
)
14424 (replace-match (cdr (assoc (char-after (match-beginning 0)) map
))
14426 (message "Timestamp is now %sactive"
14427 (if (equal (char-after beg
) ?
<) "" "in")))))
14429 (defun org-timestamp-change (n &optional what
)
14430 "Change the date in the time stamp at point.
14431 The date will be changed by N times WHAT. WHAT can be `day', `month',
14432 `year', `minute', `second'. If WHAT is not given, the cursor position
14433 in the timestamp determines what will be changed."
14434 (let ((pos (point))
14436 (dm (max (nth 1 org-time-stamp-rounding-minutes
) 1))
14440 (if (not (org-at-timestamp-p t
))
14441 (error "Not at a timestamp"))
14442 (if (and (not what
) (eq org-ts-what
'bracket
))
14443 (org-toggle-timestamp-type)
14444 (if (and (not what
) (not (eq org-ts-what
'day
))
14445 org-display-custom-times
14446 (get-text-property (point) 'display
)
14447 (not (get-text-property (1- (point)) 'display
)))
14448 (setq org-ts-what
'day
))
14449 (setq org-ts-what
(or what org-ts-what
)
14450 inactive
(= (char-after (match-beginning 0)) ?\
[)
14451 ts
(match-string 0))
14454 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
14456 (setq extra
(match-string 1 ts
)))
14457 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts
)
14459 (setq time0
(org-parse-time-string ts
))
14460 (when (and (eq org-ts-what
'minute
)
14461 (eq current-prefix-arg nil
))
14462 (setq n
(* dm
(cond ((> n
0) 1) ((< n
0) -
1) (t 0))))
14463 (when (not (= 0 (setq rem
(%
(nth 1 time0
) dm
))))
14464 (setcar (cdr time0
) (+ (nth 1 time0
)
14465 (if (> n
0) (- rem
) (- dm rem
))))))
14467 (encode-time (or (car time0
) 0)
14468 (+ (if (eq org-ts-what
'minute
) n
0) (nth 1 time0
))
14469 (+ (if (eq org-ts-what
'hour
) n
0) (nth 2 time0
))
14470 (+ (if (eq org-ts-what
'day
) n
0) (nth 3 time0
))
14471 (+ (if (eq org-ts-what
'month
) n
0) (nth 4 time0
))
14472 (+ (if (eq org-ts-what
'year
) n
0) (nth 5 time0
))
14474 (when (and (member org-ts-what
'(hour minute
))
14476 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra
))
14477 (setq extra
(org-modify-ts-extra
14479 (if (eq org-ts-what
'hour
) 2 5)
14481 (when (integerp org-ts-what
)
14482 (setq extra
(org-modify-ts-extra extra org-ts-what n dm
)))
14483 (if (eq what
'calendar
)
14484 (let ((cal-date (org-get-date-from-calendar)))
14485 (setcar (nthcdr 4 time0
) (nth 0 cal-date
)) ; month
14486 (setcar (nthcdr 3 time0
) (nth 1 cal-date
)) ; day
14487 (setcar (nthcdr 5 time0
) (nth 2 cal-date
)) ; year
14488 (setcar time0
(or (car time0
) 0))
14489 (setcar (nthcdr 1 time0
) (or (nth 1 time0
) 0))
14490 (setcar (nthcdr 2 time0
) (or (nth 2 time0
) 0))
14491 (setq time
(apply 'encode-time time0
))))
14492 (setq org-last-changed-timestamp
14493 (org-insert-time-stamp time with-hm inactive nil nil extra
))
14494 (org-clock-update-time-maybe)
14496 ;; Try to recenter the calendar window, if any
14497 (if (and org-calendar-follow-timestamp-change
14498 (get-buffer-window "*Calendar*" t
)
14499 (memq org-ts-what
'(day month year
)))
14500 (org-recenter-calendar (time-to-days time
))))))
14502 (defun org-modify-ts-extra (s pos n dm
)
14503 "Change the different parts of the lead-time and repeat fields in timestamp."
14504 (let ((idx '(("d" .
0) ("w" .
1) ("m" .
2) ("y" .
3) ("d" . -
1) ("y" .
4)))
14506 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s
)
14508 ((or (org-pos-in-match-range pos
2)
14509 (org-pos-in-match-range pos
3))
14510 (setq m
(string-to-number (match-string 3 s
))
14511 h
(string-to-number (match-string 2 s
)))
14512 (if (org-pos-in-match-range pos
2)
14514 (setq n
(* dm
(org-no-warnings (signum n
))))
14515 (when (not (= 0 (setq rem
(% m dm
))))
14516 (setq m
(+ m
(if (> n
0) (- rem
) (- dm rem
)))))
14518 (if (< m
0) (setq m
(+ m
60) h
(1- h
)))
14519 (if (> m
59) (setq m
(- m
60) h
(1+ h
)))
14520 (setq h
(min 24 (max 0 h
)))
14521 (setq ng
1 new
(format "-%02d:%02d" h m
)))
14522 ((org-pos-in-match-range pos
6)
14523 (setq ng
6 new
(car (rassoc (+ n
(cdr (assoc (match-string 6 s
) idx
))) idx
))))
14524 ((org-pos-in-match-range pos
5)
14525 (setq ng
5 new
(format "%d" (max 1 (+ n
(string-to-number (match-string 5 s
)))))))
14527 ((org-pos-in-match-range pos
9)
14528 (setq ng
9 new
(car (rassoc (+ n
(cdr (assoc (match-string 9 s
) idx
))) idx
))))
14529 ((org-pos-in-match-range pos
8)
14530 (setq ng
8 new
(format "%d" (max 0 (+ n
(string-to-number (match-string 8 s
))))))))
14534 (substring s
0 (match-beginning ng
))
14536 (substring s
(match-end ng
))))))
14539 (defun org-recenter-calendar (date)
14540 "If the calendar is visible, recenter it to DATE."
14541 (let* ((win (selected-window))
14542 (cwin (get-buffer-window "*Calendar*" t
))
14543 (calendar-move-hook nil
))
14545 (select-window cwin
)
14546 (calendar-goto-date (if (listp date
) date
14547 (calendar-gregorian-from-absolute date
)))
14548 (select-window win
))))
14550 (defun org-goto-calendar (&optional arg
)
14551 "Go to the Emacs calendar at the current date.
14552 If there is a time stamp in the current line, go to that date.
14553 A prefix ARG can be used to force the current date."
14555 (let ((tsr org-ts-regexp
) diff
14556 (calendar-move-hook nil
)
14557 (calendar-view-holidays-initially-flag nil
)
14558 (view-calendar-holidays-initially nil
)
14559 (calendar-view-diary-initially-flag nil
)
14560 (view-diary-entries-initially nil
))
14561 (if (or (org-at-timestamp-p)
14563 (beginning-of-line 1)
14564 (looking-at (concat ".*" tsr
))))
14565 (let ((d1 (time-to-days (current-time)))
14567 (org-time-string-to-time (match-string 1)))))
14568 (setq diff
(- d2 d1
))))
14570 (calendar-goto-today)
14571 (if (and diff
(not arg
)) (calendar-forward-day diff
))))
14573 (defun org-get-date-from-calendar ()
14574 "Return a list (month day year) of date at point in calendar."
14575 (with-current-buffer "*Calendar*"
14577 (calendar-cursor-to-date))))
14579 (defun org-date-from-calendar ()
14580 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
14581 If there is already a time stamp at the cursor position, update it."
14583 (if (org-at-timestamp-p t
)
14584 (org-timestamp-change 0 'calendar
)
14585 (let ((cal-date (org-get-date-from-calendar)))
14586 (org-insert-time-stamp
14587 (encode-time 0 0 0 (nth 1 cal-date
) (car cal-date
) (nth 2 cal-date
))))))
14589 (defun org-minutes-to-hh:mm-string
(m)
14590 "Compute H:MM from a number of minutes."
14591 (let ((h (/ m
60)))
14592 (setq m
(- m
(* 60 h
)))
14593 (format org-time-clocksum-format h m
)))
14595 (defun org-hh:mm-string-to-minutes
(s)
14596 "Convert a string H:MM to a number of minutes.
14597 If the string is just a number, interpret it as minutes.
14598 In fact, the first hh:mm or number in the string will be taken,
14599 there can be extra stuff in the string.
14600 If no number is found, the return value is 0."
14602 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s
)
14603 (+ (* (string-to-number (match-string 1 s
)) 60)
14604 (string-to-number (match-string 2 s
))))
14605 ((string-match "\\([0-9]+\\)" s
)
14606 (string-to-number (match-string 1 s
)))
14611 (defun org-save-all-org-buffers ()
14612 "Save all Org-mode buffers without user confirmation."
14614 (message "Saving all Org-mode buffers...")
14615 (save-some-buffers t
'org-mode-p
)
14616 (when (featurep 'org-id
) (org-id-locations-save))
14617 (message "Saving all Org-mode buffers... done"))
14619 (defun org-revert-all-org-buffers ()
14620 "Revert all Org-mode buffers.
14621 Prompt for confirmation when there are unsaved changes.
14622 Be sure you know what you are doing before letting this function
14623 overwrite your changes.
14625 This function is useful in a setup where one tracks org files
14626 with a version control system, to revert on one machine after pulling
14627 changes from another. I believe the procedure must be like this:
14629 1. M-x org-save-all-org-buffers
14630 2. Pull changes from the other machine, resolve conflicts
14631 3. M-x org-revert-all-org-buffers"
14633 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
14636 (save-window-excursion
14639 (when (and (with-current-buffer b
(org-mode-p))
14640 (with-current-buffer b buffer-file-name
))
14641 (switch-to-buffer b
)
14642 (revert-buffer t
'no-confirm
)))
14644 (when (and (featurep 'org-id
) org-id-track-globally
)
14645 (org-id-locations-load)))))
14650 (defun org-iswitchb (&optional arg
)
14651 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
14652 With a prefix argument, restrict available to files.
14653 With two prefix arguments, restrict available buffers to agenda files."
14655 (let ((blist (cond ((equal arg
'(4)) (org-buffer-list 'files
))
14656 ((equal arg
'(16)) (org-buffer-list 'agenda
))
14657 (t (org-buffer-list)))))
14659 (org-icompleting-read "Org buffer: "
14660 (mapcar 'list
(mapcar 'buffer-name blist
))
14664 (defalias 'org-ido-switchb
'org-iswitchb
)
14666 (defun org-buffer-list (&optional predicate exclude-tmp
)
14667 "Return a list of Org buffers.
14668 PREDICATE can be `export', `files' or `agenda'.
14670 export restrict the list to Export buffers.
14671 files restrict the list to buffers visiting Org files.
14672 agenda restrict the list to buffers visiting agenda files.
14674 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
14676 (agenda-files (and (eq predicate
'agenda
)
14677 (mapcar 'file-truename
(org-agenda-files t
))))
14680 ((eq predicate
'files
)
14681 (lambda (b) (with-current-buffer b
(eq major-mode
'org-mode
))))
14682 ((eq predicate
'export
)
14683 (lambda (b) (string-match "\*Org .*Export" (buffer-name b
))))
14684 ((eq predicate
'agenda
)
14686 (with-current-buffer b
14687 (and (eq major-mode
'org-mode
)
14688 (setq bfn
(buffer-file-name b
))
14689 (member (file-truename bfn
) agenda-files
)))))
14690 (t (lambda (b) (with-current-buffer b
14691 (or (eq major-mode
'org-mode
)
14692 (string-match "\*Org .*Export"
14693 (buffer-name b
)))))))))
14697 (if (and (funcall filter b
)
14698 (or (not exclude-tmp
)
14699 (not (string-match "tmp" (buffer-name b
)))))
14704 (defun org-agenda-files (&optional unrestricted archives
)
14705 "Get the list of agenda files.
14706 Optional UNRESTRICTED means return the full list even if a restriction
14707 is currently in place.
14708 When ARCHIVES is t, include all archive files that are really being
14709 used by the agenda files. If ARCHIVE is `ifmode', do this only if
14710 `org-agenda-archives-mode' is t."
14713 ((and (not unrestricted
) (get 'org-agenda-files
'org-restrict
)))
14714 ((stringp org-agenda-files
) (org-read-agenda-file-list))
14715 ((listp org-agenda-files
) org-agenda-files
)
14716 (t (error "Invalid value of `org-agenda-files'")))))
14717 (setq files
(apply 'append
14718 (mapcar (lambda (f)
14719 (if (file-directory-p f
)
14721 f t org-agenda-file-regexp
)
14724 (when org-agenda-skip-unavailable-files
14725 (setq files
(delq nil
14728 (and (file-readable-p file
) file
)))
14730 (when (or (eq archives t
)
14731 (and (eq archives
'ifmode
) (eq org-agenda-archives-mode t
)))
14732 (setq files
(org-add-archive-files files
)))
14735 (defun org-edit-agenda-file-list ()
14736 "Edit the list of agenda files.
14737 Depending on setup, this either uses customize to edit the variable
14738 `org-agenda-files', or it visits the file that is holding the list. In the
14739 latter case, the buffer is set up in a way that saving it automatically kills
14740 the buffer and restores the previous window configuration."
14742 (if (stringp org-agenda-files
)
14743 (let ((cw (current-window-configuration)))
14744 (find-file org-agenda-files
)
14745 (org-set-local 'org-window-configuration cw
)
14746 (org-add-hook 'after-save-hook
14748 (set-window-configuration
14749 (prog1 org-window-configuration
14750 (kill-buffer (current-buffer))))
14751 (org-install-agenda-files-menu)
14752 (message "New agenda file list installed"))
14754 (message "%s" (substitute-command-keys
14755 "Edit list and finish with \\[save-buffer]")))
14756 (customize-variable 'org-agenda-files
)))
14758 (defun org-store-new-agenda-file-list (list)
14759 "Set new value for the agenda file list and save it correctly."
14760 (if (stringp org-agenda-files
)
14761 (let ((fe (org-read-agenda-file-list t
)) b u
)
14762 (while (setq b
(find-buffer-visiting org-agenda-files
))
14764 (with-temp-file org-agenda-files
14767 (lambda (f) ;; Keep un-expanded entries.
14768 (if (setq u
(assoc f fe
))
14773 (let ((org-mode-hook nil
) (org-inhibit-startup t
)
14774 (org-insert-mode-line-in-empty-file nil
))
14775 (setq org-agenda-files list
)
14776 (customize-save-variable 'org-agenda-files org-agenda-files
))))
14778 (defun org-read-agenda-file-list (&optional pair-with-expansion
)
14779 "Read the list of agenda files from a file.
14780 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
14781 filenames, used by `org-store-new-agenda-file-list' to write back
14782 un-expanded file names."
14783 (when (file-directory-p org-agenda-files
)
14784 (error "`org-agenda-files' cannot be a single directory"))
14785 (when (stringp org-agenda-files
)
14787 (insert-file-contents org-agenda-files
)
14790 (let ((e (expand-file-name (substitute-in-file-name f
)
14792 (if pair-with-expansion
14795 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
14798 (defun org-cycle-agenda-files ()
14799 "Cycle through the files in `org-agenda-files'.
14800 If the current buffer visits an agenda file, find the next one in the list.
14801 If the current buffer does not, find the first agenda file."
14803 (let* ((fs (org-agenda-files t
))
14804 (files (append fs
(list (car fs
))))
14805 (tcf (if buffer-file-name
(file-truename buffer-file-name
)))
14807 (unless files
(error "No agenda files"))
14809 (while (setq file
(pop files
))
14810 (if (equal (file-truename file
) tcf
)
14812 (find-file (car files
))
14814 (find-file (car fs
)))
14815 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
14817 (defun org-agenda-file-to-front (&optional to-end
)
14818 "Move/add the current file to the top of the agenda file list.
14819 If the file is not present in the list, it is added to the front. If it is
14820 present, it is moved there. With optional argument TO-END, add/move to the
14823 (let ((org-agenda-skip-unavailable-files nil
)
14824 (file-alist (mapcar (lambda (x)
14825 (cons (file-truename x
) x
))
14826 (org-agenda-files t
)))
14827 (ctf (file-truename buffer-file-name
))
14829 (setq x
(assoc ctf file-alist
) had x
)
14831 (if (not x
) (setq x
(cons ctf
(abbreviate-file-name buffer-file-name
))))
14833 (setq file-alist
(append (delq x file-alist
) (list x
)))
14834 (setq file-alist
(cons x
(delq x file-alist
))))
14835 (org-store-new-agenda-file-list (mapcar 'cdr file-alist
))
14836 (org-install-agenda-files-menu)
14837 (message "File %s to %s of agenda file list"
14838 (if had
"moved" "added") (if to-end
"end" "front"))))
14840 (defun org-remove-file (&optional file
)
14841 "Remove current file from the list of files in variable `org-agenda-files'.
14842 These are the files which are being checked for agenda entries.
14843 Optional argument FILE means use this file instead of the current."
14845 (let* ((org-agenda-skip-unavailable-files nil
)
14846 (file (or file buffer-file-name
))
14847 (true-file (file-truename file
))
14848 (afile (abbreviate-file-name file
))
14849 (files (delq nil
(mapcar
14851 (if (equal true-file
14854 (org-agenda-files t
)))))
14855 (if (not (= (length files
) (length (org-agenda-files t
))))
14857 (org-store-new-agenda-file-list files
)
14858 (org-install-agenda-files-menu)
14859 (message "Removed file: %s" afile
))
14860 (message "File was not in list: %s (not removed)" afile
))))
14862 (defun org-file-menu-entry (file)
14863 (vector file
(list 'find-file file
) t
))
14865 (defun org-check-agenda-file (file)
14866 "Make sure FILE exists. If not, ask user what to do."
14867 (when (not (file-exists-p file
))
14868 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
14869 (abbreviate-file-name file
))
14870 (let ((r (downcase (read-char-exclusive))))
14873 (org-remove-file file
)
14874 (throw 'nextfile t
))
14875 (t (error "Abort"))))))
14877 (defun org-get-agenda-file-buffer (file)
14878 "Get a buffer visiting FILE. If the buffer needs to be created, add
14879 it to the list of buffers which might be released later."
14880 (let ((buf (org-find-base-buffer-visiting file
)))
14882 buf
; just return it
14883 ;; Make a new buffer and remember it
14884 (setq buf
(find-file-noselect file
))
14885 (if buf
(push buf org-agenda-new-buffers
))
14888 (defun org-release-buffers (blist)
14889 "Release all buffers in list, asking the user for confirmation when needed.
14890 When a buffer is unmodified, it is just killed. When modified, it is saved
14891 \(if the user agrees) and then killed."
14893 (while (setq buf
(pop blist
))
14894 (setq file
(buffer-file-name buf
))
14895 (when (and (buffer-modified-p buf
)
14897 (y-or-n-p (format "Save file %s? " file
)))
14898 (with-current-buffer buf
(save-buffer)))
14899 (kill-buffer buf
))))
14901 (defun org-prepare-agenda-buffers (files)
14902 "Create buffers for all agenda files, protect archived trees and comments."
14904 (let ((pa '(:org-archived t
))
14905 (pc '(:org-comment t
))
14906 (pall '(:org-archived t
:org-comment t
))
14907 (inhibit-read-only t
)
14908 (rea (concat ":" org-archive-tag
":"))
14912 (while (setq file
(pop files
))
14916 (org-check-agenda-file file
)
14917 (set-buffer (org-get-agenda-file-buffer file
)))
14919 (setq bmp
(buffer-modified-p))
14920 (org-refresh-category-properties)
14921 (setq org-todo-keywords-for-agenda
14922 (append org-todo-keywords-for-agenda org-todo-keywords-1
))
14923 (setq org-done-keywords-for-agenda
14924 (append org-done-keywords-for-agenda org-done-keywords
))
14925 (setq org-todo-keyword-alist-for-agenda
14926 (append org-todo-keyword-alist-for-agenda org-todo-key-alist
))
14927 (setq org-drawers-for-agenda
14928 (append org-drawers-for-agenda org-drawers
))
14929 (setq org-tag-alist-for-agenda
14930 (append org-tag-alist-for-agenda org-tag-alist
))
14933 (remove-text-properties (point-min) (point-max) pall
)
14934 (when org-agenda-skip-archived-trees
14935 (goto-char (point-min))
14936 (while (re-search-forward rea nil t
)
14937 (if (org-on-heading-p t
)
14938 (add-text-properties (point-at-bol) (org-end-of-subtree t
) pa
))))
14939 (goto-char (point-min))
14940 (setq re
(concat "^\\*+ +" org-comment-string
"\\>"))
14941 (while (re-search-forward re nil t
)
14942 (add-text-properties
14943 (match-beginning 0) (org-end-of-subtree t
) pc
)))
14944 (set-buffer-modified-p bmp
)))))
14945 (setq org-todo-keyword-alist-for-agenda
14946 (org-uniquify org-todo-keyword-alist-for-agenda
)
14947 org-tag-alist-for-agenda
(org-uniquify org-tag-alist-for-agenda
))))
14949 ;;;; Embedded LaTeX
14951 (defvar org-cdlatex-mode-map
(make-sparse-keymap)
14952 "Keymap for the minor `org-cdlatex-mode'.")
14954 (org-defkey org-cdlatex-mode-map
"_" 'org-cdlatex-underscore-caret
)
14955 (org-defkey org-cdlatex-mode-map
"^" 'org-cdlatex-underscore-caret
)
14956 (org-defkey org-cdlatex-mode-map
"`" 'cdlatex-math-symbol
)
14957 (org-defkey org-cdlatex-mode-map
"'" 'org-cdlatex-math-modify
)
14958 (org-defkey org-cdlatex-mode-map
"\C-c{" 'cdlatex-environment
)
14960 (defvar org-cdlatex-texmathp-advice-is-done nil
14961 "Flag remembering if we have applied the advice to texmathp already.")
14963 (define-minor-mode org-cdlatex-mode
14964 "Toggle the minor `org-cdlatex-mode'.
14965 This mode supports entering LaTeX environment and math in LaTeX fragments
14967 \\{org-cdlatex-mode-map}"
14969 (when org-cdlatex-mode
(require 'cdlatex
))
14970 (unless org-cdlatex-texmathp-advice-is-done
14971 (setq org-cdlatex-texmathp-advice-is-done t
)
14972 (defadvice texmathp
(around org-math-always-on activate
)
14973 "Always return t in org-mode buffers.
14974 This is because we want to insert math symbols without dollars even outside
14975 the LaTeX math segments. If Orgmode thinks that point is actually inside
14976 an embedded LaTeX fragment, let texmathp do its job.
14977 \\[org-cdlatex-mode-map]"
14981 ((not (org-mode-p)) ad-do-it
)
14982 ((eq this-command
'cdlatex-math-symbol
)
14983 (setq ad-return-value t
14984 texmathp-why
'("cdlatex-math-symbol in org-mode" .
0)))
14986 (let ((p (org-inside-LaTeX-fragment-p)))
14987 (if (and p
(member (car p
) (plist-get org-format-latex-options
:matchers
)))
14988 (setq ad-return-value t
14989 texmathp-why
'("Org-mode embedded math" .
0))
14990 (if p ad-do-it
)))))))))
14992 (defun turn-on-org-cdlatex ()
14993 "Unconditionally turn on `org-cdlatex-mode'."
14994 (org-cdlatex-mode 1))
14996 (defun org-inside-LaTeX-fragment-p ()
14997 "Test if point is inside a LaTeX fragment.
14998 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
14999 sequence appearing also before point.
15000 Even though the matchers for math are configurable, this function assumes
15001 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15002 delimiters are skipped when they have been removed by customization.
15003 The return value is nil, or a cons cell with the delimiter and
15004 and the position of this delimiter.
15006 This function does a reasonably good job, but can locally be fooled by
15007 for example currency specifications. For example it will assume being in
15008 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15009 fragments that are properly closed, but during editing, we have to live
15010 with the uncertainty caused by missing closing delimiters. This function
15011 looks only before point, not after."
15013 (let ((pos (point))
15014 (dodollar (member "$" (plist-get org-format-latex-options
:matchers
)))
15016 (re-search-backward (concat "^\\(" paragraph-start
"\\)") nil t
)
15018 dd-on str
(start 0) m re
)
15021 (setq str
(concat (buffer-substring lim
(point)) "\000 X$.")
15022 re
(nth 1 (assoc "$" org-latex-regexps
)))
15023 (while (string-match re str start
)
15025 ((= (match-end 0) (length str
))
15026 (throw 'exit
(cons "$" (+ lim
(match-beginning 0) 1))))
15027 ((= (match-end 0) (- (length str
) 5))
15029 (t (setq start
(match-end 0))))))
15030 (when (setq m
(re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t
))
15032 (and (match-beginning 1) (throw 'exit
(cons (match-string 1) m
)))
15033 (and (match-beginning 2) (throw 'exit nil
))
15035 (while (re-search-backward "\\$\\$" lim t
)
15036 (setq dd-on
(not dd-on
)))
15038 (if dd-on
(cons "$$" m
))))))
15040 (defun org-inside-latex-macro-p ()
15041 "Is point inside a LaTeX macro or its arguments?"
15044 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15048 (message "%s" (org-inside-latex-macro-p)))
15050 (defun org-try-cdlatex-tab ()
15051 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15052 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15053 - inside a LaTeX fragment, or
15054 - after the first word in a line, where an abbreviation expansion could
15055 insert a LaTeX environment."
15056 (when org-cdlatex-mode
15059 (skip-chars-backward "a-zA-Z0-9*")
15060 (skip-chars-backward " \t")
15063 ((org-inside-LaTeX-fragment-p)
15067 (defun org-cdlatex-underscore-caret (&optional arg
)
15068 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15069 Revert to the normal definition outside of these fragments."
15071 (if (org-inside-LaTeX-fragment-p)
15072 (call-interactively 'cdlatex-sub-superscript
)
15073 (let (org-cdlatex-mode)
15074 (call-interactively (key-binding (vector last-input-event
))))))
15076 (defun org-cdlatex-math-modify (&optional arg
)
15077 "Execute `cdlatex-math-modify' in LaTeX fragments.
15078 Revert to the normal definition outside of these fragments."
15080 (if (org-inside-LaTeX-fragment-p)
15081 (call-interactively 'cdlatex-math-modify
)
15082 (let (org-cdlatex-mode)
15083 (call-interactively (key-binding (vector last-input-event
))))))
15085 (defvar org-latex-fragment-image-overlays nil
15086 "List of overlays carrying the images of latex fragments.")
15087 (make-variable-buffer-local 'org-latex-fragment-image-overlays
)
15089 (defun org-remove-latex-fragment-image-overlays ()
15090 "Remove all overlays with LaTeX fragment images in current buffer."
15091 (mapc 'org-delete-overlay org-latex-fragment-image-overlays
)
15092 (setq org-latex-fragment-image-overlays nil
))
15094 (defun org-preview-latex-fragment (&optional subtree
)
15095 "Preview the LaTeX fragment at point, or all locally or globally.
15096 If the cursor is in a LaTeX fragment, create the image and overlay
15097 it over the source code. If there is no fragment at point, display
15098 all fragments in the current text, from one headline to the next. With
15099 prefix SUBTREE, display all fragments in the current subtree. With a
15100 double prefix `C-u C-u', or when the cursor is before the first headline,
15101 display all fragments in the buffer.
15102 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15104 (org-remove-latex-fragment-image-overlays)
15107 (let (beg end at msg
)
15109 ((or (equal subtree
'(16))
15110 (not (save-excursion
15111 (re-search-backward (concat "^" outline-regexp
) nil t
))))
15112 (setq beg
(point-min) end
(point-max)
15113 msg
"Creating images for buffer...%s"))
15114 ((equal subtree
'(4))
15115 (org-back-to-heading)
15116 (setq beg
(point) end
(org-end-of-subtree t
)
15117 msg
"Creating images for subtree...%s"))
15119 (if (setq at
(org-inside-LaTeX-fragment-p))
15120 (goto-char (max (point-min) (- (cdr at
) 2)))
15121 (org-back-to-heading))
15122 (setq beg
(point) end
(progn (outline-next-heading) (point))
15123 msg
(if at
"Creating image...%s"
15124 "Creating images for entry...%s"))))
15126 (narrow-to-region beg end
)
15129 (concat "ltxpng/" (file-name-sans-extension
15130 (file-name-nondirectory
15131 buffer-file-name
)))
15132 default-directory
'overlays msg at
'forbuffer
)
15133 (message msg
"done. Use `C-c C-c' to remove images.")))))
15135 (defvar org-latex-regexps
15136 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t
)
15137 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15138 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15139 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
15140 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
15141 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil
)
15142 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil
)
15143 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil
))
15144 "Regular expressions for matching embedded LaTeX.")
15146 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer
)
15147 "Replace LaTeX fragments with links to an image, and produce images.
15148 Some of the options can be changed using the variable
15149 `org-format-latex-options'."
15150 (if (and overlays
(fboundp 'clear-image-cache
)) (clear-image-cache))
15151 (let* ((prefixnodir (file-name-nondirectory prefix
))
15152 (absprefix (expand-file-name prefix dir
))
15153 (todir (file-name-directory absprefix
))
15154 (opt org-format-latex-options
)
15155 (matchers (plist-get opt
:matchers
))
15156 (re-list org-latex-regexps
)
15157 (org-format-latex-header-extra
15158 (plist-get (org-infile-export-plist) :latex-header-extra
))
15159 (cnt 0) txt hash link beg end re e checkdir
15160 executables-checked
15161 m n block linkfile movefile ov
)
15162 ;; Check the different regular expressions
15163 (while (setq e
(pop re-list
))
15164 (setq m
(car e
) re
(nth 1 e
) n
(nth 2 e
)
15165 block
(if (nth 3 e
) "\n\n" ""))
15166 (when (member m matchers
)
15167 (goto-char (point-min))
15168 (while (re-search-forward re nil t
)
15169 (when (and (or (not at
) (equal (cdr at
) (match-beginning n
)))
15170 (not (get-text-property (match-beginning n
)
15173 (not (eq (get-char-property (match-beginning n
)
15175 'org-latex-overlay
))))
15176 (setq txt
(match-string n
)
15177 beg
(match-beginning n
) end
(match-end n
)
15179 (let (print-length print-level
) ; make sure full list is printed
15180 (setq hash
(sha1 (prin1-to-string
15181 (list org-format-latex-header
15182 org-format-latex-header-extra
15183 org-export-latex-default-packages-alist
15184 org-export-latex-packages-alist
15185 org-format-latex-options
15187 linkfile
(format "%s_%s.png" prefix hash
)
15188 movefile
(format "%s_%s.png" absprefix hash
)))
15189 (setq link
(concat block
"[[file:" linkfile
"]]" block
))
15190 (if msg
(message msg cnt
))
15192 (unless checkdir
; make sure the directory exists
15194 (or (file-directory-p todir
) (make-directory todir
)))
15196 (unless executables-checked
15197 (org-check-external-command
15198 "latex" "needed to convert LaTeX fragments to images")
15199 (org-check-external-command
15200 "dvipng" "needed to convert LaTeX fragments to images")
15201 (setq executables-checked t
))
15203 (unless (file-exists-p movefile
)
15204 (org-create-formula-image
15205 txt movefile opt forbuffer
))
15209 (if (eq (org-overlay-get o
'org-overlay-type
)
15210 'org-latex-overlay
)
15211 (org-delete-overlay o
)))
15212 (org-overlays-in beg end
))
15213 (setq ov
(org-make-overlay beg end
))
15214 (org-overlay-put ov
'org-overlay-type
'org-latex-overlay
)
15215 (if (featurep 'xemacs
)
15217 (org-overlay-put ov
'invisible t
)
15220 (make-glyph (vector 'png
:file movefile
))))
15223 (list 'image
:type
'png
:file movefile
:ascent
'center
)))
15224 (push ov org-latex-fragment-image-overlays
)
15226 (delete-region beg end
)
15227 (insert (org-add-props link
15228 (list 'org-latex-src
15229 (replace-regexp-in-string "\"" "" txt
)))))))))))
15231 ;; This function borrows from Ganesh Swami's latex2png.el
15232 (defun org-create-formula-image (string tofile options buffer
)
15233 "This calls dvipng."
15234 (require 'org-latex
)
15235 (let* ((tmpdir (if (featurep 'xemacs
)
15237 temporary-file-directory
))
15238 (texfilebase (make-temp-name
15239 (expand-file-name "orgtex" tmpdir
)))
15240 (texfile (concat texfilebase
".tex"))
15241 (dvifile (concat texfilebase
".dvi"))
15242 (pngfile (concat texfilebase
".png"))
15243 (fnh (if (featurep 'xemacs
)
15244 (font-height (get-face-font 'default
))
15245 (face-attribute 'default
:height nil
)))
15246 (scale (or (plist-get options
(if buffer
:scale
:html-scale
)) 1.0))
15247 (dpi (number-to-string (* scale
(floor (* 0.9 (if buffer fnh
140.
))))))
15248 (fg (or (plist-get options
(if buffer
:foreground
:html-foreground
))
15250 (bg (or (plist-get options
(if buffer
:background
:html-background
))
15252 (if (eq fg
'default
) (setq fg
(org-dvipng-color :foreground
)))
15253 (if (eq bg
'default
) (setq bg
(org-dvipng-color :background
)))
15254 (with-temp-file texfile
15255 (insert org-format-latex-header
15256 (if (or org-export-latex-default-packages-alist
15257 org-export-latex-packages-alist
)
15259 (mapconcat (lambda(p)
15260 (if (equal "" (car p
))
15261 (format "\\usepackage{%s}" (cadr p
))
15262 (format "\\usepackage[%s]{%s}"
15263 (car p
) (cadr p
))))
15265 org-export-latex-default-packages-alist
15266 org-export-latex-packages-alist
)
15269 (if org-format-latex-header-extra
15270 (concat "\n" org-format-latex-header-extra
)
15272 "\n\\begin{document}\n" string
"\n\\end{document}\n")
15273 (org-export-latex-fix-inputenc))
15274 (let ((dir default-directory
))
15275 (condition-case nil
15278 (call-process "latex" nil nil nil texfile
))
15281 (if (not (file-exists-p dvifile
))
15282 (progn (message "Failed to create dvi file from %s" texfile
) nil
)
15283 (condition-case nil
15284 (call-process "dvipng" nil nil nil
15287 ;;"-x" scale "-y" scale
15292 (if (not (file-exists-p pngfile
))
15293 (if org-format-latex-signal-error
15294 (error "Failed to create png file from %s" texfile
)
15295 (message "Failed to create png file from %s" texfile
)
15297 ;; Use the requested file name and clean up
15298 (copy-file pngfile tofile
'replace
)
15299 (loop for e in
'(".dvi" ".tex" ".aux" ".log" ".png") do
15300 (delete-file (concat texfilebase e
)))
15303 (defun org-dvipng-color (attr)
15304 "Return an rgb color specification for dvipng."
15305 (apply 'format
"rgb %s %s %s"
15306 (mapcar 'org-normalize-color
15307 (color-values (face-attribute 'default attr nil
)))))
15309 (defun org-normalize-color (value)
15310 "Return string to be used as color value for an RGB component."
15311 (format "%g" (/ value
65535.0)))
15315 ;; Make `C-c C-x' a prefix key
15316 (org-defkey org-mode-map
"\C-c\C-x" (make-sparse-keymap))
15318 ;; TAB key with modifiers
15319 (org-defkey org-mode-map
"\C-i" 'org-cycle
)
15320 (org-defkey org-mode-map
[(tab)] 'org-cycle
)
15321 (org-defkey org-mode-map
[(control tab
)] 'org-force-cycle-archived
)
15322 (org-defkey org-mode-map
[(meta tab
)] 'org-complete
)
15323 (org-defkey org-mode-map
"\M-\t" 'org-complete
)
15324 (org-defkey org-mode-map
"\M-\C-i" 'org-complete
)
15325 ;; The following line is necessary under Suse GNU/Linux
15326 (unless (featurep 'xemacs
)
15327 (org-defkey org-mode-map
[S-iso-lefttab
] 'org-shifttab
))
15328 (org-defkey org-mode-map
[(shift tab
)] 'org-shifttab
)
15329 (define-key org-mode-map
[backtab] 'org-shifttab)
15331 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
15332 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
15333 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
15335 ;; Cursor keys with modifiers
15336 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
15337 (org-defkey org-mode-map [(meta right)] 'org-metaright)
15338 (org-defkey org-mode-map [(meta up)] 'org-metaup)
15339 (org-defkey org-mode-map [(meta down)] 'org-metadown)
15341 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
15342 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
15343 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
15344 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
15346 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
15347 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
15348 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
15349 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
15351 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
15352 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
15354 ;;; Extra keys for tty access.
15355 ;; We only set them when really needed because otherwise the
15356 ;; menus don't show the simple keys
15358 (when (or org-use-extra-keys
15359 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
15360 (not window-system))
15361 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
15362 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
15363 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
15364 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
15365 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
15366 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
15367 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
15368 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
15369 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
15370 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
15371 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
15372 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
15373 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
15374 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
15375 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
15376 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
15377 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
15378 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
15379 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
15380 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
15381 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
15382 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
15383 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
15384 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
15385 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
15386 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
15387 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
15388 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
15390 ;; All the other keys
15392 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
15393 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
15394 (if (boundp 'narrow-map)
15395 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
15396 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
15397 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
15398 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
15399 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
15400 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
15401 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
15402 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
15403 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
15404 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
15405 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
15406 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
15407 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
15408 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
15409 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
15410 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
15411 (org-defkey org-mode-map "\C-c\C-v" 'org-show-todo-tree)
15412 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
15413 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
15414 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
15415 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
15416 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
15417 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
15418 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
15419 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
15420 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
15421 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
15422 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
15423 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
15424 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
15425 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
15426 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
15427 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
15428 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
15429 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
15430 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
15431 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
15432 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
15433 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
15434 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
15435 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
15436 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
15437 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
15438 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
15439 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
15440 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
15441 (org-defkey org-mode-map "\C-c^" 'org-sort)
15442 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
15443 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
15444 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
15445 (org-defkey org-mode-map "\C-m" 'org-return)
15446 (org-defkey org-mode-map "\C-j" 'org-return-indent)
15447 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
15448 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
15449 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
15450 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
15451 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
15452 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
15453 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
15454 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
15455 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
15456 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
15457 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
15458 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
15459 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
15460 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
15461 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
15462 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
15463 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
15464 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
15465 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
15466 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
15468 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
15469 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
15470 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
15471 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
15473 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
15474 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
15475 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
15476 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
15477 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
15478 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
15479 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
15480 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
15481 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
15482 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
15483 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
15484 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
15485 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
15486 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
15487 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
15489 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
15490 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
15491 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
15492 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
15494 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
15496 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
15498 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
15499 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
15501 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
15504 (when (featurep 'xemacs)
15505 (org-defkey org-mode-map 'button3 'popup-mode-menu))
15508 (defconst org-speed-commands-default
15510 ("Outline Navigation")
15511 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
15512 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
15513 ("f" . (org-speed-move-safe 'org-forward-same-level))
15514 ("b" . (org-speed-move-safe 'org-backward-same-level))
15515 ("u" . (org-speed-move-safe 'outline-up-heading))
15517 ("g" . (org-refile t))
15518 ("Outline Visibility")
15520 ("C" . org-shifttab)
15521 (" " . org-display-outline-path)
15522 ("Outline Structure Editing")
15523 ("U" . org-shiftmetaup)
15524 ("D" . org-shiftmetadown)
15525 ("r" . org-metaright)
15526 ("l" . org-metaleft)
15527 ("R" . org-shiftmetaright)
15528 ("L" . org-shiftmetaleft)
15529 ("i" . (progn (forward-char 1) (call-interactively
15530 'org-insert-heading-respect-content)))
15533 ("a" . org-archive-subtree-default-with-confirmation)
15534 ("." . outline-mark-subtree)
15536 ("I" . org-clock-in)
15537 ("O" . org-clock-out)
15538 ("Meta Data Editing")
15540 ("0" . (org-priority ?\ ))
15541 ("1" . (org-priority ?A))
15542 ("2" . (org-priority ?B))
15543 ("3" . (org-priority ?C))
15544 (";" . org-set-tags-command)
15545 ("e" . org-set-effort)
15546 ("Agenda Views etc")
15548 ("/" . org-sparse-tree)
15550 ("o" . org-open-at-point)
15551 ("?" . org-speed-command-help)
15553 "The default speed commands.")
15555 (defun org-print-speed-command (e)
15556 (if (> (length (car e)) 1)
15561 (princ (make-string (length (car e)) ?-))
15565 (if (symbolp (cdr e))
15566 (princ (symbol-name (cdr e)))
15570 (defun org-speed-command-help ()
15571 "Show the available speed commands."
15573 (if (not org-use-speed-commands)
15574 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
15575 (with-output-to-temp-buffer "*Help*"
15576 (princ "User-defined Speed commands\n===========================\n")
15577 (mapc 'org-print-speed-command org-speed-commands-user)
15579 (princ "Built-in Speed commands\n=======================\n")
15580 (mapc 'org-print-speed-command org-speed-commands-default))
15581 (with-current-buffer "*Help*"
15582 (setq truncate-lines t))))
15584 (defun org-speed-move-safe (cmd)
15585 "Execute CMD, but make sure that the cursor always ends up in a headline.
15586 If not, return to the original position and throw an error."
15588 (let ((pos (point)))
15589 (call-interactively cmd)
15590 (unless (and (bolp) (org-on-heading-p))
15592 (error "Boundary reached while executing %s" cmd))))
15594 (defvar org-self-insert-command-undo-counter 0)
15596 (defvar org-table-auto-blank-field) ; defined in org-table.el
15597 (defvar org-speed-command nil)
15598 (defun org-self-insert-command (N)
15599 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
15600 If the cursor is in a table looking at whitespace, the whitespace is
15601 overwritten, and the table is not marked as requiring realignment."
15604 ((and org-use-speed-commands
15605 (or (and (bolp) (looking-at outline-regexp))
15606 (and (functionp org-use-speed-commands)
15607 (funcall org-use-speed-commands)))
15610 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
15611 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
15613 ((commandp org-speed-command)
15614 (setq this-command org-speed-command)
15615 (call-interactively org-speed-command))
15616 ((functionp org-speed-command)
15617 (funcall org-speed-command))
15618 ((and org-speed-command (listp org-speed-command))
15619 (eval org-speed-command))
15620 (t (let (org-use-speed-commands)
15621 (call-interactively 'org-self-insert-command)))))
15625 ;; check if we blank the field, and if that triggers align
15626 (and (featurep 'org-table) org-table-auto-blank-field
15627 (member last-command
15628 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
15629 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
15630 ;; got extra space, this field does not determine column width
15631 (let (org-table-may-need-update) (org-table-blank-field))
15632 ;; no extra space, this field may determine column width
15633 (org-table-blank-field)))
15636 (looking-at "[^|\n]* |"))
15637 (let (org-table-may-need-update)
15638 (goto-char (1- (match-end 0)))
15639 (delete-backward-char 1)
15640 (goto-char (match-beginning 0))
15641 (self-insert-command N)))
15643 (setq org-table-may-need-update t)
15644 (self-insert-command N)
15645 (org-fix-tags-on-the-fly)
15646 (if org-self-insert-cluster-for-undo
15647 (if (not (eq last-command 'org-self-insert-command))
15648 (setq org-self-insert-command-undo-counter 1)
15649 (if (>= org-self-insert-command-undo-counter 20)
15650 (setq org-self-insert-command-undo-counter 1)
15651 (and (> org-self-insert-command-undo-counter 0)
15653 (not (cadr buffer-undo-list)) ; remove nil entry
15654 (setcdr buffer-undo-list (cddr buffer-undo-list)))
15655 (setq org-self-insert-command-undo-counter
15656 (1+ org-self-insert-command-undo-counter))))))))
15658 (defun org-fix-tags-on-the-fly ()
15659 (when (and (equal (char-after (point-at-bol)) ?*)
15660 (org-on-heading-p))
15661 (org-align-tags-here org-tags-column)))
15663 (defun org-delete-backward-char (N)
15664 "Like `delete-backward-char', insert whitespace at field end in tables.
15665 When deleting backwards, in tables this function will insert whitespace in
15666 front of the next \"|\" separator, to keep the table aligned. The table will
15667 still be marked for re-alignment if the field did fill the entire column,
15668 because, in this case the deletion might narrow the column."
15670 (if (and (org-table-p)
15672 (string-match "|" (buffer-substring (point-at-bol) (point)))
15673 (looking-at ".*?|"))
15674 (let ((pos (point))
15675 (noalign (looking-at "[^|\n\r]* |"))
15676 (c org-table-may-need-update))
15677 (backward-delete-char N)
15678 (skip-chars-forward "^|")
15680 (goto-char (1- pos))
15681 ;; noalign: if there were two spaces at the end, this field
15682 ;; does not determine the width of the column.
15683 (if noalign (setq org-table-may-need-update c)))
15684 (backward-delete-char N)
15685 (org-fix-tags-on-the-fly)))
15687 (defun org-delete-char (N)
15688 "Like `delete-char', but insert whitespace at field end in tables.
15689 When deleting characters, in tables this function will insert whitespace in
15690 front of the next \"|\" separator, to keep the table aligned. The table will
15691 still be marked for re-alignment if the field did fill the entire column,
15692 because, in this case the deletion might narrow the column."
15694 (if (and (org-table-p)
15696 (not (= (char-after) ?|))
15698 (if (looking-at ".*?|")
15699 (let ((pos (point))
15700 (noalign (looking-at "[^|\n\r]* |"))
15701 (c org-table-may-need-update))
15702 (replace-match (concat
15703 (substring (match-string 0) 1 -1)
15706 ;; noalign: if there were two spaces at the end, this field
15707 ;; does not determine the width of the column.
15708 (if noalign (setq org-table-may-need-update c)))
15711 (org-fix-tags-on-the-fly)))
15713 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
15714 (put 'org-self-insert-command 'delete-selection t)
15715 (put 'orgtbl-self-insert-command 'delete-selection t)
15716 (put 'org-delete-char 'delete-selection 'supersede)
15717 (put 'org-delete-backward-char 'delete-selection 'supersede)
15718 (put 'org-yank 'delete-selection 'yank)
15720 ;; Make `flyspell-mode' delay after some commands
15721 (put 'org-self-insert-command 'flyspell-delayed t)
15722 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
15723 (put 'org-delete-char 'flyspell-delayed t)
15724 (put 'org-delete-backward-char 'flyspell-delayed t)
15726 ;; Make pabbrev-mode expand after org-mode commands
15727 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
15728 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
15730 ;; How to do this: Measure non-white length of current string
15731 ;; If equal to column width, we should realign.
15733 (defun org-remap (map &rest commands)
15734 "In MAP, remap the functions given in COMMANDS.
15735 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
15738 (setq old (pop commands) new (pop commands))
15739 (if (fboundp 'command-remapping)
15740 (org-defkey map (vector 'remap old) new)
15741 (substitute-key-definition old new map global-map)))))
15743 (when (eq org-enable-table-editor 'optimized)
15744 ;; If the user wants maximum table support, we need to hijack
15745 ;; some standard editing functions
15746 (org-remap org-mode-map
15747 'self-insert-command 'org-self-insert-command
15748 'delete-char 'org-delete-char
15749 'delete-backward-char 'org-delete-backward-char)
15750 (org-defkey org-mode-map "|" 'org-force-self-insert))
15752 (defvar org-ctrl-c-ctrl-c-hook nil
15753 "Hook for functions attaching themselves to `C-c C-c'.
15754 This can be used to add additional functionality to the C-c C-c key which
15755 executes context-dependent commands.
15756 Each function will be called with no arguments. The function must check
15757 if the context is appropriate for it to act. If yes, it should do its
15758 thing and then return a non-nil value. If the context is wrong,
15759 just do nothing and return nil.")
15761 (defvar org-tab-first-hook nil
15762 "Hook for functions to attach themselves to TAB.
15763 See `org-ctrl-c-ctrl-c-hook' for more information.
15764 This hook runs as the first action when TAB is pressed, even before
15765 `org-cycle' messes around with the `outline-regexp' to cater for
15766 inline tasks and plain list item folding.
15767 If any function in this hook returns t, not other actions like table
15768 field motion visibility cycling will be done.")
15770 (defvar org-tab-after-check-for-table-hook nil
15771 "Hook for functions to attach themselves to TAB.
15772 See `org-ctrl-c-ctrl-c-hook' for more information.
15773 This hook runs after it has been established that the cursor is not in a
15774 table, but before checking if the cursor is in a headline or if global cycling
15776 If any function in this hook returns t, not other actions like visibility
15777 cycling will be done.")
15779 (defvar org-tab-after-check-for-cycling-hook nil
15780 "Hook for functions to attach themselves to TAB.
15781 See `org-ctrl-c-ctrl-c-hook' for more information.
15782 This hook runs after it has been established that not table field motion and
15783 not visibility should be done because of current context. This is probably
15784 the place where a package like yasnippets can hook in.")
15786 (defvar org-tab-before-tab-emulation-hook nil
15787 "Hook for functions to attach themselves to TAB.
15788 See `org-ctrl-c-ctrl-c-hook' for more information.
15789 This hook runs after every other options for TAB have been exhausted, but
15790 before indentation and \t insertion takes place.")
15792 (defvar org-metaleft-hook nil
15793 "Hook for functions attaching themselves to `M-left'.
15794 See `org-ctrl-c-ctrl-c-hook' for more information.")
15795 (defvar org-metaright-hook nil
15796 "Hook for functions attaching themselves to `M-right'.
15797 See `org-ctrl-c-ctrl-c-hook' for more information.")
15798 (defvar org-metaup-hook nil
15799 "Hook for functions attaching themselves to `M-up'.
15800 See `org-ctrl-c-ctrl-c-hook' for more information.")
15801 (defvar org-metadown-hook nil
15802 "Hook for functions attaching themselves to `M-down'.
15803 See `org-ctrl-c-ctrl-c-hook' for more information.")
15804 (defvar org-shiftmetaleft-hook nil
15805 "Hook for functions attaching themselves to `M-S-left'.
15806 See `org-ctrl-c-ctrl-c-hook' for more information.")
15807 (defvar org-shiftmetaright-hook nil
15808 "Hook for functions attaching themselves to `M-S-right'.
15809 See `org-ctrl-c-ctrl-c-hook' for more information.")
15810 (defvar org-shiftmetaup-hook nil
15811 "Hook for functions attaching themselves to `M-S-up'.
15812 See `org-ctrl-c-ctrl-c-hook' for more information.")
15813 (defvar org-shiftmetadown-hook nil
15814 "Hook for functions attaching themselves to `M-S-down'.
15815 See `org-ctrl-c-ctrl-c-hook' for more information.")
15816 (defvar org-metareturn-hook nil
15817 "Hook for functions attaching themselves to `M-RET'.
15818 See `org-ctrl-c-ctrl-c-hook' for more information.")
15820 (defun org-modifier-cursor-error ()
15821 "Throw an error, a modified cursor command was applied in wrong context."
15822 (error "This command is active in special context like tables, headlines or items"))
15824 (defun org-shiftselect-error ()
15825 "Throw an error because Shift-Cursor command was applied in wrong context."
15826 (if (and (boundp 'shift-select-mode) shift-select-mode)
15827 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
15828 (error "This command works only in special context like headlines or timestamps")))
15830 (defun org-call-for-shift-select (cmd)
15831 (let ((this-command-keys-shift-translated t))
15832 (call-interactively cmd)))
15834 (defun org-shifttab (&optional arg)
15835 "Global visibility cycling or move to previous table field.
15836 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
15838 See the individual commands for more information."
15841 ((org-at-table-p) (call-interactively 'org-table-previous-field))
15843 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
15844 (message "Content view to level: %d" arg)
15845 (org-content (prefix-numeric-value arg2))
15846 (setq org-cycle-global-status 'overview)))
15847 (t (call-interactively 'org-global-cycle))))
15849 (defun org-shiftmetaleft ()
15850 "Promote subtree or delete table column.
15851 Calls `org-promote-subtree', `org-outdent-item',
15852 or `org-table-delete-column', depending on context.
15853 See the individual commands for more information."
15856 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
15857 ((org-at-table-p) (call-interactively 'org-table-delete-column))
15858 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
15859 ((org-at-item-p) (call-interactively 'org-outdent-item))
15860 (t (org-modifier-cursor-error))))
15862 (defun org-shiftmetaright ()
15863 "Demote subtree or insert table column.
15864 Calls `org-demote-subtree', `org-indent-item',
15865 or `org-table-insert-column', depending on context.
15866 See the individual commands for more information."
15869 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
15870 ((org-at-table-p) (call-interactively 'org-table-insert-column))
15871 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
15872 ((org-at-item-p) (call-interactively 'org-indent-item))
15873 (t (org-modifier-cursor-error))))
15875 (defun org-shiftmetaup (&optional arg)
15876 "Move subtree up or kill table row.
15877 Calls `org-move-subtree-up' or `org-table-kill-row' or
15878 `org-move-item-up' depending on context. See the individual commands
15879 for more information."
15882 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
15883 ((org-at-table-p) (call-interactively 'org-table-kill-row))
15884 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
15885 ((org-at-item-p) (call-interactively 'org-move-item-up))
15886 (t (org-modifier-cursor-error))))
15888 (defun org-shiftmetadown (&optional arg)
15889 "Move subtree down or insert table row.
15890 Calls `org-move-subtree-down' or `org-table-insert-row' or
15891 `org-move-item-down', depending on context. See the individual
15892 commands for more information."
15895 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
15896 ((org-at-table-p) (call-interactively 'org-table-insert-row))
15897 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
15898 ((org-at-item-p) (call-interactively 'org-move-item-down))
15899 (t (org-modifier-cursor-error))))
15901 (defun org-metaleft (&optional arg)
15902 "Promote heading or move table column to left.
15903 Calls `org-do-promote' or `org-table-move-column', depending on context.
15904 With no specific context, calls the Emacs default `backward-word'.
15905 See the individual commands for more information."
15908 ((run-hook-with-args-until-success 'org-metaleft-hook))
15909 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
15910 ((or (org-on-heading-p)
15911 (and (org-region-active-p)
15913 (goto-char (region-beginning))
15914 (org-on-heading-p))))
15915 (call-interactively 'org-do-promote))
15916 ((or (org-at-item-p)
15917 (and (org-region-active-p)
15919 (goto-char (region-beginning))
15921 (call-interactively 'org-outdent-item))
15922 (t (call-interactively 'backward-word))))
15924 (defun org-metaright (&optional arg)
15925 "Demote subtree or move table column to right.
15926 Calls `org-do-demote' or `org-table-move-column', depending on context.
15927 With no specific context, calls the Emacs default `forward-word'.
15928 See the individual commands for more information."
15931 ((run-hook-with-args-until-success 'org-metaright-hook))
15932 ((org-at-table-p) (call-interactively 'org-table-move-column))
15933 ((or (org-on-heading-p)
15934 (and (org-region-active-p)
15936 (goto-char (region-beginning))
15937 (org-on-heading-p))))
15938 (call-interactively 'org-do-demote))
15939 ((or (org-at-item-p)
15940 (and (org-region-active-p)
15942 (goto-char (region-beginning))
15944 (call-interactively 'org-indent-item))
15945 (t (call-interactively 'forward-word))))
15947 (defun org-metaup (&optional arg)
15948 "Move subtree up or move table row up.
15949 Calls `org-move-subtree-up' or `org-table-move-row' or
15950 `org-move-item-up', depending on context. See the individual commands
15951 for more information."
15954 ((run-hook-with-args-until-success 'org-metaup-hook))
15955 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
15956 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
15957 ((org-at-item-p) (call-interactively 'org-move-item-up))
15958 (t (transpose-lines 1) (beginning-of-line -1))))
15960 (defun org-metadown (&optional arg)
15961 "Move subtree down or move table row down.
15962 Calls `org-move-subtree-down' or `org-table-move-row' or
15963 `org-move-item-down', depending on context. See the individual
15964 commands for more information."
15967 ((run-hook-with-args-until-success 'org-metadown-hook))
15968 ((org-at-table-p) (call-interactively 'org-table-move-row))
15969 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
15970 ((org-at-item-p) (call-interactively 'org-move-item-down))
15971 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
15973 (defun org-shiftup (&optional arg)
15974 "Increase item in timestamp or increase priority of current headline.
15975 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
15976 depending on context. See the individual commands for more information."
15979 ((and org-support-shift-select (org-region-active-p))
15980 (org-call-for-shift-select 'previous-line))
15981 ((org-at-timestamp-p t)
15982 (call-interactively (if org-edit-timestamp-down-means-later
15983 'org-timestamp-down 'org-timestamp-up)))
15984 ((and (not (eq org-support-shift-select 'always))
15985 org-enable-priority-commands
15986 (org-on-heading-p))
15987 (call-interactively 'org-priority-up))
15988 ((and (not org-support-shift-select) (org-at-item-p))
15989 (call-interactively 'org-previous-item))
15990 ((org-clocktable-try-shift 'up arg))
15991 (org-support-shift-select
15992 (org-call-for-shift-select 'previous-line))
15993 (t (org-shiftselect-error))))
15995 (defun org-shiftdown (&optional arg)
15996 "Decrease item in timestamp or decrease priority of current headline.
15997 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
15998 depending on context. See the individual commands for more information."
16001 ((and org-support-shift-select (org-region-active-p))
16002 (org-call-for-shift-select 'next-line))
16003 ((org-at-timestamp-p t)
16004 (call-interactively (if org-edit-timestamp-down-means-later
16005 'org-timestamp-up 'org-timestamp-down)))
16006 ((and (not (eq org-support-shift-select 'always))
16007 org-enable-priority-commands
16008 (org-on-heading-p))
16009 (call-interactively 'org-priority-down))
16010 ((and (not org-support-shift-select) (org-at-item-p))
16011 (call-interactively 'org-next-item))
16012 ((org-clocktable-try-shift 'down arg))
16013 (org-support-shift-select
16014 (org-call-for-shift-select 'next-line))
16015 (t (org-shiftselect-error))))
16017 (defun org-shiftright (&optional arg)
16018 "Cycle the thing at point or in the current line, depending on context.
16019 Depending on context, this does one of the following:
16021 - switch a timestamp at point one day into the future
16022 - on a headline, switch to the next TODO keyword.
16023 - on an item, switch entire list to the next bullet type
16024 - on a property line, switch to the next allowed value
16025 - on a clocktable definition line, move time block into the future"
16028 ((and org-support-shift-select (org-region-active-p))
16029 (org-call-for-shift-select 'forward-char))
16030 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16031 ((and (not (eq org-support-shift-select 'always))
16032 (org-on-heading-p))
16033 (let ((org-inhibit-logging
16034 (not org-treat-S-cursor-todo-selection-as-state-change))
16035 (org-inhibit-blocking
16036 (not org-treat-S-cursor-todo-selection-as-state-change)))
16037 (org-call-with-arg 'org-todo 'right)))
16038 ((or (and org-support-shift-select
16039 (not (eq org-support-shift-select 'always))
16040 (org-at-item-bullet-p))
16041 (and (not org-support-shift-select) (org-at-item-p)))
16042 (org-call-with-arg 'org-cycle-list-bullet nil))
16043 ((and (not (eq org-support-shift-select 'always))
16044 (org-at-property-p))
16045 (call-interactively 'org-property-next-allowed-value))
16046 ((org-clocktable-try-shift 'right arg))
16047 (org-support-shift-select
16048 (org-call-for-shift-select 'forward-char))
16049 (t (org-shiftselect-error))))
16051 (defun org-shiftleft (&optional arg)
16052 "Cycle the thing at point or in the current line, depending on context.
16053 Depending on context, this does one of the following:
16055 - switch a timestamp at point one day into the past
16056 - on a headline, switch to the previous TODO keyword.
16057 - on an item, switch entire list to the previous bullet type
16058 - on a property line, switch to the previous allowed value
16059 - on a clocktable definition line, move time block into the past"
16062 ((and org-support-shift-select (org-region-active-p))
16063 (org-call-for-shift-select 'backward-char))
16064 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16065 ((and (not (eq org-support-shift-select 'always))
16066 (org-on-heading-p))
16067 (let ((org-inhibit-logging
16068 (not org-treat-S-cursor-todo-selection-as-state-change))
16069 (org-inhibit-blocking
16070 (not org-treat-S-cursor-todo-selection-as-state-change)))
16071 (org-call-with-arg 'org-todo 'left)))
16072 ((or (and org-support-shift-select
16073 (not (eq org-support-shift-select 'always))
16074 (org-at-item-bullet-p))
16075 (and (not org-support-shift-select) (org-at-item-p)))
16076 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16077 ((and (not (eq org-support-shift-select 'always))
16078 (org-at-property-p))
16079 (call-interactively 'org-property-previous-allowed-value))
16080 ((org-clocktable-try-shift 'left arg))
16081 (org-support-shift-select
16082 (org-call-for-shift-select 'backward-char))
16083 (t (org-shiftselect-error))))
16085 (defun org-shiftcontrolright ()
16086 "Switch to next TODO set."
16089 ((and org-support-shift-select (org-region-active-p))
16090 (org-call-for-shift-select 'forward-word))
16091 ((and (not (eq org-support-shift-select 'always))
16092 (org-on-heading-p))
16093 (org-call-with-arg 'org-todo 'nextset))
16094 (org-support-shift-select
16095 (org-call-for-shift-select 'forward-word))
16096 (t (org-shiftselect-error))))
16098 (defun org-shiftcontrolleft ()
16099 "Switch to previous TODO set."
16102 ((and org-support-shift-select (org-region-active-p))
16103 (org-call-for-shift-select 'backward-word))
16104 ((and (not (eq org-support-shift-select 'always))
16105 (org-on-heading-p))
16106 (org-call-with-arg 'org-todo 'previousset))
16107 (org-support-shift-select
16108 (org-call-for-shift-select 'backward-word))
16109 (t (org-shiftselect-error))))
16111 (defun org-ctrl-c-ret ()
16112 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16115 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16116 (t (call-interactively 'org-insert-heading))))
16118 (defun org-copy-special ()
16119 "Copy region in table or copy current subtree.
16120 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16121 See the individual commands for more information."
16123 (call-interactively
16124 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16126 (defun org-cut-special ()
16127 "Cut region in table or cut current subtree.
16128 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16129 See the individual commands for more information."
16131 (call-interactively
16132 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16134 (defun org-paste-special (arg)
16135 "Paste rectangular region into table, or past subtree relative to level.
16136 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16137 See the individual commands for more information."
16139 (if (org-at-table-p)
16140 (org-table-paste-rectangle)
16141 (org-paste-subtree arg)))
16143 (defun org-edit-special ()
16144 "Call a special editor for the stuff at point.
16145 When at a table, call the formula editor with `org-table-edit-formulas'.
16146 When at the first line of an src example, call `org-edit-src-code'.
16147 When in an #+include line, visit the include file. Otherwise call
16148 `ffap' to visit the file at point."
16151 ((org-at-table.el-p)
16152 (org-edit-src-code))
16154 (call-interactively 'org-table-edit-formulas))
16156 (beginning-of-line 1)
16157 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16158 (find-file (org-trim (match-string 1))))
16159 ((org-edit-src-code))
16160 ((org-edit-fixed-width-region))
16161 (t (call-interactively 'ffap))))
16164 (defun org-ctrl-c-ctrl-c (&optional arg)
16165 "Set tags in headline, or update according to changed information at point.
16167 This command does many different things, depending on context:
16169 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
16170 this is what we do.
16172 - If the cursor is on a statistics cookie, update it.
16174 - If the cursor is in a headline, prompt for tags and insert them
16175 into the current line, aligned to `org-tags-column'. When called
16176 with prefix arg, realign all tags in the current buffer.
16178 - If the cursor is in one of the special #+KEYWORD lines, this
16179 triggers scanning the buffer for these lines and updating the
16182 - If the cursor is inside a table, realign the table. This command
16183 works even if the automatic table editor has been turned off.
16185 - If the cursor is on a #+TBLFM line, re-apply the formulas to
16188 - If the cursor is at a footnote reference or definition, jump to
16189 the corresponding definition or references, respectively.
16191 - If the cursor is a the beginning of a dynamic block, update it.
16193 - If the current buffer is a remember buffer, close note and file
16194 it. A prefix argument of 1 files to the default location
16195 without further interaction. A prefix argument of 2 files to
16196 the currently clocking task.
16198 - If the cursor is on a <<<target>>>, update radio targets and corresponding
16199 links in this buffer.
16201 - If the cursor is on a numbered item in a plain list, renumber the
16204 - If the cursor is on a checkbox, toggle it."
16206 (let ((org-enable-table-editor t))
16208 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
16209 org-occur-highlights
16210 org-latex-fragment-image-overlays)
16211 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
16212 (org-remove-occur-highlights)
16213 (org-remove-latex-fragment-image-overlays)
16214 (message "Temporary highlights/overlays removed from current buffer"))
16215 ((and (local-variable-p 'org-finish-function (current-buffer))
16216 (fboundp org-finish-function))
16217 (funcall org-finish-function))
16218 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
16219 ((or (looking-at (org-re org-property-start-re))
16220 (org-at-property-p))
16221 (call-interactively 'org-property-action))
16222 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
16223 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
16224 (or (org-on-heading-p) (org-at-item-p)))
16225 (call-interactively 'org-update-statistics-cookies))
16226 ((org-on-heading-p) (call-interactively 'org-set-tags))
16227 ((org-at-table.el-p)
16228 (message "Use C-c ' to edit table.el tables"))
16230 (org-table-maybe-eval-formula)
16232 (call-interactively 'org-table-recalculate)
16233 (org-table-maybe-recalculate-line))
16234 (call-interactively 'org-table-align))
16235 ((or (org-footnote-at-reference-p)
16236 (org-footnote-at-definition-p))
16237 (call-interactively 'org-footnote-action))
16238 ((org-at-item-checkbox-p)
16239 (call-interactively 'org-toggle-checkbox))
16242 (call-interactively 'org-toggle-checkbox)
16243 (call-interactively 'org-maybe-renumber-ordered-list)))
16244 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
16246 (beginning-of-line 1)
16247 (save-excursion (org-update-dblock)))
16249 (beginning-of-line 1)
16250 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
16252 ((equal (match-string 1) "TBLFM")
16253 ;; Recalculate the table before this line
16255 (beginning-of-line 1)
16256 (skip-chars-backward " \r\n\t")
16257 (if (org-at-table-p)
16258 (org-call-with-arg 'org-table-recalculate (or arg t)))))
16260 (let ((org-inhibit-startup-visibility-stuff t)
16261 (org-startup-align-all-tables nil))
16262 (org-save-outline-visibility 'use-markers (org-mode-restart)))
16263 (message "Local setup has been refreshed"))))
16264 ((org-clock-update-time-maybe))
16265 (t (error "C-c C-c can do nothing useful at this location")))))
16267 (defun org-mode-restart ()
16268 "Restart Org-mode, to scan again for special lines.
16269 Also updates the keyword regular expressions."
16272 (message "Org-mode restarted"))
16274 (defun org-kill-note-or-show-branches ()
16275 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
16277 (if (not org-finish-function)
16278 (call-interactively 'show-branches)
16279 (let ((org-note-abort t))
16280 (funcall org-finish-function))))
16282 (defun org-return (&optional indent)
16283 "Goto next table row or insert a newline.
16284 Calls `org-table-next-row' or `newline', depending on context.
16285 See the individual commands for more information."
16288 ((bobp) (if indent (newline-and-indent) (newline)))
16290 (org-table-justify-field-maybe)
16291 (call-interactively 'org-table-next-row))
16292 ((and org-return-follows-link
16293 (eq (get-text-property (point) 'face) 'org-link))
16294 (call-interactively 'org-open-at-point))
16295 ((and (org-at-heading-p)
16297 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
16301 (t (if indent (newline-and-indent) (newline)))))
16303 (defun org-return-indent ()
16304 "Goto next table row or insert a newline and indent.
16305 Calls `org-table-next-row' or `newline-and-indent', depending on
16306 context. See the individual commands for more information."
16310 (defun org-ctrl-c-star ()
16311 "Compute table, or change heading status of lines.
16312 Calls `org-table-recalculate' or `org-toggle-heading',
16313 depending on context."
16317 (call-interactively 'org-table-recalculate))
16319 ;; Convert all lines in region to list items
16320 (call-interactively 'org-toggle-heading))))
16322 (defun org-ctrl-c-minus ()
16323 "Insert separator line in table or modify bullet status of line.
16324 Also turns a plain line or a region of lines into list items.
16325 Calls `org-table-insert-hline', `org-toggle-item', or
16326 `org-cycle-list-bullet', depending on context."
16330 (call-interactively 'org-table-insert-hline))
16331 ((org-region-active-p)
16332 (call-interactively 'org-toggle-item))
16334 (call-interactively 'org-cycle-list-bullet))
16336 (call-interactively 'org-toggle-item))))
16338 (defun org-toggle-item ()
16339 "Convert headings or normal lines to items, items to normal lines.
16340 If there is no active region, only the current line is considered.
16342 If the first line in the region is a headline, convert all headlines to items.
16344 If the first line in the region is an item, convert all items to normal lines.
16346 If the first line is normal text, add an item bullet to each line."
16348 (let (l2 l beg end)
16349 (if (org-region-active-p)
16350 (setq beg (region-beginning) end (region-end))
16351 (setq beg (point-at-bol)
16352 end (min (1+ (point-at-eol)) (point-max))))
16355 (setq l2 (org-current-line))
16357 (beginning-of-line 1)
16358 (setq l (1- (org-current-line)))
16359 (if (org-at-item-p)
16360 ;; We already have items, de-itemize
16361 (while (< (setq l (1+ l)) l2)
16362 (when (org-at-item-p)
16363 (goto-char (match-beginning 2))
16364 (delete-region (match-beginning 2) (match-end 2))
16365 (and (looking-at "[ \t]+") (replace-match "")))
16366 (beginning-of-line 2))
16367 (if (org-on-heading-p)
16368 ;; Headings, convert to items
16369 (while (< (setq l (1+ l)) l2)
16370 (if (looking-at org-outline-regexp)
16371 (replace-match "- " t t))
16372 (beginning-of-line 2))
16373 ;; normal lines, turn them into items
16374 (while (< (setq l (1+ l)) l2)
16375 (unless (org-at-item-p)
16376 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16377 (replace-match "\\1- \\2")))
16378 (beginning-of-line 2)))))))
16380 (defun org-toggle-heading (&optional nstars)
16381 "Convert headings to normal text, or items or text to headings.
16382 If there is no active region, only the current line is considered.
16384 If the first line is a heading, remove the stars from all headlines
16387 If the first line is a plain list item, turn all plain list items
16390 If the first line is a normal line, turn each and every line in the
16391 region into a heading.
16393 When converting a line into a heading, the number of stars is chosen
16394 such that the lines become children of the current entry. However,
16395 when a prefix argument is given, its value determines the number of
16398 (let (l2 l itemp beg end)
16399 (if (org-region-active-p)
16400 (setq beg (region-beginning) end (region-end))
16401 (setq beg (point-at-bol)
16402 end (min (1+ (point-at-eol)) (point-max))))
16405 (setq l2 (org-current-line))
16407 (beginning-of-line 1)
16408 (setq l (1- (org-current-line)))
16409 (if (org-on-heading-p)
16410 ;; We already have headlines, de-star them
16411 (while (< (setq l (1+ l)) l2)
16412 (when (org-on-heading-p t)
16413 (and (looking-at outline-regexp) (replace-match "")))
16414 (beginning-of-line 2))
16415 (setq itemp (org-at-item-p))
16418 (make-string (prefix-numeric-value current-prefix-arg)
16421 (if (re-search-backward org-complex-heading-regexp nil t)
16422 (match-string 1) ""))))
16423 (add-stars (cond (nstars "")
16424 ((equal stars "") "*")
16425 (org-odd-levels-only "**")
16427 (rpl (concat stars add-stars " ")))
16428 (while (< (setq l (1+ l)) l2)
16430 (and (org-at-item-p) (replace-match rpl t t))
16431 (unless (org-on-heading-p)
16432 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16433 (replace-match (concat rpl (match-string 2))))))
16434 (beginning-of-line 2)))))))
16436 (defun org-meta-return (&optional arg)
16437 "Insert a new heading or wrap a region in a table.
16438 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
16439 See the individual commands for more information."
16442 ((run-hook-with-args-until-success 'org-metareturn-hook))
16444 (call-interactively 'org-table-wrap-region))
16445 (t (call-interactively 'org-insert-heading))))
16449 ;; Define the Org-mode menus
16450 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
16452 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
16453 ["Next Field" org-cycle (org-at-table-p)]
16454 ["Previous Field" org-shifttab (org-at-table-p)]
16455 ["Next Row" org-return (org-at-table-p)]
16457 ["Blank Field" org-table-blank-field (org-at-table-p)]
16458 ["Edit Field" org-table-edit-field (org-at-table-p)]
16459 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
16462 ["Move Column Left" org-metaleft (org-at-table-p)]
16463 ["Move Column Right" org-metaright (org-at-table-p)]
16464 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
16465 ["Insert Column" org-shiftmetaright (org-at-table-p)])
16467 ["Move Row Up" org-metaup (org-at-table-p)]
16468 ["Move Row Down" org-metadown (org-at-table-p)]
16469 ["Delete Row" org-shiftmetaup (org-at-table-p)]
16470 ["Insert Row" org-shiftmetadown (org-at-table-p)]
16471 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
16473 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
16475 ["Copy Rectangle" org-copy-special (org-at-table-p)]
16476 ["Cut Rectangle" org-cut-special (org-at-table-p)]
16477 ["Paste Rectangle" org-paste-special (org-at-table-p)]
16478 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
16481 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
16482 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
16483 ["Edit Formulas" org-edit-special (org-at-table-p)]
16485 ["Recalculate line" org-table-recalculate (org-at-table-p)]
16486 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
16487 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
16489 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
16491 ["Sum Column/Rectangle" org-table-sum
16492 (or (org-at-table-p) (org-region-active-p))]
16493 ["Which Column?" org-table-current-column (org-at-table-p)])
16495 org-table-toggle-formula-debugger
16496 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
16497 ["Show Col/Row Numbers"
16498 org-table-toggle-coordinate-overlays
16500 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
16502 ["Create" org-table-create (and (not (org-at-table-p))
16503 org-enable-table-editor)]
16504 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
16505 ["Import from File" org-table-import (not (org-at-table-p))]
16506 ["Export to File" org-table-export (org-at-table-p)]
16508 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
16510 (easy-menu-define org-org-menu org-mode-map "Org menu"
16513 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
16514 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
16515 ["Sparse Tree..." org-sparse-tree t]
16516 ["Reveal Context" org-reveal t]
16517 ["Show All" show-all t]
16519 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
16521 ["New Heading" org-insert-heading t]
16522 ("Navigate Headings"
16523 ["Up" outline-up-heading t]
16524 ["Next" outline-next-visible-heading t]
16525 ["Previous" outline-previous-visible-heading t]
16526 ["Next Same Level" outline-forward-same-level t]
16527 ["Previous Same Level" outline-backward-same-level t]
16529 ["Jump" org-goto t])
16531 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
16532 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
16534 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
16535 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
16536 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
16538 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
16540 ["Promote Heading" org-metaleft (not (org-at-table-p))]
16541 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
16542 ["Demote Heading" org-metaright (not (org-at-table-p))]
16543 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
16545 ["Sort Region/Children" org-sort (not (org-at-table-p))]
16547 ["Convert to odd levels" org-convert-to-odd-levels t]
16548 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
16550 ["Emphasis..." org-emphasize t]
16551 ["Edit Source Example" org-edit-special t]
16553 ["Footnote new/jump" org-footnote-action t]
16554 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
16556 ["Archive (default method)" org-archive-subtree-default t]
16558 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
16559 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
16560 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
16564 ["Store Link (Global)" org-store-link t]
16565 ["Find existing link to here" org-occur-link-in-agenda-files t]
16566 ["Insert Link" org-insert-link t]
16567 ["Follow Link" org-open-at-point t]
16569 ["Next link" org-next-link t]
16570 ["Previous link" org-previous-link t]
16572 ["Descriptive Links"
16573 (progn (org-add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
16575 :selected (member '(org-link) buffer-invisibility-spec)]
16578 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
16580 :selected (not (member '(org-link) buffer-invisibility-spec))])
16583 ["TODO/DONE/-" org-todo t]
16585 ["Next keyword" org-shiftright (org-on-heading-p)]
16586 ["Previous keyword" org-shiftleft (org-on-heading-p)]
16587 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
16588 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
16589 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
16590 ["Show TODO Tree" org-show-todo-tree t]
16591 ["Global TODO list" org-todo-list t]
16593 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
16594 :selected org-enforce-todo-dependencies :style toggle :active t]
16595 "Settings for tree at point"
16596 ["Do Children sequentially" org-toggle-ordered-property :style radio
16597 :selected (ignore-errors (org-entry-get nil "ORDERED"))
16598 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16599 ["Do Children parallel" org-toggle-ordered-property :style radio
16600 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
16601 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16603 ["Set Priority" org-priority t]
16604 ["Priority Up" org-shiftup t]
16605 ["Priority Down" org-shiftdown t]
16607 ["Get news from all feeds" org-feed-update-all t]
16608 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
16609 ["Customize feeds" (customize-variable 'org-feed-alist) t])
16610 ("TAGS and Properties"
16611 ["Set Tags" org-set-tags-command t]
16612 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
16614 ["Set property" org-set-property t]
16615 ["Column view of properties" org-columns t]
16616 ["Insert Column View DBlock" org-insert-columns-dblock t])
16617 ("Dates and Scheduling"
16618 ["Timestamp" org-time-stamp t]
16619 ["Timestamp (inactive)" org-time-stamp-inactive t]
16621 ["1 Day Later" org-shiftright t]
16622 ["1 Day Earlier" org-shiftleft t]
16623 ["1 ... Later" org-shiftup t]
16624 ["1 ... Earlier" org-shiftdown t])
16625 ["Compute Time Range" org-evaluate-time-range t]
16626 ["Schedule Item" org-schedule t]
16627 ["Deadline" org-deadline t]
16629 ["Custom time format" org-toggle-time-stamp-overlays
16630 :style radio :selected org-display-custom-times]
16632 ["Goto Calendar" org-goto-calendar t]
16633 ["Date from Calendar" org-date-from-calendar t]
16635 ["Start/Restart Timer" org-timer-start t]
16636 ["Pause/Continue Timer" org-timer-pause-or-continue t]
16637 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
16638 ["Insert Timer String" org-timer t]
16639 ["Insert Timer Item" org-timer-item t])
16641 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
16642 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
16643 ["Clock out" org-clock-out t]
16644 ["Clock cancel" org-clock-cancel t]
16646 ["Mark as default task" org-clock-mark-default-task t]
16647 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
16648 ["Goto running clock" org-clock-goto t]
16650 ["Display times" org-clock-display t]
16651 ["Create clock table" org-clock-report t]
16653 ["Record DONE time"
16654 (progn (setq org-log-done (not org-log-done))
16655 (message "Switching to %s will %s record a timestamp"
16656 (car org-done-keywords)
16657 (if org-log-done "automatically" "not")))
16658 :style toggle :selected org-log-done])
16660 ["Agenda Command..." org-agenda t]
16661 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
16662 ("File List for Agenda")
16663 ("Special views current file"
16664 ["TODO Tree" org-show-todo-tree t]
16665 ["Check Deadlines" org-check-deadlines t]
16666 ["Timeline" org-timeline t]
16667 ["Tags/Property tree" org-match-sparse-tree t])
16669 ["Export/Publish..." org-export t]
16671 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
16672 :selected org-cdlatex-mode]
16673 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
16674 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
16675 ["Modify math symbol" org-cdlatex-math-modify
16676 (org-inside-LaTeX-fragment-p)]
16677 ["Insert citation" org-reftex-citation t]
16679 ["Export LaTeX fragments as images"
16680 (if (featurep 'org-exp)
16681 (setq org-export-with-LaTeX-fragments
16682 (not org-export-with-LaTeX-fragments))
16683 (require 'org-exp))
16684 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
16685 org-export-with-LaTeX-fragments)]
16687 ["Template for BEAMER" org-beamer-settings-template t])
16690 ["Push Files and Views" org-mobile-push t]
16691 ["Get Captured and Flagged" org-mobile-pull t]
16692 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
16694 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
16697 ["Show Version" org-version t]
16698 ["Info Documentation" org-info t])
16700 ["Browse Org Group" org-customize t]
16702 ["Expand This Menu" org-create-customize-menu
16703 (fboundp 'customize-menu-create)])
16704 ["Send bug report" org-submit-bug-report t]
16707 ["Refresh setup current buffer" org-mode-restart t]
16708 ["Reload Org (after update)" org-reload t]
16709 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
16712 (defun org-info (&optional node)
16713 "Read documentation for Org-mode in the info system.
16714 With optional NODE, go directly to that node."
16716 (info (format "(org)%s" (or node ""))))
16719 (defun org-submit-bug-report ()
16720 "Submit a bug report on Org-mode via mail.
16722 Don't hesitate to report any problems or inaccurate documentation.
16724 If you don't have setup sending mail from (X)Emacs, please copy the
16725 output buffer into your mail program, as it gives us important
16726 information about your Org-mode version and configuration."
16728 (require 'reporter)
16729 (org-load-modules-maybe)
16730 (org-require-autoloaded-modules)
16731 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
16732 (reporter-submit-bug-report
16733 "emacs-orgmode@gnu.org"
16736 (save-window-excursion
16737 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
16738 (delete-other-windows)
16740 (insert "You are about to submit a bug report to the Org-mode mailing list.
16742 We would like to add your full Org-mode and Outline configuration to the
16743 bug report. This greatly simplifies the work of the maintainer and
16744 other experts on the mailing list.
16746 HOWEVER, some variables you have customized may contain private
16747 information. The names of customers, colleagues, or friends, might
16748 appear in the form of file names, tags, todo states, or search strings.
16749 If you answer yes to the prompt, you might want to check and remove
16750 such private information before sending the email.")
16751 (add-text-properties (point-min) (point-max) '(face org-warning))
16752 (when (yes-or-no-p "Include your Org-mode configuration ")
16756 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
16757 (or (and (symbol-value v)
16758 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
16760 (get v 'custom-type) (get v 'standard-value)
16761 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
16763 (kill-buffer (get-buffer "*Warn about privacy*"))
16766 "Remember to cover the basics, that is, what you expected to happen and
16767 what in fact did happen. You don't know how to make a good report? See
16769 http://orgmode.org/manual/Feedback.html#Feedback
16771 Your bug report will be posted to the Org-mode mailing list.
16772 ------------------------------------------------------------------------")
16774 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
16775 (replace-match "\\1Bug: \\3 [\\2]")))))
16778 (defun org-install-agenda-files-menu ()
16779 (let ((bl (buffer-list)))
16782 (set-buffer (pop bl))
16783 (if (org-mode-p) (setq bl nil)))
16786 '("Org") "File List for Agenda"
16789 ["Edit File List" (org-edit-agenda-file-list) t]
16790 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
16791 ["Remove Current File from List" org-remove-file t]
16792 ["Cycle through agenda files" org-cycle-agenda-files t]
16793 ["Occur in all agenda files" org-occur-in-agenda-files t]
16795 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
16800 (defun org-require-autoloaded-modules ()
16803 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
16804 org-docbook org-exp org-html org-icalendar
16806 org-publish org-remember org-table
16807 org-timer org-xoxo)))
16810 (defun org-reload (&optional uncompiled)
16811 "Reload all org lisp files.
16812 With prefix arg UNCOMPILED, load the uncompiled versions."
16814 (require 'find-func)
16815 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
16816 (dir-org (file-name-directory (org-find-library-name "org")))
16817 (dir-org-contrib (ignore-errors
16818 (file-name-directory
16819 (org-find-library-name "org-contribdir"))))
16821 (append (directory-files dir-org t file-re)
16822 (and dir-org-contrib
16823 (directory-files dir-org-contrib t file-re))))
16824 (remove-re (concat (if (featurep 'xemacs)
16825 "org-colview" "org-colview-xemacs")
16827 (setq files (mapcar 'file-name-sans-extension files))
16828 (setq files (mapcar
16829 (lambda (x) (if (string-match remove-re x) nil x))
16831 (setq files (delq nil files))
16834 (when (featurep (intern (file-name-nondirectory f)))
16835 (if (and (not uncompiled)
16836 (file-exists-p (concat f ".elc")))
16837 (load (concat f ".elc") nil nil t)
16838 (load (concat f ".el") nil nil t))))
16843 (defun org-customize ()
16844 "Call the customize function with org as argument."
16846 (org-load-modules-maybe)
16847 (org-require-autoloaded-modules)
16848 (customize-browse 'org))
16850 (defun org-create-customize-menu ()
16851 "Create a full customization menu for Org-mode, insert it into the menu."
16853 (org-load-modules-maybe)
16854 (org-require-autoloaded-modules)
16855 (if (fboundp 'customize-menu-create)
16858 '("Org") "Customize"
16859 `(["Browse Org group" org-customize t]
16861 ,(customize-menu-create 'org)
16862 ["Set" Custom-set t]
16863 ["Save" Custom-save t]
16864 ["Reset to Current" Custom-reset-current t]
16865 ["Reset to Saved" Custom-reset-saved t]
16866 ["Reset to Standard Settings" Custom-reset-standard t]))
16867 (message "\"Org\"-menu now contains full customization menu"))
16868 (error "Cannot expand menu (outdated version of cus-edit.el)")))
16870 ;;;; Miscellaneous stuff
16872 ;;; Generally useful functions
16874 (defun org-get-at-bol (property)
16875 "Get text property PROPERTY at beginning of line."
16876 (get-text-property (point-at-bol) property))
16878 (defun org-find-text-property-in-string (prop s)
16879 "Return the first non-nil value of property PROP in string S."
16880 (or (get-text-property 0 prop s)
16881 (get-text-property (or (next-single-property-change 0 prop s) 0)
16884 (defun org-display-warning (message) ;; Copied from Emacs-Muse
16885 "Display the given MESSAGE as a warning."
16886 (if (fboundp 'display-warning)
16887 (display-warning 'org message
16888 (if (featurep 'xemacs)
16891 (let ((buf (get-buffer-create "*Org warnings*")))
16892 (with-current-buffer buf
16893 (goto-char (point-max))
16894 (insert "Warning (Org): " message)
16897 (display-buffer buf)
16900 (defun org-in-commented-line ()
16901 "Is point in a line starting with `#'?"
16902 (equal (char-after (point-at-bol)) ?#))
16904 (defun org-in-verbatim-emphasis ()
16906 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
16908 (defun org-goto-marker-or-bmk (marker &optional bookmark)
16909 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
16910 (if (and marker (marker-buffer marker)
16911 (buffer-live-p (marker-buffer marker)))
16913 (switch-to-buffer (marker-buffer marker))
16914 (if (or (> marker (point-max)) (< marker (point-min)))
16917 (org-show-context 'org-goto))
16919 (bookmark-jump bookmark)
16920 (error "Cannot find location"))))
16922 (defun org-quote-csv-field (s)
16923 "Quote field for inclusion in CSV material."
16924 (if (string-match "[\",]" s)
16925 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
16928 (defun org-plist-delete (plist property)
16929 "Delete PROPERTY from PLIST.
16930 This is in contrast to merely setting it to 0."
16933 (if (not (eq property (car plist)))
16934 (setq p (plist-put p (car plist) (nth 1 plist))))
16935 (setq plist (cddr plist)))
16938 (defun org-force-self-insert (N)
16939 "Needed to enforce self-insert under remapping."
16941 (self-insert-command N))
16943 (defun org-string-width (s)
16944 "Compute width of string, ignoring invisible characters.
16945 This ignores character with invisibility property `org-link', and also
16946 characters with property `org-cwidth', because these will become invisible
16947 upon the next fontification round."
16949 (when (or (eq t buffer-invisibility-spec)
16950 (assq 'org-link buffer-invisibility-spec))
16951 (while (setq b (text-property-any 0 (length s)
16952 'invisible 'org-link s))
16953 (setq s (concat (substring s 0 b)
16954 (substring s (or (next-single-property-change
16955 b 'invisible s) (length s)))))))
16956 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
16957 (setq s (concat (substring s 0 b)
16958 (substring s (or (next-single-property-change
16959 b 'org-cwidth s) (length s))))))
16960 (setq l (string-width s) b -1)
16961 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
16962 (setq l (- l (get-text-property b 'org-dwidth-n s))))
16965 (defun org-get-indentation (&optional line)
16966 "Get the indentation of the current line, interpreting tabs.
16967 When LINE is given, assume it represents a line and compute its indentation."
16969 (if (string-match "^ *" (org-remove-tabs line))
16972 (beginning-of-line 1)
16973 (skip-chars-forward " \t")
16974 (current-column))))
16976 (defun org-remove-tabs (s &optional width)
16977 "Replace tabulators in S with spaces.
16978 Assumes that s is a single line, starting in column 0."
16979 (setq width (or width tab-width))
16980 (while (string-match "\t" s)
16981 (setq s (replace-match
16983 (- (* width (/ (+ (match-beginning 0) width) width))
16984 (match-beginning 0)) ?\ )
16988 (defun org-fix-indentation (line ind)
16989 "Fix indentation in LINE.
16990 IND is a cons cell with target and minimum indentation.
16991 If the current indentation in LINE is smaller than the minimum,
16992 leave it alone. If it is larger than ind, set it to the target."
16993 (let* ((l (org-remove-tabs line))
16994 (i (org-get-indentation l))
16995 (i1 (car ind)) (i2 (cdr ind)))
16996 (if (>= i i2) (setq l (substring line i2)))
16998 (concat (make-string i1 ?\ ) l)
17001 (defun org-remove-indentation (code &optional n)
17002 "Remove the maximum common indentation from the lines in CODE.
17003 N may optionally be the number of spaces to remove."
17006 (org-do-remove-indentation n)
17009 (defun org-do-remove-indentation (&optional n)
17010 "Remove the maximum common indentation from the buffer."
17011 (untabify (point-min) (point-max))
17012 (let ((min 10000) re)
17015 (goto-char (point-min))
17016 (while (re-search-forward "^ *[^ \n]" nil t)
17017 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17018 (unless (or (= min 0) (= min 10000))
17019 (setq re (format "^ \\{%d\\}" min))
17020 (goto-char (point-min))
17021 (while (re-search-forward re nil t)
17026 (defun org-fill-template (template alist)
17027 "Find each %key of ALIST in TEMPLATE and replace it."
17028 (let ((case-fold-search nil)
17030 (setq alist (sort (copy-sequence alist)
17031 (lambda (a b) (< (length (car a)) (length (car b))))))
17032 (while (setq entry (pop alist))
17034 (replace-regexp-in-string
17035 (concat "%" (regexp-quote (car entry)))
17036 (cdr entry) template t t)))
17039 (defun org-base-buffer (buffer)
17040 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17043 (or (buffer-base-buffer buffer)
17046 (defun org-trim (s)
17047 "Remove whitespace at beginning and end of string."
17048 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17049 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17052 (defun org-wrap (string &optional width lines)
17053 "Wrap string to either a number of lines, or a width in characters.
17054 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17055 that costs. If there is a word longer than WIDTH, the text is actually
17056 wrapped to the length of that word.
17057 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17058 many lines, whatever width that takes.
17059 The return value is a list of lines, without newlines at the end."
17060 (let* ((words (org-split-string string "[ \t\n]+"))
17061 (maxword (apply 'max (mapcar 'org-string-width words)))
17064 (org-do-wrap words (max maxword width)))
17067 (setq ll (org-do-wrap words maxword))
17068 (if (<= (length ll) lines)
17071 (while (> (length ll) lines)
17073 (setq ll (org-do-wrap words w)))
17075 (t (error "Cannot wrap this")))))
17077 (defun org-do-wrap (words width)
17078 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17081 (setq line (pop words))
17082 (while (and words (< (+ (length line) (length (car words))) width))
17083 (setq line (concat line " " (pop words))))
17084 (setq lines (push line lines)))
17087 (defun org-split-string (string &optional separators)
17088 "Splits STRING into substrings at SEPARATORS.
17089 No empty strings are returned if there are matches at the beginning
17090 and end of string."
17091 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17095 (while (and (string-match rexp string
17097 (= start (match-beginning 0))
17098 (< start (length string)))
17100 (< (match-beginning 0) (length string)))
17102 (or (eq (match-beginning 0) 0)
17103 (and (eq (match-beginning 0) (match-end 0))
17104 (eq (match-beginning 0) start))
17106 (cons (substring string start (match-beginning 0))
17108 (setq start (match-end 0)))
17109 (or (eq start (length string))
17111 (cons (substring string start)
17115 (defun org-quote-vert (s)
17116 "Replace \"|\" with \"\\vert\"."
17117 (while (string-match "|" s)
17118 (setq s (replace-match "\\vert" t t s)))
17121 (defun org-uuidgen-p (s)
17122 "Is S an ID created by UUIDGEN?"
17123 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17125 (defun org-context ()
17126 "Return a list of contexts of the current cursor position.
17127 If several contexts apply, all are returned.
17128 Each context entry is a list with a symbol naming the context, and
17129 two positions indicating start and end of the context. Possible
17132 :headline anywhere in a headline
17133 :headline-stars on the leading stars in a headline
17134 :todo-keyword on a TODO keyword (including DONE) in a headline
17135 :tags on the TAGS in a headline
17136 :priority on the priority cookie in a headline
17137 :item on the first line of a plain list item
17138 :item-bullet on the bullet/number of a plain list item
17139 :checkbox on the checkbox in a plain list item
17140 :table in an org-mode table
17141 :table-special on a special filed in a table
17142 :table-table in a table.el table
17143 :link on a hyperlink
17144 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
17145 :target on a <<target>>
17146 :radio-target on a <<<radio-target>>>
17147 :latex-fragment on a LaTeX fragment
17148 :latex-preview on a LaTeX fragment with overlayed preview image
17150 This function expects the position to be visible because it uses font-lock
17151 faces as a help to recognize the following contexts: :table-special, :link,
17153 (let* ((f (get-text-property (point) 'face))
17154 (faces (if (listp f) f (list f)))
17155 (p (point)) clist o)
17156 ;; First the large context
17158 ((org-on-heading-p t)
17159 (push (list :headline (point-at-bol) (point-at-eol)) clist)
17161 (beginning-of-line 1)
17162 (looking-at org-todo-line-tags-regexp))
17163 (push (org-point-in-group p 1 :headline-stars) clist)
17164 (push (org-point-in-group p 2 :todo-keyword) clist)
17165 (push (org-point-in-group p 4 :tags) clist))
17167 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
17168 (if (looking-at "\\[#[A-Z0-9]\\]")
17169 (push (org-point-in-group p 0 :priority) clist)))
17172 (push (org-point-in-group p 2 :item-bullet) clist)
17173 (push (list :item (point-at-bol)
17174 (save-excursion (org-end-of-item) (point)))
17176 (and (org-at-item-checkbox-p)
17177 (push (org-point-in-group p 0 :checkbox) clist)))
17180 (push (list :table (org-table-begin) (org-table-end)) clist)
17181 (if (memq 'org-formula faces)
17182 (push (list :table-special
17183 (previous-single-property-change p 'face)
17184 (next-single-property-change p 'face)) clist)))
17185 ((org-at-table-p 'any)
17186 (push (list :table-table) clist)))
17189 ;; Now the small context
17191 ((org-at-timestamp-p)
17192 (push (org-point-in-group p 0 :timestamp) clist))
17193 ((memq 'org-link faces)
17195 (previous-single-property-change p 'face)
17196 (next-single-property-change p 'face)) clist))
17197 ((memq 'org-special-keyword faces)
17198 (push (list :keyword
17199 (previous-single-property-change p 'face)
17200 (next-single-property-change p 'face)) clist))
17202 (push (org-point-in-group p 0 :target) clist)
17203 (goto-char (1- (match-beginning 0)))
17204 (if (looking-at org-radio-target-regexp)
17205 (push (org-point-in-group p 0 :radio-target) clist))
17207 ((setq o (car (delq nil
17210 (if (memq x org-latex-fragment-image-overlays) x))
17211 (org-overlays-at (point))))))
17212 (push (list :latex-fragment
17213 (org-overlay-start o) (org-overlay-end o)) clist)
17214 (push (list :latex-preview
17215 (org-overlay-start o) (org-overlay-end o)) clist))
17216 ((org-inside-LaTeX-fragment-p)
17217 ;; FIXME: positions wrong.
17218 (push (list :latex-fragment (point) (point)) clist)))
17220 (setq clist (nreverse (delq nil clist)))
17223 ;; FIXME: Compare with at-regexp-p Do we need both?
17224 (defun org-in-regexp (re &optional nlines visually)
17225 "Check if point is inside a match of regexp.
17226 Normally only the current line is checked, but you can include NLINES extra
17227 lines both before and after point into the search.
17228 If VISUALLY is set, require that the cursor is not after the match but
17229 really on, so that the block visually is on the match."
17231 (let ((pos (point))
17232 (eol (point-at-eol (+ 1 (or nlines 0))))
17233 (inc (if visually 1 0)))
17235 (beginning-of-line (- 1 (or nlines 0)))
17236 (while (re-search-forward re eol t)
17237 (if (and (<= (match-beginning 0) pos)
17238 (>= (+ inc (match-end 0)) pos))
17239 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
17241 (defun org-at-regexp-p (regexp)
17242 "Is point inside a match of REGEXP in the current line?"
17245 (let ((pos (point)) (end (point-at-eol)))
17246 (beginning-of-line 1)
17247 (while (re-search-forward regexp end t)
17248 (if (and (<= (match-beginning 0) pos)
17249 (>= (match-end 0) pos))
17253 (defun org-in-regexps-block-p (start-re end-re)
17254 "Returns t if the current point is between matches of START-RE and END-RE.
17255 This will also return to if point is on one of the two matches."
17259 (and (or (org-at-regexp-p start-re)
17260 (re-search-backward start-re nil t))
17261 (re-search-forward end-re nil t)
17264 (defun org-occur-in-agenda-files (regexp &optional nlines)
17265 "Call `multi-occur' with buffers for all agenda files."
17266 (interactive "sOrg-files matching: \np")
17267 (let* ((files (org-agenda-files))
17268 (tnames (mapcar 'file-truename files))
17269 (extra org-agenda-text-search-extra-files)
17271 (when (eq (car extra) 'agenda-archives)
17272 (setq extra (cdr extra))
17273 (setq files (org-add-archive-files files)))
17274 (while (setq f (pop extra))
17275 (unless (member (file-truename f) tnames)
17276 (add-to-list 'files f 'append)
17277 (add-to-list 'tnames (file-truename f) 'append)))
17279 (mapcar (lambda (x)
17280 (with-current-buffer
17281 (or (get-file-buffer x) (find-file-noselect x))
17287 (if (boundp 'occur-mode-find-occurrence-hook)
17289 (add-hook 'occur-mode-find-occurrence-hook
17294 (defadvice occur-mode-goto-occurrence
17295 (after org-occur-reveal activate)
17296 (and (org-mode-p) (org-reveal)))
17297 (defadvice occur-mode-goto-occurrence-other-window
17298 (after org-occur-reveal activate)
17299 (and (org-mode-p) (org-reveal)))
17300 (defadvice occur-mode-display-occurrence
17301 (after org-occur-reveal activate)
17303 (let ((pos (occur-mode-find-occurrence)))
17304 (with-current-buffer (marker-buffer pos)
17309 (defun org-occur-link-in-agenda-files ()
17310 "Create a link and search for it in the agendas.
17311 The link is not stored in `org-stored-links', it is just created
17312 for the search purpose."
17314 (let ((link (condition-case nil
17315 (org-store-link nil)
17316 (error "Unable to create a link to here"))))
17317 (org-occur-in-agenda-files (regexp-quote link))))
17319 (defun org-uniquify (list)
17320 "Remove duplicate elements from LIST."
17322 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
17325 (defun org-delete-all (elts list)
17326 "Remove all elements in ELTS from LIST."
17328 (setq list (delete (pop elts) list)))
17331 (defun org-back-over-empty-lines ()
17332 "Move backwards over whitespace, to the beginning of the first empty line.
17333 Returns the number of empty lines passed."
17334 (let ((pos (point)))
17335 (skip-chars-backward " \t\n\r")
17336 (beginning-of-line 2)
17337 (goto-char (min (point) pos))
17338 (count-lines (point) pos)))
17340 (defun org-skip-whitespace ()
17341 (skip-chars-forward " \t\n\r"))
17343 (defun org-point-in-group (point group &optional context)
17344 "Check if POINT is in match-group GROUP.
17345 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
17346 match. If the match group does ot exist or point is not inside it,
17348 (and (match-beginning group)
17349 (>= point (match-beginning group))
17350 (<= point (match-end group))
17352 (list context (match-beginning group) (match-end group))
17355 (defun org-switch-to-buffer-other-window (&rest args)
17356 "Switch to buffer in a second window on the current frame.
17357 In particular, do not allow pop-up frames."
17358 (let (pop-up-frames special-display-buffer-names special-display-regexps
17359 special-display-function)
17360 (apply 'switch-to-buffer-other-window args)))
17362 (defun org-combine-plists (&rest plists)
17363 "Create a single property list from all plists in PLISTS.
17364 The process starts by copying the first list, and then setting properties
17365 from the other lists. Settings in the last list are the most significant
17366 ones and overrule settings in the other lists."
17367 (let ((rtn (copy-sequence (pop plists)))
17370 (setq ls (pop plists))
17372 (setq p (pop ls) v (pop ls))
17373 (setq rtn (plist-put rtn p v))))
17376 (defun org-move-line-down (arg)
17377 "Move the current line down. With prefix argument, move it past ARG lines."
17379 (let ((col (current-column))
17381 (beginning-of-line 1) (setq beg (point))
17382 (beginning-of-line 2) (setq end (point))
17383 (beginning-of-line (+ 1 arg))
17384 (setq pos (move-marker (make-marker) (point)))
17385 (insert (delete-and-extract-region beg end))
17387 (org-move-to-column col)))
17389 (defun org-move-line-up (arg)
17390 "Move the current line up. With prefix argument, move it past ARG lines."
17392 (let ((col (current-column))
17394 (beginning-of-line 1) (setq beg (point))
17395 (beginning-of-line 2) (setq end (point))
17396 (beginning-of-line (- arg))
17397 (setq pos (move-marker (make-marker) (point)))
17398 (insert (delete-and-extract-region beg end))
17400 (org-move-to-column col)))
17402 (defun org-replace-escapes (string table)
17403 "Replace %-escapes in STRING with values in TABLE.
17404 TABLE is an association list with keys like \"%a\" and string values.
17405 The sequences in STRING may contain normal field width and padding information,
17406 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
17407 so values can contain further %-escapes if they are define later in TABLE."
17408 (let ((case-fold-search nil)
17410 (while (setq e (pop table))
17411 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
17412 (while (string-match re string)
17413 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
17415 (setq string (replace-match rpl t t string))))
17419 (defun org-sublist (list start end)
17420 "Return a section of LIST, from START to END.
17421 Counting starts at 1."
17422 (let (rtn (c start))
17423 (setq list (nthcdr (1- start) list))
17424 (while (and list (<= c end))
17425 (push (pop list) rtn)
17429 (defun org-find-base-buffer-visiting (file)
17430 "Like `find-buffer-visiting' but always return the base buffer and
17431 not an indirect buffer."
17432 (let ((buf (or (get-file-buffer file)
17433 (find-buffer-visiting file))))
17435 (or (buffer-base-buffer buf) buf)
17438 (defun org-image-file-name-regexp (&optional extensions)
17439 "Return regexp matching the file names of images.
17440 If EXTENSIONS is given, only match these."
17441 (if (and (not extensions) (fboundp 'image-file-name-regexp))
17442 (image-file-name-regexp)
17443 (let ((image-file-name-extensions
17445 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
17446 "xbm" "xpm" "pbm" "pgm" "ppm"))))
17448 (regexp-opt (nconc (mapcar 'upcase
17449 image-file-name-extensions)
17450 image-file-name-extensions)
17454 (defun org-file-image-p (file &optional extensions)
17455 "Return non-nil if FILE is an image."
17457 (string-match (org-image-file-name-regexp extensions) file)))
17459 (defun org-get-cursor-date ()
17460 "Return the date at cursor in as a time.
17461 This works in the calendar and in the agenda, anywhere else it just
17462 returns the current time."
17463 (let (date day defd)
17465 ((eq major-mode 'calendar-mode)
17466 (setq date (calendar-cursor-to-date)
17467 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
17468 ((eq major-mode 'org-agenda-mode)
17469 (setq day (get-text-property (point) 'day))
17471 (setq date (calendar-gregorian-from-absolute day)
17472 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
17474 (or defd (current-time))))
17476 (defvar org-agenda-action-marker (make-marker)
17477 "Marker pointing to the entry for the next agenda action.")
17479 (defun org-mark-entry-for-agenda-action ()
17480 "Mark the current entry as target of an agenda action.
17481 Agenda actions are actions executed from the agenda with the key `k',
17482 which make use of the date at the cursor."
17484 (move-marker org-agenda-action-marker
17485 (save-excursion (org-back-to-heading t) (point))
17488 "Entry marked for action; press `k' at desired date in agenda or calendar"))
17490 ;;; Paragraph filling stuff.
17491 ;; We want this to be just right, so use the full arsenal.
17493 (defun org-indent-line-function ()
17494 "Indent line like previous, but further if previous was headline or item."
17496 (let* ((pos (point))
17497 (itemp (org-at-item-p))
17498 (case-fold-search t)
17499 (org-drawer-regexp (or org-drawer-regexp "\000"))
17500 column bpos bcol tpos tcol bullet btype bullet-type)
17501 ;; Find the previous relevant line
17502 (beginning-of-line 1)
17504 ((looking-at "#") (setq column 0))
17505 ((looking-at "\\*+ ") (setq column 0))
17506 ((and (looking-at "[ \t]*:END:")
17507 (save-excursion (re-search-backward org-drawer-regexp nil t)))
17509 (goto-char (1- (match-beginning 1)))
17510 (setq column (current-column))))
17511 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
17513 (re-search-backward
17514 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
17515 (setq column (org-get-indentation (match-string 0))))
17517 (beginning-of-line 0)
17518 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
17519 (not (looking-at "[ \t]*:END:"))
17520 (not (looking-at org-drawer-regexp)))
17521 (beginning-of-line 0))
17523 ((looking-at "\\*+[ \t]+")
17524 (if (not org-adapt-indentation)
17526 (goto-char (match-end 0))
17527 (setq column (current-column))))
17528 ((looking-at org-drawer-regexp)
17529 (goto-char (1- (match-beginning 1)))
17530 (setq column (current-column)))
17531 ((looking-at "\\([ \t]*\\):END:")
17532 (goto-char (match-end 1))
17533 (setq column (current-column)))
17535 (org-beginning-of-item)
17536 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
17537 (setq bpos (match-beginning 1) tpos (match-end 0)
17538 bcol (progn (goto-char bpos) (current-column))
17539 tcol (progn (goto-char tpos) (current-column))
17540 bullet (match-string 1)
17541 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
17542 (if (> tcol (+ bcol org-description-max-indent))
17543 (setq tcol (+ bcol 5)))
17547 (beginning-of-line 1)
17548 (if (looking-at "\\S-")
17550 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
17551 (setq bullet (match-string 1)
17552 btype (if (string-match "[0-9]" bullet) "n" bullet))
17553 (setq column (if (equal btype bullet-type) bcol tcol)))
17554 (setq column (org-get-indentation)))))
17555 (t (setq column (org-get-indentation))))))
17557 (if (<= (current-column) (current-indentation))
17558 (org-indent-line-to column)
17559 (save-excursion (org-indent-line-to column)))
17560 (setq column (current-column))
17561 (beginning-of-line 1)
17563 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
17564 (replace-match (concat (match-string 1)
17565 (format org-property-format
17566 (match-string 2) (match-string 3)))
17568 (org-move-to-column column)))
17570 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
17571 "Variable to store copy of `adaptive-fill-regexp'.
17572 Since `adaptive-fill-regexp' is set to never match, we need to
17573 store a backup of its value before entering `org-mode' so that
17574 the functionality can be provided as a fall-back.")
17576 (defun org-set-autofill-regexps ()
17578 ;; In the paragraph separator we include headlines, because filling
17579 ;; text in a line directly attached to a headline would otherwise
17580 ;; fill the headline as well.
17581 (org-set-local 'comment-start-skip "^#+[ \t]*")
17582 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
17583 ;; The paragraph starter includes hand-formatted lists.
17591 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
17594 "\\\\\\(begin\\|end\\|[][]\\)"))
17595 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
17596 ;; But only if the user has not turned off tables or fixed-width regions
17598 'auto-fill-inhibit-regexp
17599 (concat "\\*+ \\|#\\+"
17600 "\\|[ \t]*" org-keyword-time-regexp
17601 (if (or org-enable-table-editor org-enable-fixed-width-editor)
17604 (if org-enable-table-editor "|" "")
17605 (if org-enable-fixed-width-editor ":" "")
17607 ;; We use our own fill-paragraph function, to make sure that tables
17608 ;; and fixed-width regions are not wrapped. That function will pass
17609 ;; through to `fill-paragraph' when appropriate.
17610 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
17611 ;; Adaptive filling: To get full control, first make sure that
17612 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
17613 (unless (local-variable-p 'adaptive-fill-regexp)
17614 (org-set-local 'org-adaptive-fill-regexp-backup
17615 adaptive-fill-regexp))
17616 (org-set-local 'adaptive-fill-regexp "\000")
17617 (org-set-local 'adaptive-fill-function
17618 'org-adaptive-fill-function)
17620 'align-mode-rules-list
17621 '((org-in-buffer-settings
17622 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
17623 (modes . '(org-mode))))))
17625 (defun org-fill-paragraph (&optional justify)
17626 "Re-align a table, pass through to fill-paragraph if no table."
17627 (let ((table-p (org-at-table-p))
17628 (table.el-p (org-at-table.el-p)))
17629 (cond ((and (equal (char-after (point-at-bol)) ?*)
17630 (save-excursion (goto-char (point-at-bol))
17631 (looking-at outline-regexp)))
17632 t) ; skip headlines
17633 (table.el-p t) ; skip table.el tables
17634 (table-p (org-table-align) t) ; align org-mode tables
17635 (t nil)))) ; call paragraph-fill
17637 ;; For reference, this is the default value of adaptive-fill-regexp
17638 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
17640 (defun org-adaptive-fill-function ()
17641 "Return a fill prefix for org-mode files.
17642 In particular, this makes sure hanging paragraphs for hand-formatted lists
17646 ((looking-at "#[ \t]+")
17647 (match-string-no-properties 0))
17648 ;; Description list
17649 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
17651 (if (> (match-end 1) (+ (match-beginning 1)
17652 org-description-max-indent))
17653 (goto-char (+ (match-beginning 1) 5))
17654 (goto-char (match-end 0)))
17655 (make-string (current-column) ?\ )))
17656 ;; Ordered or unordered list
17657 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
17659 (goto-char (match-end 0))
17660 (make-string (current-column) ?\ )))
17662 ((looking-at org-adaptive-fill-regexp-backup)
17663 (match-string-no-properties 0))))
17667 (defun org-toggle-fixed-width-section (arg)
17668 "Toggle the fixed-width export.
17669 If there is no active region, the QUOTE keyword at the current headline is
17670 inserted or removed. When present, it causes the text between this headline
17671 and the next to be exported as fixed-width text, and unmodified.
17672 If there is an active region, this command adds or removes a colon as the
17673 first character of this line. If the first character of a line is a colon,
17674 this line is also exported in fixed-width font."
17677 (regionp (org-region-active-p))
17678 (beg (if regionp (region-beginning) (point)))
17679 (end (if regionp (region-end)))
17680 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
17681 (case-fold-search nil)
17682 (re "[ \t]*\\(: \\)")
17687 (setq cc (current-column))
17688 (beginning-of-line 1)
17689 (setq off (looking-at re))
17690 (while (> nlines 0)
17691 (setq nlines (1- nlines))
17692 (beginning-of-line 1)
17695 (org-move-to-column cc t)
17698 ((and off (looking-at re))
17699 (replace-match "" t t nil 1))
17700 ((not off) (org-move-to-column cc t) (insert ": ")))
17703 (org-back-to-heading)
17704 (if (looking-at (concat outline-regexp
17705 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
17706 (replace-match "" t t nil 1)
17707 (if (looking-at outline-regexp)
17709 (goto-char (match-end 0))
17710 (insert org-quote-string " "))))))))
17712 (defun org-reftex-citation ()
17713 "Use reftex-citation to insert a citation into the buffer.
17714 This looks for a line like
17716 #+BIBLIOGRAPHY: foo plain option:-d
17718 and derives from it that foo.bib is the bibliography file relevant
17719 for this document. It then installs the necessary environment for RefTeX
17720 to work in this buffer and calls `reftex-citation' to insert a citation
17723 Export of such citations to both LaTeX and HTML is handled by the contributed
17724 package org-exp-bibtex by Taru Karttunen."
17726 (let ((reftex-docstruct-symbol 'rds)
17727 (reftex-cite-format "\\cite{%l}")
17732 (let ((case-fold-search t)
17733 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
17734 (if (not (save-excursion
17735 (or (re-search-forward re nil t)
17736 (re-search-backward re nil t))))
17737 (error "No bibliography defined in file")
17738 (setq bib (concat (match-string 1) ".bib")
17739 rds (list (list 'bib bib)))))))
17740 (call-interactively 'reftex-citation)))
17742 ;;;; Functions extending outline functionality
17744 (defun org-beginning-of-line (&optional arg)
17745 "Go to the beginning of the current line. If that is invisible, continue
17746 to a visible line beginning. This makes the function of C-a more intuitive.
17747 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17748 first attempt, and only move to after the tags when the cursor is already
17749 beyond the end of the headline."
17751 (let ((pos (point))
17752 (special (if (consp org-special-ctrl-a/e)
17753 (car org-special-ctrl-a/e)
17754 org-special-ctrl-a/e))
17756 (if (org-bound-and-true-p line-move-visual)
17757 (beginning-of-visual-line 1)
17758 (beginning-of-line 1))
17759 (if (and arg (fboundp 'move-beginning-of-line))
17760 (call-interactively 'move-beginning-of-line)
17764 (if (org-invisible-p)
17765 (while (and (not (bobp)) (org-invisible-p))
17767 (beginning-of-line 1))
17768 (forward-char 1))))
17771 ((and (looking-at org-complex-heading-regexp)
17772 (= (char-after (match-end 1)) ?\ ))
17773 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
17777 (cond ((> pos refpos) refpos)
17778 ((= pos (point)) refpos)
17780 (cond ((> pos (point)) (point))
17781 ((not (eq last-command this-command)) (point))
17786 (cond ((> pos (match-end 4)) (match-end 4))
17787 ((= pos (point)) (match-end 4))
17789 (cond ((> pos (point)) (point))
17790 ((not (eq last-command this-command)) (point))
17791 (t (match-end 4))))))))
17793 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17795 (defun org-end-of-line (&optional arg)
17796 "Go to the end of the line.
17797 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17798 first attempt, and only move to after the tags when the cursor is already
17799 beyond the end of the headline."
17801 (let ((special (if (consp org-special-ctrl-a/e)
17802 (cdr org-special-ctrl-a/e)
17803 org-special-ctrl-a/e)))
17804 (if (or (not special)
17805 (not (org-on-heading-p))
17807 (call-interactively
17808 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
17809 ((fboundp 'move-end-of-line) 'move-end-of-line)
17811 (let ((pos (point)))
17812 (beginning-of-line 1)
17813 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
17815 (if (or (< pos (match-beginning 1))
17816 (= pos (match-end 0)))
17817 (goto-char (match-beginning 1))
17818 (goto-char (match-end 0)))
17819 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
17820 (goto-char (match-end 0))
17821 (goto-char (match-beginning 1))))
17822 (call-interactively (if (fboundp 'move-end-of-line)
17826 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17828 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
17829 (define-key org-mode-map "\C-e" 'org-end-of-line)
17830 (define-key org-mode-map [home] 'org-beginning-of-line)
17831 (define-key org-mode-map [end] 'org-end-of-line)
17833 (defun org-backward-sentence (&optional arg)
17834 "Go to beginning of sentence, or beginning of table field.
17835 This will call `backward-sentence' or `org-table-beginning-of-field',
17836 depending on context."
17839 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
17840 (t (call-interactively 'backward-sentence))))
17842 (defun org-forward-sentence (&optional arg)
17843 "Go to end of sentence, or end of table field.
17844 This will call `forward-sentence' or `org-table-end-of-field',
17845 depending on context."
17848 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
17849 (t (call-interactively 'forward-sentence))))
17851 (define-key org-mode-map "\M-a" 'org-backward-sentence)
17852 (define-key org-mode-map "\M-e" 'org-forward-sentence)
17854 (defun org-kill-line (&optional arg)
17855 "Kill line, to tags or end of line."
17858 ((or (not org-special-ctrl-k)
17860 (not (org-on-heading-p)))
17861 (call-interactively 'kill-line))
17862 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
17863 (kill-region (point) (match-beginning 1))
17864 (org-set-tags nil t))
17865 (t (kill-region (point) (point-at-eol)))))
17867 (define-key org-mode-map "\C-k" 'org-kill-line)
17869 (defun org-yank (&optional arg)
17870 "Yank. If the kill is a subtree, treat it specially.
17871 This command will look at the current kill and check if is a single
17872 subtree, or a series of subtrees[1]. If it passes the test, and if the
17873 cursor is at the beginning of a line or after the stars of a currently
17874 empty headline, then the yank is handled specially. How exactly depends
17875 on the value of the following variables, both set by default.
17877 org-yank-folded-subtrees
17878 When set, the subtree(s) will be folded after insertion, but only
17879 if doing so would now swallow text after the yanked text.
17881 org-yank-adjusted-subtrees
17882 When set, the subtree will be promoted or demoted in order to
17883 fit into the local outline tree structure, which means that the level
17884 will be adjusted so that it becomes the smaller one of the two
17885 *visible* surrounding headings.
17887 Any prefix to this command will cause `yank' to be called directly with
17888 no special treatment. In particular, a simple `C-u' prefix will just
17889 plainly yank the text as it is.
17891 \[1] The test checks if the first non-white line is a heading
17892 and if there are no other headings with fewer stars."
17894 (org-yank-generic 'yank arg))
17896 (defun org-yank-generic (command arg)
17897 "Perform some yank-like command.
17899 This function implements the behavior described in the `org-yank'
17900 documentation. However, it has been generalized to work for any
17901 interactive command with similar behavior."
17903 ;; pretend to be command COMMAND
17904 (setq this-command command)
17907 (call-interactively command)
17909 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
17910 (and (org-kill-is-subtree-p)
17912 (and (looking-at "[ \t]*$")
17915 (buffer-substring (point-at-bol) (point)))))))
17918 ((and subtreep org-yank-folded-subtrees)
17919 (let ((beg (point))
17921 (if (and subtreep org-yank-adjusted-subtrees)
17922 (org-paste-subtree nil nil 'for-yank)
17923 (call-interactively command))
17927 (when (and (bolp) subtreep
17928 (not (setq swallowp
17929 (org-yank-folding-would-swallow-text beg end))))
17930 (or (looking-at outline-regexp)
17931 (re-search-forward (concat "^" outline-regexp) end t))
17932 (while (and (< (point) end) (looking-at outline-regexp))
17934 (org-cycle-show-empty-lines 'folded)
17935 (condition-case nil
17936 (outline-forward-same-level 1)
17937 (error (goto-char end)))))
17940 "Inserted text not folded because that would swallow text"))
17943 (skip-chars-forward " \t\n\r")
17944 (beginning-of-line 1)
17945 (push-mark beg 'nomsg)))
17946 ((and subtreep org-yank-adjusted-subtrees)
17947 (let ((beg (point-at-bol)))
17948 (org-paste-subtree nil nil 'for-yank)
17949 (push-mark beg 'nomsg)))
17951 (call-interactively command))))))
17953 (defun org-yank-folding-would-swallow-text (beg end)
17954 "Would hide-subtree at BEG swallow any text after END?"
17958 (when (or (looking-at outline-regexp)
17959 (re-search-forward (concat "^" outline-regexp) end t))
17960 (setq level (org-outline-level)))
17962 (skip-chars-forward " \t\r\n\v\f")
17964 (and (bolp) (looking-at org-outline-regexp)
17965 (<= (org-outline-level) level)))
17966 nil ; Nothing would be swallowed
17967 t)))) ; something would swallow
17969 (define-key org-mode-map "\C-y" 'org-yank)
17971 (defun org-invisible-p ()
17972 "Check if point is at a character currently not visible."
17973 ;; Early versions of noutline don't have `outline-invisible-p'.
17974 (if (fboundp 'outline-invisible-p)
17975 (outline-invisible-p)
17976 (get-char-property (point) 'invisible)))
17978 (defun org-invisible-p2 ()
17979 "Check if point is at a character currently not visible."
17981 (if (and (eolp) (not (bobp))) (backward-char 1))
17982 ;; Early versions of noutline don't have `outline-invisible-p'.
17983 (if (fboundp 'outline-invisible-p)
17984 (outline-invisible-p)
17985 (get-char-property (point) 'invisible))))
17987 (defun org-back-to-heading (&optional invisible-ok)
17988 "Call `outline-back-to-heading', but provide a better error message."
17989 (condition-case nil
17990 (outline-back-to-heading invisible-ok)
17991 (error (error "Before first headline at position %d in buffer %s"
17992 (point) (current-buffer)))))
17994 (defun org-before-first-heading-p ()
17995 "Before first heading?"
17997 (null (re-search-backward "^\\*+ " nil t))))
17999 (defun org-on-heading-p (&optional ignored)
18000 (outline-on-heading-p t))
18001 (defun org-at-heading-p (&optional ignored)
18002 (outline-on-heading-p t))
18004 (defun org-point-at-end-of-empty-headline ()
18005 "If point is at the end of an empty headline, return t, else nil.
18006 If the heading only contains a TODO keyword, it is still still considered
18008 (and (looking-at "[ \t]*$")
18010 (beginning-of-line 1)
18011 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18013 (defun org-at-heading-or-item-p ()
18014 (or (org-on-heading-p) (org-at-item-p)))
18016 (defun org-on-target-p ()
18017 (or (org-in-regexp org-radio-target-regexp)
18018 (org-in-regexp org-target-regexp)))
18020 (defun org-up-heading-all (arg)
18021 "Move to the heading line of which the present line is a subheading.
18022 This function considers both visible and invisible heading lines.
18023 With argument, move up ARG levels."
18024 (if (fboundp 'outline-up-heading-all)
18025 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18026 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18028 (defun org-up-heading-safe ()
18029 "Move to the heading line of which the present line is a subheading.
18030 This version will not throw an error. It will return the level of the
18031 headline found, or nil if no higher level is found.
18033 Also, this function will be a lot faster than `outline-up-heading',
18034 because it relies on stars being the outline starters. This can really
18035 make a significant difference in outlines with very many siblings."
18036 (let (start-level re)
18037 (org-back-to-heading t)
18038 (setq start-level (funcall outline-level))
18039 (if (equal start-level 1)
18041 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18042 (if (re-search-backward re nil t)
18043 (funcall outline-level)))))
18045 (defun org-first-sibling-p ()
18046 "Is this heading the first child of its parents?"
18048 (let ((re (concat "^" outline-regexp))
18050 (unless (org-at-heading-p t)
18051 (error "Not at a heading"))
18052 (setq level (funcall outline-level))
18054 (if (not (re-search-backward re nil t))
18056 (setq l (funcall outline-level))
18059 (defun org-goto-sibling (&optional previous)
18060 "Goto the next sibling, even if it is invisible.
18061 When PREVIOUS is set, go to the previous sibling instead. Returns t
18062 when a sibling was found. When none is found, return nil and don't
18064 (let ((fun (if previous 're-search-backward 're-search-forward))
18066 (re (concat "^" outline-regexp))
18068 (when (condition-case nil (org-back-to-heading t) (error nil))
18069 (setq level (funcall outline-level))
18071 (or previous (forward-char 1))
18072 (while (funcall fun re nil t)
18073 (setq l (funcall outline-level))
18074 (when (< l level) (goto-char pos) (throw 'exit nil))
18075 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18079 (defun org-show-siblings ()
18080 "Show all siblings of the current headline."
18082 (while (org-goto-sibling) (org-flag-heading nil)))
18084 (while (org-goto-sibling 'previous)
18085 (org-flag-heading nil))))
18087 (defun org-show-hidden-entry ()
18088 "Show an entry where even the heading is hidden."
18092 (defun org-flag-heading (flag &optional entry)
18093 "Flag the current heading. FLAG non-nil means make invisible.
18094 When ENTRY is non-nil, show the entire entry."
18096 (org-back-to-heading t)
18097 ;; Check if we should show the entire entry
18102 (and (outline-next-heading)
18103 (org-flag-heading nil))))
18104 (outline-flag-region (max (point-min) (1- (point)))
18105 (save-excursion (outline-end-of-heading) (point))
18108 (defun org-get-next-sibling ()
18109 "Move to next heading of the same level, and return point.
18110 If there is no such heading, return nil.
18111 This is like outline-next-sibling, but invisible headings are ok."
18112 (let ((level (funcall outline-level)))
18113 (outline-next-heading)
18114 (while (and (not (eobp)) (> (funcall outline-level) level))
18115 (outline-next-heading))
18116 (if (or (eobp) (< (funcall outline-level) level))
18120 (defun org-get-last-sibling ()
18121 "Move to previous heading of the same level, and return point.
18122 If there is no such heading, return nil."
18123 (let ((opoint (point))
18124 (level (funcall outline-level)))
18125 (outline-previous-heading)
18126 (when (and (/= (point) opoint) (outline-on-heading-p t))
18127 (while (and (> (funcall outline-level) level)
18129 (outline-previous-heading))
18130 (if (< (funcall outline-level) level)
18134 (defun org-end-of-subtree (&optional invisible-OK to-heading)
18135 ;; This contains an exact copy of the original function, but it uses
18136 ;; `org-back-to-heading', to make it work also in invisible
18137 ;; trees. And is uses an invisible-OK argument.
18138 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
18139 ;; Furthermore, when used inside Org, finding the end of a large subtree
18140 ;; with many children and grandchildren etc, this can be much faster
18141 ;; than the outline version.
18142 (org-back-to-heading invisible-OK)
18144 (level (funcall outline-level)))
18145 (if (and (org-mode-p) (< level 1000))
18146 ;; A true heading (not a plain list item), in Org-mode
18147 ;; This means we can easily find the end by looking
18148 ;; only for the right number of stars. Using a regexp to do
18149 ;; this is so much faster than using a Lisp loop.
18150 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
18152 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
18153 ;; something else, do it the slow way
18154 (while (and (not (eobp))
18155 (or first (> (funcall outline-level) level)))
18157 (outline-next-heading)))
18159 (if (memq (preceding-char) '(?\n ?\^M))
18161 ;; Go to end of line before heading
18163 (if (memq (preceding-char) '(?\n ?\^M))
18164 ;; leave blank line before heading
18165 (forward-char -1))))))
18168 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
18169 "Use Org version in org-mode, for dramatic speed-up."
18170 (if (eq major-mode 'org-mode)
18172 (org-end-of-subtree nil t)
18173 (unless (eobp) (backward-char 1)))
18176 (defun org-forward-same-level (arg &optional invisible-ok)
18177 "Move forward to the arg'th subheading at same level as this one.
18178 Stop at the first and last subheadings of a superior heading."
18180 (org-back-to-heading invisible-ok)
18182 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18183 (re (format "^\\*\\{1,%d\\} " level))
18187 (while (and (re-search-forward re nil 'move)
18188 (setq l (- (match-end 0) (match-beginning 0) 1))
18191 (progn (backward-char 1) (org-invisible-p)))
18192 (if (< l level) (setq arg 1)))
18193 (setq arg (1- arg)))
18194 (beginning-of-line 1)))
18196 (defun org-backward-same-level (arg &optional invisible-ok)
18197 "Move backward to the arg'th subheading at same level as this one.
18198 Stop at the first and last subheadings of a superior heading."
18200 (org-back-to-heading)
18202 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18203 (re (format "^\\*\\{1,%d\\} " level))
18206 (while (and (re-search-backward re nil 'move)
18207 (setq l (- (match-end 0) (match-beginning 0) 1))
18211 (if (< l level) (setq arg 1)))
18212 (setq arg (1- arg)))))
18214 (defun org-show-subtree ()
18215 "Show everything after this heading at deeper levels."
18216 (outline-flag-region
18219 (org-end-of-subtree t t))
18222 (defun org-show-entry ()
18223 "Show the body directly following this heading.
18224 Show the heading too, if it is currently invisible."
18227 (condition-case nil
18229 (org-back-to-heading t)
18230 (outline-flag-region
18231 (max (point-min) (1- (point)))
18233 (if (re-search-forward
18234 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
18235 (match-beginning 1)
18238 (org-cycle-hide-drawers 'children))
18241 (defun org-make-options-regexp (kwds &optional extra)
18242 "Make a regular expression for keyword lines."
18246 (mapconcat 'regexp-quote kwds "\\|")
18247 (if extra (concat "\\|" extra))
18251 ;; Make isearch reveal the necessary context
18252 (defun org-isearch-end ()
18253 "Reveal context after isearch exits."
18254 (when isearch-success ; only if search was successful
18255 (if (featurep 'xemacs)
18256 ;; Under XEmacs, the hook is run in the correct place,
18257 ;; we directly show the context.
18258 (org-show-context 'isearch)
18259 ;; In Emacs the hook runs *before* restoring the overlays.
18260 ;; So we have to use a one-time post-command-hook to do this.
18261 ;; (Emacs 22 has a special variable, see function `org-mode')
18262 (unless (and (boundp 'isearch-mode-end-hook-quit)
18263 isearch-mode-end-hook-quit)
18264 ;; Only when the isearch was not quitted.
18265 (org-add-hook 'post-command-hook 'org-isearch-post-command
18266 'append 'local)))))
18268 (defun org-isearch-post-command ()
18269 "Remove self from hook, and show context."
18270 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
18271 (org-show-context 'isearch))
18274 ;;;; Integration with and fixes for other packages
18278 (defvar org-imenu-markers nil
18279 "All markers currently used by Imenu.")
18280 (make-variable-buffer-local 'org-imenu-markers)
18282 (defun org-imenu-new-marker (&optional pos)
18283 "Return a new marker for use by Imenu, and remember the marker."
18284 (let ((m (make-marker)))
18285 (move-marker m (or pos (point)))
18286 (push m org-imenu-markers)
18289 (defun org-imenu-get-tree ()
18290 "Produce the index for Imenu."
18291 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
18292 (setq org-imenu-markers nil)
18293 (let* ((n org-imenu-depth)
18294 (re (concat "^" outline-regexp))
18295 (subs (make-vector (1+ n) nil))
18301 (goto-char (point-max))
18302 (while (re-search-backward re nil t)
18303 (setq level (org-reduced-level (funcall outline-level)))
18305 (looking-at org-complex-heading-regexp)
18306 (setq head (org-link-display-format
18307 (org-match-string-no-properties 4))
18308 m (org-imenu-new-marker))
18309 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
18310 (if (>= level last-level)
18311 (push (cons head m) (aref subs level))
18312 (push (cons head (aref subs (1+ level))) (aref subs level))
18313 (loop for i from (1+ level) to n do (aset subs i nil)))
18314 (setq last-level level)))))
18317 (eval-after-load "imenu"
18319 (add-hook 'imenu-after-jump-hook
18321 (if (eq major-mode 'org-mode)
18322 (org-show-context 'org-goto))))))
18324 (defun org-link-display-format (link)
18325 "Replace a link with either the description, or the link target
18326 if no description is present"
18328 (if (string-match org-bracket-link-analytic-regexp link)
18329 (replace-match (if (match-end 5)
18330 (match-string 5 link)
18331 (concat (match-string 1 link)
18332 (match-string 3 link)))
18336 ;; Speedbar support
18338 (defvar org-speedbar-restriction-lock-overlay (org-make-overlay 1 1)
18339 "Overlay marking the agenda restriction line in speedbar.")
18340 (org-overlay-put org-speedbar-restriction-lock-overlay
18341 'face 'org-agenda-restriction-lock)
18342 (org-overlay-put org-speedbar-restriction-lock-overlay
18343 'help-echo "Agendas are currently limited to this item.")
18344 (org-detach-overlay org-speedbar-restriction-lock-overlay)
18346 (defun org-speedbar-set-agenda-restriction ()
18347 "Restrict future agenda commands to the location at point in speedbar.
18348 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
18350 (require 'org-agenda)
18351 (let (p m tp np dir txt)
18353 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18355 (setq m (get-text-property p 'org-imenu-marker))
18356 (with-current-buffer (marker-buffer m)
18358 (org-agenda-set-restriction-lock 'subtree)))
18359 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18360 'speedbar-function 'speedbar-find-file))
18361 (setq tp (previous-single-property-change
18362 (1+ p) 'speedbar-function)
18363 np (next-single-property-change
18364 tp 'speedbar-function)
18365 dir (speedbar-line-directory)
18366 txt (buffer-substring-no-properties (or tp (point-min))
18367 (or np (point-max))))
18368 (with-current-buffer (find-file-noselect
18369 (let ((default-directory dir))
18370 (expand-file-name txt)))
18371 (unless (org-mode-p)
18372 (error "Cannot restrict to non-Org-mode file"))
18373 (org-agenda-set-restriction-lock 'file)))
18374 (t (error "Don't know how to restrict Org-mode's agenda")))
18375 (org-move-overlay org-speedbar-restriction-lock-overlay
18376 (point-at-bol) (point-at-eol))
18377 (setq current-prefix-arg nil)
18378 (org-agenda-maybe-redo)))
18380 (eval-after-load "speedbar"
18382 (speedbar-add-supported-extension ".org")
18383 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
18384 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
18385 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
18386 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
18387 (add-hook 'speedbar-visiting-tag-hook
18388 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
18391 ;;; Fixes and Hacks for problems with other packages
18393 ;; Make flyspell not check words in links, to not mess up our keymap
18394 (defun org-mode-flyspell-verify ()
18395 "Don't let flyspell put overlays at active buttons."
18396 (and (not (get-text-property (point) 'keymap))
18397 (not (get-text-property (point) 'org-no-flyspell))))
18399 (defun org-remove-flyspell-overlays-in (beg end)
18400 "Remove flyspell overlays in region."
18401 (and (org-bound-and-true-p flyspell-mode)
18402 (fboundp 'flyspell-delete-region-overlays)
18403 (flyspell-delete-region-overlays beg end))
18404 (add-text-properties beg end '(org-no-flyspell t)))
18406 ;; Make `bookmark-jump' shows the jump location if it was hidden.
18407 (eval-after-load "bookmark"
18408 '(if (boundp 'bookmark-after-jump-hook)
18409 ;; We can use the hook
18410 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
18411 ;; Hook not available, use advice
18412 (defadvice bookmark-jump (after org-make-visible activate)
18413 "Make the position visible."
18414 (org-bookmark-jump-unhide))))
18416 ;; Make sure saveplace shows the location if it was hidden
18417 (eval-after-load "saveplace"
18418 '(defadvice save-place-find-file-hook (after org-make-visible activate)
18419 "Make the position visible."
18420 (org-bookmark-jump-unhide)))
18422 ;; Make sure ecb shows the location if it was hidden
18423 (eval-after-load "ecb"
18424 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
18425 "Make hierarchy visible when jumping into location from ECB tree buffer."
18426 (if (eq major-mode 'org-mode)
18427 (org-show-context))))
18429 (defun org-bookmark-jump-unhide ()
18430 "Unhide the current position, to show the bookmark location."
18432 (or (org-invisible-p)
18433 (save-excursion (goto-char (max (point-min) (1- (point))))
18434 (org-invisible-p)))
18435 (org-show-context 'bookmark-jump)))
18437 ;; Make session.el ignore our circular variable
18438 (eval-after-load "session"
18439 '(add-to-list 'session-globals-exclude 'org-mark-ring))
18441 ;;;; Experimental code
18443 (defun org-closed-in-range ()
18444 "Sparse tree of items closed in a certain time range.
18445 Still experimental, may disappear in the future."
18447 ;; Get the time interval from the user.
18448 (let* ((time1 (org-float-time
18449 (org-read-date nil 'to-time nil "Starting date: ")))
18450 (time2 (org-float-time
18451 (org-read-date nil 'to-time nil "End date:")))
18452 ;; callback function
18453 (callback (lambda ()
18456 (apply 'encode-time
18457 (org-parse-time-string
18458 (match-string 1))))))
18459 ;; check if time in interval
18460 (and (>= time time1) (<= time time2))))))
18461 ;; make tree, check each match with the callback
18462 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
18468 (run-hooks 'org-load-hook)
18470 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
18472 ;;; org.el ends here