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
))
92 (require 'org-footnote
)
94 ;;;; Customization variables
98 (defconst org-version
"6.33trans"
99 "The version number of the file org.el.")
101 (defun org-version (&optional here
)
102 "Show the org-mode version in the echo area.
103 With prefix arg HERE, insert it at point."
105 (let* ((origin default-directory
)
106 (version org-version
)
108 (dir (concat (file-name-directory (locate-library "org")) "../" )))
109 (when (and (file-exists-p (expand-file-name ".git" dir
))
110 (executable-find "git"))
114 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
115 (with-current-buffer "*Shell Command Output*"
116 (goto-char (point-min))
117 (setq git-version
(buffer-substring (point) (point-at-eol))))
118 (subst-char-in-string ?- ?. git-version t
)
119 (when (string-match "\\S-"
120 (shell-command-to-string
121 "git diff-index --name-only HEAD --"))
122 (setq git-version
(concat git-version
".dirty")))
123 (setq version
(concat version
" (" git-version
")"))))
125 (setq version
(format "Org-mode version %s" version
))
126 (if here
(insert version
))
129 ;;; Compatibility constants
131 ;;; The custom variables
134 "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
" docview: Links to doc-view buffers" org-docview
)
193 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
194 (const :tag
" id: Global IDs for identifying entries" org-id
)
195 (const :tag
" info: Links to Info nodes" org-info
)
196 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
197 (const :tag
" habit: Track your consistency with habits" org-habit
)
198 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
199 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
200 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
201 (const :tag
" mew Links to Mew folders/messages" org-mew
)
202 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
203 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
204 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
205 (const :tag
" vm: Links to VM folders/messages" org-vm
)
206 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
207 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
208 (const :tag
" mouse: Additional mouse support" org-mouse
)
210 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
211 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
212 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
213 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
214 (const :tag
"C collector: Collect properties into tables" org-collector
)
215 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
216 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
217 (const :tag
"C eval: Include command output as text" org-eval
)
218 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
219 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
220 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
221 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
222 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
224 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
226 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
227 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
228 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
229 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
230 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
231 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
232 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
233 (const :tag
"C R: Computation using the R language" org-R
)
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 special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
238 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
239 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
240 (const :tag
"C track: Keep up with Org-mode development" org-track
)
241 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
243 (defcustom org-support-shift-select nil
244 "Non-nil means, make shift-cursor commands select text when possible.
246 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
247 selecting a region, or enlarge thusly regions started in this way.
248 In Org-mode, in special contexts, these same keys are used for other
249 purposes, important enough to compete with shift selection. Org tries
250 to balance these needs by supporting `shift-select-mode' outside these
251 special contexts, under control of this variable.
253 The default of this variable is nil, to avoid confusing behavior. Shifted
254 cursor keys will then execute Org commands in the following contexts:
255 - on a headline, changing TODO state (left/right) and priority (up/down)
256 - on a time stamp, changing the time
257 - in a plain list item, changing the bullet type
258 - in a property definition line, switching between allowed values
259 - in the BEGIN line of a clock table (changing the time block).
260 Outside these contexts, the commands will throw an error.
262 When this variable is t and the cursor is not in a special context,
263 Org-mode will support shift-selection for making and enlarging regions.
264 To make this more effective, the bullet cycling will no longer happen
265 anywhere in an item line, but only if the cursor is exactly on the bullet.
267 If you set this variable to the symbol `always', then the keys
268 will not be special in headlines, property lines, and item lines, to make
269 shift selection work there as well. If this is what you want, you can
270 use the following alternative commands: `C-c C-t' and `C-c ,' to
271 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
272 TODO sets, `C-c -' to cycle item bullet types, and properties can be
273 edited by hand or in column view.
275 However, when the cursor is on a timestamp, shift-cursor commands
276 will still edit the time stamp - this is just too good to give up.
278 XEmacs user should have this variable set to nil, because shift-select-mode
282 (const :tag
"Never" nil
)
283 (const :tag
"When outside special context" t
)
284 (const :tag
"Everywhere except timestamps" always
)))
286 (defgroup org-startup nil
287 "Options concerning startup of Org-mode."
291 (defcustom org-startup-folded t
292 "Non-nil means, entering Org-mode will switch to OVERVIEW.
293 This can also be configured on a per-file basis by adding one of
294 the following lines anywhere in the buffer:
296 #+STARTUP: fold (or `overview', this is equivalent)
297 #+STARTUP: nofold (or `showall', this is equivalent)
299 #+STARTUP: showeverything"
302 (const :tag
"nofold: show all" nil
)
303 (const :tag
"fold: overview" t
)
304 (const :tag
"content: all headlines" content
)
305 (const :tag
"show everything, even drawers" showeverything
)))
307 (defcustom org-startup-truncated t
308 "Non-nil means, entering Org-mode will set `truncate-lines'.
309 This is useful since some lines containing links can be very long and
310 uninteresting. Also tables look terrible when wrapped."
314 (defcustom org-startup-indented nil
315 "Non-nil means, turn on `org-indent-mode' on startup.
316 This can also be configured on a per-file basis by adding one of
317 the following lines anywhere in the buffer:
321 :group
'org-structure
323 (const :tag
"Not" nil
)
324 (const :tag
"Globally (slow on startup in large files)" t
)))
326 (defcustom org-startup-with-beamer-mode nil
327 "Non-nil means, turn on `org-beamer-mode' on startup.
328 This can also be configured on a per-file basis by adding one of
329 the following lines anywhere in the buffer:
335 (defcustom org-startup-align-all-tables nil
336 "Non-nil means, align all tables when visiting a file.
337 This is useful when the column width in tables is forced with <N> cookies
338 in table fields. Such tables will look correct only after the first re-align.
339 This can also be configured on a per-file basis by adding one of
340 the following lines anywhere in the buffer:
346 (defcustom org-insert-mode-line-in-empty-file nil
347 "Non-nil means insert the first line setting Org-mode in empty files.
348 When the function `org-mode' is called interactively in an empty file, this
349 normally means that the file name does not automatically trigger Org-mode.
350 To ensure that the file will always be in Org-mode in the future, a
351 line enforcing Org-mode will be inserted into the buffer, if this option
356 (defcustom org-replace-disputed-keys nil
357 "Non-nil means use alternative key bindings for some keys.
358 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
359 These keys are also used by other packages like shift-selection-mode'
360 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
361 If you want to use Org-mode together with one of these other modes,
362 or more generally if you would like to move some Org-mode commands to
363 other keys, set this variable and configure the keys with the variable
366 This option is only relevant at load-time of Org-mode, and must be set
367 *before* org.el is loaded. Changing it requires a restart of Emacs to
372 (defcustom org-use-extra-keys nil
373 "Non-nil means use extra key sequence definitions for certain
374 commands. This happens automatically if you run XEmacs or if
375 window-system is nil. This variable lets you do the same
376 manually. You must set it before loading org.
378 Example: on Carbon Emacs 22 running graphically, with an external
379 keyboard on a Powerbook, the default way of setting M-left might
380 not work for either Alt or ESC. Setting this variable will make
385 (if (fboundp 'defvaralias
)
386 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
388 (defcustom org-disputed-keys
389 '(([(shift up
)] .
[(meta p
)])
390 ([(shift down
)] .
[(meta n
)])
391 ([(shift left
)] .
[(meta -
)])
392 ([(shift right
)] .
[(meta +)])
393 ([(control shift right
)] .
[(meta shift
+)])
394 ([(control shift left
)] .
[(meta shift -
)]))
395 "Keys for which Org-mode and other modes compete.
396 This is an alist, cars are the default keys, second element specifies
397 the alternative to use when `org-replace-disputed-keys' is t.
399 Keys can be specified in any syntax supported by `define-key'.
400 The value of this option takes effect only at Org-mode's startup,
401 therefore you'll have to restart Emacs to apply it after changing."
406 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
407 Or return the original if not disputed."
408 (if org-replace-disputed-keys
409 (let* ((nkey (key-description key
))
410 (x (org-find-if (lambda (x)
411 (equal (key-description (car x
)) nkey
))
416 (defun org-find-if (predicate seq
)
419 (if (funcall predicate
(car seq
))
420 (throw 'exit
(car seq
))
423 (defun org-defkey (keymap key def
)
424 "Define a key, possibly translated, as returned by `org-key'."
425 (define-key keymap
(org-key key
) def
))
427 (defcustom org-ellipsis nil
428 "The ellipsis to use in the Org-mode outline.
429 When nil, just use the standard three dots. When a string, use that instead,
430 When a face, use the standard 3 dots, but with the specified face.
431 The change affects only Org-mode (which will then use its own display table).
432 Changing this requires executing `M-x org-mode' in a buffer to become
435 :type
'(choice (const :tag
"Default" nil
)
436 (face :tag
"Face" :value org-warning
)
437 (string :tag
"String" :value
"...#")))
439 (defvar org-display-table nil
440 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
442 (defgroup org-keywords nil
443 "Keywords in Org-mode."
447 (defcustom org-deadline-string
"DEADLINE:"
448 "String to mark deadline entries.
449 A deadline is this string, followed by a time stamp. Should be a word,
450 terminated by a colon. You can insert a schedule keyword and
451 a timestamp with \\[org-deadline].
452 Changes become only effective after restarting Emacs."
456 (defcustom org-scheduled-string
"SCHEDULED:"
457 "String to mark scheduled TODO entries.
458 A schedule is this string, followed by a time stamp. Should be a word,
459 terminated by a colon. You can insert a schedule keyword and
460 a timestamp with \\[org-schedule].
461 Changes become only effective after restarting Emacs."
465 (defcustom org-closed-string
"CLOSED:"
466 "String used as the prefix for timestamps logging closing a TODO entry."
470 (defcustom org-clock-string
"CLOCK:"
471 "String used as prefix for timestamps clocking work hours on an item."
475 (defcustom org-comment-string
"COMMENT"
476 "Entries starting with this keyword will never be exported.
477 An entry can be toggled between COMMENT and normal with
478 \\[org-toggle-comment].
479 Changes become only effective after restarting Emacs."
483 (defcustom org-quote-string
"QUOTE"
484 "Entries starting with this keyword will be exported in fixed-width font.
485 Quoting applies only to the text in the entry following the headline, and does
486 not extend beyond the next headline, even if that is lower level.
487 An entry can be toggled between QUOTE and normal with
488 \\[org-toggle-fixed-width-section]."
492 (defconst org-repeat-re
493 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
494 "Regular expression for specifying repeated events.
495 After a match, group 1 contains the repeat expression.")
497 (defgroup org-structure nil
498 "Options concerning the general structure of Org-mode files."
502 (defgroup org-reveal-location nil
503 "Options about how to make context of a location visible."
504 :tag
"Org Reveal Location"
505 :group
'org-structure
)
507 (defconst org-context-choice
509 (const :tag
"Always" t
)
510 (const :tag
"Never" nil
)
511 (repeat :greedy t
:tag
"Individual contexts"
513 (choice :tag
"Context"
520 (const bookmark-jump
)
524 "Contexts for the reveal options.")
526 (defcustom org-show-hierarchy-above
'((default . t
))
527 "Non-nil means, show full hierarchy when revealing a location.
528 Org-mode often shows locations in an org-mode file which might have
529 been invisible before. When this is set, the hierarchy of headings
530 above the exposed location is shown.
531 Turning this off for example for sparse trees makes them very compact.
532 Instead of t, this can also be an alist specifying this option for different
533 contexts. Valid contexts are
534 agenda when exposing an entry from the agenda
535 org-goto when using the command `org-goto' on key C-c C-j
536 occur-tree when using the command `org-occur' on key C-c /
537 tags-tree when constructing a sparse tree based on tags matches
538 link-search when exposing search matches associated with a link
539 mark-goto when exposing the jump goal of a mark
540 bookmark-jump when exposing a bookmark location
541 isearch when exiting from an incremental search
542 default default for all contexts not set explicitly"
543 :group
'org-reveal-location
544 :type org-context-choice
)
546 (defcustom org-show-following-heading
'((default . nil
))
547 "Non-nil means, show following heading when revealing a location.
548 Org-mode often shows locations in an org-mode file which might have
549 been invisible before. When this is set, the heading following the
551 Turning this off for example for sparse trees makes them very compact,
552 but makes it harder to edit the location of the match. In such a case,
553 use the command \\[org-reveal] to show more context.
554 Instead of t, this can also be an alist specifying this option for different
555 contexts. See `org-show-hierarchy-above' for valid contexts."
556 :group
'org-reveal-location
557 :type org-context-choice
)
559 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
560 "Non-nil means, show all sibling heading when revealing a location.
561 Org-mode often shows locations in an org-mode file which might have
562 been invisible before. When this is set, the sibling of the current entry
563 heading are all made visible. If `org-show-hierarchy-above' is t,
564 the same happens on each level of the hierarchy above the current entry.
566 By default this is on for the isearch context, off for all other contexts.
567 Turning this off for example for sparse trees makes them very compact,
568 but makes it harder to edit the location of the match. In such a case,
569 use the command \\[org-reveal] to show more context.
570 Instead of t, this can also be an alist specifying this option for different
571 contexts. See `org-show-hierarchy-above' for valid contexts."
572 :group
'org-reveal-location
573 :type org-context-choice
)
575 (defcustom org-show-entry-below
'((default . nil
))
576 "Non-nil means, show the entry below a headline when revealing a location.
577 Org-mode often shows locations in an org-mode file which might have
578 been invisible before. When this is set, the text below the headline that is
579 exposed is also shown.
581 By default this is off for all contexts.
582 Instead of t, this can also be an alist specifying this option for different
583 contexts. See `org-show-hierarchy-above' for valid contexts."
584 :group
'org-reveal-location
585 :type org-context-choice
)
587 (defcustom org-indirect-buffer-display
'other-window
588 "How should indirect tree buffers be displayed?
589 This applies to indirect buffers created with the commands
590 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
592 current-window Display in the current window
593 other-window Just display in another window.
594 dedicated-frame Create one new frame, and re-use it each time.
595 new-frame Make a new frame each time. Note that in this case
596 previously-made indirect buffers are kept, and you need to
597 kill these buffers yourself."
598 :group
'org-structure
599 :group
'org-agenda-windows
601 (const :tag
"In current window" current-window
)
602 (const :tag
"In current frame, other window" other-window
)
603 (const :tag
"Each time a new frame" new-frame
)
604 (const :tag
"One dedicated frame" dedicated-frame
)))
606 (defcustom org-use-speed-commands nil
607 "Non-nil means, activate single letter commands at beginning of a headline.
608 This may also be a function to test for appropriate locations where speed
609 commands should be active."
610 :group
'org-structure
612 (const :tag
"Never" nil
)
613 (const :tag
"At beginning of headline stars" t
)
616 (defcustom org-speed-commands-user nil
617 "Alist of additional speed commands.
618 This list will be checked before `org-speed-commands-default'
619 when the variable `org-use-speed-commands' is non-nil
620 and when the cursor is at the beginning of a headline.
621 The car if each entry is a string with a single letter, which must
622 be assigned to `self-insert-command' in the global map.
623 The cdr is either a command to be called interactively, a function
624 to be called, or a form to be evaluated.
625 An entry that is just a list with a single string will be interpreted
626 as a descriptive headline that will be added when listing the speed
627 copmmands in the Help buffer using the `?' speed command."
628 :group
'org-structure
629 :type
'(repeat :value
("k" . ignore
)
630 (choice :value
("k" . ignore
)
631 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
632 (cons :tag
"Letter and Command"
633 (string :tag
"Command letter")
638 (defgroup org-cycle nil
639 "Options concerning visibility cycling in Org-mode."
641 :group
'org-structure
)
643 (defcustom org-cycle-skip-children-state-if-no-children t
644 "Non-nil means, skip CHILDREN state in entries that don't have any."
648 (defcustom org-cycle-max-level nil
649 "Maximum level which should still be subject to visibility cycling.
650 Levels higher than this will, for cycling, be treated as text, not a headline.
651 When `org-odd-levels-only' is set, a value of N in this variable actually
652 means 2N-1 stars as the limiting headline.
653 When nil, cycle all levels.
654 Note that the limiting level of cycling is also influenced by
655 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
656 `org-inlinetask-min-level' is, cycling will be limited to levels one less
660 (const :tag
"No limit" nil
)
661 (integer :tag
"Maximum level")))
663 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
664 "Names of drawers. Drawers are not opened by cycling on the headline above.
665 Drawers only open with a TAB on the drawer line itself. A drawer looks like
670 The drawer \"PROPERTIES\" is special for capturing properties through
673 Drawers can be defined on the per-file basis with a line like:
675 #+DRAWERS: HIDDEN STATE PROPERTIES"
676 :group
'org-structure
678 :type
'(repeat (string :tag
"Drawer Name")))
680 (defcustom org-hide-block-startup nil
681 "Non-nil means, , entering Org-mode will fold all blocks.
682 This can also be set in on a per-file basis with
684 #+STARTUP: hideblocks
685 #+STARTUP: showblocks"
690 (defcustom org-cycle-global-at-bob nil
691 "Cycle globally if cursor is at beginning of buffer and not at a headline.
692 This makes it possible to do global cycling without having to use S-TAB or
693 C-u TAB. For this special case to work, the first line of the buffer
694 must not be a headline - it may be empty or some other text. When used in
695 this way, `org-cycle-hook' is disables temporarily, to make sure the
696 cursor stays at the beginning of the buffer.
697 When this option is nil, don't do anything special at the beginning
702 (defcustom org-cycle-level-after-item
/entry-creation t
703 "Non-nil means, cycle entry level or item indentation in new empty entries.
705 When the cursor is at the end of an empty headline, i.e with only stars
706 and maybe a TODO keyword, TAB will then switch the entry to become a child,
707 and then all possible anchestor states, before returning to the original state.
708 This makes data entry extremely fast: M-RET to create a new headline,
709 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
711 When the cursor is at the end of an empty plain list item, one TAB will
712 make it a subitem, two or more tabs will back up to make this an item
713 higher up in the item hierarchy."
717 (defcustom org-cycle-emulate-tab t
718 "Where should `org-cycle' emulate TAB.
720 white Only in completely white lines
721 whitestart Only at the beginning of lines, before the first non-white char
722 t Everywhere except in headlines
723 exc-hl-bol Everywhere except at the start of a headline
724 If TAB is used in a place where it does not emulate TAB, the current subtree
725 visibility is cycled."
727 :type
'(choice (const :tag
"Never" nil
)
728 (const :tag
"Only in completely white lines" white
)
729 (const :tag
"Before first char in a line" whitestart
)
730 (const :tag
"Everywhere except in headlines" t
)
731 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
734 (defcustom org-cycle-separator-lines
2
735 "Number of empty lines needed to keep an empty line between collapsed trees.
736 If you leave an empty line between the end of a subtree and the following
737 headline, this empty line is hidden when the subtree is folded.
738 Org-mode will leave (exactly) one empty line visible if the number of
739 empty lines is equal or larger to the number given in this variable.
740 So the default 2 means, at least 2 empty lines after the end of a subtree
741 are needed to produce free space between a collapsed subtree and the
744 If the number is negative, and the number of empty lines is at least -N,
745 all empty lines are shown.
747 Special case: when 0, never leave empty lines in collapsed view."
750 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
752 (defcustom org-pre-cycle-hook nil
753 "Hook that is run before visibility cycling is happening.
754 The function(s) in this hook must accept a single argument which indicates
755 the new state that will be set right after running this hook. The
756 argument is a symbol. Before a global state change, it can have the values
757 `overview', `content', or `all'. Before a local state change, it can have
758 the values `folded', `children', or `subtree'."
762 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
763 org-cycle-hide-drawers
764 org-cycle-show-empty-lines
765 org-optimize-window-after-visibility-change
)
766 "Hook that is run after `org-cycle' has changed the buffer visibility.
767 The function(s) in this hook must accept a single argument which indicates
768 the new state that was set by the most recent `org-cycle' command. The
769 argument is a symbol. After a global state change, it can have the values
770 `overview', `content', or `all'. After a local state change, it can have
771 the values `folded', `children', or `subtree'."
775 (defgroup org-edit-structure nil
776 "Options concerning structure editing in Org-mode."
777 :tag
"Org Edit Structure"
778 :group
'org-structure
)
780 (defcustom org-odd-levels-only nil
781 "Non-nil means, skip even levels and only use odd levels for the outline.
782 This has the effect that two stars are being added/taken away in
783 promotion/demotion commands. It also influences how levels are
784 handled by the exporters.
785 Changing it requires restart of `font-lock-mode' to become effective
786 for fontification also in regions already fontified.
787 You may also set this on a per-file basis by adding one of the following
792 :group
'org-edit-structure
793 :group
'org-font-lock
796 (defcustom org-adapt-indentation t
797 "Non-nil means, adapt indentation to outline node level.
799 When this variable is set, Org assumes that you write outlines by
800 indenting text in each node to align with the headline (after the stars).
801 The following issues are influenced by this variable:
803 - When this is set and the *entire* text in an entry is indented, the
804 indentation is increased by one space in a demotion command, and
805 decreased by one in a promotion command. If any line in the entry
806 body starts with text at column 0, indentation is not changed at all.
808 - Property drawers and planning information is inserted indented when
809 this variable s set. When nil, they will not be indented.
811 - TAB indents a line relative to context. The lines below a headline
812 will be indented when this variable is set.
814 Note that this is all about true indentation, by adding and removing
815 space characters. See also `org-indent.el' which does level-dependent
816 indentation in a virtual way, i.e. at display time in Emacs."
817 :group
'org-edit-structure
820 (defcustom org-special-ctrl-a
/e nil
821 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
823 When t, `C-a' will bring back the cursor to the beginning of the
824 headline text, i.e. after the stars and after a possible TODO keyword.
825 In an item, this will be the position after the bullet.
826 When the cursor is already at that position, another `C-a' will bring
827 it to the beginning of the line.
829 `C-e' will jump to the end of the headline, ignoring the presence of tags
830 in the headline. A second `C-e' will then jump to the true end of the
831 line, after any tags. This also means that, when this variable is
832 non-nil, `C-e' also will never jump beyond the end of the heading of a
833 folded section, i.e. not after the ellipses.
835 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
836 going to the true line boundary first. Only a directly following, identical
837 keypress will bring the cursor to the special positions.
839 This may also be a cons cell where the behavior for `C-a' and `C-e' is
841 :group
'org-edit-structure
843 (const :tag
"off" nil
)
844 (const :tag
"on: after stars/bullet and before tags first" t
)
845 (const :tag
"reversed: true line boundary first" reversed
)
846 (cons :tag
"Set C-a and C-e separately"
847 (choice :tag
"Special C-a"
848 (const :tag
"off" nil
)
849 (const :tag
"on: after stars/bullet first" t
)
850 (const :tag
"reversed: before stars/bullet first" reversed
))
851 (choice :tag
"Special C-e"
852 (const :tag
"off" nil
)
853 (const :tag
"on: before tags first" t
)
854 (const :tag
"reversed: after tags first" reversed
)))))
855 (if (fboundp 'defvaralias
)
856 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
858 (defcustom org-special-ctrl-k nil
859 "Non-nil means `C-k' will behave specially in headlines.
860 When nil, `C-k' will call the default `kill-line' command.
861 When t, the following will happen while the cursor is in the headline:
863 - When the cursor is at the beginning of a headline, kill the entire
864 line and possible the folded subtree below the line.
865 - When in the middle of the headline text, kill the headline up to the tags.
866 - When after the headline text, kill the tags."
867 :group
'org-edit-structure
870 (defcustom org-yank-folded-subtrees t
871 "Non-nil means, when yanking subtrees, fold them.
872 If the kill is a single subtree, or a sequence of subtrees, i.e. if
873 it starts with a heading and all other headings in it are either children
874 or siblings, then fold all the subtrees. However, do this only if no
875 text after the yank would be swallowed into a folded tree by this action."
876 :group
'org-edit-structure
879 (defcustom org-yank-adjusted-subtrees nil
880 "Non-nil means, when yanking subtrees, adjust the level.
881 With this setting, `org-paste-subtree' is used to insert the subtree, see
882 this function for details."
883 :group
'org-edit-structure
886 (defcustom org-M-RET-may-split-line
'((default . t
))
887 "Non-nil means, M-RET will split the line at the cursor position.
888 When nil, it will go to the end of the line before making a
890 You may also set this option in a different way for different
891 contexts. Valid contexts are:
893 headline when creating a new headline
894 item when creating a new item
895 table in a table field
896 default the value to be used for all contexts not explicitly
898 :group
'org-structure
901 (const :tag
"Always" t
)
902 (const :tag
"Never" nil
)
903 (repeat :greedy t
:tag
"Individual contexts"
905 (choice :tag
"Context"
913 (defcustom org-insert-heading-respect-content nil
914 "Non-nil means, insert new headings after the current subtree.
915 When nil, the new heading is created directly after the current line.
916 The commands \\[org-insert-heading-respect-content] and
917 \\[org-insert-todo-heading-respect-content] turn this variable on
918 for the duration of the command."
919 :group
'org-structure
922 (defcustom org-blank-before-new-entry
'((heading . auto
)
923 (plain-list-item . auto
))
924 "Should `org-insert-heading' leave a blank line before new heading/item?
925 The value is an alist, with `heading' and `plain-list-item' as car,
926 and a boolean flag as cdr. For plain lists, if the variable
927 `org-empty-line-terminates-plain-lists' is set, the setting here
928 is ignored and no empty line is inserted, to keep the list in tact."
929 :group
'org-edit-structure
931 (cons (const heading
)
932 (choice (const :tag
"Never" nil
)
933 (const :tag
"Always" t
)
934 (const :tag
"Auto" auto
)))
935 (cons (const plain-list-item
)
936 (choice (const :tag
"Never" nil
)
937 (const :tag
"Always" t
)
938 (const :tag
"Auto" auto
)))))
940 (defcustom org-insert-heading-hook nil
941 "Hook being run after inserting a new heading."
942 :group
'org-edit-structure
945 (defcustom org-enable-fixed-width-editor t
946 "Non-nil means, lines starting with \":\" are treated as fixed-width.
947 This currently only means, they are never auto-wrapped.
948 When nil, such lines will be treated like ordinary lines.
949 See also the QUOTE keyword."
950 :group
'org-edit-structure
954 (defcustom org-goto-auto-isearch t
955 "Non-nil means, typing characters in org-goto starts incremental search."
956 :group
'org-edit-structure
959 (defgroup org-sparse-trees nil
960 "Options concerning sparse trees in Org-mode."
961 :tag
"Org Sparse Trees"
962 :group
'org-structure
)
964 (defcustom org-highlight-sparse-tree-matches t
965 "Non-nil means, highlight all matches that define a sparse tree.
966 The highlights will automatically disappear the next time the buffer is
967 changed by an edit command."
968 :group
'org-sparse-trees
971 (defcustom org-remove-highlights-with-change t
972 "Non-nil means, any change to the buffer will remove temporary highlights.
973 Such highlights are created by `org-occur' and `org-clock-display'.
974 When nil, `C-c C-c needs to be used to get rid of the highlights.
975 The highlights created by `org-preview-latex-fragment' always need
976 `C-c C-c' to be removed."
977 :group
'org-sparse-trees
982 (defcustom org-occur-hook
'(org-first-headline-recenter)
983 "Hook that is run after `org-occur' has constructed a sparse tree.
984 This can be used to recenter the window to show as much of the structure
986 :group
'org-sparse-trees
989 (defgroup org-imenu-and-speedbar nil
990 "Options concerning imenu and speedbar in Org-mode."
991 :tag
"Org Imenu and Speedbar"
992 :group
'org-structure
)
994 (defcustom org-imenu-depth
2
995 "The maximum level for Imenu access to Org-mode headlines.
996 This also applied for speedbar access."
997 :group
'org-imenu-and-speedbar
1000 (defgroup org-table nil
1001 "Options concerning tables in Org-mode."
1005 (defcustom org-enable-table-editor
'optimized
1006 "Non-nil means, lines starting with \"|\" are handled by the table editor.
1007 When nil, such lines will be treated like ordinary lines.
1009 When equal to the symbol `optimized', the table editor will be optimized to
1011 - Automatic overwrite mode in front of whitespace in table fields.
1012 This makes the structure of the table stay in tact as long as the edited
1013 field does not exceed the column width.
1014 - Minimize the number of realigns. Normally, the table is aligned each time
1015 TAB or RET are pressed to move to another field. With optimization this
1016 happens only if changes to a field might have changed the column width.
1017 Optimization requires replacing the functions `self-insert-command',
1018 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1019 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1020 very good at guessing when a re-align will be necessary, but you can always
1021 force one with \\[org-ctrl-c-ctrl-c].
1023 If you would like to use the optimized version in Org-mode, but the
1024 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1026 This variable can be used to turn on and off the table editor during a session,
1027 but in order to toggle optimization, a restart is required.
1029 See also the variable `org-table-auto-blank-field'."
1032 (const :tag
"off" nil
)
1034 (const :tag
"on, optimized" optimized
)))
1036 (defcustom org-self-insert-cluster-for-undo t
1037 "Non-nil means cluster self-insert commands for undo when possible.
1038 If this is set, then, like in the Emacs command loop, 20 consecutive
1039 characters will be undone together.
1040 This is configurable, because there is some impact on typing performance."
1044 (defcustom org-table-tab-recognizes-table.el t
1045 "Non-nil means, TAB will automatically notice a table.el table.
1046 When it sees such a table, it moves point into it and - if necessary -
1047 calls `table-recognize-table'."
1048 :group
'org-table-editing
1051 (defgroup org-link nil
1052 "Options concerning links in Org-mode."
1056 (defvar org-link-abbrev-alist-local nil
1057 "Buffer-local version of `org-link-abbrev-alist', which see.
1058 The value of this is taken from the #+LINK lines.")
1059 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1061 (defcustom org-link-abbrev-alist nil
1062 "Alist of link abbreviations.
1063 The car of each element is a string, to be replaced at the start of a link.
1064 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1065 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1067 [[linkkey:tag][description]]
1069 The 'linkkey' must be a word word, starting with a letter, followed
1070 by letters, numbers, '-' or '_'.
1072 If REPLACE is a string, the tag will simply be appended to create the link.
1073 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1074 the placeholder \"%h\" will cause a url-encoded version of the tag to
1075 be inserted at that point (see the function `url-hexify-string').
1077 REPLACE may also be a function that will be called with the tag as the
1078 only argument to create the link, which should be returned as a string.
1080 See the manual for examples."
1084 (string :tag
"Protocol")
1086 (string :tag
"Format")
1089 (defcustom org-descriptive-links t
1090 "Non-nil means, hide link part and only show description of bracket links.
1091 Bracket links are like [[link][description]]. This variable sets the initial
1092 state in new org-mode buffers. The setting can then be toggled on a
1093 per-buffer basis from the Org->Hyperlinks menu."
1097 (defcustom org-link-file-path-type
'adaptive
1098 "How the path name in file links should be stored.
1101 relative Relative to the current directory, i.e. the directory of the file
1102 into which the link is being inserted.
1103 absolute Absolute path, if possible with ~ for home directory.
1104 noabbrev Absolute path, no abbreviation of home directory.
1105 adaptive Use relative path for files in the current directory and sub-
1106 directories of it. For other files, use an absolute path."
1114 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1115 "Types of links that should be activated in Org-mode files.
1116 This is a list of symbols, each leading to the activation of a certain link
1117 type. In principle, it does not hurt to turn on most link types - there may
1118 be a small gain when turning off unused link types. The types are:
1120 bracket The recommended [[link][description]] or [[link]] links with hiding.
1121 angular Links in angular brackets that may contain whitespace like
1122 <bbdb:Carsten Dominik>.
1123 plain Plain links in normal text, no whitespace, like http://google.com.
1124 radio Text that is matched by a radio target, see manual for details.
1125 tag Tag settings in a headline (link to tag search).
1126 date Time stamps (link to calendar).
1127 footnote Footnote labels.
1129 Changing this variable requires a restart of Emacs to become effective."
1131 :type
'(set :greedy t
1132 (const :tag
"Double bracket links (new style)" bracket
)
1133 (const :tag
"Angular bracket links (old style)" angular
)
1134 (const :tag
"Plain text links" plain
)
1135 (const :tag
"Radio target matches" radio
)
1136 (const :tag
"Tags" tag
)
1137 (const :tag
"Timestamps" date
)
1138 (const :tag
"Footnotes" footnote
)))
1140 (defcustom org-make-link-description-function nil
1141 "Function to use to generate link descriptions from links. If
1142 nil the link location will be used. This function must take two
1143 parameters; the first is the link and the second the description
1144 org-insert-link has generated, and should return the description
1149 (defgroup org-link-store nil
1150 "Options concerning storing links in Org-mode."
1151 :tag
"Org Store Link"
1154 (defcustom org-email-link-description-format
"Email %c: %.30s"
1155 "Format of the description part of a link to an email or usenet message.
1156 The following %-escapes will be replaced by corresponding information:
1158 %F full \"From\" field
1159 %f name, taken from \"From\" field, address if no name
1160 %T full \"To\" field
1161 %t first name in \"To\" field, address if no name
1162 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1163 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1167 You may use normal field width specification between the % and the letter.
1168 This is for example useful to limit the length of the subject.
1170 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1171 :group
'org-link-store
1174 (defcustom org-from-is-user-regexp
1176 (when (and user-mail-address
(not (string= user-mail-address
"")))
1177 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1178 (when (and user-full-name
(not (string= user-full-name
"")))
1179 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1180 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1181 "Regexp matched against the \"From:\" header of an email or usenet message.
1182 It should match if the message is from the user him/herself."
1183 :group
'org-link-store
1186 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1187 "Non-nil means, storing a link to an Org file will use entry IDs.
1189 Note that before this variable is even considered, org-id must be loaded,
1190 so please customize `org-modules' and turn it on.
1192 The variable can have the following values:
1194 t Create an ID if needed to make a link to the current entry.
1196 create-if-interactive
1197 If `org-store-link' is called directly (interactively, as a user
1198 command), do create an ID to support the link. But when doing the
1199 job for remember, only use the ID if it already exists. The
1200 purpose of this setting is to avoid proliferation of unwanted
1201 IDs, just because you happen to be in an Org file when you
1202 call `org-remember' that automatically and preemptively
1203 creates a link. If you do want to get an ID link in a remember
1204 template to an entry not having an ID, create it first by
1205 explicitly creating a link to it, using `C-c C-l' first.
1207 create-if-interactive-and-no-custom-id
1208 Like create-if-interactive, but do not create an ID if there is
1209 a CUSTOM_ID property defined in the entry. This is the default.
1212 Use existing ID, do not create one.
1214 nil Never use an ID to make a link, instead link using a text search for
1216 :group
'org-link-store
1218 (const :tag
"Create ID to make link" t
)
1219 (const :tag
"Create if storing link interactively"
1220 create-if-interactive
)
1221 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1222 create-if-interactive-and-no-custom-id
)
1223 (const :tag
"Only use existing" use-existing
)
1224 (const :tag
"Do not use ID to create link" nil
)))
1226 (defcustom org-context-in-file-links t
1227 "Non-nil means, file links from `org-store-link' contain context.
1228 A search string will be added to the file name with :: as separator and
1229 used to find the context when the link is activated by the command
1230 `org-open-at-point'.
1231 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1232 negates this setting for the duration of the command."
1233 :group
'org-link-store
1236 (defcustom org-keep-stored-link-after-insertion nil
1237 "Non-nil means, keep link in list for entire session.
1239 The command `org-store-link' adds a link pointing to the current
1240 location to an internal list. These links accumulate during a session.
1241 The command `org-insert-link' can be used to insert links into any
1242 Org-mode file (offering completion for all stored links). When this
1243 option is nil, every link which has been inserted once using \\[org-insert-link]
1244 will be removed from the list, to make completing the unused links
1246 :group
'org-link-store
1249 (defgroup org-link-follow nil
1250 "Options concerning following links in Org-mode."
1251 :tag
"Org Follow Link"
1254 (defcustom org-link-translation-function nil
1255 "Function to translate links with different syntax to Org syntax.
1256 This can be used to translate links created for example by the Planner
1257 or emacs-wiki packages to Org syntax.
1258 The function must accept two parameters, a TYPE containing the link
1259 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1260 which is everything after the link protocol. It should return a cons
1261 with possibly modified values of type and path.
1262 Org contains a function for this, so if you set this variable to
1263 `org-translate-link-from-planner', you should be able follow many
1264 links created by planner."
1265 :group
'org-link-follow
1268 (defcustom org-follow-link-hook nil
1269 "Hook that is run after a link has been followed."
1270 :group
'org-link-follow
1273 (defcustom org-tab-follows-link nil
1274 "Non-nil means, on links TAB will follow the link.
1275 Needs to be set before org.el is loaded.
1276 This really should not be used, it does not make sense, and the
1277 implementation is bad."
1278 :group
'org-link-follow
1281 (defcustom org-return-follows-link nil
1282 "Non-nil means, on links RET will follow the link.
1283 Needs to be set before org.el is loaded."
1284 :group
'org-link-follow
1287 (defcustom org-mouse-1-follows-link
1288 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1289 "Non-nil means, mouse-1 on a link will follow the link.
1290 A longer mouse click will still set point. Does not work on XEmacs.
1291 Needs to be set before org.el is loaded."
1292 :group
'org-link-follow
1295 (defcustom org-mark-ring-length
4
1296 "Number of different positions to be recorded in the ring
1297 Changing this requires a restart of Emacs to work correctly."
1298 :group
'org-link-follow
1301 (defcustom org-link-frame-setup
1302 '((vm . vm-visit-folder-other-frame
)
1303 (gnus . gnus-other-frame
)
1304 (file . find-file-other-window
))
1305 "Setup the frame configuration for following links.
1306 When following a link with Emacs, it may often be useful to display
1307 this link in another window or frame. This variable can be used to
1308 set this up for the different types of links.
1311 `vm-visit-folder-other-frame'
1312 For Gnus, use any of
1315 `org-gnus-no-new-news'
1316 For FILE, use any of
1318 `find-file-other-window'
1319 `find-file-other-frame'
1320 For the calendar, use the variable `calendar-setup'.
1321 For BBDB, it is currently only possible to display the matches in
1323 :group
'org-link-follow
1327 (const vm-visit-folder
)
1328 (const vm-visit-folder-other-window
)
1329 (const vm-visit-folder-other-frame
)))
1333 (const gnus-other-frame
)
1334 (const org-gnus-no-new-news
)))
1338 (const find-file-other-window
)
1339 (const find-file-other-frame
)))))
1341 (defcustom org-display-internal-link-with-indirect-buffer nil
1342 "Non-nil means, use indirect buffer to display infile links.
1343 Activating internal links (from one location in a file to another location
1344 in the same file) normally just jumps to the location. When the link is
1345 activated with a C-u prefix (or with mouse-3), the link is displayed in
1346 another window. When this option is set, the other window actually displays
1347 an indirect buffer clone of the current buffer, to avoid any visibility
1348 changes to the current buffer."
1349 :group
'org-link-follow
1352 (defcustom org-open-non-existing-files nil
1353 "Non-nil means, `org-open-file' will open non-existing files.
1354 When nil, an error will be generated.
1355 This variable applies only to external applications because they
1356 might choke on non-existing files. If the link is to a file that
1357 will be opened in Emacs, the variable is ignored."
1358 :group
'org-link-follow
1361 (defcustom org-open-directory-means-index-dot-org nil
1362 "Non-nil means, a link to a directory really means to index.org.
1363 When nil, following a directory link will run dired or open a finder/explorer
1364 window on that directory."
1365 :group
'org-link-follow
1368 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1369 "Function and arguments to call for following mailto links.
1370 This is a list with the first element being a lisp function, and the
1371 remaining elements being arguments to the function. In string arguments,
1372 %a will be replaced by the address, and %s will be replaced by the subject
1373 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1374 :group
'org-link-follow
1376 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1377 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1378 (const :tag
"message-mail" (message-mail "%a" "%s"))
1379 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1381 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1382 "Non-nil means, ask for confirmation before executing shell links.
1383 Shell links can be dangerous: just think about a link
1385 [[shell:rm -rf ~/*][Google Search]]
1387 This link would show up in your Org-mode document as \"Google Search\",
1388 but really it would remove your entire home directory.
1389 Therefore we advise against setting this variable to nil.
1390 Just change it to `y-or-n-p' if you want to confirm with a
1391 single keystroke rather than having to type \"yes\"."
1392 :group
'org-link-follow
1394 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1395 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1396 (const :tag
"no confirmation (dangerous)" nil
)))
1398 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1399 "Non-nil means, ask for confirmation before executing Emacs Lisp links.
1400 Elisp links can be dangerous: just think about a link
1402 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1404 This link would show up in your Org-mode document as \"Google Search\",
1405 but really it would remove your entire home directory.
1406 Therefore we advise against setting this variable to nil.
1407 Just change it to `y-or-n-p' if you want to confirm with a
1408 single keystroke rather than having to type \"yes\"."
1409 :group
'org-link-follow
1411 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1412 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1413 (const :tag
"no confirmation (dangerous)" nil
)))
1415 (defconst org-file-apps-defaults-gnu
1419 "Default file applications on a UNIX or GNU/Linux system.
1420 See `org-file-apps'.")
1422 (defconst org-file-apps-defaults-macosx
1425 (system .
"open %s")
1427 ("eps.gz" .
"gv %s")
1429 ("fig" .
"xfig %s"))
1430 "Default file applications on a MacOS X system.
1431 The system \"open\" is known as a default, but we use X11 applications
1432 for some files for which the OS does not have a good default.
1433 See `org-file-apps'.")
1435 (defconst org-file-apps-defaults-windowsnt
1439 (list (if (featurep 'xemacs
)
1440 'mswindows-shell-execute
1444 (list (if (featurep 'xemacs
)
1445 'mswindows-shell-execute
1448 "Default file applications on a Windows NT system.
1449 The system \"open\" is used for most files.
1450 See `org-file-apps'.")
1452 (defcustom org-file-apps
1455 ("\\.mm\\'" . default
)
1456 ("\\.x?html?\\'" . default
)
1457 ("\\.pdf\\'" . default
)
1459 "External applications for opening `file:path' items in a document.
1460 Org-mode uses system defaults for different file types, but
1461 you can use this variable to set the application for a given file
1462 extension. The entries in this list are cons cells where the car identifies
1463 files and the cdr the corresponding command. Possible values for the
1465 \"regex\" Regular expression matched against the file name. For backward
1466 compatibility, this can also be a string with only alphanumeric
1467 characters, which is then interpreted as an extension.
1468 `directory' Matches a directory
1469 `remote' Matches a remote file, accessible through tramp or efs.
1470 Remote files most likely should be visited through Emacs
1471 because external applications cannot handle such paths.
1472 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1473 so all files Emacs knows how to handle. Using this with
1474 command `emacs' will open most files in Emacs. Beware that this
1475 will also open html files inside Emacs, unless you add
1476 (\"html\" . default) to the list as well.
1477 t Default for files not matched by any of the other options.
1478 `system' The system command to open files, like `open' on Windows
1479 and Mac OS X, and mailcap under GNU/Linux. This is the command
1480 that will be selected if you call `C-c C-o' with a double
1483 Possible values for the command are:
1484 `emacs' The file will be visited by the current Emacs process.
1485 `default' Use the default application for this file type, which is the
1486 association for t in the list, most likely in the system-specific
1488 This can be used to overrule an unwanted setting in the
1489 system-specific variable.
1490 `system' Use the system command for opening files, like \"open\".
1491 This command is specified by the entry whose car is `system'.
1492 Most likely, the system-specific version of this variable
1493 does define this command, but you can overrule/replace it
1495 string A command to be executed by a shell; %s will be replaced
1496 by the path to the file.
1497 sexp A Lisp form which will be evaluated. The file path will
1498 be available in the Lisp variable `file'.
1499 For more examples, see the system specific constants
1500 `org-file-apps-defaults-macosx'
1501 `org-file-apps-defaults-windowsnt'
1502 `org-file-apps-defaults-gnu'."
1503 :group
'org-link-follow
1505 (cons (choice :value
""
1506 (string :tag
"Extension")
1507 (const :tag
"System command to open files" system
)
1508 (const :tag
"Default for unrecognized files" t
)
1509 (const :tag
"Remote file" remote
)
1510 (const :tag
"Links to a directory" directory
)
1511 (const :tag
"Any files that have Emacs modes"
1514 (const :tag
"Visit with Emacs" emacs
)
1515 (const :tag
"Use default" default
)
1516 (const :tag
"Use the system command" system
)
1517 (string :tag
"Command")
1518 (sexp :tag
"Lisp form")))))
1520 (defgroup org-refile nil
1521 "Options concerning refiling entries in Org-mode."
1525 (defcustom org-directory
"~/org"
1526 "Directory with org files.
1527 This is just a default location to look for Org files. There is no need
1528 at all to put your files into this directory. It is only used in the
1529 following situations:
1531 1. When a remember template specifies a target file that is not an
1532 absolute path. The path will then be interpreted relative to
1534 2. When a remember note is filed away in an interactive way (when exiting the
1535 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1536 with `org-directory' as the default path."
1538 :group
'org-remember
1541 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1542 "Default target for storing notes.
1543 Used by the hooks for remember.el. This can be a string, or nil to mean
1544 the value of `remember-data-file'.
1545 You can set this on a per-template basis with the variable
1546 `org-remember-templates'."
1548 :group
'org-remember
1550 (const :tag
"Default from remember-data-file" nil
)
1553 (defcustom org-goto-interface
'outline
1554 "The default interface to be used for `org-goto'.
1556 outline The interface shows an outline of the relevant file
1557 and the correct heading is found by moving through
1558 the outline or by searching with incremental search.
1559 outline-path-completion Headlines in the current buffer are offered via
1560 completion. This is the interface also used by
1561 the refile command."
1564 (const :tag
"Outline" outline
)
1565 (const :tag
"Outline-path-completion" outline-path-completion
)))
1567 (defcustom org-goto-max-level
5
1568 "Maximum level to be considered when running org-goto with refile interface."
1572 (defcustom org-reverse-note-order nil
1573 "Non-nil means, store new notes at the beginning of a file or entry.
1574 When nil, new notes will be filed to the end of a file or entry.
1575 This can also be a list with cons cells of regular expressions that
1576 are matched against file names, and values."
1577 :group
'org-remember
1580 (const :tag
"Reverse always" t
)
1581 (const :tag
"Reverse never" nil
)
1582 (repeat :tag
"By file name regexp"
1583 (cons regexp boolean
))))
1585 (defcustom org-refile-targets nil
1586 "Targets for refiling entries with \\[org-refile].
1587 This is list of cons cells. Each cell contains:
1588 - a specification of the files to be considered, either a list of files,
1589 or a symbol whose function or variable value will be used to retrieve
1590 a file name or a list of file names. If you use `org-agenda-files' for
1591 that, all agenda files will be scanned for targets. Nil means, consider
1592 headings in the current buffer.
1593 - A specification of how to find candidate refile targets. This may be
1595 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1596 This tag has to be present in all target headlines, inheritance will
1598 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1600 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1601 headlines that are refiling targets.
1602 - a cons cell (:level . N). Any headline of level N is considered a target.
1603 Note that, when `org-odd-levels-only' is set, level corresponds to
1604 order in hierarchy, not to the number of stars.
1605 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1606 Note that, when `org-odd-levels-only' is set, level corresponds to
1607 order in hierarchy, not to the number of stars.
1609 You can set the variable `org-refile-target-verify-function' to a function
1610 to verify each headline found by the simple critery above.
1612 When this variable is nil, all top-level headlines in the current buffer
1613 are used, equivalent to the value `((nil . (:level . 1))'."
1617 (choice :value org-agenda-files
1618 (const :tag
"All agenda files" org-agenda-files
)
1619 (const :tag
"Current buffer" nil
)
1620 (function) (variable) (file))
1621 (choice :tag
"Identify target headline by"
1622 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1623 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1624 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1625 (cons :tag
"Level number" (const :value
:level
) (integer))
1626 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1628 (defcustom org-refile-target-verify-function nil
1629 "Function to verify if the headline at point should be a refile target.
1630 The function will be called without arguments, with point at the
1631 beginning of the headline. It should return t and leave point
1632 where it is if the headline is a valid target for refiling.
1634 If the target should not be selected, the function must return nil.
1635 In addition to this, it may move point to a place from where the search
1636 should be continued. For example, the function may decide that the entire
1637 subtree of the current entry should be excluded and move point to the end
1642 (defcustom org-refile-use-outline-path nil
1643 "Non-nil means, provide refile targets as paths.
1644 So a level 3 headline will be available as level1/level2/level3.
1646 When the value is `file', also include the file name (without directory)
1647 into the path. In this case, you can also stop the completion after
1648 the file name, to get entries inserted as top level in the file.
1650 When `full-file-path', include the full file path."
1653 (const :tag
"Not" nil
)
1654 (const :tag
"Yes" t
)
1655 (const :tag
"Start with file name" file
)
1656 (const :tag
"Start with full file path" full-file-path
)))
1658 (defcustom org-outline-path-complete-in-steps t
1659 "Non-nil means, complete the outline path in hierarchical steps.
1660 When Org-mode uses the refile interface to select an outline path
1661 \(see variable `org-refile-use-outline-path'), the completion of
1662 the path can be done is a single go, or if can be done in steps down
1663 the headline hierarchy. Going in steps is probably the best if you
1664 do not use a special completion package like `ido' or `icicles'.
1665 However, when using these packages, going in one step can be very
1666 fast, while still showing the whole path to the entry."
1670 (defcustom org-refile-allow-creating-parent-nodes nil
1671 "Non-nil means, allow to create new nodes as refile targets.
1672 New nodes are then created by adding \"/new node name\" to the completion
1673 of an existing node. When the value of this variable is `confirm',
1674 new node creation must be confirmed by the user (recommended)
1675 When nil, the completion must match an existing entry.
1677 Note that, if the new heading is not seen by the criteria
1678 listed in `org-refile-targets', multiple instances of the same
1679 heading would be created by trying again to file under the new
1683 (const :tag
"Never" nil
)
1684 (const :tag
"Always" t
)
1685 (const :tag
"Prompt for confirmation" confirm
)))
1687 (defgroup org-todo nil
1688 "Options concerning TODO items in Org-mode."
1692 (defgroup org-progress nil
1693 "Options concerning Progress logging in Org-mode."
1697 (defvar org-todo-interpretation-widgets
1699 (:tag
"Sequence (cycling hits every state)" sequence
)
1700 (:tag
"Type (cycling directly to DONE)" type
))
1701 "The available interpretation symbols for customizing
1702 `org-todo-keywords'.
1703 Interested libraries should add to this list.")
1705 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1706 "List of TODO entry keyword sequences and their interpretation.
1707 \\<org-mode-map>This is a list of sequences.
1709 Each sequence starts with a symbol, either `sequence' or `type',
1710 indicating if the keywords should be interpreted as a sequence of
1711 action steps, or as different types of TODO items. The first
1712 keywords are states requiring action - these states will select a headline
1713 for inclusion into the global TODO list Org-mode produces. If one of
1714 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1715 signify that no further action is necessary. If \"|\" is not found,
1716 the last keyword is treated as the only DONE state of the sequence.
1718 The command \\[org-todo] cycles an entry through these states, and one
1719 additional state where no keyword is present. For details about this
1720 cycling, see the manual.
1722 TODO keywords and interpretation can also be set on a per-file basis with
1723 the special #+SEQ_TODO and #+TYP_TODO lines.
1725 Each keyword can optionally specify a character for fast state selection
1726 \(in combination with the variable `org-use-fast-todo-selection')
1727 and specifiers for state change logging, using the same syntax
1728 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1729 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1730 indicates to record a time stamp each time this state is selected.
1732 Each keyword may also specify if a timestamp or a note should be
1733 recorded when entering or leaving the state, by adding additional
1734 characters in the parenthesis after the keyword. This looks like this:
1735 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1736 record only the time of the state change. With X and Y being either
1737 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1738 Y when leaving the state if and only if the *target* state does not
1739 define X. You may omit any of the fast-selection key or X or /Y,
1740 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1742 For backward compatibility, this variable may also be just a list
1743 of keywords - in this case the interpretation (sequence or type) will be
1744 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1746 :group
'org-keywords
1748 (repeat :tag
"Old syntax, just keywords"
1749 (string :tag
"Keyword"))
1750 (repeat :tag
"New syntax"
1753 :tag
"Interpretation"
1754 ;;Quick and dirty way to see
1755 ;;`org-todo-interpretations'. This takes the
1756 ;;place of item arguments
1764 org-todo-interpretation-widgets
))
1767 (string :tag
"Keyword"))))))
1769 (defvar org-todo-keywords-1 nil
1770 "All TODO and DONE keywords active in a buffer.")
1771 (make-variable-buffer-local 'org-todo-keywords-1
)
1772 (defvar org-todo-keywords-for-agenda nil
)
1773 (defvar org-done-keywords-for-agenda nil
)
1774 (defvar org-drawers-for-agenda nil
)
1775 (defvar org-todo-keyword-alist-for-agenda nil
)
1776 (defvar org-tag-alist-for-agenda nil
)
1777 (defvar org-agenda-contributing-files nil
)
1778 (defvar org-not-done-keywords nil
)
1779 (make-variable-buffer-local 'org-not-done-keywords
)
1780 (defvar org-done-keywords nil
)
1781 (make-variable-buffer-local 'org-done-keywords
)
1782 (defvar org-todo-heads nil
)
1783 (make-variable-buffer-local 'org-todo-heads
)
1784 (defvar org-todo-sets nil
)
1785 (make-variable-buffer-local 'org-todo-sets
)
1786 (defvar org-todo-log-states nil
)
1787 (make-variable-buffer-local 'org-todo-log-states
)
1788 (defvar org-todo-kwd-alist nil
)
1789 (make-variable-buffer-local 'org-todo-kwd-alist
)
1790 (defvar org-todo-key-alist nil
)
1791 (make-variable-buffer-local 'org-todo-key-alist
)
1792 (defvar org-todo-key-trigger nil
)
1793 (make-variable-buffer-local 'org-todo-key-trigger
)
1795 (defcustom org-todo-interpretation
'sequence
1796 "Controls how TODO keywords are interpreted.
1797 This variable is in principle obsolete and is only used for
1798 backward compatibility, if the interpretation of todo keywords is
1799 not given already in `org-todo-keywords'. See that variable for
1802 :group
'org-keywords
1803 :type
'(choice (const sequence
)
1806 (defcustom org-use-fast-todo-selection t
1807 "Non-nil means, use the fast todo selection scheme with C-c C-t.
1808 This variable describes if and under what circumstances the cycling
1809 mechanism for TODO keywords will be replaced by a single-key, direct
1812 When nil, fast selection is never used.
1814 When the symbol `prefix', it will be used when `org-todo' is called with
1815 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1816 in an agenda buffer.
1818 When t, fast selection is used by default. In this case, the prefix
1819 argument forces cycling instead.
1821 In all cases, the special interface is only used if access keys have actually
1822 been assigned by the user, i.e. if keywords in the configuration are followed
1823 by a letter in parenthesis, like TODO(t)."
1826 (const :tag
"Never" nil
)
1827 (const :tag
"By default" t
)
1828 (const :tag
"Only with C-u C-c C-t" prefix
)))
1830 (defcustom org-provide-todo-statistics t
1831 "Non-nil means, update todo statistics after insert and toggle.
1832 ALL-HEADLINES means update todo statistics by including headlines
1833 with no TODO keyword as well, counting them as not done.
1834 A list of TODO keywords means the same, but skip keywords that are
1837 When this is set, todo statistics is updated in the parent of the
1838 current entry each time a todo state is changed."
1841 (const :tag
"Yes, only for TODO entries" t
)
1842 (const :tag
"Yes, including all entries" 'all-headlines
)
1843 (repeat :tag
"Yes, for TODOs in this list"
1844 (string :tag
"TODO keyword"))
1845 (other :tag
"No TODO statistics" nil
)))
1847 (defcustom org-hierarchical-todo-statistics t
1848 "Non-nil means, TODO statistics covers just direct children.
1849 When nil, all entries in the subtree are considered.
1850 This has only an effect if `org-provide-todo-statistics' is set.
1851 To set this to nil for only a single subtree, use a COOKIE_DATA
1852 property and include the word \"recursive\" into the value."
1856 (defcustom org-after-todo-state-change-hook nil
1857 "Hook which is run after the state of a TODO item was changed.
1858 The new state (a string with a TODO keyword, or nil) is available in the
1859 Lisp variable `state'."
1863 (defvar org-blocker-hook nil
1864 "Hook for functions that are allowed to block a state change.
1866 Each function gets as its single argument a property list, see
1867 `org-trigger-hook' for more information about this list.
1869 If any of the functions in this hook returns nil, the state change
1872 (defvar org-trigger-hook nil
1873 "Hook for functions that are triggered by a state change.
1875 Each function gets as its single argument a property list with at least
1876 the following elements:
1878 (:type type-of-change :position pos-at-entry-start
1879 :from old-state :to new-state)
1881 Depending on the type, more properties may be present.
1883 This mechanism is currently implemented for:
1887 :type todo-state-change
1888 :from previous state (keyword as a string), or nil, or a symbol
1889 'todo' or 'done', to indicate the general type of state.
1890 :to new state, like in :from")
1892 (defcustom org-enforce-todo-dependencies nil
1893 "Non-nil means, undone TODO entries will block switching the parent to DONE.
1894 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1895 be blocked if any prior sibling is not yet done.
1896 Finally, if the parent is blocked because of ordered siblings of its own,
1897 the child will also be blocked.
1898 This variable needs to be set before org.el is loaded, and you need to
1899 restart Emacs after a change to make the change effective. The only way
1900 to change is while Emacs is running is through the customize interface."
1901 :set
(lambda (var val
)
1904 (add-hook 'org-blocker-hook
1905 'org-block-todo-from-children-or-siblings-or-parent
)
1906 (remove-hook 'org-blocker-hook
1907 'org-block-todo-from-children-or-siblings-or-parent
)))
1911 (defcustom org-enforce-todo-checkbox-dependencies nil
1912 "Non-nil means, unchecked boxes will block switching the parent to DONE.
1913 When this is nil, checkboxes have no influence on switching TODO states.
1914 When non-nil, you first need to check off all check boxes before the TODO
1915 entry can be switched to DONE.
1916 This variable needs to be set before org.el is loaded, and you need to
1917 restart Emacs after a change to make the change effective. The only way
1918 to change is while Emacs is running is through the customize interface."
1919 :set
(lambda (var val
)
1922 (add-hook 'org-blocker-hook
1923 'org-block-todo-from-checkboxes
)
1924 (remove-hook 'org-blocker-hook
1925 'org-block-todo-from-checkboxes
)))
1929 (defcustom org-treat-insert-todo-heading-as-state-change nil
1930 "Non-nil means, inserting a TODO heading is treated as state change.
1931 So when the command \\[org-insert-todo-heading] is used, state change
1932 logging will apply if appropriate. When nil, the new TODO item will
1933 be inserted directly, and no logging will take place."
1937 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
1938 "Non-nil means, switching TODO states with S-cursor counts as state change.
1939 This is the default behavior. However, setting this to nil allows a
1940 convenient way to select a TODO state and bypass any logging associated
1945 (defcustom org-todo-state-tags-triggers nil
1946 "Tag changes that should be triggered by TODO state changes.
1947 This is a list. Each entry is
1949 (state-change (tag . flag) .......)
1951 State-change can be a string with a state, and empty string to indicate the
1952 state that has no TODO keyword, or it can be one of the symbols `todo'
1953 or `done', meaning any not-done or done state, respectively."
1957 (cons (choice :tag
"When changing to"
1958 (const :tag
"Not-done state" todo
)
1959 (const :tag
"Done state" done
)
1960 (string :tag
"State"))
1962 (cons :tag
"Tag action"
1964 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
1966 (defcustom org-log-done nil
1967 "Information to record when a task moves to the DONE state.
1969 Possible values are:
1971 nil Don't add anything, just change the keyword
1972 time Add a time stamp to the task
1973 note Prompt for a note and add it with template `org-log-note-headings'
1975 This option can also be set with on a per-file-basis with
1977 #+STARTUP: nologdone
1979 #+STARTUP: lognotedone
1981 You can have local logging settings for a subtree by setting the LOGGING
1982 property to one or more of these keywords."
1984 :group
'org-progress
1986 (const :tag
"No logging" nil
)
1987 (const :tag
"Record CLOSED timestamp" time
)
1988 (const :tag
"Record CLOSED timestamp with note." note
)))
1990 ;; Normalize old uses of org-log-done.
1992 ((eq org-log-done t
) (setq org-log-done
'time
))
1993 ((and (listp org-log-done
) (memq 'done org-log-done
))
1994 (setq org-log-done
'note
)))
1996 (defcustom org-log-reschedule nil
1997 "Information to record when the scheduling date of a tasks is modified.
1999 Possible values are:
2001 nil Don't add anything, just change the date
2002 time Add a time stamp to the task
2003 note Prompt for a note and add it with template `org-log-note-headings'
2005 This option can also be set with on a per-file-basis with
2007 #+STARTUP: nologreschedule
2008 #+STARTUP: logreschedule
2009 #+STARTUP: lognotereschedule"
2011 :group
'org-progress
2013 (const :tag
"No logging" nil
)
2014 (const :tag
"Record timestamp" time
)
2015 (const :tag
"Record timestamp with note." note
)))
2017 (defcustom org-log-redeadline nil
2018 "Information to record when the deadline date of a tasks is modified.
2020 Possible values are:
2022 nil Don't add anything, just change the date
2023 time Add a time stamp to the task
2024 note Prompt for a note and add it with template `org-log-note-headings'
2026 This option can also be set with on a per-file-basis with
2028 #+STARTUP: nologredeadline
2029 #+STARTUP: logredeadline
2030 #+STARTUP: lognoteredeadline
2032 You can have local logging settings for a subtree by setting the LOGGING
2033 property to one or more of these keywords."
2035 :group
'org-progress
2037 (const :tag
"No logging" nil
)
2038 (const :tag
"Record timestamp" time
)
2039 (const :tag
"Record timestamp with note." note
)))
2041 (defcustom org-log-note-clock-out nil
2042 "Non-nil means, record a note when clocking out of an item.
2043 This can also be configured on a per-file basis by adding one of
2044 the following lines anywhere in the buffer:
2046 #+STARTUP: lognoteclock-out
2047 #+STARTUP: nolognoteclock-out"
2049 :group
'org-progress
2052 (defcustom org-log-done-with-time t
2053 "Non-nil means, the CLOSED time stamp will contain date and time.
2054 When nil, only the date will be recorded."
2055 :group
'org-progress
2058 (defcustom org-log-note-headings
2059 '((done .
"CLOSING NOTE %t")
2060 (state .
"State %-12s from %-12S %t")
2061 (note .
"Note taken on %t")
2062 (reschedule .
"Rescheduled from %S on %t")
2063 (delschedule .
"Not scheduled, was %S on %t")
2064 (redeadline .
"New deadline from %S on %t")
2065 (deldeadline .
"Removed deadline, was %S on %t")
2067 "Headings for notes added to entries.
2068 The value is an alist, with the car being a symbol indicating the note
2069 context, and the cdr is the heading to be used. The heading may also be the
2071 %t in the heading will be replaced by a time stamp.
2072 %s will be replaced by the new TODO state, in double quotes.
2073 %S will be replaced by the old TODO state, in double quotes.
2074 %u will be replaced by the user name.
2075 %U will be replaced by the full user name.
2077 In fact, it is not a good idea to change the `state' entry, because
2078 agenda log mode depends on the format of these entries."
2080 :group
'org-progress
2081 :type
'(list :greedy t
2082 (cons (const :tag
"Heading when closing an item" done
) string
)
2084 "Heading when changing todo state (todo sequence only)"
2086 (cons (const :tag
"Heading when just taking a note" note
) string
)
2087 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2088 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2089 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2090 (cons (const :tag
"Heading when changing deadline" redeadline
) string
2091 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
))))
2093 (unless (assq 'note org-log-note-headings
)
2094 (push '(note .
"%t") org-log-note-headings
))
2096 (defcustom org-log-into-drawer nil
2097 "Non-nil means, insert state change notes and time stamps into a drawer.
2098 When nil, state changes notes will be inserted after the headline and
2099 any scheduling and clock lines, but not inside a drawer.
2101 The value of this variable should be the name of the drawer to use.
2102 LOGBOOK is proposed at the default drawer for this purpose, you can
2103 also set this to a string to define the drawer of your choice.
2105 A value of t is also allowed, representing \"LOGBOOK\".
2107 If this variable is set, `org-log-state-notes-insert-after-drawers'
2110 You can set the property LOG_INTO_DRAWER to overrule this setting for
2113 :group
'org-progress
2115 (const :tag
"Not into a drawer" nil
)
2116 (const :tag
"LOGBOOK" t
)
2117 (string :tag
"Other")))
2119 (if (fboundp 'defvaralias
)
2120 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2122 (defun org-log-into-drawer ()
2123 "Return the value of `org-log-into-drawer', but let properties overrule.
2124 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2125 used instead of the default value."
2126 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2128 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2129 ((equal p
"t") "LOGBOOK")
2132 (defcustom org-log-state-notes-insert-after-drawers nil
2133 "Non-nil means, insert state change notes after any drawers in entry.
2134 Only the drawers that *immediately* follow the headline and the
2135 deadline/scheduled line are skipped.
2136 When nil, insert notes right after the heading and perhaps the line
2137 with deadline/scheduling if present.
2139 This variable will have no effect if `org-log-into-drawer' is
2142 :group
'org-progress
2145 (defcustom org-log-states-order-reversed t
2146 "Non-nil means, the latest state change note will be directly after heading.
2147 When nil, the notes will be orderer according to time."
2149 :group
'org-progress
2152 (defcustom org-log-repeat
'time
2153 "Non-nil means, record moving through the DONE state when triggering repeat.
2154 An auto-repeating task is immediately switched back to TODO when
2155 marked DONE. If you are not logging state changes (by adding \"@\"
2156 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2157 record a closing note, there will be no record of the task moving
2158 through DONE. This variable forces taking a note anyway.
2160 nil Don't force a record
2161 time Record a time stamp
2164 This option can also be set with on a per-file-basis with
2166 #+STARTUP: logrepeat
2167 #+STARTUP: lognoterepeat
2168 #+STARTUP: nologrepeat
2170 You can have local logging settings for a subtree by setting the LOGGING
2171 property to one or more of these keywords."
2173 :group
'org-progress
2175 (const :tag
"Don't force a record" nil
)
2176 (const :tag
"Force recording the DONE state" time
)
2177 (const :tag
"Force recording a note with the DONE state" note
)))
2180 (defgroup org-priorities nil
2181 "Priorities in Org-mode."
2182 :tag
"Org Priorities"
2185 (defcustom org-enable-priority-commands t
2186 "Non-nil means, priority commands are active.
2187 When nil, these commands will be disabled, so that you never accidentally
2189 :group
'org-priorities
2192 (defcustom org-highest-priority ?A
2193 "The highest priority of TODO items. A character like ?A, ?B etc.
2194 Must have a smaller ASCII number than `org-lowest-priority'."
2195 :group
'org-priorities
2198 (defcustom org-lowest-priority ?C
2199 "The lowest priority of TODO items. A character like ?A, ?B etc.
2200 Must have a larger ASCII number than `org-highest-priority'."
2201 :group
'org-priorities
2204 (defcustom org-default-priority ?B
2205 "The default priority of TODO items.
2206 This is the priority an item get if no explicit priority is given."
2207 :group
'org-priorities
2210 (defcustom org-priority-start-cycle-with-default t
2211 "Non-nil means, start with default priority when starting to cycle.
2212 When this is nil, the first step in the cycle will be (depending on the
2213 command used) one higher or lower that the default priority."
2214 :group
'org-priorities
2217 (defgroup org-time nil
2218 "Options concerning time stamps and deadlines in Org-mode."
2222 (defcustom org-insert-labeled-timestamps-at-point nil
2223 "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point.
2224 When nil, these labeled time stamps are forces into the second line of an
2225 entry, just after the headline. When scheduling from the global TODO list,
2226 the time stamp will always be forced into the second line."
2230 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2231 "Formats for `format-time-string' which are used for time stamps.
2232 It is not recommended to change this constant.")
2234 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2235 "Number of minutes to round time stamps to.
2236 These are two values, the first applies when first creating a time stamp.
2237 The second applies when changing it with the commands `S-up' and `S-down'.
2238 When changing the time stamp, this means that it will change in steps
2239 of N minutes, as given by the second value.
2241 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2242 numbers should be factors of 60, so for example 5, 10, 15.
2244 When this is larger than 1, you can still force an exact time-stamp by using
2245 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2246 and by using a prefix arg to `S-up/down' to specify the exact number
2247 of minutes to shift."
2249 :get
'(lambda (var) ; Make sure all entries have 5 elements
2250 (if (integerp (default-value var
))
2251 (list (default-value var
) 5)
2252 (default-value var
)))
2254 (integer :tag
"when inserting times")
2255 (integer :tag
"when modifying times")))
2257 ;; Normalize old customizations of this variable.
2258 (when (integerp org-time-stamp-rounding-minutes
)
2259 (setq org-time-stamp-rounding-minutes
2260 (list org-time-stamp-rounding-minutes
2261 org-time-stamp-rounding-minutes
)))
2263 (defcustom org-display-custom-times nil
2264 "Non-nil means, overlay custom formats over all time stamps.
2265 The formats are defined through the variable `org-time-stamp-custom-formats'.
2266 To turn this on on a per-file basis, insert anywhere in the file:
2267 #+STARTUP: customtime"
2271 (make-variable-buffer-local 'org-display-custom-times
)
2273 (defcustom org-time-stamp-custom-formats
2274 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2275 "Custom formats for time stamps. See `format-time-string' for the syntax.
2276 These are overlayed over the default ISO format if the variable
2277 `org-display-custom-times' is set. Time like %H:%M should be at the
2278 end of the second format. The custom formats are also honored by export
2279 commands, if custom time display is turned on at the time of export."
2283 (defun org-time-stamp-format (&optional long inactive
)
2284 "Get the right format for a time string."
2285 (let ((f (if long
(cdr org-time-stamp-formats
)
2286 (car org-time-stamp-formats
))))
2288 (concat "[" (substring f
1 -
1) "]")
2291 (defcustom org-time-clocksum-format
"%d:%02d"
2292 "The format string used when creating CLOCKSUM lines, or when
2293 org-mode generates a time duration."
2297 (defcustom org-time-clocksum-use-fractional nil
2298 "If non-nil, \\[org-clock-display] uses fractional times.
2299 org-mode generates a time duration."
2303 (defcustom org-time-clocksum-fractional-format
"%.2f"
2304 "The format string used when creating CLOCKSUM lines, or when
2305 org-mode generates a time duration."
2309 (defcustom org-deadline-warning-days
14
2310 "No. of days before expiration during which a deadline becomes active.
2311 This variable governs the display in sparse trees and in the agenda.
2312 When 0 or negative, it means use this number (the absolute value of it)
2313 even if a deadline has a different individual lead time specified.
2315 Custom commands can set this variable in the options section."
2317 :group
'org-agenda-daily
/weekly
2320 (defcustom org-read-date-prefer-future t
2321 "Non-nil means, assume future for incomplete date input from user.
2322 This affects the following situations:
2323 1. The user gives a month but not a year.
2324 For example, if it is april and you enter \"feb 2\", this will be read
2325 as feb 2, *next* year. \"May 5\", however, will be this year.
2326 2. The user gives a day, but no month.
2327 For example, if today is the 15th, and you enter \"3\", Org-mode will
2328 read this as the third of *next* month. However, if you enter \"17\",
2329 it will be considered as *this* month.
2331 If you set this variable to the symbol `time', then also the following
2334 3. If the user gives a time, but no day. If the time is before now,
2335 to will be interpreted as tomorrow.
2337 Currently none of this works for ISO week specifications.
2339 When this option is nil, the current day, month and year will always be
2343 (const :tag
"Never" nil
)
2344 (const :tag
"Check month and day" t
)
2345 (const :tag
"Check month, day, and time" time
)))
2347 (defcustom org-read-date-display-live t
2348 "Non-nil means, display current interpretation of date prompt live.
2349 This display will be in an overlay, in the minibuffer."
2353 (defcustom org-read-date-popup-calendar t
2354 "Non-nil means, pop up a calendar when prompting for a date.
2355 In the calendar, the date can be selected with mouse-1. However, the
2356 minibuffer will also be active, and you can simply enter the date as well.
2357 When nil, only the minibuffer will be available."
2360 (if (fboundp 'defvaralias
)
2361 (defvaralias 'org-popup-calendar-for-date-prompt
2362 'org-read-date-popup-calendar
))
2364 (defcustom org-read-date-minibuffer-setup-hook nil
2365 "Hook to be used to set up keys for the date/time interface.
2366 Add key definitions to `minibuffer-local-map', which will be a temporary
2371 (defcustom org-extend-today-until
0
2372 "The hour when your day really ends. Must be an integer.
2373 This has influence for the following applications:
2374 - When switching the agenda to \"today\". It it is still earlier than
2375 the time given here, the day recognized as TODAY is actually yesterday.
2376 - When a date is read from the user and it is still before the time given
2377 here, the current date and time will be assumed to be yesterday, 23:59.
2378 Also, timestamps inserted in remember templates follow this rule.
2380 IMPORTANT: This is a feature whose implementation is and likely will
2381 remain incomplete. Really, it is only here because past midnight seems to
2382 be the favorite working time of John Wiegley :-)"
2386 (defcustom org-edit-timestamp-down-means-later nil
2387 "Non-nil means, S-down will increase the time in a time stamp.
2388 When nil, S-up will increase."
2392 (defcustom org-calendar-follow-timestamp-change t
2393 "Non-nil means, make the calendar window follow timestamp changes.
2394 When a timestamp is modified and the calendar window is visible, it will be
2395 moved to the new date."
2399 (defgroup org-tags nil
2400 "Options concerning tags in Org-mode."
2404 (defcustom org-tag-alist nil
2405 "List of tags allowed in Org-mode files.
2406 When this list is nil, Org-mode will base TAG input on what is already in the
2408 The value of this variable is an alist, the car of each entry must be a
2409 keyword as a string, the cdr may be a character that is used to select
2410 that tag through the fast-tag-selection interface.
2411 See the manual for details."
2415 (cons (string :tag
"Tag name")
2416 (character :tag
"Access char"))
2417 (list :tag
"Start radio group"
2419 (option (string :tag
"Group description")))
2420 (list :tag
"End radio group"
2422 (option (string :tag
"Group description")))
2423 (const :tag
"New line" (:newline
)))))
2425 (defcustom org-tag-persistent-alist nil
2426 "List of tags that will always appear in all Org-mode files.
2427 This is in addition to any in buffer settings or customizations
2429 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2430 The value of this variable is an alist, the car of each entry must be a
2431 keyword as a string, the cdr may be a character that is used to select
2432 that tag through the fast-tag-selection interface.
2433 See the manual for details.
2434 To disable these tags on a per-file basis, insert anywhere in the file:
2439 (cons (string :tag
"Tag name")
2440 (character :tag
"Access char"))
2441 (const :tag
"Start radio group" (:startgroup
))
2442 (const :tag
"End radio group" (:endgroup
))
2443 (const :tag
"New line" (:newline
)))))
2445 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2446 "If non-nil, always offer completion for all tags of all agenda files.
2447 Instead of customizing this variable directly, you might want to
2448 set it locally for remember buffers, because there no list of
2449 tags in that file can be created dynamically (there are none).
2451 (add-hook 'org-remember-mode-hook
2453 (set (make-local-variable
2454 'org-complete-tags-always-offer-all-agenda-tags)
2459 (defvar org-file-tags nil
2460 "List of tags that can be inherited by all entries in the file.
2461 The tags will be inherited if the variable `org-use-tag-inheritance'
2462 says they should be.
2463 This variable is populated from #+FILETAGS lines.")
2465 (defcustom org-use-fast-tag-selection
'auto
2466 "Non-nil means, use fast tag selection scheme.
2467 This is a special interface to select and deselect tags with single keys.
2468 When nil, fast selection is never used.
2469 When the symbol `auto', fast selection is used if and only if selection
2470 characters for tags have been configured, either through the variable
2471 `org-tag-alist' or through a #+TAGS line in the buffer.
2472 When t, fast selection is always used and selection keys are assigned
2473 automatically if necessary."
2476 (const :tag
"Always" t
)
2477 (const :tag
"Never" nil
)
2478 (const :tag
"When selection characters are configured" 'auto
)))
2480 (defcustom org-fast-tag-selection-single-key nil
2481 "Non-nil means, fast tag selection exits after first change.
2482 When nil, you have to press RET to exit it.
2483 During fast tag selection, you can toggle this flag with `C-c'.
2484 This variable can also have the value `expert'. In this case, the window
2485 displaying the tags menu is not even shown, until you press C-c again."
2488 (const :tag
"No" nil
)
2489 (const :tag
"Yes" t
)
2490 (const :tag
"Expert" expert
)))
2492 (defvar org-fast-tag-selection-include-todo nil
2493 "Non-nil means, fast tags selection interface will also offer TODO states.
2494 This is an undocumented feature, you should not rely on it.")
2496 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2497 "The column to which tags should be indented in a headline.
2498 If this number is positive, it specifies the column. If it is negative,
2499 it means that the tags should be flushright to that column. For example,
2500 -80 works well for a normal 80 character screen."
2504 (defcustom org-auto-align-tags t
2505 "Non-nil means, realign tags after pro/demotion of TODO state change.
2506 These operations change the length of a headline and therefore shift
2507 the tags around. With this options turned on, after each such operation
2508 the tags are again aligned to `org-tags-column'."
2512 (defcustom org-use-tag-inheritance t
2513 "Non-nil means, tags in levels apply also for sublevels.
2514 When nil, only the tags directly given in a specific line apply there.
2515 This may also be a list of tags that should be inherited, or a regexp that
2516 matches tags that should be inherited. Additional control is possible
2517 with the variable `org-tags-exclude-from-inheritance' which gives an
2518 explicit list of tags to be excluded from inheritance., even if the value of
2519 `org-use-tag-inheritance' would select it for inheritance.
2521 If this option is t, a match early-on in a tree can lead to a large
2522 number of matches in the subtree when constructing the agenda or creating
2523 a sparse tree. If you only want to see the first match in a tree during
2524 a search, check out the variable `org-tags-match-list-sublevels'."
2527 (const :tag
"Not" nil
)
2528 (const :tag
"Always" t
)
2529 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2530 (regexp :tag
"Tags matched by regexp")))
2532 (defcustom org-tags-exclude-from-inheritance nil
2533 "List of tags that should never be inherited.
2534 This is a way to exclude a few tags from inheritance. For way to do
2535 the opposite, to actively allow inheritance for selected tags,
2536 see the variable `org-use-tag-inheritance'."
2538 :type
'(repeat (string :tag
"Tag")))
2540 (defun org-tag-inherit-p (tag)
2541 "Check if TAG is one that should be inherited."
2543 ((member tag org-tags-exclude-from-inheritance
) nil
)
2544 ((eq org-use-tag-inheritance t
) t
)
2545 ((not org-use-tag-inheritance
) nil
)
2546 ((stringp org-use-tag-inheritance
)
2547 (string-match org-use-tag-inheritance tag
))
2548 ((listp org-use-tag-inheritance
)
2549 (member tag org-use-tag-inheritance
))
2550 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2552 (defcustom org-tags-match-list-sublevels t
2553 "Non-nil means list also sublevels of headlines matching a search.
2554 This variable applies to tags/property searches, and also to stuck
2555 projects because this search is based on a tags match as well.
2557 When set to the symbol `indented', sublevels are indented with
2560 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2561 the sublevels of a headline matching a tag search often also match
2562 the same search. Listing all of them can create very long lists.
2563 Setting this variable to nil causes subtrees of a match to be skipped.
2565 This variable is semi-obsolete and probably should always be true. It
2566 is better to limit inheritance to certain tags using the variables
2567 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2570 (const :tag
"No, don't list them" nil
)
2571 (const :tag
"Yes, do list them" t
)
2572 (const :tag
"List them, indented with leading dots" indented
)))
2574 (defcustom org-tags-sort-function nil
2575 "When set, tags are sorted using this function as a comparator"
2578 (const :tag
"No sorting" nil
)
2579 (const :tag
"Alphabetical" string
<)
2580 (const :tag
"Reverse alphabetical" string
>)
2581 (function :tag
"Custom function" nil
)))
2583 (defvar org-tags-history nil
2584 "History of minibuffer reads for tags.")
2585 (defvar org-last-tags-completion-table nil
2586 "The last used completion table for tags.")
2587 (defvar org-after-tags-change-hook nil
2588 "Hook that is run after the tags in a line have changed.")
2590 (defgroup org-properties nil
2591 "Options concerning properties in Org-mode."
2592 :tag
"Org Properties"
2595 (defcustom org-property-format
"%-10s %s"
2596 "How property key/value pairs should be formatted by `indent-line'.
2597 When `indent-line' hits a property definition, it will format the line
2598 according to this format, mainly to make sure that the values are
2599 lined-up with respect to each other."
2600 :group
'org-properties
2603 (defcustom org-use-property-inheritance nil
2604 "Non-nil means, properties apply also for sublevels.
2606 This setting is chiefly used during property searches. Turning it on can
2607 cause significant overhead when doing a search, which is why it is not
2610 When nil, only the properties directly given in the current entry count.
2611 When t, every property is inherited. The value may also be a list of
2612 properties that should have inheritance, or a regular expression matching
2613 properties that should be inherited.
2615 However, note that some special properties use inheritance under special
2616 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2617 and the properties ending in \"_ALL\" when they are used as descriptor
2618 for valid values of a property.
2620 Note for programmers:
2621 When querying an entry with `org-entry-get', you can control if inheritance
2622 should be used. By default, `org-entry-get' looks only at the local
2623 properties. You can request inheritance by setting the inherit argument
2624 to t (to force inheritance) or to `selective' (to respect the setting
2626 :group
'org-properties
2628 (const :tag
"Not" nil
)
2629 (const :tag
"Always" t
)
2630 (repeat :tag
"Specific properties" (string :tag
"Property"))
2631 (regexp :tag
"Properties matched by regexp")))
2633 (defun org-property-inherit-p (property)
2634 "Check if PROPERTY is one that should be inherited."
2636 ((eq org-use-property-inheritance t
) t
)
2637 ((not org-use-property-inheritance
) nil
)
2638 ((stringp org-use-property-inheritance
)
2639 (string-match org-use-property-inheritance property
))
2640 ((listp org-use-property-inheritance
)
2641 (member property org-use-property-inheritance
))
2642 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2644 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2645 "The default column format, if no other format has been defined.
2646 This variable can be set on the per-file basis by inserting a line
2648 #+COLUMNS: %25ITEM ....."
2649 :group
'org-properties
2652 (defcustom org-columns-ellipses
".."
2653 "The ellipses to be used when a field in column view is truncated.
2654 When this is the empty string, as many characters as possible are shown,
2655 but then there will be no visual indication that the field has been truncated.
2656 When this is a string of length N, the last N characters of a truncated
2657 field are replaced by this string. If the column is narrower than the
2658 ellipses string, only part of the ellipses string will be shown."
2659 :group
'org-properties
2662 (defcustom org-columns-modify-value-for-display-function nil
2663 "Function that modifies values for display in column view.
2664 For example, it can be used to cut out a certain part from a time stamp.
2665 The function must take 2 arguments:
2667 column-title The title of the column (*not* the property name)
2668 value The value that should be modified.
2670 The function should return the value that should be displayed,
2671 or nil if the normal value should be used."
2672 :group
'org-properties
2675 (defcustom org-effort-property
"Effort"
2676 "The property that is being used to keep track of effort estimates.
2677 Effort estimates given in this property need to have the format H:MM."
2678 :group
'org-properties
2679 :group
'org-progress
2680 :type
'(string :tag
"Property"))
2682 (defconst org-global-properties-fixed
2683 '(("VISIBILITY_ALL" .
"folded children content all")
2684 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2685 "List of property/value pairs that can be inherited by any entry.
2687 These are fixed values, for the preset properties. The user variable
2688 that can be used to add to this list is `org-global-properties'.
2690 The entries in this list are cons cells where the car is a property
2691 name and cdr is a string with the value. If the value represents
2692 multiple items like an \"_ALL\" property, separate the items by
2695 (defcustom org-global-properties nil
2696 "List of property/value pairs that can be inherited by any entry.
2698 This list will be combined with the constant `org-global-properties-fixed'.
2700 The entries in this list are cons cells where the car is a property
2701 name and cdr is a string with the value.
2703 You can set buffer-local values for the same purpose in the variable
2704 `org-file-properties' this by adding lines like
2706 #+PROPERTY: NAME VALUE"
2707 :group
'org-properties
2709 (cons (string :tag
"Property")
2710 (string :tag
"Value"))))
2712 (defvar org-file-properties nil
2713 "List of property/value pairs that can be inherited by any entry.
2714 Valid for the current buffer.
2715 This variable is populated from #+PROPERTY lines.")
2716 (make-variable-buffer-local 'org-file-properties
)
2718 (defgroup org-agenda nil
2719 "Options concerning agenda views in Org-mode."
2723 (defvar org-category nil
2724 "Variable used by org files to set a category for agenda display.
2725 Such files should use a file variable to set it, for example
2727 # -*- mode: org; org-category: \"ELisp\"
2729 or contain a special line
2733 If the file does not specify a category, then file's base name
2735 (make-variable-buffer-local 'org-category
)
2736 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2738 (defcustom org-agenda-files nil
2739 "The files to be used for agenda display.
2740 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2741 \\[org-remove-file]. You can also use customize to edit the list.
2743 If an entry is a directory, all files in that directory that are matched by
2744 `org-agenda-file-regexp' will be part of the file list.
2746 If the value of the variable is not a list but a single file name, then
2747 the list of agenda files is actually stored and maintained in that file, one
2748 agenda file per line."
2751 (repeat :tag
"List of files and directories" file
)
2752 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2754 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2755 "Regular expression to match files for `org-agenda-files'.
2756 If any element in the list in that variable contains a directory instead
2757 of a normal file, all files in that directory that are matched by this
2758 regular expression will be included."
2762 (defcustom org-agenda-text-search-extra-files nil
2763 "List of extra files to be searched by text search commands.
2764 These files will be search in addition to the agenda files by the
2765 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2766 Note that these files will only be searched for text search commands,
2767 not for the other agenda views like todo lists, tag searches or the weekly
2768 agenda. This variable is intended to list notes and possibly archive files
2769 that should also be searched by these two commands.
2770 In fact, if the first element in the list is the symbol `agenda-archives',
2771 than all archive files of all agenda files will be added to the search
2774 :type
'(set :greedy t
2775 (const :tag
"Agenda Archives" agenda-archives
)
2776 (repeat :inline t
(file))))
2778 (if (fboundp 'defvaralias
)
2779 (defvaralias 'org-agenda-multi-occur-extra-files
2780 'org-agenda-text-search-extra-files
))
2782 (defcustom org-agenda-skip-unavailable-files nil
2783 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2784 A nil value means to remove them, after a query, from the list."
2788 (defcustom org-calendar-to-agenda-key
[?c
]
2789 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2790 The command `org-calendar-goto-agenda' will be bound to this key. The
2791 default is the character `c' because then `c' can be used to switch back and
2792 forth between agenda and calendar."
2796 (defcustom org-calendar-agenda-action-key
[?k
]
2797 "The key to be installed in `calendar-mode-map' for agenda-action.
2798 The command `org-agenda-action' will be bound to this key. The
2799 default is the character `k' because we use the same key in the agenda."
2803 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2804 "The key to be installed in `calendar-mode-map' for adding diary entries.
2805 This option is irrelevant until `org-agenda-diary-file' has been configured
2806 to point to an Org-mode file. When that is the case, the command
2807 `org-agenda-diary-entry' will be bound to the key given here, by default
2808 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2809 if you want to continue doing this, you need to change this to a different
2814 (defcustom org-agenda-diary-file
'diary-file
2815 "File to which to add new entries with the `i' key in agenda and calendar.
2816 When this is the symbol `diary-file', the functionality in the Emacs
2817 calendar will be used to add entries to the `diary-file'. But when this
2818 points to a file, `org-agenda-diary-entry' will be used instead."
2821 (const :tag
"The standard Emacs diary file" diary-file
)
2822 (file :tag
"Special Org file diary entries")))
2824 (eval-after-load "calendar"
2826 (org-defkey calendar-mode-map org-calendar-to-agenda-key
2827 'org-calendar-goto-agenda
)
2828 (org-defkey calendar-mode-map org-calendar-agenda-action-key
2830 (add-hook 'calendar-mode-hook
2832 (unless (eq org-agenda-diary-file
'diary-file
)
2833 (define-key calendar-mode-map
2834 org-calendar-insert-diary-entry-key
2835 'org-agenda-diary-entry
))))))
2837 (defgroup org-latex nil
2838 "Options for embedding LaTeX code into Org-mode."
2842 (defcustom org-format-latex-options
2843 '(:foreground default
:background default
:scale
1.0
2844 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
2845 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
2846 "Options for creating images from LaTeX fragments.
2847 This is a property list with the following properties:
2848 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
2849 `default' means use the foreground of the default face.
2850 :background the background color, or \"Transparent\".
2851 `default' means use the background of the default face.
2852 :scale a scaling factor for the size of the images.
2853 :html-foreground, :html-background, :html-scale
2854 the same numbers for HTML export.
2855 :matchers a list indicating which matchers should be used to
2856 find LaTeX fragments. Valid members of this list are:
2857 \"begin\" find environments
2858 \"$1\" find single characters surrounded by $.$
2859 \"$\" find math expressions surrounded by $...$
2860 \"$$\" find math expressions surrounded by $$....$$
2861 \"\\(\" find math expressions surrounded by \\(...\\)
2862 \"\\ [\" find math expressions surrounded by \\ [...\\]"
2866 (defcustom org-format-latex-header
"\\documentclass{article}
2867 \\usepackage{amssymb}
2868 \\usepackage[usenames]{color}
2869 \\usepackage{amsmath}
2870 \\usepackage{latexsym}
2871 \\usepackage[mathscr]{eucal}
2872 \\pagestyle{empty} % do not remove
2873 % The settings below are copied from fullpage.sty
2874 \\setlength{\\textwidth}{\\paperwidth}
2875 \\addtolength{\\textwidth}{-3cm}
2876 \\setlength{\\oddsidemargin}{1.5cm}
2877 \\addtolength{\\oddsidemargin}{-2.54cm}
2878 \\setlength{\\evensidemargin}{\\oddsidemargin}
2879 \\setlength{\\textheight}{\\paperheight}
2880 \\addtolength{\\textheight}{-\\headheight}
2881 \\addtolength{\\textheight}{-\\headsep}
2882 \\addtolength{\\textheight}{-\\footskip}
2883 \\addtolength{\\textheight}{-3cm}
2884 \\setlength{\\topmargin}{1.5cm}
2885 \\addtolength{\\topmargin}{-2.54cm}"
2886 "The document header used for processing LaTeX fragments.
2887 It is imperative that this header make sure that no page number
2888 appears on the page."
2892 (defvar org-format-latex-header-extra nil
)
2894 ;; The following variable is defined here because is it also used
2895 ;; when formatting latex fragments. Originally it was part of the
2896 ;; LaTeX exporter, which is why the name includes "export".
2897 (defcustom org-export-latex-packages-alist nil
2898 "Alist of packages to be inserted in the header.
2899 Each cell is of the format \( \"option\" . \"package\" \)."
2900 :group
'org-export-latex
2903 (string :tag
"option")
2904 (string :tag
"package"))))
2906 (defgroup org-font-lock nil
2907 "Font-lock settings for highlighting in Org-mode."
2908 :tag
"Org Font Lock"
2911 (defcustom org-level-color-stars-only nil
2912 "Non-nil means fontify only the stars in each headline.
2913 When nil, the entire headline is fontified.
2914 Changing it requires restart of `font-lock-mode' to become effective
2915 also in regions already fontified."
2916 :group
'org-font-lock
2919 (defcustom org-hide-leading-stars nil
2920 "Non-nil means, hide the first N-1 stars in a headline.
2921 This works by using the face `org-hide' for these stars. This
2922 face is white for a light background, and black for a dark
2923 background. You may have to customize the face `org-hide' to
2925 Changing it requires restart of `font-lock-mode' to become effective
2926 also in regions already fontified.
2927 You may also set this on a per-file basis by adding one of the following
2928 lines to the buffer:
2930 #+STARTUP: hidestars
2931 #+STARTUP: showstars"
2932 :group
'org-font-lock
2935 (defcustom org-fontify-done-headline nil
2936 "Non-nil means, change the face of a headline if it is marked DONE.
2937 Normally, only the TODO/DONE keyword indicates the state of a headline.
2938 When this is non-nil, the headline after the keyword is set to the
2939 `org-headline-done' as an additional indication."
2940 :group
'org-font-lock
2943 (defcustom org-fontify-emphasized-text t
2944 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
2945 Changing this variable requires a restart of Emacs to take effect."
2946 :group
'org-font-lock
2949 (defcustom org-fontify-whole-heading-line nil
2950 "Non-nil means fontify the whole line for headings.
2951 This is useful when setting a background color for the
2953 :group
'org-font-lock
2956 (defcustom org-highlight-latex-fragments-and-specials nil
2957 "Non-nil means, fontify what is treated specially by the exporters."
2958 :group
'org-font-lock
2961 (defcustom org-hide-emphasis-markers nil
2962 "Non-nil mean font-lock should hide the emphasis marker characters."
2963 :group
'org-font-lock
2966 (defvar org-emph-re nil
2967 "Regular expression for matching emphasis.")
2968 (defvar org-verbatim-re nil
2969 "Regular expression for matching verbatim text.")
2970 (defvar org-emphasis-regexp-components
) ; defined just below
2971 (defvar org-emphasis-alist
) ; defined just below
2972 (defun org-set-emph-re (var val
)
2973 "Set variable and compute the emphasis regular expression."
2975 (when (and (boundp 'org-emphasis-alist
)
2976 (boundp 'org-emphasis-regexp-components
)
2977 org-emphasis-alist org-emphasis-regexp-components
)
2978 (let* ((e org-emphasis-regexp-components
)
2984 (body1 (concat body
"*?"))
2985 (markers (mapconcat 'car org-emphasis-alist
""))
2986 (vmarkers (mapconcat
2987 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
2988 org-emphasis-alist
"")))
2989 ;; make sure special characters appear at the right position in the class
2990 (if (string-match "\\^" markers
)
2991 (setq markers
(concat (replace-match "" t t markers
) "^")))
2992 (if (string-match "-" markers
)
2993 (setq markers
(concat (replace-match "" t t markers
) "-")))
2994 (if (string-match "\\^" vmarkers
)
2995 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
2996 (if (string-match "-" vmarkers
)
2997 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
2999 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3000 (int-to-string nl
) "\\}")))
3003 (concat "\\([" pre
"]\\|^\\)"
3005 "\\([" markers
"]\\)"
3013 "\\([" post
"]\\|$\\)"))
3014 (setq org-verbatim-re
3015 (concat "\\([" pre
"]\\|^\\)"
3017 "\\([" vmarkers
"]\\)"
3025 "\\([" post
"]\\|$\\)")))))
3027 (defcustom org-emphasis-regexp-components
3028 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3029 "Components used to build the regular expression for emphasis.
3030 This is a list with 6 entries. Terminology: In an emphasis string
3031 like \" *strong word* \", we call the initial space PREMATCH, the final
3032 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3033 and \"trong wor\" is the body. The different components in this variable
3034 specify what is allowed/forbidden in each part:
3036 pre Chars allowed as prematch. Beginning of line will be allowed too.
3037 post Chars allowed as postmatch. End of line will be allowed too.
3038 border The chars *forbidden* as border characters.
3039 body-regexp A regexp like \".\" to match a body character. Don't use
3040 non-shy groups here, and don't allow newline here.
3041 newline The maximum number of newlines allowed in an emphasis exp.
3043 Use customize to modify this, or restart Emacs after changing it."
3044 :group
'org-font-lock
3045 :set
'org-set-emph-re
3047 (sexp :tag
"Allowed chars in pre ")
3048 (sexp :tag
"Allowed chars in post ")
3049 (sexp :tag
"Forbidden chars in border ")
3050 (sexp :tag
"Regexp for body ")
3051 (integer :tag
"number of newlines allowed")
3052 (option (boolean :tag
"Please ignore this button"))))
3054 (defcustom org-emphasis-alist
3055 `(("*" bold
"<b>" "</b>")
3056 ("/" italic
"<i>" "</i>")
3057 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3058 ("=" org-code
"<code>" "</code>" verbatim
)
3059 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3060 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3063 "Special syntax for emphasized text.
3064 Text starting and ending with a special character will be emphasized, for
3065 example *bold*, _underlined_ and /italic/. This variable sets the marker
3066 characters, the face to be used by font-lock for highlighting in Org-mode
3067 Emacs buffers, and the HTML tags to be used for this.
3068 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3069 Use customize to modify this, or restart Emacs after changing it."
3070 :group
'org-font-lock
3071 :set
'org-set-emph-re
3074 (string :tag
"Marker character")
3076 (face :tag
"Font-lock-face")
3077 (plist :tag
"Face property list"))
3078 (string :tag
"HTML start tag")
3079 (string :tag
"HTML end tag")
3080 (option (const verbatim
)))))
3082 (defvar org-protecting-blocks
3083 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3084 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3085 This is needed for font-lock setup.")
3087 ;;; Miscellaneous options
3089 (defgroup org-completion nil
3090 "Completion in Org-mode."
3091 :tag
"Org Completion"
3094 (defcustom org-completion-use-ido nil
3095 "Non-nil means, use ido completion wherever possible.
3096 Note that `ido-mode' must be active for this variable to be relevant.
3097 If you decide to turn this variable on, you might well want to turn off
3098 `org-outline-path-complete-in-steps'.
3099 See also `org-completion-use-iswitchb'."
3100 :group
'org-completion
3103 (defcustom org-completion-use-iswitchb nil
3104 "Non-nil means, use iswitchb completion wherever possible.
3105 Note that `iswitchb-mode' must be active for this variable to be relevant.
3106 If you decide to turn this variable on, you might well want to turn off
3107 `org-outline-path-complete-in-steps'.
3108 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3109 :group
'org-completion
3112 (defcustom org-completion-fallback-command
'hippie-expand
3113 "The expansion command called by \\[org-complete] in normal context.
3114 Normal means, no org-mode-specific context."
3115 :group
'org-completion
3118 ;;; Functions and variables from their packages
3119 ;; Declared here to avoid compiler warnings
3122 (defvar outline-mode-menu-heading
)
3123 (defvar outline-mode-menu-show
)
3124 (defvar outline-mode-menu-hide
)
3125 (defvar zmacs-regions
) ; XEmacs regions
3128 (defvar mark-active
)
3131 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3132 (declare-function calendar-forward-day
"cal-move" (arg))
3133 (declare-function calendar-goto-date
"cal-move" (date))
3134 (declare-function calendar-goto-today
"cal-move" ())
3135 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3136 (defvar calc-embedded-close-formula
)
3137 (defvar calc-embedded-open-formula
)
3138 (declare-function cdlatex-tab
"ext:cdlatex" ())
3139 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3140 (defvar font-lock-unfontify-region-function
)
3141 (declare-function iswitchb-read-buffer
"iswitchb"
3142 (prompt &optional default require-match start matches-set
))
3143 (defvar iswitchb-temp-buflist
)
3144 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3145 (defvar org-agenda-tags-todo-honor-ignore-options
)
3146 (declare-function org-agenda-skip
"org-agenda" ())
3148 org-format-agenda-item
"org-agenda"
3149 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3150 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3151 (declare-function org-agenda-change-all-lines
"org-agenda"
3152 (newhead hdmarker
&optional fixface just-this
))
3153 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3154 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3155 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3157 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3158 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3159 "org-agenda" (&optional end
))
3160 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3161 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3162 (declare-function parse-time-string
"parse-time" (string))
3163 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3164 (defvar remember-data-file
)
3165 (defvar texmathp-why
)
3166 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3167 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3169 (defvar w3m-current-url
)
3170 (defvar w3m-current-title
)
3172 (defvar org-latex-regexps
)
3174 ;;; Autoload and prepare some org modules
3176 ;; Some table stuff that needs to be defined here, because it is used
3177 ;; by the functions setting up org-mode or checking for table context.
3179 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3180 "Detects an org-type or table-type table.")
3181 (defconst org-table-line-regexp
"^[ \t]*|"
3182 "Detects an org-type table line.")
3183 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3184 "Detects an org-type table line.")
3185 (defconst org-table-hline-regexp
"^[ \t]*|-"
3186 "Detects an org-type table hline.")
3187 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3188 "Detects a table-type table hline.")
3189 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3190 "Searching from within a table (any type) this finds the first line
3191 outside the table.")
3193 ;; Autoload the functions in org-table.el that are needed by functions here.
3196 (org-autoload "org-table"
3197 '(org-table-align org-table-begin org-table-blank-field
3198 org-table-convert org-table-convert-region org-table-copy-down
3199 org-table-copy-region org-table-create
3200 org-table-create-or-convert-from-region
3201 org-table-create-with-table.el org-table-current-dline
3202 org-table-cut-region org-table-delete-column org-table-edit-field
3203 org-table-edit-formulas org-table-end org-table-eval-formula
3204 org-table-export org-table-field-info
3205 org-table-get-stored-formulas org-table-goto-column
3206 org-table-hline-and-move org-table-import org-table-insert-column
3207 org-table-insert-hline org-table-insert-row org-table-iterate
3208 org-table-justify-field-maybe org-table-kill-row
3209 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3210 org-table-move-column org-table-move-column-left
3211 org-table-move-column-right org-table-move-row
3212 org-table-move-row-down org-table-move-row-up
3213 org-table-next-field org-table-next-row org-table-paste-rectangle
3214 org-table-previous-field org-table-recalculate
3215 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3216 org-table-toggle-coordinate-overlays
3217 org-table-toggle-formula-debugger org-table-wrap-region
3218 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3220 (defun org-at-table-p (&optional table-type
)
3221 "Return t if the cursor is inside an org-type table.
3222 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3223 (if org-enable-table-editor
3225 (beginning-of-line 1)
3226 (looking-at (if table-type org-table-any-line-regexp
3227 org-table-line-regexp
)))
3229 (defsubst org-table-p
() (org-at-table-p))
3231 (defun org-at-table.el-p
()
3232 "Return t if and only if we are at a table.el table."
3233 (and (org-at-table-p 'any
)
3235 (goto-char (org-table-begin 'any
))
3236 (looking-at org-table1-hline-regexp
))))
3237 (defun org-table-recognize-table.el
()
3238 "If there is a table.el table nearby, recognize it and move into it."
3239 (if org-table-tab-recognizes-table.el
3240 (if (org-at-table.el-p
)
3242 (beginning-of-line 1)
3243 (if (looking-at org-table-dataline-regexp
)
3245 (if (looking-at org-table1-hline-regexp
)
3247 (beginning-of-line 2)
3248 (if (looking-at org-table-any-border-regexp
)
3249 (beginning-of-line -
1)))))
3250 (if (re-search-forward "|" (org-table-end t
) t
)
3253 (if (table--at-cell-p (point))
3255 (message "recognizing table.el table...")
3256 (table-recognize-table)
3257 (message "recognizing table.el table...done")))
3258 (error "This should not happen..."))
3263 (defun org-at-table-hline-p ()
3264 "Return t if the cursor is inside a hline in a table."
3265 (if org-enable-table-editor
3267 (beginning-of-line 1)
3268 (looking-at org-table-hline-regexp
))
3271 (defvar org-table-clean-did-remove-column nil
)
3273 (defun org-table-map-tables (function)
3274 "Apply FUNCTION to the start of all tables in the buffer."
3278 (goto-char (point-min))
3279 (while (re-search-forward org-table-any-line-regexp nil t
)
3280 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
3281 (beginning-of-line 1)
3282 (when (looking-at org-table-line-regexp
)
3283 (save-excursion (funcall function
))
3284 (or (looking-at org-table-line-regexp
)
3286 (re-search-forward org-table-any-border-regexp nil
1))))
3287 (message "Mapping tables: done"))
3289 ;; Declare and autoload functions from org-exp.el & Co
3291 (declare-function org-default-export-plist
"org-exp")
3292 (declare-function org-infile-export-plist
"org-exp")
3293 (declare-function org-get-current-options
"org-exp")
3295 (org-autoload "org-exp"
3296 '(org-export org-export-visible
3297 org-insert-export-options-template
3298 org-table-clean-before-export
))
3299 (org-autoload "org-ascii"
3300 '(org-export-as-ascii org-export-ascii-preprocess
3301 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3302 org-export-region-as-ascii
))
3303 (org-autoload "org-latex"
3304 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3305 org-replace-region-by-latex org-export-region-as-latex
3306 org-export-as-latex org-export-as-pdf
3307 org-export-as-pdf-and-open
))
3308 (org-autoload "org-html"
3309 '(org-export-as-html-and-open
3310 org-export-as-html-batch org-export-as-html-to-buffer
3311 org-replace-region-by-html org-export-region-as-html
3312 org-export-as-html
))
3313 (org-autoload "org-docbook"
3314 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3315 org-replace-region-by-docbook org-export-region-as-docbook
3316 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3317 org-export-as-docbook
))
3318 (org-autoload "org-icalendar"
3319 '(org-export-icalendar-this-file
3320 org-export-icalendar-all-agenda-files
3321 org-export-icalendar-combine-agenda-files
))
3322 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3323 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3325 ;; Declare and autoload functions from org-agenda.el
3328 (org-autoload "org-agenda"
3329 '(org-agenda org-agenda-list org-search-view
3330 org-todo-list org-tags-view org-agenda-list-stuck-projects
3331 org-diary org-agenda-to-appt
3332 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3334 ;; Autoload org-remember
3337 (org-autoload "org-remember"
3338 '(org-remember-insinuate org-remember-annotation
3339 org-remember-apply-template org-remember org-remember-handler
)))
3341 ;; Autoload org-clock.el
3344 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3346 (declare-function org-clock-update-mode-line
"org-clock" ())
3347 (declare-function org-resolve-clocks
"org-clock"
3348 (&optional also-non-dangling-p prompt last-valid
))
3349 (defvar org-clock-start-time
)
3350 (defvar org-clock-marker
(make-marker)
3351 "Marker recording the last clock-in.")
3352 (defvar org-clock-hd-marker
(make-marker)
3353 "Marker recording the last clock-in, but the headline position.")
3354 (defvar org-clock-heading
""
3355 "The heading of the current clock entry.")
3356 (defun org-clock-is-active ()
3357 "Return non-nil if clock is currently running.
3358 The return value is actually the clock marker."
3359 (marker-buffer org-clock-marker
))
3364 '(org-clock-in org-clock-out org-clock-cancel
3365 org-clock-goto org-clock-sum org-clock-display
3366 org-clock-remove-overlays org-clock-report
3367 org-clocktable-shift org-dblock-write
:clocktable
3368 org-get-clocktable org-resolve-clocks
)))
3370 (defun org-clock-update-time-maybe ()
3371 "If this is a CLOCK line, update it and return t.
3372 Otherwise, return nil."
3375 (beginning-of-line 1)
3376 (skip-chars-forward " \t")
3377 (when (looking-at org-clock-string
)
3378 (let ((re (concat "[ \t]*" org-clock-string
3379 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3380 "\\([ \t]*=>.*\\)?\\)?"))
3383 ((not (looking-at re
))
3385 ((not (match-end 2))
3386 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3387 (> org-clock-marker
(point))
3388 (<= org-clock-marker
(point-at-eol)))
3389 ;; The clock is running here
3390 (setq org-clock-start-time
3392 (org-parse-time-string (match-string 1))))
3393 (org-clock-update-mode-line)))
3395 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3397 (setq ts
(match-string 1)
3398 te
(match-string 3))
3399 (setq s
(- (org-float-time
3400 (apply 'encode-time
(org-parse-time-string te
)))
3402 (apply 'encode-time
(org-parse-time-string ts
))))
3405 h
(floor (/ s
3600))
3409 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3412 (defun org-check-running-clock ()
3413 "Check if the current buffer contains the running clock.
3414 If yes, offer to stop it and to save the buffer with the changes."
3415 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3416 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3419 (when (y-or-n-p "Save changed buffer?")
3422 (defun org-clocktable-try-shift (dir n
)
3423 "Check if this line starts a clock table, if yes, shift the time block."
3424 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3425 (org-clocktable-shift dir n
)))
3427 ;; Autoload org-timer.el
3432 '(org-timer-start org-timer org-timer-item
3433 org-timer-change-times-in-region
3435 org-timer-reset-timers
3436 org-timer-show-remaining-time
)))
3438 ;; Autoload org-feed.el
3443 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3446 ;; Autoload org-indent.el
3448 ;; Define the variable already here, to make sure we have it.
3449 (defvar org-indent-mode nil
3450 "Non-nil if Org-Indent mode is enabled.
3451 Use the command `org-indent-mode' to change this variable.")
3456 '(org-indent-mode)))
3458 ;; Autoload org-mobile.el
3463 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3465 ;; Autoload archiving code
3466 ;; The stuff that is needed for cycling and tags has to be defined here.
3468 (defgroup org-archive nil
3469 "Options concerning archiving in Org-mode."
3471 :group
'org-structure
)
3473 (defcustom org-archive-location
"%s_archive::"
3474 "The location where subtrees should be archived.
3476 The value of this variable is a string, consisting of two parts,
3477 separated by a double-colon. The first part is a filename and
3478 the second part is a headline.
3480 When the filename is omitted, archiving happens in the same file.
3481 %s in the filename will be replaced by the current file
3482 name (without the directory part). Archiving to a different file
3483 is useful to keep archived entries from contributing to the
3486 The archived entries will be filed as subtrees of the specified
3487 headline. When the headline is omitted, the subtrees are simply
3488 filed away at the end of the file, as top-level entries. Also in
3489 the heading you can use %s to represent the file name, this can be
3490 useful when using the same archive for a number of different files.
3492 Here are a few examples:
3494 If the current file is Projects.org, archive in file
3495 Projects.org_archive, as top-level trees. This is the default.
3497 \"::* Archived Tasks\"
3498 Archive in the current file, under the top-level headline
3499 \"* Archived Tasks\".
3501 \"~/org/archive.org::\"
3502 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3504 \"~/org/archive.org::From %s\"
3505 Archive in file ~/org/archive.org (absolute path), under headlines
3506 \"From FILENAME\" where file name is the current file name.
3508 \"basement::** Finished Tasks\"
3509 Archive in file ./basement (relative path), as level 3 trees
3510 below the level 2 heading \"** Finished Tasks\".
3512 You may set this option on a per-file basis by adding to the buffer a
3515 #+ARCHIVE: basement::** Finished Tasks
3517 You may also define it locally for a subtree by setting an ARCHIVE property
3518 in the entry. If such a property is found in an entry, or anywhere up
3519 the hierarchy, it will be used."
3523 (defcustom org-archive-tag
"ARCHIVE"
3524 "The tag that marks a subtree as archived.
3525 An archived subtree does not open during visibility cycling, and does
3526 not contribute to the agenda listings.
3527 After changing this, font-lock must be restarted in the relevant buffers to
3528 get the proper fontification."
3530 :group
'org-keywords
3533 (defcustom org-agenda-skip-archived-trees t
3534 "Non-nil means, the agenda will skip any items located in archived trees.
3535 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3536 variable is no longer recommended, you should leave it at the value t.
3537 Instead, use the key `v' to cycle the archives-mode in the agenda."
3539 :group
'org-agenda-skip
3542 (defcustom org-columns-skip-archived-trees t
3543 "Non-nil means, ignore archived trees when creating column view."
3545 :group
'org-properties
3548 (defcustom org-cycle-open-archived-trees nil
3549 "Non-nil means, `org-cycle' will open archived trees.
3550 An archived tree is a tree marked with the tag ARCHIVE.
3551 When nil, archived trees will stay folded. You can still open them with
3552 normal outline commands like `show-all', but not with the cycling commands."
3557 (defcustom org-sparse-tree-open-archived-trees nil
3558 "Non-nil means sparse tree construction shows matches in archived trees.
3559 When nil, matches in these trees are highlighted, but the trees are kept in
3562 :group
'org-sparse-trees
3565 (defun org-cycle-hide-archived-subtrees (state)
3566 "Re-hide all archived subtrees after a visibility state change."
3567 (when (and (not org-cycle-open-archived-trees
)
3568 (not (memq state
'(overview folded
))))
3570 (let* ((globalp (memq state
'(contents all
)))
3571 (beg (if globalp
(point-min) (point)))
3572 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3573 (org-hide-archived-subtrees beg end
)
3575 (if (looking-at (concat ".*:" org-archive-tag
":"))
3576 (message "%s" (substitute-command-keys
3577 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3579 (defun org-force-cycle-archived ()
3580 "Cycle subtree even if it is archived."
3582 (setq this-command
'org-cycle
)
3583 (let ((org-cycle-open-archived-trees t
))
3584 (call-interactively 'org-cycle
)))
3586 (defun org-hide-archived-subtrees (beg end
)
3587 "Re-hide all archived subtrees after a visibility state change."
3589 (let* ((re (concat ":" org-archive-tag
":")))
3591 (while (re-search-forward re end t
)
3592 (and (org-on-heading-p) (org-flag-subtree t
))
3593 (org-end-of-subtree t
)))))
3595 (defun org-flag-subtree (flag)
3597 (org-back-to-heading t
)
3598 (outline-end-of-heading)
3599 (outline-flag-region (point)
3600 (progn (org-end-of-subtree t
) (point))
3603 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3606 (org-autoload "org-archive"
3607 '(org-add-archive-files org-archive-subtree
3608 org-archive-to-archive-sibling org-toggle-archive-tag
3609 org-archive-subtree-default
3610 org-archive-subtree-default-with-confirmation
)))
3612 ;; Autoload Column View Code
3614 (declare-function org-columns-number-to-string
"org-colview")
3615 (declare-function org-columns-get-format-and-top-level
"org-colview")
3616 (declare-function org-columns-compute
"org-colview")
3618 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3619 '(org-columns-number-to-string org-columns-get-format-and-top-level
3620 org-columns-compute org-agenda-columns org-columns-remove-overlays
3621 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3625 (declare-function org-id-store-link
"org-id")
3626 (declare-function org-id-locations-load
"org-id")
3627 (declare-function org-id-locations-save
"org-id")
3628 (defvar org-id-track-globally
)
3629 (org-autoload "org-id"
3630 '(org-id-get-create org-id-new org-id-copy org-id-get
3631 org-id-get-with-outline-path-completion
3632 org-id-get-with-outline-drilling
3633 org-id-goto org-id-find org-id-store-link
))
3635 ;; Autoload Plotting Code
3637 (org-autoload "org-plot"
3638 '(org-plot/gnuplot
))
3640 ;;; Variables for pre-computed regular expressions, all buffer local
3642 (defvar org-drawer-regexp nil
3643 "Matches first line of a hidden block.")
3644 (make-variable-buffer-local 'org-drawer-regexp
)
3645 (defvar org-todo-regexp nil
3646 "Matches any of the TODO state keywords.")
3647 (make-variable-buffer-local 'org-todo-regexp
)
3648 (defvar org-not-done-regexp nil
3649 "Matches any of the TODO state keywords except the last one.")
3650 (make-variable-buffer-local 'org-not-done-regexp
)
3651 (defvar org-not-done-heading-regexp nil
3652 "Matches a TODO headline that is not done.")
3653 (make-variable-buffer-local 'org-not-done-regexp
)
3654 (defvar org-todo-line-regexp nil
3655 "Matches a headline and puts TODO state into group 2 if present.")
3656 (make-variable-buffer-local 'org-todo-line-regexp
)
3657 (defvar org-complex-heading-regexp nil
3658 "Matches a headline and puts everything into groups:
3660 group 2: The todo keyword, maybe
3661 group 3: Priority cookie
3662 group 4: True headline
3664 (make-variable-buffer-local 'org-complex-heading-regexp
)
3665 (defvar org-complex-heading-regexp-format nil
)
3666 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3667 (defvar org-todo-line-tags-regexp nil
3668 "Matches a headline and puts TODO state into group 2 if present.
3669 Also put tags into group 4 if tags are present.")
3670 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3671 (defvar org-nl-done-regexp nil
3672 "Matches newline followed by a headline with the DONE keyword.")
3673 (make-variable-buffer-local 'org-nl-done-regexp
)
3674 (defvar org-looking-at-done-regexp nil
3675 "Matches the DONE keyword a point.")
3676 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3677 (defvar org-ds-keyword-length
12
3678 "Maximum length of the Deadline and SCHEDULED keywords.")
3679 (make-variable-buffer-local 'org-ds-keyword-length
)
3680 (defvar org-deadline-regexp nil
3681 "Matches the DEADLINE keyword.")
3682 (make-variable-buffer-local 'org-deadline-regexp
)
3683 (defvar org-deadline-time-regexp nil
3684 "Matches the DEADLINE keyword together with a time stamp.")
3685 (make-variable-buffer-local 'org-deadline-time-regexp
)
3686 (defvar org-deadline-line-regexp nil
3687 "Matches the DEADLINE keyword and the rest of the line.")
3688 (make-variable-buffer-local 'org-deadline-line-regexp
)
3689 (defvar org-scheduled-regexp nil
3690 "Matches the SCHEDULED keyword.")
3691 (make-variable-buffer-local 'org-scheduled-regexp
)
3692 (defvar org-scheduled-time-regexp nil
3693 "Matches the SCHEDULED keyword together with a time stamp.")
3694 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3695 (defvar org-closed-time-regexp nil
3696 "Matches the CLOSED keyword together with a time stamp.")
3697 (make-variable-buffer-local 'org-closed-time-regexp
)
3699 (defvar org-keyword-time-regexp nil
3700 "Matches any of the 4 keywords, together with the time stamp.")
3701 (make-variable-buffer-local 'org-keyword-time-regexp
)
3702 (defvar org-keyword-time-not-clock-regexp nil
3703 "Matches any of the 3 keywords, together with the time stamp.")
3704 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
3705 (defvar org-maybe-keyword-time-regexp nil
3706 "Matches a timestamp, possibly preceeded by a keyword.")
3707 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
3708 (defvar org-planning-or-clock-line-re nil
3709 "Matches a line with planning or clock info.")
3710 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
3711 (defvar org-all-time-keywords nil
3712 "List of time keywords.")
3713 (make-variable-buffer-local 'org-all-time-keywords
)
3715 (defconst org-plain-time-of-day-regexp
3718 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3721 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3723 "Regular expression to match a plain time or time range.
3724 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3725 groups carry important information:
3727 1 the first time, range or not
3728 8 the second time, if it is a range.")
3730 (defconst org-plain-time-extension-regexp
3733 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3734 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3735 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3736 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3737 groups carry important information:
3740 9 minutes of duration")
3742 (defconst org-stamp-time-of-day-regexp
3744 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3745 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3747 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3748 "Regular expression to match a timestamp time or time range.
3749 After a match, the following groups carry important information:
3751 1 date plus weekday, for back referencing to make sure both times are on the same day
3752 2 the first time, range or not
3753 4 the second time, if it is a range.")
3755 (defconst org-startup-options
3756 '(("fold" org-startup-folded t
)
3757 ("overview" org-startup-folded t
)
3758 ("nofold" org-startup-folded nil
)
3759 ("showall" org-startup-folded nil
)
3760 ("showeverything" org-startup-folded showeverything
)
3761 ("content" org-startup-folded content
)
3762 ("indent" org-startup-indented t
)
3763 ("noindent" org-startup-indented nil
)
3764 ("hidestars" org-hide-leading-stars t
)
3765 ("showstars" org-hide-leading-stars nil
)
3766 ("odd" org-odd-levels-only t
)
3767 ("oddeven" org-odd-levels-only nil
)
3768 ("align" org-startup-align-all-tables t
)
3769 ("noalign" org-startup-align-all-tables nil
)
3770 ("customtime" org-display-custom-times t
)
3771 ("logdone" org-log-done time
)
3772 ("lognotedone" org-log-done note
)
3773 ("nologdone" org-log-done nil
)
3774 ("lognoteclock-out" org-log-note-clock-out t
)
3775 ("nolognoteclock-out" org-log-note-clock-out nil
)
3776 ("logrepeat" org-log-repeat state
)
3777 ("lognoterepeat" org-log-repeat note
)
3778 ("nologrepeat" org-log-repeat nil
)
3779 ("logreschedule" org-log-reschedule time
)
3780 ("lognotereschedule" org-log-reschedule note
)
3781 ("nologreschedule" org-log-reschedule nil
)
3782 ("logredeadline" org-log-redeadline time
)
3783 ("lognoteredeadline" org-log-redeadline note
)
3784 ("nologredeadline" org-log-redeadline nil
)
3785 ("fninline" org-footnote-define-inline t
)
3786 ("nofninline" org-footnote-define-inline nil
)
3787 ("fnlocal" org-footnote-section nil
)
3788 ("fnauto" org-footnote-auto-label t
)
3789 ("fnprompt" org-footnote-auto-label nil
)
3790 ("fnconfirm" org-footnote-auto-label confirm
)
3791 ("fnplain" org-footnote-auto-label plain
)
3792 ("fnadjust" org-footnote-auto-adjust t
)
3793 ("nofnadjust" org-footnote-auto-adjust nil
)
3794 ("constcgs" constants-unit-system cgs
)
3795 ("constSI" constants-unit-system SI
)
3796 ("noptag" org-tag-persistent-alist nil
)
3797 ("hideblocks" org-hide-block-startup t
)
3798 ("nohideblocks" org-hide-block-startup nil
)
3799 ("beamer" org-startup-with-beamer-mode t
))
3800 "Variable associated with STARTUP options for org-mode.
3801 Each element is a list of three items: The startup options as written
3802 in the #+STARTUP line, the corresponding variable, and the value to
3803 set this variable to if the option is found. An optional forth element PUSH
3804 means to push this value onto the list in the variable.")
3806 (defun org-set-regexps-and-options ()
3807 "Precompute regular expressions for current buffer."
3809 (org-set-local 'org-todo-kwd-alist nil
)
3810 (org-set-local 'org-todo-key-alist nil
)
3811 (org-set-local 'org-todo-key-trigger nil
)
3812 (org-set-local 'org-todo-keywords-1 nil
)
3813 (org-set-local 'org-done-keywords nil
)
3814 (org-set-local 'org-todo-heads nil
)
3815 (org-set-local 'org-todo-sets nil
)
3816 (org-set-local 'org-todo-log-states nil
)
3817 (org-set-local 'org-file-properties nil
)
3818 (org-set-local 'org-file-tags nil
)
3819 (let ((re (org-make-options-regexp
3820 '("CATEGORY" "TODO" "COLUMNS"
3821 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
3822 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS")
3823 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
3825 kwds kws0 kwsa key log value cat arch tags const links hw dws
3826 tail sep kws1 prio props ftags drawers beamer-p
3827 ext-setup-or-nil setup-contents
(start 0))
3831 (goto-char (point-min))
3832 (while (or (and ext-setup-or-nil
3833 (string-match re ext-setup-or-nil start
)
3834 (setq start
(match-end 0)))
3835 (and (setq ext-setup-or-nil nil start
0)
3836 (re-search-forward re nil t
)))
3837 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
3838 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
3840 ((equal key
"CATEGORY")
3841 (if (string-match "[ \t]+$" value
)
3842 (setq value
(replace-match "" t t value
)))
3844 ((member key
'("SEQ_TODO" "TODO"))
3845 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
3846 ((equal key
"TYP_TODO")
3847 (push (cons 'type
(org-split-string value splitre
)) kwds
))
3848 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
3849 ;; general TODO-like setup
3850 (push (cons (intern (downcase (match-string 1 key
)))
3851 (org-split-string value splitre
)) kwds
))
3853 (setq tags
(append tags
(if tags
'("\\n") nil
)
3854 (org-split-string value splitre
))))
3855 ((equal key
"COLUMNS")
3856 (org-set-local 'org-columns-default-format value
))
3858 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
3859 (push (cons (match-string 1 value
)
3860 (org-trim (match-string 2 value
)))
3862 ((equal key
"PRIORITIES")
3863 (setq prio
(org-split-string value
" +")))
3864 ((equal key
"PROPERTY")
3865 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
3866 (push (cons (match-string 1 value
) (match-string 2 value
))
3868 ((equal key
"FILETAGS")
3869 (when (string-match "\\S-" value
)
3874 (mapcar (lambda (x) (org-split-string x
":"))
3875 (org-split-string value
)))))))
3876 ((equal key
"DRAWERS")
3877 (setq drawers
(org-split-string value splitre
)))
3878 ((equal key
"CONSTANTS")
3879 (setq const
(append const
(org-split-string value splitre
))))
3880 ((equal key
"STARTUP")
3881 (let ((opts (org-split-string value splitre
))
3883 (while (setq l
(pop opts
))
3884 (when (setq l
(assoc l org-startup-options
))
3885 (setq var
(nth 1 l
) val
(nth 2 l
))
3887 (set (make-local-variable var
) val
)
3888 (if (not (listp (symbol-value var
)))
3889 (set (make-local-variable var
) nil
))
3890 (set (make-local-variable var
) (symbol-value var
))
3891 (add-to-list var val
))))))
3892 ((equal key
"ARCHIVE")
3893 (string-match " *$" value
)
3894 (setq arch
(replace-match "" t t value
))
3895 (remove-text-properties 0 (length arch
)
3896 '(face t fontified t
) arch
))
3897 ((equal key
"LATEX_CLASS")
3898 (setq beamer-p
(equal value
"beamer")))
3899 ((equal key
"SETUPFILE")
3900 (setq setup-contents
(org-file-contents
3902 (org-remove-double-quotes value
))
3904 (if (not ext-setup-or-nil
)
3905 (setq ext-setup-or-nil setup-contents start
0)
3906 (setq ext-setup-or-nil
3907 (concat (substring ext-setup-or-nil
0 start
)
3908 "\n" setup-contents
"\n"
3909 (substring ext-setup-or-nil start
)))))
3912 (org-set-local 'org-category
(intern cat
))
3913 (push (cons "CATEGORY" cat
) props
))
3915 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
3916 (setq prio
(mapcar 'string-to-char prio
))
3917 (org-set-local 'org-highest-priority
(nth 0 prio
))
3918 (org-set-local 'org-lowest-priority
(nth 1 prio
))
3919 (org-set-local 'org-default-priority
(nth 2 prio
)))
3920 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
3921 (and ftags
(org-set-local 'org-file-tags
3922 (mapcar 'org-add-prop-inherited ftags
)))
3923 (and drawers
(org-set-local 'org-drawers drawers
))
3924 (and arch
(org-set-local 'org-archive-location arch
))
3925 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
3926 ;; Process the TODO keywords
3928 ;; Use the global values as if they had been given locally.
3929 (setq kwds
(default-value 'org-todo-keywords
))
3930 (if (stringp (car kwds
))
3931 (setq kwds
(list (cons org-todo-interpretation
3932 (default-value 'org-todo-keywords
)))))
3933 (setq kwds
(reverse kwds
)))
3934 (setq kwds
(nreverse kwds
))
3936 (while (setq kws
(pop kwds
))
3938 (run-hook-with-args-until-success
3939 'org-todo-setup-filter-hook kws
)
3941 (setq inter
(pop kws
) sep
(member "|" kws
)
3942 kws0
(delete "|" (copy-sequence kws
))
3947 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
3949 (setq kw
(match-string 1 x
)
3950 key
(and (match-end 2) (match-string 2 x
))
3951 log
(org-extract-log-state-settings x
))
3952 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
3953 (and log
(push log org-todo-log-states
))
3955 (error "Invalid TODO keyword %s" x
)))
3957 kwsa
(if kwsa
(append '((:startgroup
))
3961 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
3962 tail
(list inter hw
(car dws
) (org-last dws
))))
3963 (add-to-list 'org-todo-heads hw
'append
)
3964 (push kws1 org-todo-sets
)
3965 (setq org-done-keywords
(append org-done-keywords dws nil
))
3966 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
3967 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
3968 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
3969 (setq org-todo-sets
(nreverse org-todo-sets
)
3970 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
3971 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
3972 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
3973 ;; Process the constants
3976 (while (setq e
(pop const
))
3977 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
3978 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
3979 (setq org-table-formula-constants-local cst
)))
3981 ;; Process the tags.
3984 (while (setq e
(pop tags
))
3986 ((equal e
"{") (push '(:startgroup
) tgs
))
3987 ((equal e
"}") (push '(:endgroup
) tgs
))
3988 ((equal e
"\\n") (push '(:newline
) tgs
))
3989 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
3990 (push (cons (match-string 1 e
)
3991 (string-to-char (match-string 2 e
)))
3993 (t (push (list e
) tgs
))))
3994 (org-set-local 'org-tag-alist nil
)
3995 (while (setq e
(pop tgs
))
3996 (or (and (stringp (car e
))
3997 (assoc (car e
) org-tag-alist
))
3998 (push e org-tag-alist
)))))
4000 ;; Compute the regular expressions and other local variables
4001 (if (not org-done-keywords
)
4002 (setq org-done-keywords
(and org-todo-keywords-1
4003 (list (org-last org-todo-keywords-1
)))))
4004 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4005 (length org-scheduled-string
)
4006 (length org-clock-string
)
4007 (length org-closed-string
)))
4009 (concat "^[ \t]*:\\("
4010 (mapconcat 'regexp-quote org-drawers
"\\|")
4012 org-not-done-keywords
4013 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4015 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4019 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4021 org-not-done-heading-regexp
4022 (concat "^\\(\\*+\\)[ \t]+\\("
4023 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4025 org-todo-line-regexp
4026 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4027 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4028 "\\)\\>\\)?[ \t]*\\(.*\\)")
4029 org-complex-heading-regexp
4030 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4031 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4032 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4033 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4034 org-complex-heading-regexp-format
4035 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4036 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4037 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(%s\\)"
4038 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4040 (concat "\n\\*+[ \t]+"
4041 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4043 org-todo-line-tags-regexp
4044 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4045 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4047 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4048 org-looking-at-done-regexp
4050 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4052 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4053 org-deadline-time-regexp
4054 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4055 org-deadline-line-regexp
4056 (concat "\\<\\(" org-deadline-string
"\\).*")
4057 org-scheduled-regexp
4058 (concat "\\<" org-scheduled-string
)
4059 org-scheduled-time-regexp
4060 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4061 org-closed-time-regexp
4062 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4063 org-keyword-time-regexp
4064 (concat "\\<\\(" org-scheduled-string
4065 "\\|" org-deadline-string
4066 "\\|" org-closed-string
4067 "\\|" org-clock-string
"\\)"
4068 " *[[<]\\([^]>]+\\)[]>]")
4069 org-keyword-time-not-clock-regexp
4070 (concat "\\<\\(" org-scheduled-string
4071 "\\|" org-deadline-string
4072 "\\|" org-closed-string
4074 " *[[<]\\([^]>]+\\)[]>]")
4075 org-maybe-keyword-time-regexp
4076 (concat "\\(\\<\\(" org-scheduled-string
4077 "\\|" org-deadline-string
4078 "\\|" org-closed-string
4079 "\\|" org-clock-string
"\\)\\)?"
4080 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4081 org-planning-or-clock-line-re
4082 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4083 "\\|" org-deadline-string
4084 "\\|" org-closed-string
"\\|" org-clock-string
4086 org-all-time-keywords
4087 (mapcar (lambda (w) (substring w
0 -
1))
4088 (list org-scheduled-string org-deadline-string
4089 org-clock-string org-closed-string
))
4091 (org-compute-latex-and-specials-regexp)
4092 (org-set-font-lock-defaults))))
4094 (defun org-file-contents (file &optional noerror
)
4095 "Return the contents of FILE, as a string."
4097 (not (file-readable-p file
)))
4100 (message "Cannot read file %s" file
)
4103 (error "Cannot read file %s" file
))
4105 (insert-file-contents file
)
4108 (defun org-extract-log-state-settings (x)
4109 "Extract the log state setting from a TODO keyword string.
4110 This will extract info from a string like \"WAIT(w@/!)\"."
4111 (let (kw key log1 log2
)
4112 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4113 (setq kw
(match-string 1 x
)
4114 key
(and (match-end 2) (match-string 2 x
))
4115 log1
(and (match-end 3) (match-string 3 x
))
4116 log2
(and (match-end 4) (match-string 4 x
)))
4119 (and log1
(if (equal log1
"!") 'time
'note
))
4120 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4122 (defun org-remove-keyword-keys (list)
4123 "Remove a pair of parenthesis at the end of each string in LIST."
4125 (if (string-match "(.*)$" x
)
4126 (substring x
0 (match-beginning 0))
4130 ;; FIXME: this could be done much better, using second characters etc.
4131 (defun org-assign-fast-keys (alist)
4132 "Assign fast keys to a keyword-key alist.
4133 Respect keys that are already there."
4134 (let (new e k c c1 c2
(char ?a
))
4135 (while (setq e
(pop alist
))
4137 ((equal e
'(:startgroup
)) (push e new
))
4138 ((equal e
'(:endgroup
)) (push e new
))
4139 ((equal e
'(:newline
)) (push e new
))
4141 (setq k
(car e
) c2 nil
)
4144 ;; automatically assign a character.
4145 (setq c1
(string-to-char
4146 (downcase (substring
4147 k
(if (= (string-to-char k
) ?
@) 1 0)))))
4148 (if (or (rassoc c1 new
) (rassoc c1 alist
))
4149 (while (or (rassoc char new
) (rassoc char alist
))
4150 (setq char
(1+ char
)))
4152 (setq c
(or c2 char
)))
4153 (push (cons k c
) new
))))
4156 ;;; Some variables used in various places
4158 (defvar org-window-configuration nil
4159 "Used in various places to store a window configuration.")
4160 (defvar org-selected-window nil
4161 "Used in various places to store a window configuration.")
4162 (defvar org-finish-function nil
4163 "Function to be called when `C-c C-c' is used.
4164 This is for getting out of special buffers like remember.")
4167 ;; FIXME: Occasionally check by commenting these, to make sure
4168 ;; no other functions uses these, forgetting to let-bind them.
4173 ;; Defined somewhere in this file, but used before definition.
4174 (defvar org-html-entities
)
4175 (defvar org-struct-menu
)
4176 (defvar org-org-menu
)
4177 (defvar org-tbl-menu
)
4179 ;;;; Define the Org-mode
4181 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4182 (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."))
4185 ;; We use a before-change function to check if a table might need
4187 (defvar org-table-may-need-update t
4188 "Indicates that a table might need an update.
4189 This variable is set by `org-before-change-function'.
4190 `org-table-align' sets it back to nil.")
4191 (defun org-before-change-function (beg end
)
4192 "Every change indicates that a table might need an update."
4193 (setq org-table-may-need-update t
))
4194 (defvar org-mode-map
)
4195 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4196 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4197 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4198 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4199 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4200 (defvar org-table-buffer-is-an nil
)
4201 (defconst org-outline-regexp
"\\*+ ")
4204 (define-derived-mode org-mode outline-mode
"Org"
4205 "Outline-based notes management and organizer, alias
4206 \"Carsten's outline-mode for keeping track of everything.\"
4208 Org-mode develops organizational tasks around a NOTES file which
4209 contains information about projects as plain text. Org-mode is
4210 implemented on top of outline-mode, which is ideal to keep the content
4211 of large files well structured. It supports ToDo items, deadlines and
4212 time stamps, which magically appear in the diary listing of the Emacs
4213 calendar. Tables are easily created with a built-in table editor.
4214 Plain text URL-like links connect to websites, emails (VM), Usenet
4215 messages (Gnus), BBDB entries, and any files related to the project.
4216 For printing and sharing of notes, an Org-mode file (or a part of it)
4217 can be exported as a structured ASCII or HTML file.
4219 The following commands are available:
4223 ;; Get rid of Outline menus, they are not needed
4224 ;; Need to do this here because define-derived-mode sets up
4225 ;; the keymap so late. Still, it is a waste to call this each time
4226 ;; we switch another buffer into org-mode.
4227 (if (featurep 'xemacs
)
4228 (when (boundp 'outline-mode-menu-heading
)
4229 ;; Assume this is Greg's port, it used easymenu
4230 (easy-menu-remove outline-mode-menu-heading
)
4231 (easy-menu-remove outline-mode-menu-show
)
4232 (easy-menu-remove outline-mode-menu-hide
))
4233 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4234 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4235 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4237 (org-load-modules-maybe)
4238 (easy-menu-add org-org-menu
)
4239 (easy-menu-add org-tbl-menu
)
4240 (org-install-agenda-files-menu)
4241 (if org-descriptive-links
(org-add-to-invisibility-spec '(org-link)))
4242 (org-add-to-invisibility-spec '(org-cwidth))
4243 (org-add-to-invisibility-spec '(org-hide-block . t
))
4244 (when (featurep 'xemacs
)
4245 (org-set-local 'line-move-ignore-invisible t
))
4246 (org-set-local 'outline-regexp org-outline-regexp
)
4247 (org-set-local 'outline-level
'org-outline-level
)
4248 (when (and org-ellipsis
4249 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4250 (fboundp 'make-glyph-code
))
4251 (unless org-display-table
4252 (setq org-display-table
(make-display-table)))
4253 (set-display-table-slot
4256 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4258 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4259 (setq buffer-display-table org-display-table
))
4260 (org-set-regexps-and-options)
4261 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4262 ;; tag faces set outside customize.... force initialization.
4263 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4265 (org-set-local 'calc-embedded-open-mode
"# ")
4266 (modify-syntax-entry ?
# "<")
4267 (modify-syntax-entry ?
@ "w")
4268 (if org-startup-truncated
(setq truncate-lines t
))
4269 (org-set-local 'font-lock-unfontify-region-function
4270 'org-unfontify-region
)
4271 ;; Activate before-change-function
4272 (org-set-local 'org-table-may-need-update t
)
4273 (org-add-hook 'before-change-functions
'org-before-change-function nil
4275 ;; Check for running clock before killing a buffer
4276 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4277 ;; Paragraphs and auto-filling
4278 (org-set-autofill-regexps)
4279 (setq indent-line-function
'org-indent-line-function
)
4280 (org-update-radio-target-regexp)
4281 ;; Make sure dependence stuff works reliably, even for users who set it
4283 (if org-enforce-todo-dependencies
4284 (add-hook 'org-blocker-hook
4285 'org-block-todo-from-children-or-siblings-or-parent
)
4286 (remove-hook 'org-blocker-hook
4287 'org-block-todo-from-children-or-siblings-or-parent
))
4288 (if org-enforce-todo-checkbox-dependencies
4289 (add-hook 'org-blocker-hook
4290 'org-block-todo-from-checkboxes
)
4291 (remove-hook 'org-blocker-hook
4292 'org-block-todo-from-checkboxes
))
4294 ;; Comment characters
4295 ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
4296 (org-set-local 'comment-padding
" ")
4298 ;; Align options lines
4300 'align-mode-rules-list
4301 '((org-in-buffer-settings
4302 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4303 (modes .
'(org-mode)))))
4306 (org-set-local 'imenu-create-index-function
4307 'org-imenu-get-tree
)
4309 ;; Make isearch reveal context
4310 (if (or (featurep 'xemacs
)
4311 (not (boundp 'outline-isearch-open-invisible-function
)))
4312 ;; Emacs 21 and XEmacs make use of the hook
4313 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4314 ;; Emacs 22 deals with this through a special variable
4315 (org-set-local 'outline-isearch-open-invisible-function
4316 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4318 ;; Turn on org-beamer-mode?
4319 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4321 ;; If empty file that did not turn on org-mode automatically, make it to.
4322 (if (and org-insert-mode-line-in-empty-file
4324 (= (point-min) (point-max)))
4325 (insert "# -*- mode: org -*-\n\n"))
4326 (unless org-inhibit-startup
4327 (when org-startup-align-all-tables
4328 (let ((bmp (buffer-modified-p)))
4329 (org-table-map-tables 'org-table-align
)
4330 (set-buffer-modified-p bmp
)))
4331 (when org-startup-indented
4332 (require 'org-indent
)
4333 (org-indent-mode 1))
4334 (unless org-inhibit-startup-visibility-stuff
4335 (org-set-startup-visibility))))
4337 (when (fboundp 'abbrev-table-put
)
4338 (abbrev-table-put org-mode-abbrev-table
4339 :parents
(list text-mode-abbrev-table
)))
4341 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4343 (defun org-current-time ()
4344 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4345 (if (> (car org-time-stamp-rounding-minutes
) 1)
4346 (let ((r (car org-time-stamp-rounding-minutes
))
4347 (time (decode-time)))
4349 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4353 ;;;; Font-Lock stuff, including the activators
4355 (defvar org-mouse-map
(make-sparse-keymap))
4356 (org-defkey org-mouse-map
4357 (if (featurep 'xemacs
) [button2] [mouse-2]) 'org-open-at-mouse)
4358 (org-defkey org-mouse-map
4359 (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
4360 (when org-mouse-1-follows-link
4361 (org-defkey org-mouse-map [follow-link] 'mouse-face))
4362 (when org-tab-follows-link
4363 (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
4364 (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
4366 (require 'font-lock)
4368 (defconst org-non-link-chars "]\t\n\r<>")
4369 (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
4371 (defvar org-link-types-re nil
4372 "Matches a link that has a url-like prefix like \"http:\"")
4373 (defvar org-link-re-with-space nil
4374 "Matches a link with spaces, optional angular brackets around it.")
4375 (defvar org-link-re-with-space2 nil
4376 "Matches a link with spaces, optional angular brackets around it.")
4377 (defvar org-link-re-with-space3 nil
4378 "Matches a link with spaces, only for internal part in bracket links.")
4379 (defvar org-angle-link-re nil
4380 "Matches link with angular brackets, spaces are allowed.")
4381 (defvar org-plain-link-re nil
4382 "Matches plain link, without spaces.")
4383 (defvar org-bracket-link-regexp nil
4384 "Matches a link in double brackets.")
4385 (defvar org-bracket-link-analytic-regexp nil
4386 "Regular expression used to analyze links.
4387 Here is what the match groups contain after a match:
4393 (defvar org-bracket-link-analytic-regexp++ nil
4394 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4395 (defvar org-any-link-re nil
4396 "Regular expression matching any link.")
4398 (defun org-make-link-regexps ()
4399 "Update the link regular expressions.
4400 This should be called after the variable `org-link-types' has changed."
4401 (setq org-link-types-re
4403 "\\`\\(" (mapconcat 'identity org-link-types "\\|") "\\):")
4404 org-link-re-with-space
4406 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
4407 "\\([^" org-non-link-chars " ]"
4408 "[^" org-non-link-chars "]*"
4409 "[^" org-non-link-chars " ]\\)>?")
4410 org-link-re-with-space2
4412 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
4413 "\\([^" org-non-link-chars " ]"
4415 "[^" org-non-link-chars " ]\\)>?")
4416 org-link-re-with-space3
4418 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
4419 "\\([^" org-non-link-chars " ]"
4423 "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
4424 "\\([^" org-non-link-chars " ]"
4425 "[^" org-non-link-chars "]*"
4429 "\\<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
4430 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4431 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4432 org-bracket-link-regexp
4433 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4434 org-bracket-link-analytic-regexp
4437 "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?"
4440 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4442 org-bracket-link-analytic-regexp++
4445 "\\(\\(" (mapconcat 'identity (cons "coderef" org-link-types) "\\|") "\\):\\)?"
4448 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4451 (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
4452 org-angle-link-re "\\)\\|\\("
4453 org-plain-link-re "\\)")))
4455 (org-make-link-regexps)
4457 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4458 "Regular expression for fast time stamp matching.")
4459 (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4460 "Regular expression for fast time stamp matching.")
4461 (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4462 "Regular expression matching time strings for analysis.
4463 This one does not require the space after the date, so it can be used
4464 on a string that terminates immediately after the date.")
4465 (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4466 "Regular expression matching time strings for analysis.")
4467 (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
4468 "Regular expression matching time stamps, with groups.")
4469 (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
4470 "Regular expression matching time stamps (also [..]), with groups.")
4471 (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
4472 "Regular expression matching a time stamp range.")
4473 (defconst org-tr-regexp-both
4474 (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
4475 "Regular expression matching a time stamp range.")
4476 (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
4477 org-ts-regexp "\\)?")
4478 "Regular expression matching a time stamp or time stamp range.")
4479 (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
4480 org-ts-regexp-both "\\)?")
4481 "Regular expression matching a time stamp or time stamp range.
4482 The time stamps may be either active or inactive.")
4484 (defvar org-emph-face nil)
4486 (defun org-do-emphasis-faces (limit)
4487 "Run through the buffer and add overlays to links."
4489 (while (and (not rtn) (re-search-forward org-emph-re limit t))
4490 (if (not (= (char-after (match-beginning 3))
4491 (char-after (match-beginning 4))))
4494 (setq a (assoc (match-string 3) org-emphasis-alist))
4495 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4499 (org-remove-flyspell-overlays-in
4500 (match-beginning 0) (match-end 0)))
4501 (add-text-properties (match-beginning 2) (match-end 2)
4502 '(font-lock-multiline t))
4503 (when org-hide-emphasis-markers
4504 (add-text-properties (match-end 4) (match-beginning 5)
4505 '(invisible org-link))
4506 (add-text-properties (match-beginning 3) (match-end 3)
4507 '(invisible org-link)))))
4511 (defun org-emphasize (&optional char)
4512 "Insert or change an emphasis, i.e. a font like bold or italic.
4513 If there is an active region, change that region to a new emphasis.
4514 If there is no region, just insert the marker characters and position
4515 the cursor between them.
4516 CHAR should be either the marker character, or the first character of the
4517 HTML tag associated with that emphasis. If CHAR is a space, the means
4518 to remove the emphasis of the selected region.
4519 If char is not given (for example in an interactive call) it
4520 will be prompted for."
4522 (let ((eal org-emphasis-alist) e det
4523 (erc org-emphasis-regexp-components)
4525 (string "") beg end move tag c s)
4526 (if (org-region-active-p)
4527 (setq beg (region-beginning) end (region-end)
4528 string (buffer-substring beg end))
4531 (while (setq e (pop eal))
4532 (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
4534 (push (cons c (string-to-char (car e))) det)
4535 (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
4536 (substring tag 1)))))
4537 (setq det (nreverse det))
4539 (message "%s" (concat "Emphasis marker or tag:" prompt))
4540 (setq char (read-char-exclusive)))
4541 (setq char (or (cdr (assoc char det)) char))
4542 (if (equal char ?\ )
4543 (setq s "" move nil)
4544 (unless (assoc (char-to-string char) org-emphasis-alist)
4545 (error "No such emphasis marker: \"%c\"" char))
4546 (setq s (char-to-string char)))
4547 (while (and (> (length string) 1)
4548 (equal (substring string 0 1) (substring string -1))
4549 (assoc (substring string 0 1) org-emphasis-alist))
4550 (setq string (substring string 1 -1)))
4551 (setq string (concat s string s))
4552 (if beg (delete-region beg end))
4554 (string-match (concat "[" (nth 0 erc) "\n]")
4555 (char-to-string (char-before (point)))))
4557 (unless (string-match (concat "[" (nth 1 erc) "\n]")
4558 (char-to-string (char-after (point))))
4559 (insert " ") (backward-char 1))
4561 (and move (backward-char 1))))
4563 (defconst org-nonsticky-props
4564 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
4566 (defsubst org-rear-nonsticky-at (pos)
4567 (add-text-properties (1- pos) pos (list 'rear-nonsticky org-nonsticky-props)))
4569 (defun org-activate-plain-links (limit)
4570 "Run through the buffer and add overlays to links."
4573 (if (re-search-forward org-plain-link-re limit t)
4575 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4576 (setq f (get-text-property (match-beginning 0) 'face))
4577 (if (or (eq f 'org-tag)
4578 (and (listp f) (memq 'org-tag f)))
4580 (add-text-properties (match-beginning 0) (match-end 0)
4581 (list 'mouse-face 'highlight
4583 'keymap org-mouse-map))
4584 (org-rear-nonsticky-at (match-end 0)))
4587 (defun org-activate-code (limit)
4588 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
4590 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4591 (remove-text-properties (match-beginning 0) (match-end 0)
4592 '(display t invisible t intangible t))
4595 (defun org-fontify-meta-lines-and-blocks (limit)
4596 "Fontify #+ lines and blocks, in the correct ways."
4597 (let ((case-fold-search t))
4598 (if (re-search-forward
4599 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4601 (let ((beg (match-beginning 0))
4602 (beg1 (line-beginning-position 2))
4603 (dc1 (downcase (match-string 2)))
4604 (dc3 (downcase (match-string 3)))
4605 end end1 quoting block-type)
4607 ((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
4608 ;; a single line of backend-specific content
4609 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4610 (remove-text-properties (match-beginning 0) (match-end 0)
4611 '(display t invisible t intangible t))
4612 (add-text-properties (match-beginning 1) (match-end 3)
4613 '(font-lock-fontified t face org-meta-line))
4614 (add-text-properties (match-beginning 6) (match-end 6)
4615 '(font-lock-fontified t face org-block))
4617 ((and (match-end 4) (equal dc3 "begin"))
4619 (setq block-type (downcase (match-string 5))
4620 quoting (member block-type org-protecting-blocks))
4621 (when (re-search-forward
4622 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4623 nil t) ;; on purpose, we look further than LIMIT
4624 (setq end (match-end 0) end1 (1- (match-beginning 0)))
4626 (remove-text-properties beg end
4627 '(display t invisible t intangible t)))
4628 (add-text-properties
4630 '(font-lock-fontified t font-lock-multiline t))
4631 (add-text-properties beg beg1 '(face org-meta-line))
4632 (add-text-properties end1 end '(face org-meta-line))
4635 (add-text-properties beg1 end1 '(face org-block)))
4636 ((string= block-type "quote")
4637 (add-text-properties beg1 end1 '(face org-quote)))
4638 ((string= block-type "verse")
4639 (add-text-properties beg1 end1 '(face org-verse))))
4641 ((not (member (char-after beg) '(?\ ?\t)))
4642 ;; just any other in-buffer setting, but not indented
4643 (add-text-properties
4645 '(font-lock-fontified t face org-meta-line))
4647 ((or (member dc1 '("begin:" "end:" "caption:" "label:"
4648 "orgtbl:" "tblfm:" "tblname:"))
4649 (and (match-end 4) (equal dc3 "attr")))
4650 (add-text-properties
4652 '(font-lock-fontified t face org-meta-line))
4654 ((member dc3 '(" " ""))
4655 (add-text-properties
4657 '(font-lock-fontified t face font-lock-comment-face)))
4660 (defun org-activate-angle-links (limit)
4661 "Run through the buffer and add overlays to links."
4662 (if (re-search-forward org-angle-link-re limit t)
4664 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4665 (add-text-properties (match-beginning 0) (match-end 0)
4666 (list 'mouse-face 'highlight
4667 'keymap org-mouse-map))
4668 (org-rear-nonsticky-at (match-end 0))
4671 (defun org-activate-footnote-links (limit)
4672 "Run through the buffer and add overlays to links."
4673 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
4676 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4677 (add-text-properties (match-beginning 2) (match-end 2)
4678 (list 'mouse-face 'highlight
4679 'keymap org-mouse-map
4681 (if (= (point-at-bol) (match-beginning 2))
4682 "Footnote definition"
4683 "Footnote reference")
4685 (org-rear-nonsticky-at (match-end 2))
4688 (defun org-activate-bracket-links (limit)
4689 "Run through the buffer and add overlays to bracketed links."
4690 (if (re-search-forward org-bracket-link-regexp limit t)
4691 (let* ((help (concat "LINK: "
4692 (org-match-string-no-properties 1)))
4693 ;; FIXME: above we should remove the escapes.
4694 ;; but that requires another match, protecting match data,
4695 ;; a lot of overhead for font-lock.
4696 (ip (org-maybe-intangible
4697 (list 'invisible 'org-link
4698 'keymap org-mouse-map 'mouse-face 'highlight
4699 'font-lock-multiline t 'help-echo help)))
4700 (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
4701 'font-lock-multiline t 'help-echo help)))
4702 ;; We need to remove the invisible property here. Table narrowing
4703 ;; may have made some of this invisible.
4704 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4705 (remove-text-properties (match-beginning 0) (match-end 0)
4709 (add-text-properties (match-beginning 0) (match-beginning 3) ip)
4710 (org-rear-nonsticky-at (match-beginning 3))
4711 (add-text-properties (match-beginning 3) (match-end 3) vp)
4712 (org-rear-nonsticky-at (match-end 3))
4713 (add-text-properties (match-end 3) (match-end 0) ip)
4714 (org-rear-nonsticky-at (match-end 0)))
4715 (add-text-properties (match-beginning 0) (match-beginning 1) ip)
4716 (org-rear-nonsticky-at (match-beginning 1))
4717 (add-text-properties (match-beginning 1) (match-end 1) vp)
4718 (org-rear-nonsticky-at (match-end 1))
4719 (add-text-properties (match-end 1) (match-end 0) ip)
4720 (org-rear-nonsticky-at (match-end 0)))
4723 (defun org-activate-dates (limit)
4724 "Run through the buffer and add overlays to dates."
4725 (if (re-search-forward org-tsr-regexp-both limit t)
4727 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4728 (add-text-properties (match-beginning 0) (match-end 0)
4729 (list 'mouse-face 'highlight
4730 'keymap org-mouse-map))
4731 (org-rear-nonsticky-at (match-end 0))
4732 (when org-display-custom-times
4734 (org-display-custom-time (match-beginning 3) (match-end 3)))
4735 (org-display-custom-time (match-beginning 1) (match-end 1)))
4738 (defvar org-target-link-regexp nil
4739 "Regular expression matching radio targets in plain text.")
4740 (make-variable-buffer-local 'org-target-link-regexp)
4741 (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
4742 "Regular expression matching a link target.")
4743 (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
4744 "Regular expression matching a radio target.")
4745 (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
4746 "Regular expression matching any target.")
4748 (defun org-activate-target-links (limit)
4749 "Run through the buffer and add overlays to target matches."
4750 (when org-target-link-regexp
4751 (let ((case-fold-search t))
4752 (if (re-search-forward org-target-link-regexp limit t)
4754 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4755 (add-text-properties (match-beginning 0) (match-end 0)
4756 (list 'mouse-face 'highlight
4757 'keymap org-mouse-map
4758 'help-echo "Radio target link"
4759 'org-linked-text t))
4760 (org-rear-nonsticky-at (match-end 0))
4763 (defun org-update-radio-target-regexp ()
4764 "Find all radio targets in this file and update the regular expression."
4766 (when (memq 'radio org-activate-links)
4767 (setq org-target-link-regexp
4768 (org-make-target-link-regexp (org-all-targets 'radio)))
4769 (org-restart-font-lock)))
4771 (defun org-hide-wide-columns (limit)
4773 (setq s (text-property-any (point) (or limit (point-max))
4776 (setq e (next-single-property-change s 'org-cwidth))
4777 (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
4781 (defvar org-latex-and-specials-regexp nil
4782 "Regular expression for highlighting export special stuff.")
4783 (defvar org-match-substring-regexp)
4784 (defvar org-match-substring-with-braces-regexp)
4786 ;; This should be with the exporter code, but we also use if for font-locking
4787 (defconst org-export-html-special-string-regexps
4788 '(("\\\\-" . "­")
4789 ("---\\([^-]\\)" . "—\\1")
4790 ("--\\([^-]\\)" . "–\\1")
4791 ("\\.\\.\\." . "…"))
4792 "Regular expressions for special string conversion.")
4795 (defun org-compute-latex-and-specials-regexp ()
4796 "Compute regular expression for stuff treated specially by exporters."
4797 (if (not org-highlight-latex-fragments-and-specials)
4798 (org-set-local 'org-latex-and-specials-regexp nil)
4801 ((matchers (plist-get org-format-latex-options :matchers))
4802 (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
4803 org-latex-regexps)))
4804 (options (org-combine-plists (org-default-export-plist)
4805 (org-infile-export-plist)))
4806 (org-export-with-sub-superscripts (plist-get options :sub-superscript))
4807 (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
4808 (org-export-with-TeX-macros (plist-get options :TeX-macros))
4809 (org-export-html-expand (plist-get options :expand-quoted-html))
4810 (org-export-with-special-strings (plist-get options :special-strings))
4813 ((equal org-export-with-sub-superscripts '{})
4814 (list org-match-substring-with-braces-regexp))
4815 (org-export-with-sub-superscripts
4816 (list org-match-substring-regexp))
4819 (if org-export-with-LaTeX-fragments
4820 (mapcar (lambda (x) (nth 1 x)) latexs)))
4822 (if org-export-with-TeX-macros
4823 (list (concat "\\\\"
4825 (append (mapcar 'car org-html-entities)
4826 (if (boundp 'org-latex-entities)
4828 (or (car-safe x) x))
4833 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
4834 (re-special (if org-export-with-special-strings
4835 (mapcar (lambda (x) (car x))
4836 org-export-html-special-string-regexps)))
4840 (if org-export-html-expand "@<[^>\n]+>")
4843 'org-latex-and-specials-regexp
4844 (mapconcat 'identity (append re-latex re-sub re-macros re-special
4847 (defun org-do-latex-and-special-faces (limit)
4848 "Run through the buffer and add overlays to links."
4849 (when org-latex-and-specials-regexp
4851 (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
4853 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
4855 '(org-code org-verbatim underline)))
4858 d (cond ((member (char-after (1+ (match-beginning 0)))
4861 (font-lock-prepend-text-property
4862 (+ d (match-beginning 0)) (match-end 0)
4863 'face 'org-latex-and-export-specials)
4864 (add-text-properties (+ d (match-beginning 0)) (match-end 0)
4865 '(font-lock-multiline t)))))
4868 (defun org-restart-font-lock ()
4869 "Restart font-lock-mode, to force refontification."
4870 (when (and (boundp 'font-lock-mode) font-lock-mode)
4872 (font-lock-mode 1)))
4874 (defun org-all-targets (&optional radio)
4875 "Return a list of all targets in this file.
4876 With optional argument RADIO, only find radio targets."
4877 (let ((re (if radio org-radio-target-regexp org-target-regexp))
4880 (goto-char (point-min))
4881 (while (re-search-forward re nil t)
4882 (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
4885 (defun org-make-target-link-regexp (targets)
4886 "Make regular expression matching all strings in TARGETS.
4887 The regular expression finds the targets also if there is a line break
4894 (while (string-match " +" x)
4895 (setq x (replace-match "\\s-+" t t x)))
4901 (defun org-activate-tags (limit)
4902 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
4904 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
4905 (add-text-properties (match-beginning 1) (match-end 1)
4906 (list 'mouse-face 'highlight
4907 'keymap org-mouse-map))
4908 (org-rear-nonsticky-at (match-end 1))
4911 (defun org-outline-level ()
4912 "Compute the outline level of the heading at point.
4913 This function assumes that the cursor is at the beginning of a line matched
4914 by outline-regexp. Otherwise it returns garbage.
4915 If this is called at a normal headline, the level is the number of stars.
4916 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
4917 For plain list items, if they are matched by `outline-regexp', this returns
4918 1000 plus the line indentation."
4920 (looking-at outline-regexp)
4921 (if (match-beginning 1)
4922 (+ (org-get-string-indentation (match-string 1)) 1000)
4923 (1- (- (match-end 0) (match-beginning 0))))))
4925 (defvar org-font-lock-keywords nil)
4927 (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
4928 "Regular expression matching a property line.")
4930 (defvar org-font-lock-hook nil
4931 "Functions to be called for special font lock stuff.")
4933 (defun org-font-lock-hook (limit)
4934 (run-hook-with-args 'org-font-lock-hook limit))
4936 (defun org-set-font-lock-defaults ()
4937 (let* ((em org-fontify-emphasized-text)
4938 (lk org-activate-links)
4939 (org-font-lock-extra-keywords
4942 '(org-font-lock-hook)
4944 `(,(if org-fontify-whole-heading-line
4945 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
4946 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
4947 (1 (org-get-level-face 1))
4948 (2 (org-get-level-face 2))
4949 (3 (org-get-level-face 3)))
4951 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
4954 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
4955 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
4956 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
4957 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t))
4959 (list org-drawer-regexp '(0 'org-special-keyword t))
4960 (list "^[ \t]*:END:" '(0 'org-special-keyword t))
4962 (list org-property-re
4963 '(1 'org-special-keyword t)
4964 '(3 'org-property-value t))
4966 (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
4967 (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
4968 (if (memq 'plain lk) '(org-activate-plain-links))
4969 (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
4970 (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
4971 (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
4972 (if (memq 'footnote lk) '(org-activate-footnote-links
4973 (2 'org-footnote t)))
4974 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
4975 '(org-hide-wide-columns (0 nil append))
4977 (list (concat "^\\*+[ \t]+" org-todo-regexp "\\([ \t]\\|$\\)")
4978 '(1 (org-get-todo-face 1) t))
4980 (if org-fontify-done-headline
4981 (list (concat "^[*]+ +\\<\\("
4982 (mapconcat 'regexp-quote org-done-keywords "\\|")
4984 '(2 'org-headline-done t))
4987 '(org-font-lock-add-priority-faces)
4989 '(org-font-lock-add-tag-faces)
4991 (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
4992 (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
4993 (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
4994 (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
4997 (if (featurep 'xemacs)
4998 '(org-do-emphasis-faces (0 nil append))
4999 '(org-do-emphasis-faces)))
5001 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5002 2 'org-checkbox prepend)
5003 (if org-provide-checkbox-statistics
5004 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5005 (0 (org-get-checkbox-statistics-face) t)))
5006 ;; Description list items
5007 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5009 ;; ARCHIVEd headings
5010 (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
5011 '(1 'org-archived prepend))
5013 '(org-do-latex-and-special-faces)
5015 '(org-activate-code (1 'org-code t))
5017 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5018 "\\|" org-quote-string "\\)\\>")
5019 '(1 'org-special-keyword t))
5020 '("^#.*" (0 'font-lock-comment-face t))
5021 ;; Blocks and meta lines
5022 '(org-fontify-meta-lines-and-blocks)
5024 (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
5025 ;; Now set the full font-lock-keywords
5026 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
5027 (org-set-local 'font-lock-defaults
5028 '(org-font-lock-keywords t nil nil backward-paragraph))
5029 (kill-local-variable 'font-lock-keywords) nil))
5031 (defun org-fontify-like-in-org-mode (s &optional odd-levels)
5032 "Fontify string S like in Org-mode"
5035 (let ((org-odd-levels-only odd-levels))
5037 (font-lock-fontify-buffer)
5043 (defun org-get-level-face (n)
5044 "Get the right face for match N in font-lock matching of headlines."
5045 (setq org-l (- (match-end 2) (match-beginning 1) 1))
5046 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
5047 (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
5049 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
5051 (t (if org-level-color-stars-only nil org-f))))
5053 (defun org-get-todo-face (kwd)
5054 "Get the right face for a TODO keyword KWD.
5055 If KWD is a number, get the corresponding match group."
5056 (if (numberp kwd) (setq kwd (match-string kwd)))
5057 (or (cdr (assoc kwd org-todo-keyword-faces))
5058 (and (member kwd org-done-keywords) 'org-done)
5061 (defun org-font-lock-add-tag-faces (limit)
5062 "Add the special tag faces."
5063 (when (and org-tag-faces org-tags-special-faces-re)
5064 (while (re-search-forward org-tags-special-faces-re limit t)
5065 (add-text-properties (match-beginning 1) (match-end 1)
5066 (list 'face (org-get-tag-face 1)
5067 'font-lock-fontified t))
5068 (backward-char 1))))
5070 (defun org-font-lock-add-priority-faces (limit)
5071 "Add the special priority faces."
5072 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t)
5073 (add-text-properties
5074 (match-beginning 0) (match-end 0)
5075 (list 'face (or (cdr (assoc (char-after (match-beginning 1))
5076 org-priority-faces))
5077 'org-special-keyword)
5078 'font-lock-fontified t))))
5080 (defun org-get-tag-face (kwd)
5081 "Get the right face for a TODO keyword KWD.
5082 If KWD is a number, get the corresponding match group."
5083 (if (numberp kwd) (setq kwd (match-string kwd)))
5084 (or (cdr (assoc kwd org-tag-faces))
5087 (defun org-unfontify-region (beg end &optional maybe_loudly)
5088 "Remove fontification and activation overlays from links."
5089 (font-lock-default-unfontify-region beg end)
5090 (let* ((buffer-undo-list t)
5091 (inhibit-read-only t) (inhibit-point-motion-hooks t)
5092 (inhibit-modification-hooks t)
5093 deactivate-mark buffer-file-name buffer-file-truename)
5094 (remove-text-properties
5097 ;; also remove line-prefix and wrap-prefix properties
5098 '(mouse-face t keymap t org-linked-text t
5099 invisible t intangible t
5100 line-prefix t wrap-prefix t
5102 '(mouse-face t keymap t org-linked-text t
5103 invisible t intangible t
5104 org-no-flyspell t)))))
5106 ;;;; Visibility cycling, including org-goto and indirect buffer
5110 (defvar org-cycle-global-status nil)
5111 (make-variable-buffer-local 'org-cycle-global-status)
5112 (defvar org-cycle-subtree-status nil)
5113 (make-variable-buffer-local 'org-cycle-subtree-status)
5117 (defvar org-inlinetask-min-level)
5119 (defun org-cycle (&optional arg)
5120 "TAB-action and visibility cycling for Org-mode.
5122 This is the command invoked in Org-mode by the TAB key. Its main purpose
5123 is outline visibility cycling, but it also invokes other actions
5124 in special contexts.
5126 - When this function is called with a prefix argument, rotate the entire
5127 buffer through 3 states (global cycling)
5128 1. OVERVIEW: Show only top-level headlines.
5129 2. CONTENTS: Show all headlines of all levels, but no body text.
5130 3. SHOW ALL: Show everything.
5131 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5132 determined by the variable `org-startup-folded', and by any VISIBILITY
5133 properties in the buffer.
5134 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5135 including any drawers.
5137 - When inside a table, re-align the table and move to the next field.
5139 - When point is at the beginning of a headline, rotate the subtree started
5140 by this line through 3 different states (local cycling)
5141 1. FOLDED: Only the main headline is shown.
5142 2. CHILDREN: The main headline and the direct children are shown.
5143 From this state, you can move to one of the children
5144 and zoom in further.
5145 3. SUBTREE: Show the entire subtree, including body text.
5146 If there is no subtree, switch directly from CHILDREN to FOLDED.
5148 - When there is a numeric prefix, go up to a heading with level ARG, do
5149 a `show-subtree' and return to the previous cursor position. If ARG
5150 is negative, go up that many levels.
5152 - When point is not at the beginning of a headline, execute the global
5153 binding for TAB, which is re-indenting the line. See the option
5154 `org-cycle-emulate-tab' for details.
5156 - Special case: if point is at the beginning of the buffer and there is
5157 no headline in line 1, this function will act as if called with prefix arg.
5158 But only if also the variable `org-cycle-global-at-bob' is t."
5160 (org-load-modules-maybe)
5161 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook)
5162 (and org-cycle-level-after-item/entry-creation
5163 (or (org-cycle-level)
5164 (org-cycle-item-indentation))))
5166 (or org-cycle-max-level
5167 (and (boundp 'org-inlinetask-min-level)
5168 org-inlinetask-min-level
5169 (1- org-inlinetask-min-level))))
5170 (nstars (and limit-level
5171 (if org-odd-levels-only
5172 (and limit-level (1- (* limit-level 2)))
5176 ((not (org-mode-p)) outline-regexp)
5177 ((or (eq org-cycle-include-plain-lists 'integrate)
5178 (and org-cycle-include-plain-lists (org-at-item-p)))
5180 (if nstars (format "\\{1,%d\\}" nstars) "+")
5181 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5182 (t (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))))
5183 (bob-special (and org-cycle-global-at-bob (bobp)
5184 (not (looking-at outline-regexp))))
5187 (delq 'org-optimize-window-after-visibility-change
5188 (copy-sequence org-cycle-hook))
5192 (if (or bob-special (equal arg '(4)))
5193 ;; special case: use global cycling
5199 (org-set-startup-visibility)
5200 (message "Startup visibility, plus VISIBILITY properties"))
5204 (message "Entire buffer visible, including drawers"))
5206 ((org-at-table-p 'any)
5207 ;; Enter the table or move to the next field in the table
5208 (or (org-table-recognize-table.el)
5210 (if arg (org-table-edit-field t)
5211 (org-table-justify-field-maybe)
5212 (call-interactively 'org-table-next-field)))))
5214 ((run-hook-with-args-until-success
5215 'org-tab-after-check-for-table-hook))
5217 ((eq arg t) ;; Global cycling
5218 (org-cycle-internal-global))
5220 ((and org-drawers org-drawer-regexp
5222 (beginning-of-line 1)
5223 (looking-at org-drawer-regexp)))
5224 ;; Toggle block visibility
5226 (not (get-char-property (match-end 0) 'invisible))))
5229 ;; Show-subtree, ARG levels up from here.
5231 (org-back-to-heading)
5232 (outline-up-heading (if (< arg 0) (- arg)
5233 (- (funcall outline-level) arg)))
5234 (org-show-subtree)))
5236 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
5237 (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
5239 (org-cycle-internal-local))
5241 ;; TAB emulation and template completion
5242 (buffer-read-only (org-back-to-heading))
5244 ((run-hook-with-args-until-success
5245 'org-tab-after-check-for-cycling-hook))
5247 ((org-try-structure-completion))
5249 ((org-try-cdlatex-tab))
5251 ((run-hook-with-args-until-success
5252 'org-tab-before-tab-emulation-hook))
5254 ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
5256 (not (looking-at outline-regexp))))
5257 (call-interactively (global-key-binding "\t")))
5259 ((if (and (memq org-cycle-emulate-tab '(white whitestart))
5260 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5261 (or (and (eq org-cycle-emulate-tab 'white)
5262 (= (match-end 0) (point-at-eol)))
5263 (and (eq org-cycle-emulate-tab 'whitestart)
5264 (>= (match-end 0) pos))))
5266 (eq org-cycle-emulate-tab t))
5267 (call-interactively (global-key-binding "\t")))
5270 (org-back-to-heading)
5273 (defun org-cycle-internal-global ()
5274 "Do the global cycling action."
5276 ((and (eq last-command this-command)
5277 (eq org-cycle-global-status 'overview))
5278 ;; We just created the overview - now do table of contents
5279 ;; This can be slow in very large buffers, so indicate action
5280 (run-hook-with-args 'org-pre-cycle-hook 'contents)
5281 (message "CONTENTS...")
5283 (message "CONTENTS...done")
5284 (setq org-cycle-global-status 'contents)
5285 (run-hook-with-args 'org-cycle-hook 'contents))
5287 ((and (eq last-command this-command)
5288 (eq org-cycle-global-status 'contents))
5289 ;; We just showed the table of contents - now show everything
5290 (run-hook-with-args 'org-pre-cycle-hook 'all)
5292 (message "SHOW ALL")
5293 (setq org-cycle-global-status 'all)
5294 (run-hook-with-args 'org-cycle-hook 'all))
5297 ;; Default action: go to overview
5298 (run-hook-with-args 'org-pre-cycle-hook 'overview)
5300 (message "OVERVIEW")
5301 (setq org-cycle-global-status 'overview)
5302 (run-hook-with-args 'org-cycle-hook 'overview))))
5304 (defun org-cycle-internal-local ()
5305 "Do the local cycling action."
5306 (org-back-to-heading)
5307 (let ((goal-column 0) eoh eol eos level has-children children-skipped)
5308 ;; First, some boundaries
5310 (org-back-to-heading)
5311 (setq level (funcall outline-level))
5313 (beginning-of-line 2)
5314 (if (or (featurep 'xemacs) (<= emacs-major-version 21))
5315 ; XEmacs does not have `next-single-char-property-change'
5316 ; I'm not sure about Emacs 21.
5317 (while (and (not (eobp)) ;; this is like `next-line'
5318 (get-char-property (1- (point)) 'invisible))
5319 (beginning-of-line 2))
5320 (while (and (not (eobp)) ;; this is like `next-line'
5321 (get-char-property (1- (point)) 'invisible))
5322 (goto-char (next-single-char-property-change (point) 'invisible))
5323 ;;;??? (or (bolp) (beginning-of-line 2))))
5324 (and (eolp) (beginning-of-line 2))))
5326 (outline-end-of-heading) (setq eoh (point))
5328 (outline-next-heading)
5329 (setq has-children (and (org-at-heading-p t)
5330 (> (funcall outline-level) level))))
5331 (org-end-of-subtree t)
5333 (skip-chars-forward " \t\n")
5334 (beginning-of-line 1) ; in case this is an item
5336 (setq eos (if (eobp) (point) (1- (point)))))
5337 ;; Find out what to do next and set `this-command'
5340 ;; Nothing is hidden behind this heading
5341 (run-hook-with-args 'org-pre-cycle-hook 'empty)
5342 (message "EMPTY ENTRY")
5343 (setq org-cycle-subtree-status nil)
5346 (outline-next-heading)
5347 (if (org-invisible-p) (org-flag-heading nil))))
5348 ((and (or (>= eol eos)
5349 (not (string-match "\\S-" (buffer-substring eol eos))))
5351 (not (setq children-skipped
5352 org-cycle-skip-children-state-if-no-children))))
5353 ;; Entire subtree is hidden in one line: children view
5354 (run-hook-with-args 'org-pre-cycle-hook 'children)
5357 (message "CHILDREN")
5360 (outline-next-heading)
5361 (if (org-invisible-p) (org-flag-heading nil)))
5362 (setq org-cycle-subtree-status 'children)
5363 (run-hook-with-args 'org-cycle-hook 'children))
5364 ((or children-skipped
5365 (and (eq last-command this-command)
5366 (eq org-cycle-subtree-status 'children)))
5367 ;; We just showed the children, or no children are there,
5368 ;; now show everything.
5369 (run-hook-with-args 'org-pre-cycle-hook 'subtree)
5371 (message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
5372 (setq org-cycle-subtree-status 'subtree)
5373 (run-hook-with-args 'org-cycle-hook 'subtree))
5375 ;; Default action: hide the subtree.
5376 (run-hook-with-args 'org-pre-cycle-hook 'folded)
5379 (setq org-cycle-subtree-status 'folded)
5380 (run-hook-with-args 'org-cycle-hook 'folded)))))
5383 (defun org-global-cycle (&optional arg)
5384 "Cycle the global visibility. For details see `org-cycle'.
5385 With C-u prefix arg, switch to startup visibility.
5386 With a numeric prefix, show all headlines up to that level."
5388 (let ((org-cycle-include-plain-lists
5389 (if (org-mode-p) org-cycle-include-plain-lists nil)))
5393 (hide-sublevels arg)
5394 (setq org-cycle-global-status 'contents))
5396 (org-set-startup-visibility)
5397 (message "Startup visibility, plus VISIBILITY properties."))
5399 (org-cycle '(4))))))
5401 (defun org-set-startup-visibility ()
5402 "Set the visibility required by startup options and properties."
5404 ((eq org-startup-folded t)
5406 ((eq org-startup-folded 'content)
5407 (let ((this-command 'org-cycle) (last-command 'org-cycle))
5408 (org-cycle '(4)) (org-cycle '(4)))))
5409 (unless (eq org-startup-folded 'showeverything)
5410 (if org-hide-block-startup (org-hide-block-all))
5411 (org-set-visibility-according-to-property 'no-cleanup)
5412 (org-cycle-hide-archived-subtrees 'all)
5413 (org-cycle-hide-drawers 'all)
5414 (org-cycle-show-empty-lines 'all)))
5416 (defun org-set-visibility-according-to-property (&optional no-cleanup)
5417 "Switch subtree visibilities according to :VISIBILITY: property."
5419 (let (org-show-entry-below state)
5421 (goto-char (point-min))
5422 (while (re-search-forward
5423 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5425 (setq state (match-string 1))
5427 (org-back-to-heading t)
5431 ((equal state '("fold" "folded"))
5433 ((equal state "children")
5434 (org-show-hidden-entry)
5436 ((equal state "content")
5439 (org-narrow-to-subtree)
5441 ((member state '("all" "showall"))
5444 (org-cycle-hide-archived-subtrees 'all)
5445 (org-cycle-hide-drawers 'all)
5446 (org-cycle-show-empty-lines 'all)))))
5448 (defun org-overview ()
5449 "Switch to overview mode, showing only top-level headlines.
5450 Really, this shows all headlines with level equal or greater than the level
5451 of the first headline in the buffer. This is important, because if the
5452 first headline is not level one, then (hide-sublevels 1) gives confusing
5455 (let ((level (save-excursion
5456 (goto-char (point-min))
5457 (if (re-search-forward (concat "^" outline-regexp) nil t)
5459 (goto-char (match-beginning 0))
5460 (funcall outline-level))))))
5461 (and level (hide-sublevels level))))
5463 (defun org-content (&optional arg)
5464 "Show all headlines in the buffer, like a table of contents.
5465 With numerical argument N, show content up to level N."
5468 ;; Visit all headings and show their offspring
5469 (and (integerp arg) (org-overview))
5470 (goto-char (point-max))
5472 (while (and (progn (condition-case nil
5473 (outline-previous-visible-heading 1)
5474 (error (goto-char (point-min))))
5476 (looking-at outline-regexp))
5478 (show-children (1- arg))
5480 (if (bobp) (throw 'exit nil))))))
5483 (defun org-optimize-window-after-visibility-change (state)
5484 "Adjust the window after a change in outline visibility.
5485 This function is the default value of the hook `org-cycle-hook'."
5486 (when (get-buffer-window (current-buffer))
5488 ((eq state 'content) nil)
5489 ((eq state 'all) nil)
5490 ((eq state 'folded) nil)
5491 ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
5492 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
5494 (defun org-remove-empty-overlays-at (pos)
5495 "Remove outline overlays that do not contain non-white stuff."
5498 (and (eq 'outline (org-overlay-get o 'invisible))
5499 (not (string-match "\\S-" (buffer-substring (org-overlay-start o)
5500 (org-overlay-end o))))
5501 (org-delete-overlay o)))
5502 (org-overlays-at pos)))
5504 (defun org-clean-visibility-after-subtree-move ()
5505 "Fix visibility issues after moving a subtree."
5506 ;; First, find a reasonable region to look at:
5507 ;; Start two siblings above, end three below
5508 (let* ((beg (save-excursion
5509 (and (org-get-last-sibling)
5510 (org-get-last-sibling))
5512 (end (save-excursion
5513 (and (org-get-next-sibling)
5514 (org-get-next-sibling)
5515 (org-get-next-sibling))
5516 (if (org-at-heading-p)
5519 (level (looking-at "\\*+"))
5520 (re (if level (concat "^" (regexp-quote (match-string 0)) " "))))
5523 (narrow-to-region beg end)
5525 ;; Properly fold already folded siblings
5526 (goto-char (point-min))
5527 (while (re-search-forward re nil t)
5528 (if (and (not (org-invisible-p))
5530 (goto-char (point-at-eol)) (org-invisible-p)))
5532 (org-cycle-show-empty-lines 'overview)
5533 (org-cycle-hide-drawers 'overview)))))
5535 (defun org-cycle-show-empty-lines (state)
5536 "Show empty lines above all visible headlines.
5537 The region to be covered depends on STATE when called through
5538 `org-cycle-hook'. Lisp program can use t for STATE to get the
5539 entire buffer covered. Note that an empty line is only shown if there
5540 are at least `org-cycle-separator-lines' empty lines before the headline."
5541 (when (not (= org-cycle-separator-lines 0))
5543 (let* ((n (abs org-cycle-separator-lines))
5545 ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
5546 ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
5547 (t (let ((ns (number-to-string (- n 2))))
5548 (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
5549 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
5552 ((memq state '(overview contents t))
5553 (setq beg (point-min) end (point-max)))
5554 ((memq state '(children folded))
5555 (setq beg (point) end (progn (org-end-of-subtree t t)
5556 (beginning-of-line 2)
5560 (while (re-search-forward re end t)
5561 (unless (get-char-property (match-end 1) 'invisible)
5562 (setq e (match-end 1))
5563 (if (< org-cycle-separator-lines 0)
5564 (setq b (save-excursion
5565 (goto-char (match-beginning 0))
5566 (org-back-over-empty-lines)
5568 (goto-char (max (point-min) (1- (point))))
5572 (setq b (match-beginning 1)))
5573 (outline-flag-region b e nil)))))))
5574 ;; Never hide empty lines at the end of the file.
5576 (goto-char (point-max))
5577 (outline-previous-heading)
5578 (outline-end-of-heading)
5579 (if (and (looking-at "[ \t\n]+")
5580 (= (match-end 0) (point-max)))
5581 (outline-flag-region (point) (match-end 0) nil))))
5583 (defun org-show-empty-lines-in-parent ()
5584 "Move to the parent and re-show empty lines before visible headlines."
5586 (let ((context (if (org-up-heading-safe) 'children 'overview)))
5587 (org-cycle-show-empty-lines context))))
5589 (defun org-files-list ()
5590 "Return `org-agenda-files' list, plus all open org-mode files.
5591 This is useful for operations that need to scan all of a user's
5592 open and agenda-wise Org files."
5593 (let ((files (mapcar 'expand-file-name (org-agenda-files))))
5594 (dolist (buf (buffer-list))
5595 (with-current-buffer buf
5596 (if (and (eq major-mode 'org-mode) (buffer-file-name))
5597 (let ((file (expand-file-name (buffer-file-name))))
5598 (unless (member file files)
5599 (push file files))))))
5602 (defsubst org-entry-beginning-position ()
5603 "Return the beginning position of the current entry."
5604 (save-excursion (outline-back-to-heading t) (point)))
5606 (defsubst org-entry-end-position ()
5607 "Return the end position of the current entry."
5608 (save-excursion (outline-next-heading) (point)))
5610 (defun org-cycle-hide-drawers (state)
5611 "Re-hide all drawers after a visibility state change."
5612 (when (and (org-mode-p)
5613 (not (memq state '(overview folded contents))))
5615 (let* ((globalp (memq state '(contents all)))
5616 (beg (if globalp (point-min) (point)))
5617 (end (if globalp (point-max)
5618 (if (eq state 'children)
5619 (save-excursion (outline-next-heading) (point))
5620 (org-end-of-subtree t)))))
5622 (while (re-search-forward org-drawer-regexp end t)
5623 (org-flag-drawer t))))))
5625 (defun org-flag-drawer (flag)
5627 (beginning-of-line 1)
5628 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
5629 (let ((b (match-end 0))
5630 (outline-regexp org-outline-regexp))
5631 (if (re-search-forward
5633 (save-excursion (outline-next-heading) (point)) t)
5634 (outline-flag-region b (point-at-eol) flag)
5635 (error ":END: line missing at position %s" b))))))
5637 (defun org-subtree-end-visible-p ()
5638 "Is the end of the current subtree visible?"
5639 (pos-visible-in-window-p
5640 (save-excursion (org-end-of-subtree t) (point))))
5642 (defun org-first-headline-recenter (&optional N)
5643 "Move cursor to the first headline and recenter the headline.
5644 Optional argument N means, put the headline into the Nth line of the window."
5645 (goto-char (point-min))
5646 (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
5648 (recenter (prefix-numeric-value N))))
5650 ;;; Saving and restoring visibility
5652 (defun org-outline-overlay-data (&optional use-markers)
5653 "Return a list of the locations of all outline overlays.
5654 The are overlays with the `invisible' property value `outline'.
5655 The return valus is a list of cons cells, with start and stop
5656 positions for each overlay.
5657 If USE-MARKERS is set, return the positions as markers."
5664 (when (eq (org-overlay-get o 'invisible) 'outline)
5665 (setq beg (org-overlay-start o)
5666 end (org-overlay-end o))
5667 (and beg end (> end beg)
5669 (cons (move-marker (make-marker) beg)
5670 (move-marker (make-marker) end))
5672 (org-overlays-in (point-min) (point-max))))))))
5674 (defun org-set-outline-overlay-data (data)
5675 "Create visibility overlays for all positions in DATA.
5676 DATA should have been made by `org-outline-overlay-data'."
5683 (setq o (org-make-overlay (car c) (cdr c)))
5684 (org-overlay-put o 'invisible 'outline))
5687 (defmacro org-save-outline-visibility (use-markers &rest body)
5688 "Save and restore outline visibility around BODY.
5689 If USE-MARKERS is non-nil, use markers for the positions.
5690 This means that the buffer may change while running BODY,
5691 but it also means that the buffer should stay alive
5692 during the operation, because otherwise all these markers will
5694 `(let ((data (org-outline-overlay-data ,use-markers)))
5698 (org-set-outline-overlay-data data))
5701 (and (markerp (car c)) (move-marker (car c) nil))
5702 (and (markerp (cdr c)) (move-marker (cdr c) nil)))
5706 ;;; Folding of blocks
5708 (defconst org-block-regexp
5710 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
5711 "Regular expression for hiding blocks.")
5713 (defvar org-hide-block-overlays nil
5714 "Overlays hiding blocks.")
5715 (make-variable-buffer-local 'org-hide-block-overlays)
5717 (defun org-block-map (function &optional start end)
5718 "Call func at the head of all source blocks in the current
5719 buffer. Optional arguments START and END can be used to limit
5721 (let ((start (or start (point-min)))
5722 (end (or end (point-max))))
5725 (while (and (< (point) end) (re-search-forward org-block-regexp end t))
5728 (goto-char (match-beginning 0))
5729 (funcall function)))))))
5731 (defun org-hide-block-toggle-all ()
5732 "Toggle the visibility of all blocks in the current buffer."
5733 (org-block-map #'org-hide-block-toggle))
5735 (defun org-hide-block-all ()
5736 "Fold all blocks in the current buffer."
5738 (org-show-block-all)
5739 (org-block-map #'org-hide-block-toggle-maybe))
5741 (defun org-show-block-all ()
5742 "Unfold all blocks in the current buffer."
5743 (mapc 'org-delete-overlay org-hide-block-overlays)
5744 (setq org-hide-block-overlays nil))
5746 (defun org-hide-block-toggle-maybe ()
5747 "Toggle visibility of block at point."
5749 (let ((case-fold-search t))
5751 (beginning-of-line 1)
5752 (looking-at org-block-regexp))
5753 (progn (org-hide-block-toggle)
5754 t) ;; to signal that we took action
5755 nil))) ;; to signal that we did not
5757 (defun org-hide-block-toggle (&optional force)
5758 "Toggle the visibility of the current block."
5762 (if (re-search-forward org-block-regexp nil t)
5763 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
5764 (end (match-end 0)) ;; end of entire body
5766 (if (memq t (mapcar (lambda (overlay)
5767 (eq (org-overlay-get overlay 'invisible)
5769 (org-overlays-at start)))
5770 (if (or (not force) (eq force 'off))
5772 (when (member ov org-hide-block-overlays)
5773 (setq org-hide-block-overlays
5774 (delq ov org-hide-block-overlays)))
5775 (when (eq (org-overlay-get ov 'invisible)
5777 (org-delete-overlay ov)))
5778 (org-overlays-at start)))
5779 (setq ov (org-make-overlay start end))
5780 (org-overlay-put ov 'invisible 'org-hide-block)
5781 ;; make the block accessible to isearch
5783 ov 'isearch-open-invisible
5785 (when (member ov org-hide-block-overlays)
5786 (setq org-hide-block-overlays
5787 (delq ov org-hide-block-overlays)))
5788 (when (eq (org-overlay-get ov 'invisible)
5790 (org-delete-overlay ov))))
5791 (push ov org-hide-block-overlays)))
5792 (error "Not looking at a source block"))))
5794 ;; org-tab-after-check-for-cycling-hook
5795 (add-hook 'org-tab-first-hook 'org-hide-block-toggle-maybe)
5796 ;; Remove overlays when changing major mode
5797 (add-hook 'org-mode-hook
5798 (lambda () (org-add-hook 'change-major-mode-hook
5799 'org-show-block-all 'append 'local)))
5803 (defvar org-goto-window-configuration nil)
5804 (defvar org-goto-marker nil)
5805 (defvar org-goto-map
5806 (let ((map (make-sparse-keymap)))
5807 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
5808 (while (setq cmd (pop cmds))
5809 (substitute-key-definition cmd cmd map global-map)))
5810 (suppress-keymap map)
5811 (org-defkey map "\C-m" 'org-goto-ret)
5812 (org-defkey map [(return)] 'org-goto-ret)
5813 (org-defkey map [(left)] 'org-goto-left)
5814 (org-defkey map [(right)] 'org-goto-right)
5815 (org-defkey map [(control ?g)] 'org-goto-quit)
5816 (org-defkey map "\C-i" 'org-cycle)
5817 (org-defkey map [(tab)] 'org-cycle)
5818 (org-defkey map [(down)] 'outline-next-visible-heading)
5819 (org-defkey map [(up)] 'outline-previous-visible-heading)
5820 (if org-goto-auto-isearch
5821 (if (fboundp 'define-key-after)
5822 (define-key-after map [t] 'org-goto-local-auto-isearch)
5824 (org-defkey map "q" 'org-goto-quit)
5825 (org-defkey map "n" 'outline-next-visible-heading)
5826 (org-defkey map "p" 'outline-previous-visible-heading)
5827 (org-defkey map "f" 'outline-forward-same-level)
5828 (org-defkey map "b" 'outline-backward-same-level)
5829 (org-defkey map "u" 'outline-up-heading))
5830 (org-defkey map "/" 'org-occur)
5831 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
5832 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
5833 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
5834 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
5835 (org-defkey map "\C-c\C-u" 'outline-up-heading)
5838 (defconst org-goto-help
5839 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
5840 RET=jump to location [Q]uit and return to previous location
5841 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
5843 (defvar org-goto-start-pos) ; dynamically scoped parameter
5845 ;; FIXME: Docstring does not mention both interfaces
5846 (defun org-goto (&optional alternative-interface)
5847 "Look up a different location in the current file, keeping current visibility.
5849 When you want look-up or go to a different location in a document, the
5850 fastest way is often to fold the entire buffer and then dive into the tree.
5851 This method has the disadvantage, that the previous location will be folded,
5852 which may not be what you want.
5854 This command works around this by showing a copy of the current buffer
5855 in an indirect buffer, in overview mode. You can dive into the tree in
5856 that copy, use org-occur and incremental search to find a location.
5857 When pressing RET or `Q', the command returns to the original buffer in
5858 which the visibility is still unchanged. After RET is will also jump to
5859 the location selected in the indirect buffer and expose the
5860 the headline hierarchy above."
5862 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
5863 (org-refile-use-outline-path t)
5864 (org-refile-target-verify-function nil)
5866 (if (not alternative-interface)
5868 (if (eq org-goto-interface 'outline)
5869 'outline-path-completion
5871 (org-goto-start-pos (point))
5873 (if (eq interface 'outline)
5874 (car (org-get-location (current-buffer) org-goto-help))
5875 (nth 3 (org-refile-get-location "Goto: ")))))
5878 (org-mark-ring-push org-goto-start-pos)
5879 (goto-char selected-point)
5880 (if (or (org-invisible-p) (org-invisible-p2))
5881 (org-show-context 'org-goto)))
5884 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
5885 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
5886 (defvar org-goto-local-auto-isearch-map) ; defined below
5888 (defun org-get-location (buf help)
5889 "Let the user select a location in the Org-mode buffer BUF.
5890 This function uses a recursive edit. It returns the selected position
5892 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
5893 (isearch-hide-immediately nil)
5894 (isearch-search-fun-function
5895 (lambda () 'org-goto-local-search-headings))
5896 (org-goto-selected-point org-goto-exit-command))
5898 (save-window-excursion
5899 (delete-other-windows)
5900 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
5903 (make-indirect-buffer (current-buffer) "*org-goto*")
5904 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
5905 (with-output-to-temp-buffer "*Help*"
5907 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
5908 (setq buffer-read-only nil)
5909 (let ((org-startup-truncated t)
5910 (org-startup-folded nil)
5911 (org-startup-align-all-tables nil))
5914 (setq buffer-read-only t)
5915 (if (and (boundp 'org-goto-start-pos)
5916 (integer-or-marker-p org-goto-start-pos))
5917 (let ((org-show-hierarchy-above t)
5918 (org-show-siblings t)
5919 (org-show-following-heading t))
5920 (goto-char org-goto-start-pos)
5921 (and (org-invisible-p) (org-show-context)))
5922 (goto-char (point-min)))
5923 (let (org-special-ctrl-a/e) (org-beginning-of-line))
5924 (message "Select location and press RET")
5925 (use-local-map org-goto-map)
5928 (kill-buffer "*org-goto*")
5929 (cons org-goto-selected-point org-goto-exit-command)))
5931 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
5932 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
5933 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
5934 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
5936 (defun org-goto-local-search-headings (string bound noerror)
5937 "Search and make sure that any matches are in headlines."
5939 (while (if isearch-forward
5940 (search-forward string bound noerror)
5941 (search-backward string bound noerror))
5942 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
5943 (and (member :headline context)
5944 (not (member :tags context))))
5945 (throw 'return (point))))))
5947 (defun org-goto-local-auto-isearch ()
5950 (goto-char (point-min))
5951 (let ((keys (this-command-keys)))
5952 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
5954 (isearch-process-search-char (string-to-char keys)))))
5956 (defun org-goto-ret (&optional arg)
5957 "Finish `org-goto' by going to the new location."
5959 (setq org-goto-selected-point (point)
5960 org-goto-exit-command 'return)
5963 (defun org-goto-left ()
5964 "Finish `org-goto' by going to the new location."
5966 (if (org-on-heading-p)
5968 (beginning-of-line 1)
5969 (setq org-goto-selected-point (point)
5970 org-goto-exit-command 'left)
5972 (error "Not on a heading")))
5974 (defun org-goto-right ()
5975 "Finish `org-goto' by going to the new location."
5977 (if (org-on-heading-p)
5979 (setq org-goto-selected-point (point)
5980 org-goto-exit-command 'right)
5982 (error "Not on a heading")))
5984 (defun org-goto-quit ()
5985 "Finish `org-goto' without cursor motion."
5987 (setq org-goto-selected-point nil)
5988 (setq org-goto-exit-command 'quit)
5991 ;;; Indirect buffer display of subtrees
5993 (defvar org-indirect-dedicated-frame nil
5994 "This is the frame being used for indirect tree display.")
5995 (defvar org-last-indirect-buffer nil)
5997 (defun org-tree-to-indirect-buffer (&optional arg)
5998 "Create indirect buffer and narrow it to current subtree.
5999 With numerical prefix ARG, go up to this level and then take that tree.
6000 If ARG is negative, go up that many levels.
6001 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6002 indirect buffer previously made with this command, to avoid proliferation of
6003 indirect buffers. However, when you call the command with a `C-u' prefix, or
6004 when `org-indirect-buffer-display' is `new-frame', the last buffer
6005 is kept so that you can work with several indirect buffers at the same time.
6006 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6007 requests that a new frame be made for the new buffer, so that the dedicated
6008 frame is not changed."
6010 (let ((cbuf (current-buffer))
6011 (cwin (selected-window))
6013 beg end level heading ibuf)
6015 (org-back-to-heading t)
6017 (setq level (org-outline-level))
6018 (if (< arg 0) (setq arg (+ level arg)))
6019 (while (> (setq level (org-outline-level)) arg)
6020 (outline-up-heading 1 t)))
6022 heading (org-get-heading))
6023 (org-end-of-subtree t t) (setq end (point)))
6024 (if (and (buffer-live-p org-last-indirect-buffer)
6025 (not (eq org-indirect-buffer-display 'new-frame))
6027 (kill-buffer org-last-indirect-buffer))
6028 (setq ibuf (org-get-indirect-buffer cbuf)
6029 org-last-indirect-buffer ibuf)
6031 ((or (eq org-indirect-buffer-display 'new-frame)
6032 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6033 (select-frame (make-frame))
6034 (delete-other-windows)
6035 (switch-to-buffer ibuf)
6036 (org-set-frame-title heading))
6037 ((eq org-indirect-buffer-display 'dedicated-frame)
6039 (select-frame (or (and org-indirect-dedicated-frame
6040 (frame-live-p org-indirect-dedicated-frame)
6041 org-indirect-dedicated-frame)
6042 (setq org-indirect-dedicated-frame (make-frame)))))
6043 (delete-other-windows)
6044 (switch-to-buffer ibuf)
6045 (org-set-frame-title (concat "Indirect: " heading)))
6046 ((eq org-indirect-buffer-display 'current-window)
6047 (switch-to-buffer ibuf))
6048 ((eq org-indirect-buffer-display 'other-window)
6049 (pop-to-buffer ibuf))
6050 (t (error "Invalid value")))
6051 (if (featurep 'xemacs)
6052 (save-excursion (org-mode) (turn-on-font-lock)))
6053 (narrow-to-region beg end)
6056 (and (window-live-p cwin) (select-window cwin))))
6058 (defun org-get-indirect-buffer (&optional buffer)
6059 (setq buffer (or buffer (current-buffer)))
6060 (let ((n 1) (base (buffer-name buffer)) bname)
6061 (while (buffer-live-p
6062 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6065 (make-indirect-buffer buffer bname 'clone)
6066 (error (make-indirect-buffer buffer bname)))))
6068 (defun org-set-frame-title (title)
6069 "Set the title of the current frame to the string TITLE."
6070 ;; FIXME: how to name a single frame in XEmacs???
6071 (unless (featurep 'xemacs)
6072 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6074 ;;;; Structure editing
6076 ;;; Inserting headlines
6078 (defun org-previous-line-empty-p ()
6081 (or (beginning-of-line 0) t)
6083 (looking-at "[ \t]*$")))))
6085 (defun org-insert-heading (&optional force-heading)
6086 "Insert a new heading or item with same depth at point.
6087 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6088 If point is at the beginning of a headline, insert a sibling before the
6089 current headline. If point is not at the beginning, do not split the line,
6090 but create the new headline after the current line."
6092 (if (or (= (buffer-size) 0)
6093 (and (not (save-excursion (and (ignore-errors (org-back-to-heading))
6094 (org-on-heading-p))))
6095 (not (org-in-item-p))))
6097 (when (or force-heading (not (org-insert-item)))
6098 (let* ((empty-line-p nil)
6099 (head (save-excursion
6102 (org-back-to-heading)
6103 (setq empty-line-p (org-previous-line-empty-p))
6106 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6107 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6108 pos hide-previous previous-pos)
6110 ((and (org-on-heading-p) (bolp)
6112 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6113 ;; insert before the current line
6114 (open-line (if blank 2 1)))
6116 (not org-insert-heading-respect-content)
6119 (backward-char 1) (not (org-invisible-p)))))
6120 ;; insert right here
6123 ;; somewhere in the line
6125 (setq previous-pos (point-at-bol))
6127 (setq hide-previous (org-invisible-p)))
6128 (and org-insert-heading-respect-content (org-show-subtree))
6130 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6133 (goto-char (point-at-bol))
6134 (and (looking-at org-complex-heading-regexp)
6135 (> p (match-beginning 4)))))))
6138 (org-insert-heading-respect-content
6139 (org-end-of-subtree nil t)
6140 (or (bolp) (newline))
6141 (or (org-previous-line-empty-p)
6142 (and blank (newline)))
6148 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6149 (setq tags (and (match-end 2) (match-string 2)))
6151 (delete-region (match-beginning 1) (match-end 1)))
6152 (setq pos (point-at-bol))
6153 (or split (end-of-line 1))
6154 (delete-horizontal-space)
6155 (newline (if blank 2 1))
6161 (org-set-tags nil 'align))))
6163 (or split (end-of-line 1))
6164 (newline (if blank 2 1)))))))
6165 (insert head) (just-one-space)
6168 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6169 (when (and org-insert-heading-respect-content hide-previous)
6171 (goto-char previous-pos)
6173 (run-hooks 'org-insert-heading-hook)))))
6175 (defun org-get-heading (&optional no-tags)
6176 "Return the heading of the current entry, without the stars."
6178 (org-back-to-heading t)
6181 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6182 "\\*+[ \t]+\\([^\r\n]*\\)"))
6183 (match-string 1) "")))
6185 (defun org-heading-components ()
6186 "Return the components of the current heading.
6187 This is a list with the following elements:
6188 - the level as an integer
6189 - the reduced level, different if `org-odd-levels-only' is set.
6190 - the TODO keyword, or nil
6191 - the priority character, like ?A, or nil if no priority is given
6192 - the headline text itself, or the tags string if no headline text
6193 - the tags string, or nil."
6195 (org-back-to-heading t)
6196 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6197 (list (length (match-string 1))
6198 (org-reduced-level (length (match-string 1)))
6199 (org-match-string-no-properties 2)
6200 (and (match-end 3) (aref (match-string 3) 2))
6201 (org-match-string-no-properties 4)
6202 (org-match-string-no-properties 5)))))
6204 (defun org-get-entry ()
6205 "Get the entry text, after heading, entire subtree."
6207 (org-back-to-heading t)
6208 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6210 (defun org-insert-heading-after-current ()
6211 "Insert a new heading with same level as current, after current subtree."
6213 (org-back-to-heading)
6214 (org-insert-heading)
6215 (org-move-subtree-down)
6218 (defun org-insert-heading-respect-content ()
6220 (let ((org-insert-heading-respect-content t))
6221 (org-insert-heading t)))
6223 (defun org-insert-todo-heading-respect-content (&optional force-state)
6225 (let ((org-insert-heading-respect-content t))
6226 (org-insert-todo-heading force-state t)))
6228 (defun org-insert-todo-heading (arg &optional force-heading)
6229 "Insert a new heading with the same level and TODO state as current heading.
6230 If the heading has no TODO state, or if the state is DONE, use the first
6231 state (TODO by default). Also with prefix arg, force first state."
6233 (when (or force-heading (not (org-insert-item 'checkbox)))
6234 (org-insert-heading force-heading)
6236 (org-back-to-heading)
6237 (outline-previous-heading)
6238 (looking-at org-todo-line-regexp))
6242 (not (match-beginning 2))
6243 (member (match-string 2) org-done-keywords))
6244 (car org-todo-keywords-1)
6248 (run-hook-with-args-until-success
6249 'org-todo-get-default-hook new-mark-x nil)
6251 (beginning-of-line 1)
6252 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6253 (if org-treat-insert-todo-heading-as-state-change
6255 (insert new-mark " "))))
6256 (when org-provide-todo-statistics
6257 (org-update-parent-todo-statistics))))
6259 (defun org-insert-subheading (arg)
6260 "Insert a new subheading and demote it.
6261 Works for outline headings and for plain lists alike."
6263 (org-insert-heading arg)
6265 ((org-on-heading-p) (org-do-demote))
6266 ((org-at-item-p) (org-indent-item 1))))
6268 (defun org-insert-todo-subheading (arg)
6269 "Insert a new subheading with TODO keyword or checkbox and demote it.
6270 Works for outline headings and for plain lists alike."
6272 (org-insert-todo-heading arg)
6274 ((org-on-heading-p) (org-do-demote))
6275 ((org-at-item-p) (org-indent-item 1))))
6277 ;;; Promotion and Demotion
6279 (defvar org-after-demote-entry-hook nil
6280 "Hook run after an entry has been demoted.
6281 The cursor will be at the beginning of the entry.
6282 When a subtree is being demoted, the hook will be called for each node.")
6284 (defvar org-after-promote-entry-hook nil
6285 "Hook run after an entry has been promoted.
6286 The cursor will be at the beginning of the entry.
6287 When a subtree is being promoted, the hook will be called for each node.")
6289 (defun org-promote-subtree ()
6290 "Promote the entire subtree.
6291 See also `org-promote'."
6294 (org-map-tree 'org-promote))
6295 (org-fix-position-after-promote))
6297 (defun org-demote-subtree ()
6298 "Demote the entire subtree. See `org-demote'.
6299 See also `org-promote'."
6302 (org-map-tree 'org-demote))
6303 (org-fix-position-after-promote))
6306 (defun org-do-promote ()
6307 "Promote the current heading higher up the tree.
6308 If the region is active in `transient-mark-mode', promote all headings
6312 (if (org-region-active-p)
6313 (org-map-region 'org-promote (region-beginning) (region-end))
6315 (org-fix-position-after-promote))
6317 (defun org-do-demote ()
6318 "Demote the current heading lower down the tree.
6319 If the region is active in `transient-mark-mode', demote all headings
6323 (if (org-region-active-p)
6324 (org-map-region 'org-demote (region-beginning) (region-end))
6326 (org-fix-position-after-promote))
6328 (defun org-fix-position-after-promote ()
6329 "Make sure that after pro/demotion cursor position is right."
6330 (let ((pos (point)))
6331 (when (save-excursion
6332 (beginning-of-line 1)
6333 (looking-at org-todo-line-regexp)
6334 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6335 (cond ((eobp) (insert " "))
6336 ((eolp) (insert " "))
6337 ((equal (char-after) ?\ ) (forward-char 1))))))
6339 (defun org-current-level ()
6340 "Return the level of the current entry, or nil if before the first headline.
6341 The level is the number of stars at the beginning of the headline."
6345 (org-back-to-heading t)
6346 (funcall outline-level))
6349 (defun org-reduced-level (l)
6350 "Compute the effective level of a heading.
6351 This takes into account the setting of `org-odd-levels-only'."
6352 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6354 (defun org-get-valid-level (level &optional change)
6355 "Rectify a level change under the influence of `org-odd-levels-only'
6356 LEVEL is a current level, CHANGE is by how much the level should be
6357 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6358 even level numbers will become the next higher odd number."
6359 (if org-odd-levels-only
6360 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6361 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6362 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6363 (max 1 (+ level (or change 0)))))
6365 (if (boundp 'define-obsolete-function-alias)
6366 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6367 (define-obsolete-function-alias 'org-get-legal-level
6368 'org-get-valid-level)
6369 (define-obsolete-function-alias 'org-get-legal-level
6370 'org-get-valid-level "23.1")))
6372 (defun org-promote ()
6373 "Promote the current heading higher up the tree.
6374 If the region is active in `transient-mark-mode', promote all headings
6376 (org-back-to-heading t)
6377 (let* ((level (save-match-data (funcall outline-level)))
6378 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6379 (diff (abs (- level (length up-head) -1))))
6380 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6381 (replace-match up-head nil t)
6382 ;; Fixup tag positioning
6383 (and org-auto-align-tags (org-set-tags nil t))
6384 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6385 (run-hooks 'org-after-promote-entry-hook)))
6387 (defun org-demote ()
6388 "Demote the current heading lower down the tree.
6389 If the region is active in `transient-mark-mode', demote all headings
6391 (org-back-to-heading t)
6392 (let* ((level (save-match-data (funcall outline-level)))
6393 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6394 (diff (abs (- level (length down-head) -1))))
6395 (replace-match down-head nil t)
6396 ;; Fixup tag positioning
6397 (and org-auto-align-tags (org-set-tags nil t))
6398 (if org-adapt-indentation (org-fixup-indentation diff))
6399 (run-hooks 'org-after-demote-entry-hook)))
6401 (defvar org-tab-ind-state nil)
6403 (defun org-cycle-level ()
6404 (let ((org-adapt-indentation nil))
6405 (when (and (looking-at "[ \t]*$")
6407 (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp "\\)?[ \t]*")))
6408 (setq this-command 'org-cycle-level)
6409 (if (eq last-command 'org-cycle-level)
6411 (progn (org-do-promote)
6412 (if (equal org-tab-ind-state (org-current-level))
6417 (beginning-of-line 1)
6418 (and (looking-at "\\*+")
6420 (make-string org-tab-ind-state ?*))))
6421 (setq this-command 'org-cycle))))
6422 (setq org-tab-ind-state (- (match-end 1) (match-beginning 1)))
6426 (defun org-map-tree (fun)
6427 "Call FUN for every heading underneath the current one."
6428 (org-back-to-heading)
6429 (let ((level (funcall outline-level)))
6433 (outline-next-heading)
6434 (> (funcall outline-level) level))
6438 (defun org-map-region (fun beg end)
6439 "Call FUN for every heading between BEG and END."
6440 (let ((org-ignore-region t))
6442 (setq end (copy-marker end))
6444 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6448 (outline-next-heading)
6453 (defun org-fixup-indentation (diff)
6454 "Change the indentation in the current entry by DIFF
6455 However, if any line in the current entry has no indentation, or if it
6456 would end up with no indentation after the change, nothing at all is done."
6458 (let ((end (save-excursion (outline-next-heading)
6460 (prohibit (if (> diff 0)
6462 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6464 (unless (save-excursion (end-of-line 1)
6465 (re-search-forward prohibit end t))
6466 (while (and (< (point) end)
6467 (re-search-forward "^[ \t]+" end t))
6468 (goto-char (match-end 0))
6469 (setq col (current-column))
6470 (if (< diff 0) (replace-match ""))
6471 (org-indent-to-column (+ diff col))))
6472 (move-marker end nil))))
6474 (defun org-convert-to-odd-levels ()
6475 "Convert an org-mode file with all levels allowed to one with odd levels.
6476 This will leave level 1 alone, convert level 2 to level 3, level 3 to
6479 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
6480 (let ((outline-regexp org-outline-regexp)
6481 (outline-level 'org-outline-level)
6482 (org-odd-levels-only nil) n)
6484 (goto-char (point-min))
6485 (while (re-search-forward "^\\*\\*+ " nil t)
6486 (setq n (- (length (match-string 0)) 2))
6487 (while (>= (setq n (1- n)) 0)
6489 (end-of-line 1))))))
6491 (defun org-convert-to-oddeven-levels ()
6492 "Convert an org-mode file with only odd levels to one with odd and even levels.
6493 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
6494 section with an even level, conversion would destroy the structure of the file. An error
6495 is signaled in this case."
6497 (goto-char (point-min))
6498 ;; First check if there are no even levels
6499 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
6500 (org-show-context t)
6501 (error "Not all levels are odd in this file. Conversion not possible"))
6502 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
6503 (let ((outline-regexp org-outline-regexp)
6504 (outline-level 'org-outline-level)
6505 (org-odd-levels-only nil) n)
6507 (goto-char (point-min))
6508 (while (re-search-forward "^\\*\\*+ " nil t)
6509 (setq n (/ (1- (length (match-string 0))) 2))
6510 (while (>= (setq n (1- n)) 0)
6512 (end-of-line 1))))))
6514 (defun org-tr-level (n)
6515 "Make N odd if required."
6516 (if org-odd-levels-only (1+ (/ n 2)) n))
6518 ;;; Vertical tree motion, cutting and pasting of subtrees
6520 (defun org-move-subtree-up (&optional arg)
6521 "Move the current subtree up past ARG headlines of the same level."
6523 (org-move-subtree-down (- (prefix-numeric-value arg))))
6525 (defun org-move-subtree-down (&optional arg)
6526 "Move the current subtree down past ARG headlines of the same level."
6528 (setq arg (prefix-numeric-value arg))
6529 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
6530 'org-get-last-sibling))
6531 (ins-point (make-marker))
6533 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
6535 (org-back-to-heading)
6538 (setq ne-beg (org-back-over-empty-lines))
6541 (save-excursion (outline-end-of-heading)
6542 (setq folded (org-invisible-p)))
6543 (outline-end-of-subtree))
6544 (outline-next-heading)
6545 (setq ne-end (org-back-over-empty-lines))
6548 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
6549 ;; include less whitespace
6552 (forward-line (- ne-beg ne-end))
6553 (setq beg (point))))
6554 ;; Find insertion point, with error handling
6556 (or (and (funcall movfunc) (looking-at outline-regexp))
6557 (progn (goto-char beg0)
6558 (error "Cannot move past superior level or buffer limit")))
6559 (setq cnt (1- cnt)))
6561 ;; Moving forward - still need to move over subtree
6562 (progn (org-end-of-subtree t t)
6564 (org-back-over-empty-lines)
6565 (or (bolp) (newline)))))
6566 (setq ne-ins (org-back-over-empty-lines))
6567 (move-marker ins-point (point))
6568 (setq txt (buffer-substring beg end))
6569 (org-save-markers-in-region beg end)
6570 (delete-region beg end)
6571 (org-remove-empty-overlays-at beg)
6572 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
6573 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
6574 (and (not (bolp)) (looking-at "\n") (forward-char 1))
6575 (let ((bbb (point)))
6576 (insert-before-markers txt)
6577 (org-reinstall-markers-in-region bbb)
6578 (move-marker ins-point bbb))
6579 (or (bolp) (insert "\n"))
6580 (setq ins-end (point))
6581 (goto-char ins-point)
6582 (org-skip-whitespace)
6583 (when (and (< arg 0)
6584 (org-first-sibling-p)
6586 ;; Move whitespace back to beginning
6589 (let ((kill-whole-line t))
6590 (kill-line (- ne-ins ne-beg)) (point)))
6591 (insert (make-string (- ne-ins ne-beg) ?\n)))
6592 (move-marker ins-point nil)
6597 (org-cycle-hide-drawers 'children))
6598 (org-clean-visibility-after-subtree-move)))
6600 (defvar org-subtree-clip ""
6601 "Clipboard for cut and paste of subtrees.
6602 This is actually only a copy of the kill, because we use the normal kill
6603 ring. We need it to check if the kill was created by `org-copy-subtree'.")
6605 (defvar org-subtree-clip-folded nil
6606 "Was the last copied subtree folded?
6607 This is used to fold the tree back after pasting.")
6609 (defun org-cut-subtree (&optional n)
6610 "Cut the current subtree into the clipboard.
6611 With prefix arg N, cut this many sequential subtrees.
6612 This is a short-hand for marking the subtree and then cutting it."
6614 (org-copy-subtree n 'cut))
6616 (defun org-copy-subtree (&optional n cut force-store-markers)
6617 "Cut the current subtree into the clipboard.
6618 With prefix arg N, cut this many sequential subtrees.
6619 This is a short-hand for marking the subtree and then copying it.
6620 If CUT is non-nil, actually cut the subtree.
6621 If FORCE-STORE-MARKERS is non-nil, store the relative locations
6622 of some markers in the region, even if CUT is non-nil. This is
6623 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
6625 (let (beg end folded (beg0 (point)))
6627 (org-back-to-heading nil) ; take what looks like a subtree
6628 (org-back-to-heading t)) ; take what is really there
6629 (org-back-over-empty-lines)
6631 (skip-chars-forward " \t\r\n")
6633 (save-excursion (outline-end-of-heading)
6634 (setq folded (org-invisible-p)))
6636 (org-forward-same-level (1- n) t)
6638 (org-end-of-subtree t t))
6639 (org-back-over-empty-lines)
6643 (setq org-subtree-clip-folded folded)
6644 (when (or cut force-store-markers)
6645 (org-save-markers-in-region beg end))
6646 (if cut (kill-region beg end) (copy-region-as-kill beg end))
6647 (setq org-subtree-clip (current-kill 0))
6648 (message "%s: Subtree(s) with %d characters"
6649 (if cut "Cut" "Copied")
6650 (length org-subtree-clip)))))
6652 (defun org-paste-subtree (&optional level tree for-yank)
6653 "Paste the clipboard as a subtree, with modification of headline level.
6654 The entire subtree is promoted or demoted in order to match a new headline
6657 If the cursor is at the beginning of a headline, the same level as
6658 that headline is used to paste the tree
6660 If not, the new level is derived from the *visible* headings
6661 before and after the insertion point, and taken to be the inferior headline
6662 level of the two. So if the previous visible heading is level 3 and the
6663 next is level 4 (or vice versa), level 4 will be used for insertion.
6664 This makes sure that the subtree remains an independent subtree and does
6665 not swallow low level entries.
6667 You can also force a different level, either by using a numeric prefix
6668 argument, or by inserting the heading marker by hand. For example, if the
6669 cursor is after \"*****\", then the tree will be shifted to level 5.
6671 If optional TREE is given, use this text instead of the kill ring.
6673 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
6674 move back over whitespace before inserting, and move point to the end of
6675 the inserted text when done."
6677 (setq tree (or tree (and kill-ring (current-kill 0))))
6678 (unless (org-kill-is-subtree-p tree)
6680 (substitute-command-keys
6681 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
6682 (let* ((visp (not (org-invisible-p)))
6684 (^re (concat "^\\(" outline-regexp "\\)"))
6685 (re (concat "\\(" outline-regexp "\\)"))
6686 (^re_ (concat "\\(\\*+\\)[ \t]*"))
6688 (old-level (if (string-match ^re txt)
6689 (- (match-end 0) (match-beginning 0) 1)
6691 (force-level (cond (level (prefix-numeric-value level))
6692 ((and (looking-at "[ \t]*$")
6694 ^re_ (buffer-substring
6695 (point-at-bol) (point))))
6696 (- (match-end 1) (match-beginning 1)))
6698 (looking-at org-outline-regexp))
6699 (- (match-end 0) (point) 1))
6701 (previous-level (save-excursion
6704 (outline-previous-visible-heading 1)
6706 (- (match-end 0) (match-beginning 0) 1)
6709 (next-level (save-excursion
6712 (or (looking-at outline-regexp)
6713 (outline-next-visible-heading 1))
6715 (- (match-end 0) (match-beginning 0) 1)
6718 (new-level (or force-level (max previous-level next-level)))
6719 (shift (if (or (= old-level -1)
6721 (= old-level new-level))
6723 (- new-level old-level)))
6724 (delta (if (> shift 0) -1 1))
6725 (func (if (> shift 0) 'org-demote 'org-promote))
6726 (org-odd-levels-only nil)
6728 ;; Remove the forced level indicator
6730 (delete-region (point-at-bol) (point)))
6732 (beginning-of-line 1)
6733 (unless for-yank (org-back-over-empty-lines))
6735 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
6736 (insert-before-markers txt)
6737 (unless (string-match "\n\\'" txt) (insert "\n"))
6738 (setq newend (point))
6739 (org-reinstall-markers-in-region beg)
6742 (skip-chars-forward " \t\n\r")
6744 (if (and (org-invisible-p) visp)
6745 (save-excursion (outline-show-heading)))
6746 ;; Shift if necessary
6749 (narrow-to-region beg end)
6750 (while (not (= shift 0))
6751 (org-map-region func (point-min) (point-max))
6752 (setq shift (+ delta shift)))
6753 (goto-char (point-min))
6754 (setq newend (point-max))))
6755 (when (or (interactive-p) for-yank)
6756 (message "Clipboard pasted as level %d subtree" new-level))
6757 (if (and (not for-yank) ; in this case, org-yank will decide about folding
6759 (eq org-subtree-clip (current-kill 0))
6760 org-subtree-clip-folded)
6761 ;; The tree was folded before it was killed/copied
6763 (and for-yank (goto-char newend))))
6765 (defun org-kill-is-subtree-p (&optional txt)
6766 "Check if the current kill is an outline subtree, or a set of trees.
6767 Returns nil if kill does not start with a headline, or if the first
6768 headline level is not the largest headline level in the tree.
6769 So this will actually accept several entries of equal levels as well,
6770 which is OK for `org-paste-subtree'.
6771 If optional TXT is given, check this string instead of the current kill."
6772 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
6773 (start-level (and kill
6774 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
6775 org-outline-regexp "\\)")
6777 (- (match-end 2) (match-beginning 2) 1)))
6778 (re (concat "^" org-outline-regexp))
6779 (start (1+ (or (match-beginning 2) -1))))
6780 (if (not start-level)
6782 nil) ;; does not even start with a heading
6784 (while (setq start (string-match re kill (1+ start)))
6785 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
6789 (defvar org-markers-to-move nil
6790 "Markers that should be moved with a cut-and-paste operation.
6791 Those markers are stored together with their positions relative to
6792 the start of the region.")
6794 (defun org-save-markers-in-region (beg end)
6795 "Check markers in region.
6796 If these markers are between BEG and END, record their position relative
6797 to BEG, so that after moving the block of text, we can put the markers back
6799 This function gets called just before an entry or tree gets cut from the
6800 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
6801 called immediately, to move the markers with the entries."
6802 (setq org-markers-to-move nil)
6803 (when (featurep 'org-clock)
6804 (org-clock-save-markers-for-cut-and-paste beg end))
6805 (when (featurep 'org-agenda)
6806 (org-agenda-save-markers-for-cut-and-paste beg end)))
6808 (defun org-check-and-save-marker (marker beg end)
6809 "Check if MARKER is between BEG and END.
6810 If yes, remember the marker and the distance to BEG."
6811 (when (and (marker-buffer marker)
6812 (equal (marker-buffer marker) (current-buffer)))
6813 (if (and (>= marker beg) (< marker end))
6814 (push (cons marker (- marker beg)) org-markers-to-move))))
6816 (defun org-reinstall-markers-in-region (beg)
6817 "Move all remembered markers to their position relative to BEG."
6819 (move-marker (car x) (+ beg (cdr x))))
6820 org-markers-to-move)
6821 (setq org-markers-to-move nil))
6823 (defun org-narrow-to-subtree ()
6824 "Narrow buffer to the current subtree."
6829 (progn (org-back-to-heading t) (point))
6830 (progn (org-end-of-subtree t t) (point))))))
6832 (defun org-clone-subtree-with-time-shift (n &optional shift)
6833 "Clone the task (subtree) at point N times.
6834 The clones will be inserted as siblings.
6836 In interactive use, the user will be prompted for the number of clones
6837 to be produced, and for a time SHIFT, which may be a repeater as used
6838 in time stamps, for example `+3d'.
6840 When a valid repeater is given and the entry contains any time stamps,
6841 the clones will become a sequence in time, with time stamps in the
6842 subtree shifted for each clone produced. If SHIFT is nil or the
6843 empty string, time stamps will be left alone.
6845 If the original subtree did contain time stamps with a repeater,
6846 the following will happen:
6847 - the repeater will be removed in each clone
6848 - an additional clone will be produced, with the current, unshifted
6849 date(s) in the entry.
6850 - the original entry will be placed *after* all the clones, with
6852 - the start days in the repeater in the original entry will be shifted
6853 to past the last clone.
6854 I this way you can spell out a number of instances of a repeating task,
6855 and still retain the repeater to cover future instances of the task."
6856 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
6857 (let (beg end template task
6858 shift-n shift-what doshift nmin nmax (n-no-remove -1))
6859 (if (not (and (integerp n) (> n 0)))
6860 (error "Invalid number of replications %s" n))
6861 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
6862 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
6864 (error "Invalid shift specification %s" shift))
6866 (setq shift-n (string-to-number (match-string 1 shift))
6867 shift-what (cdr (assoc (match-string 2 shift)
6868 '(("d" . day) ("w" . week)
6869 ("m" . month) ("y" . year))))))
6870 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
6871 (setq nmin 1 nmax n)
6872 (org-back-to-heading t)
6874 (org-end-of-subtree t t)
6875 (or (bolp) (insert "\n"))
6877 (setq template (buffer-substring beg end))
6879 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
6880 (delete-region beg end)
6882 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
6884 (loop for n from nmin to nmax do
6886 (setq task template)
6890 (goto-char (point-min))
6891 (while (re-search-forward org-ts-regexp-both nil t)
6892 (org-timestamp-change (* n shift-n) shift-what))
6893 (unless (= n n-no-remove)
6894 (goto-char (point-min))
6895 (while (re-search-forward org-ts-regexp nil t)
6897 (goto-char (match-beginning 0))
6898 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
6899 (delete-region (match-beginning 1) (match-end 1))))))
6900 (setq task (buffer-string))))
6906 (defun org-sort (with-case)
6907 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
6908 Optional argument WITH-CASE means sort case-sensitively.
6909 With a double prefix argument, also remove duplicate entries."
6911 (if (org-at-table-p)
6912 (org-call-with-arg 'org-table-sort-lines with-case)
6913 (org-call-with-arg 'org-sort-entries-or-items with-case)))
6915 (defun org-sort-remove-invisible (s)
6916 (remove-text-properties 0 (length s) org-rm-props s)
6917 (while (string-match org-bracket-link-regexp s)
6918 (setq s (replace-match (if (match-end 2)
6920 (match-string 1 s)) t t s)))
6923 (defvar org-priority-regexp) ; defined later in the file
6925 (defvar org-after-sorting-entries-or-items-hook nil
6926 "Hook that is run after a bunch of entries or items have been sorted.
6927 When children are sorted, the cursor is in the parent line when this
6928 hook gets called. When a region or a plain list is sorted, the cursor
6929 will be in the first entry of the sorted region/list.")
6931 (defun org-sort-entries-or-items
6932 (&optional with-case sorting-type getkey-func compare-func property)
6933 "Sort entries on a certain level of an outline tree, or plain list items.
6934 If there is an active region, the entries in the region are sorted.
6935 Else, if the cursor is before the first entry, sort the top-level items.
6936 Else, the children of the entry at point are sorted.
6937 If the cursor is at the first item in a plain list, the list items will be
6940 Sorting can be alphabetically, numerically, by date/time as given by
6941 a time stamp, by a property or by priority.
6943 The command prompts for the sorting type unless it has been given to the
6944 function through the SORTING-TYPE argument, which needs to a character,
6945 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
6946 precise meaning of each character:
6948 n Numerically, by converting the beginning of the entry/item to a number.
6949 a Alphabetically, ignoring the TODO keyword and the priority, if any.
6950 t By date/time, either the first active time stamp in the entry, or, if
6951 none exist, by the first inactive one.
6952 In items, only the first line will be checked.
6953 s By the scheduled date/time.
6954 d By deadline date/time.
6955 c By creation time, which is assumed to be the first inactive time stamp
6956 at the beginning of a line.
6957 p By priority according to the cookie.
6958 r By the value of a property.
6960 Capital letters will reverse the sort order.
6962 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
6963 called with point at the beginning of the record. It must return either
6964 a string or a number that should serve as the sorting key for that record.
6966 Comparing entries ignores case by default. However, with an optional argument
6967 WITH-CASE, the sorting considers case as well."
6969 (let ((case-func (if with-case 'identity 'downcase))
6970 start beg end stars re re2
6971 txt what tmp plain-list-p)
6972 ;; Find beginning and end of region to sort
6974 ((org-region-active-p)
6975 ;; we will sort the region
6976 (setq end (region-end)
6978 (goto-char (region-beginning))
6979 (if (not (org-on-heading-p)) (outline-next-heading))
6980 (setq start (point)))
6982 ;; we will sort this plain list
6983 (org-beginning-of-item-list) (setq start (point))
6984 (org-end-of-item-list)
6985 (or (bolp) (insert "\n"))
6988 (setq plain-list-p t
6990 ((or (org-on-heading-p)
6991 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
6992 ;; we will sort the children of the current headline
6993 (org-back-to-heading)
6995 end (progn (org-end-of-subtree t t)
6996 (or (bolp) (insert "\n"))
6997 (org-back-over-empty-lines)
7002 (outline-next-heading))
7004 ;; we will sort the top-level entries in this file
7005 (goto-char (point-min))
7006 (or (org-on-heading-p) (outline-next-heading))
7007 (setq start (point))
7008 (goto-char (point-max))
7009 (beginning-of-line 1)
7010 (when (looking-at ".*?\\S-")
7011 ;; File ends in a non-white line
7014 (setq end (point-max))
7015 (setq what "top-level")
7020 (if (>= beg end) (error "Nothing to sort"))
7022 (unless plain-list-p
7023 (looking-at "\\(\\*+\\)")
7024 (setq stars (match-string 1)
7025 re (concat "^" (regexp-quote stars) " +")
7026 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7027 txt (buffer-substring beg end))
7028 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7029 (if (and (not (equal stars "*")) (string-match re2 txt))
7030 (error "Region to sort contains a level above the first entry")))
7032 (unless sorting-type
7035 "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
7036 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7037 [t]ime [s]cheduled [d]eadline [c]reated
7038 A/N/T/S/D/C/P/O/F means reversed:")
7040 (setq sorting-type (read-char-exclusive))
7042 (and (= (downcase sorting-type) ?f)
7044 (org-icompleting-read "Sort using function: "
7045 obarray 'fboundp t nil nil))
7046 (setq getkey-func (intern getkey-func)))
7048 (and (= (downcase sorting-type) ?r)
7050 (org-icompleting-read "Property: "
7051 (mapcar 'list (org-buffer-property-keys t))
7054 (message "Sorting entries...")
7057 (narrow-to-region start end)
7059 (let ((dcst (downcase sorting-type))
7060 (case-fold-search nil)
7061 (now (current-time)))
7063 (/= dcst sorting-type)
7064 ;; This function moves to the beginning character of the "record" to
7068 (if (org-at-item-p) t (goto-char (point-max))))
7070 (if (re-search-forward re nil t)
7071 (goto-char (match-beginning 0))
7072 (goto-char (point-max)))))
7073 ;; This function moves to the last character of the "record" being
7080 (outline-forward-same-level 1)
7082 (goto-char (point-max)))))))
7084 ;; This function returns the value that gets sorted against.
7087 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7090 (string-to-number (buffer-substring (match-end 0)
7093 (buffer-substring (match-end 0) (point-at-eol)))
7095 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7096 (re-search-forward org-ts-regexp-both
7098 (org-time-string-to-seconds (match-string 0))
7099 (org-float-time now)))
7103 (setq tmp (funcall getkey-func))
7104 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7106 (error "Invalid key function `%s'" getkey-func)))
7107 (t (error "Invalid sorting type `%c'" sorting-type)))))
7111 (if (looking-at org-complex-heading-regexp)
7112 (string-to-number (match-string 4))
7115 (if (looking-at org-complex-heading-regexp)
7116 (funcall case-func (match-string 4))
7119 (let ((end (save-excursion (outline-next-heading) (point))))
7120 (if (or (re-search-forward org-ts-regexp end t)
7121 (re-search-forward org-ts-regexp-both end t))
7122 (org-time-string-to-seconds (match-string 0))
7123 (org-float-time now))))
7125 (let ((end (save-excursion (outline-next-heading) (point))))
7126 (if (re-search-forward
7127 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7129 (org-time-string-to-seconds (match-string 0))
7130 (org-float-time now))))
7132 (let ((end (save-excursion (outline-next-heading) (point))))
7133 (if (re-search-forward org-scheduled-time-regexp end t)
7134 (org-time-string-to-seconds (match-string 1))
7135 (org-float-time now))))
7137 (let ((end (save-excursion (outline-next-heading) (point))))
7138 (if (re-search-forward org-deadline-time-regexp end t)
7139 (org-time-string-to-seconds (match-string 1))
7140 (org-float-time now))))
7142 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7143 (string-to-char (match-string 2))
7144 org-default-priority))
7146 (or (org-entry-get nil property) ""))
7148 (if (looking-at org-complex-heading-regexp)
7149 (- 9999 (length (member (match-string 2)
7150 org-todo-keywords-1)))))
7154 (setq tmp (funcall getkey-func))
7155 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7157 (error "Invalid key function `%s'" getkey-func)))
7158 (t (error "Invalid sorting type `%c'" sorting-type)))))
7161 ((= dcst ?a) 'string<)
7162 ((= dcst ?f) compare-func)
7163 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7165 (run-hooks 'org-after-sorting-entries-or-items-hook)
7166 (message "Sorting entries...done")))
7168 (defun org-do-sort (table what &optional with-case sorting-type)
7169 "Sort TABLE of WHAT according to SORTING-TYPE.
7170 The user will be prompted for the SORTING-TYPE if the call to this
7171 function does not specify it. WHAT is only for the prompt, to indicate
7172 what is being sorted. The sorting key will be extracted from
7173 the car of the elements of the table.
7174 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7175 (unless sorting-type
7177 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
7179 (setq sorting-type (read-char-exclusive)))
7180 (let ((dcst (downcase sorting-type))
7181 extractfun comparefun)
7182 ;; Define the appropriate functions
7185 (setq extractfun 'string-to-number
7186 comparefun (if (= dcst sorting-type) '< '>)))
7188 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7189 (lambda(x) (downcase (org-sort-remove-invisible x))))
7190 comparefun (if (= dcst sorting-type)
7192 (lambda (a b) (and (not (string< a b))
7193 (not (string= a b)))))))
7197 (if (or (string-match org-ts-regexp x)
7198 (string-match org-ts-regexp-both x))
7200 (org-time-string-to-time (match-string 0 x)))
7202 comparefun (if (= dcst sorting-type) '< '>)))
7203 (t (error "Invalid sorting type `%c'" sorting-type)))
7205 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7207 (lambda (a b) (funcall comparefun (car a) (car b))))))
7210 ;;; The orgstruct minor mode
7212 ;; Define a minor mode which can be used in other modes in order to
7213 ;; integrate the org-mode structure editing commands.
7215 ;; This is really a hack, because the org-mode structure commands use
7216 ;; keys which normally belong to the major mode. Here is how it
7217 ;; works: The minor mode defines all the keys necessary to operate the
7218 ;; structure commands, but wraps the commands into a function which
7219 ;; tests if the cursor is currently at a headline or a plain list
7220 ;; item. If that is the case, the structure command is used,
7221 ;; temporarily setting many Org-mode variables like regular
7222 ;; expressions for filling etc. However, when any of those keys is
7223 ;; used at a different location, function uses `key-binding' to look
7224 ;; up if the key has an associated command in another currently active
7225 ;; keymap (minor modes, major mode, global), and executes that
7226 ;; command. There might be problems if any of the keys is otherwise
7227 ;; used as a prefix key.
7229 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7230 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7231 ;; addresses this by checking explicitly for both bindings.
7233 (defvar orgstruct-mode-map (make-sparse-keymap)
7234 "Keymap for the minor `orgstruct-mode'.")
7236 (defvar org-local-vars nil
7237 "List of local variables, for use by `orgstruct-mode'")
7240 (define-minor-mode orgstruct-mode
7241 "Toggle the minor more `orgstruct-mode'.
7242 This mode is for using Org-mode structure commands in other modes.
7243 The following key behave as if Org-mode was active, if the cursor
7244 is on a headline, or on a plain list item (both in the definition
7247 M-up Move entry/item up
7248 M-down Move entry/item down
7251 M-S-up Move entry/item up
7252 M-S-down Move entry/item down
7253 M-S-left Promote subtree
7254 M-S-right Demote subtree
7255 M-q Fill paragraph and items like in Org-mode
7257 C-c - Cycle list bullet
7258 TAB Cycle item visibility
7259 M-RET Insert new heading/item
7260 S-M-RET Insert new TODO heading / Checkbox item
7261 C-c C-c Set tags / toggle checkbox"
7262 nil " OrgStruct" nil
7263 (org-load-modules-maybe)
7264 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7267 (defun turn-on-orgstruct ()
7268 "Unconditionally turn on `orgstruct-mode'."
7271 (defun orgstruct++-mode (&optional arg)
7272 "Toggle `orgstruct-mode', the enhanced version of it.
7273 In addition to setting orgstruct-mode, this also exports all indentation
7274 and autofilling variables from org-mode into the buffer. It will also
7275 recognize item context in multiline items.
7276 Note that turning off orgstruct-mode will *not* remove the
7277 indentation/paragraph settings. This can only be done by refreshing the
7278 major mode, for example with \\[normal-mode]."
7280 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7288 "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7289 (symbol-name (car x)))
7290 (setq var (car x) val (nth 1 x))
7291 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7293 (org-set-local 'orgstruct-is-++ t))))
7295 (defvar orgstruct-is-++ nil
7296 "Is orgstruct-mode in ++ version in the current-buffer?")
7297 (make-variable-buffer-local 'orgstruct-is-++)
7300 (defun turn-on-orgstruct++ ()
7301 "Unconditionally turn on `orgstruct++-mode'."
7302 (orgstruct++-mode 1))
7304 (defun orgstruct-error ()
7305 "Error when there is no default binding for a structure key."
7307 (error "This key has no function outside structure elements"))
7309 (defun orgstruct-setup ()
7310 "Setup orgstruct keymaps."
7314 '([(meta up)] org-metaup)
7315 '([(meta down)] org-metadown)
7316 '([(meta left)] org-metaleft)
7317 '([(meta right)] org-metaright)
7318 '([(meta shift up)] org-shiftmetaup)
7319 '([(meta shift down)] org-shiftmetadown)
7320 '([(meta shift left)] org-shiftmetaleft)
7321 '([(meta shift right)] org-shiftmetaright)
7322 '([?\e (up)] org-metaup)
7323 '([?\e (down)] org-metadown)
7324 '([?\e (left)] org-metaleft)
7325 '([?\e (right)] org-metaright)
7326 '([?\e (shift up)] org-shiftmetaup)
7327 '([?\e (shift down)] org-shiftmetadown)
7328 '([?\e (shift left)] org-shiftmetaleft)
7329 '([?\e (shift right)] org-shiftmetaright)
7330 '([(shift up)] org-shiftup)
7331 '([(shift down)] org-shiftdown)
7332 '([(shift left)] org-shiftleft)
7333 '([(shift right)] org-shiftright)
7334 '("\C-c\C-c" org-ctrl-c-ctrl-c)
7335 '("\M-q" fill-paragraph)
7337 '("\C-c-" org-cycle-list-bullet)))
7339 (while (setq elt (pop bindings))
7340 (setq nfunc (1+ nfunc))
7341 (setq key (org-key (car elt))
7343 cmd (orgstruct-make-binding fun nfunc key))
7344 (org-defkey orgstruct-mode-map key cmd))
7346 ;; Special treatment needed for TAB and RET
7347 (org-defkey orgstruct-mode-map [(tab)]
7348 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
7349 (org-defkey orgstruct-mode-map "\C-i"
7350 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
7352 (org-defkey orgstruct-mode-map "\M-\C-m"
7353 (orgstruct-make-binding 'org-insert-heading 105
7354 "\M-\C-m" [(meta return)]))
7355 (org-defkey orgstruct-mode-map [(meta return)]
7356 (orgstruct-make-binding 'org-insert-heading 106
7357 [(meta return)] "\M-\C-m"))
7359 (org-defkey orgstruct-mode-map [(shift meta return)]
7360 (orgstruct-make-binding 'org-insert-todo-heading 107
7361 [(meta return)] "\M-\C-m"))
7363 (org-defkey orgstruct-mode-map "\e\C-m"
7364 (orgstruct-make-binding 'org-insert-heading 108
7365 "\e\C-m" [?\e (return)]))
7366 (org-defkey orgstruct-mode-map [?\e (return)]
7367 (orgstruct-make-binding 'org-insert-heading 109
7368 [?\e (return)] "\e\C-m"))
7369 (org-defkey orgstruct-mode-map [?\e (shift return)]
7370 (orgstruct-make-binding 'org-insert-todo-heading 110
7371 [?\e (return)] "\e\C-m"))
7373 (unless org-local-vars
7374 (setq org-local-vars (org-get-local-variables)))
7378 (defun orgstruct-make-binding (fun n &rest keys)
7379 "Create a function for binding in the structure minor mode.
7380 FUN is the command to call inside a table. N is used to create a unique
7381 command name. KEYS are keys that should be checked in for a command
7382 to execute outside of tables."
7385 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
7387 (concat "In Structure, run `" (symbol-name fun) "'.\n"
7388 "Outside of structure, run the binding of `"
7389 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
7393 `(org-context-p 'headline 'item
7394 (and orgstruct-is-++
7395 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7397 (list 'org-run-like-in-org-mode (list 'quote fun))
7398 (list 'let '(orgstruct-mode)
7399 (list 'call-interactively
7402 (list 'key-binding k))
7404 '('orgstruct-error))))))))
7406 (defun org-context-p (&rest contexts)
7407 "Check if local context is any of CONTEXTS.
7408 Possible values in the list of contexts are `table', `headline', and `item'."
7409 (let ((pos (point)))
7410 (goto-char (point-at-bol))
7411 (prog1 (or (and (memq 'table contexts)
7412 (looking-at "[ \t]*|"))
7413 (and (memq 'headline contexts)
7414 ;;????????? (looking-at "\\*+"))
7415 (looking-at outline-regexp))
7416 (and (memq 'item contexts)
7417 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
7418 (and (memq 'item-body contexts)
7422 (defun org-get-local-variables ()
7423 "Return a list of all local variables in an org-mode buffer."
7425 (with-current-buffer (get-buffer-create "*Org tmp*")
7428 (setq varlist (buffer-local-variables)))
7429 (kill-buffer "*Org tmp*")
7436 (list (car x) (list 'quote (cdr x)))))
7438 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7439 (symbol-name (car x)))
7444 (defun org-run-like-in-org-mode (cmd)
7445 "Run a command, pretending that the current buffer is in Org-mode.
7446 This will temporarily bind local variables that are typically bound in
7447 Org-mode to the values they have in Org-mode, and then interactively
7449 (org-load-modules-maybe)
7450 (unless org-local-vars
7451 (setq org-local-vars (org-get-local-variables)))
7452 (eval (list 'let org-local-vars
7453 (list 'call-interactively (list 'quote cmd)))))
7457 (defun org-get-category (&optional pos)
7458 "Get the category applying to position POS."
7459 (get-text-property (or pos (point)) 'org-category))
7461 (defun org-refresh-category-properties ()
7462 "Refresh category text properties in the buffer."
7463 (let ((def-cat (cond
7464 ((null org-category)
7465 (if buffer-file-name
7466 (file-name-sans-extension
7467 (file-name-nondirectory buffer-file-name))
7469 ((symbolp org-category) (symbol-name org-category))
7471 beg end cat pos optionp)
7476 (goto-char (point-min))
7477 (put-text-property (point) (point-max) 'org-category def-cat)
7478 (while (re-search-forward
7479 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
7480 (setq pos (match-end 0)
7481 optionp (equal (char-after (match-beginning 0)) ?#)
7482 cat (org-trim (match-string 2)))
7484 (setq beg (point-at-bol) end (point-max))
7485 (org-back-to-heading t)
7486 (setq beg (point) end (org-end-of-subtree t t)))
7487 (put-text-property beg end 'org-category cat)
7488 (goto-char pos)))))))
7493 ;;; Link abbreviations
7495 (defun org-link-expand-abbrev (link)
7496 "Apply replacements as defined in `org-link-abbrev-alist."
7497 (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
7498 (let* ((key (match-string 1 link))
7499 (as (or (assoc key org-link-abbrev-alist-local)
7500 (assoc key org-link-abbrev-alist)))
7501 (tag (and (match-end 2) (match-string 3 link)))
7507 ((symbolp rpl) (funcall rpl tag))
7508 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
7509 ((string-match "%h" rpl)
7510 (replace-match (url-hexify-string (or tag "")) t t rpl))
7511 (t (concat rpl tag)))))
7514 ;;; Storing and inserting links
7516 (defvar org-insert-link-history nil
7517 "Minibuffer history for links inserted with `org-insert-link'.")
7519 (defvar org-stored-links nil
7520 "Contains the links stored with `org-store-link'.")
7522 (defvar org-store-link-plist nil
7523 "Plist with info about the most recently link created with `org-store-link'.")
7525 (defvar org-link-protocols nil
7526 "Link protocols added to Org-mode using `org-add-link-type'.")
7528 (defvar org-store-link-functions nil
7529 "List of functions that are called to create and store a link.
7530 Each function will be called in turn until one returns a non-nil
7531 value. Each function should check if it is responsible for creating
7532 this link (for example by looking at the major mode).
7533 If not, it must exit and return nil.
7534 If yes, it should return a non-nil value after a calling
7535 `org-store-link-props' with a list of properties and values.
7536 Special properties are:
7538 :type The link prefix. like \"http\". This must be given.
7539 :link The link, like \"http://www.astro.uva.nl/~dominik\".
7540 This is obligatory as well.
7541 :description Optional default description for the second pair
7542 of brackets in an Org-mode link. The user can still change
7543 this when inserting this link into an Org-mode buffer.
7545 In addition to these, any additional properties can be specified
7546 and then used in remember templates.")
7548 (defun org-add-link-type (type &optional follow export)
7549 "Add TYPE to the list of `org-link-types'.
7550 Re-compute all regular expressions depending on `org-link-types'
7552 FOLLOW and EXPORT are two functions.
7554 FOLLOW should take the link path as the single argument and do whatever
7555 is necessary to follow the link, for example find a file or display
7558 EXPORT should format the link path for export to one of the export formats.
7559 It should be a function accepting three arguments:
7561 path the path of the link, the text after the prefix (like \"http:\")
7562 desc the description of the link, if any, nil if there was no description
7563 format the export format, a symbol like `html' or `latex'.
7565 The function may use the FORMAT information to return different values
7566 depending on the format. The return value will be put literally into
7568 Org-mode has a built-in default for exporting links. If you are happy with
7569 this default, there is no need to define an export function for the link
7570 type. For a simple example of an export function, see `org-bbdb.el'."
7571 (add-to-list 'org-link-types type t)
7572 (org-make-link-regexps)
7573 (if (assoc type org-link-protocols)
7574 (setcdr (assoc type org-link-protocols) (list follow export))
7575 (push (list type follow export) org-link-protocols)))
7577 (defvar org-agenda-buffer-name)
7580 (defun org-store-link (arg)
7581 "\\<org-mode-map>Store an org-link to the current location.
7582 This link is added to `org-stored-links' and can later be inserted
7583 into an org-buffer with \\[org-insert-link].
7585 For some link types, a prefix arg is interpreted:
7586 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
7587 For file links, arg negates `org-context-in-file-links'."
7589 (org-load-modules-maybe)
7590 (setq org-store-link-plist nil) ; reset
7591 (let ((outline-regexp (org-get-limited-outline-regexp))
7592 link cpltxt desc description search txt custom-id)
7595 ((run-hook-with-args-until-success 'org-store-link-functions)
7596 (setq link (plist-get org-store-link-plist :link)
7597 desc (or (plist-get org-store-link-plist :description) link)))
7599 ((equal (buffer-name) "*Org Edit Src Example*")
7601 (while (or (not label)
7605 (goto-char (point-min))
7607 (regexp-quote (format org-coderef-label-format label))
7609 (when label (message "Label exists already") (sit-for 2))
7610 (setq label (read-string "Code line label: " label)))
7612 (setq link (format org-coderef-label-format label))
7613 (setq gc (- 79 (length link)))
7614 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
7616 (setq link (concat "(" label ")") desc nil)))
7618 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
7619 ;; We are in the agenda, link to referenced location
7620 (let ((m (or (get-text-property (point) 'org-hd-marker)
7621 (get-text-property (point) 'org-marker))))
7623 (org-with-point-at m
7624 (call-interactively 'org-store-link)))))
7626 ((eq major-mode 'calendar-mode)
7627 (let ((cd (calendar-cursor-to-date)))
7630 (car org-time-stamp-formats)
7632 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
7634 (org-store-link-props :type "calendar" :date cd)))
7636 ((eq major-mode 'w3-mode)
7637 (setq cpltxt (if (and (buffer-name)
7638 (not (string-match "Untitled" (buffer-name))))
7641 link (org-make-link (url-view-url t)))
7642 (org-store-link-props :type "w3" :url (url-view-url t)))
7644 ((eq major-mode 'w3m-mode)
7645 (setq cpltxt (or w3m-current-title w3m-current-url)
7646 link (org-make-link w3m-current-url))
7647 (org-store-link-props :type "w3m" :url (url-view-url t)))
7649 ((setq search (run-hook-with-args-until-success
7650 'org-create-file-search-functions))
7651 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
7653 (setq cpltxt (or description link)))
7655 ((eq major-mode 'image-mode)
7656 (setq cpltxt (concat "file:"
7657 (abbreviate-file-name buffer-file-name))
7658 link (org-make-link cpltxt))
7659 (org-store-link-props :type "image" :file buffer-file-name))
7661 ((eq major-mode 'dired-mode)
7662 ;; link to the file in the current line
7663 (setq cpltxt (concat "file:"
7664 (abbreviate-file-name
7666 (dired-get-filename nil t))))
7667 link (org-make-link cpltxt)))
7669 ((and buffer-file-name (org-mode-p))
7670 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID")))
7672 ((org-in-regexp "<<\\(.*?\\)>>")
7675 (abbreviate-file-name buffer-file-name)
7676 "::" (match-string 1))
7677 link (org-make-link cpltxt)))
7678 ((and (featurep 'org-id)
7679 (or (eq org-link-to-org-use-id t)
7680 (and (eq org-link-to-org-use-id 'create-if-interactive)
7682 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
7685 (and org-link-to-org-use-id
7687 (org-entry-get nil "ID")
7689 ;; We can make a link using the ID.
7690 (setq link (condition-case nil
7691 (prog1 (org-id-store-link)
7692 (setq desc (plist-get org-store-link-plist
7695 ;; probably before first headline, link to file only
7697 (abbreviate-file-name buffer-file-name))))))
7699 ;; Just link to current headline
7700 (setq cpltxt (concat "file:"
7701 (abbreviate-file-name buffer-file-name)))
7702 ;; Add a context search string
7703 (when (org-xor org-context-in-file-links arg)
7705 ((org-on-heading-p) nil)
7706 ((org-region-active-p)
7707 (buffer-substring (region-beginning) (region-end)))
7709 (when (or (null txt) (string-match "\\S-" txt))
7713 (org-make-org-heading-search-string txt)
7715 desc (or (nth 4 (ignore-errors
7716 (org-heading-components))) "NONE"))))
7717 (if (string-match "::\\'" cpltxt)
7718 (setq cpltxt (substring cpltxt 0 -2)))
7719 (setq link (org-make-link cpltxt)))))
7721 ((buffer-file-name (buffer-base-buffer))
7722 ;; Just link to this file here.
7723 (setq cpltxt (concat "file:"
7724 (abbreviate-file-name
7725 (buffer-file-name (buffer-base-buffer)))))
7726 ;; Add a context string
7727 (when (org-xor org-context-in-file-links arg)
7728 (setq txt (if (org-region-active-p)
7729 (buffer-substring (region-beginning) (region-end))
7730 (buffer-substring (point-at-bol) (point-at-eol))))
7731 ;; Only use search option if there is some text.
7732 (when (string-match "\\S-" txt)
7734 (concat cpltxt "::" (org-make-org-heading-search-string txt))
7736 (setq link (org-make-link cpltxt)))
7739 (error "Cannot link to a buffer which is not visiting a file"))
7741 (t (setq link nil)))
7743 (if (consp link) (setq cpltxt (car link) link (cdr link)))
7744 (setq link (or link cpltxt)
7745 desc (or desc cpltxt))
7746 (if (equal desc "NONE") (setq desc nil))
7748 (if (and (or (interactive-p) executing-kbd-macro) link)
7750 (setq org-stored-links
7751 (cons (list link desc) org-stored-links))
7752 (message "Stored: %s" (or desc link))
7754 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
7756 (setq org-stored-links
7757 (cons (list link desc) org-stored-links))))
7758 (and link (org-make-link-string link desc)))))
7760 (defun org-store-link-props (&rest plist)
7761 "Store link properties, extract names and addresses."
7763 (when (setq x (plist-get plist :from))
7764 (setq adr (mail-extract-address-components x))
7765 (setq plist (plist-put plist :fromname (car adr)))
7766 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
7767 (when (setq x (plist-get plist :to))
7768 (setq adr (mail-extract-address-components x))
7769 (setq plist (plist-put plist :toname (car adr)))
7770 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
7771 (let ((from (plist-get plist :from))
7772 (to (plist-get plist :to)))
7773 (when (and from to org-from-is-user-regexp)
7775 (plist-put plist :fromto
7776 (if (string-match org-from-is-user-regexp from)
7778 (concat "from %f"))))))
7779 (setq org-store-link-plist plist))
7781 (defun org-add-link-props (&rest plist)
7782 "Add these properties to the link property list."
7785 (setq key (pop plist) value (pop plist))
7786 (setq org-store-link-plist
7787 (plist-put org-store-link-plist key value)))))
7789 (defun org-email-link-description (&optional fmt)
7790 "Return the description part of an email link.
7791 This takes information from `org-store-link-plist' and formats it
7792 according to FMT (default from `org-email-link-description-format')."
7793 (setq fmt (or fmt org-email-link-description-format))
7794 (let* ((p org-store-link-plist)
7795 (to (plist-get p :toaddress))
7796 (from (plist-get p :fromaddress))
7799 (cons "%c" (plist-get p :fromto))
7800 (cons "%F" (plist-get p :from))
7801 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
7802 (cons "%T" (plist-get p :to))
7803 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
7804 (cons "%s" (plist-get p :subject))
7805 (cons "%m" (plist-get p :message-id)))))
7806 (when (string-match "%c" fmt)
7807 ;; Check if the user wrote this message
7808 (if (and org-from-is-user-regexp from to
7809 (save-match-data (string-match org-from-is-user-regexp from)))
7810 (setq fmt (replace-match "to %t" t t fmt))
7811 (setq fmt (replace-match "from %f" t t fmt))))
7812 (org-replace-escapes fmt table)))
7814 (defun org-make-org-heading-search-string (&optional string heading)
7815 "Make search string for STRING or current headline."
7817 (let ((s (or string (org-get-heading))))
7818 (unless (and string (not heading))
7819 ;; We are using a headline, clean up garbage in there.
7820 (if (string-match org-todo-regexp s)
7821 (setq s (replace-match "" t t s)))
7822 (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s)
7823 (setq s (replace-match "" t t s)))
7824 (setq s (org-trim s))
7825 (if (string-match (concat "^\\(" org-quote-string "\\|"
7826 org-comment-string "\\)") s)
7827 (setq s (replace-match "" t t s)))
7828 (while (string-match org-ts-regexp s)
7829 (setq s (replace-match "" t t s))))
7830 (while (string-match "[^a-zA-Z_0-9 \t]+" s)
7831 (setq s (replace-match " " t t s)))
7832 (or string (setq s (concat "*" s))) ; Add * for headlines
7833 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
7835 (defun org-make-link (&rest strings)
7836 "Concatenate STRINGS."
7837 (apply 'concat strings))
7839 (defun org-make-link-string (link &optional description)
7840 "Make a link with brackets, consisting of LINK and DESCRIPTION."
7841 (unless (string-match "\\S-" link)
7842 (error "Empty link"))
7843 (when (and description
7844 (stringp description)
7845 (not (string-match "\\S-" description)))
7846 (setq description nil))
7847 (when (stringp description)
7848 ;; Remove brackets from the description, they are fatal.
7849 (while (string-match "\\[" description)
7850 (setq description (replace-match "{" t t description)))
7851 (while (string-match "\\]" description)
7852 (setq description (replace-match "}" t t description))))
7853 (when (equal (org-link-escape link) description)
7854 ;; No description needed, it is identical
7855 (setq description nil))
7856 (when (and (not description)
7857 (not (equal link (org-link-escape link))))
7858 (setq description (org-extract-attributes link)))
7859 (concat "[[" (org-link-escape link) "]"
7860 (if description (concat "[" description "]") "")
7863 (defconst org-link-escape-chars
7867 (?\340 . "%E0") ; `a
7868 (?\342 . "%E2") ; ^a
7869 (?\347 . "%E7") ; ,c
7870 (?\350 . "%E8") ; `e
7871 (?\351 . "%E9") ; 'e
7872 (?\352 . "%EA") ; ^e
7873 (?\356 . "%EE") ; ^i
7874 (?\364 . "%F4") ; ^o
7875 (?\371 . "%F9") ; `u
7876 (?\373 . "%FB") ; ^u
7882 "Association list of escapes for some characters problematic in links.
7883 This is the list that is used for internal purposes.")
7885 (defvar org-url-encoding-use-url-hexify nil)
7887 (defconst org-link-escape-chars-browser
7888 '((?\ . "%20")) ; 32 for the SPC char
7889 "Association list of escapes for some characters problematic in links.
7890 This is the list that is used before handing over to the browser.")
7892 (defun org-link-escape (text &optional table)
7893 "Escape characters in TEXT that are problematic for links."
7894 (if org-url-encoding-use-url-hexify
7895 (url-hexify-string text)
7896 (setq table (or table org-link-escape-chars))
7898 (let ((re (mapconcat (lambda (x) (regexp-quote
7899 (char-to-string (car x))))
7901 (while (string-match re text)
7904 (cdr (assoc (string-to-char (match-string 0 text))
7909 (defun org-link-unescape (text &optional table)
7910 "Reverse the action of `org-link-escape'."
7911 (if org-url-encoding-use-url-hexify
7912 (url-unhex-string text)
7913 (setq table (or table org-link-escape-chars))
7915 (let ((re (mapconcat (lambda (x) (regexp-quote (cdr x)))
7917 (while (string-match re text)
7920 (char-to-string (car (rassoc (match-string 0 text) table)))
7924 (defun org-xor (a b)
7928 (defun org-fixup-message-id-for-http (s)
7929 "Replace special characters in a message id, so it can be used in an http query."
7930 (while (string-match "<" s)
7931 (setq s (replace-match "%3C" t t s)))
7932 (while (string-match ">" s)
7933 (setq s (replace-match "%3E" t t s)))
7934 (while (string-match "@" s)
7935 (setq s (replace-match "%40" t t s)))
7939 (defun org-insert-link-global ()
7940 "Insert a link like Org-mode does.
7941 This command can be called in any mode to insert a link in Org-mode syntax."
7943 (org-load-modules-maybe)
7944 (org-run-like-in-org-mode 'org-insert-link))
7946 (defun org-insert-link (&optional complete-file link-location)
7947 "Insert a link. At the prompt, enter the link.
7949 Completion can be used to insert any of the link protocol prefixes like
7952 The history can be used to select a link previously stored with
7953 `org-store-link'. When the empty string is entered (i.e. if you just
7954 press RET at the prompt), the link defaults to the most recently
7955 stored link. As SPC triggers completion in the minibuffer, you need to
7956 use M-SPC or C-q SPC to force the insertion of a space character.
7958 You will also be prompted for a description, and if one is given, it will
7959 be displayed in the buffer instead of the link.
7961 If there is already a link at point, this command will allow you to edit link
7962 and description parts.
7964 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
7965 be selected using completion. The path to the file will be relative to the
7966 current directory if the file is in the current directory or a subdirectory.
7967 Otherwise, the link will be the absolute path as completed in the minibuffer
7968 \(i.e. normally ~/path/to/file). You can configure this behavior using the
7969 option `org-link-file-path-type'.
7971 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
7972 the current directory or below.
7974 With three \\[universal-argument] prefixes, negate the meaning of
7975 `org-keep-stored-link-after-insertion'.
7977 If `org-make-link-description-function' is non-nil, this function will be
7978 called with the link target, and the result will be the default
7981 If the LINK-LOCATION parameter is non-nil, this value will be
7982 used as the link location instead of reading one interactively."
7984 (let* ((wcf (current-window-configuration))
7985 (region (if (org-region-active-p)
7986 (buffer-substring (region-beginning) (region-end))))
7987 (remove (and region (list (region-beginning) (region-end))))
7989 tmphist ; byte-compile incorrectly complains about this
7990 (link link-location)
7991 entry file all-prefixes)
7993 (link-location) ; specified by arg, just use it.
7994 ((org-in-regexp org-bracket-link-regexp 1)
7995 ;; We do have a link at point, and we are going to edit it.
7996 (setq remove (list (match-beginning 0) (match-end 0)))
7997 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
7998 (setq link (read-string "Link: "
8000 (org-match-string-no-properties 1)))))
8001 ((or (org-in-regexp org-angle-link-re)
8002 (org-in-regexp org-plain-link-re))
8003 ;; Convert to bracket link
8004 (setq remove (list (match-beginning 0) (match-end 0))
8005 link (read-string "Link: "
8006 (org-remove-angle-brackets (match-string 0)))))
8007 ((member complete-file '((4) (16)))
8008 ;; Completing read for file names.
8009 (setq link (org-file-complete-link complete-file)))
8011 ;; Read link, with completion for stored links.
8012 (with-output-to-temp-buffer "*Org Links*"
8013 (princ "Insert a link.
8014 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
8015 (when org-stored-links
8016 (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
8019 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8020 (reverse org-stored-links) "\n"))))
8021 (let ((cw (selected-window)))
8022 (select-window (get-buffer-window "*Org Links*"))
8023 (setq truncate-lines t)
8024 (unless (pos-visible-in-window-p (point-max))
8025 (org-fit-window-to-buffer))
8026 (and (window-live-p cw) (select-window cw)))
8027 ;; Fake a link history, containing the stored links.
8028 (setq tmphist (append (mapcar 'car org-stored-links)
8029 org-insert-link-history))
8030 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8031 (mapcar 'car org-link-abbrev-alist)
8036 (let ((org-completion-use-ido nil)
8037 (org-completion-use-iswitchb nil))
8038 (org-completing-read
8041 (mapcar (lambda (x) (list (concat x ":")))
8043 (mapcar 'car org-stored-links))
8046 (car (car org-stored-links)))))
8047 (if (not (string-match "\\S-" link))
8048 (error "No link selected"))
8049 (if (or (member link all-prefixes)
8050 (and (equal ":" (substring link -1))
8051 (member (substring link 0 -1) all-prefixes)
8052 (setq link (substring link 0 -1))))
8053 (setq link (org-link-try-special-completion link))))
8054 (set-window-configuration wcf)
8055 (kill-buffer "*Org Links*"))
8056 (setq entry (assoc link org-stored-links))
8057 (or entry (push link org-insert-link-history))
8058 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8059 (not org-keep-stored-link-after-insertion))
8060 (setq org-stored-links (delq (assoc link org-stored-links)
8062 (setq desc (or desc (nth 1 entry)))))
8064 (if (string-match org-plain-link-re link)
8065 ;; URL-like link, normalize the use of angular brackets.
8066 (setq link (org-make-link (org-remove-angle-brackets link))))
8068 ;; Check if we are linking to the current file with a search option
8069 ;; If yes, simplify the link by using only the search option.
8070 (when (and buffer-file-name
8071 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
8072 (let* ((path (match-string 1 link))
8073 (case-fold-search nil)
8074 (search (match-string 2 link)))
8076 (if (equal (file-truename buffer-file-name) (file-truename path))
8077 ;; We are linking to this same file, with a search option
8078 (setq link search)))))
8080 ;; Check if we can/should use a relative path. If yes, simplify the link
8081 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
8082 (let* ((type (match-string 1 link))
8083 (path (match-string 2 link))
8085 (case-fold-search nil))
8087 ((or (eq org-link-file-path-type 'absolute)
8088 (equal complete-file '(16)))
8089 (setq path (abbreviate-file-name (expand-file-name path))))
8090 ((eq org-link-file-path-type 'noabbrev)
8091 (setq path (expand-file-name path)))
8092 ((eq org-link-file-path-type 'relative)
8093 (setq path (file-relative-name path)))
8096 (if (string-match (concat "^" (regexp-quote
8097 (file-name-as-directory
8098 (expand-file-name "."))))
8099 (expand-file-name path))
8100 ;; We are linking a file with relative path name.
8101 (setq path (substring (expand-file-name path)
8103 (setq path (abbreviate-file-name (expand-file-name path)))))))
8104 (setq link (concat type path))
8105 (if (equal desc origpath)
8108 (if org-make-link-description-function
8109 (setq desc (funcall org-make-link-description-function link desc)))
8111 (setq desc (read-string "Description: " desc))
8112 (unless (string-match "\\S-" desc) (setq desc nil))
8113 (if remove (apply 'delete-region remove))
8114 (insert (org-make-link-string link desc))))
8116 (defun org-link-try-special-completion (type)
8117 "If there is completion support for link type TYPE, offer it."
8118 (let ((fun (intern (concat "org-" type "-complete-link"))))
8121 (read-string "Link (no completion support): " (concat type ":")))))
8123 (defun org-file-complete-link (&optional arg)
8124 "Create a file link using completion."
8126 (setq file (read-file-name "File: "))
8127 (let ((pwd (file-name-as-directory (expand-file-name ".")))
8128 (pwd1 (file-name-as-directory (abbreviate-file-name
8129 (expand-file-name ".")))))
8132 (setq link (org-make-link
8134 (abbreviate-file-name (expand-file-name file)))))
8135 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
8136 (setq link (org-make-link "file:" (match-string 1 file))))
8137 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
8138 (expand-file-name file))
8139 (setq link (org-make-link
8140 "file:" (match-string 1 (expand-file-name file)))))
8141 (t (setq link (org-make-link "file:" file)))))
8144 (defun org-completing-read (&rest args)
8145 "Completing-read with SPACE being a normal character."
8146 (let ((minibuffer-local-completion-map
8147 (copy-keymap minibuffer-local-completion-map)))
8148 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8149 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
8150 (apply 'org-icompleting-read args)))
8152 (defun org-completing-read-no-i (&rest args)
8153 (let (org-completion-use-ido org-completion-use-iswitchb)
8154 (apply 'org-completing-read args)))
8156 (defun org-iswitchb-completing-read (prompt choices &rest args)
8157 "Use iswitch as a completing-read replacement to choose from choices.
8158 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8160 (let* ((iswitchb-use-virtual-buffers nil)
8161 (iswitchb-make-buflist-hook
8163 (setq iswitchb-temp-buflist choices))))
8164 (iswitchb-read-buffer prompt)))
8166 (defun org-icompleting-read (&rest args)
8167 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
8168 (org-without-partial-completion
8169 (if (and org-completion-use-ido
8170 (fboundp 'ido-completing-read)
8171 (boundp 'ido-mode) ido-mode
8172 (listp (second args)))
8173 (let ((ido-enter-matching-directory nil))
8174 (apply 'ido-completing-read (concat (car args))
8175 (if (consp (car (nth 1 args)))
8176 (mapcar (lambda (x) (car x)) (nth 1 args))
8179 (if (and org-completion-use-iswitchb
8180 (boundp 'iswitchb-mode) iswitchb-mode
8181 (listp (second args)))
8182 (apply 'org-iswitchb-completing-read (concat (car args))
8183 (if (consp (car (nth 1 args)))
8184 (mapcar (lambda (x) (car x)) (nth 1 args))
8187 (apply 'completing-read args)))))
8189 (defun org-extract-attributes (s)
8190 "Extract the attributes cookie from a string and set as text property."
8191 (let (a attr (start 0) key value)
8193 (when (string-match "{{\\([^}]+\\)}}$" s)
8194 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8195 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
8196 (setq key (match-string 1 a) value (match-string 2 a)
8198 attr (plist-put attr (intern key) value))))
8199 (org-add-props s nil 'org-attr attr))
8202 (defun org-extract-attributes-from-string (tag)
8203 (let (key value attr)
8204 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
8205 (setq key (match-string 1 tag) value (match-string 2 tag)
8206 tag (replace-match "" t t tag)
8207 attr (plist-put attr (intern key) value)))
8210 (defun org-attributes-to-string (plist)
8211 "Format a property list into an HTML attribute list."
8212 (let ((s "") key value)
8214 (setq key (pop plist) value (pop plist))
8216 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8219 ;;; Opening/following a link
8221 (defvar org-link-search-failed nil)
8223 (defvar org-open-link-functions nil
8224 "Hook for functions finding a plain text link.
8225 These functions must take a single argument, the link content.
8226 They will be called for links that look like [[link text][description]]
8227 when LINK TEXT does not have a protocol like \"http:\" and does not look
8228 like a filename (e.g. \"./blue.png\").
8230 These functions will be called *before* Org attempts to resolve the
8231 link by doing text searches in the current buffer - so if you want a
8232 link \"[[target]]\" to still find \"<<target>>\", your function should
8233 handle this as a special case.
8235 When the function does handle the link, it must return a non-nil value.
8236 If it decides that it is not responsible for this link, it must return
8237 nil to indicate that that Org-mode can continue with other options
8238 like exact and fuzzy text search.")
8240 (defun org-next-link ()
8241 "Move forward to the next link.
8242 If the link is in hidden text, expose it."
8244 (when (and org-link-search-failed (eq this-command last-command))
8245 (goto-char (point-min))
8246 (message "Link search wrapped back to beginning of buffer"))
8247 (setq org-link-search-failed nil)
8248 (let* ((pos (point))
8250 (a (assoc :link ct)))
8251 (if a (goto-char (nth 2 a)))
8252 (if (re-search-forward org-any-link-re nil t)
8254 (goto-char (match-beginning 0))
8255 (if (org-invisible-p) (org-show-context)))
8257 (setq org-link-search-failed t)
8258 (error "No further link found"))))
8260 (defun org-previous-link ()
8261 "Move backward to the previous link.
8262 If the link is in hidden text, expose it."
8264 (when (and org-link-search-failed (eq this-command last-command))
8265 (goto-char (point-max))
8266 (message "Link search wrapped back to end of buffer"))
8267 (setq org-link-search-failed nil)
8268 (let* ((pos (point))
8270 (a (assoc :link ct)))
8271 (if a (goto-char (nth 1 a)))
8272 (if (re-search-backward org-any-link-re nil t)
8274 (goto-char (match-beginning 0))
8275 (if (org-invisible-p) (org-show-context)))
8277 (setq org-link-search-failed t)
8278 (error "No further link found"))))
8280 (defun org-translate-link (s)
8281 "Translate a link string if a translation function has been defined."
8282 (if (and org-link-translation-function
8283 (fboundp org-link-translation-function)
8284 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8286 (setq s (funcall org-link-translation-function
8287 (match-string 1) (match-string 2)))
8288 (concat (car s) ":" (cdr s)))
8291 (defun org-translate-link-from-planner (type path)
8292 "Translate a link from Emacs Planner syntax so that Org can follow it.
8293 This is still an experimental function, your mileage may vary."
8295 ((member type '("http" "https" "news" "ftp"))
8296 ;; standard Internet links are the same.
8298 ((and (equal type "irc") (string-match "^//" path))
8299 ;; Planner has two / at the beginning of an irc link, we have 1.
8300 ;; We should have zero, actually....
8301 (setq path (substring path 1)))
8302 ((and (equal type "lisp") (string-match "^/" path))
8303 ;; Planner has a slash, we do not.
8304 (setq type "elisp" path (substring path 1)))
8305 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8306 ;; A typical message link. Planner has the id after the final slash,
8307 ;; we separate it with a hash mark
8308 (setq path (concat (match-string 1 path) "#"
8309 (org-remove-angle-brackets (match-string 2 path)))))
8313 (defun org-find-file-at-mouse (ev)
8314 "Open file link or URL at mouse."
8316 (mouse-set-point ev)
8317 (org-open-at-point 'in-emacs))
8319 (defun org-open-at-mouse (ev)
8320 "Open file link or URL at mouse."
8322 (mouse-set-point ev)
8323 (if (eq major-mode 'org-agenda-mode)
8324 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8325 (org-open-at-point))
8327 (defvar org-window-config-before-follow-link nil
8328 "The window configuration before following a link.
8329 This is saved in case the need arises to restore it.")
8331 (defvar org-open-link-marker (make-marker)
8332 "Marker pointing to the location where `org-open-at-point; was called.")
8335 (defun org-open-at-point-global ()
8336 "Follow a link like Org-mode does.
8337 This command can be called in any mode to follow a link that has
8340 (org-run-like-in-org-mode 'org-open-at-point))
8343 (defun org-open-link-from-string (s &optional arg reference-buffer)
8344 "Open a link in the string S, as if it was in Org-mode."
8345 (interactive "sLink: \nP")
8346 (let ((reference-buffer (or reference-buffer (current-buffer))))
8348 (let ((org-inhibit-startup t))
8351 (goto-char (point-min))
8352 (org-open-at-point arg reference-buffer)))))
8354 (defun org-open-at-point (&optional in-emacs reference-buffer)
8355 "Open link at or after point.
8356 If there is no link at point, this function will search forward up to
8357 the end of the current line.
8358 Normally, files will be opened by an appropriate application. If the
8359 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8360 With a double prefix argument, try to open outside of Emacs, in the
8361 application the system uses for this file type."
8363 (org-load-modules-maybe)
8364 (move-marker org-open-link-marker (point))
8365 (setq org-window-config-before-follow-link (current-window-configuration))
8366 (org-remove-occur-highlights nil nil t)
8368 ((and (org-on-heading-p)
8370 (concat org-plain-link-re "\\|"
8371 org-bracket-link-regexp "\\|"
8372 org-angle-link-re "\\|"
8373 "[ \t]:[^ \t\n]+:[ \t]*$"))))
8374 (or (org-offer-links-in-entry in-emacs)
8375 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8376 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8377 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8378 (org-footnote-action))
8380 (let (type path link line search (pos (point)))
8383 (skip-chars-forward "^]\n\r")
8384 (when (org-in-regexp org-bracket-link-regexp 1)
8385 (setq link (org-extract-attributes
8386 (org-link-unescape (org-match-string-no-properties 1))))
8387 (while (string-match " *\n *" link)
8388 (setq link (replace-match " " t t link)))
8389 (setq link (org-link-expand-abbrev link))
8391 ((or (file-name-absolute-p link)
8392 (string-match "^\\.\\.?/" link))
8393 (setq type "file" path link))
8394 ((string-match org-link-re-with-space3 link)
8395 (setq type (match-string 1 link) path (match-string 2 link)))
8396 (t (setq type "thisfile" path link)))
8399 (when (get-text-property (point) 'org-linked-text)
8400 (setq type "thisfile"
8401 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8402 (1+ (point)) (point))
8403 path (buffer-substring
8404 (previous-single-property-change pos 'org-linked-text)
8405 (next-single-property-change pos 'org-linked-text)))
8409 (when (or (org-in-regexp org-angle-link-re)
8410 (org-in-regexp org-plain-link-re))
8411 (setq type (match-string 1) path (match-string 2))
8414 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8416 path (match-string 1))
8417 (while (string-match ":" path)
8418 (setq path (replace-match "+" t t path)))
8420 (when (org-in-regexp "<\\([^><\n]+\\)>")
8421 (setq type "tree-match"
8422 path (match-string 1))
8425 (error "No link found"))
8427 ;; switch back to reference buffer
8428 ;; needed when if called in a temporary buffer through
8429 ;; org-open-link-from-string
8430 (with-current-buffer (or reference-buffer (current-buffer))
8432 ;; Remove any trailing spaces in path
8433 (if (string-match " +\\'" path)
8434 (setq path (replace-match "" t t path)))
8435 (if (and org-link-translation-function
8436 (fboundp org-link-translation-function))
8437 ;; Check if we need to translate the link
8438 (let ((tmp (funcall org-link-translation-function type path)))
8439 (setq type (car tmp) path (cdr tmp))))
8443 ((assoc type org-link-protocols)
8444 (funcall (nth 1 (assoc type org-link-protocols)) path))
8446 ((equal type "mailto")
8447 (let ((cmd (car org-link-mailto-program))
8448 (args (cdr org-link-mailto-program)) args1
8449 (address path) (subject "") a)
8450 (if (string-match "\\(.*\\)::\\(.*\\)" path)
8451 (setq address (match-string 1 path)
8452 subject (org-link-escape (match-string 2 path))))
8455 ((not (stringp (car args))) (push (pop args) args1))
8456 (t (setq a (pop args))
8457 (if (string-match "%a" a)
8458 (setq a (replace-match address t t a)))
8459 (if (string-match "%s" a)
8460 (setq a (replace-match subject t t a)))
8462 (apply cmd (nreverse args1))))
8464 ((member type '("http" "https" "ftp" "news"))
8465 (browse-url (concat type ":" (org-link-escape
8466 path org-link-escape-chars-browser))))
8468 ((member type '("message"))
8469 (browse-url (concat type ":" path)))
8471 ((string= type "tags")
8472 (org-tags-view in-emacs path))
8474 ((string= type "tree-match")
8475 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
8477 ((string= type "file")
8478 (if (string-match "::\\([0-9]+\\)\\'" path)
8479 (setq line (string-to-number (match-string 1 path))
8480 path (substring path 0 (match-beginning 0)))
8481 (if (string-match "::\\(.+\\)\\'" path)
8482 (setq search (match-string 1 path)
8483 path (substring path 0 (match-beginning 0)))))
8484 (if (string-match "[*?{]" (file-name-nondirectory path))
8486 (org-open-file path in-emacs line search)))
8488 ((string= type "news")
8490 (org-gnus-follow-link path))
8492 ((string= type "shell")
8494 (if (or (not org-confirm-shell-link-function)
8495 (funcall org-confirm-shell-link-function
8496 (format "Execute \"%s\" in shell? "
8497 (org-add-props cmd nil
8498 'face 'org-warning))))
8500 (message "Executing %s" cmd)
8501 (shell-command cmd))
8504 ((string= type "elisp")
8506 (if (or (not org-confirm-elisp-link-function)
8507 (funcall org-confirm-elisp-link-function
8508 (format "Execute \"%s\" as elisp? "
8509 (org-add-props cmd nil
8510 'face 'org-warning))))
8511 (message "%s => %s" cmd
8512 (if (equal (string-to-char cmd) ?\()
8514 (call-interactively (read cmd))))
8517 ((and (string= type "thisfile")
8518 (run-hook-with-args-until-success
8519 'org-open-link-functions path)))
8521 ((string= type "thisfile")
8523 (switch-to-buffer-other-window
8524 (org-get-buffer-for-internal-link (current-buffer)))
8525 (org-mark-ring-push))
8526 (let ((cmd `(org-link-search
8528 ,(cond ((equal in-emacs '(4)) 'occur)
8529 ((equal in-emacs '(16)) 'org-occur)
8532 (condition-case nil (eval cmd)
8533 (error (progn (widen) (eval cmd))))))
8536 (browse-url-at-point)))))))
8537 (move-marker org-open-link-marker nil)
8538 (run-hook-with-args 'org-follow-link-hook))
8540 (defun org-offer-links-in-entry (&optional nth zero)
8541 "Offer links in the current entry and follow the selected link.
8542 If there is only one link, follow it immediately as well.
8543 If NTH is an integer, immediately pick the NTH link found.
8544 If ZERO is a string, check also this string for a link, and if
8545 there is one, offer it as link number zero."
8546 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
8547 "\\(" org-angle-link-re "\\)\\|"
8548 "\\(" org-plain-link-re "\\)"))
8550 (in-emacs (if (integerp nth) nil nth))
8551 have-zero end links link c)
8552 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
8553 (push (match-string 0 zero) links)
8554 (setq cnt (1- cnt) have-zero t))
8556 (org-back-to-heading t)
8557 (setq end (save-excursion (outline-next-heading) (point)))
8558 (while (re-search-forward re end t)
8559 (push (match-string 0) links))
8560 (setq links (org-uniquify (reverse links))))
8564 (message "No links"))
8565 ((equal (length links) 1)
8566 (setq link (car links)))
8567 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
8568 (setq link (nth (if have-zero nth (1- nth)) links)))
8569 (t ; we have to select a link
8571 (save-window-excursion
8572 (delete-other-windows)
8573 (with-output-to-temp-buffer "*Select Link*"
8575 (if (not (string-match org-bracket-link-regexp l))
8576 (princ (format "[%c] %s\n" (incf cnt)
8577 (org-remove-angle-brackets l)))
8579 (princ (format "[%c] %s (%s)\n" (incf cnt)
8580 (match-string 3 l) (match-string 1 l)))
8581 (princ (format "[%c] %s\n" (incf cnt)
8582 (match-string 1 l))))))
8584 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
8585 (message "Select link to open:")
8586 (setq c (read-char-exclusive))
8587 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
8588 (when (equal c ?q) (error "Abort"))
8590 (if have-zero (setq nth (1+ nth)))
8591 (unless (and (integerp nth) (>= (length links) nth))
8592 (error "Invalid link selection"))
8593 (setq link (nth (1- nth) links))))
8595 (progn (org-open-link-from-string link in-emacs (current-buffer)) t)
8600 (defun org-get-effort (&optional pom)
8601 "Get the effort estimate for the current entry."
8602 (org-entry-get pom org-effort-property))
8606 (defvar org-create-file-search-functions nil
8607 "List of functions to construct the right search string for a file link.
8608 These functions are called in turn with point at the location to
8609 which the link should point.
8611 A function in the hook should first test if it would like to
8612 handle this file type, for example by checking the major-mode or
8613 the file extension. If it decides not to handle this file, it
8614 should just return nil to give other functions a chance. If it
8615 does handle the file, it must return the search string to be used
8616 when following the link. The search string will be part of the
8617 file link, given after a double colon, and `org-open-at-point'
8618 will automatically search for it. If special measures must be
8619 taken to make the search successful, another function should be
8620 added to the companion hook `org-execute-file-search-functions',
8623 A function in this hook may also use `setq' to set the variable
8624 `description' to provide a suggestion for the descriptive text to
8625 be used for this link when it gets inserted into an Org-mode
8626 buffer with \\[org-insert-link].")
8628 (defvar org-execute-file-search-functions nil
8629 "List of functions to execute a file search triggered by a link.
8631 Functions added to this hook must accept a single argument, the
8632 search string that was part of the file link, the part after the
8633 double colon. The function must first check if it would like to
8634 handle this search, for example by checking the major-mode or the
8635 file extension. If it decides not to handle this search, it
8636 should just return nil to give other functions a chance. If it
8637 does handle the search, it must return a non-nil value to keep
8638 other functions from trying.
8640 Each function can access the current prefix argument through the
8641 variable `current-prefix-argument'. Note that a single prefix is
8642 used to force opening a link in Emacs, so it may be good to only
8643 use a numeric or double prefix to guide the search function.
8645 In case this is needed, a function in this hook can also restore
8646 the window configuration before `org-open-at-point' was called using:
8648 (set-window-configuration org-window-config-before-follow-link)")
8650 (defun org-link-search (s &optional type avoid-pos)
8651 "Search for a link search option.
8652 If S is surrounded by forward slashes, it is interpreted as a
8653 regular expression. In org-mode files, this will create an `org-occur'
8654 sparse tree. In ordinary files, `occur' will be used to list matches.
8655 If the current buffer is in `dired-mode', grep will be used to search
8656 in all files. If AVOID-POS is given, ignore matches near that position."
8657 (let ((case-fold-search t)
8658 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
8659 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
8660 (append '(("") (" ") ("\t") ("\n"))
8664 (pre nil) (post nil)
8665 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
8667 ;; First check if there are any special
8668 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
8669 ;; Now try the builtin stuff
8670 ((and (equal (string-to-char s0) ?#)
8673 (goto-char (point-min))
8676 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
8677 (setq type 'dedicated
8678 pos (match-beginning 0))))
8679 ;; There is an exact target for this
8681 (org-back-to-heading t)))
8683 (goto-char (point-min))
8686 (concat "<<" (regexp-quote s0) ">>") nil t)
8687 (setq type 'dedicated
8688 pos (match-beginning 0))))
8689 ;; There is an exact target for this
8691 ((and (string-match "^(\\(.*\\))$" s0)
8693 (goto-char (point-min))
8696 (concat "[^[]" (regexp-quote
8697 (format org-coderef-label-format
8698 (match-string 1 s0))))
8700 (setq type 'dedicated
8701 pos (1+ (match-beginning 0))))))
8702 ;; There is a coderef target for this
8704 ((string-match "^/\\(.*\\)/$" s)
8705 ;; A regular expression
8708 (org-occur (match-string 1 s)))
8709 ;;((eq major-mode 'dired-mode)
8710 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
8711 (t (org-do-occur (match-string 1 s)))))
8713 ;; A normal search strings
8714 (when (equal (string-to-char s) ?*)
8715 ;; Anchor on headlines, post may include tags.
8716 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
8717 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
8719 (remove-text-properties
8721 '(face nil mouse-face nil keymap nil fontified nil) s)
8722 ;; Make a series of regular expressions to find a match
8723 (setq words (org-split-string s "[ \n\r\t]+")
8725 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
8726 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
8728 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
8729 re2a (concat "[ \t\r\n]" re2a_)
8730 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
8731 re4 (concat "[^a-zA-Z_]" re4_)
8733 re1 (concat pre re2 post)
8734 re3 (concat pre (if pre re4_ re4) post)
8735 re5 (concat pre ".*" re4)
8736 re2 (concat pre re2)
8737 re2a (concat pre (if pre re2a_ re2a))
8738 re4 (concat pre (if pre re4_ re4))
8739 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
8740 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
8744 ((eq type 'org-occur) (org-occur reall))
8745 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
8746 (t (goto-char (point-min))
8748 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
8749 (org-search-not-self 1 re1 nil t)
8750 (org-search-not-self 1 re2 nil t)
8751 (org-search-not-self 1 re2a nil t)
8752 (org-search-not-self 1 re3 nil t)
8753 (org-search-not-self 1 re4 nil t)
8754 (org-search-not-self 1 re5 nil t)
8756 (goto-char (match-beginning 1))
8758 (error "No match")))))
8760 ;; Normal string-search
8761 (goto-char (point-min))
8762 (if (search-forward s nil t)
8763 (goto-char (match-beginning 0))
8764 (error "No match"))))
8765 (and (org-mode-p) (org-show-context 'link-search))
8768 (defun org-search-not-self (group &rest args)
8769 "Execute `re-search-forward', but only accept matches that do not
8770 enclose the position of `org-open-link-marker'."
8771 (let ((m org-open-link-marker))
8773 (while (apply 're-search-forward args)
8774 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
8775 (goto-char (match-end group))
8776 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
8777 (> (match-beginning 0) (marker-position m))
8778 (< (match-end 0) (marker-position m)))
8780 (or (not (org-in-regexp
8781 org-bracket-link-analytic-regexp 1))
8782 (not (match-end 4)) ; no description
8783 (and (<= (match-beginning 4) (point))
8784 (>= (match-end 4) (point))))))
8785 (throw 'exit (point))))))))
8787 (defun org-get-buffer-for-internal-link (buffer)
8788 "Return a buffer to be used for displaying the link target of internal links."
8790 ((not org-display-internal-link-with-indirect-buffer)
8792 ((string-match "(Clone)$" (buffer-name buffer))
8793 (message "Buffer is already a clone, not making another one")
8794 ;; we also do not modify visibility in this case
8796 (t ; make a new indirect buffer for displaying the link
8797 (let* ((bn (buffer-name buffer))
8798 (ibn (concat bn "(Clone)"))
8799 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
8800 (with-current-buffer ib (org-overview))
8803 (defun org-do-occur (regexp &optional cleanup)
8804 "Call the Emacs command `occur'.
8805 If CLEANUP is non-nil, remove the printout of the regular expression
8806 in the *Occur* buffer. This is useful if the regex is long and not useful
8810 (let ((cwin (selected-window)) win beg end)
8811 (when (setq win (get-buffer-window "*Occur*"))
8812 (select-window win))
8813 (goto-char (point-min))
8814 (when (re-search-forward "match[a-z]+" nil t)
8815 (setq beg (match-end 0))
8816 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
8817 (setq end (1- (match-beginning 0)))))
8818 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
8819 (goto-char (point-min))
8820 (select-window cwin))))
8822 ;;; The mark ring for links jumps
8824 (defvar org-mark-ring nil
8825 "Mark ring for positions before jumps in Org-mode.")
8826 (defvar org-mark-ring-last-goto nil
8827 "Last position in the mark ring used to go back.")
8828 ;; Fill and close the ring
8829 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
8830 (loop for i from 1 to org-mark-ring-length do
8831 (push (make-marker) org-mark-ring))
8832 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
8835 (defun org-mark-ring-push (&optional pos buffer)
8836 "Put the current position or POS into the mark ring and rotate it."
8838 (setq pos (or pos (point)))
8839 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
8840 (move-marker (car org-mark-ring)
8842 (or buffer (current-buffer)))
8844 (substitute-command-keys
8845 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
8847 (defun org-mark-ring-goto (&optional n)
8848 "Jump to the previous position in the mark ring.
8849 With prefix arg N, jump back that many stored positions. When
8850 called several times in succession, walk through the entire ring.
8851 Org-mode commands jumping to a different position in the current file,
8852 or to another Org-mode file, automatically push the old position
8856 (if (eq last-command this-command)
8857 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
8858 (setq p org-mark-ring))
8859 (setq org-mark-ring-last-goto p)
8861 (switch-to-buffer (marker-buffer m))
8863 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
8865 (defun org-remove-angle-brackets (s)
8866 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
8867 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
8869 (defun org-add-angle-brackets (s)
8870 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
8871 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
8873 (defun org-remove-double-quotes (s)
8874 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
8875 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
8878 ;;; Following specific links
8880 (defun org-follow-timestamp-link ()
8882 ((org-at-date-range-p t)
8883 (let ((org-agenda-start-on-weekday)
8884 (t1 (match-string 1))
8885 (t2 (match-string 2)))
8886 (setq t1 (time-to-days (org-time-string-to-time t1))
8887 t2 (time-to-days (org-time-string-to-time t2)))
8888 (org-agenda-list nil t1 (1+ (- t2 t1)))))
8889 ((org-at-timestamp-p t)
8890 (org-agenda-list nil (time-to-days (org-time-string-to-time
8891 (substring (match-string 1) 0 10)))
8893 (t (error "This should not happen"))))
8896 ;;; Following file links
8897 (defvar org-wait nil)
8898 (defun org-open-file (path &optional in-emacs line search)
8899 "Open the file at PATH.
8900 First, this expands any special file name abbreviations. Then the
8901 configuration variable `org-file-apps' is checked if it contains an
8902 entry for this file type, and if yes, the corresponding command is launched.
8904 If no application is found, Emacs simply visits the file.
8906 With optional prefix argument IN-EMACS, Emacs will visit the file.
8907 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
8908 and o use an external application to visit the file.
8910 Optional LINE specifies a line to go to, optional SEARCH a string to
8911 search for. If LINE or SEARCH is given, the file will always be
8913 If the file does not exist, an error is thrown."
8914 (setq in-emacs (or in-emacs line search))
8915 (let* ((file (if (equal path "")
8917 (substitute-in-file-name (expand-file-name path))))
8918 (apps (append org-file-apps (org-default-apps)))
8919 (remp (and (assq 'remote apps) (org-file-remote-p file)))
8920 (dirp (if remp nil (file-directory-p file)))
8921 (file (if (and dirp org-open-directory-means-index-dot-org)
8922 (concat (file-name-as-directory file) "index.org")
8924 (a-m-a-p (assq 'auto-mode apps))
8925 (dfile (downcase file))
8926 (old-buffer (current-buffer))
8928 (old-mode major-mode)
8930 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
8931 (setq ext (match-string 1 dfile))
8932 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
8933 (setq ext (match-string 1 dfile))))
8935 ((equal in-emacs '(16))
8936 (setq cmd (cdr (assoc 'system apps))))
8937 (in-emacs (setq cmd 'emacs))
8939 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
8940 (and dirp (cdr (assoc 'directory apps)))
8941 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
8943 (cdr (assoc ext apps))
8944 (cdr (assoc t apps))))))
8945 (when (eq cmd 'system)
8946 (setq cmd (cdr (assoc 'system apps))))
8947 (when (eq cmd 'default)
8948 (setq cmd (cdr (assoc t apps))))
8949 (when (eq cmd 'mailcap)
8951 (mailcap-parse-mailcaps)
8952 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
8953 (command (mailcap-mime-info mime-type)))
8954 (if (stringp command)
8956 (setq cmd 'emacs))))
8957 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
8958 (not (file-exists-p file))
8959 (not org-open-non-existing-files))
8960 (error "No such file: %s" file))
8962 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
8963 ;; Remove quotes around the file name - we'll use shell-quote-argument.
8964 (while (string-match "['\"]%s['\"]" cmd)
8965 (setq cmd (replace-match "%s" t t cmd)))
8966 (while (string-match "%s" cmd)
8967 (setq cmd (replace-match
8969 (shell-quote-argument
8970 (convert-standard-filename file)))
8972 (save-window-excursion
8973 (start-process-shell-command cmd nil cmd)
8974 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
8978 (funcall (cdr (assq 'file org-link-frame-setup)) file)
8980 (if line (org-goto-line line)
8981 (if search (org-link-search search))))
8983 (let ((file (convert-standard-filename file)))
8985 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
8986 (and (org-mode-p) (eq old-mode 'org-mode)
8987 (or (not (equal old-buffer (current-buffer)))
8988 (not (equal old-pos (point))))
8989 (org-mark-ring-push old-pos old-buffer))))
8991 (defun org-default-apps ()
8992 "Return the default applications for this operating system."
8994 ((eq system-type 'darwin)
8995 org-file-apps-defaults-macosx)
8996 ((eq system-type 'windows-nt)
8997 org-file-apps-defaults-windowsnt)
8998 (t org-file-apps-defaults-gnu)))
9000 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9001 "Convert extensions to regular expressions in the cars of LIST.
9002 Also, weed out any non-string entries, because the return value is used
9003 only for regexp matching.
9004 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9005 point to the symbol `emacs', indicating that the file should
9006 be opened in Emacs."
9010 (if (not (stringp (car x)))
9012 (if (string-match "\\W" (car x))
9014 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9017 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9019 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9020 (defun org-file-remote-p (file)
9021 "Test whether FILE specifies a location on a remote system.
9022 Return non-nil if the location is indeed remote.
9024 For example, the filename \"/user@host:/foo\" specifies a location
9025 on the system \"/user@host:\"."
9026 (cond ((fboundp 'file-remote-p)
9027 (file-remote-p file))
9028 ((fboundp 'tramp-handle-file-remote-p)
9029 (tramp-handle-file-remote-p file))
9030 ((and (boundp 'ange-ftp-name-format)
9031 (string-match (car ange-ftp-name-format) file))
9038 (defun org-get-org-file ()
9039 "Read a filename, with default directory `org-directory'."
9040 (let ((default (or org-default-notes-file remember-data-file)))
9041 (read-file-name (format "File name [%s]: " default)
9042 (file-name-as-directory org-directory)
9045 (defun org-notes-order-reversed-p ()
9046 "Check if the current file should receive notes in reversed order."
9048 ((not org-reverse-note-order) nil)
9049 ((eq t org-reverse-note-order) t)
9050 ((not (listp org-reverse-note-order)) nil)
9052 (let ((all org-reverse-note-order)
9054 (while (setq entry (pop all))
9055 (if (string-match (car entry) buffer-file-name)
9056 (throw 'exit (cdr entry))))
9059 (defvar org-refile-target-table nil
9060 "The list of refile targets, created by `org-refile'.")
9062 (defvar org-agenda-new-buffers nil
9063 "Buffers created to visit agenda files.")
9065 (defun org-get-refile-targets (&optional default-buffer)
9066 "Produce a table with refile targets."
9067 (let ((case-fold-search nil)
9068 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9069 (entries (or org-refile-targets '((nil . (:level . 1)))))
9070 targets txt re files f desc descre fast-path-p level pos0)
9071 (message "Getting targets...")
9072 (with-current-buffer (or default-buffer (current-buffer))
9073 (while (setq entry (pop entries))
9074 (setq files (car entry) desc (cdr entry))
9075 (setq fast-path-p nil)
9077 ((null files) (setq files (list (current-buffer))))
9078 ((eq files 'org-agenda-files)
9079 (setq files (org-agenda-files 'unrestricted)))
9080 ((and (symbolp files) (fboundp files))
9081 (setq files (funcall files)))
9082 ((and (symbolp files) (boundp files))
9083 (setq files (symbol-value files))))
9084 (if (stringp files) (setq files (list files)))
9086 ((eq (car desc) :tag)
9087 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9088 ((eq (car desc) :todo)
9089 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9090 ((eq (car desc) :regexp)
9091 (setq descre (cdr desc)))
9092 ((eq (car desc) :level)
9093 (setq descre (concat "^\\*\\{" (number-to-string
9094 (if org-odd-levels-only
9095 (1- (* 2 (cdr desc)))
9098 ((eq (car desc) :maxlevel)
9099 (setq fast-path-p t)
9100 (setq descre (concat "^\\*\\{1," (number-to-string
9101 (if org-odd-levels-only
9102 (1- (* 2 (cdr desc)))
9105 (t (error "Bad refiling target description %s" desc)))
9106 (while (setq f (pop files))
9107 (with-current-buffer
9108 (if (bufferp f) f (org-get-agenda-file-buffer f))
9109 (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
9110 (setq f (and f (expand-file-name f)))
9111 (if (eq org-refile-use-outline-path 'file)
9112 (push (list (file-name-nondirectory f) f nil nil) targets))
9116 (goto-char (point-min))
9117 (while (re-search-forward descre nil t)
9118 (goto-char (setq pos0 (point-at-bol)))
9120 (when org-refile-target-verify-function
9122 (or (funcall org-refile-target-verify-function)
9124 (when (looking-at org-complex-heading-regexp)
9125 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
9126 txt (org-link-display-format (match-string 4))
9127 re (concat "^" (regexp-quote
9128 (buffer-substring (match-beginning 1)
9130 (if (match-end 5) (setq re (concat re "[ \t]+"
9132 (match-string 5)))))
9133 (setq re (concat re "[ \t]*$"))
9134 (when org-refile-use-outline-path
9135 (setq txt (mapconcat 'org-protect-slash
9137 (if (eq org-refile-use-outline-path 'file)
9138 (list (file-name-nondirectory
9139 (buffer-file-name (buffer-base-buffer))))
9140 (if (eq org-refile-use-outline-path 'full-file-path)
9141 (list (buffer-file-name (buffer-base-buffer)))))
9142 (org-get-outline-path fast-path-p level txt)
9145 (push (list txt f re (point)) targets)))
9146 (when (= (point) pos0)
9147 ;; verification function has not moved point
9148 (goto-char (point-at-eol))))))))))
9149 (message "Getting targets...done")
9150 (nreverse targets)))
9152 (defun org-protect-slash (s)
9153 (while (string-match "/" s)
9154 (setq s (replace-match "\\" t t s)))
9157 (defvar org-olpa (make-vector 20 nil))
9159 (defun org-get-outline-path (&optional fastp level heading)
9160 "Return the outline path to the current entry, as a list.
9161 The parameters FASTP, LEVEL, and HEADING are for use be a scanner
9162 routine which makes outline path derivations for an entire file,
9163 avoiding backtracing."
9167 (error "Outline path failure, more than 19 levels."))
9168 (loop for i from level upto 19 do
9169 (aset org-olpa i nil))
9171 (delq nil (append org-olpa nil))
9172 (aset org-olpa level heading)))
9173 (let (rtn case-fold-search)
9177 (while (org-up-heading-safe)
9178 (when (looking-at org-complex-heading-regexp)
9179 (push (org-match-string-no-properties 4) rtn)))
9182 (defun org-format-outline-path (path &optional width prefix)
9183 "Format the outlie path PATH for display.
9184 Width is the maximum number of characters that is available.
9185 Prefix is a prefix to be included in the returned string,
9186 such as the file name."
9187 (setq width (or width 79))
9188 (if prefix (setq width (- width (length prefix))))
9191 (let* ((nsteps (length path))
9192 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9193 (maxwidth (if (<= total-width width)
9194 10000 ;; everything fits
9195 ;; we need to shorten the level headings
9196 (/ (- width nsteps) nsteps)))
9197 (org-odd-levels-only nil)
9199 (total (1+ (length prefix))))
9200 (setq maxwidth (max maxwidth 10))
9205 (if (and (= n nsteps) (< maxwidth 10000))
9206 (setq maxwidth (- total-width total)))
9207 (if (< (length h) maxwidth)
9208 (progn (setq total (+ total (length h) 1)) h)
9209 (setq h (substring h 0 (- maxwidth 2))
9210 total (+ total maxwidth 1))
9211 (if (string-match "[ \t]+\\'" h)
9212 (setq h (substring h 0 (match-beginning 0))))
9213 (setq h (concat h "..")))
9214 (org-add-props h nil 'face
9215 (nth (% (1- n) org-n-level-faces)
9220 (defun org-display-outline-path (&optional file current)
9221 "Display the current outline path in the echo area."
9223 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9224 (case-fold-search nil)
9225 (path (and (org-mode-p) (org-get-outline-path))))
9226 (if current (setq path (append path
9228 (org-back-to-heading t)
9229 (if (looking-at org-complex-heading-regexp)
9230 (list (match-string 4)))))))
9232 (org-format-outline-path
9235 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9237 (defvar org-refile-history nil
9238 "History for refiling operations.")
9240 (defvar org-after-refile-insert-hook nil
9241 "Hook run after `org-refile' has inserted its stuff at the new location.
9242 Note that this is still *before* the stuff will be removed from
9243 the *old* location.")
9245 (defun org-refile (&optional goto default-buffer rfloc)
9246 "Move the entry at point to another heading.
9247 The list of target headings is compiled using the information in
9248 `org-refile-targets', which see. This list is created before each use
9249 and will therefore always be up-to-date.
9251 At the target location, the entry is filed as a subitem of the target heading.
9252 Depending on `org-reverse-note-order', the new subitem will either be the
9253 first or the last subitem.
9255 If there is an active region, all entries in that region will be moved.
9256 However, the region must fulfil the requirement that the first heading
9257 is the first one sets the top-level of the moved text - at most siblings
9258 below it are allowed.
9260 With prefix arg GOTO, the command will only visit the target location,
9261 not actually move anything.
9262 With a double prefix `C-u C-u', go to the location where the last refiling
9263 operation has put the subtree.
9264 With a prefix argument of `2', refile to the running clock.
9266 RFLOC can be a refile location obtained in a different way.
9268 See also `org-refile-use-outline-path' and `org-completion-use-ido'"
9270 (let* ((cbuf (current-buffer))
9271 (regionp (org-region-active-p))
9272 (region-start (and regionp (region-beginning)))
9273 (region-end (and regionp (region-end)))
9274 (region-length (and regionp (- region-end region-start)))
9275 (filename (buffer-file-name (buffer-base-buffer cbuf)))
9276 pos it nbuf file re level reversed)
9277 (setq last-command nil)
9279 (goto-char region-start)
9280 (or (bolp) (goto-char (point-at-bol)))
9281 (setq region-start (point))
9282 (unless (org-kill-is-subtree-p
9283 (buffer-substring region-start region-end))
9284 (error "The region is not a (sequence of) subtree(s)")))
9285 (if (equal goto '(16))
9286 (org-refile-goto-last-stored)
9289 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
9291 (setq it (list (or org-clock-heading "running clock")
9293 (marker-buffer org-clock-hd-marker))
9295 (marker-position org-clock-hd-marker)))
9299 (org-refile-get-location
9300 (if goto "Goto: " "Refile to: ") default-buffer
9301 org-refile-allow-creating-parent-nodes)))))
9302 (setq file (nth 1 it)
9307 (equal (buffer-file-name) file)
9309 (and (>= pos region-start)
9310 (<= pos region-end))
9311 (and (>= pos (point))
9312 (< pos (save-excursion
9313 (org-end-of-subtree t t))))))
9314 (error "Cannot refile to position inside the tree or region"))
9316 (setq nbuf (or (find-buffer-visiting file)
9317 (find-file-noselect file)))
9320 (switch-to-buffer nbuf)
9322 (org-show-context 'org-goto))
9325 (org-kill-new (buffer-substring region-start region-end))
9326 (org-save-markers-in-region region-start region-end))
9327 (org-copy-subtree 1 nil t))
9328 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
9329 (find-file-noselect file)))
9330 (setq reversed (org-notes-order-reversed-p))
9337 (looking-at outline-regexp)
9338 (setq level (org-get-valid-level (funcall outline-level) 1))
9341 (or (outline-next-heading) (point-max))
9342 (or (save-excursion (org-get-next-sibling))
9343 (org-end-of-subtree t t)
9347 (goto-char (point-max))
9348 (goto-char (point-min))
9349 (or (outline-next-heading) (goto-char (point-max)))))
9350 (if (not (bolp)) (newline))
9351 (bookmark-set "org-refile-last-stored")
9352 (org-paste-subtree level)
9353 (if (fboundp 'deactivate-mark) (deactivate-mark))
9354 (run-hooks 'org-after-refile-insert-hook))))
9356 (delete-region (point) (+ (point) region-length))
9358 (when (featurep 'org-inlinetask)
9359 (org-inlinetask-remove-END-maybe))
9360 (setq org-markers-to-move nil)
9361 (message "Refiled to \"%s\"" (car it))))))
9364 (defun org-refile-goto-last-stored ()
9365 "Go to the location where the last refile was stored."
9367 (bookmark-jump "org-refile-last-stored")
9368 (message "This is the location of the last refile"))
9370 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
9371 "Prompt the user for a refile location, using PROMPT."
9372 (let ((org-refile-targets org-refile-targets)
9373 (org-refile-use-outline-path org-refile-use-outline-path))
9374 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
9375 (unless org-refile-target-table
9376 (error "No refile targets"))
9377 (let* ((cbuf (current-buffer))
9378 (partial-completion-mode nil)
9379 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
9380 (cfunc (if (and org-refile-use-outline-path
9381 org-outline-path-complete-in-steps)
9382 'org-olpath-completing-read
9383 'org-icompleting-read))
9384 (extra (if org-refile-use-outline-path "/" ""))
9385 (filename (and cfn (expand-file-name cfn)))
9388 (if (and (not (member org-refile-use-outline-path
9389 '(file full-file-path)))
9390 (not (equal filename (nth 1 x))))
9391 (cons (concat (car x) extra " ("
9392 (file-name-nondirectory (nth 1 x)) ")")
9394 (cons (concat (car x) extra) (cdr x))))
9395 org-refile-target-table))
9396 (completion-ignore-case t)
9397 pa answ parent-target child parent old-hist)
9398 (setq old-hist org-refile-history)
9399 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
9400 nil 'org-refile-history))
9401 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
9404 (when (or (not org-refile-history)
9405 (not (eq old-hist org-refile-history))
9406 (not (equal (car pa) (car org-refile-history))))
9407 (setq org-refile-history
9408 (cons (car pa) (if (assoc (car org-refile-history) tbl)
9410 (cdr org-refile-history))))
9411 (if (equal (car org-refile-history) (nth 1 org-refile-history))
9412 (pop org-refile-history)))
9414 (when (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
9415 (setq parent (match-string 1 answ)
9416 child (match-string 2 answ))
9417 (setq parent-target (or (assoc parent tbl) (assoc (concat parent "/") tbl)))
9418 (when (and parent-target
9419 (or (eq new-nodes t)
9420 (and (eq new-nodes 'confirm)
9421 (y-or-n-p (format "Create new node \"%s\"? " child)))))
9422 (org-refile-new-child parent-target child))))))
9424 (defun org-refile-new-child (parent-target child)
9425 "Use refile target PARENT-TARGET to add new CHILD below it."
9426 (unless parent-target
9427 (error "Cannot find parent for new node"))
9428 (let ((file (nth 1 parent-target))
9429 (pos (nth 3 parent-target))
9431 (with-current-buffer (or (find-buffer-visiting file)
9432 (find-file-noselect file))
9438 (goto-char (point-max))
9439 (if (not (bolp)) (newline)))
9440 (when (looking-at outline-regexp)
9441 (setq level (funcall outline-level))
9442 (org-end-of-subtree t t))
9443 (org-back-over-empty-lines)
9444 (insert "\n" (make-string
9445 (if pos (org-get-valid-level level 1) 1) ?*)
9447 (beginning-of-line 0)
9448 (list (concat (car parent-target) "/" child) file "" (point)))))))
9450 (defun org-olpath-completing-read (prompt collection &rest args)
9451 "Read an outline path like a file name."
9452 (let ((thetable collection)
9453 (org-completion-use-ido nil) ; does not work with ido.
9454 (org-completion-use-iswitchb nil)) ; or iswitchb
9456 'org-icompleting-read prompt
9457 (lambda (string predicate &optional flag)
9458 (let (rtn r f (l (length string)))
9462 (try-completion string thetable))
9465 (setq rtn (all-completions string thetable predicate))
9468 (setq r (substring x l))
9469 (if (string-match " ([^)]*)$" x)
9470 (setq f (match-string 0 x))
9472 (if (string-match "/" r)
9473 (concat string (substring r 0 (match-end 0)) f)
9478 (assoc string thetable)))
9484 (defun org-find-dblock (name)
9485 "Find the first dynamic block with name NAME in the buffer.
9486 If not found, stay at current position and return nil."
9489 (goto-char (point-min))
9490 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
9492 (match-beginning 0))))
9493 (if pos (goto-char pos))
9496 (defconst org-dblock-start-re
9497 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
9498 "Matches the start line of a dynamic block, with parameters.")
9500 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
9501 "Matches the end of a dynamic block.")
9503 (defun org-create-dblock (plist)
9504 "Create a dynamic block section, with parameters taken from PLIST.
9505 PLIST must contain a :name entry which is used as name of the block."
9506 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
9509 (let ((col (current-column))
9510 (name (plist-get plist :name)))
9511 (insert "#+BEGIN: " name)
9513 (if (eq (car plist) :name)
9514 (setq plist (cddr plist))
9515 (insert " " (prin1-to-string (pop plist)))))
9516 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
9517 (beginning-of-line -2)))
9519 (defun org-prepare-dblock ()
9520 "Prepare dynamic block for refresh.
9521 This empties the block, puts the cursor at the insert position and returns
9522 the property list including an extra property :name with the block name."
9523 (unless (looking-at org-dblock-start-re)
9524 (error "Not at a dynamic block"))
9525 (let* ((begdel (1+ (match-end 0)))
9526 (name (org-no-properties (match-string 1)))
9527 (params (append (list :name name)
9528 (read (concat "(" (match-string 3) ")")))))
9530 (beginning-of-line 1)
9531 (skip-chars-forward " \t")
9532 (setq params (plist-put params :indentation-column (current-column))))
9533 (unless (re-search-forward org-dblock-end-re nil t)
9534 (error "Dynamic block not terminated"))
9537 (list :content (buffer-substring
9538 begdel (match-beginning 0)))))
9539 (delete-region begdel (match-beginning 0))
9544 (defun org-map-dblocks (&optional command)
9545 "Apply COMMAND to all dynamic blocks in the current buffer.
9546 If COMMAND is not given, use `org-update-dblock'."
9547 (let ((cmd (or command 'org-update-dblock))
9550 (goto-char (point-min))
9551 (while (re-search-forward org-dblock-start-re nil t)
9552 (goto-char (setq pos (match-beginning 0)))
9555 (error (message "Error during update of dynamic block")))
9557 (unless (re-search-forward org-dblock-end-re nil t)
9558 (error "Dynamic block not terminated"))))))
9560 (defun org-dblock-update (&optional arg)
9561 "User command for updating dynamic blocks.
9562 Update the dynamic block at point. With prefix ARG, update all dynamic
9563 blocks in the buffer."
9566 (org-update-all-dblocks)
9567 (or (looking-at org-dblock-start-re)
9568 (org-beginning-of-dblock))
9569 (org-update-dblock)))
9571 (defun org-update-dblock ()
9572 "Update the dynamic block at point
9573 This means to empty the block, parse for parameters and then call
9574 the correct writing function."
9575 (save-window-excursion
9576 (let* ((pos (point))
9577 (line (org-current-line))
9578 (params (org-prepare-dblock))
9579 (name (plist-get params :name))
9580 (indent (plist-get params :indentation-column))
9581 (cmd (intern (concat "org-dblock-write:" name))))
9582 (message "Updating dynamic block `%s' at line %d..." name line)
9583 (funcall cmd params)
9584 (message "Updating dynamic block `%s' at line %d...done" name line)
9586 (when (and indent (> indent 0))
9587 (setq indent (make-string indent ?\ ))
9589 (org-beginning-of-dblock)
9591 (while (not (looking-at org-dblock-end-re))
9593 (beginning-of-line 2))
9594 (when (looking-at org-dblock-end-re)
9595 (and (looking-at "[ \t]+")
9597 (insert indent)))))))
9599 (defun org-beginning-of-dblock ()
9600 "Find the beginning of the dynamic block at point.
9601 Error if there is no such block at point."
9605 (if (and (re-search-backward org-dblock-start-re nil t)
9606 (setq beg (match-beginning 0))
9607 (re-search-forward org-dblock-end-re nil t)
9608 (> (match-end 0) pos))
9611 (error "Not in a dynamic block"))))
9613 (defun org-update-all-dblocks ()
9614 "Update all dynamic blocks in the buffer.
9615 This function can be used in a hook."
9617 (org-map-dblocks 'org-update-dblock)))
9622 (defconst org-additional-option-like-keywords
9623 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
9624 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
9625 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
9626 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
9628 "ORGTBL" "TBLFM:" "TBLNAME:"
9629 "BEGIN_EXAMPLE" "END_EXAMPLE"
9630 "BEGIN_QUOTE" "END_QUOTE"
9631 "BEGIN_VERSE" "END_VERSE"
9632 "BEGIN_CENTER" "END_CENTER"
9633 "BEGIN_SRC" "END_SRC"
9634 "CATEGORY" "COLUMNS"
9640 (defcustom org-structure-template-alist
9642 ("s" "#+begin_src ?\n\n#+end_src"
9643 "<src lang=\"?\">\n\n</src>")
9644 ("e" "#+begin_example\n?\n#+end_example"
9645 "<example>\n?\n</example>")
9646 ("q" "#+begin_quote\n?\n#+end_quote"
9647 "<quote>\n?\n</quote>")
9648 ("v" "#+begin_verse\n?\n#+end_verse"
9649 "<verse>\n?\n/verse>")
9650 ("c" "#+begin_center\n?\n#+end_center"
9651 "<center>\n?\n/center>")
9652 ("l" "#+begin_latex\n?\n#+end_latex"
9653 "<literal style=\"latex\">\n?\n</literal>")
9655 "<literal style=\"latex\">?</literal>")
9656 ("h" "#+begin_html\n?\n#+end_html"
9657 "<literal style=\"html\">\n?\n</literal>")
9659 "<literal style=\"html\">?</literal>")
9660 ("a" "#+begin_ascii\n?\n#+end_ascii")
9662 ("i" "#+include %file ?"
9663 "<include file=%file markup=\"?\">")
9665 "Structure completion elements.
9666 This is a list of abbreviation keys and values. The value gets inserted
9667 it you type @samp{.} followed by the key and then the completion key,
9668 usually `M-TAB'. %file will be replaced by a file name after prompting
9669 for the file using completion.
9670 There are two templates for each key, the first uses the original Org syntax,
9671 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
9672 the default when the /org-mtags.el/ module has been loaded. See also the
9673 variable `org-mtags-prefer-muse-templates'.
9674 This is an experimental feature, it is undecided if it is going to stay in."
9675 :group 'org-completion
9678 (string :tag "Template")
9679 (string :tag "Muse Template")))
9681 (defun org-try-structure-completion ()
9682 "Try to complete a structure template before point.
9683 This looks for strings like \"<e\" on an otherwise empty line and
9685 (let ((l (buffer-substring (point-at-bol) (point)))
9687 (when (and (looking-at "[ \t]*$")
9688 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
9689 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
9690 (org-complete-expand-structure-template (+ -1 (point-at-bol)
9691 (match-beginning 1)) a)
9694 (defun org-complete-expand-structure-template (start cell)
9695 "Expand a structure template."
9696 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
9697 (rpl (nth (if musep 2 1) cell))
9699 (delete-region start (point))
9700 (when (string-match "\\`#\\+" rpl)
9703 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
9704 (setq ind (buffer-substring (point-at-bol) (point))))
9706 (setq start (point))
9707 (if (string-match "%file" rpl)
9708 (setq rpl (replace-match
9712 (abbreviate-file-name (read-file-name "Include file: ")))
9715 (setq rpl (mapconcat 'identity (split-string rpl "\n")
9718 (if (re-search-backward "\\?" start t) (delete-char 1))))
9721 (defun org-complete (&optional arg)
9722 "Perform completion on word at point.
9723 At the beginning of a headline, this completes TODO keywords as given in
9724 `org-todo-keywords'.
9725 If the current word is preceded by a backslash, completes the TeX symbols
9726 that are supported for HTML support.
9727 If the current word is preceded by \"#+\", completes special words for
9728 setting file options.
9729 In the line after \"#+STARTUP:, complete valid keywords.\"
9730 At all other locations, this simply calls the value of
9731 `org-completion-fallback-command'."
9733 (org-without-partial-completion
9737 (beg1 (save-excursion
9738 (skip-chars-backward (org-re "[:alnum:]_@"))
9740 (beg (save-excursion
9741 (skip-chars-backward "a-zA-Z0-9_:$")
9743 (confirm (lambda (x) (stringp (car x))))
9744 (searchhead (equal (char-before beg) ?*))
9746 (when (and (member (char-before beg1) '(?. ?<))
9747 (setq a (assoc (buffer-substring beg1 (point))
9748 org-structure-template-alist)))
9749 (org-complete-expand-structure-template (1- beg1) a)
9751 (tag (and (equal (char-before beg1) ?:)
9752 (equal (char-after (point-at-bol)) ?*)))
9753 (prop (and (equal (char-before beg1) ?:)
9754 (not (equal (char-after (point-at-bol)) ?*))))
9755 (texp (equal (char-before beg) ?\\))
9756 (link (equal (char-before beg) ?\[))
9757 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
9760 (startup (string-match "^#\\+STARTUP:.*"
9761 (buffer-substring (point-at-bol) (point))))
9762 (completion-ignore-case opt)
9774 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
9775 (cons (match-string 2 x)
9776 (match-string 1 x))))
9777 (org-split-string (org-get-current-options) "\n")))
9778 (mapcar 'list org-additional-option-like-keywords)))
9780 (setq type :startup)
9781 org-startup-options)
9782 (link (append org-link-abbrev-alist-local
9783 org-link-abbrev-alist))
9787 ((string-match "\\`\\*+[ \t]+\\'"
9788 (buffer-substring (point-at-bol) beg))
9790 (mapcar 'list org-todo-keywords-1))
9792 (setq type :searchhead)
9794 (goto-char (point-min))
9795 (while (re-search-forward org-todo-line-regexp nil t)
9797 (org-make-org-heading-search-string
9798 (match-string 3) t))
9801 (tag (setq type :tag beg beg1)
9802 (or org-tag-alist (org-get-buffer-tags)))
9803 (prop (setq type :prop beg beg1)
9804 (mapcar 'list (org-buffer-property-keys nil t t)))
9806 (call-interactively org-completion-fallback-command)
9807 (throw 'exit nil)))))
9808 (pattern (buffer-substring-no-properties beg end))
9809 (completion (try-completion pattern table confirm)))
9810 (cond ((eq completion t)
9811 (if (not (assoc (upcase pattern) table))
9812 (message "Already complete")
9813 (if (and (equal type :opt)
9814 (not (member (car (assoc (upcase pattern) table))
9815 org-additional-option-like-keywords)))
9816 (insert (substring (cdr (assoc (upcase pattern) table))
9818 (if (memq type '(:tag :prop)) (insert ":")))))
9820 (message "Can't find completion for \"%s\"" pattern)
9822 ((not (string= pattern completion))
9823 (delete-region beg end)
9824 (if (string-match " +$" completion)
9825 (setq completion (replace-match "" t t completion)))
9827 (if (get-buffer-window "*Completions*")
9828 (delete-window (get-buffer-window "*Completions*")))
9829 (if (assoc completion table)
9830 (if (eq type :todo) (insert " ")
9831 (if (memq type '(:tag :prop)) (insert ":"))))
9832 (if (and (equal type :opt) (assoc completion table))
9833 (message "%s" (substitute-command-keys
9834 "Press \\[org-complete] again to insert example settings"))))
9836 (message "Making completion list...")
9837 (let ((list (sort (all-completions pattern table confirm)
9839 (with-output-to-temp-buffer "*Completions*"
9841 ;; Protection needed for XEmacs and emacs 21
9842 (display-completion-list list pattern)
9843 (error (display-completion-list list)))))
9844 (message "Making completion list...%s" "done")))))))
9846 ;;;; TODO, DEADLINE, Comments
9848 (defun org-toggle-comment ()
9849 "Change the COMMENT state of an entry."
9852 (org-back-to-heading)
9853 (let (case-fold-search)
9854 (if (looking-at (concat outline-regexp
9855 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
9856 (replace-match "" t t nil 1)
9857 (if (looking-at outline-regexp)
9859 (goto-char (match-end 0))
9860 (insert org-comment-string " ")))))))
9862 (defvar org-last-todo-state-is-todo nil
9863 "This is non-nil when the last TODO state change led to a TODO state.
9864 If the last change removed the TODO tag or switched to DONE, then
9867 (defvar org-setting-tags nil) ; dynamically skipped
9869 (defun org-parse-local-options (string var)
9870 "Parse STRING for startup setting relevant for variable VAR."
9871 (let ((rtn (symbol-value var))
9874 (if (or (not string) (not (string-match "\\S-" string)))
9876 (setq opts (delq nil (mapcar (lambda (x)
9877 (setq e (assoc x org-startup-options))
9878 (if (eq (nth 1 e) var) e nil))
9879 (org-split-string string "[ \t]+"))))
9883 (while (setq e (pop opts))
9885 (setq rtn (nth 2 e))
9886 (if (not (listp rtn)) (setq rtn nil))
9887 (push (nth 2 e) rtn)))
9890 (defvar org-todo-setup-filter-hook nil
9891 "Hook for functions that pre-filter todo specs.
9893 Each function takes a todo spec and returns either `nil' or the spec
9894 transformed into canonical form." )
9896 (defvar org-todo-get-default-hook nil
9897 "Hook for functions that get a default item for todo.
9899 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
9900 `nil' or a string to be used for the todo mark." )
9902 (defvar org-agenda-headline-snapshot-before-repeat)
9904 (defun org-todo (&optional arg)
9905 "Change the TODO state of an item.
9906 The state of an item is given by a keyword at the start of the heading,
9908 *** TODO Write paper
9911 The different keywords are specified in the variable `org-todo-keywords'.
9912 By default the available states are \"TODO\" and \"DONE\".
9913 So for this example: when the item starts with TODO, it is changed to DONE.
9914 When it starts with DONE, the DONE is removed. And when neither TODO nor
9915 DONE are present, add TODO at the beginning of the heading.
9917 With C-u prefix arg, use completion to determine the new state.
9918 With numeric prefix arg, switch to that state.
9919 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
9920 With a triple C-u prefix, circumvent any state blocking.
9922 For calling through lisp, arg is also interpreted in the following way:
9923 'none -> empty state
9924 \"\"(empty string) -> switch to empty state
9925 'done -> switch to DONE
9926 'nextset -> switch to the next set of keywords
9927 'previousset -> switch to the previous set of keywords
9928 \"WAITING\" -> switch to the specified keyword, but only if it
9929 really is a member of `org-todo-keywords'."
9931 (if (equal arg '(16)) (setq arg 'nextset))
9932 (let ((org-blocker-hook org-blocker-hook)
9933 (case-fold-search nil))
9934 (when (equal arg '(64))
9935 (setq arg nil org-blocker-hook nil))
9936 (when (and org-blocker-hook
9937 (or org-inhibit-blocking
9938 (org-entry-get nil "NOBLOCKING")))
9939 (setq org-blocker-hook nil))
9942 (org-back-to-heading t)
9943 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
9944 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
9946 (let* ((match-data (match-data))
9947 (startpos (point-at-bol))
9948 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
9949 (org-log-done org-log-done)
9950 (org-log-repeat org-log-repeat)
9951 (org-todo-log-states org-todo-log-states)
9952 (this (match-string 1))
9953 (hl-pos (match-beginning 0))
9954 (head (org-get-todo-sequence-head this))
9955 (ass (assoc head org-todo-kwd-alist))
9956 (interpret (nth 1 ass))
9957 (done-word (nth 3 ass))
9958 (final-done-word (nth 4 ass))
9959 (last-state (or this ""))
9960 (completion-ignore-case t)
9961 (member (member this org-todo-keywords-1))
9964 ((and org-todo-key-trigger
9965 (or (and (equal arg '(4))
9966 (eq org-use-fast-todo-selection 'prefix))
9967 (and (not arg) org-use-fast-todo-selection
9968 (not (eq org-use-fast-todo-selection
9970 ;; Use fast selection
9971 (org-fast-todo-selection))
9972 ((and (equal arg '(4))
9973 (or (not org-use-fast-todo-selection)
9974 (not org-todo-key-trigger)))
9975 ;; Read a state with completion
9976 (org-icompleting-read
9977 "State: " (mapcar (lambda(x) (list x))
9978 org-todo-keywords-1)
9982 (if tail (car tail) nil)
9983 (car org-todo-keywords-1)))
9985 (if (equal member org-todo-keywords-1)
9988 (nth (- (length org-todo-keywords-1)
9990 org-todo-keywords-1)
9991 (org-last org-todo-keywords-1))))
9992 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
9993 (setq arg nil))) ; hack to fall back to cycling
9995 ;; user or caller requests a specific state
9997 ((equal arg "") nil)
9998 ((eq arg 'none) nil)
9999 ((eq arg 'done) (or done-word (car org-done-keywords)))
10001 (or (car (cdr (member head org-todo-heads)))
10002 (car org-todo-heads)))
10003 ((eq arg 'previousset)
10004 (let ((org-todo-heads (reverse org-todo-heads)))
10005 (or (car (cdr (member head org-todo-heads)))
10006 (car org-todo-heads))))
10007 ((car (member arg org-todo-keywords-1)))
10009 (error "State `%s' not valid in this file" arg))
10010 ((nth (1- (prefix-numeric-value arg))
10011 org-todo-keywords-1))))
10012 ((null member) (or head (car org-todo-keywords-1)))
10013 ((equal this final-done-word) nil) ;; -> make empty
10014 ((null tail) nil) ;; -> first entry
10015 ((memq interpret '(type priority))
10016 (if (eq this-command last-command)
10018 (if (> (length tail) 0)
10019 (or done-word (car org-done-keywords))
10024 (run-hook-with-args-until-success
10025 'org-todo-get-default-hook state last-state)
10027 (next (if state (concat " " state " ") " "))
10028 (change-plist (list :type 'todo-state-change :from this :to state
10029 :position startpos))
10031 (when org-blocker-hook
10032 (setq org-last-todo-state-is-todo
10033 (not (member this org-done-keywords)))
10034 (unless (save-excursion
10036 (run-hook-with-args-until-failure
10037 'org-blocker-hook change-plist)))
10038 (if (interactive-p)
10039 (error "TODO state change from %s to %s blocked" this state)
10041 (message "TODO state change from %s to %s blocked" this state)
10042 (throw 'exit nil))))
10043 (store-match-data match-data)
10044 (replace-match next t t)
10045 (unless (pos-visible-in-window-p hl-pos)
10046 (message "TODO state changed to %s" (org-trim next)))
10048 (setq head (org-get-todo-sequence-head state)
10049 ass (assoc head org-todo-kwd-alist)
10050 interpret (nth 1 ass)
10051 done-word (nth 3 ass)
10052 final-done-word (nth 4 ass)))
10053 (when (memq arg '(nextset previousset))
10054 (message "Keyword-Set %d/%d: %s"
10055 (- (length org-todo-sets) -1
10056 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10057 (length org-todo-sets)
10058 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10059 (setq org-last-todo-state-is-todo
10060 (not (member state org-done-keywords)))
10061 (setq now-done-p (and (member state org-done-keywords)
10062 (not (member this org-done-keywords))))
10063 (and logging (org-local-logging logging))
10064 (when (and (or org-todo-log-states org-log-done)
10065 (not (eq org-inhibit-logging t))
10066 (not (memq arg '(nextset previousset))))
10067 ;; we need to look at recording a time and note
10068 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10069 (nth 2 (assoc this org-todo-log-states))))
10070 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10071 (setq dolog 'time))
10073 (member state org-not-done-keywords)
10074 (not (member this org-not-done-keywords)))
10075 ;; This is now a todo state and was not one before
10076 ;; If there was a CLOSED time stamp, get rid of it.
10077 (org-add-planning-info nil nil 'closed))
10078 (when (and now-done-p org-log-done)
10079 ;; It is now done, and it was not done before
10080 (org-add-planning-info 'closed (org-current-time))
10081 (if (and (not dolog) (eq 'note org-log-done))
10082 (org-add-log-setup 'done state this 'findpos 'note)))
10083 (when (and state dolog)
10084 ;; This is a non-nil state, and we need to log it
10085 (org-add-log-setup 'state state this 'findpos dolog)))
10086 ;; Fixup tag positioning
10087 (org-todo-trigger-tag-changes state)
10088 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10089 (when org-provide-todo-statistics
10090 (org-update-parent-todo-statistics))
10091 (run-hooks 'org-after-todo-state-change-hook)
10092 (if (and arg (not (member state org-done-keywords)))
10093 (setq head (org-get-todo-sequence-head state)))
10094 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10095 ;; Do we need to trigger a repeat?
10097 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10098 ;; This is for the agenda, take a snapshot of the headline.
10100 (setq org-agenda-headline-snapshot-before-repeat
10101 (org-get-heading))))
10102 (org-auto-repeat-maybe state))
10103 ;; Fixup cursor location if close to the keyword
10104 (if (and (outline-on-heading-p)
10106 (save-excursion (beginning-of-line 1)
10107 (looking-at org-todo-line-regexp))
10108 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10110 (goto-char (or (match-end 2) (match-end 1)))
10111 (and (looking-at " ") (just-one-space))))
10112 (when org-trigger-hook
10114 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10116 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10117 "Block turning an entry into a TODO, using the hierarchy.
10118 This checks whether the current task should be blocked from state
10119 changes. Such blocking occurs when:
10121 1. The task has children which are not all in a completed state.
10123 2. A task has a parent with the property :ORDERED:, and there
10124 are siblings prior to the current task with incomplete
10127 3. The parent of the task is blocked because it has siblings that should
10128 be done first, or is child of a block grandparent TODO entry."
10131 ;; If this is not a todo state change, or if this entry is already DONE,
10133 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10134 (member (plist-get change-plist :from)
10135 (cons 'done org-done-keywords))
10136 (member (plist-get change-plist :to)
10137 (cons 'todo org-not-done-keywords))
10138 (not (plist-get change-plist :to)))
10139 (throw 'dont-block t))
10140 ;; If this task has children, and any are undone, it's blocked
10142 (org-back-to-heading t)
10143 (let ((this-level (funcall outline-level)))
10144 (outline-next-heading)
10145 (let ((child-level (funcall outline-level)))
10146 (while (and (not (eobp))
10147 (> child-level this-level))
10148 ;; this todo has children, check whether they are all
10150 (if (and (not (org-entry-is-done-p))
10151 (org-entry-is-todo-p))
10152 (throw 'dont-block nil))
10153 (outline-next-heading)
10154 (setq child-level (funcall outline-level))))))
10155 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10156 ;; any previous siblings are undone, it's blocked
10158 (org-back-to-heading t)
10159 (let* ((pos (point))
10160 (parent-pos (and (org-up-heading-safe) (point))))
10161 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10162 (when (and (org-entry-get (point) "ORDERED")
10164 (re-search-forward org-not-done-heading-regexp pos t))
10165 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10166 ;; Search further up the hierarchy, to see if an anchestor is blocked
10168 (goto-char parent-pos)
10169 (if (not (looking-at org-not-done-heading-regexp))
10170 (throw 'dont-block t)) ; do not block, parent is not a TODO
10172 (setq parent-pos (and (org-up-heading-safe) (point)))
10173 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10174 (when (and (org-entry-get (point) "ORDERED")
10176 (re-search-forward org-not-done-heading-regexp pos t))
10177 (throw 'dont-block nil))))))) ; block, older sibling not done.
10179 (defcustom org-track-ordered-property-with-tag nil
10180 "Should the ORDERED property also be shown as a tag?
10181 The ORDERED property decides if an entry should require subtasks to be
10182 completed in sequence. Since a property is not very visible, setting
10183 this option means that toggling the ORDERED property with the command
10184 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10185 not relevant for the behavior, but it makes things more visible.
10187 Note that toggling the tag with tags commands will not change the property
10188 and therefore not influence behavior!
10190 This can be t, meaning the tag ORDERED should be used, It can also be a
10191 string to select a different tag for this task."
10194 (const :tag "No tracking" nil)
10195 (const :tag "Track with ORDERED tag" t)
10196 (string :tag "Use other tag")))
10198 (defun org-toggle-ordered-property ()
10199 "Toggle the ORDERED property of the current entry.
10200 For better visibility, you can track the value of this property with a tag.
10201 See variable `org-track-ordered-property-with-tag'."
10203 (let* ((t1 org-track-ordered-property-with-tag)
10204 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10206 (org-back-to-heading)
10207 (if (org-entry-get nil "ORDERED")
10209 (org-delete-property "ORDERED")
10210 (and tag (org-toggle-tag tag 'off))
10211 (message "Subtasks can be completed in arbitrary order"))
10212 (org-entry-put nil "ORDERED" "t")
10213 (and tag (org-toggle-tag tag 'on))
10214 (message "Subtasks must be completed in sequence")))))
10216 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10217 (defun org-block-todo-from-checkboxes (change-plist)
10218 "Block turning an entry into a TODO, using checkboxes.
10219 This checks whether the current task should be blocked from state
10220 changes because there are unchecked boxes in this entry."
10222 ;; If this is not a todo state change, or if this entry is already DONE,
10224 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10225 (member (plist-get change-plist :from)
10226 (cons 'done org-done-keywords))
10227 (member (plist-get change-plist :to)
10228 (cons 'todo org-not-done-keywords))
10229 (not (plist-get change-plist :to)))
10230 (throw 'dont-block t))
10231 ;; If this task has checkboxes that are not checked, it's blocked
10233 (org-back-to-heading t)
10234 (let ((beg (point)) end)
10235 (outline-next-heading)
10238 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10241 (if (boundp 'org-blocked-by-checkboxes)
10242 (setq org-blocked-by-checkboxes t))
10243 (throw 'dont-block nil)))))
10246 (defun org-entry-blocked-p ()
10247 "Is the current entry blocked?"
10248 (if (org-entry-get nil "NOBLOCKING")
10249 nil ;; Never block this entry
10251 (run-hook-with-args-until-failure
10253 (list :type 'todo-state-change
10258 (defun org-update-statistics-cookies (all)
10259 "Update the statistics cookie, either from TODO or from checkboxes.
10260 This should be called with the cursor in a line with a statistics cookie."
10264 (org-update-checkbox-count 'all)
10265 (org-map-entries 'org-update-parent-todo-statistics))
10266 (if (not (org-on-heading-p))
10267 (org-update-checkbox-count)
10268 (let ((pos (move-marker (make-marker) (point)))
10270 (ignore-errors (org-back-to-heading t))
10271 (if (not (org-on-heading-p))
10272 (org-update-checkbox-count)
10273 (setq l1 (org-outline-level))
10274 (setq end (save-excursion
10275 (outline-next-heading)
10276 (if (org-on-heading-p) (setq l2 (org-outline-level)))
10278 (if (and (save-excursion (re-search-forward
10279 "^[ \t]*[-+*] \\[[- X]\\]" end t))
10280 (not (save-excursion (re-search-forward
10281 ":COOKIE_DATA:.*\\<todo\\>" end t))))
10282 (org-update-checkbox-count)
10283 (if (and l2 (> l2 l1))
10286 (org-update-parent-todo-statistics))
10287 (error "No data for statistics cookie"))))
10289 (move-marker pos nil)))))
10291 (defvar org-entry-property-inherited-from) ;; defined below
10292 (defun org-update-parent-todo-statistics ()
10293 "Update any statistics cookie in the parent of the current headline.
10294 When `org-hierarchical-todo-statistics' is nil, statistics will cover
10295 the entire subtree and this will travel up the hierarchy and update
10296 statistics everywhere."
10298 (let* ((lim 0) prop
10299 (recursive (or (not org-hierarchical-todo-statistics)
10302 (or (setq prop (org-entry-get
10303 nil "COOKIE_DATA" 'inherit)) ""))))
10304 (lim (or (and prop (marker-position
10305 org-entry-property-inherited-from))
10308 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
10309 level ltoggle l1 new ndel
10310 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
10313 (beginning-of-line 1)
10314 (if (org-at-heading-p)
10315 (setq ltoggle (funcall outline-level))
10316 (error "This should not happen"))
10317 (while (and (setq level (org-up-heading-safe))
10318 (or recursive first)
10320 (setq first nil cookie-present nil)
10329 (while (re-search-forward box-re (point-at-eol) t)
10330 (setq cnt-all 0 cnt-done 0 cookie-present t)
10331 (setq is-percent (match-end 2))
10333 (unless (outline-next-heading) (throw 'exit nil))
10334 (while (and (looking-at org-complex-heading-regexp)
10335 (> (setq l1 (length (match-string 1))) level))
10336 (setq kwd (and (or recursive (= l1 ltoggle))
10338 (if (or (eq org-provide-todo-statistics 'all-headlines)
10339 (and (listp org-provide-todo-statistics)
10340 (or (member kwd org-provide-todo-statistics)
10341 (member kwd org-done-keywords))))
10342 (setq cnt-all (1+ cnt-all))
10343 (if (eq org-provide-todo-statistics t)
10344 (and kwd (setq cnt-all (1+ cnt-all)))))
10345 (and (member kwd org-done-keywords)
10346 (setq cnt-done (1+ cnt-done)))
10347 (outline-next-heading)))
10350 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
10351 (format "[%d/%d]" cnt-done cnt-all))
10352 ndel (- (match-end 0) (match-beginning 0)))
10353 (goto-char (match-beginning 0))
10355 (delete-region (point) (+ (point) ndel)))
10356 (when cookie-present
10357 (run-hook-with-args 'org-after-todo-statistics-hook
10358 cnt-done (- cnt-all cnt-done))))))
10359 (run-hooks 'org-todo-statistics-hook)))
10361 (defvar org-after-todo-statistics-hook nil
10362 "Hook that is called after a TODO statistics cookie has been updated.
10363 Each function is called with two arguments: the number of not-done entries
10364 and the number of done entries.
10366 For example, the following function, when added to this hook, will switch
10367 an entry to DONE when all children are done, and back to TODO when new
10368 entries are set to a TODO status. Note that this hook is only called
10369 when there is a statistics cookie in the headline!
10371 (defun org-summary-todo (n-done n-not-done)
10372 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
10373 (let (org-log-done org-log-states) ; turn off logging
10374 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
10377 (defvar org-todo-statistics-hook nil
10378 "Hook that is run whenever Org thinks TODO statistics should be updated.
10379 This hook runs even if there is no statistics cookie present, in which case
10380 `org-after-todo-statistics-hook' would not run.")
10382 (defun org-todo-trigger-tag-changes (state)
10383 "Apply the changes defined in `org-todo-state-tags-triggers'."
10384 (let ((l org-todo-state-tags-triggers)
10386 (when (or (not state) (equal state ""))
10387 (setq changes (append changes (cdr (assoc "" l)))))
10388 (when (and (stringp state) (> (length state) 0))
10389 (setq changes (append changes (cdr (assoc state l)))))
10390 (when (member state org-not-done-keywords)
10391 (setq changes (append changes (cdr (assoc 'todo l)))))
10392 (when (member state org-done-keywords)
10393 (setq changes (append changes (cdr (assoc 'done l)))))
10394 (dolist (c changes)
10395 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
10397 (defun org-local-logging (value)
10398 "Get logging settings from a property VALUE."
10400 ;; directly set the variables, they are already local.
10401 (setq org-log-done nil
10403 org-todo-log-states nil)
10404 (setq words (org-split-string value))
10405 (while (setq w (pop words))
10407 ((setq a (assoc w org-startup-options))
10408 (and (member (nth 1 a) '(org-log-done org-log-repeat))
10409 (set (nth 1 a) (nth 2 a))))
10410 ((setq a (org-extract-log-state-settings w))
10411 (and (member (car a) org-todo-keywords-1)
10412 (push a org-todo-log-states)))))))
10414 (defun org-get-todo-sequence-head (kwd)
10415 "Return the head of the TODO sequence to which KWD belongs.
10416 If KWD is not set, check if there is a text property remembering the
10421 (or (get-text-property (point-at-bol) 'org-todo-head)
10423 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
10424 nil (point-at-eol)))
10425 (get-text-property p 'org-todo-head))))
10426 ((not (member kwd org-todo-keywords-1))
10427 (car org-todo-keywords-1))
10428 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
10430 (defun org-fast-todo-selection ()
10431 "Fast TODO keyword selection with single keys.
10432 Returns the new TODO keyword, or nil if no state change should occur."
10433 (let* ((fulltable org-todo-key-alist)
10434 (done-keywords org-done-keywords) ;; needed for the faces.
10435 (maxlen (apply 'max (mapcar
10437 (if (stringp (car x)) (string-width (car x)) 0))
10440 (fwidth (+ maxlen 3 1 3))
10441 (ncol (/ (- (window-width) 4) fwidth))
10445 (save-window-excursion
10447 (set-buffer (get-buffer-create " *Org todo*"))
10448 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
10450 (org-set-local 'org-done-keywords done-keywords)
10451 (setq tbl fulltable cnt 0)
10452 (while (setq e (pop tbl))
10454 ((equal e '(:startgroup))
10455 (push '() groups) (setq ingroup t)
10456 (when (not (= cnt 0))
10460 ((equal e '(:endgroup))
10461 (setq ingroup nil cnt 0)
10463 ((equal e '(:newline))
10464 (when (not (= cnt 0))
10468 (while (equal (car tbl) '(:newline))
10470 (setq tbl (cdr tbl)))))
10472 (setq tg (car e) c (cdr e))
10473 (if ingroup (push tg (car groups)))
10474 (setq tg (org-add-props tg nil 'face
10475 (org-get-todo-face tg)))
10476 (if (and (= cnt 0) (not ingroup)) (insert " "))
10477 (insert "[" c "] " tg (make-string
10478 (- fwidth 4 (length tg)) ?\ ))
10479 (when (= (setq cnt (1+ cnt)) ncol)
10481 (if ingroup (insert " "))
10484 (goto-char (point-min))
10485 (if (not expert) (org-fit-window-to-buffer))
10486 (message "[a-z..]:Set [SPC]:clear")
10487 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
10490 (and (= c ?q) (not (rassoc c fulltable))))
10491 (setq quit-flag t))
10493 ((setq e (rassoc c fulltable) tg (car e))
10495 (t (setq quit-flag t)))))))
10497 (defun org-entry-is-todo-p ()
10498 (member (org-get-todo-state) org-not-done-keywords))
10500 (defun org-entry-is-done-p ()
10501 (member (org-get-todo-state) org-done-keywords))
10503 (defun org-get-todo-state ()
10505 (org-back-to-heading t)
10506 (and (looking-at org-todo-line-regexp)
10508 (match-string 2))))
10510 (defun org-at-date-range-p (&optional inactive-ok)
10511 "Is the cursor inside a date range?"
10515 (let ((pos (point)))
10516 (skip-chars-backward "^[<\r\n")
10517 (skip-chars-backward "<[")
10518 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10519 (>= (match-end 0) pos)
10521 (skip-chars-backward "^<[\r\n")
10522 (skip-chars-backward "<[")
10523 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10524 (>= (match-end 0) pos)
10528 (defun org-get-repeat (&optional tagline)
10529 "Check if there is a deadline/schedule with repeater in this entry."
10532 (org-back-to-heading t)
10533 (and (re-search-forward (if tagline
10534 (concat tagline "\\s-*" org-repeat-re)
10536 (org-entry-end-position) t)
10537 (match-string-no-properties 1)))))
10539 (defvar org-last-changed-timestamp)
10540 (defvar org-last-inserted-timestamp)
10541 (defvar org-log-post-message)
10542 (defvar org-log-note-purpose)
10543 (defvar org-log-note-how)
10544 (defvar org-log-note-extra)
10545 (defun org-auto-repeat-maybe (done-word)
10546 "Check if the current headline contains a repeated deadline/schedule.
10547 If yes, set TODO state back to what it was and change the base date
10548 of repeating deadline/scheduled time stamps to new date.
10549 This function is run automatically after each state change to a DONE state."
10550 ;; last-state is dynamically scoped into this function
10551 (let* ((repeat (org-get-repeat))
10552 (aa (assoc last-state org-todo-kwd-alist))
10553 (interpret (nth 1 aa))
10555 (whata '(("d" . day) ("m" . month) ("y" . year)))
10556 (msg "Entry repeats: ")
10558 (org-todo-log-states nil)
10559 (nshiftmax 10) (nshift 0)
10560 re type n what ts time)
10562 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
10563 (org-todo (if (eq interpret 'type) last-state head))
10564 (org-entry-put nil "LAST_REPEAT" (format-time-string
10565 (org-time-stamp-format t t)))
10566 (when org-log-repeat
10567 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
10568 (memq 'org-add-log-note post-command-hook))
10569 ;; OK, we are already setup for some record
10570 (if (eq org-log-repeat 'note)
10571 ;; make sure we take a note, not only a time stamp
10572 (setq org-log-note-how 'note))
10573 ;; Set up for taking a record
10574 (org-add-log-setup 'state (or done-word (car org-done-keywords))
10576 'findpos org-log-repeat)))
10577 (org-back-to-heading t)
10578 (org-add-planning-info nil nil 'closed)
10579 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
10580 org-deadline-time-regexp "\\)\\|\\("
10581 org-ts-regexp "\\)"))
10582 (while (re-search-forward
10583 re (save-excursion (outline-next-heading) (point)) t)
10584 (setq type (if (match-end 1) org-scheduled-string
10585 (if (match-end 3) org-deadline-string "Plain:"))
10586 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
10587 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
10588 (setq n (string-to-number (match-string 2 ts))
10589 what (match-string 3 ts))
10590 (if (equal what "w") (setq n (* n 7) what "d"))
10591 ;; Preparation, see if we need to modify the start date for the change
10592 (when (match-end 1)
10593 (setq time (save-match-data (org-time-string-to-time ts)))
10595 ((equal (match-string 1 ts) ".")
10596 ;; Shift starting date to today
10597 (org-timestamp-change
10598 (- (time-to-days (current-time)) (time-to-days time))
10600 ((equal (match-string 1 ts) "+")
10601 (while (or (= nshift 0)
10602 (<= (time-to-days time) (time-to-days (current-time))))
10603 (when (= (incf nshift) nshiftmax)
10604 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
10606 (org-timestamp-change n (cdr (assoc what whata)))
10607 (org-at-timestamp-p t)
10608 (setq ts (match-string 1))
10609 (setq time (save-match-data (org-time-string-to-time ts))))
10610 (org-timestamp-change (- n) (cdr (assoc what whata)))
10611 ;; rematch, so that we have everything in place for the real shift
10612 (org-at-timestamp-p t)
10613 (setq ts (match-string 1))
10614 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
10615 (org-timestamp-change n (cdr (assoc what whata)))
10616 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
10617 (setq org-log-post-message msg)
10618 (message "%s" msg))))
10620 (defun org-show-todo-tree (arg)
10621 "Make a compact tree which shows all headlines marked with TODO.
10622 The tree will show the lines where the regexp matches, and all higher
10623 headlines above the match.
10624 With a \\[universal-argument] prefix, prompt for a regexp to match.
10625 With a numeric prefix N, construct a sparse tree for the Nth element
10626 of `org-todo-keywords-1'."
10628 (let ((case-fold-search nil)
10630 (cond ((null arg) org-not-done-regexp)
10632 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
10633 (mapcar 'list org-todo-keywords-1))))
10635 (mapconcat 'identity (org-split-string kwd "|") "\\|")
10637 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
10638 (regexp-quote (nth (1- (prefix-numeric-value arg))
10639 org-todo-keywords-1)))
10640 (t (error "Invalid prefix argument: %s" arg)))))
10641 (message "%d TODO entries found"
10642 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
10644 (defun org-deadline (&optional remove time)
10645 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
10646 With argument REMOVE, remove any deadline from the item.
10647 When TIME is set, it should be an internal time specification, and the
10648 scheduling will use the corresponding date."
10650 (let ((old-date (org-entry-get nil "DEADLINE")))
10653 (when (and old-date org-log-redeadline)
10654 (org-add-log-setup 'deldeadline nil old-date 'findpos
10655 org-log-redeadline))
10656 (org-remove-timestamp-with-keyword org-deadline-string)
10657 (message "Item no longer has a deadline."))
10658 (if (org-get-repeat)
10659 (error "Cannot change deadline on task with repeater, please do that by hand")
10660 (org-add-planning-info 'deadline time 'closed)
10661 (when (and old-date org-log-redeadline
10662 (not (equal old-date
10663 (substring org-last-inserted-timestamp 1 -1))))
10664 (org-add-log-setup 'redeadline nil old-date 'findpos
10665 org-log-redeadline))
10666 (message "Deadline on %s" org-last-inserted-timestamp)))))
10668 (defun org-schedule (&optional remove time)
10669 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
10670 With argument REMOVE, remove any scheduling date from the item.
10671 When TIME is set, it should be an internal time specification, and the
10672 scheduling will use the corresponding date."
10674 (let ((old-date (org-entry-get nil "SCHEDULED")))
10677 (when (and old-date org-log-reschedule)
10678 (org-add-log-setup 'delschedule nil old-date 'findpos
10679 org-log-reschedule))
10680 (org-remove-timestamp-with-keyword org-scheduled-string)
10681 (message "Item is no longer scheduled."))
10682 (if (org-get-repeat)
10683 (error "Cannot reschedule task with repeater, please do that by hand")
10684 (org-add-planning-info 'scheduled time 'closed)
10685 (when (and old-date org-log-reschedule
10686 (not (equal old-date
10687 (substring org-last-inserted-timestamp 1 -1))))
10688 (org-add-log-setup 'reschedule nil old-date 'findpos
10689 org-log-reschedule))
10690 (message "Scheduled to %s" org-last-inserted-timestamp)))))
10692 (defun org-get-scheduled-time (pom &optional inherit)
10693 "Get the scheduled time as a time tuple, of a format suitable
10694 for calling org-schedule with, or if there is no scheduling,
10696 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
10698 (apply 'encode-time (org-parse-time-string time)))))
10700 (defun org-get-deadline-time (pom &optional inherit)
10701 "Get the deadine as a time tuple, of a format suitable for
10702 calling org-deadline with, or if there is no scheduling, returns
10704 (let ((time (org-entry-get pom "DEADLINE" inherit)))
10706 (apply 'encode-time (org-parse-time-string time)))))
10708 (defun org-remove-timestamp-with-keyword (keyword)
10709 "Remove all time stamps with KEYWORD in the current entry."
10710 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
10713 (org-back-to-heading t)
10715 (outline-next-heading)
10716 (while (re-search-backward re beg t)
10718 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
10719 (equal (char-before) ?\ ))
10720 (backward-delete-char 1)
10721 (if (string-match "^[ \t]*$" (buffer-substring
10722 (point-at-bol) (point-at-eol)))
10723 (delete-region (point-at-bol)
10724 (min (point-max) (1+ (point-at-eol))))))))))
10726 (defun org-add-planning-info (what &optional time &rest remove)
10727 "Insert new timestamp with keyword in the line directly after the headline.
10728 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
10729 If non is given, the user is prompted for a date.
10730 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
10733 (let (org-time-was-given org-end-time-was-given ts
10734 end default-time default-input)
10737 (when (and (not time) (memq what '(scheduled deadline)))
10738 ;; Try to get a default date/time from existing timestamp
10740 (org-back-to-heading t)
10741 (setq end (save-excursion (outline-next-heading) (point)))
10742 (when (re-search-forward (if (eq what 'scheduled)
10743 org-scheduled-time-regexp
10744 org-deadline-time-regexp)
10746 (setq ts (match-string 1)
10748 (apply 'encode-time (org-parse-time-string ts))
10749 default-input (and ts (org-get-compact-tod ts))))))
10751 ;; If necessary, get the time from the user
10752 (setq time (or time (org-read-date nil 'to-time nil nil
10753 default-time default-input))))
10755 (when (and org-insert-labeled-timestamps-at-point
10756 (member what '(scheduled deadline)))
10758 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
10759 (org-insert-time-stamp time org-time-was-given
10760 nil nil nil (list org-end-time-was-given))
10764 (let (col list elt ts buffer-invisibility-spec)
10765 (org-back-to-heading t)
10766 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
10767 (goto-char (match-end 1))
10768 (setq col (current-column))
10769 (goto-char (match-end 0))
10770 (if (eobp) (insert "\n") (forward-char 1))
10771 (when (and (not what)
10774 org-keyword-time-not-clock-regexp))))
10775 ;; Nothing to add, nothing to remove...... :-)
10777 (if (and (not (looking-at outline-regexp))
10778 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
10780 (not (equal (match-string 1) org-clock-string)))
10781 (narrow-to-region (match-beginning 0) (match-end 0))
10782 (insert-before-markers "\n")
10784 (narrow-to-region (point) (point))
10785 (and org-adapt-indentation (org-indent-to-column col)))
10786 ;; Check if we have to remove something.
10787 (setq list (cons what remove))
10789 (setq elt (pop list))
10790 (goto-char (point-min))
10791 (when (or (and (eq elt 'scheduled)
10792 (re-search-forward org-scheduled-time-regexp nil t))
10793 (and (eq elt 'deadline)
10794 (re-search-forward org-deadline-time-regexp nil t))
10795 (and (eq elt 'closed)
10796 (re-search-forward org-closed-time-regexp nil t)))
10798 (if (looking-at "--+<[^>]+>") (replace-match ""))
10799 (skip-chars-backward " ")
10800 (if (looking-at " +") (replace-match ""))))
10801 (goto-char (point-max))
10802 (and org-adapt-indentation (bolp) (org-indent-to-column col))
10805 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
10806 (cond ((eq what 'scheduled) org-scheduled-string)
10807 ((eq what 'deadline) org-deadline-string)
10808 ((eq what 'closed) org-closed-string))
10810 (setq ts (org-insert-time-stamp
10812 (or org-time-was-given
10813 (and (eq what 'closed) org-log-done-with-time))
10815 nil nil (list org-end-time-was-given)))
10817 (goto-char (point-min))
10819 (if (and (looking-at "[ \t]+\n")
10820 (equal (char-before) ?\n))
10821 (delete-region (1- (point)) (point-at-eol)))
10824 (defvar org-log-note-marker (make-marker))
10825 (defvar org-log-note-purpose nil)
10826 (defvar org-log-note-state nil)
10827 (defvar org-log-note-previous-state nil)
10828 (defvar org-log-note-how nil)
10829 (defvar org-log-note-extra nil)
10830 (defvar org-log-note-window-configuration nil)
10831 (defvar org-log-note-return-to (make-marker))
10832 (defvar org-log-post-message nil
10833 "Message to be displayed after a log note has been stored.
10834 The auto-repeater uses this.")
10836 (defun org-add-note ()
10837 "Add a note to the current entry.
10838 This is done in the same way as adding a state change note."
10840 (org-add-log-setup 'note nil nil 'findpos nil))
10842 (defvar org-property-end-re)
10843 (defun org-add-log-setup (&optional purpose state prev-state
10844 findpos how &optional extra)
10845 "Set up the post command hook to take a note.
10846 If this is about to TODO state change, the new state is expected in STATE.
10847 When FINDPOS is non-nil, find the correct position for the note in
10848 the current entry. If not, assume that it can be inserted at point.
10849 HOW is an indicator what kind of note should be created.
10850 EXTRA is additional text that will be inserted into the notes buffer."
10851 (let* ((org-log-into-drawer (org-log-into-drawer))
10852 (drawer (cond ((stringp org-log-into-drawer)
10853 org-log-into-drawer)
10854 (org-log-into-drawer "LOGBOOK")
10859 (org-back-to-heading t)
10860 (narrow-to-region (point) (save-excursion
10861 (outline-next-heading) (point)))
10862 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
10863 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
10865 (goto-char (match-end 0))
10868 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
10871 (goto-char (match-end 0))
10872 (or org-log-states-order-reversed
10873 (and (re-search-forward org-property-end-re nil t)
10874 (goto-char (1- (match-beginning 0))))))
10875 (insert "\n:" drawer ":\n:END:")
10876 (beginning-of-line 0)
10877 (org-indent-line-function)
10878 (beginning-of-line 2)
10879 (org-indent-line-function)
10881 ((and org-log-state-notes-insert-after-drawers
10883 (forward-line) (looking-at org-drawer-regexp)))
10885 (while (looking-at org-drawer-regexp)
10886 (goto-char (match-end 0))
10887 (re-search-forward org-property-end-re (point-max) t)
10889 (forward-line -1)))
10890 (unless org-log-states-order-reversed
10891 (and (= (char-after) ?\n) (forward-char 1))
10892 (org-skip-over-state-notes)
10893 (skip-chars-backward " \t\n\r")))
10894 (move-marker org-log-note-marker (point))
10895 (setq org-log-note-purpose purpose
10896 org-log-note-state state
10897 org-log-note-previous-state prev-state
10898 org-log-note-how how
10899 org-log-note-extra extra)
10900 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
10902 (defun org-skip-over-state-notes ()
10903 "Skip past the list of State notes in an entry."
10904 (if (looking-at "\n[ \t]*- State") (forward-char 1))
10905 (while (looking-at "[ \t]*- State")
10906 (condition-case nil
10908 (error (org-end-of-item)))))
10910 (defun org-add-log-note (&optional purpose)
10911 "Pop up a window for taking a note, and add this note later at point."
10912 (remove-hook 'post-command-hook 'org-add-log-note)
10913 (setq org-log-note-window-configuration (current-window-configuration))
10914 (delete-other-windows)
10915 (move-marker org-log-note-return-to (point))
10916 (switch-to-buffer (marker-buffer org-log-note-marker))
10917 (goto-char org-log-note-marker)
10918 (org-switch-to-buffer-other-window "*Org Note*")
10920 (if (memq org-log-note-how '(time state))
10921 (let (current-prefix-arg) (org-store-log-note))
10922 (let ((org-inhibit-startup t)) (org-mode))
10923 (insert (format "# Insert note for %s.
10924 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
10926 ((eq org-log-note-purpose 'clock-out) "stopped clock")
10927 ((eq org-log-note-purpose 'done) "closed todo item")
10928 ((eq org-log-note-purpose 'state)
10929 (format "state change from \"%s\" to \"%s\""
10930 (or org-log-note-previous-state "")
10931 (or org-log-note-state "")))
10932 ((eq org-log-note-purpose 'reschedule)
10934 ((eq org-log-note-purpose 'delschedule)
10935 "no longer scheduled")
10936 ((eq org-log-note-purpose 'redeadline)
10937 "changing deadline")
10938 ((eq org-log-note-purpose 'deldeadline)
10939 "removing deadline")
10940 ((eq org-log-note-purpose 'note)
10942 (t (error "This should not happen")))))
10943 (if org-log-note-extra (insert org-log-note-extra))
10944 (org-set-local 'org-finish-function 'org-store-log-note)))
10946 (defvar org-note-abort nil) ; dynamically scoped
10947 (defun org-store-log-note ()
10948 "Finish taking a log note, and insert it to where it belongs."
10949 (let ((txt (buffer-string))
10950 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
10952 (kill-buffer (current-buffer))
10953 (while (string-match "\\`#.*\n[ \t\n]*" txt)
10954 (setq txt (replace-match "" t t txt)))
10955 (if (string-match "\\s-+\\'" txt)
10956 (setq txt (replace-match "" t t txt)))
10957 (setq lines (org-split-string txt "\n"))
10958 (when (and note (string-match "\\S-" note))
10960 (org-replace-escapes
10962 (list (cons "%u" (user-login-name))
10963 (cons "%U" user-full-name)
10964 (cons "%t" (format-time-string
10965 (org-time-stamp-format 'long 'inactive)
10967 (cons "%s" (if org-log-note-state
10968 (concat "\"" org-log-note-state "\"")
10970 (cons "%S" (if org-log-note-previous-state
10971 (concat "\"" org-log-note-previous-state "\"")
10973 (if lines (setq note (concat note " \\\\")))
10975 (when (or current-prefix-arg org-note-abort)
10976 (when org-log-into-drawer
10977 (org-remove-empty-drawer-at
10978 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
10979 org-log-note-marker))
10982 (with-current-buffer (marker-buffer org-log-note-marker)
10984 (goto-char org-log-note-marker)
10985 (move-marker org-log-note-marker nil)
10987 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
10988 (insert "- " (pop lines))
10989 (org-indent-line-function)
10990 (beginning-of-line 1)
10991 (looking-at "[ \t]*")
10992 (setq ind (concat (match-string 0) " "))
10994 (while lines (insert "\n" ind (pop lines)))
10995 (message "Note stored")
10996 (org-back-to-heading t)
10997 (org-cycle-hide-drawers 'children)))))
10998 (set-window-configuration org-log-note-window-configuration)
10999 (with-current-buffer (marker-buffer org-log-note-return-to)
11000 (goto-char org-log-note-return-to))
11001 (move-marker org-log-note-return-to nil)
11002 (and org-log-post-message (message "%s" org-log-post-message)))
11004 (defun org-remove-empty-drawer-at (drawer pos)
11005 "Remove an empty drawer DRAWER at position POS.
11006 POS may also be a marker."
11007 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11013 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11014 (replace-match ""))))))
11016 (defun org-sparse-tree (&optional arg)
11017 "Create a sparse tree, prompt for the details.
11018 This command can create sparse trees. You first need to select the type
11019 of match used to create the tree:
11021 t Show entries with a specific TODO keyword.
11022 m Show entries selected by a tags/property match.
11023 p Enter a property name and its value (both with completion on existing
11024 names/values) and show entries with that property.
11025 / Show entries matching a regular expression (`r' can be used as well)
11026 d Show deadlines due within `org-deadline-warning-days'.
11027 b Show deadlines and scheduled items before a date.
11028 a Show deadlines and scheduled items after a date."
11030 (let (ans kwd value)
11031 (message "Sparse tree: [/]regexp [t]odo-kwd [m]atch [p]roperty [d]eadlines [b]efore-date [a]fter-date")
11032 (setq ans (read-char-exclusive))
11035 (call-interactively 'org-check-deadlines))
11037 (call-interactively 'org-check-before-date))
11039 (call-interactively 'org-check-after-date))
11041 (org-show-todo-tree '(4)))
11042 ((member ans '(?T ?m))
11043 (call-interactively 'org-match-sparse-tree))
11044 ((member ans '(?p ?P))
11045 (setq kwd (org-icompleting-read "Property: "
11046 (mapcar 'list (org-buffer-property-keys))))
11047 (setq value (org-icompleting-read "Value: "
11048 (mapcar 'list (org-property-values kwd))))
11049 (unless (string-match "\\`{.*}\\'" value)
11050 (setq value (concat "\"" value "\"")))
11051 (org-match-sparse-tree arg (concat kwd "=" value)))
11052 ((member ans '(?r ?R ?/))
11053 (call-interactively 'org-occur))
11054 (t (error "No such sparse tree command \"%c\"" ans)))))
11056 (defvar org-occur-highlights nil
11057 "List of overlays used for occur matches.")
11058 (make-variable-buffer-local 'org-occur-highlights)
11059 (defvar org-occur-parameters nil
11060 "Parameters of the active org-occur calls.
11061 This is a list, each call to org-occur pushes as cons cell,
11062 containing the regular expression and the callback, onto the list.
11063 The list can contain several entries if `org-occur' has been called
11064 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11065 will only contain one set of parameters. When the highlights are
11066 removed (for example with `C-c C-c', or with the next edit (depending
11067 on `org-remove-highlights-with-change'), this variable is emptied
11069 (make-variable-buffer-local 'org-occur-parameters)
11071 (defun org-occur (regexp &optional keep-previous callback)
11072 "Make a compact tree which shows all matches of REGEXP.
11073 The tree will show the lines where the regexp matches, and all higher
11074 headlines above the match. It will also show the heading after the match,
11075 to make sure editing the matching entry is easy.
11076 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11077 call to `org-occur' will be kept, to allow stacking of calls to this
11079 If CALLBACK is non-nil, it is a function which is called to confirm
11080 that the match should indeed be shown."
11081 (interactive "sRegexp: \nP")
11082 (when (equal regexp "")
11083 (error "Regexp cannot be empty"))
11084 (unless keep-previous
11085 (org-remove-occur-highlights nil nil t))
11086 (push (cons regexp callback) org-occur-parameters)
11089 (goto-char (point-min))
11090 (if (or (not keep-previous) ; do not want to keep
11091 (not org-occur-highlights)) ; no previous matches
11094 (while (re-search-forward regexp nil t)
11095 (when (or (not callback)
11096 (save-match-data (funcall callback)))
11097 (setq cnt (1+ cnt))
11098 (when org-highlight-sparse-tree-matches
11099 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11100 (org-show-context 'occur-tree))))
11101 (when org-remove-highlights-with-change
11102 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11104 (unless org-sparse-tree-open-archived-trees
11105 (org-hide-archived-subtrees (point-min) (point-max)))
11106 (run-hooks 'org-occur-hook)
11107 (if (interactive-p)
11108 (message "%d match(es) for regexp %s" cnt regexp))
11111 (defun org-show-context (&optional key)
11112 "Make sure point and context and visible.
11113 How much context is shown depends upon the variables
11114 `org-show-hierarchy-above', `org-show-following-heading'. and
11115 `org-show-siblings'."
11116 (let ((heading-p (org-on-heading-p t))
11117 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11118 (following-p (org-get-alist-option org-show-following-heading key))
11119 (entry-p (org-get-alist-option org-show-entry-below key))
11120 (siblings-p (org-get-alist-option org-show-siblings key)))
11122 ;; Show heading or entry text
11123 (if (and heading-p (not entry-p))
11124 (org-flag-heading nil) ; only show the heading
11125 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11126 (org-show-hidden-entry))) ; show entire entry
11128 ;; Show next sibling, or heading below text
11130 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11131 (org-flag-heading nil))))
11132 (when siblings-p (org-show-siblings))
11134 ;; show all higher headings, possibly with siblings
11136 (while (and (condition-case nil
11137 (progn (org-up-heading-all 1) t)
11140 (org-flag-heading nil)
11141 (when siblings-p (org-show-siblings))))))))
11143 (defun org-reveal (&optional siblings)
11144 "Show current entry, hierarchy above it, and the following headline.
11145 This can be used to show a consistent set of context around locations
11146 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11147 not t for the search context.
11149 With optional argument SIBLINGS, on each level of the hierarchy all
11150 siblings are shown. This repairs the tree structure to what it would
11151 look like when opened with hierarchical calls to `org-cycle'."
11153 (let ((org-show-hierarchy-above t)
11154 (org-show-following-heading t)
11155 (org-show-siblings (if siblings t org-show-siblings)))
11156 (org-show-context nil)))
11158 (defun org-highlight-new-match (beg end)
11159 "Highlight from BEG to END and mark the highlight is an occur headline."
11160 (let ((ov (org-make-overlay beg end)))
11161 (org-overlay-put ov 'face 'secondary-selection)
11162 (push ov org-occur-highlights)))
11164 (defun org-remove-occur-highlights (&optional beg end noremove)
11165 "Remove the occur highlights from the buffer.
11166 BEG and END are ignored. If NOREMOVE is nil, remove this function
11167 from the `before-change-functions' in the current buffer."
11169 (unless org-inhibit-highlight-removal
11170 (mapc 'org-delete-overlay org-occur-highlights)
11171 (setq org-occur-highlights nil)
11172 (setq org-occur-parameters nil)
11174 (remove-hook 'before-change-functions
11175 'org-remove-occur-highlights 'local))))
11179 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11180 "Regular expression matching the priority indicator.")
11182 (defvar org-remove-priority-next-time nil)
11184 (defun org-priority-up ()
11185 "Increase the priority of the current item."
11187 (org-priority 'up))
11189 (defun org-priority-down ()
11190 "Decrease the priority of the current item."
11192 (org-priority 'down))
11194 (defun org-priority (&optional action)
11195 "Change the priority of an item by ARG.
11196 ACTION can be `set', `up', `down', or a character."
11198 (unless org-enable-priority-commands
11199 (error "Priority commands are disabled"))
11200 (setq action (or action 'set))
11201 (let (current new news have remove)
11203 (org-back-to-heading t)
11204 (if (looking-at org-priority-regexp)
11205 (setq current (string-to-char (match-string 2))
11207 (setq current org-default-priority))
11209 ((eq action 'remove)
11210 (setq remove t new ?\ ))
11211 ((or (eq action 'set)
11212 (if (featurep 'xemacs) (characterp action) (integerp action)))
11213 (if (not (eq action 'set))
11215 (message "Priority %c-%c, SPC to remove: "
11216 org-highest-priority org-lowest-priority)
11217 (setq new (read-char-exclusive)))
11218 (if (and (= (upcase org-highest-priority) org-highest-priority)
11219 (= (upcase org-lowest-priority) org-lowest-priority))
11220 (setq new (upcase new)))
11221 (cond ((equal new ?\ ) (setq remove t))
11222 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
11223 (error "Priority must be between `%c' and `%c'"
11224 org-highest-priority org-lowest-priority))))
11226 (if (and (not have) (eq last-command this-command))
11227 (setq new org-lowest-priority)
11228 (setq new (if (and org-priority-start-cycle-with-default (not have))
11229 org-default-priority (1- current)))))
11231 (if (and (not have) (eq last-command this-command))
11232 (setq new org-highest-priority)
11233 (setq new (if (and org-priority-start-cycle-with-default (not have))
11234 org-default-priority (1+ current)))))
11235 (t (error "Invalid action")))
11236 (if (or (< (upcase new) org-highest-priority)
11237 (> (upcase new) org-lowest-priority))
11239 (setq news (format "%c" new))
11242 (replace-match "" t t nil 1)
11243 (replace-match news t t nil 2))
11245 (error "No priority cookie found in line")
11246 (let ((case-fold-search nil))
11247 (looking-at org-todo-line-regexp))
11250 (goto-char (match-end 2))
11251 (insert " [#" news "]"))
11252 (goto-char (match-beginning 3))
11253 (insert "[#" news "] "))))
11254 (org-preserve-lc (org-set-tags nil 'align)))
11256 (message "Priority removed")
11257 (message "Priority of current item set to %s" news))))
11259 (defun org-get-priority (s)
11260 "Find priority cookie and return priority."
11262 (if (not (string-match org-priority-regexp s))
11263 (* 1000 (- org-lowest-priority org-default-priority))
11264 (* 1000 (- org-lowest-priority
11265 (string-to-char (match-string 2 s)))))))
11269 (defvar org-agenda-archives-mode)
11270 (defvar org-map-continue-from nil
11271 "Position from where mapping should continue.
11272 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
11274 (defvar org-scanner-tags nil
11275 "The current tag list while the tags scanner is running.")
11276 (defvar org-trust-scanner-tags nil
11277 "Should `org-get-tags-at' use the tags fro the scanner.
11278 This is for internal dynamical scoping only.
11279 When this is non-nil, the function `org-get-tags-at' will return the value
11280 of `org-scanner-tags' instead of building the list by itself. This
11281 can lead to large speed-ups when the tags scanner is used in a file with
11282 many entries, and when the list of tags is retrieved, for example to
11283 obtain a list of properties. Building the tags list for each entry in such
11284 a file becomes an N^2 operation - but with this variable set, it scales
11287 (defun org-scan-tags (action matcher &optional todo-only)
11288 "Scan headline tags with inheritance and produce output ACTION.
11290 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
11291 or `agenda' to produce an entry list for an agenda view. It can also be
11292 a Lisp form or a function that should be called at each matched headline, in
11293 this case the return value is a list of all return values from these calls.
11295 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
11296 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
11297 only lines with a TODO keyword are included in the output."
11298 (require 'org-agenda)
11299 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
11300 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
11302 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
11303 (props (list 'face 'default
11304 'done-face 'org-agenda-done
11305 'undone-face 'default
11306 'mouse-face 'highlight
11307 'org-not-done-regexp org-not-done-regexp
11308 'org-todo-regexp org-todo-regexp
11310 (format "mouse-2 or RET jump to org file %s"
11311 (abbreviate-file-name
11312 (or (buffer-file-name (buffer-base-buffer))
11313 (buffer-name (buffer-base-buffer)))))))
11314 (case-fold-search nil)
11315 (org-map-continue-from nil)
11316 lspos tags tags-list
11317 (tags-alist (list (cons 0 org-file-tags)))
11318 (llast 0) rtn rtn1 level category i txt
11319 todo marker entry priority)
11320 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
11321 (setq action (list 'lambda nil action)))
11323 (goto-char (point-min))
11324 (when (eq action 'sparse-tree)
11326 (org-remove-occur-highlights))
11327 (while (re-search-forward re nil t)
11329 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
11330 tags (if (match-end 4) (org-match-string-no-properties 4)))
11331 (goto-char (setq lspos (match-beginning 0)))
11332 (setq level (org-reduced-level (funcall outline-level))
11333 category (org-get-category))
11334 (setq i llast llast level)
11335 ;; remove tag lists from same and sublevels
11336 (while (>= i level)
11337 (when (setq entry (assoc i tags-alist))
11338 (setq tags-alist (delete entry tags-alist)))
11340 ;; add the next tags
11342 (setq tags (org-split-string tags ":")
11344 (cons (cons level tags) tags-alist)))
11345 ;; compile tags for current headline
11347 (if org-use-tag-inheritance
11348 (apply 'append (mapcar 'cdr (reverse tags-alist)))
11350 org-scanner-tags tags-list)
11351 (when org-use-tag-inheritance
11352 (setcdr (car tags-alist)
11353 (mapcar (lambda (x)
11354 (setq x (copy-sequence x))
11355 (org-add-prop-inherited x))
11356 (cdar tags-alist))))
11357 (when (and tags org-use-tag-inheritance
11358 (or (not (eq t org-use-tag-inheritance))
11359 org-tags-exclude-from-inheritance))
11360 ;; selective inheritance, remove uninherited ones
11361 (setcdr (car tags-alist)
11362 (org-remove-uniherited-tags (cdar tags-alist))))
11363 (when (and (or (not todo-only)
11364 (and (member todo org-not-done-keywords)
11365 (or (not org-agenda-tags-todo-honor-ignore-options)
11366 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
11367 (let ((case-fold-search t)) (eval matcher))
11369 (not (member org-archive-tag tags-list))
11370 ;; we have an archive tag, should we use this anyway?
11371 (or (not org-agenda-skip-archived-trees)
11372 (and (eq action 'agenda) org-agenda-archives-mode))))
11373 (unless (eq action 'sparse-tree) (org-agenda-skip))
11375 ;; select this headline
11378 ((eq action 'sparse-tree)
11379 (and org-highlight-sparse-tree-matches
11380 (org-get-heading) (match-end 0)
11381 (org-highlight-new-match
11382 (match-beginning 0) (match-beginning 1)))
11383 (org-show-context 'tags-tree))
11384 ((eq action 'agenda)
11385 (setq txt (org-format-agenda-item
11388 (if (eq org-tags-match-list-sublevels 'indented)
11389 (make-string (1- level) ?.) "")
11394 priority (org-get-priority txt))
11396 (setq marker (org-agenda-new-marker))
11397 (org-add-props txt props
11398 'org-marker marker 'org-hd-marker marker 'org-category category
11400 'priority priority 'type "tagsmatch")
11402 ((functionp action)
11403 (setq org-map-continue-from nil)
11405 (setq rtn1 (funcall action))
11407 (t (error "Invalid action")))
11409 ;; if we are to skip sublevels, jump to end of subtree
11410 (unless org-tags-match-list-sublevels
11411 (org-end-of-subtree t)
11412 (backward-char 1))))
11413 ;; Get the correct position from where to continue
11414 (if org-map-continue-from
11415 (goto-char org-map-continue-from)
11416 (and (= (point) lspos) (end-of-line 1)))))
11417 (when (and (eq action 'sparse-tree)
11418 (not org-sparse-tree-open-archived-trees))
11419 (org-hide-archived-subtrees (point-min) (point-max)))
11422 (defun org-remove-uniherited-tags (tags)
11423 "Remove all tags that are not inherited from the list TAGS."
11425 ((eq org-use-tag-inheritance t)
11426 (if org-tags-exclude-from-inheritance
11427 (org-delete-all org-tags-exclude-from-inheritance tags)
11429 ((not org-use-tag-inheritance) nil)
11430 ((stringp org-use-tag-inheritance)
11433 (if (and (string-match org-use-tag-inheritance x)
11434 (not (member x org-tags-exclude-from-inheritance)))
11437 ((listp org-use-tag-inheritance)
11440 (if (member x org-use-tag-inheritance) x nil))
11443 (defvar todo-only) ;; dynamically scoped
11445 (defun org-match-sparse-tree (&optional todo-only match)
11446 "Create a sparse tree according to tags string MATCH.
11447 MATCH can contain positive and negative selection of tags, like
11448 \"+WORK+URGENT-WITHBOSS\".
11449 If optional argument TODO-ONLY is non-nil, only select lines that are
11452 (org-prepare-agenda-buffers (list (current-buffer)))
11453 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
11455 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
11457 (defvar org-cached-props nil)
11458 (defun org-cached-entry-get (pom property)
11459 (if (or (eq t org-use-property-inheritance)
11460 (and (stringp org-use-property-inheritance)
11461 (string-match org-use-property-inheritance property))
11462 (and (listp org-use-property-inheritance)
11463 (member property org-use-property-inheritance)))
11464 ;; Caching is not possible, check it directly
11465 (org-entry-get pom property 'inherit)
11466 ;; Get all properties, so that we can do complicated checks easily
11467 (cdr (assoc property (or org-cached-props
11468 (setq org-cached-props
11469 (org-entry-properties pom)))))))
11471 (defun org-global-tags-completion-table (&optional files)
11472 "Return the list of all tags in all agenda buffer/files."
11479 (set-buffer (find-file-noselect file))
11480 (append (org-get-buffer-tags)
11481 (mapcar (lambda (x) (if (stringp (car-safe x))
11482 (list (car-safe x)) nil))
11484 (if (and files (car files))
11486 (org-agenda-files))))))))
11488 (defun org-make-tags-matcher (match)
11489 "Create the TAGS//TODO matcher form for the selection string MATCH."
11490 ;; todo-only is scoped dynamically into this function, and the function
11491 ;; may change it if the matcher asks for it.
11493 ;; Get a new match request, with completion
11494 (let ((org-last-tags-completion-table
11495 (org-global-tags-completion-table)))
11496 (setq match (org-completing-read-no-i
11497 "Match: " 'org-tags-completion-function nil nil nil
11498 'org-tags-history))))
11500 ;; Parse the string and create a lisp form
11501 (let ((match0 match)
11502 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
11504 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
11505 orterms term orlist re-p str-p level-p level-op time-p
11506 prop-p pn pv po cat-p gv rest)
11507 (if (string-match "/+" match)
11508 ;; match contains also a todo-matching request
11510 (setq tagsmatch (substring match 0 (match-beginning 0))
11511 todomatch (substring match (match-end 0)))
11512 (if (string-match "^!" todomatch)
11513 (setq todo-only t todomatch (substring todomatch 1)))
11514 (if (string-match "^\\s-*$" todomatch)
11515 (setq todomatch nil)))
11516 ;; only matching tags
11517 (setq tagsmatch match todomatch nil))
11519 ;; Make the tags matcher
11520 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
11521 (setq tagsmatcher t)
11522 (setq orterms (org-split-string tagsmatch "|") orlist nil)
11523 (while (setq term (pop orterms))
11524 (while (and (equal (substring term -1) "\\") orterms)
11525 (setq term (concat term "|" (pop orterms)))) ; repair bad split
11526 (while (string-match re term)
11527 (setq rest (substring term (match-end 0))
11528 minus (and (match-end 1)
11529 (equal (match-string 1 term) "-"))
11530 tag (match-string 2 term)
11531 re-p (equal (string-to-char tag) ?{)
11532 level-p (match-end 4)
11533 prop-p (match-end 5)
11535 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
11537 (setq level-op (org-op-to-function (match-string 3 term)))
11538 `(,level-op level ,(string-to-number
11539 (match-string 4 term))))
11541 (setq pn (match-string 5 term)
11542 po (match-string 6 term)
11543 pv (match-string 7 term)
11544 cat-p (equal pn "CATEGORY")
11545 re-p (equal (string-to-char pv) ?{)
11546 str-p (equal (string-to-char pv) ?\")
11547 time-p (save-match-data
11548 (string-match "^\"[[<].*[]>]\"$" pv))
11549 pv (if (or re-p str-p) (substring pv 1 -1) pv))
11550 (if time-p (setq pv (org-matcher-time pv)))
11551 (setq po (org-op-to-function po (if time-p 'time str-p)))
11553 ((equal pn "CATEGORY")
11554 (setq gv '(get-text-property (point) 'org-category)))
11558 (setq gv `(org-cached-entry-get nil ,pn))))
11561 `(not (string-match ,pv (or ,gv "")))
11562 `(string-match ,pv (or ,gv "")))
11564 `(,po (or ,gv "") ,pv)
11565 `(,po (string-to-number (or ,gv ""))
11566 ,(string-to-number pv) ))))
11567 (t `(member ,tag tags-list)))
11568 mm (if minus (list 'not mm) mm)
11570 (push mm tagsmatcher))
11571 (push (if (> (length tagsmatcher) 1)
11572 (cons 'and tagsmatcher)
11575 (setq tagsmatcher nil))
11576 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
11578 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
11579 ;; Make the todo matcher
11580 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
11581 (setq todomatcher t)
11582 (setq orterms (org-split-string todomatch "|") orlist nil)
11583 (while (setq term (pop orterms))
11584 (while (string-match re term)
11585 (setq minus (and (match-end 1)
11586 (equal (match-string 1 term) "-"))
11587 kwd (match-string 2 term)
11588 re-p (equal (string-to-char kwd) ?{)
11589 term (substring term (match-end 0))
11591 `(string-match ,(substring kwd 1 -1) todo)
11592 (list 'equal 'todo kwd))
11593 mm (if minus (list 'not mm) mm))
11594 (push mm todomatcher))
11595 (push (if (> (length todomatcher) 1)
11596 (cons 'and todomatcher)
11599 (setq todomatcher nil))
11600 (setq todomatcher (if (> (length orlist) 1)
11601 (cons 'or orlist) (car orlist))))
11603 ;; Return the string and lisp forms of the matcher
11604 (setq matcher (if todomatcher
11605 (list 'and tagsmatcher todomatcher)
11607 (cons match0 matcher)))
11609 (defun org-op-to-function (op &optional stringp)
11610 "Turn an operator into the appropriate function."
11613 ((equal op "<" ) '(< string< org-time<))
11614 ((equal op ">" ) '(> org-string> org-time>))
11615 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
11616 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
11617 ((member op '("=" "==")) '(= string= org-time=))
11618 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
11619 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
11621 (defun org<> (a b) (not (= a b)))
11622 (defun org-string<= (a b) (or (string= a b) (string< a b)))
11623 (defun org-string>= (a b) (not (string< a b)))
11624 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
11625 (defun org-string<> (a b) (not (string= a b)))
11626 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
11627 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
11628 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
11629 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
11630 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
11631 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
11633 "Convert S to a floating point time.
11634 If S is already a number, just return it. If it is a string, parse
11635 it as a time string and apply `float-time' to it. If S is nil, just return 0."
11639 (condition-case nil
11640 (float-time (apply 'encode-time (org-parse-time-string s)))
11644 (defun org-time-today ()
11645 "Time in seconds today at 0:00.
11646 Returns the float number of seconds since the beginning of the
11647 epoch to the beginning of today (00:00)."
11648 (float-time (apply 'encode-time
11649 (append '(0 0 0) (nthcdr 3 (decode-time))))))
11651 (defun org-matcher-time (s)
11652 "Interpret a time comparison value."
11655 ((string= s "<now>") (float-time))
11656 ((string= s "<today>") (org-time-today))
11657 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
11658 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
11659 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
11660 (+ (org-time-today)
11661 (* (string-to-number (match-string 1 s))
11662 (cdr (assoc (match-string 2 s)
11663 '(("d" . 86400.0) ("w" . 604800.0)
11664 ("m" . 2678400.0) ("y" . 31557600.0)))))))
11667 (defun org-match-any-p (re list)
11668 "Does re match any element of list?"
11669 (setq list (mapcar (lambda (x) (string-match re x)) list))
11672 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
11673 (defvar org-tags-overlay (org-make-overlay 1 1))
11674 (org-detach-overlay org-tags-overlay)
11676 (defun org-get-local-tags-at (&optional pos)
11677 "Get a list of tags defined in the current headline."
11678 (org-get-tags-at pos 'local))
11680 (defun org-get-local-tags ()
11681 "Get a list of tags defined in the current headline."
11682 (org-get-tags-at nil 'local))
11684 (defun org-get-tags-at (&optional pos local)
11685 "Get a list of all headline tags applicable at POS.
11686 POS defaults to point. If tags are inherited, the list contains
11687 the targets in the same sequence as the headlines appear, i.e.
11688 the tags of the current headline come last.
11689 When LOCAL is non-nil, only return tags from the current headline,
11690 ignore inherited ones."
11692 (if (and org-trust-scanner-tags
11693 (or (not pos) (equal pos (point)))
11696 (let (tags ltags lastpos parent)
11700 (goto-char (or pos (point)))
11703 (condition-case nil
11705 (org-back-to-heading t)
11706 (while (not (equal lastpos (point)))
11707 (setq lastpos (point))
11709 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
11710 (setq ltags (org-split-string
11711 (org-match-string-no-properties 1) ":"))
11713 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
11716 (org-remove-uniherited-tags ltags)
11719 (or org-use-tag-inheritance (throw 'done t))
11720 (if local (throw 'done t))
11721 (or (org-up-heading-safe) (error nil))
11724 (append (org-remove-uniherited-tags org-file-tags) tags)))))
11726 (defun org-add-prop-inherited (s)
11727 (add-text-properties 0 (length s) '(inherited t) s)
11730 (defun org-toggle-tag (tag &optional onoff)
11731 "Toggle the tag TAG for the current line.
11732 If ONOFF is `on' or `off', don't toggle but set to this state."
11735 (org-back-to-heading t)
11736 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
11739 (setq current (match-string 1))
11740 (replace-match ""))
11742 (setq current (nreverse (org-split-string current ":")))
11746 (or (member tag current) (push tag current)))
11748 (or (not (member tag current)) (setq current (delete tag current))))
11749 (t (if (member tag current)
11750 (setq current (delete tag current))
11752 (push tag current))))
11756 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
11757 (org-set-tags nil t))
11758 (delete-horizontal-space))
11759 (run-hooks 'org-after-tags-change-hook))
11762 (defun org-align-tags-here (to-col)
11763 ;; Assumes that this is a headline
11764 (let ((pos (point)) (col (current-column)) ncol tags-l p)
11765 (beginning-of-line 1)
11766 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
11767 (< pos (match-beginning 2)))
11769 (setq tags-l (- (match-end 2) (match-beginning 2)))
11770 (goto-char (match-beginning 1))
11772 (delete-region (point) (1+ (match-beginning 2)))
11773 (setq ncol (max (1+ (current-column))
11777 (- (abs to-col) tags-l))))
11779 (insert (make-string (- ncol (current-column)) ?\ ))
11780 (setq ncol (current-column))
11781 (when indent-tabs-mode (tabify p (point-at-eol)))
11782 (org-move-to-column (min ncol col) t))
11785 (defun org-set-tags-command (&optional arg just-align)
11786 "Call the set-tags command for the current entry."
11788 (if (org-on-heading-p)
11789 (org-set-tags arg just-align)
11791 (org-back-to-heading t)
11792 (org-set-tags arg just-align))))
11794 (defun org-set-tags-to (data)
11795 "Set the tags of the current entry to DATA, replacing the current tags.
11796 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
11797 If DATA is nil or the empty string, any tags will be removed."
11798 (interactive "sTags: ")
11802 ((equal data "") "")
11804 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
11807 (concat ":" (mapconcat 'identity data ":") ":"))
11811 (org-back-to-heading t)
11812 (when (looking-at org-complex-heading-regexp)
11815 (goto-char (match-beginning 5))
11817 (delete-region (point) (point-at-eol))
11818 (org-set-tags nil 'align))
11819 (goto-char (point-at-eol))
11821 (org-set-tags nil 'align)))
11822 (beginning-of-line 1)
11823 (if (looking-at ".*?\\([ \t]+\\)$")
11824 (delete-region (match-beginning 1) (match-end 1))))))
11826 (defun org-set-tags (&optional arg just-align)
11827 "Set the tags for the current headline.
11828 With prefix ARG, realign all tags in headings in the current buffer."
11830 (let* ((re (concat "^" outline-regexp))
11831 (current (org-get-tags-string))
11832 (col (current-column))
11833 (org-setting-tags t)
11834 table current-tags inherited-tags ; computed below when needed
11838 (goto-char (point-min))
11839 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
11840 (while (re-search-forward re nil t)
11841 (org-set-tags nil t)
11843 (message "All tags realigned to column %d" org-tags-column))
11845 (setq tags current)
11846 ;; Get a new set of tags from the user
11848 (setq table (append org-tag-persistent-alist
11849 (or org-tag-alist (org-get-buffer-tags))
11850 (and org-complete-tags-always-offer-all-agenda-tags
11851 (org-global-tags-completion-table (org-agenda-files))))
11852 org-last-tags-completion-table table
11853 current-tags (org-split-string current ":")
11854 inherited-tags (nreverse
11855 (nthcdr (length current-tags)
11856 (nreverse (org-get-tags-at))))
11858 (if (or (eq t org-use-fast-tag-selection)
11859 (and org-use-fast-tag-selection
11860 (delq nil (mapcar 'cdr table))))
11861 (org-fast-tag-selection
11862 current-tags inherited-tags table
11863 (if org-fast-tag-selection-include-todo org-todo-key-alist))
11864 (let ((org-add-colon-after-tag-completion t))
11866 (org-without-partial-completion
11867 (org-icompleting-read "Tags: " 'org-tags-completion-function
11868 nil nil current 'org-tags-history)))))))
11869 (while (string-match "[-+&]+" tags)
11870 ;; No boolean logic, just a list
11871 (setq tags (replace-match ":" t t tags))))
11873 (if org-tags-sort-function
11874 (setq tags (mapconcat 'identity
11875 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
11876 org-tags-sort-function) ":")))
11878 (if (string-match "\\`[\t ]*\\'" tags)
11880 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
11881 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
11883 ;; Insert new tags at the correct column
11884 (beginning-of-line 1)
11886 ((and (equal current "") (equal tags "")))
11887 ((re-search-forward
11888 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
11890 (if (equal tags "")
11892 (goto-char (match-beginning 0))
11893 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
11894 (1+ (point)) (point))
11895 c1 (max (1+ c0) (if (> org-tags-column 0)
11897 (- (- org-tags-column) (length tags))))
11898 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
11899 (replace-match rpl t t)
11900 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
11902 (t (error "Tags alignment failed")))
11903 (org-move-to-column col)
11905 (run-hooks 'org-after-tags-change-hook)))))
11907 (defun org-change-tag-in-region (beg end tag off)
11908 "Add or remove TAG for each entry in the region.
11909 This works in the agenda, and also in an org-mode buffer."
11911 (list (region-beginning) (region-end)
11912 (let ((org-last-tags-completion-table
11914 (org-get-buffer-tags)
11915 (org-global-tags-completion-table))))
11916 (org-icompleting-read
11917 "Tag: " 'org-tags-completion-function nil nil nil
11918 'org-tags-history))
11920 (message "[s]et or [r]emove? ")
11921 (equal (read-char-exclusive) ?r))))
11922 (if (fboundp 'deactivate-mark) (deactivate-mark))
11923 (let ((agendap (equal major-mode 'org-agenda-mode))
11924 l1 l2 m buf pos newhead (cnt 0))
11926 (setq l2 (1- (org-current-line)))
11928 (setq l1 (org-current-line))
11929 (loop for l from l1 to l2 do
11931 (setq m (get-text-property (point) 'org-hd-marker))
11932 (when (or (and (org-mode-p) (org-on-heading-p))
11934 (setq buf (if agendap (marker-buffer m) (current-buffer))
11935 pos (if agendap m (point)))
11936 (with-current-buffer buf
11940 (setq cnt (1+ cnt))
11941 (org-toggle-tag tag (if off 'off 'on))
11942 (setq newhead (org-get-heading)))))
11943 (and agendap (org-agenda-change-all-lines newhead m))))
11944 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
11946 (defun org-tags-completion-function (string predicate &optional flag)
11947 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
11948 (confirm (lambda (x) (stringp (car x)))))
11949 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
11950 (setq s1 (match-string 1 string)
11951 s2 (match-string 2 string))
11952 (setq s1 "" s2 string))
11956 (setq rtn (try-completion s2 ctable confirm))
11959 (concat s1 s2 (substring rtn (length s2))
11960 (if (and org-add-colon-after-tag-completion
11961 (assoc rtn ctable))
11966 (all-completions s2 ctable confirm)
11970 (assoc s2 ctable)))
11973 (defun org-fast-tag-insert (kwd tags face &optional end)
11974 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
11975 (insert (format "%-12s" (concat kwd ":"))
11976 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
11979 (defun org-fast-tag-show-exit (flag)
11982 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
11983 (replace-match ""))
11986 (org-move-to-column (- (window-width) 19) t)
11987 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
11989 (defun org-set-current-tags-overlay (current prefix)
11990 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
11991 (if (featurep 'xemacs)
11992 (org-overlay-display org-tags-overlay (concat prefix s)
11993 'secondary-selection)
11994 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
11995 (org-overlay-display org-tags-overlay (concat prefix s)))))
11997 (defvar org-last-tag-selection-key nil)
11998 (defun org-fast-tag-selection (current inherited table &optional todo-table)
11999 "Fast tag selection with single keys.
12000 CURRENT is the current list of tags in the headline, INHERITED is the
12001 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12002 possibly with grouping information. TODO-TABLE is a similar table with
12003 TODO keywords, should these have keys assigned to them.
12004 If the keys are nil, a-z are automatically assigned.
12005 Returns the new tags string, or nil to not change the current settings."
12006 (let* ((fulltable (append table todo-table))
12007 (maxlen (apply 'max (mapcar
12009 (if (stringp (car x)) (string-width (car x)) 0))
12011 (buf (current-buffer))
12012 (expert (eq org-fast-tag-selection-single-key 'expert))
12014 (fwidth (+ maxlen 3 1 3))
12015 (ncol (/ (- (window-width) 4) fwidth))
12018 tg cnt e c char c1 c2 ntable tbl rtn
12019 ov-start ov-end ov-prefix
12020 (exit-after-next org-fast-tag-selection-single-key)
12021 (done-keywords org-done-keywords)
12024 (beginning-of-line 1)
12026 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12027 (setq ov-start (match-beginning 1)
12028 ov-end (match-end 1)
12030 (setq ov-start (1- (point-at-eol))
12031 ov-end (1+ ov-start))
12032 (skip-chars-forward "^\n\r")
12035 (buffer-substring (1- (point)) (point))
12036 (if (> (current-column) org-tags-column)
12038 (make-string (- org-tags-column (current-column)) ?\ ))))))
12039 (org-move-overlay org-tags-overlay ov-start ov-end)
12040 (save-window-excursion
12042 (set-buffer (get-buffer-create " *Org tags*"))
12043 (delete-other-windows)
12044 (split-window-vertically)
12045 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12047 (org-set-local 'org-done-keywords done-keywords)
12048 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12049 (org-fast-tag-insert "Current" current c-face "\n\n")
12050 (org-fast-tag-show-exit exit-after-next)
12051 (org-set-current-tags-overlay current ov-prefix)
12052 (setq tbl fulltable char ?a cnt 0)
12053 (while (setq e (pop tbl))
12055 ((equal (car e) :startgroup)
12056 (push '() groups) (setq ingroup t)
12057 (when (not (= cnt 0))
12060 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12061 ((equal (car e) :endgroup)
12062 (setq ingroup nil cnt 0)
12063 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12064 ((equal e '(:newline))
12065 (when (not (= cnt 0))
12069 (while (equal (car tbl) '(:newline))
12071 (setq tbl (cdr tbl)))))
12073 (setq tg (copy-sequence (car e)) c2 nil)
12076 ;; automatically assign a character.
12077 (setq c1 (string-to-char
12078 (downcase (substring
12079 tg (if (= (string-to-char tg) ?@) 1 0)))))
12080 (if (or (rassoc c1 ntable) (rassoc c1 table))
12081 (while (or (rassoc char ntable) (rassoc char table))
12082 (setq char (1+ char)))
12084 (setq c (or c2 char)))
12085 (if ingroup (push tg (car groups)))
12086 (setq tg (org-add-props tg nil 'face
12088 ((not (assoc tg table))
12089 (org-get-todo-face tg))
12090 ((member tg current) c-face)
12091 ((member tg inherited) i-face)
12093 (if (and (= cnt 0) (not ingroup)) (insert " "))
12094 (insert "[" c "] " tg (make-string
12095 (- fwidth 4 (length tg)) ?\ ))
12096 (push (cons tg c) ntable)
12097 (when (= (setq cnt (1+ cnt)) ncol)
12099 (if ingroup (insert " "))
12101 (setq ntable (nreverse ntable))
12103 (goto-char (point-min))
12104 (if (not expert) (org-fit-window-to-buffer))
12108 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12109 (if (not groups) "no " "")
12110 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12111 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12112 (setq org-last-tag-selection-key c)
12114 ((= c ?\r) (throw 'exit t))
12116 (setq groups (not groups))
12117 (goto-char (point-min))
12118 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12121 (org-fast-tag-show-exit
12122 (setq exit-after-next (not exit-after-next)))
12124 (delete-other-windows)
12125 (split-window-vertically)
12126 (org-switch-to-buffer-other-window " *Org tags*")
12127 (org-fit-window-to-buffer)))
12129 (and (= c ?q) (not (rassoc c ntable))))
12130 (org-detach-overlay org-tags-overlay)
12131 (setq quit-flag t))
12134 (if exit-after-next (setq exit-after-next 'now)))
12136 (condition-case nil
12137 (setq tg (org-icompleting-read
12140 (with-current-buffer buf
12141 (org-get-buffer-tags)))))
12142 (quit (setq tg "")))
12143 (when (string-match "\\S-" tg)
12144 (add-to-list 'buffer-tags (list tg))
12145 (if (member tg current)
12146 (setq current (delete tg current))
12147 (push tg current)))
12148 (if exit-after-next (setq exit-after-next 'now)))
12149 ((setq e (rassoc c todo-table) tg (car e))
12150 (with-current-buffer buf
12151 (save-excursion (org-todo tg)))
12152 (if exit-after-next (setq exit-after-next 'now)))
12153 ((setq e (rassoc c ntable) tg (car e))
12154 (if (member tg current)
12155 (setq current (delete tg current))
12156 (loop for g in groups do
12159 (setq current (delete x current)))
12162 (if exit-after-next (setq exit-after-next 'now))))
12164 ;; Create a sorted list
12168 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12169 (if (eq exit-after-next 'now) (throw 'exit t))
12170 (goto-char (point-min))
12171 (beginning-of-line 2)
12172 (delete-region (point) (point-at-eol))
12173 (org-fast-tag-insert "Current" current c-face)
12174 (org-set-current-tags-overlay current ov-prefix)
12175 (while (re-search-forward
12176 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12177 (setq tg (match-string 1))
12178 (add-text-properties
12179 (match-beginning 1) (match-end 1)
12182 ((member tg current) c-face)
12183 ((member tg inherited) i-face)
12184 (t (get-text-property (match-beginning 1) 'face))))))
12185 (goto-char (point-min)))))
12186 (org-detach-overlay org-tags-overlay)
12188 (mapconcat 'identity current ":")
12191 (defun org-get-tags-string ()
12192 "Get the TAGS string in the current headline."
12193 (unless (org-on-heading-p t)
12194 (error "Not on a heading"))
12196 (beginning-of-line 1)
12197 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12198 (org-match-string-no-properties 1)
12201 (defun org-get-tags ()
12202 "Get the list of tags specified in the current headline."
12203 (org-split-string (org-get-tags-string) ":"))
12205 (defun org-get-buffer-tags ()
12206 "Get a table of all tags used in the buffer, for completion."
12209 (goto-char (point-min))
12210 (while (re-search-forward
12211 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
12212 (when (equal (char-after (point-at-bol 0)) ?*)
12213 (mapc (lambda (x) (add-to-list 'tags x))
12214 (org-split-string (org-match-string-no-properties 1) ":")))))
12215 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
12216 (mapcar 'list tags)))
12218 ;;;; The mapping API
12221 (defun org-map-entries (func &optional match scope &rest skip)
12222 "Call FUNC at each headline selected by MATCH in SCOPE.
12224 FUNC is a function or a lisp form. The function will be called without
12225 arguments, with the cursor positioned at the beginning of the headline.
12226 The return values of all calls to the function will be collected and
12227 returned as a list.
12229 The call to FUNC will be wrapped into a save-excursion form, so FUNC
12230 does not need to preserve point. After evaluation, the cursor will be
12231 moved to the end of the line (presumably of the headline of the
12232 processed entry) and search continues from there. Under some
12233 circumstances, this may not produce the wanted results. For example,
12234 if you have removed (e.g. archived) the current (sub)tree it could
12235 mean that the next entry will be skipped entirely. In such cases, you
12236 can specify the position from where search should continue by making
12237 FUNC set the variable `org-map-continue-from' to the desired buffer
12240 MATCH is a tags/property/todo match as it is used in the agenda tags view.
12241 Only headlines that are matched by this query will be considered during
12242 the iteration. When MATCH is nil or t, all headlines will be
12243 visited by the iteration.
12245 SCOPE determines the scope of this command. It can be any of:
12247 nil The current buffer, respecting the restriction if any
12248 tree The subtree started with the entry at point
12249 file The current buffer, without restriction
12251 The current buffer, and any archives associated with it
12252 agenda All agenda files
12253 agenda-with-archives
12254 All agenda files with any archive files associated with them
12256 If this is a list, all files in the list will be scanned
12258 The remaining args are treated as settings for the skipping facilities of
12259 the scanner. The following items can be given here:
12261 archive skip trees with the archive tag.
12262 comment skip trees with the COMMENT keyword
12263 function or Emacs Lisp form:
12264 will be used as value for `org-agenda-skip-function', so whenever
12265 the function returns t, FUNC will not be called for that
12266 entry and search will continue from the point where the
12267 function leaves it.
12269 If your function needs to retrieve the tags including inherited tags
12270 at the *current* entry, you can use the value of the variable
12271 `org-scanner-tags' which will be much faster than getting the value
12272 with `org-get-tags-at'. If your function gets properties with
12273 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
12274 to t around the call to `org-entry-properties' to get the same speedup.
12275 Note that if your function moves around to retrieve tags and properties at
12276 a *different* entry, you cannot use these techniques."
12277 (let* ((org-agenda-archives-mode nil) ; just to make sure
12278 (org-agenda-skip-archived-trees (memq 'archive skip))
12279 (org-agenda-skip-comment-trees (memq 'comment skip))
12280 (org-agenda-skip-function
12281 (car (org-delete-all '(comment archive) skip)))
12282 (org-tags-match-list-sublevels t)
12284 org-todo-keywords-for-agenda
12285 org-done-keywords-for-agenda
12286 org-todo-keyword-alist-for-agenda
12287 org-drawers-for-agenda
12288 org-tag-alist-for-agenda)
12291 ((eq match t) (setq matcher t))
12292 ((eq match nil) (setq matcher t))
12293 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
12297 (when (eq scope 'tree)
12298 (org-back-to-heading t)
12299 (org-narrow-to-subtree)
12304 (org-prepare-agenda-buffers
12305 (list (buffer-file-name (current-buffer))))
12306 (setq res (org-scan-tags func matcher)))
12307 ;; Get the right scope
12309 ((and scope (listp scope) (symbolp (car scope)))
12310 (setq scope (eval scope)))
12311 ((eq scope 'agenda)
12312 (setq scope (org-agenda-files t)))
12313 ((eq scope 'agenda-with-archives)
12314 (setq scope (org-agenda-files t))
12315 (setq scope (org-add-archive-files scope)))
12317 (setq scope (list (buffer-file-name))))
12318 ((eq scope 'file-with-archives)
12319 (setq scope (org-add-archive-files (list (buffer-file-name))))))
12320 (org-prepare-agenda-buffers scope)
12321 (while (setq file (pop scope))
12322 (with-current-buffer (org-find-base-buffer-visiting file)
12326 (goto-char (point-min))
12327 (setq res (append res (org-scan-tags func matcher))))))))))
12332 ;;; Setting and retrieving properties
12334 (defconst org-special-properties
12335 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
12336 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
12337 "The special properties valid in Org-mode.
12339 These are properties that are not defined in the property drawer,
12340 but in some other way.")
12342 (defconst org-default-properties
12343 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
12344 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
12345 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
12346 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
12347 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER"
12348 "CLOCK_MODELINE_TOTAL" "STYLE")
12349 "Some properties that are used by Org-mode for various purposes.
12350 Being in this list makes sure that they are offered for completion.")
12352 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
12353 "Regular expression matching the first line of a property drawer.")
12355 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
12356 "Regular expression matching the first line of a property drawer.")
12358 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
12359 "Regular expression matching the first line of a property drawer.")
12361 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
12362 "Regular expression matching the first line of a property drawer.")
12364 (defconst org-property-drawer-re
12365 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
12366 org-property-end-re "\\)\n?")
12367 "Matches an entire property drawer.")
12369 (defconst org-clock-drawer-re
12370 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
12371 org-property-end-re "\\)\n?")
12372 "Matches an entire clock drawer.")
12374 (defun org-property-action ()
12375 "Do an action on properties."
12378 (org-at-property-p)
12379 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
12380 (setq c (read-char-exclusive))
12383 (call-interactively 'org-set-property))
12385 (call-interactively 'org-delete-property))
12387 (call-interactively 'org-delete-property-globally))
12389 (call-interactively 'org-compute-property-at-point))
12390 (t (error "No such property action %c" c)))))
12392 (defun org-set-effort (&optional value)
12393 "Set the effort property of the current entry.
12394 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
12397 (if (equal value 0) (setq value 10))
12398 (let* ((completion-ignore-case t)
12399 (prop org-effort-property)
12400 (cur (org-entry-get nil prop))
12401 (allowed (org-property-get-allowed-values nil prop 'table))
12402 (existing (mapcar 'list (org-property-values prop)))
12405 ((stringp value) value)
12406 ((and allowed (integerp value))
12407 (or (car (nth (1- value) allowed))
12408 (car (org-last allowed))))
12410 (message "Select 1-9,0, [RET%s]: %s"
12411 (if cur (concat "=" cur) "")
12412 (mapconcat 'car allowed " "))
12413 (setq rpl (read-char-exclusive))
12414 (if (equal rpl ?\r)
12416 (setq rpl (- rpl ?0))
12417 (if (equal rpl 0) (setq rpl 10))
12418 (if (and (> rpl 0) (<= rpl (length allowed)))
12419 (car (nth (1- rpl) allowed))
12420 (org-completing-read "Effort: " allowed nil))))
12422 (let (org-completion-use-ido org-completion-use-iswitchb)
12423 (org-completing-read
12424 (concat "Effort " (if (and cur (string-match "\\S-" cur))
12425 (concat "[" cur "]") "")
12427 existing nil nil "" nil cur))))))
12428 (unless (equal (org-entry-get nil prop) val)
12429 (org-entry-put nil prop val))
12430 (message "%s is now %s" prop val)))
12432 (defun org-at-property-p ()
12433 "Is the cursor in a property line?"
12434 ;; FIXME: Does not check if we are actually in the drawer.
12435 ;; FIXME: also returns true on any drawers.....
12436 ;; This is used by C-c C-c for property action.
12438 (beginning-of-line 1)
12439 (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))))
12441 (defun org-get-property-block (&optional beg end force)
12442 "Return the (beg . end) range of the body of the property drawer.
12443 BEG and END can be beginning and end of subtree, if not given
12444 they will be found.
12445 If the drawer does not exist and FORCE is non-nil, create the drawer."
12448 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
12449 (end (or end (progn (outline-next-heading) (point)))))
12451 (if (re-search-forward org-property-start-re end t)
12452 (setq beg (1+ (match-end 0)))
12455 (org-insert-property-drawer)
12456 (setq end (progn (outline-next-heading) (point))))
12459 (if (re-search-forward org-property-start-re end t)
12460 (setq beg (1+ (match-end 0)))))
12461 (if (re-search-forward org-property-end-re end t)
12462 (setq end (match-beginning 0))
12463 (or force (throw 'exit nil))
12466 (org-indent-line-function)
12467 (insert ":END:\n"))
12470 (defun org-entry-properties (&optional pom which specific)
12471 "Get all properties of the entry at point-or-marker POM.
12472 This includes the TODO keyword, the tags, time strings for deadline,
12473 scheduled, and clocking, and any additional properties defined in the
12474 entry. The return value is an alist, keys may occur multiple times
12475 if the property key was used several times.
12476 POM may also be nil, in which case the current entry is used.
12477 If WHICH is nil or `all', get all properties. If WHICH is
12478 `special' or `standard', only get that subclass. If WHICH
12479 is a string only get exactly this property. Specific can be a sting, the
12480 specific property we are interested in. Specifying it can speed
12481 things up because then unnecessary parsing is avoided."
12482 (setq which (or which 'all))
12483 (org-with-point-at pom
12484 (let ((clockstr (substring org-clock-string 0 -1))
12485 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY"))
12486 beg end range props sum-props key value string clocksum)
12488 (when (condition-case nil
12489 (and (org-mode-p) (org-back-to-heading t))
12492 (setq sum-props (get-text-property (point) 'org-summaries))
12493 (setq clocksum (get-text-property (point) :org-clock-minutes))
12494 (outline-next-heading)
12496 (when (memq which '(all special))
12497 ;; Get the special properties, like TODO and tags
12499 (when (and (or (not specific) (string= specific "TODO"))
12500 (looking-at org-todo-line-regexp) (match-end 2))
12501 (push (cons "TODO" (org-match-string-no-properties 2)) props))
12502 (when (and (or (not specific) (string= specific "PRIORITY"))
12503 (looking-at org-priority-regexp))
12504 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
12505 (when (and (or (not specific) (string= specific "TAGS"))
12506 (setq value (org-get-tags-string))
12507 (string-match "\\S-" value))
12508 (push (cons "TAGS" value) props))
12509 (when (and (or (not specific) (string= specific "TAGS"))
12510 (setq value (org-get-tags-at)))
12511 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
12514 (when (or (not specific) (string= specific "TAGS"))
12515 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
12516 (when (or (not specific)
12517 (member specific org-all-time-keywords)
12518 (member specific '("TIMESTAMP" "TIMESTAMP_IA")))
12519 (while (re-search-forward org-maybe-keyword-time-regexp end t)
12520 (setq key (if (match-end 1) (substring (org-match-string-no-properties 1) 0 -1))
12521 string (if (equal key clockstr)
12525 (match-beginning 3) (goto-char (point-at-eol)))))
12526 (substring (org-match-string-no-properties 3) 1 -1)))
12528 (if (= (char-after (match-beginning 3)) ?\[)
12529 (setq key "TIMESTAMP_IA")
12530 (setq key "TIMESTAMP")))
12531 (when (or (equal key clockstr) (not (assoc key props)))
12532 (push (cons key string) props))))
12536 (when (memq which '(all standard))
12537 ;; Get the standard properties, like :PROP: ...
12538 (setq range (org-get-property-block beg end))
12540 (goto-char (car range))
12541 (while (re-search-forward
12542 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
12544 (setq key (org-match-string-no-properties 1)
12545 value (org-trim (or (org-match-string-no-properties 2) "")))
12546 (unless (member key excluded)
12547 (push (cons key (or value "")) props)))))
12549 (push (cons "CLOCKSUM"
12550 (org-columns-number-to-string (/ (float clocksum) 60.)
12553 (unless (assoc "CATEGORY" props)
12554 (setq value (or (org-get-category)
12555 (progn (org-refresh-category-properties)
12556 (org-get-category))))
12557 (push (cons "CATEGORY" value) props))
12558 (append sum-props (nreverse props)))))))
12560 (defun org-entry-get (pom property &optional inherit)
12561 "Get value of PROPERTY for entry at point-or-marker POM.
12562 If INHERIT is non-nil and the entry does not have the property,
12563 then also check higher levels of the hierarchy.
12564 If INHERIT is the symbol `selective', use inheritance only if the setting
12565 in `org-use-property-inheritance' selects PROPERTY for inheritance.
12566 If the property is present but empty, the return value is the empty string.
12567 If the property is not present at all, nil is returned."
12568 (org-with-point-at pom
12569 (if (and inherit (if (eq inherit 'selective)
12570 (org-property-inherit-p property)
12572 (org-entry-get-with-inheritance property)
12573 (if (member property org-special-properties)
12574 ;; We need a special property. Use `org-entry-properties' to
12575 ;; retrieve it, but specify the wanted property
12576 (cdr (assoc property (org-entry-properties nil 'special property)))
12577 (let ((range (org-get-property-block)))
12579 (goto-char (car range))
12581 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
12583 ;; Found the property, return it.
12585 (org-match-string-no-properties 1)
12588 (defun org-property-or-variable-value (var &optional inherit)
12589 "Check if there is a property fixing the value of VAR.
12590 If yes, return this value. If not, return the current value of the variable."
12591 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
12592 (if (and prop (stringp prop) (string-match "\\S-" prop))
12594 (symbol-value var))))
12596 (defun org-entry-delete (pom property)
12597 "Delete the property PROPERTY from entry at point-or-marker POM."
12598 (org-with-point-at pom
12599 (if (member property org-special-properties)
12600 nil ; cannot delete these properties.
12601 (let ((range (org-get-property-block)))
12603 (goto-char (car range))
12605 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
12608 (delete-region (match-beginning 0) (1+ (point-at-eol)))
12612 ;; Multi-values properties are properties that contain multiple values
12613 ;; These values are assumed to be single words, separated by whitespace.
12614 (defun org-entry-add-to-multivalued-property (pom property value)
12615 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
12616 (let* ((old (org-entry-get pom property))
12617 (values (and old (org-split-string old "[ \t]"))))
12618 (setq value (org-entry-protect-space value))
12619 (unless (member value values)
12620 (setq values (cons value values))
12621 (org-entry-put pom property
12622 (mapconcat 'identity values " ")))))
12624 (defun org-entry-remove-from-multivalued-property (pom property value)
12625 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
12626 (let* ((old (org-entry-get pom property))
12627 (values (and old (org-split-string old "[ \t]"))))
12628 (setq value (org-entry-protect-space value))
12629 (when (member value values)
12630 (setq values (delete value values))
12631 (org-entry-put pom property
12632 (mapconcat 'identity values " ")))))
12634 (defun org-entry-member-in-multivalued-property (pom property value)
12635 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
12636 (let* ((old (org-entry-get pom property))
12637 (values (and old (org-split-string old "[ \t]"))))
12638 (setq value (org-entry-protect-space value))
12639 (member value values)))
12641 (defun org-entry-get-multivalued-property (pom property)
12642 "Return a list of values in a multivalued property."
12643 (let* ((value (org-entry-get pom property))
12644 (values (and value (org-split-string value "[ \t]"))))
12645 (mapcar 'org-entry-restore-space values)))
12647 (defun org-entry-put-multivalued-property (pom property &rest values)
12648 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
12649 VALUES should be a list of strings. Spaces will be protected."
12650 (org-entry-put pom property
12651 (mapconcat 'org-entry-protect-space values " "))
12652 (let* ((value (org-entry-get pom property))
12653 (values (and value (org-split-string value "[ \t]"))))
12654 (mapcar 'org-entry-restore-space values)))
12656 (defun org-entry-protect-space (s)
12657 "Protect spaces and newline in string S."
12658 (while (string-match " " s)
12659 (setq s (replace-match "%20" t t s)))
12660 (while (string-match "\n" s)
12661 (setq s (replace-match "%0A" t t s)))
12664 (defun org-entry-restore-space (s)
12665 "Restore spaces and newline in string S."
12666 (while (string-match "%20" s)
12667 (setq s (replace-match " " t t s)))
12668 (while (string-match "%0A" s)
12669 (setq s (replace-match "\n" t t s)))
12672 (defvar org-entry-property-inherited-from (make-marker)
12673 "Marker pointing to the entry from where a property was inherited.
12674 Each call to `org-entry-get-with-inheritance' will set this marker to the
12675 location of the entry where the inheritance search matched. If there was
12676 no match, the marker will point nowhere.
12677 Note that also `org-entry-get' calls this function, if the INHERIT flag
12680 (defun org-entry-get-with-inheritance (property)
12681 "Get entry property, and search higher levels if not present."
12682 (move-marker org-entry-property-inherited-from nil)
12689 (when (setq tmp (org-entry-get nil property))
12690 (org-back-to-heading t)
12691 (move-marker org-entry-property-inherited-from (point))
12693 (or (org-up-heading-safe) (throw 'ex nil)))))
12695 (cdr (assoc property org-file-properties))
12696 (cdr (assoc property org-global-properties))
12697 (cdr (assoc property org-global-properties-fixed))))))
12699 (defvar org-property-changed-functions nil
12700 "Hook called when the value of a property has changed.
12701 Each hook function should accept two arguments, the name of the property
12702 and the new value.")
12704 (defun org-entry-put (pom property value)
12705 "Set PROPERTY to VALUE for entry at point-or-marker POM."
12706 (org-with-point-at pom
12707 (org-back-to-heading t)
12708 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
12711 ((equal property "TODO")
12712 (when (and (stringp value) (string-match "\\S-" value)
12713 (not (member value org-todo-keywords-1)))
12714 (error "\"%s\" is not a valid TODO state" value))
12715 (if (or (not value)
12716 (not (string-match "\\S-" value)))
12717 (setq value 'none))
12719 (org-set-tags nil 'align))
12720 ((equal property "PRIORITY")
12721 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
12722 (string-to-char value) ?\ ))
12723 (org-set-tags nil 'align))
12724 ((equal property "SCHEDULED")
12725 (if (re-search-forward org-scheduled-time-regexp end t)
12727 ((eq value 'earlier) (org-timestamp-change -1 'day))
12728 ((eq value 'later) (org-timestamp-change 1 'day))
12729 (t (call-interactively 'org-schedule)))
12730 (call-interactively 'org-schedule)))
12731 ((equal property "DEADLINE")
12732 (if (re-search-forward org-deadline-time-regexp end t)
12734 ((eq value 'earlier) (org-timestamp-change -1 'day))
12735 ((eq value 'later) (org-timestamp-change 1 'day))
12736 (t (call-interactively 'org-deadline)))
12737 (call-interactively 'org-deadline)))
12738 ((member property org-special-properties)
12739 (error "The %s property can not yet be set with `org-entry-put'"
12741 (t ; a non-special property
12742 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
12743 (setq range (org-get-property-block beg end 'force))
12744 (goto-char (car range))
12745 (if (re-search-forward
12746 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
12748 (delete-region (match-beginning 1) (match-end 1))
12749 (goto-char (match-beginning 1)))
12750 (goto-char (cdr range))
12753 (org-indent-line-function)
12754 (insert ":" property ":"))
12755 (and value (insert " " value))
12756 (org-indent-line-function)))))
12757 (run-hook-with-args 'org-property-changed-functions property value)))
12759 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
12760 "Get all property keys in the current buffer.
12761 With INCLUDE-SPECIALS, also list the special properties that reflect things
12762 like tags and TODO state.
12763 With INCLUDE-DEFAULTS, also include properties that has special meaning
12764 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
12765 With INCLUDE-COLUMNS, also include property names given in COLUMN
12766 formats in the current buffer."
12767 (let (rtn range cfmt s p)
12771 (goto-char (point-min))
12772 (while (re-search-forward org-property-start-re nil t)
12773 (setq range (org-get-property-block))
12774 (goto-char (car range))
12775 (while (re-search-forward
12776 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
12778 (add-to-list 'rtn (org-match-string-no-properties 1)))
12779 (outline-next-heading))))
12781 (when include-specials
12782 (setq rtn (append org-special-properties rtn)))
12784 (when include-defaults
12785 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
12786 (add-to-list 'rtn org-effort-property))
12788 (when include-columns
12792 (goto-char (point-min))
12793 (while (re-search-forward
12794 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
12796 (setq cfmt (match-string 2) s 0)
12797 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
12799 (setq s (match-end 0)
12800 p (match-string 1 cfmt))
12801 (unless (or (equal p "ITEM")
12802 (member p org-special-properties))
12803 (add-to-list 'rtn (match-string 1 cfmt))))))))
12805 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
12807 (defun org-property-values (key)
12808 "Return a list of all values of property KEY."
12812 (goto-char (point-min))
12813 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
12815 (while (re-search-forward re nil t)
12816 (add-to-list 'values (org-trim (match-string 1))))
12817 (delete "" values)))))
12819 (defun org-insert-property-drawer ()
12820 "Insert a property drawer into the current entry."
12822 (org-back-to-heading t)
12823 (looking-at outline-regexp)
12824 (let ((indent (if org-adapt-indentation
12825 (- (match-end 0)(match-beginning 0))
12828 (re (concat "^[ \t]*" org-keyword-time-regexp))
12830 (outline-next-heading)
12833 (while (re-search-forward re end t))
12834 (setq hiddenp (org-invisible-p))
12836 (and (equal (char-after) ?\n) (forward-char 1))
12837 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
12838 (if (member (match-string 1) '("CLOCK:" ":END:"))
12839 ;; just skip this line
12840 (beginning-of-line 2)
12841 ;; Drawer start, find the end
12842 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
12843 (beginning-of-line 1)))
12844 (org-skip-over-state-notes)
12845 (skip-chars-backward " \t\n\r")
12846 (if (eq (char-before) ?*) (forward-char 1))
12847 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
12848 (beginning-of-line 0)
12849 (org-indent-to-column indent)
12850 (beginning-of-line 2)
12851 (org-indent-to-column indent)
12852 (beginning-of-line 0)
12855 (org-back-to-heading t)
12857 (org-flag-drawer t))))
12859 (defun org-set-property (property value)
12860 "In the current entry, set PROPERTY to VALUE.
12861 When called interactively, this will prompt for a property name, offering
12862 completion on existing and default properties. And then it will prompt
12863 for a value, offering completion either on allowed values (via an inherited
12864 xxx_ALL property) or on existing values in other instances of this property
12865 in the current file."
12867 (let* ((completion-ignore-case t)
12868 (keys (org-buffer-property-keys nil t t))
12869 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
12870 (prop (if (member prop0 keys)
12872 (or (cdr (assoc (downcase prop0)
12873 (mapcar (lambda (x) (cons (downcase x) x))
12876 (cur (org-entry-get nil prop))
12877 (allowed (org-property-get-allowed-values nil prop 'table))
12878 (existing (mapcar 'list (org-property-values prop)))
12880 (org-completing-read "Value: " allowed nil
12881 (not (get-text-property 0 'org-unrestricted
12883 (let (org-completion-use-ido org-completion-use-iswitchb)
12884 (org-completing-read
12885 (concat "Value " (if (and cur (string-match "\\S-" cur))
12886 (concat "[" cur "]") "")
12888 existing nil nil "" nil cur)))))
12889 (list prop (if (equal val "") cur val))))
12890 (unless (equal (org-entry-get nil property) value)
12891 (org-entry-put nil property value)))
12893 (defun org-delete-property (property)
12894 "In the current entry, delete PROPERTY."
12896 (let* ((completion-ignore-case t)
12897 (prop (org-icompleting-read
12898 "Property: " (org-entry-properties nil 'standard))))
12900 (message "Property %s %s" property
12901 (if (org-entry-delete nil property)
12903 "was not present in the entry")))
12905 (defun org-delete-property-globally (property)
12906 "Remove PROPERTY globally, from all entries."
12908 (let* ((completion-ignore-case t)
12909 (prop (org-icompleting-read
12910 "Globally remove property: "
12911 (mapcar 'list (org-buffer-property-keys)))))
12916 (goto-char (point-min))
12918 (while (re-search-forward
12919 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
12921 (setq cnt (1+ cnt))
12922 (replace-match ""))
12923 (message "Property \"%s\" removed from %d entries" property cnt)))))
12925 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
12927 (defun org-compute-property-at-point ()
12928 "Compute the property at point.
12929 This looks for an enclosing column format, extracts the operator and
12930 then applies it to the property in the column format's scope."
12932 (unless (org-at-property-p)
12933 (error "Not at a property"))
12934 (let ((prop (org-match-string-no-properties 2)))
12935 (org-columns-get-format-and-top-level)
12936 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
12937 (error "No operator defined for property %s" prop))
12938 (org-columns-compute prop)))
12940 (defvar org-property-allowed-value-functions nil
12941 "Hook for functions supplying allowed values for specific.
12942 The functions must take a single argument, the name of the property, and
12943 return a flat list of allowed values. If \":ETC\" is one of
12944 the values, this means that these values are intended as defaults for
12945 completion, but that other values should be allowed too.
12946 The functions must return nil if they are now responsible for this
12949 (defun org-property-get-allowed-values (pom property &optional table)
12950 "Get allowed values for the property PROPERTY.
12951 When TABLE is non-nil, return an alist that can directly be used for
12955 ((equal property "TODO")
12956 (setq vals (org-with-point-at pom
12957 (append org-todo-keywords-1 '("")))))
12958 ((equal property "PRIORITY")
12959 (let ((n org-lowest-priority))
12960 (while (>= n org-highest-priority)
12961 (push (char-to-string n) vals)
12963 ((member property org-special-properties))
12964 ((setq vals (run-hook-with-args-until-success
12965 'org-property-allowed-value-functions property)))
12967 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
12968 (when (and vals (string-match "\\S-" vals))
12969 (setq vals (car (read-from-string (concat "(" vals ")"))))
12970 (setq vals (mapcar (lambda (x)
12971 (cond ((stringp x) x)
12972 ((numberp x) (number-to-string x))
12973 ((symbolp x) (symbol-name x))
12976 (when (member ":ETC" vals)
12977 (setq vals (remove ":ETC" vals))
12978 (org-add-props (car vals) '(org-unrestricted t)))
12979 (if table (mapcar 'list vals) vals)))
12981 (defun org-property-previous-allowed-value (&optional previous)
12982 "Switch to the next allowed value for this property."
12984 (org-property-next-allowed-value t))
12986 (defun org-property-next-allowed-value (&optional previous)
12987 "Switch to the next allowed value for this property."
12989 (unless (org-at-property-p)
12990 (error "Not at a property"))
12991 (let* ((key (match-string 2))
12992 (value (match-string 3))
12993 (allowed (or (org-property-get-allowed-values (point) key)
12994 (and (member value '("[ ]" "[-]" "[X]"))
12998 (error "Allowed values for this property have not been defined"))
12999 (if previous (setq allowed (reverse allowed)))
13000 (if (member value allowed)
13001 (setq nval (car (cdr (member value allowed)))))
13002 (setq nval (or nval (car allowed)))
13003 (if (equal nval value)
13004 (error "Only one allowed value for this property"))
13005 (org-at-property-p)
13006 (replace-match (concat " :" key ": " nval) t t)
13007 (org-indent-line-function)
13008 (beginning-of-line 1)
13009 (skip-chars-forward " \t")
13010 (run-hook-with-args 'org-property-changed-functions key nval)))
13012 (defun org-find-entry-with-id (ident)
13013 "Locate the entry that contains the ID property with exact value IDENT.
13014 IDENT can be a string, a symbol or a number, this function will search for
13015 the string representation of it.
13016 Return the position where this entry starts, or nil if there is no such entry."
13017 (interactive "sID: ")
13019 ((stringp ident) ident)
13020 ((symbol-name ident) (symbol-name ident))
13021 ((numberp ident) (number-to-string ident))
13022 (t (error "IDENT %s must be a string, symbol or number" ident))))
13023 (case-fold-search nil))
13027 (goto-char (point-min))
13028 (when (re-search-forward
13029 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13031 (org-back-to-heading t)
13036 (defvar org-last-changed-timestamp nil)
13037 (defvar org-last-inserted-timestamp nil
13038 "The last time stamp inserted with `org-insert-time-stamp'.")
13039 (defvar org-time-was-given) ; dynamically scoped parameter
13040 (defvar org-end-time-was-given) ; dynamically scoped parameter
13041 (defvar org-ts-what) ; dynamically scoped parameter
13043 (defun org-time-stamp (arg &optional inactive)
13044 "Prompt for a date/time and insert a time stamp.
13045 If the user specifies a time like HH:MM, or if this command is called
13046 with a prefix argument, the time stamp will contain date and time.
13047 Otherwise, only the date will be included. All parts of a date not
13048 specified by the user will be filled in from the current date/time.
13049 So if you press just return without typing anything, the time stamp
13050 will represent the current date/time. If there is already a timestamp
13051 at the cursor, it will be modified."
13055 ;; Default time is either today, or, when entering a range,
13056 ;; the range start.
13057 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13059 (re-search-backward
13060 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13061 (- (point) 20) t)))
13062 (apply 'encode-time (org-parse-time-string (match-string 1)))
13064 (default-input (and ts (org-get-compact-tod ts)))
13065 org-time-was-given org-end-time-was-given time)
13067 ((and (org-at-timestamp-p t)
13068 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13069 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13071 (setq time (let ((this-command this-command))
13072 (org-read-date arg 'totime nil nil
13073 default-time default-input)))
13074 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13075 ((org-at-timestamp-p t)
13076 (setq time (let ((this-command this-command))
13077 (org-read-date arg 'totime nil nil default-time default-input)))
13078 (when (org-at-timestamp-p t) ; just to get the match data
13079 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13081 (setq org-last-changed-timestamp
13082 (org-insert-time-stamp
13083 time (or org-time-was-given arg)
13084 inactive nil nil (list org-end-time-was-given))))
13085 (message "Timestamp updated"))
13087 (setq time (let ((this-command this-command))
13088 (org-read-date arg 'totime nil nil default-time default-input)))
13089 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13090 nil nil (list org-end-time-was-given))))))
13092 ;; FIXME: can we use this for something else, like computing time differences?
13093 (defun org-get-compact-tod (s)
13094 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13095 (let* ((t1 (match-string 1 s))
13096 (h1 (string-to-number (match-string 2 s)))
13097 (m1 (string-to-number (match-string 3 s)))
13098 (t2 (and (match-end 4) (match-string 5 s)))
13099 (h2 (and t2 (string-to-number (match-string 6 s))))
13100 (m2 (and t2 (string-to-number (match-string 7 s))))
13104 (setq dh (- h2 h1) dm (- m2 m1))
13105 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13106 (concat t1 "+" (number-to-string dh)
13107 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13109 (defun org-time-stamp-inactive (&optional arg)
13110 "Insert an inactive time stamp.
13111 An inactive time stamp is enclosed in square brackets instead of angle
13112 brackets. It is inactive in the sense that it does not trigger agenda entries,
13113 does not link to the calendar and cannot be changed with the S-cursor keys.
13114 So these are more for recording a certain time/date."
13116 (org-time-stamp arg 'inactive))
13118 (defvar org-date-ovl (org-make-overlay 1 1))
13119 (org-overlay-put org-date-ovl 'face 'org-warning)
13120 (org-detach-overlay org-date-ovl)
13122 (defvar org-ans1) ; dynamically scoped parameter
13123 (defvar org-ans2) ; dynamically scoped parameter
13125 (defvar org-plain-time-of-day-regexp) ; defined below
13127 (defvar org-overriding-default-time nil) ; dynamically scoped
13128 (defvar org-read-date-overlay nil)
13129 (defvar org-dcst nil) ; dynamically scoped
13130 (defvar org-read-date-history nil)
13131 (defvar org-read-date-final-answer nil)
13133 (defun org-read-date (&optional with-time to-time from-string prompt
13134 default-time default-input)
13135 "Read a date, possibly a time, and make things smooth for the user.
13136 The prompt will suggest to enter an ISO date, but you can also enter anything
13137 which will at least partially be understood by `parse-time-string'.
13138 Unrecognized parts of the date will default to the current day, month, year,
13139 hour and minute. If this command is called to replace a timestamp at point,
13140 of to enter the second timestamp of a range, the default time is taken from the
13141 existing stamp. For example,
13142 3-2-5 --> 2003-02-05
13143 feb 15 --> currentyear-02-15
13144 sep 12 9 --> 2009-09-12
13145 12:45 --> today 12:45
13146 22 sept 0:34 --> currentyear-09-22 0:34
13147 12 --> currentyear-currentmonth-12
13148 Fri --> nearest Friday (today or later)
13151 Furthermore you can specify a relative date by giving, as the *first* thing
13152 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
13153 change in days weeks, months, years.
13154 With a single plus or minus, the date is relative to today. With a double
13155 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
13156 +4d --> four days from today
13157 +4 --> same as above
13158 +2w --> two weeks from today
13159 ++5 --> five days from default date
13161 The function understands only English month and weekday abbreviations,
13162 but this can be configured with the variables `parse-time-months' and
13163 `parse-time-weekdays'.
13165 While prompting, a calendar is popped up - you can also select the
13166 date with the mouse (button 1). The calendar shows a period of three
13167 months. To scroll it to other months, use the keys `>' and `<'.
13168 If you don't like the calendar, turn it off with
13169 \(setq org-read-date-popup-calendar nil)
13171 With optional argument TO-TIME, the date will immediately be converted
13172 to an internal time.
13173 With an optional argument WITH-TIME, the prompt will suggest to also
13174 insert a time. Note that when WITH-TIME is not set, you can still
13175 enter a time, and this function will inform the calling routine about
13176 this change. The calling routine may then choose to change the format
13177 used to insert the time stamp into the buffer to include the time.
13178 With optional argument FROM-STRING, read from this string instead from
13179 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
13180 the time/date that is used for everything that is not specified by the
13182 (require 'parse-time)
13183 (let* ((org-time-stamp-rounding-minutes
13184 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
13185 (org-dcst org-display-custom-times)
13186 (ct (org-current-time))
13187 (def (or org-overriding-default-time default-time ct))
13188 (defdecode (decode-time def))
13190 (when (< (nth 2 defdecode) org-extend-today-until)
13191 (setcar (nthcdr 2 defdecode) -1)
13192 (setcar (nthcdr 1 defdecode) 59)
13193 (setq def (apply 'encode-time defdecode)
13194 defdecode (decode-time def)))))
13195 (calendar-frame-setup nil)
13196 (calendar-move-hook nil)
13197 (calendar-view-diary-initially-flag nil)
13198 (view-diary-entries-initially nil)
13199 (calendar-view-holidays-initially-flag nil)
13200 (view-calendar-holidays-initially nil)
13201 (timestr (format-time-string
13202 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
13203 (prompt (concat (if prompt (concat prompt " ") "")
13204 (format "Date+time [%s]: " timestr)))
13205 ans (org-ans0 "") org-ans1 org-ans2 final)
13208 (from-string (setq ans from-string))
13209 (org-read-date-popup-calendar
13211 (save-window-excursion
13213 (calendar-forward-day (- (time-to-days def)
13214 (calendar-absolute-from-gregorian
13215 (calendar-current-date))))
13216 (org-eval-in-calendar nil t)
13217 (let* ((old-map (current-local-map))
13218 (map (copy-keymap calendar-mode-map))
13219 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
13220 (org-defkey map (kbd "RET") 'org-calendar-select)
13221 (org-defkey map (if (featurep 'xemacs) [button1] [mouse-1])
13222 'org-calendar-select-mouse)
13223 (org-defkey map (if (featurep 'xemacs) [button2] [mouse-2
])
13224 'org-calendar-select-mouse
)
13225 (org-defkey minibuffer-local-map
[(meta shift left
)]
13226 (lambda () (interactive)
13227 (org-eval-in-calendar '(calendar-backward-month 1))))
13228 (org-defkey minibuffer-local-map
[(meta shift right
)]
13229 (lambda () (interactive)
13230 (org-eval-in-calendar '(calendar-forward-month 1))))
13231 (org-defkey minibuffer-local-map
[(meta shift up
)]
13232 (lambda () (interactive)
13233 (org-eval-in-calendar '(calendar-backward-year 1))))
13234 (org-defkey minibuffer-local-map
[(meta shift down
)]
13235 (lambda () (interactive)
13236 (org-eval-in-calendar '(calendar-forward-year 1))))
13237 (org-defkey minibuffer-local-map
[?\e
(shift left
)]
13238 (lambda () (interactive)
13239 (org-eval-in-calendar '(calendar-backward-month 1))))
13240 (org-defkey minibuffer-local-map
[?\e
(shift right
)]
13241 (lambda () (interactive)
13242 (org-eval-in-calendar '(calendar-forward-month 1))))
13243 (org-defkey minibuffer-local-map
[?\e
(shift up
)]
13244 (lambda () (interactive)
13245 (org-eval-in-calendar '(calendar-backward-year 1))))
13246 (org-defkey minibuffer-local-map
[?\e
(shift down
)]
13247 (lambda () (interactive)
13248 (org-eval-in-calendar '(calendar-forward-year 1))))
13249 (org-defkey minibuffer-local-map
[(shift up
)]
13250 (lambda () (interactive)
13251 (org-eval-in-calendar '(calendar-backward-week 1))))
13252 (org-defkey minibuffer-local-map
[(shift down
)]
13253 (lambda () (interactive)
13254 (org-eval-in-calendar '(calendar-forward-week 1))))
13255 (org-defkey minibuffer-local-map
[(shift left
)]
13256 (lambda () (interactive)
13257 (org-eval-in-calendar '(calendar-backward-day 1))))
13258 (org-defkey minibuffer-local-map
[(shift right
)]
13259 (lambda () (interactive)
13260 (org-eval-in-calendar '(calendar-forward-day 1))))
13261 (org-defkey minibuffer-local-map
">"
13262 (lambda () (interactive)
13263 (org-eval-in-calendar '(scroll-calendar-left 1))))
13264 (org-defkey minibuffer-local-map
"<"
13265 (lambda () (interactive)
13266 (org-eval-in-calendar '(scroll-calendar-right 1))))
13267 (run-hooks 'org-read-date-minibuffer-setup-hook
)
13270 (use-local-map map
)
13271 (add-hook 'post-command-hook
'org-read-date-display
)
13272 (setq org-ans0
(read-string prompt default-input
13273 'org-read-date-history nil
))
13274 ;; org-ans0: from prompt
13275 ;; org-ans1: from mouse click
13276 ;; org-ans2: from calendar motion
13277 (setq ans
(concat org-ans0
" " (or org-ans1 org-ans2
))))
13278 (remove-hook 'post-command-hook
'org-read-date-display
)
13279 (use-local-map old-map
)
13280 (when org-read-date-overlay
13281 (org-delete-overlay org-read-date-overlay
)
13282 (setq org-read-date-overlay nil
)))))))
13284 (t ; Naked prompt only
13286 (setq ans
(read-string prompt default-input
13287 'org-read-date-history timestr
))
13288 (when org-read-date-overlay
13289 (org-delete-overlay org-read-date-overlay
)
13290 (setq org-read-date-overlay nil
)))))
13292 (setq final
(org-read-date-analyze ans def defdecode
))
13293 (setq org-read-date-final-answer ans
)
13296 (apply 'encode-time final
)
13297 (if (and (boundp 'org-time-was-given
) org-time-was-given
)
13298 (format "%04d-%02d-%02d %02d:%02d"
13299 (nth 5 final
) (nth 4 final
) (nth 3 final
)
13300 (nth 2 final
) (nth 1 final
))
13301 (format "%04d-%02d-%02d" (nth 5 final
) (nth 4 final
) (nth 3 final
))))))
13306 (defvar org-read-date-analyze-futurep nil
)
13307 (defun org-read-date-display ()
13308 "Display the current date prompt interpretation in the minibuffer."
13309 (when org-read-date-display-live
13310 (when org-read-date-overlay
13311 (org-delete-overlay org-read-date-overlay
))
13314 (while (not (equal (buffer-substring
13315 (max (point-min) (- (point) 4)) (point))
13319 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
13320 " " (or org-ans1 org-ans2
)))
13321 (org-end-time-was-given nil
)
13322 (f (org-read-date-analyze ans def defdecode
))
13324 org-time-stamp-custom-formats
13325 org-time-stamp-formats
))
13326 (fmt (if (or with-time
13327 (and (boundp 'org-time-was-given
) org-time-was-given
))
13330 (txt (concat "=> " (format-time-string fmt
(apply 'encode-time f
)))))
13331 (when (and org-end-time-was-given
13332 (string-match org-plain-time-of-day-regexp txt
))
13333 (setq txt
(concat (substring txt
0 (match-end 0)) "-"
13334 org-end-time-was-given
13335 (substring txt
(match-end 0)))))
13336 (when org-read-date-analyze-futurep
13337 (setq txt
(concat txt
" (=>F)")))
13338 (setq org-read-date-overlay
13339 (org-make-overlay (1- (point-at-eol)) (point-at-eol)))
13340 (org-overlay-display org-read-date-overlay txt
'secondary-selection
))))
13342 (defun org-read-date-analyze (ans def defdecode
)
13343 "Analyse the combined answer of the date prompt."
13344 ;; FIXME: cleanup and comment
13345 (let ((nowdecode (decode-time (current-time)))
13346 delta deltan deltaw deltadef year month day
13347 hour minute second wday pm h2 m2 tl wday1
13348 iso-year iso-weekday iso-week iso-year iso-date futurep
)
13349 (setq org-read-date-analyze-futurep nil
)
13350 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans
)
13353 (when (setq delta
(org-read-date-get-relative ans
(current-time) def
))
13354 (setq ans
(replace-match "" t t ans
)
13356 deltaw
(nth 1 delta
)
13357 deltadef
(nth 2 delta
)))
13359 ;; Check if there is an iso week date in there
13360 ;; If yes, store the info and postpone interpreting it until the rest
13361 ;; of the parsing is done
13362 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans
)
13363 (setq iso-year
(if (match-end 1) (org-small-year-to-year (string-to-number (match-string 1 ans
))))
13364 iso-weekday
(if (match-end 3) (string-to-number (match-string 3 ans
)))
13365 iso-week
(string-to-number (match-string 2 ans
)))
13366 (setq ans
(replace-match "" t t ans
)))
13368 ;; Help matching ISO dates with single digit month ot day, like 2006-8-11.
13369 (when (string-match
13370 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans
)
13371 (setq year
(if (match-end 2)
13372 (string-to-number (match-string 2 ans
))
13373 (string-to-number (format-time-string "%Y")))
13374 month
(string-to-number (match-string 3 ans
))
13375 day
(string-to-number (match-string 4 ans
)))
13376 (if (< year
100) (setq year
(+ 2000 year
)))
13377 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
13379 ;; Help matching am/pm times, because `parse-time-string' does not do that.
13380 ;; If there is a time with am/pm, and *no* time without it, we convert
13381 ;; so that matching will be successful.
13382 (loop for i from
1 to
2 do
; twice, for end time as well
13383 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans
))
13384 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans
))
13385 (setq hour
(string-to-number (match-string 1 ans
))
13386 minute
(if (match-end 3)
13387 (string-to-number (match-string 3 ans
))
13390 (string-to-char (downcase (match-string 4 ans
)))))
13391 (if (and (= hour
12) (not pm
))
13393 (if (and pm
(< hour
12)) (setq hour
(+ 12 hour
))))
13394 (setq ans
(replace-match (format "%02d:%02d" hour minute
)
13397 ;; Check if a time range is given as a duration
13398 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans
)
13399 (setq hour
(string-to-number (match-string 1 ans
))
13400 h2
(+ hour
(string-to-number (match-string 3 ans
)))
13401 minute
(string-to-number (match-string 2 ans
))
13402 m2
(+ minute
(if (match-end 5) (string-to-number
13403 (match-string 5 ans
))0)))
13404 (if (>= m2
60) (setq h2
(1+ h2
) m2
(- m2
60)))
13405 (setq ans
(replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2
)
13408 ;; Check if there is a time range
13409 (when (boundp 'org-end-time-was-given
)
13410 (setq org-time-was-given nil
)
13411 (when (and (string-match org-plain-time-of-day-regexp ans
)
13413 (setq org-end-time-was-given
(match-string 8 ans
))
13414 (setq ans
(concat (substring ans
0 (match-beginning 7))
13415 (substring ans
(match-end 7))))))
13417 (setq tl
(parse-time-string ans
)
13418 day
(or (nth 3 tl
) (nth 3 defdecode
))
13419 month
(or (nth 4 tl
)
13420 (if (and org-read-date-prefer-future
13421 (nth 3 tl
) (< (nth 3 tl
) (nth 3 nowdecode
)))
13422 (prog1 (1+ (nth 4 nowdecode
)) (setq futurep t
))
13423 (nth 4 defdecode
)))
13424 year
(or (nth 5 tl
)
13425 (if (and org-read-date-prefer-future
13426 (nth 4 tl
) (< (nth 4 tl
) (nth 4 nowdecode
)))
13427 (prog1 (1+ (nth 5 nowdecode
)) (setq futurep t
))
13428 (nth 5 defdecode
)))
13429 hour
(or (nth 2 tl
) (nth 2 defdecode
))
13430 minute
(or (nth 1 tl
) (nth 1 defdecode
))
13431 second
(or (nth 0 tl
) 0)
13434 (when (and (eq org-read-date-prefer-future
'time
)
13435 (not (nth 3 tl
)) (not (nth 4 tl
)) (not (nth 5 tl
))
13436 (equal day
(nth 3 nowdecode
))
13437 (equal month
(nth 4 nowdecode
))
13438 (equal year
(nth 5 nowdecode
))
13440 (or (< (nth 2 tl
) (nth 2 nowdecode
))
13441 (and (= (nth 2 tl
) (nth 2 nowdecode
))
13443 (< (nth 1 tl
) (nth 1 nowdecode
)))))
13447 ;; Special date definitions below
13450 ;; There was an iso week
13452 (setq year
(or iso-year year
)
13453 day
(or iso-weekday wday
1)
13454 wday nil
; to make sure that the trigger below does not match
13455 iso-date
(calendar-gregorian-from-absolute
13456 (calendar-absolute-from-iso
13457 (list iso-week day year
))))
13458 ; FIXME: Should we also push ISO weeks into the future?
13459 ; (when (and org-read-date-prefer-future
13461 ; (< (calendar-absolute-from-gregorian iso-date)
13462 ; (time-to-days (current-time))))
13463 ; (setq year (1+ year)
13464 ; iso-date (calendar-gregorian-from-absolute
13465 ; (calendar-absolute-from-iso
13466 ; (list iso-week day year)))))
13467 (setq month
(car iso-date
)
13468 year
(nth 2 iso-date
)
13469 day
(nth 1 iso-date
)))
13473 (let ((now (decode-time (current-time))))
13474 (setq day
(nth 3 now
) month
(nth 4 now
) year
(nth 5 now
))))
13475 (cond ((member deltaw
'("d" "")) (setq day
(+ day deltan
)))
13476 ((equal deltaw
"w") (setq day
(+ day
(* 7 deltan
))))
13477 ((equal deltaw
"m") (setq month
(+ month deltan
)))
13478 ((equal deltaw
"y") (setq year
(+ year deltan
)))))
13479 ((and wday
(not (nth 3 tl
)))
13481 ;; Weekday was given, but no day, so pick that day in the week
13482 ;; on or after the derived date.
13483 (setq wday1
(nth 6 (decode-time (encode-time 0 0 0 day month year
))))
13484 (unless (equal wday wday1
)
13485 (setq day
(+ day
(%
(- wday wday1 -
7) 7))))))
13486 (if (and (boundp 'org-time-was-given
)
13488 (setq org-time-was-given t
))
13489 (if (< year
100) (setq year
(+ 2000 year
)))
13490 (if (< year
1970) (setq year
(nth 5 defdecode
))) ; not representable
13491 (setq org-read-date-analyze-futurep futurep
)
13492 (list second minute hour day month year
)))
13494 (defvar parse-time-weekdays
)
13496 (defun org-read-date-get-relative (s today default
)
13497 "Check string S for special relative date string.
13498 TODAY and DEFAULT are internal times, for today and for a default.
13499 Return shift list (N what def-flag)
13500 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
13501 N is the number of WHATs to shift.
13502 DEF-FLAG is t when a double ++ or -- indicates shift relative to
13503 the DEFAULT date rather than TODAY."
13507 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
13509 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays
"\\|") "\\)\\)?"
13510 "\\([ \t]\\|$\\)") s
)
13511 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
13512 (let* ((dir (if (> (match-end 1) (match-beginning 1))
13513 (string-to-char (substring (match-string 1 s
) -
1))
13515 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
13516 (n (if (match-end 2) (string-to-number (match-string 2 s
)) 1))
13517 (what (if (match-end 3) (match-string 3 s
) "d"))
13518 (wday1 (cdr (assoc (downcase what
) parse-time-weekdays
)))
13519 (date (if rel default today
))
13520 (wday (nth 6 (decode-time date
)))
13524 (setq delta
(mod (+ 7 (- wday1 wday
)) 7))
13525 (if (= dir ?-
) (setq delta
(- delta
7)))
13526 (if (> n
1) (setq delta
(+ delta
(* (1- n
) (if (= dir ?-
) -
7 7)))))
13527 (list delta
"d" rel
))
13528 (list (* n
(if (= dir ?-
) -
1 1)) what rel
)))))
13530 (defun org-eval-in-calendar (form &optional keepdate
)
13531 "Eval FORM in the calendar window and return to current window.
13532 Also, store the cursor date in variable org-ans2."
13533 (let ((sf (selected-frame))
13534 (sw (selected-window)))
13535 (select-window (get-buffer-window "*Calendar*" t
))
13537 (when (and (not keepdate
) (calendar-cursor-to-date))
13538 (let* ((date (calendar-cursor-to-date))
13539 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13540 (setq org-ans2
(format-time-string "%Y-%m-%d" time
))))
13541 (org-move-overlay org-date-ovl
(1- (point)) (1+ (point)) (current-buffer))
13543 (org-select-frame-set-input-focus sf
)))
13545 (defun org-calendar-select ()
13546 "Return to `org-read-date' with the date currently selected.
13547 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
13549 (when (calendar-cursor-to-date)
13550 (let* ((date (calendar-cursor-to-date))
13551 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13552 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
13553 (if (active-minibuffer-window) (exit-minibuffer))))
13555 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra
)
13556 "Insert a date stamp for the date given by the internal TIME.
13557 WITH-HM means, use the stamp format that includes the time of the day.
13558 INACTIVE means use square brackets instead of angular ones, so that the
13559 stamp will not contribute to the agenda.
13560 PRE and POST are optional strings to be inserted before and after the
13562 The command returns the inserted time stamp."
13563 (let ((fmt (funcall (if with-hm
'cdr
'car
) org-time-stamp-formats
))
13565 (if inactive
(setq fmt
(concat "[" (substring fmt
1 -
1) "]")))
13566 (insert-before-markers (or pre
""))
13567 (insert-before-markers (setq stamp
(format-time-string fmt time
)))
13568 (when (listp extra
)
13569 (setq extra
(car extra
))
13570 (if (and (stringp extra
)
13571 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra
))
13572 (setq extra
(format "-%02d:%02d"
13573 (string-to-number (match-string 1 extra
))
13574 (string-to-number (match-string 2 extra
))))
13578 (insert-before-markers extra
)
13580 (insert-before-markers (or post
""))
13581 (setq org-last-inserted-timestamp stamp
)))
13583 (defun org-toggle-time-stamp-overlays ()
13584 "Toggle the use of custom time stamp formats."
13586 (setq org-display-custom-times
(not org-display-custom-times
))
13587 (unless org-display-custom-times
13588 (let ((p (point-min)) (bmp (buffer-modified-p)))
13589 (while (setq p
(next-single-property-change p
'display
))
13590 (if (and (get-text-property p
'display
)
13591 (eq (get-text-property p
'face
) 'org-date
))
13592 (remove-text-properties
13593 p
(setq p
(next-single-property-change p
'display
))
13595 (set-buffer-modified-p bmp
)))
13596 (if (featurep 'xemacs
)
13597 (remove-text-properties (point-min) (point-max) '(end-glyph t
)))
13598 (org-restart-font-lock)
13599 (setq org-table-may-need-update t
)
13600 (if org-display-custom-times
13601 (message "Time stamps are overlayed with custom format")
13602 (message "Time stamp overlays removed")))
13604 (defun org-display-custom-time (beg end
)
13605 "Overlay modified time stamp format over timestamp between BEG and END."
13606 (let* ((ts (buffer-substring beg end
))
13607 t1 w1 with-hm tf time str w2
(off 0))
13609 (setq t1
(org-parse-time-string ts t
))
13610 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts
)
13611 (setq off
(- (match-end 0) (match-beginning 0)))))
13612 (setq end
(- end off
))
13613 (setq w1
(- end beg
)
13614 with-hm
(and (nth 1 t1
) (nth 2 t1
))
13615 tf
(funcall (if with-hm
'cdr
'car
) org-time-stamp-custom-formats
)
13616 time
(org-fix-decoded-time t1
)
13618 (format-time-string
13619 (substring tf
1 -
1) (apply 'encode-time time
))
13620 nil
'mouse-face
'highlight
)
13622 (if (not (= w2 w1
))
13623 (add-text-properties (1+ beg
) (+ 2 beg
)
13624 (list 'org-dwidth t
'org-dwidth-n
(- w1 w2
))))
13625 (if (featurep 'xemacs
)
13627 (put-text-property beg end
'invisible t
)
13628 (put-text-property beg end
'end-glyph
(make-glyph str
)))
13629 (put-text-property beg end
'display str
))))
13631 (defun org-translate-time (string)
13632 "Translate all timestamps in STRING to custom format.
13633 But do this only if the variable `org-display-custom-times' is set."
13634 (when org-display-custom-times
13637 (re org-ts-regexp-both
)
13638 t1 with-hm inactive tf time str beg end
)
13639 (while (setq start
(string-match re string start
))
13640 (setq beg
(match-beginning 0)
13642 t1
(save-match-data
13643 (org-parse-time-string (substring string beg end
) t
))
13644 with-hm
(and (nth 1 t1
) (nth 2 t1
))
13645 inactive
(equal (substring string beg
(1+ beg
)) "[")
13646 tf
(funcall (if with-hm
'cdr
'car
)
13647 org-time-stamp-custom-formats
)
13648 time
(org-fix-decoded-time t1
)
13649 str
(format-time-string
13651 (if inactive
"[" "<") (substring tf
1 -
1)
13652 (if inactive
"]" ">"))
13653 (apply 'encode-time time
))
13654 string
(replace-match str t t string
)
13655 start
(+ start
(length str
)))))))
13658 (defun org-fix-decoded-time (time)
13659 "Set 0 instead of nil for the first 6 elements of time.
13660 Don't touch the rest."
13662 (mapcar (lambda (x) (if (< (setq n
(1+ n
)) 7) (or x
0) x
)) time
)))
13664 (defun org-days-to-time (timestamp-string)
13665 "Difference between TIMESTAMP-STRING and now in days."
13666 (- (time-to-days (org-time-string-to-time timestamp-string
))
13667 (time-to-days (current-time))))
13669 (defun org-deadline-close (timestamp-string &optional ndays
)
13670 "Is the time in TIMESTAMP-STRING close to the current date?"
13671 (setq ndays
(or ndays
(org-get-wdays timestamp-string
)))
13672 (and (< (org-days-to-time timestamp-string
) ndays
)
13673 (not (org-entry-is-done-p))))
13675 (defun org-get-wdays (ts)
13676 "Get the deadline lead time appropriate for timestring TS."
13678 ((<= org-deadline-warning-days
0)
13679 ;; 0 or negative, enforce this value no matter what
13680 (- org-deadline-warning-days
))
13681 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts
)
13682 ;; lead time is specified.
13683 (floor (* (string-to-number (match-string 1 ts
))
13684 (cdr (assoc (match-string 2 ts
)
13685 '(("d" .
1) ("w" .
7)
13686 ("m" .
30.4) ("y" .
365.25)))))))
13687 ;; go for the default.
13688 (t org-deadline-warning-days
)))
13690 (defun org-calendar-select-mouse (ev)
13691 "Return to `org-read-date' with the date currently selected.
13692 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
13694 (mouse-set-point ev
)
13695 (when (calendar-cursor-to-date)
13696 (let* ((date (calendar-cursor-to-date))
13697 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13698 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
13699 (if (active-minibuffer-window) (exit-minibuffer))))
13701 (defun org-check-deadlines (ndays)
13702 "Check if there are any deadlines due or past due.
13703 A deadline is considered due if it happens within `org-deadline-warning-days'
13704 days from today's date. If the deadline appears in an entry marked DONE,
13705 it is not shown. The prefix arg NDAYS can be used to test that many
13706 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
13708 (let* ((org-warn-days
13710 ((equal ndays
'(4)) 100000)
13711 (ndays (prefix-numeric-value ndays
))
13712 (t (abs org-deadline-warning-days
))))
13713 (case-fold-search nil
)
13714 (regexp (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>"))
13716 (lambda () (org-deadline-close (match-string 1) org-warn-days
))))
13718 (message "%d deadlines past-due or due within %d days"
13719 (org-occur regexp nil callback
)
13722 (defun org-check-before-date (date)
13723 "Check if there are deadlines or scheduled entries before DATE."
13724 (interactive (list (org-read-date)))
13725 (let ((case-fold-search nil
)
13726 (regexp (concat "\\<\\(" org-deadline-string
13727 "\\|" org-scheduled-string
13728 "\\) *<\\([^>]+\\)>"))
13730 (lambda () (time-less-p
13731 (org-time-string-to-time (match-string 2))
13732 (org-time-string-to-time date
)))))
13733 (message "%d entries before %s"
13734 (org-occur regexp nil callback
) date
)))
13736 (defun org-check-after-date (date)
13737 "Check if there are deadlines or scheduled entries after DATE."
13738 (interactive (list (org-read-date)))
13739 (let ((case-fold-search nil
)
13740 (regexp (concat "\\<\\(" org-deadline-string
13741 "\\|" org-scheduled-string
13742 "\\) *<\\([^>]+\\)>"))
13746 (org-time-string-to-time (match-string 2))
13747 (org-time-string-to-time date
))))))
13748 (message "%d entries after %s"
13749 (org-occur regexp nil callback
) date
)))
13751 (defun org-evaluate-time-range (&optional to-buffer
)
13752 "Evaluate a time range by computing the difference between start and end.
13753 Normally the result is just printed in the echo area, but with prefix arg
13754 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
13755 If the time range is actually in a table, the result is inserted into the
13757 For time difference computation, a year is assumed to be exactly 365
13758 days in order to avoid rounding problems."
13761 (org-clock-update-time-maybe)
13763 (unless (org-at-date-range-p t
)
13764 (goto-char (point-at-bol))
13765 (re-search-forward org-tr-regexp-both
(point-at-eol) t
))
13766 (if (not (org-at-date-range-p t
))
13767 (error "Not at a time-stamp range, and none found in current line")))
13768 (let* ((ts1 (match-string 1))
13769 (ts2 (match-string 2))
13770 (havetime (or (> (length ts1
) 15) (> (length ts2
) 15)))
13771 (match-end (match-end 0))
13772 (time1 (org-time-string-to-time ts1
))
13773 (time2 (org-time-string-to-time ts2
))
13774 (t1 (org-float-time time1
))
13775 (t2 (org-float-time time2
))
13776 (diff (abs (- t2 t1
)))
13777 (negative (< (- t2 t1
) 0))
13778 ;; (ys (floor (* 365 24 60 60)))
13781 (fy "%dy %dd %02d:%02d")
13783 (fd "%dd %02d:%02d")
13788 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
13790 d
(floor (/ diff ds
)) diff
(mod diff ds
)
13791 h
(floor (/ diff hs
)) diff
(mod diff hs
)
13792 m
(floor (/ diff
60)))
13793 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
13795 d
(floor (+ (/ diff ds
) 0.5))
13797 (if (not to-buffer
)
13798 (message "%s" (org-make-tdiff-string y d h m
))
13799 (if (org-at-table-p)
13801 (goto-char match-end
)
13803 (and (looking-at " *|") (goto-char (match-end 0))))
13804 (goto-char match-end
))
13806 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
13807 (replace-match ""))
13808 (if negative
(insert " -"))
13809 (if (> y
0) (insert " " (format (if havetime fy fy1
) y d h m
))
13810 (if (> d
0) (insert " " (format (if havetime fd fd1
) d h m
))
13811 (insert " " (format fh h m
))))
13812 (if align
(org-table-align))
13813 (message "Time difference inserted")))))
13815 (defun org-make-tdiff-string (y d h m
)
13818 (if (> y
0) (setq fmt
(concat fmt
"%d year" (if (> y
1) "s" "") " ")
13820 (if (> d
0) (setq fmt
(concat fmt
"%d day" (if (> d
1) "s" "") " ")
13822 (if (> h
0) (setq fmt
(concat fmt
"%d hour" (if (> h
1) "s" "") " ")
13824 (if (> m
0) (setq fmt
(concat fmt
"%d minute" (if (> m
1) "s" "") " ")
13826 (apply 'format fmt
(nreverse l
))))
13828 (defun org-time-string-to-time (s)
13829 (apply 'encode-time
(org-parse-time-string s
)))
13830 (defun org-time-string-to-seconds (s)
13831 (org-float-time (org-time-string-to-time s
)))
13833 (defun org-time-string-to-absolute (s &optional daynr prefer show-all
)
13834 "Convert a time stamp to an absolute day number.
13835 If there is a specifyer for a cyclic time stamp, get the closest date to
13837 PREFER and SHOW-ALL are passed through to `org-closest-date'.
13838 the variable date is bound by the calendar when this is called."
13840 ((and daynr
(string-match "\\`%%\\((.*)\\)" s
))
13841 (if (org-diary-sexp-entry (match-string 1 s
) "" date
)
13844 ((and daynr
(string-match "\\+[0-9]+[dwmy]" s
))
13845 (org-closest-date s
(if (and (boundp 'daynr
) (integerp daynr
)) daynr
13846 (time-to-days (current-time))) (match-string 0 s
)
13848 (t (time-to-days (apply 'encode-time
(org-parse-time-string s
))))))
13850 (defun org-days-to-iso-week (days)
13851 "Return the iso week number."
13853 (car (calendar-iso-from-absolute days
)))
13855 (defun org-small-year-to-year (year)
13856 "Convert 2-digit years into 4-digit years.
13857 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
13858 The year 2000 cannot be abbreviated. Any year larger than 99
13859 is returned unchanged."
13861 (setq year
(+ 2000 year
))
13863 (setq year
(+ 1900 year
))))
13866 (defun org-time-from-absolute (d)
13867 "Return the time corresponding to date D.
13868 D may be an absolute day number, or a calendar-type list (month day year)."
13869 (if (numberp d
) (setq d
(calendar-gregorian-from-absolute d
)))
13870 (encode-time 0 0 0 (nth 1 d
) (car d
) (nth 2 d
)))
13872 (defun org-calendar-holiday ()
13873 "List of holidays, for Diary display in Org-mode."
13874 (require 'holidays
)
13876 (if (fboundp 'calendar-check-holidays
)
13877 'calendar-check-holidays
'check-calendar-holidays
) date
)))
13878 (if hl
(mapconcat 'identity hl
"; "))))
13880 (defun org-diary-sexp-entry (sexp entry date
)
13881 "Process a SEXP diary ENTRY for DATE."
13882 (require 'diary-lib
)
13883 (let ((result (if calendar-debug-sexp
13884 (let ((stack-trace-on-error t
))
13885 (eval (car (read-from-string sexp
))))
13886 (condition-case nil
13887 (eval (car (read-from-string sexp
)))
13890 (message "Bad sexp at line %d in %s: %s"
13892 (buffer-file-name) sexp
)
13894 (cond ((stringp result
) result
)
13895 ((and (consp result
)
13896 (stringp (cdr result
))) (cdr result
))
13900 (defun org-diary-to-ical-string (frombuf)
13901 "Get iCalendar entries from diary entries in buffer FROMBUF.
13902 This uses the icalendar.el library."
13903 (let* ((tmpdir (if (featurep 'xemacs
)
13905 temporary-file-directory
))
13906 (tmpfile (make-temp-name
13907 (expand-file-name "orgics" tmpdir
)))
13909 (with-current-buffer frombuf
13910 (icalendar-export-region (point-min) (point-max) tmpfile
)
13911 (setq buf
(find-buffer-visiting tmpfile
))
13913 (goto-char (point-min))
13914 (if (re-search-forward "^BEGIN:VEVENT" nil t
)
13915 (setq b
(match-beginning 0)))
13916 (goto-char (point-max))
13917 (if (re-search-backward "^END:VEVENT" nil t
)
13918 (setq e
(match-end 0)))
13919 (setq rtn
(if (and b e
) (concat (buffer-substring b e
) "\n") "")))
13921 (delete-file tmpfile
)
13924 (defun org-closest-date (start current change prefer show-all
)
13925 "Find the date closest to CURRENT that is consistent with START and CHANGE.
13926 When PREFER is `past' return a date that is either CURRENT or past.
13927 When PREFER is `future', return a date that is either CURRENT or future.
13928 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
13929 ;; Make the proper lists from the dates
13931 (let ((a1 '(("d" . day
) ("w" . week
) ("m" . month
) ("y" . year
)))
13932 dn dw sday cday n1 n2 n0
13933 d m y y1 y2 date1 date2 nmonths nm ny m2
)
13935 (setq start
(org-date-to-gregorian start
)
13936 current
(org-date-to-gregorian
13939 (time-to-days (current-time))))
13940 sday
(calendar-absolute-from-gregorian start
)
13941 cday
(calendar-absolute-from-gregorian current
))
13943 (if (<= cday sday
) (throw 'exit sday
))
13945 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change
)
13946 (setq dn
(string-to-number (match-string 1 change
))
13947 dw
(cdr (assoc (match-string 2 change
) a1
)))
13948 (error "Invalid change specifyer: %s" change
))
13949 (if (eq dw
'week
) (setq dw
'day dn
(* 7 dn
)))
13952 (setq n1
(+ sday
(* dn
(floor (/ (- cday sday
) dn
))))
13955 (setq d
(nth 1 start
) m
(car start
) y1
(nth 2 start
) y2
(nth 2 current
))
13956 (setq y1
(+ (* (floor (/ (- y2 y1
) dn
)) dn
) y1
))
13957 (setq date1
(list m d y1
)
13958 n1
(calendar-absolute-from-gregorian date1
)
13959 date2
(list m d
(+ y1
(* (if (< n1 cday
) 1 -
1) dn
)))
13960 n2
(calendar-absolute-from-gregorian date2
)))
13962 ;; approx number of month between the two dates
13963 (setq nmonths
(floor (/ (- cday sday
) 30.436875)))
13964 ;; How often does dn fit in there?
13965 (setq d
(nth 1 start
) m
(car start
) y
(nth 2 start
)
13966 nm
(* dn
(max 0 (1- (floor (/ nmonths dn
)))))
13968 ny
(floor (/ m
12))
13971 (while (> m
12) (setq m
(- m
12) y
(1+ y
)))
13972 (setq n1
(calendar-absolute-from-gregorian (list m d y
)))
13973 (setq m2
(+ m dn
) y2 y
)
13974 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
13975 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
)))
13976 (while (<= n2 cday
)
13977 (setq n1 n2 m m2 y y2
)
13978 (setq m2
(+ m dn
) y2 y
)
13979 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
13980 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
))))))
13981 ;; Make sure n1 is the earlier date
13982 (setq n0 n1 n1
(min n1 n2
) n2
(max n0 n2
))
13985 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
13986 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
13987 (t (if (> (abs (- cday n1
)) (abs (- cday n2
))) n2 n1
)))
13989 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
13990 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
13991 (t (if (= cday n1
) n1 n2
)))))))
13993 (defun org-date-to-gregorian (date)
13994 "Turn any specification of DATE into a gregorian date for the calendar."
13995 (cond ((integerp date
) (calendar-gregorian-from-absolute date
))
13996 ((and (listp date
) (= (length date
) 3)) date
)
13998 (setq date
(org-parse-time-string date
))
13999 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))
14001 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))))
14003 (defun org-parse-time-string (s &optional nodefault
)
14004 "Parse the standard Org-mode time string.
14005 This should be a lot faster than the normal `parse-time-string'.
14006 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14007 hour and minute fields will be nil if not given."
14008 (if (string-match org-ts-regexp0 s
)
14010 (if (or (match-beginning 8) (not nodefault
))
14011 (string-to-number (or (match-string 8 s
) "0")))
14012 (if (or (match-beginning 7) (not nodefault
))
14013 (string-to-number (or (match-string 7 s
) "0")))
14014 (string-to-number (match-string 4 s
))
14015 (string-to-number (match-string 3 s
))
14016 (string-to-number (match-string 2 s
))
14018 (error "Not a standard Org-mode time string: %s" s
)))
14020 (defun org-timestamp-up (&optional arg
)
14021 "Increase the date item at the cursor by one.
14022 If the cursor is on the year, change the year. If it is on the month or
14023 the day, change that.
14024 With prefix ARG, change by that many units."
14026 (org-timestamp-change (prefix-numeric-value arg
)))
14028 (defun org-timestamp-down (&optional arg
)
14029 "Decrease the date item at the cursor by one.
14030 If the cursor is on the year, change the year. If it is on the month or
14031 the day, change that.
14032 With prefix ARG, change by that many units."
14034 (org-timestamp-change (- (prefix-numeric-value arg
))))
14036 (defun org-timestamp-up-day (&optional arg
)
14037 "Increase the date in the time stamp by one day.
14038 With prefix ARG, change that many days."
14040 (if (and (not (org-at-timestamp-p t
))
14041 (org-on-heading-p))
14043 (org-timestamp-change (prefix-numeric-value arg
) 'day
)))
14045 (defun org-timestamp-down-day (&optional arg
)
14046 "Decrease the date in the time stamp by one day.
14047 With prefix ARG, change that many days."
14049 (if (and (not (org-at-timestamp-p t
))
14050 (org-on-heading-p))
14052 (org-timestamp-change (- (prefix-numeric-value arg
)) 'day
)))
14054 (defun org-at-timestamp-p (&optional inactive-ok
)
14055 "Determine if the cursor is in or at a timestamp."
14057 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2
))
14059 (ans (or (looking-at tsr
)
14061 (skip-chars-backward "^[<\n\r\t")
14062 (if (> (point) (point-min)) (backward-char 1))
14063 (and (looking-at tsr
)
14064 (> (- (match-end 0) pos
) -
1))))))
14066 (boundp 'org-ts-what
)
14069 ((= pos
(match-beginning 0)) 'bracket
)
14070 ((= pos
(1- (match-end 0))) 'bracket
)
14071 ((org-pos-in-match-range pos
2) 'year
)
14072 ((org-pos-in-match-range pos
3) 'month
)
14073 ((org-pos-in-match-range pos
7) 'hour
)
14074 ((org-pos-in-match-range pos
8) 'minute
)
14075 ((or (org-pos-in-match-range pos
4)
14076 (org-pos-in-match-range pos
5)) 'day
)
14077 ((and (> pos
(or (match-end 8) (match-end 5)))
14078 (< pos
(match-end 0)))
14079 (- pos
(or (match-end 8) (match-end 5))))
14083 (defun org-toggle-timestamp-type ()
14084 "Toggle the type (<active> or [inactive]) of a time stamp."
14086 (when (org-at-timestamp-p t
)
14087 (let ((beg (match-beginning 0)) (end (match-end 0))
14088 (map '((?\
[ .
"<") (?\
] .
">") (?
< .
"[") (?
> .
"]"))))
14091 (while (re-search-forward "[][<>]" end t
)
14092 (replace-match (cdr (assoc (char-after (match-beginning 0)) map
))
14094 (message "Timestamp is now %sactive"
14095 (if (equal (char-after beg
) ?
<) "" "in")))))
14097 (defun org-timestamp-change (n &optional what
)
14098 "Change the date in the time stamp at point.
14099 The date will be changed by N times WHAT. WHAT can be `day', `month',
14100 `year', `minute', `second'. If WHAT is not given, the cursor position
14101 in the timestamp determines what will be changed."
14102 (let ((pos (point))
14104 (dm (max (nth 1 org-time-stamp-rounding-minutes
) 1))
14108 (if (not (org-at-timestamp-p t
))
14109 (error "Not at a timestamp"))
14110 (if (and (not what
) (eq org-ts-what
'bracket
))
14111 (org-toggle-timestamp-type)
14112 (if (and (not what
) (not (eq org-ts-what
'day
))
14113 org-display-custom-times
14114 (get-text-property (point) 'display
)
14115 (not (get-text-property (1- (point)) 'display
)))
14116 (setq org-ts-what
'day
))
14117 (setq org-ts-what
(or what org-ts-what
)
14118 inactive
(= (char-after (match-beginning 0)) ?\
[)
14119 ts
(match-string 0))
14122 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
14124 (setq extra
(match-string 1 ts
)))
14125 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts
)
14127 (setq time0
(org-parse-time-string ts
))
14128 (when (and (eq org-ts-what
'minute
)
14129 (eq current-prefix-arg nil
))
14130 (setq n
(* dm
(cond ((> n
0) 1) ((< n
0) -
1) (t 0))))
14131 (when (not (= 0 (setq rem
(%
(nth 1 time0
) dm
))))
14132 (setcar (cdr time0
) (+ (nth 1 time0
)
14133 (if (> n
0) (- rem
) (- dm rem
))))))
14135 (encode-time (or (car time0
) 0)
14136 (+ (if (eq org-ts-what
'minute
) n
0) (nth 1 time0
))
14137 (+ (if (eq org-ts-what
'hour
) n
0) (nth 2 time0
))
14138 (+ (if (eq org-ts-what
'day
) n
0) (nth 3 time0
))
14139 (+ (if (eq org-ts-what
'month
) n
0) (nth 4 time0
))
14140 (+ (if (eq org-ts-what
'year
) n
0) (nth 5 time0
))
14142 (when (and (member org-ts-what
'(hour minute
))
14144 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra
))
14145 (setq extra
(org-modify-ts-extra
14147 (if (eq org-ts-what
'hour
) 2 5)
14149 (when (integerp org-ts-what
)
14150 (setq extra
(org-modify-ts-extra extra org-ts-what n dm
)))
14151 (if (eq what
'calendar
)
14152 (let ((cal-date (org-get-date-from-calendar)))
14153 (setcar (nthcdr 4 time0
) (nth 0 cal-date
)) ; month
14154 (setcar (nthcdr 3 time0
) (nth 1 cal-date
)) ; day
14155 (setcar (nthcdr 5 time0
) (nth 2 cal-date
)) ; year
14156 (setcar time0
(or (car time0
) 0))
14157 (setcar (nthcdr 1 time0
) (or (nth 1 time0
) 0))
14158 (setcar (nthcdr 2 time0
) (or (nth 2 time0
) 0))
14159 (setq time
(apply 'encode-time time0
))))
14160 (setq org-last-changed-timestamp
14161 (org-insert-time-stamp time with-hm inactive nil nil extra
))
14162 (org-clock-update-time-maybe)
14164 ;; Try to recenter the calendar window, if any
14165 (if (and org-calendar-follow-timestamp-change
14166 (get-buffer-window "*Calendar*" t
)
14167 (memq org-ts-what
'(day month year
)))
14168 (org-recenter-calendar (time-to-days time
))))))
14170 (defun org-modify-ts-extra (s pos n dm
)
14171 "Change the different parts of the lead-time and repeat fields in timestamp."
14172 (let ((idx '(("d" .
0) ("w" .
1) ("m" .
2) ("y" .
3) ("d" . -
1) ("y" .
4)))
14174 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s
)
14176 ((or (org-pos-in-match-range pos
2)
14177 (org-pos-in-match-range pos
3))
14178 (setq m
(string-to-number (match-string 3 s
))
14179 h
(string-to-number (match-string 2 s
)))
14180 (if (org-pos-in-match-range pos
2)
14182 (setq n
(* dm
(org-no-warnings (signum n
))))
14183 (when (not (= 0 (setq rem
(% m dm
))))
14184 (setq m
(+ m
(if (> n
0) (- rem
) (- dm rem
)))))
14186 (if (< m
0) (setq m
(+ m
60) h
(1- h
)))
14187 (if (> m
59) (setq m
(- m
60) h
(1+ h
)))
14188 (setq h
(min 24 (max 0 h
)))
14189 (setq ng
1 new
(format "-%02d:%02d" h m
)))
14190 ((org-pos-in-match-range pos
6)
14191 (setq ng
6 new
(car (rassoc (+ n
(cdr (assoc (match-string 6 s
) idx
))) idx
))))
14192 ((org-pos-in-match-range pos
5)
14193 (setq ng
5 new
(format "%d" (max 1 (+ n
(string-to-number (match-string 5 s
)))))))
14195 ((org-pos-in-match-range pos
9)
14196 (setq ng
9 new
(car (rassoc (+ n
(cdr (assoc (match-string 9 s
) idx
))) idx
))))
14197 ((org-pos-in-match-range pos
8)
14198 (setq ng
8 new
(format "%d" (max 0 (+ n
(string-to-number (match-string 8 s
))))))))
14202 (substring s
0 (match-beginning ng
))
14204 (substring s
(match-end ng
))))))
14207 (defun org-recenter-calendar (date)
14208 "If the calendar is visible, recenter it to DATE."
14209 (let* ((win (selected-window))
14210 (cwin (get-buffer-window "*Calendar*" t
))
14211 (calendar-move-hook nil
))
14213 (select-window cwin
)
14214 (calendar-goto-date (if (listp date
) date
14215 (calendar-gregorian-from-absolute date
)))
14216 (select-window win
))))
14218 (defun org-goto-calendar (&optional arg
)
14219 "Go to the Emacs calendar at the current date.
14220 If there is a time stamp in the current line, go to that date.
14221 A prefix ARG can be used to force the current date."
14223 (let ((tsr org-ts-regexp
) diff
14224 (calendar-move-hook nil
)
14225 (calendar-view-holidays-initially-flag nil
)
14226 (view-calendar-holidays-initially nil
)
14227 (calendar-view-diary-initially-flag nil
)
14228 (view-diary-entries-initially nil
))
14229 (if (or (org-at-timestamp-p)
14231 (beginning-of-line 1)
14232 (looking-at (concat ".*" tsr
))))
14233 (let ((d1 (time-to-days (current-time)))
14235 (org-time-string-to-time (match-string 1)))))
14236 (setq diff
(- d2 d1
))))
14238 (calendar-goto-today)
14239 (if (and diff
(not arg
)) (calendar-forward-day diff
))))
14241 (defun org-get-date-from-calendar ()
14242 "Return a list (month day year) of date at point in calendar."
14243 (with-current-buffer "*Calendar*"
14245 (calendar-cursor-to-date))))
14247 (defun org-date-from-calendar ()
14248 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
14249 If there is already a time stamp at the cursor position, update it."
14251 (if (org-at-timestamp-p t
)
14252 (org-timestamp-change 0 'calendar
)
14253 (let ((cal-date (org-get-date-from-calendar)))
14254 (org-insert-time-stamp
14255 (encode-time 0 0 0 (nth 1 cal-date
) (car cal-date
) (nth 2 cal-date
))))))
14257 (defun org-minutes-to-hh:mm-string
(m)
14258 "Compute H:MM from a number of minutes."
14259 (let ((h (/ m
60)))
14260 (setq m
(- m
(* 60 h
)))
14261 (format org-time-clocksum-format h m
)))
14263 (defun org-hh:mm-string-to-minutes
(s)
14264 "Convert a string H:MM to a number of minutes.
14265 If the string is just a number, interpret it as minutes.
14266 In fact, the first hh:mm or number in the string will be taken,
14267 there can be extra stuff in the string.
14268 If no number is found, the return value is 0."
14270 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s
)
14271 (+ (* (string-to-number (match-string 1 s
)) 60)
14272 (string-to-number (match-string 2 s
))))
14273 ((string-match "\\([0-9]+\\)" s
)
14274 (string-to-number (match-string 1 s
)))
14279 (defun org-save-all-org-buffers ()
14280 "Save all Org-mode buffers without user confirmation."
14282 (message "Saving all Org-mode buffers...")
14283 (save-some-buffers t
'org-mode-p
)
14284 (when (featurep 'org-id
) (org-id-locations-save))
14285 (message "Saving all Org-mode buffers... done"))
14287 (defun org-revert-all-org-buffers ()
14288 "Revert all Org-mode buffers.
14289 Prompt for confirmation when there are unsaved changes.
14290 Be sure you know what you are doing before letting this function
14291 overwrite your changes.
14293 This function is useful in a setup where one tracks org files
14294 with a version control system, to revert on one machine after pulling
14295 changes from another. I believe the procedure must be like this:
14297 1. M-x org-save-all-org-buffers
14298 2. Pull changes from the other machine, resolve conflicts
14299 3. M-x org-revert-all-org-buffers"
14301 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
14304 (save-window-excursion
14307 (when (and (with-current-buffer b
(org-mode-p))
14308 (with-current-buffer b buffer-file-name
))
14309 (switch-to-buffer b
)
14310 (revert-buffer t
'no-confirm
)))
14312 (when (and (featurep 'org-id
) org-id-track-globally
)
14313 (org-id-locations-load)))))
14318 (defun org-iswitchb (&optional arg
)
14319 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
14320 With a prefix argument, restrict available to files.
14321 With two prefix arguments, restrict available buffers to agenda files."
14323 (let ((blist (cond ((equal arg
'(4)) (org-buffer-list 'files
))
14324 ((equal arg
'(16)) (org-buffer-list 'agenda
))
14325 (t (org-buffer-list)))))
14327 (org-icompleting-read "Org buffer: "
14328 (mapcar 'list
(mapcar 'buffer-name blist
))
14332 (defalias 'org-ido-switchb
'org-iswitchb
)
14334 (defun org-buffer-list (&optional predicate exclude-tmp
)
14335 "Return a list of Org buffers.
14336 PREDICATE can be `export', `files' or `agenda'.
14338 export restrict the list to Export buffers.
14339 files restrict the list to buffers visiting Org files.
14340 agenda restrict the list to buffers visiting agenda files.
14342 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
14344 (agenda-files (and (eq predicate
'agenda
)
14345 (mapcar 'file-truename
(org-agenda-files t
))))
14348 ((eq predicate
'files
)
14349 (lambda (b) (with-current-buffer b
(eq major-mode
'org-mode
))))
14350 ((eq predicate
'export
)
14351 (lambda (b) (string-match "\*Org .*Export" (buffer-name b
))))
14352 ((eq predicate
'agenda
)
14354 (with-current-buffer b
14355 (and (eq major-mode
'org-mode
)
14356 (setq bfn
(buffer-file-name b
))
14357 (member (file-truename bfn
) agenda-files
)))))
14358 (t (lambda (b) (with-current-buffer b
14359 (or (eq major-mode
'org-mode
)
14360 (string-match "\*Org .*Export"
14361 (buffer-name b
)))))))))
14365 (if (and (funcall filter b
)
14366 (or (not exclude-tmp
)
14367 (not (string-match "tmp" (buffer-name b
)))))
14372 (defun org-agenda-files (&optional unrestricted archives
)
14373 "Get the list of agenda files.
14374 Optional UNRESTRICTED means return the full list even if a restriction
14375 is currently in place.
14376 When ARCHIVES is t, include all archive files hat are really being
14377 used by the agenda files. If ARCHIVE is `ifmode', do this only if
14378 `org-agenda-archives-mode' is t."
14381 ((and (not unrestricted
) (get 'org-agenda-files
'org-restrict
)))
14382 ((stringp org-agenda-files
) (org-read-agenda-file-list))
14383 ((listp org-agenda-files
) org-agenda-files
)
14384 (t (error "Invalid value of `org-agenda-files'")))))
14385 (setq files
(apply 'append
14386 (mapcar (lambda (f)
14387 (if (file-directory-p f
)
14389 f t org-agenda-file-regexp
)
14392 (when org-agenda-skip-unavailable-files
14393 (setq files
(delq nil
14396 (and (file-readable-p file
) file
)))
14398 (when (or (eq archives t
)
14399 (and (eq archives
'ifmode
) (eq org-agenda-archives-mode t
)))
14400 (setq files
(org-add-archive-files files
)))
14403 (defun org-edit-agenda-file-list ()
14404 "Edit the list of agenda files.
14405 Depending on setup, this either uses customize to edit the variable
14406 `org-agenda-files', or it visits the file that is holding the list. In the
14407 latter case, the buffer is set up in a way that saving it automatically kills
14408 the buffer and restores the previous window configuration."
14410 (if (stringp org-agenda-files
)
14411 (let ((cw (current-window-configuration)))
14412 (find-file org-agenda-files
)
14413 (org-set-local 'org-window-configuration cw
)
14414 (org-add-hook 'after-save-hook
14416 (set-window-configuration
14417 (prog1 org-window-configuration
14418 (kill-buffer (current-buffer))))
14419 (org-install-agenda-files-menu)
14420 (message "New agenda file list installed"))
14422 (message "%s" (substitute-command-keys
14423 "Edit list and finish with \\[save-buffer]")))
14424 (customize-variable 'org-agenda-files
)))
14426 (defun org-store-new-agenda-file-list (list)
14427 "Set new value for the agenda file list and save it correctly."
14428 (if (stringp org-agenda-files
)
14429 (let ((f org-agenda-files
) b
)
14430 (while (setq b
(find-buffer-visiting f
)) (kill-buffer b
))
14432 (insert (mapconcat 'identity list
"\n") "\n")))
14433 (let ((org-mode-hook nil
) (org-inhibit-startup t
)
14434 (org-insert-mode-line-in-empty-file nil
))
14435 (setq org-agenda-files list
)
14436 (customize-save-variable 'org-agenda-files org-agenda-files
))))
14438 (defun org-read-agenda-file-list ()
14439 "Read the list of agenda files from a file."
14440 (when (file-directory-p org-agenda-files
)
14441 (error "`org-agenda-files' cannot be a single directory"))
14442 (when (stringp org-agenda-files
)
14444 (insert-file-contents org-agenda-files
)
14445 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*"))))
14449 (defun org-cycle-agenda-files ()
14450 "Cycle through the files in `org-agenda-files'.
14451 If the current buffer visits an agenda file, find the next one in the list.
14452 If the current buffer does not, find the first agenda file."
14454 (let* ((fs (org-agenda-files t
))
14455 (files (append fs
(list (car fs
))))
14456 (tcf (if buffer-file-name
(file-truename buffer-file-name
)))
14458 (unless files
(error "No agenda files"))
14460 (while (setq file
(pop files
))
14461 (if (equal (file-truename file
) tcf
)
14463 (find-file (car files
))
14465 (find-file (car fs
)))
14466 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
14468 (defun org-agenda-file-to-front (&optional to-end
)
14469 "Move/add the current file to the top of the agenda file list.
14470 If the file is not present in the list, it is added to the front. If it is
14471 present, it is moved there. With optional argument TO-END, add/move to the
14474 (let ((org-agenda-skip-unavailable-files nil
)
14475 (file-alist (mapcar (lambda (x)
14476 (cons (file-truename x
) x
))
14477 (org-agenda-files t
)))
14478 (ctf (file-truename buffer-file-name
))
14480 (setq x
(assoc ctf file-alist
) had x
)
14482 (if (not x
) (setq x
(cons ctf
(abbreviate-file-name buffer-file-name
))))
14484 (setq file-alist
(append (delq x file-alist
) (list x
)))
14485 (setq file-alist
(cons x
(delq x file-alist
))))
14486 (org-store-new-agenda-file-list (mapcar 'cdr file-alist
))
14487 (org-install-agenda-files-menu)
14488 (message "File %s to %s of agenda file list"
14489 (if had
"moved" "added") (if to-end
"end" "front"))))
14491 (defun org-remove-file (&optional file
)
14492 "Remove current file from the list of files in variable `org-agenda-files'.
14493 These are the files which are being checked for agenda entries.
14494 Optional argument FILE means, use this file instead of the current."
14496 (let* ((org-agenda-skip-unavailable-files nil
)
14497 (file (or file buffer-file-name
))
14498 (true-file (file-truename file
))
14499 (afile (abbreviate-file-name file
))
14500 (files (delq nil
(mapcar
14502 (if (equal true-file
14505 (org-agenda-files t
)))))
14506 (if (not (= (length files
) (length (org-agenda-files t
))))
14508 (org-store-new-agenda-file-list files
)
14509 (org-install-agenda-files-menu)
14510 (message "Removed file: %s" afile
))
14511 (message "File was not in list: %s (not removed)" afile
))))
14513 (defun org-file-menu-entry (file)
14514 (vector file
(list 'find-file file
) t
))
14516 (defun org-check-agenda-file (file)
14517 "Make sure FILE exists. If not, ask user what to do."
14518 (when (not (file-exists-p file
))
14519 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
14520 (abbreviate-file-name file
))
14521 (let ((r (downcase (read-char-exclusive))))
14524 (org-remove-file file
)
14525 (throw 'nextfile t
))
14526 (t (error "Abort"))))))
14528 (defun org-get-agenda-file-buffer (file)
14529 "Get a buffer visiting FILE. If the buffer needs to be created, add
14530 it to the list of buffers which might be released later."
14531 (let ((buf (org-find-base-buffer-visiting file
)))
14533 buf
; just return it
14534 ;; Make a new buffer and remember it
14535 (setq buf
(find-file-noselect file
))
14536 (if buf
(push buf org-agenda-new-buffers
))
14539 (defun org-release-buffers (blist)
14540 "Release all buffers in list, asking the user for confirmation when needed.
14541 When a buffer is unmodified, it is just killed. When modified, it is saved
14542 \(if the user agrees) and then killed."
14544 (while (setq buf
(pop blist
))
14545 (setq file
(buffer-file-name buf
))
14546 (when (and (buffer-modified-p buf
)
14548 (y-or-n-p (format "Save file %s? " file
)))
14549 (with-current-buffer buf
(save-buffer)))
14550 (kill-buffer buf
))))
14552 (defun org-prepare-agenda-buffers (files)
14553 "Create buffers for all agenda files, protect archived trees and comments."
14555 (let ((pa '(:org-archived t
))
14556 (pc '(:org-comment t
))
14557 (pall '(:org-archived t
:org-comment t
))
14558 (inhibit-read-only t
)
14559 (rea (concat ":" org-archive-tag
":"))
14563 (while (setq file
(pop files
))
14567 (org-check-agenda-file file
)
14568 (set-buffer (org-get-agenda-file-buffer file
)))
14570 (setq bmp
(buffer-modified-p))
14571 (org-refresh-category-properties)
14572 (setq org-todo-keywords-for-agenda
14573 (append org-todo-keywords-for-agenda org-todo-keywords-1
))
14574 (setq org-done-keywords-for-agenda
14575 (append org-done-keywords-for-agenda org-done-keywords
))
14576 (setq org-todo-keyword-alist-for-agenda
14577 (append org-todo-keyword-alist-for-agenda org-todo-key-alist
))
14578 (setq org-drawers-for-agenda
14579 (append org-drawers-for-agenda org-drawers
))
14580 (setq org-tag-alist-for-agenda
14581 (append org-tag-alist-for-agenda org-tag-alist
))
14584 (remove-text-properties (point-min) (point-max) pall
)
14585 (when org-agenda-skip-archived-trees
14586 (goto-char (point-min))
14587 (while (re-search-forward rea nil t
)
14588 (if (org-on-heading-p t
)
14589 (add-text-properties (point-at-bol) (org-end-of-subtree t
) pa
))))
14590 (goto-char (point-min))
14591 (setq re
(concat "^\\*+ +" org-comment-string
"\\>"))
14592 (while (re-search-forward re nil t
)
14593 (add-text-properties
14594 (match-beginning 0) (org-end-of-subtree t
) pc
)))
14595 (set-buffer-modified-p bmp
)))))
14596 (setq org-todo-keyword-alist-for-agenda
14597 (org-uniquify org-todo-keyword-alist-for-agenda
)
14598 org-tag-alist-for-agenda
(org-uniquify org-tag-alist-for-agenda
))))
14600 ;;;; Embedded LaTeX
14602 (defvar org-cdlatex-mode-map
(make-sparse-keymap)
14603 "Keymap for the minor `org-cdlatex-mode'.")
14605 (org-defkey org-cdlatex-mode-map
"_" 'org-cdlatex-underscore-caret
)
14606 (org-defkey org-cdlatex-mode-map
"^" 'org-cdlatex-underscore-caret
)
14607 (org-defkey org-cdlatex-mode-map
"`" 'cdlatex-math-symbol
)
14608 (org-defkey org-cdlatex-mode-map
"'" 'org-cdlatex-math-modify
)
14609 (org-defkey org-cdlatex-mode-map
"\C-c{" 'cdlatex-environment
)
14611 (defvar org-cdlatex-texmathp-advice-is-done nil
14612 "Flag remembering if we have applied the advice to texmathp already.")
14614 (define-minor-mode org-cdlatex-mode
14615 "Toggle the minor `org-cdlatex-mode'.
14616 This mode supports entering LaTeX environment and math in LaTeX fragments
14618 \\{org-cdlatex-mode-map}"
14620 (when org-cdlatex-mode
(require 'cdlatex
))
14621 (unless org-cdlatex-texmathp-advice-is-done
14622 (setq org-cdlatex-texmathp-advice-is-done t
)
14623 (defadvice texmathp
(around org-math-always-on activate
)
14624 "Always return t in org-mode buffers.
14625 This is because we want to insert math symbols without dollars even outside
14626 the LaTeX math segments. If Orgmode thinks that point is actually inside
14627 an embedded LaTeX fragment, let texmathp do its job.
14628 \\[org-cdlatex-mode-map]"
14632 ((not (org-mode-p)) ad-do-it
)
14633 ((eq this-command
'cdlatex-math-symbol
)
14634 (setq ad-return-value t
14635 texmathp-why
'("cdlatex-math-symbol in org-mode" .
0)))
14637 (let ((p (org-inside-LaTeX-fragment-p)))
14638 (if (and p
(member (car p
) (plist-get org-format-latex-options
:matchers
)))
14639 (setq ad-return-value t
14640 texmathp-why
'("Org-mode embedded math" .
0))
14641 (if p ad-do-it
)))))))))
14643 (defun turn-on-org-cdlatex ()
14644 "Unconditionally turn on `org-cdlatex-mode'."
14645 (org-cdlatex-mode 1))
14647 (defun org-inside-LaTeX-fragment-p ()
14648 "Test if point is inside a LaTeX fragment.
14649 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
14650 sequence appearing also before point.
14651 Even though the matchers for math are configurable, this function assumes
14652 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
14653 delimiters are skipped when they have been removed by customization.
14654 The return value is nil, or a cons cell with the delimiter and
14655 and the position of this delimiter.
14657 This function does a reasonably good job, but can locally be fooled by
14658 for example currency specifications. For example it will assume being in
14659 inline math after \"$22.34\". The LaTeX fragment formatter will only format
14660 fragments that are properly closed, but during editing, we have to live
14661 with the uncertainty caused by missing closing delimiters. This function
14662 looks only before point, not after."
14664 (let ((pos (point))
14665 (dodollar (member "$" (plist-get org-format-latex-options
:matchers
)))
14667 (re-search-backward (concat "^\\(" paragraph-start
"\\)") nil t
)
14669 dd-on str
(start 0) m re
)
14672 (setq str
(concat (buffer-substring lim
(point)) "\000 X$.")
14673 re
(nth 1 (assoc "$" org-latex-regexps
)))
14674 (while (string-match re str start
)
14676 ((= (match-end 0) (length str
))
14677 (throw 'exit
(cons "$" (+ lim
(match-beginning 0) 1))))
14678 ((= (match-end 0) (- (length str
) 5))
14680 (t (setq start
(match-end 0))))))
14681 (when (setq m
(re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t
))
14683 (and (match-beginning 1) (throw 'exit
(cons (match-string 1) m
)))
14684 (and (match-beginning 2) (throw 'exit nil
))
14686 (while (re-search-backward "\\$\\$" lim t
)
14687 (setq dd-on
(not dd-on
)))
14689 (if dd-on
(cons "$$" m
))))))
14691 (defun org-inside-latex-macro-p ()
14692 "Is point inside a LaTeX macro or its arguments?"
14695 "\\\\[a-zA-Z]+\\*?\\(\\[[^][\n{}]*\\]\\)?\\({[^{}\n]*}\\)?")))
14697 (defun org-try-cdlatex-tab ()
14698 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
14699 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
14700 - inside a LaTeX fragment, or
14701 - after the first word in a line, where an abbreviation expansion could
14702 insert a LaTeX environment."
14703 (when org-cdlatex-mode
14706 (skip-chars-backward "a-zA-Z0-9*")
14707 (skip-chars-backward " \t")
14710 ((org-inside-LaTeX-fragment-p)
14714 (defun org-cdlatex-underscore-caret (&optional arg
)
14715 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
14716 Revert to the normal definition outside of these fragments."
14718 (if (org-inside-LaTeX-fragment-p)
14719 (call-interactively 'cdlatex-sub-superscript
)
14720 (let (org-cdlatex-mode)
14721 (call-interactively (key-binding (vector last-input-event
))))))
14723 (defun org-cdlatex-math-modify (&optional arg
)
14724 "Execute `cdlatex-math-modify' in LaTeX fragments.
14725 Revert to the normal definition outside of these fragments."
14727 (if (org-inside-LaTeX-fragment-p)
14728 (call-interactively 'cdlatex-math-modify
)
14729 (let (org-cdlatex-mode)
14730 (call-interactively (key-binding (vector last-input-event
))))))
14732 (defvar org-latex-fragment-image-overlays nil
14733 "List of overlays carrying the images of latex fragments.")
14734 (make-variable-buffer-local 'org-latex-fragment-image-overlays
)
14736 (defun org-remove-latex-fragment-image-overlays ()
14737 "Remove all overlays with LaTeX fragment images in current buffer."
14738 (mapc 'org-delete-overlay org-latex-fragment-image-overlays
)
14739 (setq org-latex-fragment-image-overlays nil
))
14741 (defun org-preview-latex-fragment (&optional subtree
)
14742 "Preview the LaTeX fragment at point, or all locally or globally.
14743 If the cursor is in a LaTeX fragment, create the image and overlay
14744 it over the source code. If there is no fragment at point, display
14745 all fragments in the current text, from one headline to the next. With
14746 prefix SUBTREE, display all fragments in the current subtree. With a
14747 double prefix `C-u C-u', or when the cursor is before the first headline,
14748 display all fragments in the buffer.
14749 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
14751 (org-remove-latex-fragment-image-overlays)
14754 (let (beg end at msg
)
14756 ((or (equal subtree
'(16))
14757 (not (save-excursion
14758 (re-search-backward (concat "^" outline-regexp
) nil t
))))
14759 (setq beg
(point-min) end
(point-max)
14760 msg
"Creating images for buffer...%s"))
14761 ((equal subtree
'(4))
14762 (org-back-to-heading)
14763 (setq beg
(point) end
(org-end-of-subtree t
)
14764 msg
"Creating images for subtree...%s"))
14766 (if (setq at
(org-inside-LaTeX-fragment-p))
14767 (goto-char (max (point-min) (- (cdr at
) 2)))
14768 (org-back-to-heading))
14769 (setq beg
(point) end
(progn (outline-next-heading) (point))
14770 msg
(if at
"Creating image...%s"
14771 "Creating images for entry...%s"))))
14773 (narrow-to-region beg end
)
14776 (concat "ltxpng/" (file-name-sans-extension
14777 (file-name-nondirectory
14778 buffer-file-name
)))
14779 default-directory
'overlays msg at
'forbuffer
)
14780 (message msg
"done. Use `C-c C-c' to remove images.")))))
14782 (defvar org-latex-regexps
14783 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t
)
14784 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
14785 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
14786 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
14787 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
14788 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil
)
14789 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil
)
14790 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil
))
14791 "Regular expressions for matching embedded LaTeX.")
14793 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer
)
14794 "Replace LaTeX fragments with links to an image, and produce images.
14795 Some of the options can be changed using the variable
14796 `org-format-latex-options'."
14797 (if (and overlays
(fboundp 'clear-image-cache
)) (clear-image-cache))
14798 (let* ((prefixnodir (file-name-nondirectory prefix
))
14799 (absprefix (expand-file-name prefix dir
))
14800 (todir (file-name-directory absprefix
))
14801 (opt org-format-latex-options
)
14802 (matchers (plist-get opt
:matchers
))
14803 (re-list org-latex-regexps
)
14804 (org-format-latex-header-extra
14805 (plist-get (org-infile-export-plist) :latex-header-extra
))
14806 (cnt 0) txt hash link beg end re e checkdir
14807 executables-checked
14808 m n block linkfile movefile ov
)
14809 ;; Check the different regular expressions
14810 (while (setq e
(pop re-list
))
14811 (setq m
(car e
) re
(nth 1 e
) n
(nth 2 e
)
14812 block
(if (nth 3 e
) "\n\n" ""))
14813 (when (member m matchers
)
14814 (goto-char (point-min))
14815 (while (re-search-forward re nil t
)
14816 (when (and (or (not at
) (equal (cdr at
) (match-beginning n
)))
14817 (not (get-text-property (match-beginning n
)
14820 (not (eq (get-char-property (match-beginning n
)
14822 'org-latex-overlay
))))
14823 (setq txt
(match-string n
)
14824 beg
(match-beginning n
) end
(match-end n
)
14826 (let (print-length print-level
) ; make sure full list is printed
14827 (setq hash
(sha1 (prin1-to-string
14828 (list org-format-latex-header
14829 org-format-latex-header-extra
14830 org-export-latex-packages-alist
14831 org-format-latex-options
14833 linkfile
(format "%s_%s.png" prefix hash
)
14834 movefile
(format "%s_%s.png" absprefix hash
)))
14835 (setq link
(concat block
"[[file:" linkfile
"]]" block
))
14836 (if msg
(message msg cnt
))
14838 (unless checkdir
; make sure the directory exists
14840 (or (file-directory-p todir
) (make-directory todir
)))
14842 (unless executables-checked
14843 (org-check-external-command
14844 "latex" "needed to convert LaTeX fragments to images")
14845 (org-check-external-command
14846 "dvipng" "needed to convert LaTeX fragments to images")
14847 (setq executables-checked t
))
14849 (unless (file-exists-p movefile
)
14850 (org-create-formula-image
14851 txt movefile opt forbuffer
))
14855 (if (eq (org-overlay-get o
'org-overlay-type
)
14856 'org-latex-overlay
)
14857 (org-delete-overlay o
)))
14858 (org-overlays-in beg end
))
14859 (setq ov
(org-make-overlay beg end
))
14860 (org-overlay-put ov
'org-overlay-type
'org-latex-overlay
)
14861 (if (featurep 'xemacs
)
14863 (org-overlay-put ov
'invisible t
)
14866 (make-glyph (vector 'png
:file movefile
))))
14869 (list 'image
:type
'png
:file movefile
:ascent
'center
)))
14870 (push ov org-latex-fragment-image-overlays
)
14872 (delete-region beg end
)
14873 (insert link
))))))))
14875 ;; This function borrows from Ganesh Swami's latex2png.el
14876 (defun org-create-formula-image (string tofile options buffer
)
14877 "This calls dvipng."
14878 (require 'org-latex
)
14879 (let* ((tmpdir (if (featurep 'xemacs
)
14881 temporary-file-directory
))
14882 (texfilebase (make-temp-name
14883 (expand-file-name "orgtex" tmpdir
)))
14884 (texfile (concat texfilebase
".tex"))
14885 (dvifile (concat texfilebase
".dvi"))
14886 (pngfile (concat texfilebase
".png"))
14887 (fnh (if (featurep 'xemacs
)
14888 (font-height (get-face-font 'default
))
14889 (face-attribute 'default
:height nil
)))
14890 (scale (or (plist-get options
(if buffer
:scale
:html-scale
)) 1.0))
14891 (dpi (number-to-string (* scale
(floor (* 0.9 (if buffer fnh
140.
))))))
14892 (fg (or (plist-get options
(if buffer
:foreground
:html-foreground
))
14894 (bg (or (plist-get options
(if buffer
:background
:html-background
))
14896 (if (eq fg
'default
) (setq fg
(org-dvipng-color :foreground
)))
14897 (if (eq bg
'default
) (setq bg
(org-dvipng-color :background
)))
14898 (with-temp-file texfile
14899 (insert org-format-latex-header
14900 (if org-export-latex-packages-alist
14902 (mapconcat (lambda(p)
14903 (if (equal "" (car p
))
14904 (format "\\usepackage{%s}" (cadr p
))
14905 (format "\\usepackage[%s]{%s}"
14906 (car p
) (cadr p
))))
14907 org-export-latex-packages-alist
"\n"))
14909 (if org-format-latex-header-extra
14910 (concat "\n" org-format-latex-header-extra
)
14912 "\n\\begin{document}\n" string
"\n\\end{document}\n"))
14913 (let ((dir default-directory
))
14914 (condition-case nil
14917 (call-process "latex" nil nil nil texfile
))
14920 (if (not (file-exists-p dvifile
))
14921 (progn (message "Failed to create dvi file from %s" texfile
) nil
)
14922 (condition-case nil
14923 (call-process "dvipng" nil nil nil
14926 ;;"-x" scale "-y" scale
14931 (if (not (file-exists-p pngfile
))
14932 (progn (message "Failed to create png file from %s" texfile
) nil
)
14933 ;; Use the requested file name and clean up
14934 (copy-file pngfile tofile
'replace
)
14935 (loop for e in
'(".dvi" ".tex" ".aux" ".log" ".png") do
14936 (delete-file (concat texfilebase e
)))
14939 (defun org-dvipng-color (attr)
14940 "Return an rgb color specification for dvipng."
14941 (apply 'format
"rgb %s %s %s"
14942 (mapcar 'org-normalize-color
14943 (color-values (face-attribute 'default attr nil
)))))
14945 (defun org-normalize-color (value)
14946 "Return string to be used as color value for an RGB component."
14947 (format "%g" (/ value
65535.0)))
14951 ;; Make `C-c C-x' a prefix key
14952 (org-defkey org-mode-map
"\C-c\C-x" (make-sparse-keymap))
14954 ;; TAB key with modifiers
14955 (org-defkey org-mode-map
"\C-i" 'org-cycle
)
14956 (org-defkey org-mode-map
[(tab)] 'org-cycle
)
14957 (org-defkey org-mode-map
[(control tab
)] 'org-force-cycle-archived
)
14958 (org-defkey org-mode-map
[(meta tab
)] 'org-complete
)
14959 (org-defkey org-mode-map
"\M-\t" 'org-complete
)
14960 (org-defkey org-mode-map
"\M-\C-i" 'org-complete
)
14961 ;; The following line is necessary under Suse GNU/Linux
14962 (unless (featurep 'xemacs
)
14963 (org-defkey org-mode-map
[S-iso-lefttab
] 'org-shifttab
))
14964 (org-defkey org-mode-map
[(shift tab
)] 'org-shifttab
)
14965 (define-key org-mode-map
[backtab] 'org-shifttab)
14967 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
14968 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
14969 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
14971 ;; Cursor keys with modifiers
14972 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
14973 (org-defkey org-mode-map [(meta right)] 'org-metaright)
14974 (org-defkey org-mode-map [(meta up)] 'org-metaup)
14975 (org-defkey org-mode-map [(meta down)] 'org-metadown)
14977 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
14978 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
14979 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
14980 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
14982 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
14983 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
14984 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
14985 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
14987 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
14988 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
14990 ;;; Extra keys for tty access.
14991 ;; We only set them when really needed because otherwise the
14992 ;; menus don't show the simple keys
14994 (when (or org-use-extra-keys
14995 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
14996 (not window-system))
14997 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
14998 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
14999 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
15000 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
15001 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
15002 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
15003 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
15004 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
15005 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
15006 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
15007 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
15008 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
15009 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
15010 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
15011 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
15012 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
15013 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
15014 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
15015 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
15016 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
15017 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
15018 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
15019 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
15020 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
15021 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
15022 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
15023 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
15024 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
15026 ;; All the other keys
15028 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
15029 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
15030 (if (boundp 'narrow-map)
15031 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
15032 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
15033 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
15034 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
15035 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
15036 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
15037 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
15038 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
15039 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
15040 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
15041 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
15042 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
15043 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
15044 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
15045 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
15046 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
15047 (org-defkey org-mode-map "\C-c\C-v" 'org-show-todo-tree)
15048 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
15049 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
15050 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
15051 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
15052 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
15053 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
15054 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
15055 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
15056 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
15057 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
15058 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
15059 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
15060 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
15061 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
15062 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
15063 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
15064 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
15065 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
15066 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
15067 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
15068 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
15069 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
15070 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
15071 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
15072 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
15073 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
15074 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
15075 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
15076 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
15077 (org-defkey org-mode-map "\C-c^" 'org-sort)
15078 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
15079 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
15080 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
15081 (org-defkey org-mode-map "\C-m" 'org-return)
15082 (org-defkey org-mode-map "\C-j" 'org-return-indent)
15083 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
15084 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
15085 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
15086 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
15087 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
15088 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
15089 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
15090 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
15091 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
15092 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
15093 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
15094 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
15095 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
15096 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
15097 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
15098 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
15099 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
15100 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
15101 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
15102 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
15104 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
15105 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
15106 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
15107 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
15109 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
15110 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
15111 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
15112 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
15113 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
15114 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
15115 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
15116 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
15117 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
15118 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
15119 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
15120 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
15121 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
15122 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
15123 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
15125 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
15126 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
15127 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
15128 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
15130 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
15132 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
15134 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
15135 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
15137 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
15140 (when (featurep 'xemacs)
15141 (org-defkey org-mode-map 'button3 'popup-mode-menu))
15144 (defconst org-speed-commands-default
15146 ("Outline Navigation")
15147 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
15148 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
15149 ("f" . (org-speed-move-safe 'org-forward-same-level))
15150 ("b" . (org-speed-move-safe 'org-backward-same-level))
15151 ("u" . (org-speed-move-safe 'outline-up-heading))
15153 ("g" . (org-refile t))
15154 ("Outline Visibility")
15156 ("C" . org-shifttab)
15157 (" " . org-display-outline-path)
15158 ("Outline Structure Editing")
15159 ("U" . org-shiftmetaup)
15160 ("D" . org-shiftmetadown)
15161 ("r" . org-metaright)
15162 ("l" . org-metaleft)
15163 ("R" . org-shiftmetaright)
15164 ("L" . org-shiftmetaleft)
15165 ("i" . (progn (forward-char 1) (call-interactively
15166 'org-insert-heading-respect-content)))
15169 ("a" . org-archive-subtree-default-with-confirmation)
15170 ("." . outline-mark-subtree)
15172 ("I" . org-clock-in)
15173 ("O" . org-clock-out)
15174 ("Meta Data Editing")
15176 ("0" . (org-priority ?\ ))
15177 ("1" . (org-priority ?A))
15178 ("2" . (org-priority ?B))
15179 ("3" . (org-priority ?C))
15180 (";" . org-set-tags-command)
15181 ("e" . org-set-effort)
15182 ("Agenda Views etc")
15184 ("/" . org-sparse-tree)
15186 ("o" . org-open-at-point)
15187 ("?" . org-speed-command-help)
15189 "The default speed commands.")
15191 (defun org-print-speed-command (e)
15192 (if (> (length (car e)) 1)
15197 (princ (make-string (length (car e)) ?-))
15201 (if (symbolp (cdr e))
15202 (princ (symbol-name (cdr e)))
15206 (defun org-speed-command-help ()
15207 "Show the available speed commands."
15209 (if (not org-use-speed-commands)
15210 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
15211 (with-output-to-temp-buffer "*Help*"
15212 (princ "User-defined Speed commands\n===========================\n")
15213 (mapc 'org-print-speed-command org-speed-commands-user)
15215 (princ "Built-in Speed commands\n=======================\n")
15216 (mapc 'org-print-speed-command org-speed-commands-default))
15217 (with-current-buffer "*Help*"
15218 (setq truncate-lines t))))
15220 (defun org-speed-move-safe (cmd)
15221 "Execute CMD, but make sure that the cursor always ends up in a headline.
15222 If not, return to the original position and throw an error."
15224 (let ((pos (point)))
15225 (call-interactively cmd)
15226 (unless (and (bolp) (org-on-heading-p))
15228 (error "Boundary reached while executing %s" cmd))))
15230 (defvar org-self-insert-command-undo-counter 0)
15232 (defvar org-table-auto-blank-field) ; defined in org-table.el
15233 (defvar org-speed-command nil)
15234 (defun org-self-insert-command (N)
15235 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
15236 If the cursor is in a table looking at whitespace, the whitespace is
15237 overwritten, and the table is not marked as requiring realignment."
15240 ((and org-use-speed-commands
15241 (or (and (bolp) (looking-at outline-regexp))
15242 (and (functionp org-use-speed-commands)
15243 (funcall org-use-speed-commands)))
15246 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
15247 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
15249 ((commandp org-speed-command)
15250 (setq this-command org-speed-command)
15251 (call-interactively org-speed-command))
15252 ((functionp org-speed-command)
15253 (funcall org-speed-command))
15254 ((and org-speed-command (listp org-speed-command))
15255 (eval org-speed-command))
15256 (t (let (org-use-speed-commands)
15257 (call-interactively 'org-self-insert-command)))))
15261 ;; check if we blank the field, and if that triggers align
15262 (and (featurep 'org-table) org-table-auto-blank-field
15263 (member last-command
15264 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
15265 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
15266 ;; got extra space, this field does not determine column width
15267 (let (org-table-may-need-update) (org-table-blank-field))
15268 ;; no extra space, this field may determine column width
15269 (org-table-blank-field)))
15272 (looking-at "[^|\n]* |"))
15273 (let (org-table-may-need-update)
15274 (goto-char (1- (match-end 0)))
15275 (delete-backward-char 1)
15276 (goto-char (match-beginning 0))
15277 (self-insert-command N)))
15279 (setq org-table-may-need-update t)
15280 (self-insert-command N)
15281 (org-fix-tags-on-the-fly)
15282 (if org-self-insert-cluster-for-undo
15283 (if (not (eq last-command 'org-self-insert-command))
15284 (setq org-self-insert-command-undo-counter 1)
15285 (if (>= org-self-insert-command-undo-counter 20)
15286 (setq org-self-insert-command-undo-counter 1)
15287 (and (> org-self-insert-command-undo-counter 0)
15289 (not (cadr buffer-undo-list)) ; remove nil entry
15290 (setcdr buffer-undo-list (cddr buffer-undo-list)))
15291 (setq org-self-insert-command-undo-counter
15292 (1+ org-self-insert-command-undo-counter))))))))
15294 (defun org-fix-tags-on-the-fly ()
15295 (when (and (equal (char-after (point-at-bol)) ?*)
15296 (org-on-heading-p))
15297 (org-align-tags-here org-tags-column)))
15299 (defun org-delete-backward-char (N)
15300 "Like `delete-backward-char', insert whitespace at field end in tables.
15301 When deleting backwards, in tables this function will insert whitespace in
15302 front of the next \"|\" separator, to keep the table aligned. The table will
15303 still be marked for re-alignment if the field did fill the entire column,
15304 because, in this case the deletion might narrow the column."
15306 (if (and (org-table-p)
15308 (string-match "|" (buffer-substring (point-at-bol) (point)))
15309 (looking-at ".*?|"))
15310 (let ((pos (point))
15311 (noalign (looking-at "[^|\n\r]* |"))
15312 (c org-table-may-need-update))
15313 (backward-delete-char N)
15314 (skip-chars-forward "^|")
15316 (goto-char (1- pos))
15317 ;; noalign: if there were two spaces at the end, this field
15318 ;; does not determine the width of the column.
15319 (if noalign (setq org-table-may-need-update c)))
15320 (backward-delete-char N)
15321 (org-fix-tags-on-the-fly)))
15323 (defun org-delete-char (N)
15324 "Like `delete-char', but insert whitespace at field end in tables.
15325 When deleting characters, in tables this function will insert whitespace in
15326 front of the next \"|\" separator, to keep the table aligned. The table will
15327 still be marked for re-alignment if the field did fill the entire column,
15328 because, in this case the deletion might narrow the column."
15330 (if (and (org-table-p)
15332 (not (= (char-after) ?|))
15334 (if (looking-at ".*?|")
15335 (let ((pos (point))
15336 (noalign (looking-at "[^|\n\r]* |"))
15337 (c org-table-may-need-update))
15338 (replace-match (concat
15339 (substring (match-string 0) 1 -1)
15342 ;; noalign: if there were two spaces at the end, this field
15343 ;; does not determine the width of the column.
15344 (if noalign (setq org-table-may-need-update c)))
15347 (org-fix-tags-on-the-fly)))
15349 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
15350 (put 'org-self-insert-command 'delete-selection t)
15351 (put 'orgtbl-self-insert-command 'delete-selection t)
15352 (put 'org-delete-char 'delete-selection 'supersede)
15353 (put 'org-delete-backward-char 'delete-selection 'supersede)
15354 (put 'org-yank 'delete-selection 'yank)
15356 ;; Make `flyspell-mode' delay after some commands
15357 (put 'org-self-insert-command 'flyspell-delayed t)
15358 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
15359 (put 'org-delete-char 'flyspell-delayed t)
15360 (put 'org-delete-backward-char 'flyspell-delayed t)
15362 ;; Make pabbrev-mode expand after org-mode commands
15363 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
15364 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
15366 ;; How to do this: Measure non-white length of current string
15367 ;; If equal to column width, we should realign.
15369 (defun org-remap (map &rest commands)
15370 "In MAP, remap the functions given in COMMANDS.
15371 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
15374 (setq old (pop commands) new (pop commands))
15375 (if (fboundp 'command-remapping)
15376 (org-defkey map (vector 'remap old) new)
15377 (substitute-key-definition old new map global-map)))))
15379 (when (eq org-enable-table-editor 'optimized)
15380 ;; If the user wants maximum table support, we need to hijack
15381 ;; some standard editing functions
15382 (org-remap org-mode-map
15383 'self-insert-command 'org-self-insert-command
15384 'delete-char 'org-delete-char
15385 'delete-backward-char 'org-delete-backward-char)
15386 (org-defkey org-mode-map "|" 'org-force-self-insert))
15388 (defvar org-ctrl-c-ctrl-c-hook nil
15389 "Hook for functions attaching themselves to `C-c C-c'.
15390 This can be used to add additional functionality to the C-c C-c key which
15391 executes context-dependent commands.
15392 Each function will be called with no arguments. The function must check
15393 if the context is appropriate for it to act. If yes, it should do its
15394 thing and then return a non-nil value. If the context is wrong,
15395 just do nothing and return nil.")
15397 (defvar org-tab-first-hook nil
15398 "Hook for functions to attach themselves to TAB.
15399 See `org-ctrl-c-ctrl-c-hook' for more information.
15400 This hook runs as the first action when TAB is pressed, even before
15401 `org-cycle' messes around with the `outline-regexp' to cater for
15402 inline tasks and plain list item folding.
15403 If any function in this hook returns t, not other actions like table
15404 field motion visibility cycling will be done.")
15406 (defvar org-tab-after-check-for-table-hook nil
15407 "Hook for functions to attach themselves to TAB.
15408 See `org-ctrl-c-ctrl-c-hook' for more information.
15409 This hook runs after it has been established that the cursor is not in a
15410 table, but before checking if the cursor is in a headline or if global cycling
15412 If any function in this hook returns t, not other actions like visibility
15413 cycling will be done.")
15415 (defvar org-tab-after-check-for-cycling-hook nil
15416 "Hook for functions to attach themselves to TAB.
15417 See `org-ctrl-c-ctrl-c-hook' for more information.
15418 This hook runs after it has been established that not table field motion and
15419 not visibility should be done because of current context. This is probably
15420 the place where a package like yasnippets can hook in.")
15422 (defvar org-tab-before-tab-emulation-hook nil
15423 "Hook for functions to attach themselves to TAB.
15424 See `org-ctrl-c-ctrl-c-hook' for more information.
15425 This hook runs after every other options for TAB have been exhausted, but
15426 before indentation and \t insertion takes place.")
15428 (defvar org-metaleft-hook nil
15429 "Hook for functions attaching themselves to `M-left'.
15430 See `org-ctrl-c-ctrl-c-hook' for more information.")
15431 (defvar org-metaright-hook nil
15432 "Hook for functions attaching themselves to `M-right'.
15433 See `org-ctrl-c-ctrl-c-hook' for more information.")
15434 (defvar org-metaup-hook nil
15435 "Hook for functions attaching themselves to `M-up'.
15436 See `org-ctrl-c-ctrl-c-hook' for more information.")
15437 (defvar org-metadown-hook nil
15438 "Hook for functions attaching themselves to `M-down'.
15439 See `org-ctrl-c-ctrl-c-hook' for more information.")
15440 (defvar org-shiftmetaleft-hook nil
15441 "Hook for functions attaching themselves to `M-S-left'.
15442 See `org-ctrl-c-ctrl-c-hook' for more information.")
15443 (defvar org-shiftmetaright-hook nil
15444 "Hook for functions attaching themselves to `M-S-right'.
15445 See `org-ctrl-c-ctrl-c-hook' for more information.")
15446 (defvar org-shiftmetaup-hook nil
15447 "Hook for functions attaching themselves to `M-S-up'.
15448 See `org-ctrl-c-ctrl-c-hook' for more information.")
15449 (defvar org-shiftmetadown-hook nil
15450 "Hook for functions attaching themselves to `M-S-down'.
15451 See `org-ctrl-c-ctrl-c-hook' for more information.")
15452 (defvar org-metareturn-hook nil
15453 "Hook for functions attaching themselves to `M-RET'.
15454 See `org-ctrl-c-ctrl-c-hook' for more information.")
15456 (defun org-modifier-cursor-error ()
15457 "Throw an error, a modified cursor command was applied in wrong context."
15458 (error "This command is active in special context like tables, headlines or items"))
15460 (defun org-shiftselect-error ()
15461 "Throw an error because Shift-Cursor command was applied in wrong context."
15462 (if (and (boundp 'shift-select-mode) shift-select-mode)
15463 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
15464 (error "This command works only in special context like headlines or timestamps")))
15466 (defun org-call-for-shift-select (cmd)
15467 (let ((this-command-keys-shift-translated t))
15468 (call-interactively cmd)))
15470 (defun org-shifttab (&optional arg)
15471 "Global visibility cycling or move to previous table field.
15472 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
15474 See the individual commands for more information."
15477 ((org-at-table-p) (call-interactively 'org-table-previous-field))
15479 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
15480 (message "Content view to level: %d" arg)
15481 (org-content (prefix-numeric-value arg2))
15482 (setq org-cycle-global-status 'overview)))
15483 (t (call-interactively 'org-global-cycle))))
15485 (defun org-shiftmetaleft ()
15486 "Promote subtree or delete table column.
15487 Calls `org-promote-subtree', `org-outdent-item',
15488 or `org-table-delete-column', depending on context.
15489 See the individual commands for more information."
15492 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
15493 ((org-at-table-p) (call-interactively 'org-table-delete-column))
15494 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
15495 ((org-at-item-p) (call-interactively 'org-outdent-item))
15496 (t (org-modifier-cursor-error))))
15498 (defun org-shiftmetaright ()
15499 "Demote subtree or insert table column.
15500 Calls `org-demote-subtree', `org-indent-item',
15501 or `org-table-insert-column', depending on context.
15502 See the individual commands for more information."
15505 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
15506 ((org-at-table-p) (call-interactively 'org-table-insert-column))
15507 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
15508 ((org-at-item-p) (call-interactively 'org-indent-item))
15509 (t (org-modifier-cursor-error))))
15511 (defun org-shiftmetaup (&optional arg)
15512 "Move subtree up or kill table row.
15513 Calls `org-move-subtree-up' or `org-table-kill-row' or
15514 `org-move-item-up' depending on context. See the individual commands
15515 for more information."
15518 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
15519 ((org-at-table-p) (call-interactively 'org-table-kill-row))
15520 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
15521 ((org-at-item-p) (call-interactively 'org-move-item-up))
15522 (t (org-modifier-cursor-error))))
15524 (defun org-shiftmetadown (&optional arg)
15525 "Move subtree down or insert table row.
15526 Calls `org-move-subtree-down' or `org-table-insert-row' or
15527 `org-move-item-down', depending on context. See the individual
15528 commands for more information."
15531 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
15532 ((org-at-table-p) (call-interactively 'org-table-insert-row))
15533 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
15534 ((org-at-item-p) (call-interactively 'org-move-item-down))
15535 (t (org-modifier-cursor-error))))
15537 (defun org-metaleft (&optional arg)
15538 "Promote heading or move table column to left.
15539 Calls `org-do-promote' or `org-table-move-column', depending on context.
15540 With no specific context, calls the Emacs default `backward-word'.
15541 See the individual commands for more information."
15544 ((run-hook-with-args-until-success 'org-metaleft-hook))
15545 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
15546 ((or (org-on-heading-p)
15547 (and (org-region-active-p)
15549 (goto-char (region-beginning))
15550 (org-on-heading-p))))
15551 (call-interactively 'org-do-promote))
15552 ((or (org-at-item-p)
15553 (and (org-region-active-p)
15555 (goto-char (region-beginning))
15557 (call-interactively 'org-outdent-item))
15558 (t (call-interactively 'backward-word))))
15560 (defun org-metaright (&optional arg)
15561 "Demote subtree or move table column to right.
15562 Calls `org-do-demote' or `org-table-move-column', depending on context.
15563 With no specific context, calls the Emacs default `forward-word'.
15564 See the individual commands for more information."
15567 ((run-hook-with-args-until-success 'org-metaright-hook))
15568 ((org-at-table-p) (call-interactively 'org-table-move-column))
15569 ((or (org-on-heading-p)
15570 (and (org-region-active-p)
15572 (goto-char (region-beginning))
15573 (org-on-heading-p))))
15574 (call-interactively 'org-do-demote))
15575 ((or (org-at-item-p)
15576 (and (org-region-active-p)
15578 (goto-char (region-beginning))
15580 (call-interactively 'org-indent-item))
15581 (t (call-interactively 'forward-word))))
15583 (defun org-metaup (&optional arg)
15584 "Move subtree up or move table row up.
15585 Calls `org-move-subtree-up' or `org-table-move-row' or
15586 `org-move-item-up', depending on context. See the individual commands
15587 for more information."
15590 ((run-hook-with-args-until-success 'org-metaup-hook))
15591 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
15592 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
15593 ((org-at-item-p) (call-interactively 'org-move-item-up))
15594 (t (transpose-lines 1) (beginning-of-line -1))))
15596 (defun org-metadown (&optional arg)
15597 "Move subtree down or move table row down.
15598 Calls `org-move-subtree-down' or `org-table-move-row' or
15599 `org-move-item-down', depending on context. See the individual
15600 commands for more information."
15603 ((run-hook-with-args-until-success 'org-metadown-hook))
15604 ((org-at-table-p) (call-interactively 'org-table-move-row))
15605 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
15606 ((org-at-item-p) (call-interactively 'org-move-item-down))
15607 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
15609 (defun org-shiftup (&optional arg)
15610 "Increase item in timestamp or increase priority of current headline.
15611 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
15612 depending on context. See the individual commands for more information."
15615 ((and org-support-shift-select (org-region-active-p))
15616 (org-call-for-shift-select 'previous-line))
15617 ((org-at-timestamp-p t)
15618 (call-interactively (if org-edit-timestamp-down-means-later
15619 'org-timestamp-down 'org-timestamp-up)))
15620 ((and (not (eq org-support-shift-select 'always))
15621 org-enable-priority-commands
15622 (org-on-heading-p))
15623 (call-interactively 'org-priority-up))
15624 ((and (not org-support-shift-select) (org-at-item-p))
15625 (call-interactively 'org-previous-item))
15626 ((org-clocktable-try-shift 'up arg))
15627 (org-support-shift-select
15628 (org-call-for-shift-select 'previous-line))
15629 (t (org-shiftselect-error))))
15631 (defun org-shiftdown (&optional arg)
15632 "Decrease item in timestamp or decrease priority of current headline.
15633 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
15634 depending on context. See the individual commands for more information."
15637 ((and org-support-shift-select (org-region-active-p))
15638 (org-call-for-shift-select 'next-line))
15639 ((org-at-timestamp-p t)
15640 (call-interactively (if org-edit-timestamp-down-means-later
15641 'org-timestamp-up 'org-timestamp-down)))
15642 ((and (not (eq org-support-shift-select 'always))
15643 org-enable-priority-commands
15644 (org-on-heading-p))
15645 (call-interactively 'org-priority-down))
15646 ((and (not org-support-shift-select) (org-at-item-p))
15647 (call-interactively 'org-next-item))
15648 ((org-clocktable-try-shift 'down arg))
15649 (org-support-shift-select
15650 (org-call-for-shift-select 'next-line))
15651 (t (org-shiftselect-error))))
15653 (defun org-shiftright (&optional arg)
15654 "Cycle the thing at point or in the current line, depending on context.
15655 Depending on context, this does one of the following:
15657 - switch a timestamp at point one day into the future
15658 - on a headline, switch to the next TODO keyword.
15659 - on an item, switch entire list to the next bullet type
15660 - on a property line, switch to the next allowed value
15661 - on a clocktable definition line, move time block into the future"
15664 ((and org-support-shift-select (org-region-active-p))
15665 (org-call-for-shift-select 'forward-char))
15666 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
15667 ((and (not (eq org-support-shift-select 'always))
15668 (org-on-heading-p))
15669 (let ((org-inhibit-logging
15670 (not org-treat-S-cursor-todo-selection-as-state-change))
15671 (org-inhibit-blocking
15672 (not org-treat-S-cursor-todo-selection-as-state-change)))
15673 (org-call-with-arg 'org-todo 'right)))
15674 ((or (and org-support-shift-select
15675 (not (eq org-support-shift-select 'always))
15676 (org-at-item-bullet-p))
15677 (and (not org-support-shift-select) (org-at-item-p)))
15678 (org-call-with-arg 'org-cycle-list-bullet nil))
15679 ((and (not (eq org-support-shift-select 'always))
15680 (org-at-property-p))
15681 (call-interactively 'org-property-next-allowed-value))
15682 ((org-clocktable-try-shift 'right arg))
15683 (org-support-shift-select
15684 (org-call-for-shift-select 'forward-char))
15685 (t (org-shiftselect-error))))
15687 (defun org-shiftleft (&optional arg)
15688 "Cycle the thing at point or in the current line, depending on context.
15689 Depending on context, this does one of the following:
15691 - switch a timestamp at point one day into the past
15692 - on a headline, switch to the previous TODO keyword.
15693 - on an item, switch entire list to the previous bullet type
15694 - on a property line, switch to the previous allowed value
15695 - on a clocktable definition line, move time block into the past"
15698 ((and org-support-shift-select (org-region-active-p))
15699 (org-call-for-shift-select 'backward-char))
15700 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
15701 ((and (not (eq org-support-shift-select 'always))
15702 (org-on-heading-p))
15703 (let ((org-inhibit-logging
15704 (not org-treat-S-cursor-todo-selection-as-state-change))
15705 (org-inhibit-blocking
15706 (not org-treat-S-cursor-todo-selection-as-state-change)))
15707 (org-call-with-arg 'org-todo 'left)))
15708 ((or (and org-support-shift-select
15709 (not (eq org-support-shift-select 'always))
15710 (org-at-item-bullet-p))
15711 (and (not org-support-shift-select) (org-at-item-p)))
15712 (org-call-with-arg 'org-cycle-list-bullet 'previous))
15713 ((and (not (eq org-support-shift-select 'always))
15714 (org-at-property-p))
15715 (call-interactively 'org-property-previous-allowed-value))
15716 ((org-clocktable-try-shift 'left arg))
15717 (org-support-shift-select
15718 (org-call-for-shift-select 'backward-char))
15719 (t (org-shiftselect-error))))
15721 (defun org-shiftcontrolright ()
15722 "Switch to next TODO set."
15725 ((and org-support-shift-select (org-region-active-p))
15726 (org-call-for-shift-select 'forward-word))
15727 ((and (not (eq org-support-shift-select 'always))
15728 (org-on-heading-p))
15729 (org-call-with-arg 'org-todo 'nextset))
15730 (org-support-shift-select
15731 (org-call-for-shift-select 'forward-word))
15732 (t (org-shiftselect-error))))
15734 (defun org-shiftcontrolleft ()
15735 "Switch to previous TODO set."
15738 ((and org-support-shift-select (org-region-active-p))
15739 (org-call-for-shift-select 'backward-word))
15740 ((and (not (eq org-support-shift-select 'always))
15741 (org-on-heading-p))
15742 (org-call-with-arg 'org-todo 'previousset))
15743 (org-support-shift-select
15744 (org-call-for-shift-select 'backward-word))
15745 (t (org-shiftselect-error))))
15747 (defun org-ctrl-c-ret ()
15748 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
15751 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
15752 (t (call-interactively 'org-insert-heading))))
15754 (defun org-copy-special ()
15755 "Copy region in table or copy current subtree.
15756 Calls `org-table-copy' or `org-copy-subtree', depending on context.
15757 See the individual commands for more information."
15759 (call-interactively
15760 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
15762 (defun org-cut-special ()
15763 "Cut region in table or cut current subtree.
15764 Calls `org-table-copy' or `org-cut-subtree', depending on context.
15765 See the individual commands for more information."
15767 (call-interactively
15768 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
15770 (defun org-paste-special (arg)
15771 "Paste rectangular region into table, or past subtree relative to level.
15772 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
15773 See the individual commands for more information."
15775 (if (org-at-table-p)
15776 (org-table-paste-rectangle)
15777 (org-paste-subtree arg)))
15779 (defun org-edit-special ()
15780 "Call a special editor for the stuff at point.
15781 When at a table, call the formula editor with `org-table-edit-formulas'.
15782 When at the first line of an src example, call `org-edit-src-code'.
15783 When in an #+include line, visit the include file. Otherwise call
15784 `ffap' to visit the file at point."
15788 (call-interactively 'org-table-edit-formulas))
15790 (beginning-of-line 1)
15791 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
15792 (find-file (org-trim (match-string 1))))
15793 ((org-edit-src-code))
15794 ((org-edit-fixed-width-region))
15795 (t (call-interactively 'ffap))))
15798 (defun org-ctrl-c-ctrl-c (&optional arg)
15799 "Set tags in headline, or update according to changed information at point.
15801 This command does many different things, depending on context:
15803 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
15804 this is what we do.
15806 - If the cursor is on a statistics cookie, update it.
15808 - If the cursor is in a headline, prompt for tags and insert them
15809 into the current line, aligned to `org-tags-column'. When called
15810 with prefix arg, realign all tags in the current buffer.
15812 - If the cursor is in one of the special #+KEYWORD lines, this
15813 triggers scanning the buffer for these lines and updating the
15816 - If the cursor is inside a table, realign the table. This command
15817 works even if the automatic table editor has been turned off.
15819 - If the cursor is on a #+TBLFM line, re-apply the formulas to
15822 - If the cursor is at a footnote reference or definition, jump to
15823 the corresponding definition or references, respectively.
15825 - If the cursor is a the beginning of a dynamic block, update it.
15827 - If the cursor is inside a table created by the table.el package,
15828 activate that table.
15830 - If the current buffer is a remember buffer, close note and file
15831 it. A prefix argument of 1 files to the default location
15832 without further interaction. A prefix argument of 2 files to
15833 the currently clocking task.
15835 - If the cursor is on a <<<target>>>, update radio targets and corresponding
15836 links in this buffer.
15838 - If the cursor is on a numbered item in a plain list, renumber the
15841 - If the cursor is on a checkbox, toggle it."
15843 (let ((org-enable-table-editor t))
15845 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
15846 org-occur-highlights
15847 org-latex-fragment-image-overlays)
15848 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
15849 (org-remove-occur-highlights)
15850 (org-remove-latex-fragment-image-overlays)
15851 (message "Temporary highlights/overlays removed from current buffer"))
15852 ((and (local-variable-p 'org-finish-function (current-buffer))
15853 (fboundp org-finish-function))
15854 (funcall org-finish-function))
15855 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
15856 ((org-at-property-p)
15857 (call-interactively 'org-property-action))
15858 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
15859 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
15860 (or (org-on-heading-p) (org-at-item-p)))
15861 (call-interactively 'org-update-statistics-cookies))
15862 ((org-on-heading-p) (call-interactively 'org-set-tags))
15863 ((org-at-table.el-p)
15865 (beginning-of-line 1)
15866 (re-search-forward "|" (save-excursion (end-of-line 2) (point)))
15867 (call-interactively 'table-recognize-table))
15869 (org-table-maybe-eval-formula)
15871 (call-interactively 'org-table-recalculate)
15872 (org-table-maybe-recalculate-line))
15873 (call-interactively 'org-table-align))
15874 ((or (org-footnote-at-reference-p)
15875 (org-footnote-at-definition-p))
15876 (call-interactively 'org-footnote-action))
15877 ((org-at-item-checkbox-p)
15878 (call-interactively 'org-toggle-checkbox))
15881 (call-interactively 'org-toggle-checkbox)
15882 (call-interactively 'org-maybe-renumber-ordered-list)))
15883 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
15885 (beginning-of-line 1)
15886 (save-excursion (org-update-dblock)))
15888 (beginning-of-line 1)
15889 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
15891 ((equal (match-string 1) "TBLFM")
15892 ;; Recalculate the table before this line
15894 (beginning-of-line 1)
15895 (skip-chars-backward " \r\n\t")
15896 (if (org-at-table-p)
15897 (org-call-with-arg 'org-table-recalculate (or arg t)))))
15899 (let ((org-inhibit-startup-visibility-stuff t)
15900 (org-startup-align-all-tables nil))
15901 (org-save-outline-visibility 'use-markers (org-mode-restart)))
15902 (message "Local setup has been refreshed"))))
15903 ((org-clock-update-time-maybe))
15904 (t (error "C-c C-c can do nothing useful at this location")))))
15906 (defun org-mode-restart ()
15907 "Restart Org-mode, to scan again for special lines.
15908 Also updates the keyword regular expressions."
15911 (message "Org-mode restarted"))
15913 (defun org-kill-note-or-show-branches ()
15914 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
15916 (if (not org-finish-function)
15917 (call-interactively 'show-branches)
15918 (let ((org-note-abort t))
15919 (funcall org-finish-function))))
15921 (defun org-return (&optional indent)
15922 "Goto next table row or insert a newline.
15923 Calls `org-table-next-row' or `newline', depending on context.
15924 See the individual commands for more information."
15927 ((bobp) (if indent (newline-and-indent) (newline)))
15929 (org-table-justify-field-maybe)
15930 (call-interactively 'org-table-next-row))
15931 ((and org-return-follows-link
15932 (eq (get-text-property (point) 'face) 'org-link))
15933 (call-interactively 'org-open-at-point))
15934 ((and (org-at-heading-p)
15936 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
15940 (t (if indent (newline-and-indent) (newline)))))
15942 (defun org-return-indent ()
15943 "Goto next table row or insert a newline and indent.
15944 Calls `org-table-next-row' or `newline-and-indent', depending on
15945 context. See the individual commands for more information."
15949 (defun org-ctrl-c-star ()
15950 "Compute table, or change heading status of lines.
15951 Calls `org-table-recalculate' or `org-toggle-heading',
15952 depending on context."
15956 (call-interactively 'org-table-recalculate))
15958 ;; Convert all lines in region to list items
15959 (call-interactively 'org-toggle-heading))))
15961 (defun org-ctrl-c-minus ()
15962 "Insert separator line in table or modify bullet status of line.
15963 Also turns a plain line or a region of lines into list items.
15964 Calls `org-table-insert-hline', `org-toggle-item', or
15965 `org-cycle-list-bullet', depending on context."
15969 (call-interactively 'org-table-insert-hline))
15970 ((org-region-active-p)
15971 (call-interactively 'org-toggle-item))
15973 (call-interactively 'org-cycle-list-bullet))
15975 (call-interactively 'org-toggle-item))))
15977 (defun org-toggle-item ()
15978 "Convert headings or normal lines to items, items to normal lines.
15979 If there is no active region, only the current line is considered.
15981 If the first line in the region is a headline, convert all headlines to items.
15983 If the first line in the region is an item, convert all items to normal lines.
15985 If the first line is normal text, add an item bullet to each line."
15987 (let (l2 l beg end)
15988 (if (org-region-active-p)
15989 (setq beg (region-beginning) end (region-end))
15990 (setq beg (point-at-bol)
15991 end (min (1+ (point-at-eol)) (point-max))))
15994 (setq l2 (org-current-line))
15996 (beginning-of-line 1)
15997 (setq l (1- (org-current-line)))
15998 (if (org-at-item-p)
15999 ;; We already have items, de-itemize
16000 (while (< (setq l (1+ l)) l2)
16001 (when (org-at-item-p)
16002 (goto-char (match-beginning 2))
16003 (delete-region (match-beginning 2) (match-end 2))
16004 (and (looking-at "[ \t]+") (replace-match "")))
16005 (beginning-of-line 2))
16006 (if (org-on-heading-p)
16007 ;; Headings, convert to items
16008 (while (< (setq l (1+ l)) l2)
16009 (if (looking-at org-outline-regexp)
16010 (replace-match "- " t t))
16011 (beginning-of-line 2))
16012 ;; normal lines, turn them into items
16013 (while (< (setq l (1+ l)) l2)
16014 (unless (org-at-item-p)
16015 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16016 (replace-match "\\1- \\2")))
16017 (beginning-of-line 2)))))))
16019 (defun org-toggle-heading (&optional nstars)
16020 "Convert headings to normal text, or items or text to headings.
16021 If there is no active region, only the current line is considered.
16023 If the first line is a heading, remove the stars from all headlines
16026 If the first line is a plain list item, turn all plain list items
16029 If the first line is a normal line, turn each and every line in the
16030 region into a heading.
16032 When converting a line into a heading, the number of stars is chosen
16033 such that the lines become children of the current entry. However,
16034 when a prefix argument is given, its value determines the number of
16037 (let (l2 l itemp beg end)
16038 (if (org-region-active-p)
16039 (setq beg (region-beginning) end (region-end))
16040 (setq beg (point-at-bol)
16041 end (min (1+ (point-at-eol)) (point-max))))
16044 (setq l2 (org-current-line))
16046 (beginning-of-line 1)
16047 (setq l (1- (org-current-line)))
16048 (if (org-on-heading-p)
16049 ;; We already have headlines, de-star them
16050 (while (< (setq l (1+ l)) l2)
16051 (when (org-on-heading-p t)
16052 (and (looking-at outline-regexp) (replace-match "")))
16053 (beginning-of-line 2))
16054 (setq itemp (org-at-item-p))
16057 (make-string (prefix-numeric-value current-prefix-arg)
16060 (if (re-search-backward org-complex-heading-regexp nil t)
16061 (match-string 1) ""))))
16062 (add-stars (cond (nstars "")
16063 ((equal stars "") "*")
16064 (org-odd-levels-only "**")
16066 (rpl (concat stars add-stars " ")))
16067 (while (< (setq l (1+ l)) l2)
16069 (and (org-at-item-p) (replace-match rpl t t))
16070 (unless (org-on-heading-p)
16071 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16072 (replace-match (concat rpl (match-string 2))))))
16073 (beginning-of-line 2)))))))
16075 (defun org-meta-return (&optional arg)
16076 "Insert a new heading or wrap a region in a table.
16077 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
16078 See the individual commands for more information."
16081 ((run-hook-with-args-until-success 'org-metareturn-hook))
16083 (call-interactively 'org-table-wrap-region))
16084 (t (call-interactively 'org-insert-heading))))
16088 ;; Define the Org-mode menus
16089 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
16091 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
16092 ["Next Field" org-cycle (org-at-table-p)]
16093 ["Previous Field" org-shifttab (org-at-table-p)]
16094 ["Next Row" org-return (org-at-table-p)]
16096 ["Blank Field" org-table-blank-field (org-at-table-p)]
16097 ["Edit Field" org-table-edit-field (org-at-table-p)]
16098 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
16101 ["Move Column Left" org-metaleft (org-at-table-p)]
16102 ["Move Column Right" org-metaright (org-at-table-p)]
16103 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
16104 ["Insert Column" org-shiftmetaright (org-at-table-p)])
16106 ["Move Row Up" org-metaup (org-at-table-p)]
16107 ["Move Row Down" org-metadown (org-at-table-p)]
16108 ["Delete Row" org-shiftmetaup (org-at-table-p)]
16109 ["Insert Row" org-shiftmetadown (org-at-table-p)]
16110 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
16112 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
16114 ["Copy Rectangle" org-copy-special (org-at-table-p)]
16115 ["Cut Rectangle" org-cut-special (org-at-table-p)]
16116 ["Paste Rectangle" org-paste-special (org-at-table-p)]
16117 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
16120 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
16121 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
16122 ["Edit Formulas" org-edit-special (org-at-table-p)]
16124 ["Recalculate line" org-table-recalculate (org-at-table-p)]
16125 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
16126 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
16128 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
16130 ["Sum Column/Rectangle" org-table-sum
16131 (or (org-at-table-p) (org-region-active-p))]
16132 ["Which Column?" org-table-current-column (org-at-table-p)])
16134 org-table-toggle-formula-debugger
16135 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
16136 ["Show Col/Row Numbers"
16137 org-table-toggle-coordinate-overlays
16139 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
16141 ["Create" org-table-create (and (not (org-at-table-p))
16142 org-enable-table-editor)]
16143 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
16144 ["Import from File" org-table-import (not (org-at-table-p))]
16145 ["Export to File" org-table-export (org-at-table-p)]
16147 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
16149 (easy-menu-define org-org-menu org-mode-map "Org menu"
16152 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
16153 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
16154 ["Sparse Tree..." org-sparse-tree t]
16155 ["Reveal Context" org-reveal t]
16156 ["Show All" show-all t]
16158 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
16160 ["New Heading" org-insert-heading t]
16161 ("Navigate Headings"
16162 ["Up" outline-up-heading t]
16163 ["Next" outline-next-visible-heading t]
16164 ["Previous" outline-previous-visible-heading t]
16165 ["Next Same Level" outline-forward-same-level t]
16166 ["Previous Same Level" outline-backward-same-level t]
16168 ["Jump" org-goto t])
16170 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
16171 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
16173 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
16174 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
16175 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
16177 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
16179 ["Promote Heading" org-metaleft (not (org-at-table-p))]
16180 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
16181 ["Demote Heading" org-metaright (not (org-at-table-p))]
16182 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
16184 ["Sort Region/Children" org-sort (not (org-at-table-p))]
16186 ["Convert to odd levels" org-convert-to-odd-levels t]
16187 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
16189 ["Emphasis..." org-emphasize t]
16190 ["Edit Source Example" org-edit-special t]
16192 ["Footnote new/jump" org-footnote-action t]
16193 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
16195 ["Archive (default method)" org-archive-subtree-default t]
16197 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
16198 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
16199 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
16203 ["Store Link (Global)" org-store-link t]
16204 ["Find existing link to here" org-occur-link-in-agenda-files t]
16205 ["Insert Link" org-insert-link t]
16206 ["Follow Link" org-open-at-point t]
16208 ["Next link" org-next-link t]
16209 ["Previous link" org-previous-link t]
16211 ["Descriptive Links"
16212 (progn (org-add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
16214 :selected (member '(org-link) buffer-invisibility-spec)]
16217 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
16219 :selected (not (member '(org-link) buffer-invisibility-spec))])
16222 ["TODO/DONE/-" org-todo t]
16224 ["Next keyword" org-shiftright (org-on-heading-p)]
16225 ["Previous keyword" org-shiftleft (org-on-heading-p)]
16226 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
16227 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
16228 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
16229 ["Show TODO Tree" org-show-todo-tree t]
16230 ["Global TODO list" org-todo-list t]
16232 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
16233 :selected org-enforce-todo-dependencies :style toggle :active t]
16234 "Settings for tree at point"
16235 ["Do Children sequentially" org-toggle-ordered-property :style radio
16236 :selected (ignore-errors (org-entry-get nil "ORDERED"))
16237 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16238 ["Do Children parallel" org-toggle-ordered-property :style radio
16239 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
16240 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16242 ["Set Priority" org-priority t]
16243 ["Priority Up" org-shiftup t]
16244 ["Priority Down" org-shiftdown t]
16246 ["Get news from all feeds" org-feed-update-all t]
16247 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
16248 ["Customize feeds" (customize-variable 'org-feed-alist) t])
16249 ("TAGS and Properties"
16250 ["Set Tags" org-set-tags-command t]
16251 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
16253 ["Set property" org-set-property t]
16254 ["Column view of properties" org-columns t]
16255 ["Insert Column View DBlock" org-insert-columns-dblock t])
16256 ("Dates and Scheduling"
16257 ["Timestamp" org-time-stamp t]
16258 ["Timestamp (inactive)" org-time-stamp-inactive t]
16260 ["1 Day Later" org-shiftright t]
16261 ["1 Day Earlier" org-shiftleft t]
16262 ["1 ... Later" org-shiftup t]
16263 ["1 ... Earlier" org-shiftdown t])
16264 ["Compute Time Range" org-evaluate-time-range t]
16265 ["Schedule Item" org-schedule t]
16266 ["Deadline" org-deadline t]
16268 ["Custom time format" org-toggle-time-stamp-overlays
16269 :style radio :selected org-display-custom-times]
16271 ["Goto Calendar" org-goto-calendar t]
16272 ["Date from Calendar" org-date-from-calendar t]
16274 ["Start/Restart Timer" org-timer-start t]
16275 ["Pause/Continue Timer" org-timer-pause-or-continue t]
16276 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
16277 ["Insert Timer String" org-timer t]
16278 ["Insert Timer Item" org-timer-item t])
16280 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
16281 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
16282 ["Clock out" org-clock-out t]
16283 ["Clock cancel" org-clock-cancel t]
16285 ["Mark as default task" org-clock-mark-default-task t]
16286 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
16287 ["Goto running clock" org-clock-goto t]
16289 ["Display times" org-clock-display t]
16290 ["Create clock table" org-clock-report t]
16292 ["Record DONE time"
16293 (progn (setq org-log-done (not org-log-done))
16294 (message "Switching to %s will %s record a timestamp"
16295 (car org-done-keywords)
16296 (if org-log-done "automatically" "not")))
16297 :style toggle :selected org-log-done])
16299 ["Agenda Command..." org-agenda t]
16300 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
16301 ("File List for Agenda")
16302 ("Special views current file"
16303 ["TODO Tree" org-show-todo-tree t]
16304 ["Check Deadlines" org-check-deadlines t]
16305 ["Timeline" org-timeline t]
16306 ["Tags/Property tree" org-match-sparse-tree t])
16308 ["Export/Publish..." org-export t]
16310 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
16311 :selected org-cdlatex-mode]
16312 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
16313 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
16314 ["Modify math symbol" org-cdlatex-math-modify
16315 (org-inside-LaTeX-fragment-p)]
16316 ["Insert citation" org-reftex-citation t]
16318 ["Export LaTeX fragments as images"
16319 (if (featurep 'org-exp)
16320 (setq org-export-with-LaTeX-fragments
16321 (not org-export-with-LaTeX-fragments))
16322 (require 'org-exp))
16323 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
16324 org-export-with-LaTeX-fragments)]
16326 ["Template for BEAMER" org-beamer-settings-template t])
16329 ["Push Files and Views" org-mobile-push t]
16330 ["Get Captured and Flagged" org-mobile-pull t]
16331 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
16333 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
16336 ["Show Version" org-version t]
16337 ["Info Documentation" org-info t])
16339 ["Browse Org Group" org-customize t]
16341 ["Expand This Menu" org-create-customize-menu
16342 (fboundp 'customize-menu-create)])
16343 ["Send bug report" org-submit-bug-report t]
16346 ["Refresh setup current buffer" org-mode-restart t]
16347 ["Reload Org (after update)" org-reload t]
16348 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
16351 (defun org-info (&optional node)
16352 "Read documentation for Org-mode in the info system.
16353 With optional NODE, go directly to that node."
16355 (info (format "(org)%s" (or node ""))))
16358 (defun org-submit-bug-report ()
16359 "Submit a bug report on Org-mode via mail.
16361 Don't hesitate to report any problems or inaccurate documentation.
16363 If you don't have setup sending mail from (X)Emacs, please copy the
16364 output buffer into your mail program, as it gives us important
16365 information about your Org-mode version and configuration."
16367 (require 'reporter)
16368 (org-load-modules-maybe)
16369 (org-require-autoloaded-modules)
16370 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
16371 (reporter-submit-bug-report
16372 "emacs-orgmode@gnu.org"
16375 (save-window-excursion
16376 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
16377 (delete-other-windows)
16379 (insert "You are about to submit a bug report to the Org-mode mailing list.
16381 We would like to add your full Org-mode and Outline configuration to the
16382 bug report. This greatly simplifies the work of the maintainer and
16383 other experts on the mailing list.
16385 HOWEVER, some variables you have customized may contain private
16386 information. The names of customers, colleagues, or friends, might
16387 appear in the form of file names, tags, todo states, or search strings.
16388 If you answer yes to the prompt, you might want to check and remove
16389 such private information before sending the email.")
16390 (add-text-properties (point-min) (point-max) '(face org-warning))
16391 (when (yes-or-no-p "Include your Org-mode configuration ")
16395 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
16396 (or (and (symbol-value v)
16397 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
16399 (get v 'custom-type) (get v 'standard-value)
16400 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
16402 (kill-buffer (get-buffer "*Warn about privacy*"))
16405 "Remember to cover the basics, that is, what you expected to happen and
16406 what in fact did happen. You don't know how to make a good report? See
16408 http://orgmode.org/manual/Feedback.html#Feedback
16410 Your bug report will be posted to the Org-mode mailing list.
16411 ------------------------------------------------------------------------")
16413 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
16414 (replace-match "\\1Bug: \\3 [\\2]")))))
16417 (defun org-install-agenda-files-menu ()
16418 (let ((bl (buffer-list)))
16421 (set-buffer (pop bl))
16422 (if (org-mode-p) (setq bl nil)))
16425 '("Org") "File List for Agenda"
16428 ["Edit File List" (org-edit-agenda-file-list) t]
16429 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
16430 ["Remove Current File from List" org-remove-file t]
16431 ["Cycle through agenda files" org-cycle-agenda-files t]
16432 ["Occur in all agenda files" org-occur-in-agenda-files t]
16434 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
16439 (defun org-require-autoloaded-modules ()
16442 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
16443 org-docbook org-exp org-html org-icalendar
16445 org-publish org-remember org-table
16446 org-timer org-xoxo)))
16449 (defun org-reload (&optional uncompiled)
16450 "Reload all org lisp files.
16451 With prefix arg UNCOMPILED, load the uncompiled versions."
16453 (require 'find-func)
16454 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
16455 (dir-org (file-name-directory (org-find-library-name "org")))
16456 (dir-org-contrib (ignore-errors
16457 (file-name-directory
16458 (org-find-library-name "org-contribdir"))))
16460 (append (directory-files dir-org t file-re)
16461 (and dir-org-contrib
16462 (directory-files dir-org-contrib t file-re))))
16463 (remove-re (concat (if (featurep 'xemacs)
16464 "org-colview" "org-colview-xemacs")
16466 (setq files (mapcar 'file-name-sans-extension files))
16467 (setq files (mapcar
16468 (lambda (x) (if (string-match remove-re x) nil x))
16470 (setq files (delq nil files))
16473 (when (featurep (intern (file-name-nondirectory f)))
16474 (if (and (not uncompiled)
16475 (file-exists-p (concat f ".elc")))
16476 (load (concat f ".elc") nil nil t)
16477 (load (concat f ".el") nil nil t))))
16482 (defun org-customize ()
16483 "Call the customize function with org as argument."
16485 (org-load-modules-maybe)
16486 (org-require-autoloaded-modules)
16487 (customize-browse 'org))
16489 (defun org-create-customize-menu ()
16490 "Create a full customization menu for Org-mode, insert it into the menu."
16492 (org-load-modules-maybe)
16493 (org-require-autoloaded-modules)
16494 (if (fboundp 'customize-menu-create)
16497 '("Org") "Customize"
16498 `(["Browse Org group" org-customize t]
16500 ,(customize-menu-create 'org)
16501 ["Set" Custom-set t]
16502 ["Save" Custom-save t]
16503 ["Reset to Current" Custom-reset-current t]
16504 ["Reset to Saved" Custom-reset-saved t]
16505 ["Reset to Standard Settings" Custom-reset-standard t]))
16506 (message "\"Org\"-menu now contains full customization menu"))
16507 (error "Cannot expand menu (outdated version of cus-edit.el)")))
16509 ;;;; Miscellaneous stuff
16511 ;;; Generally useful functions
16513 (defun org-get-at-bol (property)
16514 "Get text property PROPERTY at beginning of line."
16515 (get-text-property (point-at-bol) property))
16517 (defun org-find-text-property-in-string (prop s)
16518 "Return the first non-nil value of property PROP in string S."
16519 (or (get-text-property 0 prop s)
16520 (get-text-property (or (next-single-property-change 0 prop s) 0)
16523 (defun org-display-warning (message) ;; Copied from Emacs-Muse
16524 "Display the given MESSAGE as a warning."
16525 (if (fboundp 'display-warning)
16526 (display-warning 'org message
16527 (if (featurep 'xemacs)
16530 (let ((buf (get-buffer-create "*Org warnings*")))
16531 (with-current-buffer buf
16532 (goto-char (point-max))
16533 (insert "Warning (Org): " message)
16536 (display-buffer buf)
16539 (defun org-in-commented-line ()
16540 "Is point in a line starting with `#'?"
16541 (equal (char-after (point-at-bol)) ?#))
16543 (defun org-in-verbatim-emphasis ()
16545 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
16547 (defun org-goto-marker-or-bmk (marker &optional bookmark)
16548 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
16549 (if (and marker (marker-buffer marker)
16550 (buffer-live-p (marker-buffer marker)))
16552 (switch-to-buffer (marker-buffer marker))
16553 (if (or (> marker (point-max)) (< marker (point-min)))
16556 (org-show-context 'org-goto))
16558 (bookmark-jump bookmark)
16559 (error "Cannot find location"))))
16561 (defun org-quote-csv-field (s)
16562 "Quote field for inclusion in CSV material."
16563 (if (string-match "[\",]" s)
16564 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
16567 (defun org-plist-delete (plist property)
16568 "Delete PROPERTY from PLIST.
16569 This is in contrast to merely setting it to 0."
16572 (if (not (eq property (car plist)))
16573 (setq p (plist-put p (car plist) (nth 1 plist))))
16574 (setq plist (cddr plist)))
16577 (defun org-force-self-insert (N)
16578 "Needed to enforce self-insert under remapping."
16580 (self-insert-command N))
16582 (defun org-string-width (s)
16583 "Compute width of string, ignoring invisible characters.
16584 This ignores character with invisibility property `org-link', and also
16585 characters with property `org-cwidth', because these will become invisible
16586 upon the next fontification round."
16588 (when (or (eq t buffer-invisibility-spec)
16589 (assq 'org-link buffer-invisibility-spec))
16590 (while (setq b (text-property-any 0 (length s)
16591 'invisible 'org-link s))
16592 (setq s (concat (substring s 0 b)
16593 (substring s (or (next-single-property-change
16594 b 'invisible s) (length s)))))))
16595 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
16596 (setq s (concat (substring s 0 b)
16597 (substring s (or (next-single-property-change
16598 b 'org-cwidth s) (length s))))))
16599 (setq l (string-width s) b -1)
16600 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
16601 (setq l (- l (get-text-property b 'org-dwidth-n s))))
16604 (defun org-get-indentation (&optional line)
16605 "Get the indentation of the current line, interpreting tabs.
16606 When LINE is given, assume it represents a line and compute its indentation."
16608 (if (string-match "^ *" (org-remove-tabs line))
16611 (beginning-of-line 1)
16612 (skip-chars-forward " \t")
16613 (current-column))))
16615 (defun org-remove-tabs (s &optional width)
16616 "Replace tabulators in S with spaces.
16617 Assumes that s is a single line, starting in column 0."
16618 (setq width (or width tab-width))
16619 (while (string-match "\t" s)
16620 (setq s (replace-match
16622 (- (* width (/ (+ (match-beginning 0) width) width))
16623 (match-beginning 0)) ?\ )
16627 (defun org-fix-indentation (line ind)
16628 "Fix indentation in LINE.
16629 IND is a cons cell with target and minimum indentation.
16630 If the current indentation in LINE is smaller than the minimum,
16631 leave it alone. If it is larger than ind, set it to the target."
16632 (let* ((l (org-remove-tabs line))
16633 (i (org-get-indentation l))
16634 (i1 (car ind)) (i2 (cdr ind)))
16635 (if (>= i i2) (setq l (substring line i2)))
16637 (concat (make-string i1 ?\ ) l)
16640 (defun org-remove-indentation (code &optional n)
16641 "Remove the maximum common indentation from the lines in CODE.
16642 N may optionally be the number of spaces to remove."
16645 (org-do-remove-indentation n)
16648 (defun org-do-remove-indentation (&optional n)
16649 "Remove the maximum common indentation from the buffer."
16650 (untabify (point-min) (point-max))
16651 (let ((min 10000) re)
16654 (goto-char (point-min))
16655 (while (re-search-forward "^ *[^ \n]" nil t)
16656 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
16657 (unless (or (= min 0) (= min 10000))
16658 (setq re (format "^ \\{%d\\}" min))
16659 (goto-char (point-min))
16660 (while (re-search-forward re nil t)
16665 (defun org-fill-template (template alist)
16666 "Find each %key of ALIST in TEMPLATE and replace it."
16667 (let ((case-fold-search nil)
16669 (setq alist (sort (copy-sequence alist)
16670 (lambda (a b) (< (length (car a)) (length (car b))))))
16671 (while (setq entry (pop alist))
16673 (replace-regexp-in-string
16674 (concat "%" (regexp-quote (car entry)))
16675 (cdr entry) template t t)))
16678 (defun org-base-buffer (buffer)
16679 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
16682 (or (buffer-base-buffer buffer)
16685 (defun org-trim (s)
16686 "Remove whitespace at beginning and end of string."
16687 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
16688 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
16691 (defun org-wrap (string &optional width lines)
16692 "Wrap string to either a number of lines, or a width in characters.
16693 If WIDTH is non-nil, the string is wrapped to that width, however many lines
16694 that costs. If there is a word longer than WIDTH, the text is actually
16695 wrapped to the length of that word.
16696 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
16697 many lines, whatever width that takes.
16698 The return value is a list of lines, without newlines at the end."
16699 (let* ((words (org-split-string string "[ \t\n]+"))
16700 (maxword (apply 'max (mapcar 'org-string-width words)))
16703 (org-do-wrap words (max maxword width)))
16706 (setq ll (org-do-wrap words maxword))
16707 (if (<= (length ll) lines)
16710 (while (> (length ll) lines)
16712 (setq ll (org-do-wrap words w)))
16714 (t (error "Cannot wrap this")))))
16716 (defun org-do-wrap (words width)
16717 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
16720 (setq line (pop words))
16721 (while (and words (< (+ (length line) (length (car words))) width))
16722 (setq line (concat line " " (pop words))))
16723 (setq lines (push line lines)))
16726 (defun org-split-string (string &optional separators)
16727 "Splits STRING into substrings at SEPARATORS.
16728 No empty strings are returned if there are matches at the beginning
16729 and end of string."
16730 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
16734 (while (and (string-match rexp string
16736 (= start (match-beginning 0))
16737 (< start (length string)))
16739 (< (match-beginning 0) (length string)))
16741 (or (eq (match-beginning 0) 0)
16742 (and (eq (match-beginning 0) (match-end 0))
16743 (eq (match-beginning 0) start))
16745 (cons (substring string start (match-beginning 0))
16747 (setq start (match-end 0)))
16748 (or (eq start (length string))
16750 (cons (substring string start)
16754 (defun org-quote-vert (s)
16755 "Replace \"|\" with \"\\vert\"."
16756 (while (string-match "|" s)
16757 (setq s (replace-match "\\vert" t t s)))
16760 (defun org-uuidgen-p (s)
16761 "Is S an ID created by UUIDGEN?"
16762 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
16764 (defun org-context ()
16765 "Return a list of contexts of the current cursor position.
16766 If several contexts apply, all are returned.
16767 Each context entry is a list with a symbol naming the context, and
16768 two positions indicating start and end of the context. Possible
16771 :headline anywhere in a headline
16772 :headline-stars on the leading stars in a headline
16773 :todo-keyword on a TODO keyword (including DONE) in a headline
16774 :tags on the TAGS in a headline
16775 :priority on the priority cookie in a headline
16776 :item on the first line of a plain list item
16777 :item-bullet on the bullet/number of a plain list item
16778 :checkbox on the checkbox in a plain list item
16779 :table in an org-mode table
16780 :table-special on a special filed in a table
16781 :table-table in a table.el table
16782 :link on a hyperlink
16783 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
16784 :target on a <<target>>
16785 :radio-target on a <<<radio-target>>>
16786 :latex-fragment on a LaTeX fragment
16787 :latex-preview on a LaTeX fragment with overlayed preview image
16789 This function expects the position to be visible because it uses font-lock
16790 faces as a help to recognize the following contexts: :table-special, :link,
16792 (let* ((f (get-text-property (point) 'face))
16793 (faces (if (listp f) f (list f)))
16794 (p (point)) clist o)
16795 ;; First the large context
16797 ((org-on-heading-p t)
16798 (push (list :headline (point-at-bol) (point-at-eol)) clist)
16800 (beginning-of-line 1)
16801 (looking-at org-todo-line-tags-regexp))
16802 (push (org-point-in-group p 1 :headline-stars) clist)
16803 (push (org-point-in-group p 2 :todo-keyword) clist)
16804 (push (org-point-in-group p 4 :tags) clist))
16806 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
16807 (if (looking-at "\\[#[A-Z0-9]\\]")
16808 (push (org-point-in-group p 0 :priority) clist)))
16811 (push (org-point-in-group p 2 :item-bullet) clist)
16812 (push (list :item (point-at-bol)
16813 (save-excursion (org-end-of-item) (point)))
16815 (and (org-at-item-checkbox-p)
16816 (push (org-point-in-group p 0 :checkbox) clist)))
16819 (push (list :table (org-table-begin) (org-table-end)) clist)
16820 (if (memq 'org-formula faces)
16821 (push (list :table-special
16822 (previous-single-property-change p 'face)
16823 (next-single-property-change p 'face)) clist)))
16824 ((org-at-table-p 'any)
16825 (push (list :table-table) clist)))
16828 ;; Now the small context
16830 ((org-at-timestamp-p)
16831 (push (org-point-in-group p 0 :timestamp) clist))
16832 ((memq 'org-link faces)
16834 (previous-single-property-change p 'face)
16835 (next-single-property-change p 'face)) clist))
16836 ((memq 'org-special-keyword faces)
16837 (push (list :keyword
16838 (previous-single-property-change p 'face)
16839 (next-single-property-change p 'face)) clist))
16841 (push (org-point-in-group p 0 :target) clist)
16842 (goto-char (1- (match-beginning 0)))
16843 (if (looking-at org-radio-target-regexp)
16844 (push (org-point-in-group p 0 :radio-target) clist))
16846 ((setq o (car (delq nil
16849 (if (memq x org-latex-fragment-image-overlays) x))
16850 (org-overlays-at (point))))))
16851 (push (list :latex-fragment
16852 (org-overlay-start o) (org-overlay-end o)) clist)
16853 (push (list :latex-preview
16854 (org-overlay-start o) (org-overlay-end o)) clist))
16855 ((org-inside-LaTeX-fragment-p)
16856 ;; FIXME: positions wrong.
16857 (push (list :latex-fragment (point) (point)) clist)))
16859 (setq clist (nreverse (delq nil clist)))
16862 ;; FIXME: Compare with at-regexp-p Do we need both?
16863 (defun org-in-regexp (re &optional nlines visually)
16864 "Check if point is inside a match of regexp.
16865 Normally only the current line is checked, but you can include NLINES extra
16866 lines both before and after point into the search.
16867 If VISUALLY is set, require that the cursor is not after the match but
16868 really on, so that the block visually is on the match."
16870 (let ((pos (point))
16871 (eol (point-at-eol (+ 1 (or nlines 0))))
16872 (inc (if visually 1 0)))
16874 (beginning-of-line (- 1 (or nlines 0)))
16875 (while (re-search-forward re eol t)
16876 (if (and (<= (match-beginning 0) pos)
16877 (>= (+ inc (match-end 0)) pos))
16878 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
16880 (defun org-at-regexp-p (regexp)
16881 "Is point inside a match of REGEXP in the current line?"
16884 (let ((pos (point)) (end (point-at-eol)))
16885 (beginning-of-line 1)
16886 (while (re-search-forward regexp end t)
16887 (if (and (<= (match-beginning 0) pos)
16888 (>= (match-end 0) pos))
16892 (defun org-occur-in-agenda-files (regexp &optional nlines)
16893 "Call `multi-occur' with buffers for all agenda files."
16894 (interactive "sOrg-files matching: \np")
16895 (let* ((files (org-agenda-files))
16896 (tnames (mapcar 'file-truename files))
16897 (extra org-agenda-text-search-extra-files)
16899 (when (eq (car extra) 'agenda-archives)
16900 (setq extra (cdr extra))
16901 (setq files (org-add-archive-files files)))
16902 (while (setq f (pop extra))
16903 (unless (member (file-truename f) tnames)
16904 (add-to-list 'files f 'append)
16905 (add-to-list 'tnames (file-truename f) 'append)))
16907 (mapcar (lambda (x)
16908 (with-current-buffer
16909 (or (get-file-buffer x) (find-file-noselect x))
16915 (if (boundp 'occur-mode-find-occurrence-hook)
16917 (add-hook 'occur-mode-find-occurrence-hook
16922 (defadvice occur-mode-goto-occurrence
16923 (after org-occur-reveal activate)
16924 (and (org-mode-p) (org-reveal)))
16925 (defadvice occur-mode-goto-occurrence-other-window
16926 (after org-occur-reveal activate)
16927 (and (org-mode-p) (org-reveal)))
16928 (defadvice occur-mode-display-occurrence
16929 (after org-occur-reveal activate)
16931 (let ((pos (occur-mode-find-occurrence)))
16932 (with-current-buffer (marker-buffer pos)
16937 (defun org-occur-link-in-agenda-files ()
16938 "Create a link and search for it in the agendas.
16939 The link is not stored in `org-stored-links', it is just created
16940 for the search purpose."
16942 (let ((link (condition-case nil
16943 (org-store-link nil)
16944 (error "Unable to create a link to here"))))
16945 (org-occur-in-agenda-files (regexp-quote link))))
16947 (defun org-uniquify (list)
16948 "Remove duplicate elements from LIST."
16950 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
16953 (defun org-delete-all (elts list)
16954 "Remove all elements in ELTS from LIST."
16956 (setq list (delete (pop elts) list)))
16959 (defun org-back-over-empty-lines ()
16960 "Move backwards over whitespace, to the beginning of the first empty line.
16961 Returns the number of empty lines passed."
16962 (let ((pos (point)))
16963 (skip-chars-backward " \t\n\r")
16964 (beginning-of-line 2)
16965 (goto-char (min (point) pos))
16966 (count-lines (point) pos)))
16968 (defun org-skip-whitespace ()
16969 (skip-chars-forward " \t\n\r"))
16971 (defun org-point-in-group (point group &optional context)
16972 "Check if POINT is in match-group GROUP.
16973 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
16974 match. If the match group does ot exist or point is not inside it,
16976 (and (match-beginning group)
16977 (>= point (match-beginning group))
16978 (<= point (match-end group))
16980 (list context (match-beginning group) (match-end group))
16983 (defun org-switch-to-buffer-other-window (&rest args)
16984 "Switch to buffer in a second window on the current frame.
16985 In particular, do not allow pop-up frames."
16986 (let (pop-up-frames special-display-buffer-names special-display-regexps
16987 special-display-function)
16988 (apply 'switch-to-buffer-other-window args)))
16990 (defun org-combine-plists (&rest plists)
16991 "Create a single property list from all plists in PLISTS.
16992 The process starts by copying the first list, and then setting properties
16993 from the other lists. Settings in the last list are the most significant
16994 ones and overrule settings in the other lists."
16995 (let ((rtn (copy-sequence (pop plists)))
16998 (setq ls (pop plists))
17000 (setq p (pop ls) v (pop ls))
17001 (setq rtn (plist-put rtn p v))))
17004 (defun org-move-line-down (arg)
17005 "Move the current line down. With prefix argument, move it past ARG lines."
17007 (let ((col (current-column))
17009 (beginning-of-line 1) (setq beg (point))
17010 (beginning-of-line 2) (setq end (point))
17011 (beginning-of-line (+ 1 arg))
17012 (setq pos (move-marker (make-marker) (point)))
17013 (insert (delete-and-extract-region beg end))
17015 (org-move-to-column col)))
17017 (defun org-move-line-up (arg)
17018 "Move the current line up. With prefix argument, move it past ARG lines."
17020 (let ((col (current-column))
17022 (beginning-of-line 1) (setq beg (point))
17023 (beginning-of-line 2) (setq end (point))
17024 (beginning-of-line (- arg))
17025 (setq pos (move-marker (make-marker) (point)))
17026 (insert (delete-and-extract-region beg end))
17028 (org-move-to-column col)))
17030 (defun org-replace-escapes (string table)
17031 "Replace %-escapes in STRING with values in TABLE.
17032 TABLE is an association list with keys like \"%a\" and string values.
17033 The sequences in STRING may contain normal field width and padding information,
17034 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
17035 so values can contain further %-escapes if they are define later in TABLE."
17036 (let ((case-fold-search nil)
17038 (while (setq e (pop table))
17039 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
17040 (while (string-match re string)
17041 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
17043 (setq string (replace-match rpl t t string))))
17047 (defun org-sublist (list start end)
17048 "Return a section of LIST, from START to END.
17049 Counting starts at 1."
17050 (let (rtn (c start))
17051 (setq list (nthcdr (1- start) list))
17052 (while (and list (<= c end))
17053 (push (pop list) rtn)
17057 (defun org-find-base-buffer-visiting (file)
17058 "Like `find-buffer-visiting' but always return the base buffer and
17059 not an indirect buffer."
17060 (let ((buf (or (get-file-buffer file)
17061 (find-buffer-visiting file))))
17063 (or (buffer-base-buffer buf) buf)
17066 (defun org-image-file-name-regexp (&optional extensions)
17067 "Return regexp matching the file names of images.
17068 If EXTENSIONS is given, only match these."
17069 (if (and (not extensions) (fboundp 'image-file-name-regexp))
17070 (image-file-name-regexp)
17071 (let ((image-file-name-extensions
17073 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
17074 "xbm" "xpm" "pbm" "pgm" "ppm"))))
17076 (regexp-opt (nconc (mapcar 'upcase
17077 image-file-name-extensions)
17078 image-file-name-extensions)
17082 (defun org-file-image-p (file &optional extensions)
17083 "Return non-nil if FILE is an image."
17085 (string-match (org-image-file-name-regexp extensions) file)))
17087 (defun org-get-cursor-date ()
17088 "Return the date at cursor in as a time.
17089 This works in the calendar and in the agenda, anywhere else it just
17090 returns the current time."
17091 (let (date day defd)
17093 ((eq major-mode 'calendar-mode)
17094 (setq date (calendar-cursor-to-date)
17095 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
17096 ((eq major-mode 'org-agenda-mode)
17097 (setq day (get-text-property (point) 'day))
17099 (setq date (calendar-gregorian-from-absolute day)
17100 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
17102 (or defd (current-time))))
17104 (defvar org-agenda-action-marker (make-marker)
17105 "Marker pointing to the entry for the next agenda action.")
17107 (defun org-mark-entry-for-agenda-action ()
17108 "Mark the current entry as target of an agenda action.
17109 Agenda actions are actions executed from the agenda with the key `k',
17110 which make use of the date at the cursor."
17112 (move-marker org-agenda-action-marker
17113 (save-excursion (org-back-to-heading t) (point))
17116 "Entry marked for action; press `k' at desired date in agenda or calendar"))
17118 ;;; Paragraph filling stuff.
17119 ;; We want this to be just right, so use the full arsenal.
17121 (defun org-indent-line-function ()
17122 "Indent line like previous, but further if previous was headline or item."
17124 (let* ((pos (point))
17125 (itemp (org-at-item-p))
17126 (case-fold-search t)
17127 (org-drawer-regexp (or org-drawer-regexp "\000"))
17128 column bpos bcol tpos tcol bullet btype bullet-type)
17129 ;; Find the previous relevant line
17130 (beginning-of-line 1)
17132 ((looking-at "#") (setq column 0))
17133 ((looking-at "\\*+ ") (setq column 0))
17134 ((and (looking-at "[ \t]*:END:")
17135 (save-excursion (re-search-backward org-drawer-regexp nil t)))
17137 (goto-char (1- (match-beginning 1)))
17138 (setq column (current-column))))
17139 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
17141 (re-search-backward
17142 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
17143 (setq column (org-get-indentation (match-string 0))))
17145 (beginning-of-line 0)
17146 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
17147 (not (looking-at "[ \t]*:END:"))
17148 (not (looking-at org-drawer-regexp)))
17149 (beginning-of-line 0))
17151 ((looking-at "\\*+[ \t]+")
17152 (if (not org-adapt-indentation)
17154 (goto-char (match-end 0))
17155 (setq column (current-column))))
17156 ((looking-at org-drawer-regexp)
17157 (goto-char (1- (match-beginning 1)))
17158 (setq column (current-column)))
17159 ((looking-at "\\([ \t]*\\):END:")
17160 (goto-char (match-end 1))
17161 (setq column (current-column)))
17163 (org-beginning-of-item)
17164 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
17165 (setq bpos (match-beginning 1) tpos (match-end 0)
17166 bcol (progn (goto-char bpos) (current-column))
17167 tcol (progn (goto-char tpos) (current-column))
17168 bullet (match-string 1)
17169 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
17170 (if (> tcol (+ bcol org-description-max-indent))
17171 (setq tcol (+ bcol 5)))
17175 (beginning-of-line 1)
17176 (if (looking-at "\\S-")
17178 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
17179 (setq bullet (match-string 1)
17180 btype (if (string-match "[0-9]" bullet) "n" bullet))
17181 (setq column (if (equal btype bullet-type) bcol tcol)))
17182 (setq column (org-get-indentation)))))
17183 (t (setq column (org-get-indentation))))))
17185 (if (<= (current-column) (current-indentation))
17186 (org-indent-line-to column)
17187 (save-excursion (org-indent-line-to column)))
17188 (setq column (current-column))
17189 (beginning-of-line 1)
17191 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
17192 (replace-match (concat (match-string 1)
17193 (format org-property-format
17194 (match-string 2) (match-string 3)))
17196 (org-move-to-column column)))
17198 (defun org-set-autofill-regexps ()
17200 ;; In the paragraph separator we include headlines, because filling
17201 ;; text in a line directly attached to a headline would otherwise
17202 ;; fill the headline as well.
17203 (org-set-local 'comment-start-skip "^#+[ \t]*")
17204 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
17205 ;; The paragraph starter includes hand-formatted lists.
17213 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
17216 "\\\\\\(begin\\|end\\|[][]\\)"))
17217 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
17218 ;; But only if the user has not turned off tables or fixed-width regions
17220 'auto-fill-inhibit-regexp
17221 (concat "\\*+ \\|#\\+"
17222 "\\|[ \t]*" org-keyword-time-regexp
17223 (if (or org-enable-table-editor org-enable-fixed-width-editor)
17226 (if org-enable-table-editor "|" "")
17227 (if org-enable-fixed-width-editor ":" "")
17229 ;; We use our own fill-paragraph function, to make sure that tables
17230 ;; and fixed-width regions are not wrapped. That function will pass
17231 ;; through to `fill-paragraph' when appropriate.
17232 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
17233 ; Adaptive filling: To get full control, first make sure that
17234 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
17235 (org-set-local 'adaptive-fill-regexp "\000")
17236 (org-set-local 'adaptive-fill-function
17237 'org-adaptive-fill-function)
17239 'align-mode-rules-list
17240 '((org-in-buffer-settings
17241 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
17242 (modes . '(org-mode))))))
17244 (defun org-fill-paragraph (&optional justify)
17245 "Re-align a table, pass through to fill-paragraph if no table."
17246 (let ((table-p (org-at-table-p))
17247 (table.el-p (org-at-table.el-p)))
17248 (cond ((and (equal (char-after (point-at-bol)) ?*)
17249 (save-excursion (goto-char (point-at-bol))
17250 (looking-at outline-regexp)))
17251 t) ; skip headlines
17252 (table.el-p t) ; skip table.el tables
17253 (table-p (org-table-align) t) ; align org-mode tables
17254 (t nil)))) ; call paragraph-fill
17256 ;; For reference, this is the default value of adaptive-fill-regexp
17257 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
17259 (defun org-adaptive-fill-function ()
17260 "Return a fill prefix for org-mode files.
17261 In particular, this makes sure hanging paragraphs for hand-formatted lists
17263 (cond ((looking-at "#[ \t]+")
17265 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
17267 (if (> (match-end 1) (+ (match-beginning 1)
17268 org-description-max-indent))
17269 (goto-char (+ (match-beginning 1) 5))
17270 (goto-char (match-end 0)))
17271 (make-string (current-column) ?\ )))
17272 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)?")
17274 (goto-char (match-end 0))
17275 (make-string (current-column) ?\ )))
17280 (defun org-toggle-fixed-width-section (arg)
17281 "Toggle the fixed-width export.
17282 If there is no active region, the QUOTE keyword at the current headline is
17283 inserted or removed. When present, it causes the text between this headline
17284 and the next to be exported as fixed-width text, and unmodified.
17285 If there is an active region, this command adds or removes a colon as the
17286 first character of this line. If the first character of a line is a colon,
17287 this line is also exported in fixed-width font."
17290 (regionp (org-region-active-p))
17291 (beg (if regionp (region-beginning) (point)))
17292 (end (if regionp (region-end)))
17293 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
17294 (case-fold-search nil)
17295 (re "[ \t]*\\(: \\)")
17300 (setq cc (current-column))
17301 (beginning-of-line 1)
17302 (setq off (looking-at re))
17303 (while (> nlines 0)
17304 (setq nlines (1- nlines))
17305 (beginning-of-line 1)
17308 (org-move-to-column cc t)
17311 ((and off (looking-at re))
17312 (replace-match "" t t nil 1))
17313 ((not off) (org-move-to-column cc t) (insert ": ")))
17316 (org-back-to-heading)
17317 (if (looking-at (concat outline-regexp
17318 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
17319 (replace-match "" t t nil 1)
17320 (if (looking-at outline-regexp)
17322 (goto-char (match-end 0))
17323 (insert org-quote-string " "))))))))
17325 (defun org-reftex-citation ()
17326 "Use reftex-citation to insert a citation into the buffer.
17327 This looks for a line like
17329 #+BIBLIOGRAPHY: foo plain option:-d
17331 and derives from it that foo.bib is the bibliography file relevant
17332 for this document. It then installs the necessary environment for RefTeX
17333 to work in this buffer and calls `reftex-citation' to insert a citation
17336 Export of such citations to both LaTeX and HTML is handled by the contributed
17337 package org-exp-bibtex by Taru Karttunen."
17339 (let ((reftex-docstruct-symbol 'rds)
17340 (reftex-cite-format "\\cite{%l}")
17345 (let ((case-fold-search t)
17346 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
17347 (if (not (save-excursion
17348 (or (re-search-forward re nil t)
17349 (re-search-backward re nil t))))
17350 (error "No bibliography defined in file")
17351 (setq bib (concat (match-string 1) ".bib")
17352 rds (list (list 'bib bib)))))))
17353 (call-interactively 'reftex-citation)))
17355 ;;;; Functions extending outline functionality
17357 (defun org-beginning-of-line (&optional arg)
17358 "Go to the beginning of the current line. If that is invisible, continue
17359 to a visible line beginning. This makes the function of C-a more intuitive.
17360 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17361 first attempt, and only move to after the tags when the cursor is already
17362 beyond the end of the headline."
17364 (let ((pos (point))
17365 (special (if (consp org-special-ctrl-a/e)
17366 (car org-special-ctrl-a/e)
17367 org-special-ctrl-a/e))
17369 (if (org-bound-and-true-p line-move-visual)
17370 (beginning-of-visual-line 1)
17371 (beginning-of-line 1))
17372 (if (and arg (fboundp 'move-beginning-of-line))
17373 (call-interactively 'move-beginning-of-line)
17377 (if (org-invisible-p)
17378 (while (and (not (bobp)) (org-invisible-p))
17380 (beginning-of-line 1))
17381 (forward-char 1))))
17384 ((and (looking-at org-complex-heading-regexp)
17385 (= (char-after (match-end 1)) ?\ ))
17386 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
17390 (cond ((> pos refpos) refpos)
17391 ((= pos (point)) refpos)
17393 (cond ((> pos (point)) (point))
17394 ((not (eq last-command this-command)) (point))
17399 (cond ((> pos (match-end 4)) (match-end 4))
17400 ((= pos (point)) (match-end 4))
17402 (cond ((> pos (point)) (point))
17403 ((not (eq last-command this-command)) (point))
17404 (t (match-end 4))))))))
17406 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17408 (defun org-end-of-line (&optional arg)
17409 "Go to the end of the line.
17410 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17411 first attempt, and only move to after the tags when the cursor is already
17412 beyond the end of the headline."
17414 (let ((special (if (consp org-special-ctrl-a/e)
17415 (cdr org-special-ctrl-a/e)
17416 org-special-ctrl-a/e)))
17417 (if (or (not special)
17418 (not (org-on-heading-p))
17420 (call-interactively
17421 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
17422 ((fboundp 'move-end-of-line) 'move-end-of-line)
17424 (let ((pos (point)))
17425 (beginning-of-line 1)
17426 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
17428 (if (or (< pos (match-beginning 1))
17429 (= pos (match-end 0)))
17430 (goto-char (match-beginning 1))
17431 (goto-char (match-end 0)))
17432 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
17433 (goto-char (match-end 0))
17434 (goto-char (match-beginning 1))))
17435 (call-interactively (if (fboundp 'move-end-of-line)
17439 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17441 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
17442 (define-key org-mode-map "\C-e" 'org-end-of-line)
17443 (define-key org-mode-map [home] 'org-beginning-of-line)
17444 (define-key org-mode-map [end] 'org-end-of-line)
17446 (defun org-backward-sentence (&optional arg)
17447 "Go to beginning of sentence, or beginning of table field.
17448 This will call `backward-sentence' or `org-table-beginning-of-field',
17449 depending on context."
17452 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
17453 (t (call-interactively 'backward-sentence))))
17455 (defun org-forward-sentence (&optional arg)
17456 "Go to end of sentence, or end of table field.
17457 This will call `forward-sentence' or `org-table-end-of-field',
17458 depending on context."
17461 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
17462 (t (call-interactively 'forward-sentence))))
17464 (define-key org-mode-map "\M-a" 'org-backward-sentence)
17465 (define-key org-mode-map "\M-e" 'org-forward-sentence)
17467 (defun org-kill-line (&optional arg)
17468 "Kill line, to tags or end of line."
17471 ((or (not org-special-ctrl-k)
17473 (not (org-on-heading-p)))
17474 (call-interactively 'kill-line))
17475 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
17476 (kill-region (point) (match-beginning 1))
17477 (org-set-tags nil t))
17478 (t (kill-region (point) (point-at-eol)))))
17480 (define-key org-mode-map "\C-k" 'org-kill-line)
17482 (defun org-yank (&optional arg)
17483 "Yank. If the kill is a subtree, treat it specially.
17484 This command will look at the current kill and check if is a single
17485 subtree, or a series of subtrees[1]. If it passes the test, and if the
17486 cursor is at the beginning of a line or after the stars of a currently
17487 empty headline, then the yank is handled specially. How exactly depends
17488 on the value of the following variables, both set by default.
17490 org-yank-folded-subtrees
17491 When set, the subtree(s) will be folded after insertion, but only
17492 if doing so would now swallow text after the yanked text.
17494 org-yank-adjusted-subtrees
17495 When set, the subtree will be promoted or demoted in order to
17496 fit into the local outline tree structure, which means that the level
17497 will be adjusted so that it becomes the smaller one of the two
17498 *visible* surrounding headings.
17500 Any prefix to this command will cause `yank' to be called directly with
17501 no special treatment. In particular, a simple `C-u' prefix will just
17502 plainly yank the text as it is.
17504 \[1] The test checks if the first non-white line is a heading
17505 and if there are no other headings with fewer stars."
17507 (org-yank-generic 'yank arg))
17509 (defun org-yank-generic (command arg)
17510 "Perform some yank-like command.
17512 This function implements the behavior described in the `org-yank'
17513 documentation. However, it has been generalized to work for any
17514 interactive command with similar behavior."
17516 ;; pretend to be command COMMAND
17517 (setq this-command command)
17520 (call-interactively command)
17522 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
17523 (and (org-kill-is-subtree-p)
17525 (and (looking-at "[ \t]*$")
17528 (buffer-substring (point-at-bol) (point)))))))
17531 ((and subtreep org-yank-folded-subtrees)
17532 (let ((beg (point))
17534 (if (and subtreep org-yank-adjusted-subtrees)
17535 (org-paste-subtree nil nil 'for-yank)
17536 (call-interactively command))
17540 (when (and (bolp) subtreep
17541 (not (setq swallowp
17542 (org-yank-folding-would-swallow-text beg end))))
17543 (or (looking-at outline-regexp)
17544 (re-search-forward (concat "^" outline-regexp) end t))
17545 (while (and (< (point) end) (looking-at outline-regexp))
17547 (org-cycle-show-empty-lines 'folded)
17548 (condition-case nil
17549 (outline-forward-same-level 1)
17550 (error (goto-char end)))))
17553 "Inserted text not folded because that would swallow text"))
17556 (skip-chars-forward " \t\n\r")
17557 (beginning-of-line 1)
17558 (push-mark beg 'nomsg)))
17559 ((and subtreep org-yank-adjusted-subtrees)
17560 (let ((beg (point-at-bol)))
17561 (org-paste-subtree nil nil 'for-yank)
17562 (push-mark beg 'nomsg)))
17564 (call-interactively command))))))
17566 (defun org-yank-folding-would-swallow-text (beg end)
17567 "Would hide-subtree at BEG swallow any text after END?"
17571 (when (or (looking-at outline-regexp)
17572 (re-search-forward (concat "^" outline-regexp) end t))
17573 (setq level (org-outline-level)))
17575 (skip-chars-forward " \t\r\n\v\f")
17577 (and (bolp) (looking-at org-outline-regexp)
17578 (<= (org-outline-level) level)))
17579 nil ; Nothing would be swallowed
17580 t)))) ; something would swallow
17582 (define-key org-mode-map "\C-y" 'org-yank)
17584 (defun org-invisible-p ()
17585 "Check if point is at a character currently not visible."
17586 ;; Early versions of noutline don't have `outline-invisible-p'.
17587 (if (fboundp 'outline-invisible-p)
17588 (outline-invisible-p)
17589 (get-char-property (point) 'invisible)))
17591 (defun org-invisible-p2 ()
17592 "Check if point is at a character currently not visible."
17594 (if (and (eolp) (not (bobp))) (backward-char 1))
17595 ;; Early versions of noutline don't have `outline-invisible-p'.
17596 (if (fboundp 'outline-invisible-p)
17597 (outline-invisible-p)
17598 (get-char-property (point) 'invisible))))
17600 (defun org-back-to-heading (&optional invisible-ok)
17601 "Call `outline-back-to-heading', but provide a better error message."
17602 (condition-case nil
17603 (outline-back-to-heading invisible-ok)
17604 (error (error "Before first headline at position %d in buffer %s"
17605 (point) (current-buffer)))))
17607 (defun org-before-first-heading-p ()
17608 "Before first heading?"
17610 (null (re-search-backward "^\\*+ " nil t))))
17612 (defun org-on-heading-p (&optional ignored)
17613 (outline-on-heading-p t))
17614 (defun org-at-heading-p (&optional ignored)
17615 (outline-on-heading-p t))
17617 (defun org-at-heading-or-item-p ()
17618 (or (org-on-heading-p) (org-at-item-p)))
17620 (defun org-on-target-p ()
17621 (or (org-in-regexp org-radio-target-regexp)
17622 (org-in-regexp org-target-regexp)))
17624 (defun org-up-heading-all (arg)
17625 "Move to the heading line of which the present line is a subheading.
17626 This function considers both visible and invisible heading lines.
17627 With argument, move up ARG levels."
17628 (if (fboundp 'outline-up-heading-all)
17629 (outline-up-heading-all arg) ; emacs 21 version of outline.el
17630 (outline-up-heading arg t))) ; emacs 22 version of outline.el
17632 (defun org-up-heading-safe ()
17633 "Move to the heading line of which the present line is a subheading.
17634 This version will not throw an error. It will return the level of the
17635 headline found, or nil if no higher level is found.
17637 Also, this function will be a lot faster than `outline-up-heading',
17638 because it relies on stars being the outline starters. This can really
17639 make a significant difference in outlines with very many siblings."
17640 (let (start-level re)
17641 (org-back-to-heading t)
17642 (setq start-level (funcall outline-level))
17643 (if (equal start-level 1)
17645 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
17646 (if (re-search-backward re nil t)
17647 (funcall outline-level)))))
17649 (defun org-first-sibling-p ()
17650 "Is this heading the first child of its parents?"
17652 (let ((re (concat "^" outline-regexp))
17654 (unless (org-at-heading-p t)
17655 (error "Not at a heading"))
17656 (setq level (funcall outline-level))
17658 (if (not (re-search-backward re nil t))
17660 (setq l (funcall outline-level))
17663 (defun org-goto-sibling (&optional previous)
17664 "Goto the next sibling, even if it is invisible.
17665 When PREVIOUS is set, go to the previous sibling instead. Returns t
17666 when a sibling was found. When none is found, return nil and don't
17668 (let ((fun (if previous 're-search-backward 're-search-forward))
17670 (re (concat "^" outline-regexp))
17672 (when (condition-case nil (org-back-to-heading t) (error nil))
17673 (setq level (funcall outline-level))
17675 (or previous (forward-char 1))
17676 (while (funcall fun re nil t)
17677 (setq l (funcall outline-level))
17678 (when (< l level) (goto-char pos) (throw 'exit nil))
17679 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
17683 (defun org-show-siblings ()
17684 "Show all siblings of the current headline."
17686 (while (org-goto-sibling) (org-flag-heading nil)))
17688 (while (org-goto-sibling 'previous)
17689 (org-flag-heading nil))))
17691 (defun org-show-hidden-entry ()
17692 "Show an entry where even the heading is hidden."
17696 (defun org-flag-heading (flag &optional entry)
17697 "Flag the current heading. FLAG non-nil means make invisible.
17698 When ENTRY is non-nil, show the entire entry."
17700 (org-back-to-heading t)
17701 ;; Check if we should show the entire entry
17706 (and (outline-next-heading)
17707 (org-flag-heading nil))))
17708 (outline-flag-region (max (point-min) (1- (point)))
17709 (save-excursion (outline-end-of-heading) (point))
17712 (defun org-get-next-sibling ()
17713 "Move to next heading of the same level, and return point.
17714 If there is no such heading, return nil.
17715 This is like outline-next-sibling, but invisible headings are ok."
17716 (let ((level (funcall outline-level)))
17717 (outline-next-heading)
17718 (while (and (not (eobp)) (> (funcall outline-level) level))
17719 (outline-next-heading))
17720 (if (or (eobp) (< (funcall outline-level) level))
17724 (defun org-get-last-sibling ()
17725 "Move to previous heading of the same level, and return point.
17726 If there is no such heading, return nil."
17727 (let ((opoint (point))
17728 (level (funcall outline-level)))
17729 (outline-previous-heading)
17730 (when (and (/= (point) opoint) (outline-on-heading-p t))
17731 (while (and (> (funcall outline-level) level)
17733 (outline-previous-heading))
17734 (if (< (funcall outline-level) level)
17738 (defun org-end-of-subtree (&optional invisible-OK to-heading)
17739 ;; This contains an exact copy of the original function, but it uses
17740 ;; `org-back-to-heading', to make it work also in invisible
17741 ;; trees. And is uses an invisible-OK argument.
17742 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
17743 ;; Furthermore, when used inside Org, finding the end of a large subtree
17744 ;; with many children and grandchildren etc, this can be much faster
17745 ;; than the outline version.
17746 (org-back-to-heading invisible-OK)
17748 (level (funcall outline-level)))
17749 (if (and (org-mode-p) (< level 1000))
17750 ;; A true heading (not a plain list item), in Org-mode
17751 ;; This means we can easily find the end by looking
17752 ;; only for the right number of stars. Using a regexp to do
17753 ;; this is so much faster than using a Lisp loop.
17754 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
17756 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
17757 ;; something else, do it the slow way
17758 (while (and (not (eobp))
17759 (or first (> (funcall outline-level) level)))
17761 (outline-next-heading)))
17763 (if (memq (preceding-char) '(?\n ?\^M))
17765 ;; Go to end of line before heading
17767 (if (memq (preceding-char) '(?\n ?\^M))
17768 ;; leave blank line before heading
17769 (forward-char -1))))))
17772 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
17773 "Use Org version in org-mode, for dramatic speed-up."
17774 (if (eq major-mode 'org-mode)
17776 (org-end-of-subtree nil t)
17777 (unless (eobp) (backward-char 1)))
17780 (defun org-forward-same-level (arg &optional invisible-ok)
17781 "Move forward to the arg'th subheading at same level as this one.
17782 Stop at the first and last subheadings of a superior heading."
17784 (org-back-to-heading invisible-ok)
17786 (let* ((level (- (match-end 0) (match-beginning 0) 1))
17787 (re (format "^\\*\\{1,%d\\} " level))
17791 (while (and (re-search-forward re nil 'move)
17792 (setq l (- (match-end 0) (match-beginning 0) 1))
17795 (progn (backward-char 1) (org-invisible-p)))
17796 (if (< l level) (setq arg 1)))
17797 (setq arg (1- arg)))
17798 (beginning-of-line 1)))
17800 (defun org-backward-same-level (arg &optional invisible-ok)
17801 "Move backward to the arg'th subheading at same level as this one.
17802 Stop at the first and last subheadings of a superior heading."
17804 (org-back-to-heading)
17806 (let* ((level (- (match-end 0) (match-beginning 0) 1))
17807 (re (format "^\\*\\{1,%d\\} " level))
17810 (while (and (re-search-backward re nil 'move)
17811 (setq l (- (match-end 0) (match-beginning 0) 1))
17815 (if (< l level) (setq arg 1)))
17816 (setq arg (1- arg)))))
17818 (defun org-show-subtree ()
17819 "Show everything after this heading at deeper levels."
17820 (outline-flag-region
17823 (org-end-of-subtree t t))
17826 (defun org-show-entry ()
17827 "Show the body directly following this heading.
17828 Show the heading too, if it is currently invisible."
17831 (condition-case nil
17833 (org-back-to-heading t)
17834 (outline-flag-region
17835 (max (point-min) (1- (point)))
17837 (if (re-search-forward
17838 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
17839 (match-beginning 1)
17842 (org-cycle-hide-drawers 'children))
17845 (defun org-make-options-regexp (kwds &optional extra)
17846 "Make a regular expression for keyword lines."
17850 (mapconcat 'regexp-quote kwds "\\|")
17851 (if extra (concat "\\|" extra))
17855 ;; Make isearch reveal the necessary context
17856 (defun org-isearch-end ()
17857 "Reveal context after isearch exits."
17858 (when isearch-success ; only if search was successful
17859 (if (featurep 'xemacs)
17860 ;; Under XEmacs, the hook is run in the correct place,
17861 ;; we directly show the context.
17862 (org-show-context 'isearch)
17863 ;; In Emacs the hook runs *before* restoring the overlays.
17864 ;; So we have to use a one-time post-command-hook to do this.
17865 ;; (Emacs 22 has a special variable, see function `org-mode')
17866 (unless (and (boundp 'isearch-mode-end-hook-quit)
17867 isearch-mode-end-hook-quit)
17868 ;; Only when the isearch was not quitted.
17869 (org-add-hook 'post-command-hook 'org-isearch-post-command
17870 'append 'local)))))
17872 (defun org-isearch-post-command ()
17873 "Remove self from hook, and show context."
17874 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
17875 (org-show-context 'isearch))
17878 ;;;; Integration with and fixes for other packages
17882 (defvar org-imenu-markers nil
17883 "All markers currently used by Imenu.")
17884 (make-variable-buffer-local 'org-imenu-markers)
17886 (defun org-imenu-new-marker (&optional pos)
17887 "Return a new marker for use by Imenu, and remember the marker."
17888 (let ((m (make-marker)))
17889 (move-marker m (or pos (point)))
17890 (push m org-imenu-markers)
17893 (defun org-imenu-get-tree ()
17894 "Produce the index for Imenu."
17895 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
17896 (setq org-imenu-markers nil)
17897 (let* ((n org-imenu-depth)
17898 (re (concat "^" outline-regexp))
17899 (subs (make-vector (1+ n) nil))
17905 (goto-char (point-max))
17906 (while (re-search-backward re nil t)
17907 (setq level (org-reduced-level (funcall outline-level)))
17909 (looking-at org-complex-heading-regexp)
17910 (setq head (org-link-display-format
17911 (org-match-string-no-properties 4))
17912 m (org-imenu-new-marker))
17913 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
17914 (if (>= level last-level)
17915 (push (cons head m) (aref subs level))
17916 (push (cons head (aref subs (1+ level))) (aref subs level))
17917 (loop for i from (1+ level) to n do (aset subs i nil)))
17918 (setq last-level level)))))
17921 (eval-after-load "imenu"
17923 (add-hook 'imenu-after-jump-hook
17925 (if (eq major-mode 'org-mode)
17926 (org-show-context 'org-goto))))))
17928 (defun org-link-display-format (link)
17929 "Replace a link with either the description, or the link target
17930 if no description is present"
17932 (if (string-match org-bracket-link-analytic-regexp link)
17933 (replace-match (if (match-end 5)
17934 (match-string 5 link)
17935 (concat (match-string 1 link)
17936 (match-string 3 link)))
17940 ;; Speedbar support
17942 (defvar org-speedbar-restriction-lock-overlay (org-make-overlay 1 1)
17943 "Overlay marking the agenda restriction line in speedbar.")
17944 (org-overlay-put org-speedbar-restriction-lock-overlay
17945 'face 'org-agenda-restriction-lock)
17946 (org-overlay-put org-speedbar-restriction-lock-overlay
17947 'help-echo "Agendas are currently limited to this item.")
17948 (org-detach-overlay org-speedbar-restriction-lock-overlay)
17950 (defun org-speedbar-set-agenda-restriction ()
17951 "Restrict future agenda commands to the location at point in speedbar.
17952 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
17954 (require 'org-agenda)
17955 (let (p m tp np dir txt)
17957 ((setq p (text-property-any (point-at-bol) (point-at-eol)
17959 (setq m (get-text-property p 'org-imenu-marker))
17960 (with-current-buffer (marker-buffer m)
17962 (org-agenda-set-restriction-lock 'subtree)))
17963 ((setq p (text-property-any (point-at-bol) (point-at-eol)
17964 'speedbar-function 'speedbar-find-file))
17965 (setq tp (previous-single-property-change
17966 (1+ p) 'speedbar-function)
17967 np (next-single-property-change
17968 tp 'speedbar-function)
17969 dir (speedbar-line-directory)
17970 txt (buffer-substring-no-properties (or tp (point-min))
17971 (or np (point-max))))
17972 (with-current-buffer (find-file-noselect
17973 (let ((default-directory dir))
17974 (expand-file-name txt)))
17975 (unless (org-mode-p)
17976 (error "Cannot restrict to non-Org-mode file"))
17977 (org-agenda-set-restriction-lock 'file)))
17978 (t (error "Don't know how to restrict Org-mode's agenda")))
17979 (org-move-overlay org-speedbar-restriction-lock-overlay
17980 (point-at-bol) (point-at-eol))
17981 (setq current-prefix-arg nil)
17982 (org-agenda-maybe-redo)))
17984 (eval-after-load "speedbar"
17986 (speedbar-add-supported-extension ".org")
17987 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
17988 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
17989 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
17990 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
17991 (add-hook 'speedbar-visiting-tag-hook
17992 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
17995 ;;; Fixes and Hacks for problems with other packages
17997 ;; Make flyspell not check words in links, to not mess up our keymap
17998 (defun org-mode-flyspell-verify ()
17999 "Don't let flyspell put overlays at active buttons."
18000 (and (not (get-text-property (point) 'keymap))
18001 (not (get-text-property (point) 'org-no-flyspell))))
18003 (defun org-remove-flyspell-overlays-in (beg end)
18004 "Remove flyspell overlays in region."
18005 (and (org-bound-and-true-p flyspell-mode)
18006 (fboundp 'flyspell-delete-region-overlays)
18007 (flyspell-delete-region-overlays beg end))
18008 (add-text-properties beg end '(org-no-flyspell t)))
18010 ;; Make `bookmark-jump' shows the jump location if it was hidden.
18011 (eval-after-load "bookmark"
18012 '(if (boundp 'bookmark-after-jump-hook)
18013 ;; We can use the hook
18014 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
18015 ;; Hook not available, use advice
18016 (defadvice bookmark-jump (after org-make-visible activate)
18017 "Make the position visible."
18018 (org-bookmark-jump-unhide))))
18020 ;; Make sure saveplace shows the location if it was hidden
18021 (eval-after-load "saveplace"
18022 '(defadvice save-place-find-file-hook (after org-make-visible activate)
18023 "Make the position visible."
18024 (org-bookmark-jump-unhide)))
18026 ;; Make sure ecb shows the location if it was hidden
18027 (eval-after-load "ecb"
18028 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
18029 "Make hierarchy visible when jumping into location from ECB tree buffer."
18030 (if (eq major-mode 'org-mode)
18031 (org-show-context))))
18033 (defun org-bookmark-jump-unhide ()
18034 "Unhide the current position, to show the bookmark location."
18036 (or (org-invisible-p)
18037 (save-excursion (goto-char (max (point-min) (1- (point))))
18038 (org-invisible-p)))
18039 (org-show-context 'bookmark-jump)))
18041 ;; Make session.el ignore our circular variable
18042 (eval-after-load "session"
18043 '(add-to-list 'session-globals-exclude 'org-mark-ring))
18045 ;;;; Experimental code
18047 (defun org-closed-in-range ()
18048 "Sparse tree of items closed in a certain time range.
18049 Still experimental, may disappear in the future."
18051 ;; Get the time interval from the user.
18052 (let* ((time1 (org-float-time
18053 (org-read-date nil 'to-time nil "Starting date: ")))
18054 (time2 (org-float-time
18055 (org-read-date nil 'to-time nil "End date:")))
18056 ;; callback function
18057 (callback (lambda ()
18060 (apply 'encode-time
18061 (org-parse-time-string
18062 (match-string 1))))))
18063 ;; check if time in interval
18064 (and (>= time time1) (<= time time2))))))
18065 ;; make tree, check each match with the callback
18066 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
18072 (run-hooks 'org-load-hook)
18074 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
18076 ;;; org.el ends here