1 ;;; org.el --- Outline-based notes management and organizer
2 ;; Carstens outline-mode for keeping track of everything.
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
30 ;; project planning with a fast and effective plain-text system.
32 ;; Org-mode develops organizational tasks around NOTES files that contain
33 ;; information about projects as plain text. Org-mode is implemented on
34 ;; top of outline-mode, which makes it possible to keep the content of
35 ;; large files well structured. Visibility cycling and structure editing
36 ;; help to work with the tree. Tables are easily created with a built-in
37 ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
38 ;; and scheduling. It dynamically compiles entries into an agenda that
39 ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
40 ;; Plain text URL-like links connect to websites, emails, Usenet
41 ;; messages, BBDB entries, and any files related to the projects. For
42 ;; printing and sharing of notes, an Org-mode file can be exported as a
43 ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
44 ;; iCalendar file. It can also serve as a publishing tool for a set of
47 ;; Installation and Activation
48 ;; ---------------------------
49 ;; See the corresponding sections in the manual at
51 ;; http://orgmode.org/org.html#Installation
55 ;; The documentation of Org-mode can be found in the TeXInfo file. The
56 ;; distribution also contains a PDF version of it. At the homepage of
57 ;; Org-mode, you can read the same text online as HTML. There is also an
58 ;; excellent reference card made by Philip Rooke. This card can be found
59 ;; in the etc/ directory of Emacs 22.
61 ;; A list of recent changes can be found at
62 ;; http://orgmode.org/Changes.html
66 (defvar org-inhibit-highlight-removal nil
) ; dynamically scoped param
67 (defvar org-table-formula-constants-local nil
68 "Local version of `org-table-formula-constants'.")
69 (make-variable-buffer-local 'org-table-formula-constants-local
)
71 ;;;; Require other packages
78 ;; Emacs 22 calendar compatibility: Make sure the new variables are available
79 (unless (boundp 'calendar-view-holidays-initially-flag
)
80 (defvaralias 'calendar-view-holidays-initially-flag
81 'view-calendar-holidays-initially
))
82 (unless (boundp 'calendar-view-diary-initially-flag
)
83 (defvaralias 'calendar-view-diary-initially-flag
84 'view-diary-entries-initially
))
85 (unless (boundp 'diary-fancy-buffer
)
86 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
))
88 ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
89 ;; the file noutline.el being loaded.
90 (if (featurep 'xemacs
) (condition-case nil
(require 'noutline
)))
91 ;; We require noutline, which might be provided in outline.el
92 (require 'outline
) (require 'noutline
)
93 ;; Other stuff we need.
95 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
100 (require 'org-entities
)
101 (require 'org-compat
)
105 (require 'org-footnote
)
108 (let* ((babel-path (expand-file-name
110 (file-name-directory (or (buffer-file-name)
112 (babel-langs-path (expand-file-name "langs" babel-path
)))
113 (add-to-list 'load-path babel-path
)
114 (add-to-list 'load-path babel-langs-path
))
122 (require 'ob-emacs-lisp
)
124 ;;;; Customization variables
125 (defcustom org-clone-delete-id nil
126 "Remove ID property of clones of a subtree.
127 When non-nil, clones of a subtree don't inherit the ID property.
128 Otherwise they inherit the ID property with a new unique
135 (defconst org-version
"6.36trans"
136 "The version number of the file org.el.")
138 (defun org-version (&optional here
)
139 "Show the org-mode version in the echo area.
140 With prefix arg HERE, insert it at point."
142 (let* ((origin default-directory
)
143 (version org-version
)
145 (dir (concat (file-name-directory (locate-library "org")) "../" )))
146 (when (and (file-exists-p (expand-file-name ".git" dir
))
147 (executable-find "git"))
151 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
152 (with-current-buffer "*Shell Command Output*"
153 (goto-char (point-min))
154 (setq git-version
(buffer-substring (point) (point-at-eol))))
155 (subst-char-in-string ?- ?. git-version t
)
156 (when (string-match "\\S-"
157 (shell-command-to-string
158 "git diff-index --name-only HEAD --"))
159 (setq git-version
(concat git-version
".dirty")))
160 (setq version
(concat version
" (" git-version
")"))))
162 (setq version
(format "Org-mode version %s" version
))
163 (if here
(insert version
))
166 ;;; Compatibility constants
168 ;;; The custom variables
171 "Outline-based notes management and organizer."
176 (defcustom org-mode-hook nil
177 "Mode hook for Org-mode, run after the mode was turned on."
181 (defcustom org-load-hook nil
182 "Hook that is run after org.el has been loaded."
186 (defvar org-modules
) ; defined below
187 (defvar org-modules-loaded nil
188 "Have the modules been loaded already?")
190 (defun org-load-modules-maybe (&optional force
)
191 "Load all extensions listed in `org-modules'."
192 (when (or force
(not org-modules-loaded
))
194 (condition-case nil
(require ext
)
195 (error (message "Problems while trying to load feature `%s'" ext
))))
197 (setq org-modules-loaded t
)))
199 (defun org-set-modules (var value
)
200 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
202 (when (featurep 'org
)
203 (org-load-modules-maybe 'force
)))
205 (when (org-bound-and-true-p org-modules
)
206 (let ((a (member 'org-infojs org-modules
)))
207 (and a
(setcar a
'org-jsinfo
))))
209 (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
)
210 "Modules that should always be loaded together with org.el.
211 If a description starts with <C>, the file is not part of Emacs
212 and loading it will require that you have downloaded and properly installed
213 the org-mode distribution.
215 You can also use this system to load external packages (i.e. neither Org
216 core modules, nor modules from the CONTRIB directory). Just add symbols
217 to the end of the list. If the package is called org-xyz.el, then you need
218 to add the symbol `xyz', and the package must have a call to
222 :set
'org-set-modules
225 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
226 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
227 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
228 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
229 (const :tag
" docview: Links to doc-view buffers" org-docview
)
230 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
231 (const :tag
" id: Global IDs for identifying entries" org-id
)
232 (const :tag
" info: Links to Info nodes" org-info
)
233 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
234 (const :tag
" habit: Track your consistency with habits" org-habit
)
235 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
236 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
237 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
238 (const :tag
" mew Links to Mew folders/messages" org-mew
)
239 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
240 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
241 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
242 (const :tag
" vm: Links to VM folders/messages" org-vm
)
243 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
244 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
245 (const :tag
" mouse: Additional mouse support" org-mouse
)
247 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
248 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
249 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
250 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
251 (const :tag
"C collector: Collect properties into tables" org-collector
)
252 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
253 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
254 (const :tag
"C eval: Include command output as text" org-eval
)
255 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
256 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
257 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
258 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
259 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
261 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
263 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
264 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
265 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
266 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
267 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
268 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
269 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
270 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
271 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
272 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
273 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
274 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
275 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
276 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
277 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
278 (const :tag
"C track: Keep up with Org-mode development" org-track
)
279 (const :tag
"C TaskJuggler: Export tasks to a TaskJuggler project" org-taskjuggler
)
280 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
282 (defcustom org-support-shift-select nil
283 "Non-nil means make shift-cursor commands select text when possible.
285 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
286 selecting a region, or enlarge thusly regions started in this way.
287 In Org-mode, in special contexts, these same keys are used for other
288 purposes, important enough to compete with shift selection. Org tries
289 to balance these needs by supporting `shift-select-mode' outside these
290 special contexts, under control of this variable.
292 The default of this variable is nil, to avoid confusing behavior. Shifted
293 cursor keys will then execute Org commands in the following contexts:
294 - on a headline, changing TODO state (left/right) and priority (up/down)
295 - on a time stamp, changing the time
296 - in a plain list item, changing the bullet type
297 - in a property definition line, switching between allowed values
298 - in the BEGIN line of a clock table (changing the time block).
299 Outside these contexts, the commands will throw an error.
301 When this variable is t and the cursor is not in a special context,
302 Org-mode will support shift-selection for making and enlarging regions.
303 To make this more effective, the bullet cycling will no longer happen
304 anywhere in an item line, but only if the cursor is exactly on the bullet.
306 If you set this variable to the symbol `always', then the keys
307 will not be special in headlines, property lines, and item lines, to make
308 shift selection work there as well. If this is what you want, you can
309 use the following alternative commands: `C-c C-t' and `C-c ,' to
310 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
311 TODO sets, `C-c -' to cycle item bullet types, and properties can be
312 edited by hand or in column view.
314 However, when the cursor is on a timestamp, shift-cursor commands
315 will still edit the time stamp - this is just too good to give up.
317 XEmacs user should have this variable set to nil, because shift-select-mode
321 (const :tag
"Never" nil
)
322 (const :tag
"When outside special context" t
)
323 (const :tag
"Everywhere except timestamps" always
)))
325 (defgroup org-startup nil
326 "Options concerning startup of Org-mode."
330 (defcustom org-startup-folded t
331 "Non-nil means entering Org-mode will switch to OVERVIEW.
332 This can also be configured on a per-file basis by adding one of
333 the following lines anywhere in the buffer:
335 #+STARTUP: fold (or `overview', this is equivalent)
336 #+STARTUP: nofold (or `showall', this is equivalent)
338 #+STARTUP: showeverything"
341 (const :tag
"nofold: show all" nil
)
342 (const :tag
"fold: overview" t
)
343 (const :tag
"content: all headlines" content
)
344 (const :tag
"show everything, even drawers" showeverything
)))
346 (defcustom org-startup-truncated t
347 "Non-nil means entering Org-mode will set `truncate-lines'.
348 This is useful since some lines containing links can be very long and
349 uninteresting. Also tables look terrible when wrapped."
353 (defcustom org-startup-indented nil
354 "Non-nil means turn on `org-indent-mode' on startup.
355 This can also be configured on a per-file basis by adding one of
356 the following lines anywhere in the buffer:
360 :group
'org-structure
362 (const :tag
"Not" nil
)
363 (const :tag
"Globally (slow on startup in large files)" t
)))
365 (defcustom org-use-sub-superscripts t
366 "Non-nil means interpret \"_\" and \"^\" for export.
367 When this option is turned on, you can use TeX-like syntax for sub- and
368 superscripts. Several characters after \"_\" or \"^\" will be
369 considered as a single item - so grouping with {} is normally not
370 needed. For example, the following things will be parsed as single
371 sub- or superscripts.
373 10^24 or 10^tau several digits will be considered 1 item.
374 10^-12 or 10^-tau a leading sign with digits or a word
375 x^2-y^3 will be read as x^2 - y^3, because items are
376 terminated by almost any nonword/nondigit char.
377 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
379 Still, ambiguity is possible - so when in doubt use {} to enclose the
380 sub/superscript. If you set this variable to the symbol `{}',
381 the braces are *required* in order to trigger interpretations as
382 sub/superscript. This can be helpful in documents that need \"_\"
383 frequently in plain text.
385 Not all export backends support this, but HTML does.
387 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
389 :group
'org-export-translation
391 (const :tag
"Always interpret" t
)
392 (const :tag
"Only with braces" {})
393 (const :tag
"Never interpret" nil
)))
395 (defvaralias 'org-export-with-sub-superscripts
'org-use-sub-superscripts
)
398 (defcustom org-startup-with-beamer-mode nil
399 "Non-nil means turn on `org-beamer-mode' on startup.
400 This can also be configured on a per-file basis by adding one of
401 the following lines anywhere in the buffer:
407 (defcustom org-startup-align-all-tables nil
408 "Non-nil means align all tables when visiting a file.
409 This is useful when the column width in tables is forced with <N> cookies
410 in table fields. Such tables will look correct only after the first re-align.
411 This can also be configured on a per-file basis by adding one of
412 the following lines anywhere in the buffer:
418 (defcustom org-insert-mode-line-in-empty-file nil
419 "Non-nil means insert the first line setting Org-mode in empty files.
420 When the function `org-mode' is called interactively in an empty file, this
421 normally means that the file name does not automatically trigger Org-mode.
422 To ensure that the file will always be in Org-mode in the future, a
423 line enforcing Org-mode will be inserted into the buffer, if this option
428 (defcustom org-replace-disputed-keys nil
429 "Non-nil means use alternative key bindings for some keys.
430 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
431 These keys are also used by other packages like shift-selection-mode'
432 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
433 If you want to use Org-mode together with one of these other modes,
434 or more generally if you would like to move some Org-mode commands to
435 other keys, set this variable and configure the keys with the variable
438 This option is only relevant at load-time of Org-mode, and must be set
439 *before* org.el is loaded. Changing it requires a restart of Emacs to
444 (defcustom org-use-extra-keys nil
445 "Non-nil means use extra key sequence definitions for certain
446 commands. This happens automatically if you run XEmacs or if
447 window-system is nil. This variable lets you do the same
448 manually. You must set it before loading org.
450 Example: on Carbon Emacs 22 running graphically, with an external
451 keyboard on a Powerbook, the default way of setting M-left might
452 not work for either Alt or ESC. Setting this variable will make
457 (if (fboundp 'defvaralias
)
458 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
460 (defcustom org-disputed-keys
461 '(([(shift up
)] .
[(meta p
)])
462 ([(shift down
)] .
[(meta n
)])
463 ([(shift left
)] .
[(meta -
)])
464 ([(shift right
)] .
[(meta +)])
465 ([(control shift right
)] .
[(meta shift
+)])
466 ([(control shift left
)] .
[(meta shift -
)]))
467 "Keys for which Org-mode and other modes compete.
468 This is an alist, cars are the default keys, second element specifies
469 the alternative to use when `org-replace-disputed-keys' is t.
471 Keys can be specified in any syntax supported by `define-key'.
472 The value of this option takes effect only at Org-mode's startup,
473 therefore you'll have to restart Emacs to apply it after changing."
478 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
479 Or return the original if not disputed.
480 Also apply the trnaslations defined in `org-xemacs-key-equivalents'."
481 (when org-replace-disputed-keys
482 (let* ((nkey (key-description key
))
483 (x (org-find-if (lambda (x)
484 (equal (key-description (car x
)) nkey
))
486 (setq key
(if x
(cdr x
) key
))))
487 (when (featurep 'xemacs
)
488 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
491 (defun org-find-if (predicate seq
)
494 (if (funcall predicate
(car seq
))
495 (throw 'exit
(car seq
))
498 (defun org-defkey (keymap key def
)
499 "Define a key, possibly translated, as returned by `org-key'."
500 (define-key keymap
(org-key key
) def
))
502 (defcustom org-ellipsis nil
503 "The ellipsis to use in the Org-mode outline.
504 When nil, just use the standard three dots. When a string, use that instead,
505 When a face, use the standard 3 dots, but with the specified face.
506 The change affects only Org-mode (which will then use its own display table).
507 Changing this requires executing `M-x org-mode' in a buffer to become
510 :type
'(choice (const :tag
"Default" nil
)
511 (face :tag
"Face" :value org-warning
)
512 (string :tag
"String" :value
"...#")))
514 (defvar org-display-table nil
515 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
517 (defgroup org-keywords nil
518 "Keywords in Org-mode."
522 (defcustom org-deadline-string
"DEADLINE:"
523 "String to mark deadline entries.
524 A deadline is this string, followed by a time stamp. Should be a word,
525 terminated by a colon. You can insert a schedule keyword and
526 a timestamp with \\[org-deadline].
527 Changes become only effective after restarting Emacs."
531 (defcustom org-scheduled-string
"SCHEDULED:"
532 "String to mark scheduled TODO entries.
533 A schedule is this string, followed by a time stamp. Should be a word,
534 terminated by a colon. You can insert a schedule keyword and
535 a timestamp with \\[org-schedule].
536 Changes become only effective after restarting Emacs."
540 (defcustom org-closed-string
"CLOSED:"
541 "String used as the prefix for timestamps logging closing a TODO entry."
545 (defcustom org-clock-string
"CLOCK:"
546 "String used as prefix for timestamps clocking work hours on an item."
550 (defcustom org-comment-string
"COMMENT"
551 "Entries starting with this keyword will never be exported.
552 An entry can be toggled between COMMENT and normal with
553 \\[org-toggle-comment].
554 Changes become only effective after restarting Emacs."
558 (defcustom org-quote-string
"QUOTE"
559 "Entries starting with this keyword will be exported in fixed-width font.
560 Quoting applies only to the text in the entry following the headline, and does
561 not extend beyond the next headline, even if that is lower level.
562 An entry can be toggled between QUOTE and normal with
563 \\[org-toggle-fixed-width-section]."
567 (defconst org-repeat-re
568 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
569 "Regular expression for specifying repeated events.
570 After a match, group 1 contains the repeat expression.")
572 (defgroup org-structure nil
573 "Options concerning the general structure of Org-mode files."
577 (defgroup org-reveal-location nil
578 "Options about how to make context of a location visible."
579 :tag
"Org Reveal Location"
580 :group
'org-structure
)
582 (defconst org-context-choice
584 (const :tag
"Always" t
)
585 (const :tag
"Never" nil
)
586 (repeat :greedy t
:tag
"Individual contexts"
588 (choice :tag
"Context"
595 (const bookmark-jump
)
599 "Contexts for the reveal options.")
601 (defcustom org-show-hierarchy-above
'((default . t
))
602 "Non-nil means show full hierarchy when revealing a location.
603 Org-mode often shows locations in an org-mode file which might have
604 been invisible before. When this is set, the hierarchy of headings
605 above the exposed location is shown.
606 Turning this off for example for sparse trees makes them very compact.
607 Instead of t, this can also be an alist specifying this option for different
608 contexts. Valid contexts are
609 agenda when exposing an entry from the agenda
610 org-goto when using the command `org-goto' on key C-c C-j
611 occur-tree when using the command `org-occur' on key C-c /
612 tags-tree when constructing a sparse tree based on tags matches
613 link-search when exposing search matches associated with a link
614 mark-goto when exposing the jump goal of a mark
615 bookmark-jump when exposing a bookmark location
616 isearch when exiting from an incremental search
617 default default for all contexts not set explicitly"
618 :group
'org-reveal-location
619 :type org-context-choice
)
621 (defcustom org-show-following-heading
'((default . nil
))
622 "Non-nil means show following heading when revealing a location.
623 Org-mode often shows locations in an org-mode file which might have
624 been invisible before. When this is set, the heading following the
626 Turning this off for example for sparse trees makes them very compact,
627 but makes it harder to edit the location of the match. In such a case,
628 use the command \\[org-reveal] to show more context.
629 Instead of t, this can also be an alist specifying this option for different
630 contexts. See `org-show-hierarchy-above' for valid contexts."
631 :group
'org-reveal-location
632 :type org-context-choice
)
634 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
635 "Non-nil means show all sibling heading when revealing a location.
636 Org-mode often shows locations in an org-mode file which might have
637 been invisible before. When this is set, the sibling of the current entry
638 heading are all made visible. If `org-show-hierarchy-above' is t,
639 the same happens on each level of the hierarchy above the current entry.
641 By default this is on for the isearch context, off for all other contexts.
642 Turning this off for example for sparse trees makes them very compact,
643 but makes it harder to edit the location of the match. In such a case,
644 use the command \\[org-reveal] to show more context.
645 Instead of t, this can also be an alist specifying this option for different
646 contexts. See `org-show-hierarchy-above' for valid contexts."
647 :group
'org-reveal-location
648 :type org-context-choice
)
650 (defcustom org-show-entry-below
'((default . nil
))
651 "Non-nil means show the entry below a headline when revealing a location.
652 Org-mode often shows locations in an org-mode file which might have
653 been invisible before. When this is set, the text below the headline that is
654 exposed is also shown.
656 By default this is off for all contexts.
657 Instead of t, this can also be an alist specifying this option for different
658 contexts. See `org-show-hierarchy-above' for valid contexts."
659 :group
'org-reveal-location
660 :type org-context-choice
)
662 (defcustom org-indirect-buffer-display
'other-window
663 "How should indirect tree buffers be displayed?
664 This applies to indirect buffers created with the commands
665 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
667 current-window Display in the current window
668 other-window Just display in another window.
669 dedicated-frame Create one new frame, and re-use it each time.
670 new-frame Make a new frame each time. Note that in this case
671 previously-made indirect buffers are kept, and you need to
672 kill these buffers yourself."
673 :group
'org-structure
674 :group
'org-agenda-windows
676 (const :tag
"In current window" current-window
)
677 (const :tag
"In current frame, other window" other-window
)
678 (const :tag
"Each time a new frame" new-frame
)
679 (const :tag
"One dedicated frame" dedicated-frame
)))
681 (defcustom org-use-speed-commands nil
682 "Non-nil means activate single letter commands at beginning of a headline.
683 This may also be a function to test for appropriate locations where speed
684 commands should be active."
685 :group
'org-structure
687 (const :tag
"Never" nil
)
688 (const :tag
"At beginning of headline stars" t
)
691 (defcustom org-speed-commands-user nil
692 "Alist of additional speed commands.
693 This list will be checked before `org-speed-commands-default'
694 when the variable `org-use-speed-commands' is non-nil
695 and when the cursor is at the beginning of a headline.
696 The car if each entry is a string with a single letter, which must
697 be assigned to `self-insert-command' in the global map.
698 The cdr is either a command to be called interactively, a function
699 to be called, or a form to be evaluated.
700 An entry that is just a list with a single string will be interpreted
701 as a descriptive headline that will be added when listing the speed
702 copmmands in the Help buffer using the `?' speed command."
703 :group
'org-structure
704 :type
'(repeat :value
("k" . ignore
)
705 (choice :value
("k" . ignore
)
706 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
707 (cons :tag
"Letter and Command"
708 (string :tag
"Command letter")
713 (defgroup org-cycle nil
714 "Options concerning visibility cycling in Org-mode."
716 :group
'org-structure
)
718 (defcustom org-cycle-skip-children-state-if-no-children t
719 "Non-nil means skip CHILDREN state in entries that don't have any."
723 (defcustom org-cycle-max-level nil
724 "Maximum level which should still be subject to visibility cycling.
725 Levels higher than this will, for cycling, be treated as text, not a headline.
726 When `org-odd-levels-only' is set, a value of N in this variable actually
727 means 2N-1 stars as the limiting headline.
728 When nil, cycle all levels.
729 Note that the limiting level of cycling is also influenced by
730 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
731 `org-inlinetask-min-level' is, cycling will be limited to levels one less
735 (const :tag
"No limit" nil
)
736 (integer :tag
"Maximum level")))
738 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
739 "Names of drawers. Drawers are not opened by cycling on the headline above.
740 Drawers only open with a TAB on the drawer line itself. A drawer looks like
745 The drawer \"PROPERTIES\" is special for capturing properties through
748 Drawers can be defined on the per-file basis with a line like:
750 #+DRAWERS: HIDDEN STATE PROPERTIES"
751 :group
'org-structure
753 :type
'(repeat (string :tag
"Drawer Name")))
755 (defcustom org-hide-block-startup nil
756 "Non-nil means entering Org-mode will fold all blocks.
757 This can also be set in on a per-file basis with
759 #+STARTUP: hideblocks
760 #+STARTUP: showblocks"
765 (defcustom org-cycle-global-at-bob nil
766 "Cycle globally if cursor is at beginning of buffer and not at a headline.
767 This makes it possible to do global cycling without having to use S-TAB or
768 C-u TAB. For this special case to work, the first line of the buffer
769 must not be a headline - it may be empty or some other text. When used in
770 this way, `org-cycle-hook' is disables temporarily, to make sure the
771 cursor stays at the beginning of the buffer.
772 When this option is nil, don't do anything special at the beginning
777 (defcustom org-cycle-level-after-item
/entry-creation t
778 "Non-nil means cycle entry level or item indentation in new empty entries.
780 When the cursor is at the end of an empty headline, i.e with only stars
781 and maybe a TODO keyword, TAB will then switch the entry to become a child,
782 and then all possible anchestor states, before returning to the original state.
783 This makes data entry extremely fast: M-RET to create a new headline,
784 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
786 When the cursor is at the end of an empty plain list item, one TAB will
787 make it a subitem, two or more tabs will back up to make this an item
788 higher up in the item hierarchy."
792 (defcustom org-cycle-emulate-tab t
793 "Where should `org-cycle' emulate TAB.
795 white Only in completely white lines
796 whitestart Only at the beginning of lines, before the first non-white char
797 t Everywhere except in headlines
798 exc-hl-bol Everywhere except at the start of a headline
799 If TAB is used in a place where it does not emulate TAB, the current subtree
800 visibility is cycled."
802 :type
'(choice (const :tag
"Never" nil
)
803 (const :tag
"Only in completely white lines" white
)
804 (const :tag
"Before first char in a line" whitestart
)
805 (const :tag
"Everywhere except in headlines" t
)
806 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
809 (defcustom org-cycle-separator-lines
2
810 "Number of empty lines needed to keep an empty line between collapsed trees.
811 If you leave an empty line between the end of a subtree and the following
812 headline, this empty line is hidden when the subtree is folded.
813 Org-mode will leave (exactly) one empty line visible if the number of
814 empty lines is equal or larger to the number given in this variable.
815 So the default 2 means at least 2 empty lines after the end of a subtree
816 are needed to produce free space between a collapsed subtree and the
819 If the number is negative, and the number of empty lines is at least -N,
820 all empty lines are shown.
822 Special case: when 0, never leave empty lines in collapsed view."
825 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
827 (defcustom org-pre-cycle-hook nil
828 "Hook that is run before visibility cycling is happening.
829 The function(s) in this hook must accept a single argument which indicates
830 the new state that will be set right after running this hook. The
831 argument is a symbol. Before a global state change, it can have the values
832 `overview', `content', or `all'. Before a local state change, it can have
833 the values `folded', `children', or `subtree'."
837 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
838 org-cycle-hide-drawers
839 org-cycle-show-empty-lines
840 org-optimize-window-after-visibility-change
)
841 "Hook that is run after `org-cycle' has changed the buffer visibility.
842 The function(s) in this hook must accept a single argument which indicates
843 the new state that was set by the most recent `org-cycle' command. The
844 argument is a symbol. After a global state change, it can have the values
845 `overview', `content', or `all'. After a local state change, it can have
846 the values `folded', `children', or `subtree'."
850 (defgroup org-edit-structure nil
851 "Options concerning structure editing in Org-mode."
852 :tag
"Org Edit Structure"
853 :group
'org-structure
)
855 (defcustom org-odd-levels-only nil
856 "Non-nil means skip even levels and only use odd levels for the outline.
857 This has the effect that two stars are being added/taken away in
858 promotion/demotion commands. It also influences how levels are
859 handled by the exporters.
860 Changing it requires restart of `font-lock-mode' to become effective
861 for fontification also in regions already fontified.
862 You may also set this on a per-file basis by adding one of the following
867 :group
'org-edit-structure
868 :group
'org-appearance
871 (defcustom org-adapt-indentation t
872 "Non-nil means adapt indentation to outline node level.
874 When this variable is set, Org assumes that you write outlines by
875 indenting text in each node to align with the headline (after the stars).
876 The following issues are influenced by this variable:
878 - When this is set and the *entire* text in an entry is indented, the
879 indentation is increased by one space in a demotion command, and
880 decreased by one in a promotion command. If any line in the entry
881 body starts with text at column 0, indentation is not changed at all.
883 - Property drawers and planning information is inserted indented when
884 this variable s set. When nil, they will not be indented.
886 - TAB indents a line relative to context. The lines below a headline
887 will be indented when this variable is set.
889 Note that this is all about true indentation, by adding and removing
890 space characters. See also `org-indent.el' which does level-dependent
891 indentation in a virtual way, i.e. at display time in Emacs."
892 :group
'org-edit-structure
895 (defcustom org-special-ctrl-a
/e nil
896 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
898 When t, `C-a' will bring back the cursor to the beginning of the
899 headline text, i.e. after the stars and after a possible TODO keyword.
900 In an item, this will be the position after the bullet.
901 When the cursor is already at that position, another `C-a' will bring
902 it to the beginning of the line.
904 `C-e' will jump to the end of the headline, ignoring the presence of tags
905 in the headline. A second `C-e' will then jump to the true end of the
906 line, after any tags. This also means that, when this variable is
907 non-nil, `C-e' also will never jump beyond the end of the heading of a
908 folded section, i.e. not after the ellipses.
910 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
911 going to the true line boundary first. Only a directly following, identical
912 keypress will bring the cursor to the special positions.
914 This may also be a cons cell where the behavior for `C-a' and `C-e' is
916 :group
'org-edit-structure
918 (const :tag
"off" nil
)
919 (const :tag
"on: after stars/bullet and before tags first" t
)
920 (const :tag
"reversed: true line boundary first" reversed
)
921 (cons :tag
"Set C-a and C-e separately"
922 (choice :tag
"Special C-a"
923 (const :tag
"off" nil
)
924 (const :tag
"on: after stars/bullet first" t
)
925 (const :tag
"reversed: before stars/bullet first" reversed
))
926 (choice :tag
"Special C-e"
927 (const :tag
"off" nil
)
928 (const :tag
"on: before tags first" t
)
929 (const :tag
"reversed: after tags first" reversed
)))))
930 (if (fboundp 'defvaralias
)
931 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
933 (defcustom org-special-ctrl-k nil
934 "Non-nil means `C-k' will behave specially in headlines.
935 When nil, `C-k' will call the default `kill-line' command.
936 When t, the following will happen while the cursor is in the headline:
938 - When the cursor is at the beginning of a headline, kill the entire
939 line and possible the folded subtree below the line.
940 - When in the middle of the headline text, kill the headline up to the tags.
941 - When after the headline text, kill the tags."
942 :group
'org-edit-structure
945 (defcustom org-ctrl-k-protect-subtree nil
946 "Non-nil means, do not delete a hidden subtree with C-k.
947 When set to the symbol `error', simply throw an error when C-k is
948 used to kill (part-of) a headline that has hidden text behind it.
949 Any other non-nil value will result in a query to the user, if it is
950 OK to kill that hidden subtree. When nil, kill without remorse."
951 :group
'org-edit-structure
953 (const :tag
"Do not protect hidden subtrees" nil
)
954 (const :tag
"Protect hidden subtrees with a security query" t
)
955 (const :tag
"Never kill a hidden subtree with C-k" error
)))
957 (defcustom org-yank-folded-subtrees t
958 "Non-nil means when yanking subtrees, fold them.
959 If the kill is a single subtree, or a sequence of subtrees, i.e. if
960 it starts with a heading and all other headings in it are either children
961 or siblings, then fold all the subtrees. However, do this only if no
962 text after the yank would be swallowed into a folded tree by this action."
963 :group
'org-edit-structure
966 (defcustom org-yank-adjusted-subtrees nil
967 "Non-nil means when yanking subtrees, adjust the level.
968 With this setting, `org-paste-subtree' is used to insert the subtree, see
969 this function for details."
970 :group
'org-edit-structure
973 (defcustom org-M-RET-may-split-line
'((default . t
))
974 "Non-nil means M-RET will split the line at the cursor position.
975 When nil, it will go to the end of the line before making a
977 You may also set this option in a different way for different
978 contexts. Valid contexts are:
980 headline when creating a new headline
981 item when creating a new item
982 table in a table field
983 default the value to be used for all contexts not explicitly
985 :group
'org-structure
988 (const :tag
"Always" t
)
989 (const :tag
"Never" nil
)
990 (repeat :greedy t
:tag
"Individual contexts"
992 (choice :tag
"Context"
1000 (defcustom org-insert-heading-respect-content nil
1001 "Non-nil means insert new headings after the current subtree.
1002 When nil, the new heading is created directly after the current line.
1003 The commands \\[org-insert-heading-respect-content] and
1004 \\[org-insert-todo-heading-respect-content] turn this variable on
1005 for the duration of the command."
1006 :group
'org-structure
1009 (defcustom org-blank-before-new-entry
'((heading . auto
)
1010 (plain-list-item . auto
))
1011 "Should `org-insert-heading' leave a blank line before new heading/item?
1012 The value is an alist, with `heading' and `plain-list-item' as car,
1013 and a boolean flag as cdr. For plain lists, if the variable
1014 `org-empty-line-terminates-plain-lists' is set, the setting here
1015 is ignored and no empty line is inserted, to keep the list in tact."
1016 :group
'org-edit-structure
1018 (cons (const heading
)
1019 (choice (const :tag
"Never" nil
)
1020 (const :tag
"Always" t
)
1021 (const :tag
"Auto" auto
)))
1022 (cons (const plain-list-item
)
1023 (choice (const :tag
"Never" nil
)
1024 (const :tag
"Always" t
)
1025 (const :tag
"Auto" auto
)))))
1027 (defcustom org-insert-heading-hook nil
1028 "Hook being run after inserting a new heading."
1029 :group
'org-edit-structure
1032 (defcustom org-enable-fixed-width-editor t
1033 "Non-nil means lines starting with \":\" are treated as fixed-width.
1034 This currently only means they are never auto-wrapped.
1035 When nil, such lines will be treated like ordinary lines.
1036 See also the QUOTE keyword."
1037 :group
'org-edit-structure
1041 (defcustom org-goto-auto-isearch t
1042 "Non-nil means typing characters in org-goto starts incremental search."
1043 :group
'org-edit-structure
1046 (defgroup org-sparse-trees nil
1047 "Options concerning sparse trees in Org-mode."
1048 :tag
"Org Sparse Trees"
1049 :group
'org-structure
)
1051 (defcustom org-highlight-sparse-tree-matches t
1052 "Non-nil means highlight all matches that define a sparse tree.
1053 The highlights will automatically disappear the next time the buffer is
1054 changed by an edit command."
1055 :group
'org-sparse-trees
1058 (defcustom org-remove-highlights-with-change t
1059 "Non-nil means any change to the buffer will remove temporary highlights.
1060 Such highlights are created by `org-occur' and `org-clock-display'.
1061 When nil, `C-c C-c needs to be used to get rid of the highlights.
1062 The highlights created by `org-preview-latex-fragment' always need
1063 `C-c C-c' to be removed."
1064 :group
'org-sparse-trees
1069 (defcustom org-occur-hook
'(org-first-headline-recenter)
1070 "Hook that is run after `org-occur' has constructed a sparse tree.
1071 This can be used to recenter the window to show as much of the structure
1073 :group
'org-sparse-trees
1076 (defgroup org-imenu-and-speedbar nil
1077 "Options concerning imenu and speedbar in Org-mode."
1078 :tag
"Org Imenu and Speedbar"
1079 :group
'org-structure
)
1081 (defcustom org-imenu-depth
2
1082 "The maximum level for Imenu access to Org-mode headlines.
1083 This also applied for speedbar access."
1084 :group
'org-imenu-and-speedbar
1087 (defgroup org-table nil
1088 "Options concerning tables in Org-mode."
1092 (defcustom org-enable-table-editor
'optimized
1093 "Non-nil means lines starting with \"|\" are handled by the table editor.
1094 When nil, such lines will be treated like ordinary lines.
1096 When equal to the symbol `optimized', the table editor will be optimized to
1098 - Automatic overwrite mode in front of whitespace in table fields.
1099 This makes the structure of the table stay in tact as long as the edited
1100 field does not exceed the column width.
1101 - Minimize the number of realigns. Normally, the table is aligned each time
1102 TAB or RET are pressed to move to another field. With optimization this
1103 happens only if changes to a field might have changed the column width.
1104 Optimization requires replacing the functions `self-insert-command',
1105 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1106 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1107 very good at guessing when a re-align will be necessary, but you can always
1108 force one with \\[org-ctrl-c-ctrl-c].
1110 If you would like to use the optimized version in Org-mode, but the
1111 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1113 This variable can be used to turn on and off the table editor during a session,
1114 but in order to toggle optimization, a restart is required.
1116 See also the variable `org-table-auto-blank-field'."
1119 (const :tag
"off" nil
)
1121 (const :tag
"on, optimized" optimized
)))
1123 (defcustom org-self-insert-cluster-for-undo t
1124 "Non-nil means cluster self-insert commands for undo when possible.
1125 If this is set, then, like in the Emacs command loop, 20 consecutive
1126 characters will be undone together.
1127 This is configurable, because there is some impact on typing performance."
1131 (defcustom org-table-tab-recognizes-table.el t
1132 "Non-nil means TAB will automatically notice a table.el table.
1133 When it sees such a table, it moves point into it and - if necessary -
1134 calls `table-recognize-table'."
1135 :group
'org-table-editing
1138 (defgroup org-link nil
1139 "Options concerning links in Org-mode."
1143 (defvar org-link-abbrev-alist-local nil
1144 "Buffer-local version of `org-link-abbrev-alist', which see.
1145 The value of this is taken from the #+LINK lines.")
1146 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1148 (defcustom org-link-abbrev-alist nil
1149 "Alist of link abbreviations.
1150 The car of each element is a string, to be replaced at the start of a link.
1151 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1152 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1154 [[linkkey:tag][description]]
1156 The 'linkkey' must be a word word, starting with a letter, followed
1157 by letters, numbers, '-' or '_'.
1159 If REPLACE is a string, the tag will simply be appended to create the link.
1160 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1161 the placeholder \"%h\" will cause a url-encoded version of the tag to
1162 be inserted at that point (see the function `url-hexify-string').
1164 REPLACE may also be a function that will be called with the tag as the
1165 only argument to create the link, which should be returned as a string.
1167 See the manual for examples."
1171 (string :tag
"Protocol")
1173 (string :tag
"Format")
1176 (defcustom org-descriptive-links t
1177 "Non-nil means hide link part and only show description of bracket links.
1178 Bracket links are like [[link][description]]. This variable sets the initial
1179 state in new org-mode buffers. The setting can then be toggled on a
1180 per-buffer basis from the Org->Hyperlinks menu."
1184 (defcustom org-link-file-path-type
'adaptive
1185 "How the path name in file links should be stored.
1188 relative Relative to the current directory, i.e. the directory of the file
1189 into which the link is being inserted.
1190 absolute Absolute path, if possible with ~ for home directory.
1191 noabbrev Absolute path, no abbreviation of home directory.
1192 adaptive Use relative path for files in the current directory and sub-
1193 directories of it. For other files, use an absolute path."
1201 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1202 "Types of links that should be activated in Org-mode files.
1203 This is a list of symbols, each leading to the activation of a certain link
1204 type. In principle, it does not hurt to turn on most link types - there may
1205 be a small gain when turning off unused link types. The types are:
1207 bracket The recommended [[link][description]] or [[link]] links with hiding.
1208 angular Links in angular brackets that may contain whitespace like
1209 <bbdb:Carsten Dominik>.
1210 plain Plain links in normal text, no whitespace, like http://google.com.
1211 radio Text that is matched by a radio target, see manual for details.
1212 tag Tag settings in a headline (link to tag search).
1213 date Time stamps (link to calendar).
1214 footnote Footnote labels.
1216 Changing this variable requires a restart of Emacs to become effective."
1218 :type
'(set :greedy t
1219 (const :tag
"Double bracket links (new style)" bracket
)
1220 (const :tag
"Angular bracket links (old style)" angular
)
1221 (const :tag
"Plain text links" plain
)
1222 (const :tag
"Radio target matches" radio
)
1223 (const :tag
"Tags" tag
)
1224 (const :tag
"Timestamps" date
)
1225 (const :tag
"Footnotes" footnote
)))
1227 (defcustom org-make-link-description-function nil
1228 "Function to use to generate link descriptions from links. If
1229 nil the link location will be used. This function must take two
1230 parameters; the first is the link and the second the description
1231 org-insert-link has generated, and should return the description
1236 (defgroup org-link-store nil
1237 "Options concerning storing links in Org-mode."
1238 :tag
"Org Store Link"
1241 (defcustom org-email-link-description-format
"Email %c: %.30s"
1242 "Format of the description part of a link to an email or usenet message.
1243 The following %-escapes will be replaced by corresponding information:
1245 %F full \"From\" field
1246 %f name, taken from \"From\" field, address if no name
1247 %T full \"To\" field
1248 %t first name in \"To\" field, address if no name
1249 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1250 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1254 You may use normal field width specification between the % and the letter.
1255 This is for example useful to limit the length of the subject.
1257 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1258 :group
'org-link-store
1261 (defcustom org-from-is-user-regexp
1263 (when (and user-mail-address
(not (string= user-mail-address
"")))
1264 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1265 (when (and user-full-name
(not (string= user-full-name
"")))
1266 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1267 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1268 "Regexp matched against the \"From:\" header of an email or usenet message.
1269 It should match if the message is from the user him/herself."
1270 :group
'org-link-store
1273 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1274 "Non-nil means storing a link to an Org file will use entry IDs.
1276 Note that before this variable is even considered, org-id must be loaded,
1277 so please customize `org-modules' and turn it on.
1279 The variable can have the following values:
1281 t Create an ID if needed to make a link to the current entry.
1283 create-if-interactive
1284 If `org-store-link' is called directly (interactively, as a user
1285 command), do create an ID to support the link. But when doing the
1286 job for remember, only use the ID if it already exists. The
1287 purpose of this setting is to avoid proliferation of unwanted
1288 IDs, just because you happen to be in an Org file when you
1289 call `org-remember' that automatically and preemptively
1290 creates a link. If you do want to get an ID link in a remember
1291 template to an entry not having an ID, create it first by
1292 explicitly creating a link to it, using `C-c C-l' first.
1294 create-if-interactive-and-no-custom-id
1295 Like create-if-interactive, but do not create an ID if there is
1296 a CUSTOM_ID property defined in the entry. This is the default.
1299 Use existing ID, do not create one.
1301 nil Never use an ID to make a link, instead link using a text search for
1303 :group
'org-link-store
1305 (const :tag
"Create ID to make link" t
)
1306 (const :tag
"Create if storing link interactively"
1307 create-if-interactive
)
1308 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1309 create-if-interactive-and-no-custom-id
)
1310 (const :tag
"Only use existing" use-existing
)
1311 (const :tag
"Do not use ID to create link" nil
)))
1313 (defcustom org-context-in-file-links t
1314 "Non-nil means file links from `org-store-link' contain context.
1315 A search string will be added to the file name with :: as separator and
1316 used to find the context when the link is activated by the command
1317 `org-open-at-point'.
1318 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1319 negates this setting for the duration of the command."
1320 :group
'org-link-store
1323 (defcustom org-keep-stored-link-after-insertion nil
1324 "Non-nil means keep link in list for entire session.
1326 The command `org-store-link' adds a link pointing to the current
1327 location to an internal list. These links accumulate during a session.
1328 The command `org-insert-link' can be used to insert links into any
1329 Org-mode file (offering completion for all stored links). When this
1330 option is nil, every link which has been inserted once using \\[org-insert-link]
1331 will be removed from the list, to make completing the unused links
1333 :group
'org-link-store
1336 (defgroup org-link-follow nil
1337 "Options concerning following links in Org-mode."
1338 :tag
"Org Follow Link"
1341 (defcustom org-link-translation-function nil
1342 "Function to translate links with different syntax to Org syntax.
1343 This can be used to translate links created for example by the Planner
1344 or emacs-wiki packages to Org syntax.
1345 The function must accept two parameters, a TYPE containing the link
1346 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1347 which is everything after the link protocol. It should return a cons
1348 with possibly modified values of type and path.
1349 Org contains a function for this, so if you set this variable to
1350 `org-translate-link-from-planner', you should be able follow many
1351 links created by planner."
1352 :group
'org-link-follow
1355 (defcustom org-follow-link-hook nil
1356 "Hook that is run after a link has been followed."
1357 :group
'org-link-follow
1360 (defcustom org-tab-follows-link nil
1361 "Non-nil means on links TAB will follow the link.
1362 Needs to be set before org.el is loaded.
1363 This really should not be used, it does not make sense, and the
1364 implementation is bad."
1365 :group
'org-link-follow
1368 (defcustom org-return-follows-link nil
1369 "Non-nil means on links RET will follow the link."
1370 :group
'org-link-follow
1373 (defcustom org-mouse-1-follows-link
1374 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1375 "Non-nil means mouse-1 on a link will follow the link.
1376 A longer mouse click will still set point. Does not work on XEmacs.
1377 Needs to be set before org.el is loaded."
1378 :group
'org-link-follow
1381 (defcustom org-mark-ring-length
4
1382 "Number of different positions to be recorded in the ring
1383 Changing this requires a restart of Emacs to work correctly."
1384 :group
'org-link-follow
1387 (defcustom org-link-frame-setup
1388 '((vm . vm-visit-folder-other-frame
)
1389 (gnus . gnus-other-frame
)
1390 (file . find-file-other-window
)
1391 (wl . wl-other-frame
))
1392 "Setup the frame configuration for following links.
1393 When following a link with Emacs, it may often be useful to display
1394 this link in another window or frame. This variable can be used to
1395 set this up for the different types of links.
1398 `vm-visit-folder-other-frame'
1399 For Gnus, use any of
1402 `org-gnus-no-new-news'
1403 For FILE, use any of
1405 `find-file-other-window'
1406 `find-file-other-frame'
1407 For Wanderlust use any of
1410 For the calendar, use the variable `calendar-setup'.
1411 For BBDB, it is currently only possible to display the matches in
1413 :group
'org-link-follow
1417 (const vm-visit-folder
)
1418 (const vm-visit-folder-other-window
)
1419 (const vm-visit-folder-other-frame
)))
1423 (const gnus-other-frame
)
1424 (const org-gnus-no-new-news
)))
1428 (const find-file-other-window
)
1429 (const find-file-other-frame
)))
1433 (const wl-other-frame
)))))
1435 (defcustom org-display-internal-link-with-indirect-buffer nil
1436 "Non-nil means use indirect buffer to display infile links.
1437 Activating internal links (from one location in a file to another location
1438 in the same file) normally just jumps to the location. When the link is
1439 activated with a C-u prefix (or with mouse-3), the link is displayed in
1440 another window. When this option is set, the other window actually displays
1441 an indirect buffer clone of the current buffer, to avoid any visibility
1442 changes to the current buffer."
1443 :group
'org-link-follow
1446 (defcustom org-open-non-existing-files nil
1447 "Non-nil means `org-open-file' will open non-existing files.
1448 When nil, an error will be generated.
1449 This variable applies only to external applications because they
1450 might choke on non-existing files. If the link is to a file that
1451 will be opened in Emacs, the variable is ignored."
1452 :group
'org-link-follow
1455 (defcustom org-open-directory-means-index-dot-org nil
1456 "Non-nil means a link to a directory really means to index.org.
1457 When nil, following a directory link will run dired or open a finder/explorer
1458 window on that directory."
1459 :group
'org-link-follow
1462 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1463 "Function and arguments to call for following mailto links.
1464 This is a list with the first element being a lisp function, and the
1465 remaining elements being arguments to the function. In string arguments,
1466 %a will be replaced by the address, and %s will be replaced by the subject
1467 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1468 :group
'org-link-follow
1470 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1471 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1472 (const :tag
"message-mail" (message-mail "%a" "%s"))
1473 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1475 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1476 "Non-nil means ask for confirmation before executing shell links.
1477 Shell links can be dangerous: just think about a link
1479 [[shell:rm -rf ~/*][Google Search]]
1481 This link would show up in your Org-mode document as \"Google Search\",
1482 but really it would remove your entire home directory.
1483 Therefore we advise against setting this variable to nil.
1484 Just change it to `y-or-n-p' if you want to confirm with a
1485 single keystroke rather than having to type \"yes\"."
1486 :group
'org-link-follow
1488 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1489 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1490 (const :tag
"no confirmation (dangerous)" nil
)))
1491 (put 'org-confirm-shell-link-function
1492 'safe-local-variable
1493 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1495 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1496 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1497 Elisp links can be dangerous: just think about a link
1499 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1501 This link would show up in your Org-mode document as \"Google Search\",
1502 but really it would remove your entire home directory.
1503 Therefore we advise against setting this variable to nil.
1504 Just change it to `y-or-n-p' if you want to confirm with a
1505 single keystroke rather than having to type \"yes\"."
1506 :group
'org-link-follow
1508 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1509 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1510 (const :tag
"no confirmation (dangerous)" nil
)))
1511 (put 'org-confirm-shell-link-function
1512 'safe-local-variable
1513 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1515 (defconst org-file-apps-defaults-gnu
1519 "Default file applications on a UNIX or GNU/Linux system.
1520 See `org-file-apps'.")
1522 (defconst org-file-apps-defaults-macosx
1525 (system .
"open %s")
1527 ("eps.gz" .
"gv %s")
1529 ("fig" .
"xfig %s"))
1530 "Default file applications on a MacOS X system.
1531 The system \"open\" is known as a default, but we use X11 applications
1532 for some files for which the OS does not have a good default.
1533 See `org-file-apps'.")
1535 (defconst org-file-apps-defaults-windowsnt
1539 (list (if (featurep 'xemacs
)
1540 'mswindows-shell-execute
1544 (list (if (featurep 'xemacs
)
1545 'mswindows-shell-execute
1548 "Default file applications on a Windows NT system.
1549 The system \"open\" is used for most files.
1550 See `org-file-apps'.")
1552 (defcustom org-file-apps
1555 ("\\.mm\\'" . default
)
1556 ("\\.x?html?\\'" . default
)
1557 ("\\.pdf\\'" . default
)
1559 "External applications for opening `file:path' items in a document.
1560 Org-mode uses system defaults for different file types, but
1561 you can use this variable to set the application for a given file
1562 extension. The entries in this list are cons cells where the car identifies
1563 files and the cdr the corresponding command. Possible values for the
1565 \"string\" A string as a file identifier can be interpreted in different
1566 ways, depending on its contents:
1568 - Alphanumeric characters only:
1569 Match links with this file extension.
1570 Example: (\"pdf\" . \"evince %s\")
1571 to open PDFs with evince.
1573 - Regular expression: Match links where the
1574 filename matches the regexp. If you want to
1575 use groups here, use shy groups.
1577 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1578 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1579 to open *.html and *.xhtml with firefox.
1581 - Regular expression which contains (non-shy) groups:
1582 Match links where the whole link, including \"::\", and
1583 anything after that, matches the regexp.
1584 In a custom command string, %1, %2, etc. are replaced with
1585 the parts of the link that were matched by the groups.
1586 For backwards compatibility, if a command string is given
1587 that does not use any of the group matches, this case is
1588 handled identically to the second one (i.e. match against
1591 In a custom lisp form, you can access the group matches with
1592 (match-string n link).
1594 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1595 to open [[file:document.pdf::5]] with evince at page 5.
1597 `directory' Matches a directory
1598 `remote' Matches a remote file, accessible through tramp or efs.
1599 Remote files most likely should be visited through Emacs
1600 because external applications cannot handle such paths.
1601 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1602 so all files Emacs knows how to handle. Using this with
1603 command `emacs' will open most files in Emacs. Beware that this
1604 will also open html files inside Emacs, unless you add
1605 (\"html\" . default) to the list as well.
1606 t Default for files not matched by any of the other options.
1607 `system' The system command to open files, like `open' on Windows
1608 and Mac OS X, and mailcap under GNU/Linux. This is the command
1609 that will be selected if you call `C-c C-o' with a double
1612 Possible values for the command are:
1613 `emacs' The file will be visited by the current Emacs process.
1614 `default' Use the default application for this file type, which is the
1615 association for t in the list, most likely in the system-specific
1617 This can be used to overrule an unwanted setting in the
1618 system-specific variable.
1619 `system' Use the system command for opening files, like \"open\".
1620 This command is specified by the entry whose car is `system'.
1621 Most likely, the system-specific version of this variable
1622 does define this command, but you can overrule/replace it
1624 string A command to be executed by a shell; %s will be replaced
1625 by the path to the file.
1626 sexp A Lisp form which will be evaluated. The file path will
1627 be available in the Lisp variable `file'.
1628 For more examples, see the system specific constants
1629 `org-file-apps-defaults-macosx'
1630 `org-file-apps-defaults-windowsnt'
1631 `org-file-apps-defaults-gnu'."
1632 :group
'org-link-follow
1634 (cons (choice :value
""
1635 (string :tag
"Extension")
1636 (const :tag
"System command to open files" system
)
1637 (const :tag
"Default for unrecognized files" t
)
1638 (const :tag
"Remote file" remote
)
1639 (const :tag
"Links to a directory" directory
)
1640 (const :tag
"Any files that have Emacs modes"
1643 (const :tag
"Visit with Emacs" emacs
)
1644 (const :tag
"Use default" default
)
1645 (const :tag
"Use the system command" system
)
1646 (string :tag
"Command")
1647 (sexp :tag
"Lisp form")))))
1651 (defgroup org-refile nil
1652 "Options concerning refiling entries in Org-mode."
1656 (defcustom org-directory
"~/org"
1657 "Directory with org files.
1658 This is just a default location to look for Org files. There is no need
1659 at all to put your files into this directory. It is only used in the
1660 following situations:
1662 1. When a remember template specifies a target file that is not an
1663 absolute path. The path will then be interpreted relative to
1665 2. When a remember note is filed away in an interactive way (when exiting the
1666 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1667 with `org-directory' as the default path."
1669 :group
'org-remember
1672 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1673 "Default target for storing notes.
1674 Used by the hooks for remember.el. This can be a string, or nil to mean
1675 the value of `remember-data-file'.
1676 You can set this on a per-template basis with the variable
1677 `org-remember-templates'."
1679 :group
'org-remember
1681 (const :tag
"Default from remember-data-file" nil
)
1684 (defcustom org-goto-interface
'outline
1685 "The default interface to be used for `org-goto'.
1687 outline The interface shows an outline of the relevant file
1688 and the correct heading is found by moving through
1689 the outline or by searching with incremental search.
1690 outline-path-completion Headlines in the current buffer are offered via
1691 completion. This is the interface also used by
1692 the refile command."
1695 (const :tag
"Outline" outline
)
1696 (const :tag
"Outline-path-completion" outline-path-completion
)))
1698 (defcustom org-goto-max-level
5
1699 "Maximum level to be considered when running org-goto with refile interface."
1703 (defcustom org-reverse-note-order nil
1704 "Non-nil means store new notes at the beginning of a file or entry.
1705 When nil, new notes will be filed to the end of a file or entry.
1706 This can also be a list with cons cells of regular expressions that
1707 are matched against file names, and values."
1708 :group
'org-remember
1711 (const :tag
"Reverse always" t
)
1712 (const :tag
"Reverse never" nil
)
1713 (repeat :tag
"By file name regexp"
1714 (cons regexp boolean
))))
1716 (defcustom org-log-refile nil
1717 "Information to record when a task is refiled.
1719 Possible values are:
1721 nil Don't add anything
1722 time Add a time stamp to the task
1723 note Prompt for a note and add it with template `org-log-note-headings'
1725 This option can also be set with on a per-file-basis with
1727 #+STARTUP: nologrefile
1728 #+STARTUP: logrefile
1729 #+STARTUP: lognoterefile
1731 You can have local logging settings for a subtree by setting the LOGGING
1732 property to one or more of these keywords.
1734 When bulk-refiling from the agenda, the value `note' is forbidden and
1735 will temporarily be changed to `time'."
1737 :group
'org-progress
1739 (const :tag
"No logging" nil
)
1740 (const :tag
"Record timestamp" time
)
1741 (const :tag
"Record timestamp with note." note
)))
1743 (defcustom org-refile-targets nil
1744 "Targets for refiling entries with \\[org-refile].
1745 This is list of cons cells. Each cell contains:
1746 - a specification of the files to be considered, either a list of files,
1747 or a symbol whose function or variable value will be used to retrieve
1748 a file name or a list of file names. If you use `org-agenda-files' for
1749 that, all agenda files will be scanned for targets. Nil means consider
1750 headings in the current buffer.
1751 - A specification of how to find candidate refile targets. This may be
1753 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1754 This tag has to be present in all target headlines, inheritance will
1756 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1758 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1759 headlines that are refiling targets.
1760 - a cons cell (:level . N). Any headline of level N is considered a target.
1761 Note that, when `org-odd-levels-only' is set, level corresponds to
1762 order in hierarchy, not to the number of stars.
1763 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1764 Note that, when `org-odd-levels-only' is set, level corresponds to
1765 order in hierarchy, not to the number of stars.
1767 You can set the variable `org-refile-target-verify-function' to a function
1768 to verify each headline found by the simple critery above.
1770 When this variable is nil, all top-level headlines in the current buffer
1771 are used, equivalent to the value `((nil . (:level . 1))'."
1775 (choice :value org-agenda-files
1776 (const :tag
"All agenda files" org-agenda-files
)
1777 (const :tag
"Current buffer" nil
)
1778 (function) (variable) (file))
1779 (choice :tag
"Identify target headline by"
1780 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1781 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1782 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1783 (cons :tag
"Level number" (const :value
:level
) (integer))
1784 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1786 (defcustom org-refile-target-verify-function nil
1787 "Function to verify if the headline at point should be a refile target.
1788 The function will be called without arguments, with point at the
1789 beginning of the headline. It should return t and leave point
1790 where it is if the headline is a valid target for refiling.
1792 If the target should not be selected, the function must return nil.
1793 In addition to this, it may move point to a place from where the search
1794 should be continued. For example, the function may decide that the entire
1795 subtree of the current entry should be excluded and move point to the end
1800 (defcustom org-refile-use-cache nil
1801 "Non-nil means cache refile targets to speed up the process.
1802 The cache for a particular file will be updated automatically when
1803 the buffer has been killed, or when any of the marker used for flagging
1804 refile targets no longer points at a live buffer.
1805 If you have added new entries to a buffer that might themselves be targets,
1806 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
1807 find that easier, `C-u C-u C-u C-c C-w'."
1811 (defcustom org-refile-use-outline-path nil
1812 "Non-nil means provide refile targets as paths.
1813 So a level 3 headline will be available as level1/level2/level3.
1815 When the value is `file', also include the file name (without directory)
1816 into the path. In this case, you can also stop the completion after
1817 the file name, to get entries inserted as top level in the file.
1819 When `full-file-path', include the full file path."
1822 (const :tag
"Not" nil
)
1823 (const :tag
"Yes" t
)
1824 (const :tag
"Start with file name" file
)
1825 (const :tag
"Start with full file path" full-file-path
)))
1827 (defcustom org-outline-path-complete-in-steps t
1828 "Non-nil means complete the outline path in hierarchical steps.
1829 When Org-mode uses the refile interface to select an outline path
1830 \(see variable `org-refile-use-outline-path'), the completion of
1831 the path can be done is a single go, or if can be done in steps down
1832 the headline hierarchy. Going in steps is probably the best if you
1833 do not use a special completion package like `ido' or `icicles'.
1834 However, when using these packages, going in one step can be very
1835 fast, while still showing the whole path to the entry."
1839 (defcustom org-refile-allow-creating-parent-nodes nil
1840 "Non-nil means allow to create new nodes as refile targets.
1841 New nodes are then created by adding \"/new node name\" to the completion
1842 of an existing node. When the value of this variable is `confirm',
1843 new node creation must be confirmed by the user (recommended)
1844 When nil, the completion must match an existing entry.
1846 Note that, if the new heading is not seen by the criteria
1847 listed in `org-refile-targets', multiple instances of the same
1848 heading would be created by trying again to file under the new
1852 (const :tag
"Never" nil
)
1853 (const :tag
"Always" t
)
1854 (const :tag
"Prompt for confirmation" confirm
)))
1856 (defgroup org-todo nil
1857 "Options concerning TODO items in Org-mode."
1861 (defgroup org-progress nil
1862 "Options concerning Progress logging in Org-mode."
1866 (defvar org-todo-interpretation-widgets
1868 (:tag
"Sequence (cycling hits every state)" sequence
)
1869 (:tag
"Type (cycling directly to DONE)" type
))
1870 "The available interpretation symbols for customizing
1871 `org-todo-keywords'.
1872 Interested libraries should add to this list.")
1874 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1875 "List of TODO entry keyword sequences and their interpretation.
1876 \\<org-mode-map>This is a list of sequences.
1878 Each sequence starts with a symbol, either `sequence' or `type',
1879 indicating if the keywords should be interpreted as a sequence of
1880 action steps, or as different types of TODO items. The first
1881 keywords are states requiring action - these states will select a headline
1882 for inclusion into the global TODO list Org-mode produces. If one of
1883 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1884 signify that no further action is necessary. If \"|\" is not found,
1885 the last keyword is treated as the only DONE state of the sequence.
1887 The command \\[org-todo] cycles an entry through these states, and one
1888 additional state where no keyword is present. For details about this
1889 cycling, see the manual.
1891 TODO keywords and interpretation can also be set on a per-file basis with
1892 the special #+SEQ_TODO and #+TYP_TODO lines.
1894 Each keyword can optionally specify a character for fast state selection
1895 \(in combination with the variable `org-use-fast-todo-selection')
1896 and specifiers for state change logging, using the same syntax
1897 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1898 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1899 indicates to record a time stamp each time this state is selected.
1901 Each keyword may also specify if a timestamp or a note should be
1902 recorded when entering or leaving the state, by adding additional
1903 characters in the parenthesis after the keyword. This looks like this:
1904 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1905 record only the time of the state change. With X and Y being either
1906 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1907 Y when leaving the state if and only if the *target* state does not
1908 define X. You may omit any of the fast-selection key or X or /Y,
1909 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1911 For backward compatibility, this variable may also be just a list
1912 of keywords - in this case the interpretation (sequence or type) will be
1913 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1915 :group
'org-keywords
1917 (repeat :tag
"Old syntax, just keywords"
1918 (string :tag
"Keyword"))
1919 (repeat :tag
"New syntax"
1922 :tag
"Interpretation"
1923 ;;Quick and dirty way to see
1924 ;;`org-todo-interpretations'. This takes the
1925 ;;place of item arguments
1933 org-todo-interpretation-widgets
))
1936 (string :tag
"Keyword"))))))
1938 (defvar org-todo-keywords-1 nil
1939 "All TODO and DONE keywords active in a buffer.")
1940 (make-variable-buffer-local 'org-todo-keywords-1
)
1941 (defvar org-todo-keywords-for-agenda nil
)
1942 (defvar org-done-keywords-for-agenda nil
)
1943 (defvar org-drawers-for-agenda nil
)
1944 (defvar org-todo-keyword-alist-for-agenda nil
)
1945 (defvar org-tag-alist-for-agenda nil
)
1946 (defvar org-agenda-contributing-files nil
)
1947 (defvar org-not-done-keywords nil
)
1948 (make-variable-buffer-local 'org-not-done-keywords
)
1949 (defvar org-done-keywords nil
)
1950 (make-variable-buffer-local 'org-done-keywords
)
1951 (defvar org-todo-heads nil
)
1952 (make-variable-buffer-local 'org-todo-heads
)
1953 (defvar org-todo-sets nil
)
1954 (make-variable-buffer-local 'org-todo-sets
)
1955 (defvar org-todo-log-states nil
)
1956 (make-variable-buffer-local 'org-todo-log-states
)
1957 (defvar org-todo-kwd-alist nil
)
1958 (make-variable-buffer-local 'org-todo-kwd-alist
)
1959 (defvar org-todo-key-alist nil
)
1960 (make-variable-buffer-local 'org-todo-key-alist
)
1961 (defvar org-todo-key-trigger nil
)
1962 (make-variable-buffer-local 'org-todo-key-trigger
)
1964 (defcustom org-todo-interpretation
'sequence
1965 "Controls how TODO keywords are interpreted.
1966 This variable is in principle obsolete and is only used for
1967 backward compatibility, if the interpretation of todo keywords is
1968 not given already in `org-todo-keywords'. See that variable for
1971 :group
'org-keywords
1972 :type
'(choice (const sequence
)
1975 (defcustom org-use-fast-todo-selection t
1976 "Non-nil means use the fast todo selection scheme with C-c C-t.
1977 This variable describes if and under what circumstances the cycling
1978 mechanism for TODO keywords will be replaced by a single-key, direct
1981 When nil, fast selection is never used.
1983 When the symbol `prefix', it will be used when `org-todo' is called with
1984 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1985 in an agenda buffer.
1987 When t, fast selection is used by default. In this case, the prefix
1988 argument forces cycling instead.
1990 In all cases, the special interface is only used if access keys have actually
1991 been assigned by the user, i.e. if keywords in the configuration are followed
1992 by a letter in parenthesis, like TODO(t)."
1995 (const :tag
"Never" nil
)
1996 (const :tag
"By default" t
)
1997 (const :tag
"Only with C-u C-c C-t" prefix
)))
1999 (defcustom org-provide-todo-statistics t
2000 "Non-nil means update todo statistics after insert and toggle.
2001 ALL-HEADLINES means update todo statistics by including headlines
2002 with no TODO keyword as well, counting them as not done.
2003 A list of TODO keywords means the same, but skip keywords that are
2006 When this is set, todo statistics is updated in the parent of the
2007 current entry each time a todo state is changed."
2010 (const :tag
"Yes, only for TODO entries" t
)
2011 (const :tag
"Yes, including all entries" 'all-headlines
)
2012 (repeat :tag
"Yes, for TODOs in this list"
2013 (string :tag
"TODO keyword"))
2014 (other :tag
"No TODO statistics" nil
)))
2016 (defcustom org-hierarchical-todo-statistics t
2017 "Non-nil means TODO statistics covers just direct children.
2018 When nil, all entries in the subtree are considered.
2019 This has only an effect if `org-provide-todo-statistics' is set.
2020 To set this to nil for only a single subtree, use a COOKIE_DATA
2021 property and include the word \"recursive\" into the value."
2025 (defcustom org-after-todo-state-change-hook nil
2026 "Hook which is run after the state of a TODO item was changed.
2027 The new state (a string with a TODO keyword, or nil) is available in the
2028 Lisp variable `state'."
2032 (defvar org-blocker-hook nil
2033 "Hook for functions that are allowed to block a state change.
2035 Each function gets as its single argument a property list, see
2036 `org-trigger-hook' for more information about this list.
2038 If any of the functions in this hook returns nil, the state change
2041 (defvar org-trigger-hook nil
2042 "Hook for functions that are triggered by a state change.
2044 Each function gets as its single argument a property list with at least
2045 the following elements:
2047 (:type type-of-change :position pos-at-entry-start
2048 :from old-state :to new-state)
2050 Depending on the type, more properties may be present.
2052 This mechanism is currently implemented for:
2056 :type todo-state-change
2057 :from previous state (keyword as a string), or nil, or a symbol
2058 'todo' or 'done', to indicate the general type of state.
2059 :to new state, like in :from")
2061 (defcustom org-enforce-todo-dependencies nil
2062 "Non-nil means undone TODO entries will block switching the parent to DONE.
2063 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2064 be blocked if any prior sibling is not yet done.
2065 Finally, if the parent is blocked because of ordered siblings of its own,
2066 the child will also be blocked.
2067 This variable needs to be set before org.el is loaded, and you need to
2068 restart Emacs after a change to make the change effective. The only way
2069 to change is while Emacs is running is through the customize interface."
2070 :set
(lambda (var val
)
2073 (add-hook 'org-blocker-hook
2074 'org-block-todo-from-children-or-siblings-or-parent
)
2075 (remove-hook 'org-blocker-hook
2076 'org-block-todo-from-children-or-siblings-or-parent
)))
2080 (defcustom org-enforce-todo-checkbox-dependencies nil
2081 "Non-nil means unchecked boxes will block switching the parent to DONE.
2082 When this is nil, checkboxes have no influence on switching TODO states.
2083 When non-nil, you first need to check off all check boxes before the TODO
2084 entry can be switched to DONE.
2085 This variable needs to be set before org.el is loaded, and you need to
2086 restart Emacs after a change to make the change effective. The only way
2087 to change is while Emacs is running is through the customize interface."
2088 :set
(lambda (var val
)
2091 (add-hook 'org-blocker-hook
2092 'org-block-todo-from-checkboxes
)
2093 (remove-hook 'org-blocker-hook
2094 'org-block-todo-from-checkboxes
)))
2098 (defcustom org-treat-insert-todo-heading-as-state-change nil
2099 "Non-nil means inserting a TODO heading is treated as state change.
2100 So when the command \\[org-insert-todo-heading] is used, state change
2101 logging will apply if appropriate. When nil, the new TODO item will
2102 be inserted directly, and no logging will take place."
2106 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2107 "Non-nil means switching TODO states with S-cursor counts as state change.
2108 This is the default behavior. However, setting this to nil allows a
2109 convenient way to select a TODO state and bypass any logging associated
2114 (defcustom org-todo-state-tags-triggers nil
2115 "Tag changes that should be triggered by TODO state changes.
2116 This is a list. Each entry is
2118 (state-change (tag . flag) .......)
2120 State-change can be a string with a state, and empty string to indicate the
2121 state that has no TODO keyword, or it can be one of the symbols `todo'
2122 or `done', meaning any not-done or done state, respectively."
2126 (cons (choice :tag
"When changing to"
2127 (const :tag
"Not-done state" todo
)
2128 (const :tag
"Done state" done
)
2129 (string :tag
"State"))
2131 (cons :tag
"Tag action"
2133 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2135 (defcustom org-log-done nil
2136 "Information to record when a task moves to the DONE state.
2138 Possible values are:
2140 nil Don't add anything, just change the keyword
2141 time Add a time stamp to the task
2142 note Prompt for a note and add it with template `org-log-note-headings'
2144 This option can also be set with on a per-file-basis with
2146 #+STARTUP: nologdone
2148 #+STARTUP: lognotedone
2150 You can have local logging settings for a subtree by setting the LOGGING
2151 property to one or more of these keywords."
2153 :group
'org-progress
2155 (const :tag
"No logging" nil
)
2156 (const :tag
"Record CLOSED timestamp" time
)
2157 (const :tag
"Record CLOSED timestamp with note." note
)))
2159 ;; Normalize old uses of org-log-done.
2161 ((eq org-log-done t
) (setq org-log-done
'time
))
2162 ((and (listp org-log-done
) (memq 'done org-log-done
))
2163 (setq org-log-done
'note
)))
2165 (defcustom org-log-reschedule nil
2166 "Information to record when the scheduling date of a tasks is modified.
2168 Possible values are:
2170 nil Don't add anything, just change the date
2171 time Add a time stamp to the task
2172 note Prompt for a note and add it with template `org-log-note-headings'
2174 This option can also be set with on a per-file-basis with
2176 #+STARTUP: nologreschedule
2177 #+STARTUP: logreschedule
2178 #+STARTUP: lognotereschedule"
2180 :group
'org-progress
2182 (const :tag
"No logging" nil
)
2183 (const :tag
"Record timestamp" time
)
2184 (const :tag
"Record timestamp with note." note
)))
2186 (defcustom org-log-redeadline nil
2187 "Information to record when the deadline date of a tasks is modified.
2189 Possible values are:
2191 nil Don't add anything, just change the date
2192 time Add a time stamp to the task
2193 note Prompt for a note and add it with template `org-log-note-headings'
2195 This option can also be set with on a per-file-basis with
2197 #+STARTUP: nologredeadline
2198 #+STARTUP: logredeadline
2199 #+STARTUP: lognoteredeadline
2201 You can have local logging settings for a subtree by setting the LOGGING
2202 property to one or more of these keywords."
2204 :group
'org-progress
2206 (const :tag
"No logging" nil
)
2207 (const :tag
"Record timestamp" time
)
2208 (const :tag
"Record timestamp with note." note
)))
2210 (defcustom org-log-note-clock-out nil
2211 "Non-nil means record a note when clocking out of an item.
2212 This can also be configured on a per-file basis by adding one of
2213 the following lines anywhere in the buffer:
2215 #+STARTUP: lognoteclock-out
2216 #+STARTUP: nolognoteclock-out"
2218 :group
'org-progress
2221 (defcustom org-log-done-with-time t
2222 "Non-nil means the CLOSED time stamp will contain date and time.
2223 When nil, only the date will be recorded."
2224 :group
'org-progress
2227 (defcustom org-log-note-headings
2228 '((done .
"CLOSING NOTE %t")
2229 (state .
"State %-12s from %-12S %t")
2230 (note .
"Note taken on %t")
2231 (reschedule .
"Rescheduled from %S on %t")
2232 (delschedule .
"Not scheduled, was %S on %t")
2233 (redeadline .
"New deadline from %S on %t")
2234 (deldeadline .
"Removed deadline, was %S on %t")
2235 (refile .
"Refiled on %t")
2237 "Headings for notes added to entries.
2238 The value is an alist, with the car being a symbol indicating the note
2239 context, and the cdr is the heading to be used. The heading may also be the
2241 %t in the heading will be replaced by a time stamp.
2242 %T will be an acive time stamp instead the default inacive one
2243 %s will be replaced by the new TODO state, in double quotes.
2244 %S will be replaced by the old TODO state, in double quotes.
2245 %u will be replaced by the user name.
2246 %U will be replaced by the full user name.
2248 In fact, it is not a good idea to change the `state' entry, because
2249 agenda log mode depends on the format of these entries."
2251 :group
'org-progress
2252 :type
'(list :greedy t
2253 (cons (const :tag
"Heading when closing an item" done
) string
)
2255 "Heading when changing todo state (todo sequence only)"
2257 (cons (const :tag
"Heading when just taking a note" note
) string
)
2258 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2259 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2260 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2261 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2262 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2263 (cons (const :tag
"Heading when refiling" refile
) string
)))
2265 (unless (assq 'note org-log-note-headings
)
2266 (push '(note .
"%t") org-log-note-headings
))
2268 (defcustom org-log-into-drawer nil
2269 "Non-nil means insert state change notes and time stamps into a drawer.
2270 When nil, state changes notes will be inserted after the headline and
2271 any scheduling and clock lines, but not inside a drawer.
2273 The value of this variable should be the name of the drawer to use.
2274 LOGBOOK is proposed at the default drawer for this purpose, you can
2275 also set this to a string to define the drawer of your choice.
2277 A value of t is also allowed, representing \"LOGBOOK\".
2279 If this variable is set, `org-log-state-notes-insert-after-drawers'
2282 You can set the property LOG_INTO_DRAWER to overrule this setting for
2285 :group
'org-progress
2287 (const :tag
"Not into a drawer" nil
)
2288 (const :tag
"LOGBOOK" t
)
2289 (string :tag
"Other")))
2291 (if (fboundp 'defvaralias
)
2292 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2294 (defun org-log-into-drawer ()
2295 "Return the value of `org-log-into-drawer', but let properties overrule.
2296 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2297 used instead of the default value."
2298 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2300 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2301 ((equal p
"t") "LOGBOOK")
2304 (defcustom org-log-state-notes-insert-after-drawers nil
2305 "Non-nil means insert state change notes after any drawers in entry.
2306 Only the drawers that *immediately* follow the headline and the
2307 deadline/scheduled line are skipped.
2308 When nil, insert notes right after the heading and perhaps the line
2309 with deadline/scheduling if present.
2311 This variable will have no effect if `org-log-into-drawer' is
2314 :group
'org-progress
2317 (defcustom org-log-states-order-reversed t
2318 "Non-nil means the latest state note will be directly after heading.
2319 When nil, the state change notes will be ordered according to time."
2321 :group
'org-progress
2324 (defcustom org-todo-repeat-to-state nil
2325 "The TODO state to which a repeater should return the repeating task.
2326 By default this is the first task in a TODO sequence, or the previous state
2327 in a TODO_TYP set. But you can specify another task here.
2328 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2330 :type
'(choice (const :tag
"Head of sequence" nil
)
2331 (string :tag
"Specific state")))
2333 (defcustom org-log-repeat
'time
2334 "Non-nil means record moving through the DONE state when triggering repeat.
2335 An auto-repeating task is immediately switched back to TODO when
2336 marked DONE. If you are not logging state changes (by adding \"@\"
2337 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2338 record a closing note, there will be no record of the task moving
2339 through DONE. This variable forces taking a note anyway.
2341 nil Don't force a record
2342 time Record a time stamp
2345 This option can also be set with on a per-file-basis with
2347 #+STARTUP: logrepeat
2348 #+STARTUP: lognoterepeat
2349 #+STARTUP: nologrepeat
2351 You can have local logging settings for a subtree by setting the LOGGING
2352 property to one or more of these keywords."
2354 :group
'org-progress
2356 (const :tag
"Don't force a record" nil
)
2357 (const :tag
"Force recording the DONE state" time
)
2358 (const :tag
"Force recording a note with the DONE state" note
)))
2361 (defgroup org-priorities nil
2362 "Priorities in Org-mode."
2363 :tag
"Org Priorities"
2366 (defcustom org-enable-priority-commands t
2367 "Non-nil means priority commands are active.
2368 When nil, these commands will be disabled, so that you never accidentally
2370 :group
'org-priorities
2373 (defcustom org-highest-priority ?A
2374 "The highest priority of TODO items. A character like ?A, ?B etc.
2375 Must have a smaller ASCII number than `org-lowest-priority'."
2376 :group
'org-priorities
2379 (defcustom org-lowest-priority ?C
2380 "The lowest priority of TODO items. A character like ?A, ?B etc.
2381 Must have a larger ASCII number than `org-highest-priority'."
2382 :group
'org-priorities
2385 (defcustom org-default-priority ?B
2386 "The default priority of TODO items.
2387 This is the priority an item get if no explicit priority is given."
2388 :group
'org-priorities
2391 (defcustom org-priority-start-cycle-with-default t
2392 "Non-nil means start with default priority when starting to cycle.
2393 When this is nil, the first step in the cycle will be (depending on the
2394 command used) one higher or lower that the default priority."
2395 :group
'org-priorities
2398 (defgroup org-time nil
2399 "Options concerning time stamps and deadlines in Org-mode."
2403 (defcustom org-insert-labeled-timestamps-at-point nil
2404 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2405 When nil, these labeled time stamps are forces into the second line of an
2406 entry, just after the headline. When scheduling from the global TODO list,
2407 the time stamp will always be forced into the second line."
2411 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2412 "Formats for `format-time-string' which are used for time stamps.
2413 It is not recommended to change this constant.")
2415 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2416 "Number of minutes to round time stamps to.
2417 These are two values, the first applies when first creating a time stamp.
2418 The second applies when changing it with the commands `S-up' and `S-down'.
2419 When changing the time stamp, this means that it will change in steps
2420 of N minutes, as given by the second value.
2422 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2423 numbers should be factors of 60, so for example 5, 10, 15.
2425 When this is larger than 1, you can still force an exact time-stamp by using
2426 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2427 and by using a prefix arg to `S-up/down' to specify the exact number
2428 of minutes to shift."
2430 :get
'(lambda (var) ; Make sure both elements are there
2431 (if (integerp (default-value var
))
2432 (list (default-value var
) 5)
2433 (default-value var
)))
2435 (integer :tag
"when inserting times")
2436 (integer :tag
"when modifying times")))
2438 ;; Normalize old customizations of this variable.
2439 (when (integerp org-time-stamp-rounding-minutes
)
2440 (setq org-time-stamp-rounding-minutes
2441 (list org-time-stamp-rounding-minutes
2442 org-time-stamp-rounding-minutes
)))
2444 (defcustom org-display-custom-times nil
2445 "Non-nil means overlay custom formats over all time stamps.
2446 The formats are defined through the variable `org-time-stamp-custom-formats'.
2447 To turn this on on a per-file basis, insert anywhere in the file:
2448 #+STARTUP: customtime"
2452 (make-variable-buffer-local 'org-display-custom-times
)
2454 (defcustom org-time-stamp-custom-formats
2455 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2456 "Custom formats for time stamps. See `format-time-string' for the syntax.
2457 These are overlayed over the default ISO format if the variable
2458 `org-display-custom-times' is set. Time like %H:%M should be at the
2459 end of the second format. The custom formats are also honored by export
2460 commands, if custom time display is turned on at the time of export."
2464 (defun org-time-stamp-format (&optional long inactive
)
2465 "Get the right format for a time string."
2466 (let ((f (if long
(cdr org-time-stamp-formats
)
2467 (car org-time-stamp-formats
))))
2469 (concat "[" (substring f
1 -
1) "]")
2472 (defcustom org-time-clocksum-format
"%d:%02d"
2473 "The format string used when creating CLOCKSUM lines, or when
2474 org-mode generates a time duration."
2478 (defcustom org-time-clocksum-use-fractional nil
2479 "If non-nil, \\[org-clock-display] uses fractional times.
2480 org-mode generates a time duration."
2484 (defcustom org-time-clocksum-fractional-format
"%.2f"
2485 "The format string used when creating CLOCKSUM lines, or when
2486 org-mode generates a time duration."
2490 (defcustom org-deadline-warning-days
14
2491 "No. of days before expiration during which a deadline becomes active.
2492 This variable governs the display in sparse trees and in the agenda.
2493 When 0 or negative, it means use this number (the absolute value of it)
2494 even if a deadline has a different individual lead time specified.
2496 Custom commands can set this variable in the options section."
2498 :group
'org-agenda-daily
/weekly
2501 (defcustom org-read-date-prefer-future t
2502 "Non-nil means assume future for incomplete date input from user.
2503 This affects the following situations:
2504 1. The user gives a month but not a year.
2505 For example, if it is april and you enter \"feb 2\", this will be read
2506 as feb 2, *next* year. \"May 5\", however, will be this year.
2507 2. The user gives a day, but no month.
2508 For example, if today is the 15th, and you enter \"3\", Org-mode will
2509 read this as the third of *next* month. However, if you enter \"17\",
2510 it will be considered as *this* month.
2512 If you set this variable to the symbol `time', then also the following
2515 3. If the user gives a time, but no day. If the time is before now,
2516 to will be interpreted as tomorrow.
2518 Currently none of this works for ISO week specifications.
2520 When this option is nil, the current day, month and year will always be
2524 (const :tag
"Never" nil
)
2525 (const :tag
"Check month and day" t
)
2526 (const :tag
"Check month, day, and time" time
)))
2528 (defcustom org-read-date-display-live t
2529 "Non-nil means display current interpretation of date prompt live.
2530 This display will be in an overlay, in the minibuffer."
2534 (defcustom org-read-date-popup-calendar t
2535 "Non-nil means pop up a calendar when prompting for a date.
2536 In the calendar, the date can be selected with mouse-1. However, the
2537 minibuffer will also be active, and you can simply enter the date as well.
2538 When nil, only the minibuffer will be available."
2541 (if (fboundp 'defvaralias
)
2542 (defvaralias 'org-popup-calendar-for-date-prompt
2543 'org-read-date-popup-calendar
))
2545 (defcustom org-read-date-minibuffer-setup-hook nil
2546 "Hook to be used to set up keys for the date/time interface.
2547 Add key definitions to `minibuffer-local-map', which will be a temporary
2552 (defcustom org-extend-today-until
0
2553 "The hour when your day really ends. Must be an integer.
2554 This has influence for the following applications:
2555 - When switching the agenda to \"today\". It it is still earlier than
2556 the time given here, the day recognized as TODAY is actually yesterday.
2557 - When a date is read from the user and it is still before the time given
2558 here, the current date and time will be assumed to be yesterday, 23:59.
2559 Also, timestamps inserted in remember templates follow this rule.
2561 IMPORTANT: This is a feature whose implementation is and likely will
2562 remain incomplete. Really, it is only here because past midnight seems to
2563 be the favorite working time of John Wiegley :-)"
2567 (defcustom org-edit-timestamp-down-means-later nil
2568 "Non-nil means S-down will increase the time in a time stamp.
2569 When nil, S-up will increase."
2573 (defcustom org-calendar-follow-timestamp-change t
2574 "Non-nil means make the calendar window follow timestamp changes.
2575 When a timestamp is modified and the calendar window is visible, it will be
2576 moved to the new date."
2580 (defgroup org-tags nil
2581 "Options concerning tags in Org-mode."
2585 (defcustom org-tag-alist nil
2586 "List of tags allowed in Org-mode files.
2587 When this list is nil, Org-mode will base TAG input on what is already in the
2589 The value of this variable is an alist, the car of each entry must be a
2590 keyword as a string, the cdr may be a character that is used to select
2591 that tag through the fast-tag-selection interface.
2592 See the manual for details."
2596 (cons (string :tag
"Tag name")
2597 (character :tag
"Access char"))
2598 (list :tag
"Start radio group"
2600 (option (string :tag
"Group description")))
2601 (list :tag
"End radio group"
2603 (option (string :tag
"Group description")))
2604 (const :tag
"New line" (:newline
)))))
2606 (defcustom org-tag-persistent-alist nil
2607 "List of tags that will always appear in all Org-mode files.
2608 This is in addition to any in buffer settings or customizations
2610 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2611 The value of this variable is an alist, the car of each entry must be a
2612 keyword as a string, the cdr may be a character that is used to select
2613 that tag through the fast-tag-selection interface.
2614 See the manual for details.
2615 To disable these tags on a per-file basis, insert anywhere in the file:
2620 (cons (string :tag
"Tag name")
2621 (character :tag
"Access char"))
2622 (const :tag
"Start radio group" (:startgroup
))
2623 (const :tag
"End radio group" (:endgroup
))
2624 (const :tag
"New line" (:newline
)))))
2626 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2627 "If non-nil, always offer completion for all tags of all agenda files.
2628 Instead of customizing this variable directly, you might want to
2629 set it locally for remember buffers, because there no list of
2630 tags in that file can be created dynamically (there are none).
2632 (add-hook 'org-remember-mode-hook
2634 (set (make-local-variable
2635 'org-complete-tags-always-offer-all-agenda-tags)
2640 (defvar org-file-tags nil
2641 "List of tags that can be inherited by all entries in the file.
2642 The tags will be inherited if the variable `org-use-tag-inheritance'
2643 says they should be.
2644 This variable is populated from #+FILETAGS lines.")
2646 (defcustom org-use-fast-tag-selection
'auto
2647 "Non-nil means use fast tag selection scheme.
2648 This is a special interface to select and deselect tags with single keys.
2649 When nil, fast selection is never used.
2650 When the symbol `auto', fast selection is used if and only if selection
2651 characters for tags have been configured, either through the variable
2652 `org-tag-alist' or through a #+TAGS line in the buffer.
2653 When t, fast selection is always used and selection keys are assigned
2654 automatically if necessary."
2657 (const :tag
"Always" t
)
2658 (const :tag
"Never" nil
)
2659 (const :tag
"When selection characters are configured" 'auto
)))
2661 (defcustom org-fast-tag-selection-single-key nil
2662 "Non-nil means fast tag selection exits after first change.
2663 When nil, you have to press RET to exit it.
2664 During fast tag selection, you can toggle this flag with `C-c'.
2665 This variable can also have the value `expert'. In this case, the window
2666 displaying the tags menu is not even shown, until you press C-c again."
2669 (const :tag
"No" nil
)
2670 (const :tag
"Yes" t
)
2671 (const :tag
"Expert" expert
)))
2673 (defvar org-fast-tag-selection-include-todo nil
2674 "Non-nil means fast tags selection interface will also offer TODO states.
2675 This is an undocumented feature, you should not rely on it.")
2677 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2678 "The column to which tags should be indented in a headline.
2679 If this number is positive, it specifies the column. If it is negative,
2680 it means that the tags should be flushright to that column. For example,
2681 -80 works well for a normal 80 character screen."
2685 (defcustom org-auto-align-tags t
2686 "Non-nil means realign tags after pro/demotion of TODO state change.
2687 These operations change the length of a headline and therefore shift
2688 the tags around. With this options turned on, after each such operation
2689 the tags are again aligned to `org-tags-column'."
2693 (defcustom org-use-tag-inheritance t
2694 "Non-nil means tags in levels apply also for sublevels.
2695 When nil, only the tags directly given in a specific line apply there.
2696 This may also be a list of tags that should be inherited, or a regexp that
2697 matches tags that should be inherited. Additional control is possible
2698 with the variable `org-tags-exclude-from-inheritance' which gives an
2699 explicit list of tags to be excluded from inheritance., even if the value of
2700 `org-use-tag-inheritance' would select it for inheritance.
2702 If this option is t, a match early-on in a tree can lead to a large
2703 number of matches in the subtree when constructing the agenda or creating
2704 a sparse tree. If you only want to see the first match in a tree during
2705 a search, check out the variable `org-tags-match-list-sublevels'."
2708 (const :tag
"Not" nil
)
2709 (const :tag
"Always" t
)
2710 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2711 (regexp :tag
"Tags matched by regexp")))
2713 (defcustom org-tags-exclude-from-inheritance nil
2714 "List of tags that should never be inherited.
2715 This is a way to exclude a few tags from inheritance. For way to do
2716 the opposite, to actively allow inheritance for selected tags,
2717 see the variable `org-use-tag-inheritance'."
2719 :type
'(repeat (string :tag
"Tag")))
2721 (defun org-tag-inherit-p (tag)
2722 "Check if TAG is one that should be inherited."
2724 ((member tag org-tags-exclude-from-inheritance
) nil
)
2725 ((eq org-use-tag-inheritance t
) t
)
2726 ((not org-use-tag-inheritance
) nil
)
2727 ((stringp org-use-tag-inheritance
)
2728 (string-match org-use-tag-inheritance tag
))
2729 ((listp org-use-tag-inheritance
)
2730 (member tag org-use-tag-inheritance
))
2731 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2733 (defcustom org-tags-match-list-sublevels t
2734 "Non-nil means list also sublevels of headlines matching a search.
2735 This variable applies to tags/property searches, and also to stuck
2736 projects because this search is based on a tags match as well.
2738 When set to the symbol `indented', sublevels are indented with
2741 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2742 the sublevels of a headline matching a tag search often also match
2743 the same search. Listing all of them can create very long lists.
2744 Setting this variable to nil causes subtrees of a match to be skipped.
2746 This variable is semi-obsolete and probably should always be true. It
2747 is better to limit inheritance to certain tags using the variables
2748 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2751 (const :tag
"No, don't list them" nil
)
2752 (const :tag
"Yes, do list them" t
)
2753 (const :tag
"List them, indented with leading dots" indented
)))
2755 (defcustom org-tags-sort-function nil
2756 "When set, tags are sorted using this function as a comparator"
2759 (const :tag
"No sorting" nil
)
2760 (const :tag
"Alphabetical" string
<)
2761 (const :tag
"Reverse alphabetical" string
>)
2762 (function :tag
"Custom function" nil
)))
2764 (defvar org-tags-history nil
2765 "History of minibuffer reads for tags.")
2766 (defvar org-last-tags-completion-table nil
2767 "The last used completion table for tags.")
2768 (defvar org-after-tags-change-hook nil
2769 "Hook that is run after the tags in a line have changed.")
2771 (defgroup org-properties nil
2772 "Options concerning properties in Org-mode."
2773 :tag
"Org Properties"
2776 (defcustom org-property-format
"%-10s %s"
2777 "How property key/value pairs should be formatted by `indent-line'.
2778 When `indent-line' hits a property definition, it will format the line
2779 according to this format, mainly to make sure that the values are
2780 lined-up with respect to each other."
2781 :group
'org-properties
2784 (defcustom org-use-property-inheritance nil
2785 "Non-nil means properties apply also for sublevels.
2787 This setting is chiefly used during property searches. Turning it on can
2788 cause significant overhead when doing a search, which is why it is not
2791 When nil, only the properties directly given in the current entry count.
2792 When t, every property is inherited. The value may also be a list of
2793 properties that should have inheritance, or a regular expression matching
2794 properties that should be inherited.
2796 However, note that some special properties use inheritance under special
2797 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2798 and the properties ending in \"_ALL\" when they are used as descriptor
2799 for valid values of a property.
2801 Note for programmers:
2802 When querying an entry with `org-entry-get', you can control if inheritance
2803 should be used. By default, `org-entry-get' looks only at the local
2804 properties. You can request inheritance by setting the inherit argument
2805 to t (to force inheritance) or to `selective' (to respect the setting
2807 :group
'org-properties
2809 (const :tag
"Not" nil
)
2810 (const :tag
"Always" t
)
2811 (repeat :tag
"Specific properties" (string :tag
"Property"))
2812 (regexp :tag
"Properties matched by regexp")))
2814 (defun org-property-inherit-p (property)
2815 "Check if PROPERTY is one that should be inherited."
2817 ((eq org-use-property-inheritance t
) t
)
2818 ((not org-use-property-inheritance
) nil
)
2819 ((stringp org-use-property-inheritance
)
2820 (string-match org-use-property-inheritance property
))
2821 ((listp org-use-property-inheritance
)
2822 (member property org-use-property-inheritance
))
2823 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2825 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2826 "The default column format, if no other format has been defined.
2827 This variable can be set on the per-file basis by inserting a line
2829 #+COLUMNS: %25ITEM ....."
2830 :group
'org-properties
2833 (defcustom org-columns-ellipses
".."
2834 "The ellipses to be used when a field in column view is truncated.
2835 When this is the empty string, as many characters as possible are shown,
2836 but then there will be no visual indication that the field has been truncated.
2837 When this is a string of length N, the last N characters of a truncated
2838 field are replaced by this string. If the column is narrower than the
2839 ellipses string, only part of the ellipses string will be shown."
2840 :group
'org-properties
2843 (defcustom org-columns-modify-value-for-display-function nil
2844 "Function that modifies values for display in column view.
2845 For example, it can be used to cut out a certain part from a time stamp.
2846 The function must take 2 arguments:
2848 column-title The title of the column (*not* the property name)
2849 value The value that should be modified.
2851 The function should return the value that should be displayed,
2852 or nil if the normal value should be used."
2853 :group
'org-properties
2856 (defcustom org-effort-property
"Effort"
2857 "The property that is being used to keep track of effort estimates.
2858 Effort estimates given in this property need to have the format H:MM."
2859 :group
'org-properties
2860 :group
'org-progress
2861 :type
'(string :tag
"Property"))
2863 (defconst org-global-properties-fixed
2864 '(("VISIBILITY_ALL" .
"folded children content all")
2865 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2866 "List of property/value pairs that can be inherited by any entry.
2868 These are fixed values, for the preset properties. The user variable
2869 that can be used to add to this list is `org-global-properties'.
2871 The entries in this list are cons cells where the car is a property
2872 name and cdr is a string with the value. If the value represents
2873 multiple items like an \"_ALL\" property, separate the items by
2876 (defcustom org-global-properties nil
2877 "List of property/value pairs that can be inherited by any entry.
2879 This list will be combined with the constant `org-global-properties-fixed'.
2881 The entries in this list are cons cells where the car is a property
2882 name and cdr is a string with the value.
2884 You can set buffer-local values for the same purpose in the variable
2885 `org-file-properties' this by adding lines like
2887 #+PROPERTY: NAME VALUE"
2888 :group
'org-properties
2890 (cons (string :tag
"Property")
2891 (string :tag
"Value"))))
2893 (defvar org-file-properties nil
2894 "List of property/value pairs that can be inherited by any entry.
2895 Valid for the current buffer.
2896 This variable is populated from #+PROPERTY lines.")
2897 (make-variable-buffer-local 'org-file-properties
)
2899 (defgroup org-agenda nil
2900 "Options concerning agenda views in Org-mode."
2904 (defvar org-category nil
2905 "Variable used by org files to set a category for agenda display.
2906 Such files should use a file variable to set it, for example
2908 # -*- mode: org; org-category: \"ELisp\"
2910 or contain a special line
2914 If the file does not specify a category, then file's base name
2916 (make-variable-buffer-local 'org-category
)
2917 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2919 (defcustom org-agenda-files nil
2920 "The files to be used for agenda display.
2921 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2922 \\[org-remove-file]. You can also use customize to edit the list.
2924 If an entry is a directory, all files in that directory that are matched by
2925 `org-agenda-file-regexp' will be part of the file list.
2927 If the value of the variable is not a list but a single file name, then
2928 the list of agenda files is actually stored and maintained in that file, one
2929 agenda file per line. In this file paths can be given relative to
2930 `org-directory'. Tilde expansion and environment variable substitution
2934 (repeat :tag
"List of files and directories" file
)
2935 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2937 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2938 "Regular expression to match files for `org-agenda-files'.
2939 If any element in the list in that variable contains a directory instead
2940 of a normal file, all files in that directory that are matched by this
2941 regular expression will be included."
2945 (defcustom org-agenda-text-search-extra-files nil
2946 "List of extra files to be searched by text search commands.
2947 These files will be search in addition to the agenda files by the
2948 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2949 Note that these files will only be searched for text search commands,
2950 not for the other agenda views like todo lists, tag searches or the weekly
2951 agenda. This variable is intended to list notes and possibly archive files
2952 that should also be searched by these two commands.
2953 In fact, if the first element in the list is the symbol `agenda-archives',
2954 than all archive files of all agenda files will be added to the search
2957 :type
'(set :greedy t
2958 (const :tag
"Agenda Archives" agenda-archives
)
2959 (repeat :inline t
(file))))
2961 (if (fboundp 'defvaralias
)
2962 (defvaralias 'org-agenda-multi-occur-extra-files
2963 'org-agenda-text-search-extra-files
))
2965 (defcustom org-agenda-skip-unavailable-files nil
2966 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2967 A nil value means to remove them, after a query, from the list."
2971 (defcustom org-calendar-to-agenda-key
[?c
]
2972 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2973 The command `org-calendar-goto-agenda' will be bound to this key. The
2974 default is the character `c' because then `c' can be used to switch back and
2975 forth between agenda and calendar."
2979 (defcustom org-calendar-agenda-action-key
[?k
]
2980 "The key to be installed in `calendar-mode-map' for agenda-action.
2981 The command `org-agenda-action' will be bound to this key. The
2982 default is the character `k' because we use the same key in the agenda."
2986 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2987 "The key to be installed in `calendar-mode-map' for adding diary entries.
2988 This option is irrelevant until `org-agenda-diary-file' has been configured
2989 to point to an Org-mode file. When that is the case, the command
2990 `org-agenda-diary-entry' will be bound to the key given here, by default
2991 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2992 if you want to continue doing this, you need to change this to a different
2997 (defcustom org-agenda-diary-file
'diary-file
2998 "File to which to add new entries with the `i' key in agenda and calendar.
2999 When this is the symbol `diary-file', the functionality in the Emacs
3000 calendar will be used to add entries to the `diary-file'. But when this
3001 points to a file, `org-agenda-diary-entry' will be used instead."
3004 (const :tag
"The standard Emacs diary file" diary-file
)
3005 (file :tag
"Special Org file diary entries")))
3007 (eval-after-load "calendar"
3009 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3010 'org-calendar-goto-agenda
)
3011 (org-defkey calendar-mode-map org-calendar-agenda-action-key
3013 (add-hook 'calendar-mode-hook
3015 (unless (eq org-agenda-diary-file
'diary-file
)
3016 (define-key calendar-mode-map
3017 org-calendar-insert-diary-entry-key
3018 'org-agenda-diary-entry
))))))
3020 (defgroup org-latex nil
3021 "Options for embedding LaTeX code into Org-mode."
3025 (defcustom org-format-latex-options
3026 '(:foreground default
:background default
:scale
1.0
3027 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
3028 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3029 "Options for creating images from LaTeX fragments.
3030 This is a property list with the following properties:
3031 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3032 `default' means use the foreground of the default face.
3033 :background the background color, or \"Transparent\".
3034 `default' means use the background of the default face.
3035 :scale a scaling factor for the size of the images.
3036 :html-foreground, :html-background, :html-scale
3037 the same numbers for HTML export.
3038 :matchers a list indicating which matchers should be used to
3039 find LaTeX fragments. Valid members of this list are:
3040 \"begin\" find environments
3041 \"$1\" find single characters surrounded by $.$
3042 \"$\" find math expressions surrounded by $...$
3043 \"$$\" find math expressions surrounded by $$....$$
3044 \"\\(\" find math expressions surrounded by \\(...\\)
3045 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3049 (defcustom org-format-latex-signal-error t
3050 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3051 When nil, just push out a message."
3055 (defcustom org-format-latex-header
"\\documentclass{article}
3056 \\usepackage[usenames]{color}
3057 \\usepackage{amsmath}
3058 \\usepackage[mathscr]{eucal}
3059 \\pagestyle{empty} % do not remove
3062 % The settings below are copied from fullpage.sty
3063 \\setlength{\\textwidth}{\\paperwidth}
3064 \\addtolength{\\textwidth}{-3cm}
3065 \\setlength{\\oddsidemargin}{1.5cm}
3066 \\addtolength{\\oddsidemargin}{-2.54cm}
3067 \\setlength{\\evensidemargin}{\\oddsidemargin}
3068 \\setlength{\\textheight}{\\paperheight}
3069 \\addtolength{\\textheight}{-\\headheight}
3070 \\addtolength{\\textheight}{-\\headsep}
3071 \\addtolength{\\textheight}{-\\footskip}
3072 \\addtolength{\\textheight}{-3cm}
3073 \\setlength{\\topmargin}{1.5cm}
3074 \\addtolength{\\topmargin}{-2.54cm}"
3075 "The document header used for processing LaTeX fragments.
3076 It is imperative that this header make sure that no page number
3077 appears on the page. The package defined in the variables
3078 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
3079 will either replace the placeholder \"[PACKAGES]\" in this header, or they
3084 (defvar org-format-latex-header-extra nil
)
3086 (defun org-set-packages-alist (var val
)
3087 "Set the packages alist and make sure it has 3 elements per entry."
3088 (set var
(mapcar (lambda (x)
3089 (if (and (consp x
) (= (length x
) 2))
3090 (list (car x
) (nth 1 x
) t
)
3094 (defun org-get-packages-alist (var)
3096 "Get the packages alist and make sure it has 3 elements per entry."
3098 (if (and (consp x
) (= (length x
) 2))
3099 (list (car x
) (nth 1 x
) t
)
3101 (default-value var
)))
3103 ;; The following variables are defined here because is it also used
3104 ;; when formatting latex fragments. Originally it was part of the
3105 ;; LaTeX exporter, which is why the name includes "export".
3106 (defcustom org-export-latex-default-packages-alist
3107 '(("AUTO" "inputenc" t
)
3111 ("" "longtable" nil
)
3124 "Alist of default packages to be inserted in the header.
3125 Change this only if one of the packages here causes an incompatibility
3126 with another package you are using.
3127 The packages in this list are needed by one part or another of Org-mode
3128 to function properly.
3130 - inputenc, fontenc, t1enc: for basic font and character selection
3131 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3132 for interpreting the entities in `org-entities'. You can skip some of these
3133 packages if you don't use any of the symbols in it.
3134 - graphicx: for including images
3135 - float, wrapfig: for figure placement
3136 - longtable: for long tables
3137 - hyperref: for cross references
3139 Therefore you should not modify this variable unless you know what you
3140 are doing. The one reason to change it anyway is that you might be loading
3141 some other package that conflicts with one of the default packages.
3142 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3143 If SNIPPET-FLAG is t, the package also needs to be included when
3144 compiling LaTeX snippets into images for inclusion into HTML."
3145 :group
'org-export-latex
3146 :set
'org-set-packages-alist
3147 :get
'org-get-packages-alist
3150 (list :tag
"options/package pair"
3151 (string :tag
"options")
3152 (string :tag
"package")
3153 (boolean :tag
"Snippet"))
3154 (string :tag
"A line of LaTeX"))))
3156 (defcustom org-export-latex-packages-alist nil
3157 "Alist of packages to be inserted in every LaTeX header.
3158 These will be inserted after `org-export-latex-default-packages-alist'.
3159 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3160 SNIPPET-FLAG, when t, indicates that this package is also needed when
3161 turning LaTeX snippets into images for inclusion into HTML.
3162 Make sure that you only list packages here which:
3163 - you want in every file
3164 - do not conflict with the default packages in
3165 `org-export-latex-default-packages-alist'
3166 - do not conflict with the setup in `org-format-latex-header'."
3167 :group
'org-export-latex
3168 :set
'org-set-packages-alist
3169 :get
'org-get-packages-alist
3172 (list :tag
"options/package pair"
3173 (string :tag
"options")
3174 (string :tag
"package")
3175 (boolean :tag
"Snippet"))
3176 (string :tag
"A line of LaTeX"))))
3179 (defgroup org-appearance nil
3180 "Settings for Org-mode appearance."
3181 :tag
"Org Appearance"
3184 (defcustom org-level-color-stars-only nil
3185 "Non-nil means fontify only the stars in each headline.
3186 When nil, the entire headline is fontified.
3187 Changing it requires restart of `font-lock-mode' to become effective
3188 also in regions already fontified."
3189 :group
'org-appearance
3192 (defcustom org-hide-leading-stars nil
3193 "Non-nil means hide the first N-1 stars in a headline.
3194 This works by using the face `org-hide' for these stars. This
3195 face is white for a light background, and black for a dark
3196 background. You may have to customize the face `org-hide' to
3198 Changing it requires restart of `font-lock-mode' to become effective
3199 also in regions already fontified.
3200 You may also set this on a per-file basis by adding one of the following
3201 lines to the buffer:
3203 #+STARTUP: hidestars
3204 #+STARTUP: showstars"
3205 :group
'org-appearance
3208 (defcustom org-hidden-keywords nil
3209 "List of keywords that should be hidden when typed in the org buffer.
3210 For example, add #+TITLE to this list in order to make the
3211 document title appear in the buffer without the initial #+TITLE:
3213 :group
'org-appearance
3214 :type
'(set (const :tag
"#+AUTHOR" author
)
3215 (const :tag
"#+DATE" date
)
3216 (const :tag
"#+EMAIL" email
)
3217 (const :tag
"#+TITLE" title
)))
3219 (defcustom org-fontify-done-headline nil
3220 "Non-nil means change the face of a headline if it is marked DONE.
3221 Normally, only the TODO/DONE keyword indicates the state of a headline.
3222 When this is non-nil, the headline after the keyword is set to the
3223 `org-headline-done' as an additional indication."
3224 :group
'org-appearance
3227 (defcustom org-fontify-emphasized-text t
3228 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3229 Changing this variable requires a restart of Emacs to take effect."
3230 :group
'org-appearance
3233 (defcustom org-fontify-whole-heading-line nil
3234 "Non-nil means fontify the whole line for headings.
3235 This is useful when setting a background color for the
3237 :group
'org-appearance
3240 (defcustom org-highlight-latex-fragments-and-specials nil
3241 "Non-nil means fontify what is treated specially by the exporters."
3242 :group
'org-appearance
3245 (defcustom org-hide-emphasis-markers nil
3246 "Non-nil mean font-lock should hide the emphasis marker characters."
3247 :group
'org-appearance
3250 (defcustom org-pretty-entities nil
3251 "Non-nil means show entities as UTF8 characters.
3252 When nil, the \\name form remains in the buffer."
3253 :group
'org-appearance
3256 (defcustom org-pretty-entities-include-sub-superscripts t
3257 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3258 :group
'org-appearance
3261 (defvar org-emph-re nil
3262 "Regular expression for matching emphasis.
3263 After a match, the match groups contain these elements:
3264 1 The character before the proper match, or empty at beginning of line
3265 2 The proper match, including the leading and trailing markers
3266 3 The leading marker like * or /, indicating the type of highlighting
3267 4 The text between the emphasis markers, not including the markers
3268 5 The character after the match, empty at the end of a line")
3269 (defvar org-verbatim-re nil
3270 "Regular expression for matching verbatim text.")
3271 (defvar org-emphasis-regexp-components
) ; defined just below
3272 (defvar org-emphasis-alist
) ; defined just below
3273 (defun org-set-emph-re (var val
)
3274 "Set variable and compute the emphasis regular expression."
3276 (when (and (boundp 'org-emphasis-alist
)
3277 (boundp 'org-emphasis-regexp-components
)
3278 org-emphasis-alist org-emphasis-regexp-components
)
3279 (let* ((e org-emphasis-regexp-components
)
3285 (body1 (concat body
"*?"))
3286 (markers (mapconcat 'car org-emphasis-alist
""))
3287 (vmarkers (mapconcat
3288 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3289 org-emphasis-alist
"")))
3290 ;; make sure special characters appear at the right position in the class
3291 (if (string-match "\\^" markers
)
3292 (setq markers
(concat (replace-match "" t t markers
) "^")))
3293 (if (string-match "-" markers
)
3294 (setq markers
(concat (replace-match "" t t markers
) "-")))
3295 (if (string-match "\\^" vmarkers
)
3296 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3297 (if (string-match "-" vmarkers
)
3298 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3300 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3301 (int-to-string nl
) "\\}")))
3304 (concat "\\([" pre
"]\\|^\\)"
3306 "\\([" markers
"]\\)"
3314 "\\([" post
"]\\|$\\)"))
3315 (setq org-verbatim-re
3316 (concat "\\([" pre
"]\\|^\\)"
3318 "\\([" vmarkers
"]\\)"
3326 "\\([" post
"]\\|$\\)")))))
3328 (defcustom org-emphasis-regexp-components
3329 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3330 "Components used to build the regular expression for emphasis.
3331 This is a list with 6 entries. Terminology: In an emphasis string
3332 like \" *strong word* \", we call the initial space PREMATCH, the final
3333 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3334 and \"trong wor\" is the body. The different components in this variable
3335 specify what is allowed/forbidden in each part:
3337 pre Chars allowed as prematch. Beginning of line will be allowed too.
3338 post Chars allowed as postmatch. End of line will be allowed too.
3339 border The chars *forbidden* as border characters.
3340 body-regexp A regexp like \".\" to match a body character. Don't use
3341 non-shy groups here, and don't allow newline here.
3342 newline The maximum number of newlines allowed in an emphasis exp.
3344 Use customize to modify this, or restart Emacs after changing it."
3345 :group
'org-appearance
3346 :set
'org-set-emph-re
3348 (sexp :tag
"Allowed chars in pre ")
3349 (sexp :tag
"Allowed chars in post ")
3350 (sexp :tag
"Forbidden chars in border ")
3351 (sexp :tag
"Regexp for body ")
3352 (integer :tag
"number of newlines allowed")
3353 (option (boolean :tag
"Please ignore this button"))))
3355 (defcustom org-emphasis-alist
3356 `(("*" bold
"<b>" "</b>")
3357 ("/" italic
"<i>" "</i>")
3358 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3359 ("=" org-code
"<code>" "</code>" verbatim
)
3360 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3361 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3364 "Special syntax for emphasized text.
3365 Text starting and ending with a special character will be emphasized, for
3366 example *bold*, _underlined_ and /italic/. This variable sets the marker
3367 characters, the face to be used by font-lock for highlighting in Org-mode
3368 Emacs buffers, and the HTML tags to be used for this.
3369 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3370 For DocBook export, see the variable `org-export-docbook-emphasis-alist'.
3371 Use customize to modify this, or restart Emacs after changing it."
3372 :group
'org-appearance
3373 :set
'org-set-emph-re
3376 (string :tag
"Marker character")
3378 (face :tag
"Font-lock-face")
3379 (plist :tag
"Face property list"))
3380 (string :tag
"HTML start tag")
3381 (string :tag
"HTML end tag")
3382 (option (const verbatim
)))))
3384 (defvar org-protecting-blocks
3385 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3386 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3387 This is needed for font-lock setup.")
3389 ;;; Miscellaneous options
3391 (defgroup org-completion nil
3392 "Completion in Org-mode."
3393 :tag
"Org Completion"
3396 (defcustom org-completion-use-ido nil
3397 "Non-nil means use ido completion wherever possible.
3398 Note that `ido-mode' must be active for this variable to be relevant.
3399 If you decide to turn this variable on, you might well want to turn off
3400 `org-outline-path-complete-in-steps'.
3401 See also `org-completion-use-iswitchb'."
3402 :group
'org-completion
3405 (defcustom org-completion-use-iswitchb nil
3406 "Non-nil means use iswitchb completion wherever possible.
3407 Note that `iswitchb-mode' must be active for this variable to be relevant.
3408 If you decide to turn this variable on, you might well want to turn off
3409 `org-outline-path-complete-in-steps'.
3410 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3411 :group
'org-completion
3414 (defcustom org-completion-fallback-command
'hippie-expand
3415 "The expansion command called by \\[org-complete] in normal context.
3416 Normal means no org-mode-specific context."
3417 :group
'org-completion
3420 ;;; Functions and variables from their packages
3421 ;; Declared here to avoid compiler warnings
3424 (defvar outline-mode-menu-heading
)
3425 (defvar outline-mode-menu-show
)
3426 (defvar outline-mode-menu-hide
)
3427 (defvar zmacs-regions
) ; XEmacs regions
3430 (defvar mark-active
)
3433 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3434 (declare-function calendar-forward-day
"cal-move" (arg))
3435 (declare-function calendar-goto-date
"cal-move" (date))
3436 (declare-function calendar-goto-today
"cal-move" ())
3437 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3438 (defvar calc-embedded-close-formula
)
3439 (defvar calc-embedded-open-formula
)
3440 (declare-function cdlatex-tab
"ext:cdlatex" ())
3441 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3442 (defvar font-lock-unfontify-region-function
)
3443 (declare-function iswitchb-read-buffer
"iswitchb"
3444 (prompt &optional default require-match start matches-set
))
3445 (defvar iswitchb-temp-buflist
)
3446 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3447 (defvar org-agenda-tags-todo-honor-ignore-options
)
3448 (declare-function org-agenda-skip
"org-agenda" ())
3450 org-format-agenda-item
"org-agenda"
3451 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3452 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3453 (declare-function org-agenda-change-all-lines
"org-agenda"
3454 (newhead hdmarker
&optional fixface just-this
))
3455 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3456 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3457 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3459 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3460 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3461 "org-agenda" (&optional end
))
3462 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3463 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3464 (declare-function parse-time-string
"parse-time" (string))
3465 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3466 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3467 (defvar remember-data-file
)
3468 (defvar texmathp-why
)
3469 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3470 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3472 (defvar w3m-current-url
)
3473 (defvar w3m-current-title
)
3475 (defvar org-latex-regexps
)
3477 ;;; Autoload and prepare some org modules
3479 ;; Some table stuff that needs to be defined here, because it is used
3480 ;; by the functions setting up org-mode or checking for table context.
3482 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3483 "Detects an org-type or table-type table.")
3484 (defconst org-table-line-regexp
"^[ \t]*|"
3485 "Detects an org-type table line.")
3486 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3487 "Detects an org-type table line.")
3488 (defconst org-table-hline-regexp
"^[ \t]*|-"
3489 "Detects an org-type table hline.")
3490 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3491 "Detects a table-type table hline.")
3492 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3493 "Searching from within a table (any type) this finds the first line
3494 outside the table.")
3496 ;; Autoload the functions in org-table.el that are needed by functions here.
3499 (org-autoload "org-table"
3500 '(org-table-align org-table-begin org-table-blank-field
3501 org-table-convert org-table-convert-region org-table-copy-down
3502 org-table-copy-region org-table-create
3503 org-table-create-or-convert-from-region
3504 org-table-create-with-table.el org-table-current-dline
3505 org-table-cut-region org-table-delete-column org-table-edit-field
3506 org-table-edit-formulas org-table-end org-table-eval-formula
3507 org-table-export org-table-field-info
3508 org-table-get-stored-formulas org-table-goto-column
3509 org-table-hline-and-move org-table-import org-table-insert-column
3510 org-table-insert-hline org-table-insert-row org-table-iterate
3511 org-table-justify-field-maybe org-table-kill-row
3512 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3513 org-table-move-column org-table-move-column-left
3514 org-table-move-column-right org-table-move-row
3515 org-table-move-row-down org-table-move-row-up
3516 org-table-next-field org-table-next-row org-table-paste-rectangle
3517 org-table-previous-field org-table-recalculate
3518 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3519 org-table-toggle-coordinate-overlays
3520 org-table-toggle-formula-debugger org-table-wrap-region
3521 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3523 (defun org-at-table-p (&optional table-type
)
3524 "Return t if the cursor is inside an org-type table.
3525 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3526 (if org-enable-table-editor
3528 (beginning-of-line 1)
3529 (looking-at (if table-type org-table-any-line-regexp
3530 org-table-line-regexp
)))
3532 (defsubst org-table-p
() (org-at-table-p))
3534 (defun org-at-table.el-p
()
3535 "Return t if and only if we are at a table.el table."
3536 (and (org-at-table-p 'any
)
3538 (goto-char (org-table-begin 'any
))
3539 (looking-at org-table1-hline-regexp
))))
3540 (defun org-table-recognize-table.el
()
3541 "If there is a table.el table nearby, recognize it and move into it."
3542 (if org-table-tab-recognizes-table.el
3543 (if (org-at-table.el-p
)
3545 (beginning-of-line 1)
3546 (if (looking-at org-table-dataline-regexp
)
3548 (if (looking-at org-table1-hline-regexp
)
3550 (beginning-of-line 2)
3551 (if (looking-at org-table-any-border-regexp
)
3552 (beginning-of-line -
1)))))
3553 (if (re-search-forward "|" (org-table-end t
) t
)
3556 (if (table--at-cell-p (point))
3558 (message "recognizing table.el table...")
3559 (table-recognize-table)
3560 (message "recognizing table.el table...done")))
3561 (error "This should not happen..."))
3566 (defun org-at-table-hline-p ()
3567 "Return t if the cursor is inside a hline in a table."
3568 (if org-enable-table-editor
3570 (beginning-of-line 1)
3571 (looking-at org-table-hline-regexp
))
3574 (defvar org-table-clean-did-remove-column nil
)
3576 (defun org-table-map-tables (function &optional quietly
)
3577 "Apply FUNCTION to the start of all tables in the buffer."
3581 (goto-char (point-min))
3582 (while (re-search-forward org-table-any-line-regexp nil t
)
3584 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3585 (beginning-of-line 1)
3586 (when (looking-at org-table-line-regexp
)
3587 (save-excursion (funcall function
))
3588 (or (looking-at org-table-line-regexp
)
3590 (re-search-forward org-table-any-border-regexp nil
1))))
3591 (unless quietly
(message "Mapping tables: done")))
3593 ;; Declare and autoload functions from org-exp.el & Co
3595 (declare-function org-default-export-plist
"org-exp")
3596 (declare-function org-infile-export-plist
"org-exp")
3597 (declare-function org-get-current-options
"org-exp")
3599 (org-autoload "org-exp"
3600 '(org-export org-export-visible
3601 org-insert-export-options-template
3602 org-table-clean-before-export
))
3603 (org-autoload "org-ascii"
3604 '(org-export-as-ascii org-export-ascii-preprocess
3605 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3606 org-export-region-as-ascii
))
3607 (org-autoload "org-latex"
3608 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3609 org-replace-region-by-latex org-export-region-as-latex
3610 org-export-as-latex org-export-as-pdf
3611 org-export-as-pdf-and-open
))
3612 (org-autoload "org-html"
3613 '(org-export-as-html-and-open
3614 org-export-as-html-batch org-export-as-html-to-buffer
3615 org-replace-region-by-html org-export-region-as-html
3616 org-export-as-html
))
3617 (org-autoload "org-docbook"
3618 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3619 org-replace-region-by-docbook org-export-region-as-docbook
3620 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3621 org-export-as-docbook
))
3622 (org-autoload "org-icalendar"
3623 '(org-export-icalendar-this-file
3624 org-export-icalendar-all-agenda-files
3625 org-export-icalendar-combine-agenda-files
))
3626 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3627 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3629 ;; Declare and autoload functions from org-agenda.el
3632 (org-autoload "org-agenda"
3633 '(org-agenda org-agenda-list org-search-view
3634 org-todo-list org-tags-view org-agenda-list-stuck-projects
3635 org-diary org-agenda-to-appt
3636 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3638 ;; Autoload org-remember
3641 (org-autoload "org-remember"
3642 '(org-remember-insinuate org-remember-annotation
3643 org-remember-apply-template org-remember org-remember-handler
)))
3646 (org-autoload "org-capture"
3647 '(org-capture org-capture-insert-template-here
3648 org-capture-import-remember-templates
)))
3650 ;; Autoload org-clock.el
3653 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3655 (declare-function org-clock-update-mode-line
"org-clock" ())
3656 (declare-function org-resolve-clocks
"org-clock"
3657 (&optional also-non-dangling-p prompt last-valid
))
3658 (defvar org-clock-start-time
)
3659 (defvar org-clock-marker
(make-marker)
3660 "Marker recording the last clock-in.")
3661 (defvar org-clock-hd-marker
(make-marker)
3662 "Marker recording the last clock-in, but the headline position.")
3663 (defvar org-clock-heading
""
3664 "The heading of the current clock entry.")
3665 (defun org-clock-is-active ()
3666 "Return non-nil if clock is currently running.
3667 The return value is actually the clock marker."
3668 (marker-buffer org-clock-marker
))
3673 '(org-clock-in org-clock-out org-clock-cancel
3674 org-clock-goto org-clock-sum org-clock-display
3675 org-clock-remove-overlays org-clock-report
3676 org-clocktable-shift org-dblock-write
:clocktable
3677 org-get-clocktable org-resolve-clocks
)))
3679 (defun org-clock-update-time-maybe ()
3680 "If this is a CLOCK line, update it and return t.
3681 Otherwise, return nil."
3684 (beginning-of-line 1)
3685 (skip-chars-forward " \t")
3686 (when (looking-at org-clock-string
)
3687 (let ((re (concat "[ \t]*" org-clock-string
3688 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3689 "\\([ \t]*=>.*\\)?\\)?"))
3692 ((not (looking-at re
))
3694 ((not (match-end 2))
3695 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3696 (> org-clock-marker
(point))
3697 (<= org-clock-marker
(point-at-eol)))
3698 ;; The clock is running here
3699 (setq org-clock-start-time
3701 (org-parse-time-string (match-string 1))))
3702 (org-clock-update-mode-line)))
3704 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3706 (setq ts
(match-string 1)
3707 te
(match-string 3))
3708 (setq s
(- (org-float-time
3709 (apply 'encode-time
(org-parse-time-string te
)))
3711 (apply 'encode-time
(org-parse-time-string ts
))))
3714 h
(floor (/ s
3600))
3718 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3721 (defun org-check-running-clock ()
3722 "Check if the current buffer contains the running clock.
3723 If yes, offer to stop it and to save the buffer with the changes."
3724 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3725 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3728 (when (y-or-n-p "Save changed buffer?")
3731 (defun org-clocktable-try-shift (dir n
)
3732 "Check if this line starts a clock table, if yes, shift the time block."
3733 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3734 (org-clocktable-shift dir n
)))
3736 ;; Autoload org-timer.el
3741 '(org-timer-start org-timer org-timer-item
3742 org-timer-change-times-in-region
3744 org-timer-reset-timers
3745 org-timer-show-remaining-time
)))
3747 ;; Autoload org-feed.el
3752 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3755 ;; Autoload org-indent.el
3757 ;; Define the variable already here, to make sure we have it.
3758 (defvar org-indent-mode nil
3759 "Non-nil if Org-Indent mode is enabled.
3760 Use the command `org-indent-mode' to change this variable.")
3765 '(org-indent-mode)))
3767 ;; Autoload org-mobile.el
3772 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3774 ;; Autoload archiving code
3775 ;; The stuff that is needed for cycling and tags has to be defined here.
3777 (defgroup org-archive nil
3778 "Options concerning archiving in Org-mode."
3780 :group
'org-structure
)
3782 (defcustom org-archive-location
"%s_archive::"
3783 "The location where subtrees should be archived.
3785 The value of this variable is a string, consisting of two parts,
3786 separated by a double-colon. The first part is a filename and
3787 the second part is a headline.
3789 When the filename is omitted, archiving happens in the same file.
3790 %s in the filename will be replaced by the current file
3791 name (without the directory part). Archiving to a different file
3792 is useful to keep archived entries from contributing to the
3795 The archived entries will be filed as subtrees of the specified
3796 headline. When the headline is omitted, the subtrees are simply
3797 filed away at the end of the file, as top-level entries. Also in
3798 the heading you can use %s to represent the file name, this can be
3799 useful when using the same archive for a number of different files.
3801 Here are a few examples:
3803 If the current file is Projects.org, archive in file
3804 Projects.org_archive, as top-level trees. This is the default.
3806 \"::* Archived Tasks\"
3807 Archive in the current file, under the top-level headline
3808 \"* Archived Tasks\".
3810 \"~/org/archive.org::\"
3811 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3813 \"~/org/archive.org::From %s\"
3814 Archive in file ~/org/archive.org (absolute path), under headlines
3815 \"From FILENAME\" where file name is the current file name.
3817 \"basement::** Finished Tasks\"
3818 Archive in file ./basement (relative path), as level 3 trees
3819 below the level 2 heading \"** Finished Tasks\".
3821 You may set this option on a per-file basis by adding to the buffer a
3824 #+ARCHIVE: basement::** Finished Tasks
3826 You may also define it locally for a subtree by setting an ARCHIVE property
3827 in the entry. If such a property is found in an entry, or anywhere up
3828 the hierarchy, it will be used."
3832 (defcustom org-archive-tag
"ARCHIVE"
3833 "The tag that marks a subtree as archived.
3834 An archived subtree does not open during visibility cycling, and does
3835 not contribute to the agenda listings.
3836 After changing this, font-lock must be restarted in the relevant buffers to
3837 get the proper fontification."
3839 :group
'org-keywords
3842 (defcustom org-agenda-skip-archived-trees t
3843 "Non-nil means the agenda will skip any items located in archived trees.
3844 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3845 variable is no longer recommended, you should leave it at the value t.
3846 Instead, use the key `v' to cycle the archives-mode in the agenda."
3848 :group
'org-agenda-skip
3851 (defcustom org-columns-skip-archived-trees t
3852 "Non-nil means ignore archived trees when creating column view."
3854 :group
'org-properties
3857 (defcustom org-cycle-open-archived-trees nil
3858 "Non-nil means `org-cycle' will open archived trees.
3859 An archived tree is a tree marked with the tag ARCHIVE.
3860 When nil, archived trees will stay folded. You can still open them with
3861 normal outline commands like `show-all', but not with the cycling commands."
3866 (defcustom org-sparse-tree-open-archived-trees nil
3867 "Non-nil means sparse tree construction shows matches in archived trees.
3868 When nil, matches in these trees are highlighted, but the trees are kept in
3871 :group
'org-sparse-trees
3874 (defun org-cycle-hide-archived-subtrees (state)
3875 "Re-hide all archived subtrees after a visibility state change."
3876 (when (and (not org-cycle-open-archived-trees
)
3877 (not (memq state
'(overview folded
))))
3879 (let* ((globalp (memq state
'(contents all
)))
3880 (beg (if globalp
(point-min) (point)))
3881 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3882 (org-hide-archived-subtrees beg end
)
3884 (if (looking-at (concat ".*:" org-archive-tag
":"))
3885 (message "%s" (substitute-command-keys
3886 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3888 (defun org-force-cycle-archived ()
3889 "Cycle subtree even if it is archived."
3891 (setq this-command
'org-cycle
)
3892 (let ((org-cycle-open-archived-trees t
))
3893 (call-interactively 'org-cycle
)))
3895 (defun org-hide-archived-subtrees (beg end
)
3896 "Re-hide all archived subtrees after a visibility state change."
3898 (let* ((re (concat ":" org-archive-tag
":")))
3900 (while (re-search-forward re end t
)
3901 (when (org-on-heading-p)
3902 (org-flag-subtree t
)
3903 (org-end-of-subtree t
))))))
3905 (defun org-flag-subtree (flag)
3907 (org-back-to-heading t
)
3908 (outline-end-of-heading)
3909 (outline-flag-region (point)
3910 (progn (org-end-of-subtree t
) (point))
3913 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3916 (org-autoload "org-archive"
3917 '(org-add-archive-files org-archive-subtree
3918 org-archive-to-archive-sibling org-toggle-archive-tag
3919 org-archive-subtree-default
3920 org-archive-subtree-default-with-confirmation
)))
3922 ;; Autoload Column View Code
3924 (declare-function org-columns-number-to-string
"org-colview")
3925 (declare-function org-columns-get-format-and-top-level
"org-colview")
3926 (declare-function org-columns-compute
"org-colview")
3928 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3929 '(org-columns-number-to-string org-columns-get-format-and-top-level
3930 org-columns-compute org-agenda-columns org-columns-remove-overlays
3931 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3935 (declare-function org-id-store-link
"org-id")
3936 (declare-function org-id-locations-load
"org-id")
3937 (declare-function org-id-locations-save
"org-id")
3938 (defvar org-id-track-globally
)
3939 (org-autoload "org-id"
3940 '(org-id-get-create org-id-new org-id-copy org-id-get
3941 org-id-get-with-outline-path-completion
3942 org-id-get-with-outline-drilling
3943 org-id-goto org-id-find org-id-store-link
))
3945 ;; Autoload Plotting Code
3947 (org-autoload "org-plot"
3948 '(org-plot/gnuplot
))
3950 ;;; Variables for pre-computed regular expressions, all buffer local
3952 (defvar org-drawer-regexp nil
3953 "Matches first line of a hidden block.")
3954 (make-variable-buffer-local 'org-drawer-regexp
)
3955 (defvar org-todo-regexp nil
3956 "Matches any of the TODO state keywords.")
3957 (make-variable-buffer-local 'org-todo-regexp
)
3958 (defvar org-not-done-regexp nil
3959 "Matches any of the TODO state keywords except the last one.")
3960 (make-variable-buffer-local 'org-not-done-regexp
)
3961 (defvar org-not-done-heading-regexp nil
3962 "Matches a TODO headline that is not done.")
3963 (make-variable-buffer-local 'org-not-done-regexp
)
3964 (defvar org-todo-line-regexp nil
3965 "Matches a headline and puts TODO state into group 2 if present.")
3966 (make-variable-buffer-local 'org-todo-line-regexp
)
3967 (defvar org-complex-heading-regexp nil
3968 "Matches a headline and puts everything into groups:
3970 group 2: The todo keyword, maybe
3971 group 3: Priority cookie
3972 group 4: True headline
3974 (make-variable-buffer-local 'org-complex-heading-regexp
)
3975 (defvar org-complex-heading-regexp-format nil
)
3976 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3977 (defvar org-todo-line-tags-regexp nil
3978 "Matches a headline and puts TODO state into group 2 if present.
3979 Also put tags into group 4 if tags are present.")
3980 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3981 (defvar org-nl-done-regexp nil
3982 "Matches newline followed by a headline with the DONE keyword.")
3983 (make-variable-buffer-local 'org-nl-done-regexp
)
3984 (defvar org-looking-at-done-regexp nil
3985 "Matches the DONE keyword a point.")
3986 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3987 (defvar org-ds-keyword-length
12
3988 "Maximum length of the Deadline and SCHEDULED keywords.")
3989 (make-variable-buffer-local 'org-ds-keyword-length
)
3990 (defvar org-deadline-regexp nil
3991 "Matches the DEADLINE keyword.")
3992 (make-variable-buffer-local 'org-deadline-regexp
)
3993 (defvar org-deadline-time-regexp nil
3994 "Matches the DEADLINE keyword together with a time stamp.")
3995 (make-variable-buffer-local 'org-deadline-time-regexp
)
3996 (defvar org-deadline-line-regexp nil
3997 "Matches the DEADLINE keyword and the rest of the line.")
3998 (make-variable-buffer-local 'org-deadline-line-regexp
)
3999 (defvar org-scheduled-regexp nil
4000 "Matches the SCHEDULED keyword.")
4001 (make-variable-buffer-local 'org-scheduled-regexp
)
4002 (defvar org-scheduled-time-regexp nil
4003 "Matches the SCHEDULED keyword together with a time stamp.")
4004 (make-variable-buffer-local 'org-scheduled-time-regexp
)
4005 (defvar org-closed-time-regexp nil
4006 "Matches the CLOSED keyword together with a time stamp.")
4007 (make-variable-buffer-local 'org-closed-time-regexp
)
4009 (defvar org-keyword-time-regexp nil
4010 "Matches any of the 4 keywords, together with the time stamp.")
4011 (make-variable-buffer-local 'org-keyword-time-regexp
)
4012 (defvar org-keyword-time-not-clock-regexp nil
4013 "Matches any of the 3 keywords, together with the time stamp.")
4014 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4015 (defvar org-maybe-keyword-time-regexp nil
4016 "Matches a timestamp, possibly preceeded by a keyword.")
4017 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4018 (defvar org-planning-or-clock-line-re nil
4019 "Matches a line with planning or clock info.")
4020 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
4021 (defvar org-all-time-keywords nil
4022 "List of time keywords.")
4023 (make-variable-buffer-local 'org-all-time-keywords
)
4025 (defconst org-plain-time-of-day-regexp
4028 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4031 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4033 "Regular expression to match a plain time or time range.
4034 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4035 groups carry important information:
4037 1 the first time, range or not
4038 8 the second time, if it is a range.")
4040 (defconst org-plain-time-extension-regexp
4043 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4044 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4045 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4046 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4047 groups carry important information:
4050 9 minutes of duration")
4052 (defconst org-stamp-time-of-day-regexp
4054 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4055 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4057 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4058 "Regular expression to match a timestamp time or time range.
4059 After a match, the following groups carry important information:
4061 1 date plus weekday, for back referencing to make sure both times are on the same day
4062 2 the first time, range or not
4063 4 the second time, if it is a range.")
4065 (defconst org-startup-options
4066 '(("fold" org-startup-folded t
)
4067 ("overview" org-startup-folded t
)
4068 ("nofold" org-startup-folded nil
)
4069 ("showall" org-startup-folded nil
)
4070 ("showeverything" org-startup-folded showeverything
)
4071 ("content" org-startup-folded content
)
4072 ("indent" org-startup-indented t
)
4073 ("noindent" org-startup-indented nil
)
4074 ("hidestars" org-hide-leading-stars t
)
4075 ("showstars" org-hide-leading-stars nil
)
4076 ("odd" org-odd-levels-only t
)
4077 ("oddeven" org-odd-levels-only nil
)
4078 ("align" org-startup-align-all-tables t
)
4079 ("noalign" org-startup-align-all-tables nil
)
4080 ("customtime" org-display-custom-times t
)
4081 ("logdone" org-log-done time
)
4082 ("lognotedone" org-log-done note
)
4083 ("nologdone" org-log-done nil
)
4084 ("lognoteclock-out" org-log-note-clock-out t
)
4085 ("nolognoteclock-out" org-log-note-clock-out nil
)
4086 ("logrepeat" org-log-repeat state
)
4087 ("lognoterepeat" org-log-repeat note
)
4088 ("nologrepeat" org-log-repeat nil
)
4089 ("logreschedule" org-log-reschedule time
)
4090 ("lognotereschedule" org-log-reschedule note
)
4091 ("nologreschedule" org-log-reschedule nil
)
4092 ("logredeadline" org-log-redeadline time
)
4093 ("lognoteredeadline" org-log-redeadline note
)
4094 ("nologredeadline" org-log-redeadline nil
)
4095 ("logrefile" org-log-refile time
)
4096 ("lognoterefile" org-log-refile note
)
4097 ("nologrefile" org-log-refile nil
)
4098 ("fninline" org-footnote-define-inline t
)
4099 ("nofninline" org-footnote-define-inline nil
)
4100 ("fnlocal" org-footnote-section nil
)
4101 ("fnauto" org-footnote-auto-label t
)
4102 ("fnprompt" org-footnote-auto-label nil
)
4103 ("fnconfirm" org-footnote-auto-label confirm
)
4104 ("fnplain" org-footnote-auto-label plain
)
4105 ("fnadjust" org-footnote-auto-adjust t
)
4106 ("nofnadjust" org-footnote-auto-adjust nil
)
4107 ("constcgs" constants-unit-system cgs
)
4108 ("constSI" constants-unit-system SI
)
4109 ("noptag" org-tag-persistent-alist nil
)
4110 ("hideblocks" org-hide-block-startup t
)
4111 ("nohideblocks" org-hide-block-startup nil
)
4112 ("beamer" org-startup-with-beamer-mode t
)
4113 ("entitiespretty" org-pretty-entities t
)
4114 ("entitiesplain" org-pretty-entities nil
))
4115 "Variable associated with STARTUP options for org-mode.
4116 Each element is a list of three items: The startup options as written
4117 in the #+STARTUP line, the corresponding variable, and the value to
4118 set this variable to if the option is found. An optional forth element PUSH
4119 means to push this value onto the list in the variable.")
4121 (defun org-set-regexps-and-options ()
4122 "Precompute regular expressions for current buffer."
4124 (org-set-local 'org-todo-kwd-alist nil
)
4125 (org-set-local 'org-todo-key-alist nil
)
4126 (org-set-local 'org-todo-key-trigger nil
)
4127 (org-set-local 'org-todo-keywords-1 nil
)
4128 (org-set-local 'org-done-keywords nil
)
4129 (org-set-local 'org-todo-heads nil
)
4130 (org-set-local 'org-todo-sets nil
)
4131 (org-set-local 'org-todo-log-states nil
)
4132 (org-set-local 'org-file-properties nil
)
4133 (org-set-local 'org-file-tags nil
)
4134 (let ((re (org-make-options-regexp
4135 '("CATEGORY" "TODO" "COLUMNS"
4136 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
4137 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS"
4139 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4141 (scripts org-use-sub-superscripts
)
4142 kwds kws0 kwsa key log value cat arch tags const links hw dws
4143 tail sep kws1 prio props ftags drawers beamer-p
4144 ext-setup-or-nil setup-contents
(start 0))
4148 (goto-char (point-min))
4149 (while (or (and ext-setup-or-nil
4150 (string-match re ext-setup-or-nil start
)
4151 (setq start
(match-end 0)))
4152 (and (setq ext-setup-or-nil nil start
0)
4153 (re-search-forward re nil t
)))
4154 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4155 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4156 (if (stringp value
) (setq value
(org-trim value
)))
4158 ((equal key
"CATEGORY")
4160 ((member key
'("SEQ_TODO" "TODO"))
4161 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4162 ((equal key
"TYP_TODO")
4163 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4164 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4165 ;; general TODO-like setup
4166 (push (cons (intern (downcase (match-string 1 key
)))
4167 (org-split-string value splitre
)) kwds
))
4169 (setq tags
(append tags
(if tags
'("\\n") nil
)
4170 (org-split-string value splitre
))))
4171 ((equal key
"COLUMNS")
4172 (org-set-local 'org-columns-default-format value
))
4174 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4175 (push (cons (match-string 1 value
)
4176 (org-trim (match-string 2 value
)))
4178 ((equal key
"PRIORITIES")
4179 (setq prio
(org-split-string value
" +")))
4180 ((equal key
"PROPERTY")
4181 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4182 (push (cons (match-string 1 value
) (match-string 2 value
))
4184 ((equal key
"FILETAGS")
4185 (when (string-match "\\S-" value
)
4190 (mapcar (lambda (x) (org-split-string x
":"))
4191 (org-split-string value
)))))))
4192 ((equal key
"DRAWERS")
4193 (setq drawers
(org-split-string value splitre
)))
4194 ((equal key
"CONSTANTS")
4195 (setq const
(append const
(org-split-string value splitre
))))
4196 ((equal key
"STARTUP")
4197 (let ((opts (org-split-string value splitre
))
4199 (while (setq l
(pop opts
))
4200 (when (setq l
(assoc l org-startup-options
))
4201 (setq var
(nth 1 l
) val
(nth 2 l
))
4203 (set (make-local-variable var
) val
)
4204 (if (not (listp (symbol-value var
)))
4205 (set (make-local-variable var
) nil
))
4206 (set (make-local-variable var
) (symbol-value var
))
4207 (add-to-list var val
))))))
4208 ((equal key
"ARCHIVE")
4210 (remove-text-properties 0 (length arch
)
4211 '(face t fontified t
) arch
))
4212 ((equal key
"LATEX_CLASS")
4213 (setq beamer-p
(equal value
"beamer")))
4214 ((equal key
"OPTIONS")
4215 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4216 (setq scripts
(read (match-string 2 value
)))))
4217 ((equal key
"SETUPFILE")
4218 (setq setup-contents
(org-file-contents
4220 (org-remove-double-quotes value
))
4222 (if (not ext-setup-or-nil
)
4223 (setq ext-setup-or-nil setup-contents start
0)
4224 (setq ext-setup-or-nil
4225 (concat (substring ext-setup-or-nil
0 start
)
4226 "\n" setup-contents
"\n"
4227 (substring ext-setup-or-nil start
)))))
4229 (org-set-local 'org-use-sub-superscripts scripts
)
4231 (org-set-local 'org-category
(intern cat
))
4232 (push (cons "CATEGORY" cat
) props
))
4234 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4235 (setq prio
(mapcar 'string-to-char prio
))
4236 (org-set-local 'org-highest-priority
(nth 0 prio
))
4237 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4238 (org-set-local 'org-default-priority
(nth 2 prio
)))
4239 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4240 (and ftags
(org-set-local 'org-file-tags
4241 (mapcar 'org-add-prop-inherited ftags
)))
4242 (and drawers
(org-set-local 'org-drawers drawers
))
4243 (and arch
(org-set-local 'org-archive-location arch
))
4244 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4245 ;; Process the TODO keywords
4247 ;; Use the global values as if they had been given locally.
4248 (setq kwds
(default-value 'org-todo-keywords
))
4249 (if (stringp (car kwds
))
4250 (setq kwds
(list (cons org-todo-interpretation
4251 (default-value 'org-todo-keywords
)))))
4252 (setq kwds
(reverse kwds
)))
4253 (setq kwds
(nreverse kwds
))
4255 (while (setq kws
(pop kwds
))
4257 (run-hook-with-args-until-success
4258 'org-todo-setup-filter-hook kws
)
4260 (setq inter
(pop kws
) sep
(member "|" kws
)
4261 kws0
(delete "|" (copy-sequence kws
))
4266 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4268 (setq kw
(match-string 1 x
)
4269 key
(and (match-end 2) (match-string 2 x
))
4270 log
(org-extract-log-state-settings x
))
4271 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4272 (and log
(push log org-todo-log-states
))
4274 (error "Invalid TODO keyword %s" x
)))
4276 kwsa
(if kwsa
(append '((:startgroup
))
4280 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4281 tail
(list inter hw
(car dws
) (org-last dws
))))
4282 (add-to-list 'org-todo-heads hw
'append
)
4283 (push kws1 org-todo-sets
)
4284 (setq org-done-keywords
(append org-done-keywords dws nil
))
4285 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4286 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4287 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4288 (setq org-todo-sets
(nreverse org-todo-sets
)
4289 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4290 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4291 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4292 ;; Process the constants
4295 (while (setq e
(pop const
))
4296 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4297 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4298 (setq org-table-formula-constants-local cst
)))
4300 ;; Process the tags.
4303 (while (setq e
(pop tags
))
4305 ((equal e
"{") (push '(:startgroup
) tgs
))
4306 ((equal e
"}") (push '(:endgroup
) tgs
))
4307 ((equal e
"\\n") (push '(:newline
) tgs
))
4308 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4309 (push (cons (match-string 1 e
)
4310 (string-to-char (match-string 2 e
)))
4312 (t (push (list e
) tgs
))))
4313 (org-set-local 'org-tag-alist nil
)
4314 (while (setq e
(pop tgs
))
4315 (or (and (stringp (car e
))
4316 (assoc (car e
) org-tag-alist
))
4317 (push e org-tag-alist
)))))
4319 ;; Compute the regular expressions and other local variables
4320 (if (not org-done-keywords
)
4321 (setq org-done-keywords
(and org-todo-keywords-1
4322 (list (org-last org-todo-keywords-1
)))))
4323 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4324 (length org-scheduled-string
)
4325 (length org-clock-string
)
4326 (length org-closed-string
)))
4328 (concat "^[ \t]*:\\("
4329 (mapconcat 'regexp-quote org-drawers
"\\|")
4331 org-not-done-keywords
4332 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4334 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4338 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4340 org-not-done-heading-regexp
4341 (concat "^\\(\\*+\\)[ \t]+\\("
4342 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4344 org-todo-line-regexp
4345 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4346 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4347 "\\)\\>\\)?[ \t]*\\(.*\\)")
4348 org-complex-heading-regexp
4349 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4350 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4351 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4352 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4353 org-complex-heading-regexp-format
4354 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4355 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4357 "\\(?:[ \t]*\\(\\[#.\\]\\)\\)?"
4358 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4360 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4361 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4363 (concat "\n\\*+[ \t]+"
4364 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4366 org-todo-line-tags-regexp
4367 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4368 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4370 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4371 org-looking-at-done-regexp
4373 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4375 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4376 org-deadline-time-regexp
4377 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4378 org-deadline-line-regexp
4379 (concat "\\<\\(" org-deadline-string
"\\).*")
4380 org-scheduled-regexp
4381 (concat "\\<" org-scheduled-string
)
4382 org-scheduled-time-regexp
4383 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4384 org-closed-time-regexp
4385 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4386 org-keyword-time-regexp
4387 (concat "\\<\\(" org-scheduled-string
4388 "\\|" org-deadline-string
4389 "\\|" org-closed-string
4390 "\\|" org-clock-string
"\\)"
4391 " *[[<]\\([^]>]+\\)[]>]")
4392 org-keyword-time-not-clock-regexp
4393 (concat "\\<\\(" org-scheduled-string
4394 "\\|" org-deadline-string
4395 "\\|" org-closed-string
4397 " *[[<]\\([^]>]+\\)[]>]")
4398 org-maybe-keyword-time-regexp
4399 (concat "\\(\\<\\(" org-scheduled-string
4400 "\\|" org-deadline-string
4401 "\\|" org-closed-string
4402 "\\|" org-clock-string
"\\)\\)?"
4403 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4404 org-planning-or-clock-line-re
4405 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4406 "\\|" org-deadline-string
4407 "\\|" org-closed-string
"\\|" org-clock-string
4409 org-all-time-keywords
4410 (mapcar (lambda (w) (substring w
0 -
1))
4411 (list org-scheduled-string org-deadline-string
4412 org-clock-string org-closed-string
))
4414 (org-compute-latex-and-specials-regexp)
4415 (org-set-font-lock-defaults))))
4417 (defun org-file-contents (file &optional noerror
)
4418 "Return the contents of FILE, as a string."
4420 (not (file-readable-p file
)))
4423 (message "Cannot read file \"%s\"" file
)
4426 (error "Cannot read file \"%s\"" file
))
4428 (insert-file-contents file
)
4431 (defun org-extract-log-state-settings (x)
4432 "Extract the log state setting from a TODO keyword string.
4433 This will extract info from a string like \"WAIT(w@/!)\"."
4434 (let (kw key log1 log2
)
4435 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4436 (setq kw
(match-string 1 x
)
4437 key
(and (match-end 2) (match-string 2 x
))
4438 log1
(and (match-end 3) (match-string 3 x
))
4439 log2
(and (match-end 4) (match-string 4 x
)))
4442 (and log1
(if (equal log1
"!") 'time
'note
))
4443 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4445 (defun org-remove-keyword-keys (list)
4446 "Remove a pair of parenthesis at the end of each string in LIST."
4448 (if (string-match "(.*)$" x
)
4449 (substring x
0 (match-beginning 0))
4453 (defun org-assign-fast-keys (alist)
4454 "Assign fast keys to a keyword-key alist.
4455 Respect keys that are already there."
4456 (let (new e
(alt ?
0))
4457 (while (setq e
(pop alist
))
4458 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4459 (cdr e
)) ;; Key already assigned.
4461 (let ((clist (string-to-list (downcase (car e
))))
4462 (used (append new alist
)))
4463 (when (= (car clist
) ?
@)
4465 (while (and clist
(rassoc (car clist
) used
))
4468 (while (rassoc alt used
)
4470 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4473 ;;; Some variables used in various places
4475 (defvar org-window-configuration nil
4476 "Used in various places to store a window configuration.")
4477 (defvar org-selected-window nil
4478 "Used in various places to store a window configuration.")
4479 (defvar org-finish-function nil
4480 "Function to be called when `C-c C-c' is used.
4481 This is for getting out of special buffers like remember.")
4484 ;; FIXME: Occasionally check by commenting these, to make sure
4485 ;; no other functions uses these, forgetting to let-bind them.
4490 ;; Defined somewhere in this file, but used before definition.
4491 (defvar org-entities
) ;; defined in org-entities.el
4492 (defvar org-struct-menu
)
4493 (defvar org-org-menu
)
4494 (defvar org-tbl-menu
)
4496 ;;;; Define the Org-mode
4498 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4499 (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."))
4502 ;; We use a before-change function to check if a table might need
4504 (defvar org-table-may-need-update t
4505 "Indicates that a table might need an update.
4506 This variable is set by `org-before-change-function'.
4507 `org-table-align' sets it back to nil.")
4508 (defun org-before-change-function (beg end
)
4509 "Every change indicates that a table might need an update."
4510 (setq org-table-may-need-update t
))
4511 (defvar org-mode-map
)
4512 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4513 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4514 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4515 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4516 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4517 (defvar org-table-buffer-is-an nil
)
4518 (defconst org-outline-regexp
"\\*+ ")
4521 (define-derived-mode org-mode outline-mode
"Org"
4522 "Outline-based notes management and organizer, alias
4523 \"Carsten's outline-mode for keeping track of everything.\"
4525 Org-mode develops organizational tasks around a NOTES file which
4526 contains information about projects as plain text. Org-mode is
4527 implemented on top of outline-mode, which is ideal to keep the content
4528 of large files well structured. It supports ToDo items, deadlines and
4529 time stamps, which magically appear in the diary listing of the Emacs
4530 calendar. Tables are easily created with a built-in table editor.
4531 Plain text URL-like links connect to websites, emails (VM), Usenet
4532 messages (Gnus), BBDB entries, and any files related to the project.
4533 For printing and sharing of notes, an Org-mode file (or a part of it)
4534 can be exported as a structured ASCII or HTML file.
4536 The following commands are available:
4540 ;; Get rid of Outline menus, they are not needed
4541 ;; Need to do this here because define-derived-mode sets up
4542 ;; the keymap so late. Still, it is a waste to call this each time
4543 ;; we switch another buffer into org-mode.
4544 (if (featurep 'xemacs
)
4545 (when (boundp 'outline-mode-menu-heading
)
4546 ;; Assume this is Greg's port, it uses easymenu
4547 (easy-menu-remove outline-mode-menu-heading
)
4548 (easy-menu-remove outline-mode-menu-show
)
4549 (easy-menu-remove outline-mode-menu-hide
))
4550 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4551 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4552 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4554 (org-load-modules-maybe)
4555 (easy-menu-add org-org-menu
)
4556 (easy-menu-add org-tbl-menu
)
4557 (org-install-agenda-files-menu)
4558 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4559 (add-to-invisibility-spec '(org-cwidth))
4560 (add-to-invisibility-spec '(org-hide-block . t
))
4561 (when (featurep 'xemacs
)
4562 (org-set-local 'line-move-ignore-invisible t
))
4563 (org-set-local 'outline-regexp org-outline-regexp
)
4564 (org-set-local 'outline-level
'org-outline-level
)
4565 (when (and org-ellipsis
4566 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4567 (fboundp 'make-glyph-code
))
4568 (unless org-display-table
4569 (setq org-display-table
(make-display-table)))
4570 (set-display-table-slot
4573 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4575 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4576 (setq buffer-display-table org-display-table
))
4577 (org-set-regexps-and-options)
4578 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4579 ;; tag faces set outside customize.... force initialization.
4580 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4582 (org-set-local 'calc-embedded-open-mode
"# ")
4583 (modify-syntax-entry ?
@ "w")
4584 (if org-startup-truncated
(setq truncate-lines t
))
4585 (org-set-local 'font-lock-unfontify-region-function
4586 'org-unfontify-region
)
4587 ;; Activate before-change-function
4588 (org-set-local 'org-table-may-need-update t
)
4589 (org-add-hook 'before-change-functions
'org-before-change-function nil
4591 ;; Check for running clock before killing a buffer
4592 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4593 ;; Paragraphs and auto-filling
4594 (org-set-autofill-regexps)
4595 (setq indent-line-function
'org-indent-line-function
)
4596 (org-update-radio-target-regexp)
4597 ;; Beginning/end of defun
4598 (org-set-local 'beginning-of-defun-function
'org-beginning-of-defun
)
4599 (org-set-local 'end-of-defun-function
'org-end-of-defun
)
4600 ;; Make sure dependence stuff works reliably, even for users who set it
4602 (if org-enforce-todo-dependencies
4603 (add-hook 'org-blocker-hook
4604 'org-block-todo-from-children-or-siblings-or-parent
)
4605 (remove-hook 'org-blocker-hook
4606 'org-block-todo-from-children-or-siblings-or-parent
))
4607 (if org-enforce-todo-checkbox-dependencies
4608 (add-hook 'org-blocker-hook
4609 'org-block-todo-from-checkboxes
)
4610 (remove-hook 'org-blocker-hook
4611 'org-block-todo-from-checkboxes
))
4613 ;; Comment characters
4614 (org-set-local 'comment-start
"#")
4615 (org-set-local 'comment-padding
" ")
4617 ;; Align options lines
4619 'align-mode-rules-list
4620 '((org-in-buffer-settings
4621 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4622 (modes .
'(org-mode)))))
4625 (org-set-local 'imenu-create-index-function
4626 'org-imenu-get-tree
)
4628 ;; Make isearch reveal context
4629 (if (or (featurep 'xemacs
)
4630 (not (boundp 'outline-isearch-open-invisible-function
)))
4631 ;; Emacs 21 and XEmacs make use of the hook
4632 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4633 ;; Emacs 22 deals with this through a special variable
4634 (org-set-local 'outline-isearch-open-invisible-function
4635 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4637 ;; Turn on org-beamer-mode?
4638 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4640 ;; If empty file that did not turn on org-mode automatically, make it to.
4641 (if (and org-insert-mode-line-in-empty-file
4643 (= (point-min) (point-max)))
4644 (insert "# -*- mode: org -*-\n\n"))
4645 (unless org-inhibit-startup
4646 (when org-startup-align-all-tables
4647 (let ((bmp (buffer-modified-p)))
4648 (org-table-map-tables 'org-table-align
'quietly
)
4649 (set-buffer-modified-p bmp
)))
4650 (when org-startup-indented
4651 (require 'org-indent
)
4652 (org-indent-mode 1))
4653 (unless org-inhibit-startup-visibility-stuff
4654 (org-set-startup-visibility))))
4656 (when (fboundp 'abbrev-table-put
)
4657 (abbrev-table-put org-mode-abbrev-table
4658 :parents
(list text-mode-abbrev-table
)))
4660 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4662 (defun org-current-time ()
4663 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4664 (if (> (car org-time-stamp-rounding-minutes
) 1)
4665 (let ((r (car org-time-stamp-rounding-minutes
))
4666 (time (decode-time)))
4668 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4672 ;;;; Font-Lock stuff, including the activators
4674 (defvar org-mouse-map
(make-sparse-keymap))
4675 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
4676 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
4677 (when org-mouse-1-follows-link
4678 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
4679 (when org-tab-follows-link
4680 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
4681 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
4683 (require 'font-lock
)
4685 (defconst org-non-link-chars
"]\t\n\r<>")
4686 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
4687 "shell" "elisp" "doi"))
4688 (defvar org-link-types-re nil
4689 "Matches a link that has a url-like prefix like \"http:\"")
4690 (defvar org-link-re-with-space nil
4691 "Matches a link with spaces, optional angular brackets around it.")
4692 (defvar org-link-re-with-space2 nil
4693 "Matches a link with spaces, optional angular brackets around it.")
4694 (defvar org-link-re-with-space3 nil
4695 "Matches a link with spaces, only for internal part in bracket links.")
4696 (defvar org-angle-link-re nil
4697 "Matches link with angular brackets, spaces are allowed.")
4698 (defvar org-plain-link-re nil
4699 "Matches plain link, without spaces.")
4700 (defvar org-bracket-link-regexp nil
4701 "Matches a link in double brackets.")
4702 (defvar org-bracket-link-analytic-regexp nil
4703 "Regular expression used to analyze links.
4704 Here is what the match groups contain after a match:
4710 (defvar org-bracket-link-analytic-regexp
++ nil
4711 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4712 (defvar org-any-link-re nil
4713 "Regular expression matching any link.")
4715 (defcustom org-match-sexp-depth
3
4716 "Number of stacked braces for sub/superscript matching.
4717 This has to be set before loading org.el to be effective."
4718 :group
'org-export-translation
; ??????????????????????????/
4721 (defun org-create-multibrace-regexp (left right n
)
4722 "Create a regular expression which will match a balanced sexp.
4723 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4724 as single character strings.
4725 The regexp returned will match the entire expression including the
4726 delimiters. It will also define a single group which contains the
4727 match except for the outermost delimiters. The maximum depth of
4728 stacked delimiters is N. Escaping delimiters is not possible."
4729 (let* ((nothing (concat "[^" left right
"]*?"))
4732 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4735 re
(concat re or next
)
4736 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4737 (concat left
"\\(" re
"\\)" right
)))
4739 (defvar org-match-substring-regexp
4741 "\\([^\\]\\)\\([_^]\\)\\("
4742 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4744 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4746 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4747 "The regular expression matching a sub- or superscript.")
4749 (defvar org-match-substring-with-braces-regexp
4751 "\\([^\\]\\)\\([_^]\\)\\("
4752 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4754 "The regular expression matching a sub- or superscript, forcing braces.")
4756 (defun org-make-link-regexps ()
4757 "Update the link regular expressions.
4758 This should be called after the variable `org-link-types' has changed."
4759 (setq org-link-types-re
4761 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
4762 org-link-re-with-space
4764 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4765 "\\([^" org-non-link-chars
" ]"
4766 "[^" org-non-link-chars
"]*"
4767 "[^" org-non-link-chars
" ]\\)>?")
4768 org-link-re-with-space2
4770 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4771 "\\([^" org-non-link-chars
" ]"
4773 "[^" org-non-link-chars
" ]\\)>?")
4774 org-link-re-with-space3
4776 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4777 "\\([^" org-non-link-chars
" ]"
4781 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4782 "\\([^" org-non-link-chars
" ]"
4783 "[^" org-non-link-chars
"]*"
4787 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4788 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4789 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4790 org-bracket-link-regexp
4791 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4792 org-bracket-link-analytic-regexp
4795 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
4798 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4800 org-bracket-link-analytic-regexp
++
4803 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
4806 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4809 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
4810 org-angle-link-re
"\\)\\|\\("
4811 org-plain-link-re
"\\)")))
4813 (org-make-link-regexps)
4815 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4816 "Regular expression for fast time stamp matching.")
4817 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4818 "Regular expression for fast time stamp matching.")
4819 (defconst org-ts-regexp0
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4820 "Regular expression matching time strings for analysis.
4821 This one does not require the space after the date, so it can be used
4822 on a string that terminates immediately after the date.")
4823 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4824 "Regular expression matching time strings for analysis.")
4825 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
4826 "Regular expression matching time stamps, with groups.")
4827 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
4828 "Regular expression matching time stamps (also [..]), with groups.")
4829 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
4830 "Regular expression matching a time stamp range.")
4831 (defconst org-tr-regexp-both
4832 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
4833 "Regular expression matching a time stamp range.")
4834 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
4835 org-ts-regexp
"\\)?")
4836 "Regular expression matching a time stamp or time stamp range.")
4837 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
4838 org-ts-regexp-both
"\\)?")
4839 "Regular expression matching a time stamp or time stamp range.
4840 The time stamps may be either active or inactive.")
4842 (defvar org-emph-face nil
)
4844 (defun org-do-emphasis-faces (limit)
4845 "Run through the buffer and add overlays to links."
4847 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
4848 (if (not (= (char-after (match-beginning 3))
4849 (char-after (match-beginning 4))))
4852 (setq a
(assoc (match-string 3) org-emphasis-alist
))
4853 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4857 (org-remove-flyspell-overlays-in
4858 (match-beginning 0) (match-end 0)))
4859 (add-text-properties (match-beginning 2) (match-end 2)
4860 '(font-lock-multiline t org-emphasis t
))
4861 (when org-hide-emphasis-markers
4862 (add-text-properties (match-end 4) (match-beginning 5)
4863 '(invisible org-link
))
4864 (add-text-properties (match-beginning 3) (match-end 3)
4865 '(invisible org-link
)))))
4869 (defun org-emphasize (&optional char
)
4870 "Insert or change an emphasis, i.e. a font like bold or italic.
4871 If there is an active region, change that region to a new emphasis.
4872 If there is no region, just insert the marker characters and position
4873 the cursor between them.
4874 CHAR should be either the marker character, or the first character of the
4875 HTML tag associated with that emphasis. If CHAR is a space, the means
4876 to remove the emphasis of the selected region.
4877 If char is not given (for example in an interactive call) it
4878 will be prompted for."
4880 (let ((eal org-emphasis-alist
) e det
4881 (erc org-emphasis-regexp-components
)
4883 (string "") beg end move tag c s
)
4884 (if (org-region-active-p)
4885 (setq beg
(region-beginning) end
(region-end)
4886 string
(buffer-substring beg end
))
4889 (while (setq e
(pop eal
))
4890 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
4892 (push (cons c
(string-to-char (car e
))) det
)
4893 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
4894 (substring tag
1)))))
4895 (setq det
(nreverse det
))
4897 (message "%s" (concat "Emphasis marker or tag:" prompt
))
4898 (setq char
(read-char-exclusive)))
4899 (setq char
(or (cdr (assoc char det
)) char
))
4900 (if (equal char ?\
)
4901 (setq s
"" move nil
)
4902 (unless (assoc (char-to-string char
) org-emphasis-alist
)
4903 (error "No such emphasis marker: \"%c\"" char
))
4904 (setq s
(char-to-string char
)))
4905 (while (and (> (length string
) 1)
4906 (equal (substring string
0 1) (substring string -
1))
4907 (assoc (substring string
0 1) org-emphasis-alist
))
4908 (setq string
(substring string
1 -
1)))
4909 (setq string
(concat s string s
))
4910 (if beg
(delete-region beg end
))
4912 (string-match (concat "[" (nth 0 erc
) "\n]")
4913 (char-to-string (char-before (point)))))
4916 (string-match (concat "[" (nth 1 erc
) "\n]")
4917 (char-to-string (char-after (point)))))
4918 (insert " ") (backward-char 1))
4920 (and move
(backward-char 1))))
4922 (defconst org-nonsticky-props
4923 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
4925 (defsubst org-rear-nonsticky-at
(pos)
4926 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
4928 (defun org-activate-plain-links (limit)
4929 "Run through the buffer and add overlays to links."
4932 (if (re-search-forward org-plain-link-re limit t
)
4934 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4935 (setq f
(get-text-property (match-beginning 0) 'face
))
4936 (if (or (eq f
'org-tag
)
4937 (and (listp f
) (memq 'org-tag f
)))
4939 (add-text-properties (match-beginning 0) (match-end 0)
4940 (list 'mouse-face
'highlight
4942 'keymap org-mouse-map
))
4943 (org-rear-nonsticky-at (match-end 0)))
4946 (defun org-activate-code (limit)
4947 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t
)
4949 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4950 (remove-text-properties (match-beginning 0) (match-end 0)
4951 '(display t invisible t intangible t
))
4954 (defun org-fontify-meta-lines-and-blocks (limit)
4955 "Fontify #+ lines and blocks, in the correct ways."
4956 (let ((case-fold-search t
))
4957 (if (re-search-forward
4958 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4960 (let ((beg (match-beginning 0))
4961 (beg1 (line-beginning-position 2))
4962 (dc1 (downcase (match-string 2)))
4963 (dc3 (downcase (match-string 3)))
4964 end end1 quoting block-type
)
4966 ((member dc1
'("html:" "ascii:" "latex:" "docbook:"))
4967 ;; a single line of backend-specific content
4968 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4969 (remove-text-properties (match-beginning 0) (match-end 0)
4970 '(display t invisible t intangible t
))
4971 (add-text-properties (match-beginning 1) (match-end 3)
4972 '(font-lock-fontified t face org-meta-line
))
4973 (add-text-properties (match-beginning 6) (match-end 6)
4974 '(font-lock-fontified t face org-block
))
4976 ((and (match-end 4) (equal dc3
"begin"))
4978 (setq block-type
(downcase (match-string 5))
4979 quoting
(member block-type org-protecting-blocks
))
4980 (when (re-search-forward
4981 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4982 nil t
) ;; on purpose, we look further than LIMIT
4983 (setq end
(match-end 0) end1
(1- (match-beginning 0)))
4985 (remove-text-properties beg end
4986 '(display t invisible t intangible t
)))
4987 (add-text-properties
4989 '(font-lock-fontified t font-lock-multiline t
))
4990 (add-text-properties beg beg1
'(face org-meta-line
))
4991 (add-text-properties end1 end
'(face org-meta-line
))
4994 (add-text-properties beg1 end1
'(face org-block
)))
4995 ((not org-fontify-quote-and-verse-blocks
))
4996 ((string= block-type
"quote")
4997 (add-text-properties beg1 end1
'(face org-quote
)))
4998 ((string= block-type
"verse")
4999 (add-text-properties beg1 end1
'(face org-verse
))))
5001 ((member dc1
'("title:" "author:" "email:" "date:"))
5002 (add-text-properties
5004 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
5005 '(font-lock-fontified t invisible t
)
5006 '(font-lock-fontified t face org-document-info-keyword
)))
5007 (add-text-properties
5008 (match-beginning 6) (match-end 6)
5009 (if (string-equal dc1
"title:")
5010 '(font-lock-fontified t face org-document-title
)
5011 '(font-lock-fontified t face org-document-info
))))
5012 ((not (member (char-after beg
) '(?\ ?
\t)))
5013 ;; just any other in-buffer setting, but not indented
5014 (add-text-properties
5016 '(font-lock-fontified t face org-meta-line
))
5018 ((or (member dc1
'("begin:" "end:" "caption:" "label:"
5019 "orgtbl:" "tblfm:" "tblname:" "result:"
5020 "results:" "source:" "srcname:" "call:"))
5021 (and (match-end 4) (equal dc3
"attr")))
5022 (add-text-properties
5024 '(font-lock-fontified t face org-meta-line
))
5026 ((member dc3
'(" " ""))
5027 (add-text-properties
5029 '(font-lock-fontified t face font-lock-comment-face
)))
5032 (defun org-activate-angle-links (limit)
5033 "Run through the buffer and add overlays to links."
5034 (if (re-search-forward org-angle-link-re limit t
)
5036 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5037 (add-text-properties (match-beginning 0) (match-end 0)
5038 (list 'mouse-face
'highlight
5039 'keymap org-mouse-map
))
5040 (org-rear-nonsticky-at (match-end 0))
5043 (defun org-activate-footnote-links (limit)
5044 "Run through the buffer and add overlays to links."
5045 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
5048 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5049 (add-text-properties (match-beginning 2) (match-end 2)
5050 (list 'mouse-face
'highlight
5051 'keymap org-mouse-map
5053 (if (= (point-at-bol) (match-beginning 2))
5054 "Footnote definition"
5055 "Footnote reference")
5057 (org-rear-nonsticky-at (match-end 2))
5060 (defun org-activate-bracket-links (limit)
5061 "Run through the buffer and add overlays to bracketed links."
5062 (if (re-search-forward org-bracket-link-regexp limit t
)
5063 (let* ((help (concat "LINK: "
5064 (org-match-string-no-properties 1)))
5065 ;; FIXME: above we should remove the escapes.
5066 ;; but that requires another match, protecting match data,
5067 ;; a lot of overhead for font-lock.
5068 (ip (org-maybe-intangible
5069 (list 'invisible
'org-link
5070 'keymap org-mouse-map
'mouse-face
'highlight
5071 'font-lock-multiline t
'help-echo help
)))
5072 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5073 'font-lock-multiline t
'help-echo help
)))
5074 ;; We need to remove the invisible property here. Table narrowing
5075 ;; may have made some of this invisible.
5076 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5077 (remove-text-properties (match-beginning 0) (match-end 0)
5081 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5082 (org-rear-nonsticky-at (match-beginning 3))
5083 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5084 (org-rear-nonsticky-at (match-end 3))
5085 (add-text-properties (match-end 3) (match-end 0) ip
)
5086 (org-rear-nonsticky-at (match-end 0)))
5087 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5088 (org-rear-nonsticky-at (match-beginning 1))
5089 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5090 (org-rear-nonsticky-at (match-end 1))
5091 (add-text-properties (match-end 1) (match-end 0) ip
)
5092 (org-rear-nonsticky-at (match-end 0)))
5095 (defun org-activate-dates (limit)
5096 "Run through the buffer and add overlays to dates."
5097 (if (re-search-forward org-tsr-regexp-both limit t
)
5099 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5100 (add-text-properties (match-beginning 0) (match-end 0)
5101 (list 'mouse-face
'highlight
5102 'keymap org-mouse-map
))
5103 (org-rear-nonsticky-at (match-end 0))
5104 (when org-display-custom-times
5106 (org-display-custom-time (match-beginning 3) (match-end 3)))
5107 (org-display-custom-time (match-beginning 1) (match-end 1)))
5110 (defvar org-target-link-regexp nil
5111 "Regular expression matching radio targets in plain text.")
5112 (make-variable-buffer-local 'org-target-link-regexp
)
5113 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5114 "Regular expression matching a link target.")
5115 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5116 "Regular expression matching a radio target.")
5117 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5118 "Regular expression matching any target.")
5120 (defun org-activate-target-links (limit)
5121 "Run through the buffer and add overlays to target matches."
5122 (when org-target-link-regexp
5123 (let ((case-fold-search t
))
5124 (if (re-search-forward org-target-link-regexp limit t
)
5126 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5127 (add-text-properties (match-beginning 0) (match-end 0)
5128 (list 'mouse-face
'highlight
5129 'keymap org-mouse-map
5130 'help-echo
"Radio target link"
5131 'org-linked-text t
))
5132 (org-rear-nonsticky-at (match-end 0))
5135 (defun org-update-radio-target-regexp ()
5136 "Find all radio targets in this file and update the regular expression."
5138 (when (memq 'radio org-activate-links
)
5139 (setq org-target-link-regexp
5140 (org-make-target-link-regexp (org-all-targets 'radio
)))
5141 (org-restart-font-lock)))
5143 (defun org-hide-wide-columns (limit)
5145 (setq s
(text-property-any (point) (or limit
(point-max))
5148 (setq e
(next-single-property-change s
'org-cwidth
))
5149 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5153 (defvar org-latex-and-specials-regexp nil
5154 "Regular expression for highlighting export special stuff.")
5155 (defvar org-match-substring-regexp
)
5156 (defvar org-match-substring-with-braces-regexp
)
5158 ;; This should be with the exporter code, but we also use if for font-locking
5159 (defconst org-export-html-special-string-regexps
5160 '(("\\\\-" .
"­")
5161 ("---\\([^-]\\)" .
"—\\1")
5162 ("--\\([^-]\\)" .
"–\\1")
5163 ("\\.\\.\\." .
"…"))
5164 "Regular expressions for special string conversion.")
5167 (defun org-compute-latex-and-specials-regexp ()
5168 "Compute regular expression for stuff treated specially by exporters."
5169 (if (not org-highlight-latex-fragments-and-specials
)
5170 (org-set-local 'org-latex-and-specials-regexp nil
)
5173 ((matchers (plist-get org-format-latex-options
:matchers
))
5174 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
5175 org-latex-regexps
)))
5176 (org-export-allow-BIND nil
)
5177 (options (org-combine-plists (org-default-export-plist)
5178 (org-infile-export-plist)))
5179 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
5180 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
5181 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
5182 (org-export-html-expand (plist-get options
:expand-quoted-html
))
5183 (org-export-with-special-strings (plist-get options
:special-strings
))
5186 ((equal org-export-with-sub-superscripts
'{})
5187 (list org-match-substring-with-braces-regexp
))
5188 (org-export-with-sub-superscripts
5189 (list org-match-substring-regexp
))
5192 (if org-export-with-LaTeX-fragments
5193 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
5195 (if org-export-with-TeX-macros
5196 (list (concat "\\\\"
5202 (append org-entities-user
5204 (if (boundp 'org-latex-entities
)
5206 (or (car-safe x
) x
))
5211 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5212 (re-special (if org-export-with-special-strings
5213 (mapcar (lambda (x) (car x
))
5214 org-export-html-special-string-regexps
)))
5218 (if org-export-html-expand
"@<[^>\n]+>")
5221 'org-latex-and-specials-regexp
5222 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5225 (defun org-do-latex-and-special-faces (limit)
5226 "Run through the buffer and add overlays to links."
5227 (when org-latex-and-specials-regexp
5229 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5231 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5233 '(org-code org-verbatim underline
)))
5236 d
(cond ((member (char-after (1+ (match-beginning 0)))
5239 (font-lock-prepend-text-property
5240 (+ d
(match-beginning 0)) (match-end 0)
5241 'face
'org-latex-and-export-specials
)
5242 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5243 '(font-lock-multiline t
)))))
5246 (defun org-restart-font-lock ()
5247 "Restart font-lock-mode, to force refontification."
5248 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5250 (font-lock-mode 1)))
5252 (defun org-all-targets (&optional radio
)
5253 "Return a list of all targets in this file.
5254 With optional argument RADIO, only find radio targets."
5255 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5258 (goto-char (point-min))
5259 (while (re-search-forward re nil t
)
5260 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5263 (defun org-make-target-link-regexp (targets)
5264 "Make regular expression matching all strings in TARGETS.
5265 The regular expression finds the targets also if there is a line break
5272 (while (string-match " +" x
)
5273 (setq x
(replace-match "\\s-+" t t x
)))
5279 (defun org-activate-tags (limit)
5280 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t
)
5282 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5283 (add-text-properties (match-beginning 1) (match-end 1)
5284 (list 'mouse-face
'highlight
5285 'keymap org-mouse-map
))
5286 (org-rear-nonsticky-at (match-end 1))
5289 (defun org-outline-level ()
5290 "Compute the outline level of the heading at point.
5291 This function assumes that the cursor is at the beginning of a line matched
5292 by outline-regexp. Otherwise it returns garbage.
5293 If this is called at a normal headline, the level is the number of stars.
5294 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5295 For plain list items, if they are matched by `outline-regexp', this returns
5296 1000 plus the line indentation."
5298 (looking-at outline-regexp
)
5299 (if (match-beginning 1)
5300 (+ (org-get-string-indentation (match-string 1)) 1000)
5301 (1- (- (match-end 0) (match-beginning 0))))))
5303 (defvar org-font-lock-keywords nil
)
5305 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5306 "Regular expression matching a property line.")
5308 (defvar org-font-lock-hook nil
5309 "Functions to be called for special font lock stuff.")
5311 (defun org-font-lock-hook (limit)
5312 (run-hook-with-args 'org-font-lock-hook limit
))
5314 (defun org-set-font-lock-defaults ()
5315 (let* ((em org-fontify-emphasized-text
)
5316 (lk org-activate-links
)
5317 (org-font-lock-extra-keywords
5320 '(org-font-lock-hook)
5322 `(,(if org-fontify-whole-heading-line
5323 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5324 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5325 (1 (org-get-level-face 1))
5326 (2 (org-get-level-face 2))
5327 (3 (org-get-level-face 3)))
5329 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5332 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5333 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5334 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5335 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t
))
5337 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5338 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5340 (list org-property-re
5341 '(1 'org-special-keyword t
)
5342 '(3 'org-property-value t
))
5344 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5345 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5346 (if (memq 'plain lk
) '(org-activate-plain-links))
5347 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5348 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5349 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5350 (if (memq 'footnote lk
) '(org-activate-footnote-links
5351 (2 'org-footnote t
)))
5352 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5353 '(org-hide-wide-columns (0 nil append
))
5355 (list (concat "^\\*+[ \t]+" org-todo-regexp
"\\([ \t]\\|$\\)")
5356 '(1 (org-get-todo-face 1) t
))
5358 (if org-fontify-done-headline
5359 (list (concat "^[*]+ +\\<\\("
5360 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5362 '(2 'org-headline-done t
))
5365 '(org-font-lock-add-priority-faces)
5367 '(org-font-lock-add-tag-faces)
5369 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5370 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5371 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5372 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5375 (if (featurep 'xemacs
)
5376 '(org-do-emphasis-faces (0 nil append
))
5377 '(org-do-emphasis-faces)))
5379 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5380 2 'org-checkbox prepend
)
5381 (if org-provide-checkbox-statistics
5382 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5383 (0 (org-get-checkbox-statistics-face) t
)))
5384 ;; Description list items
5385 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5387 ;; ARCHIVEd headings
5388 (list (concat "^\\*+ \\(.*:" org-archive-tag
":.*\\)")
5389 '(1 'org-archived prepend
))
5391 '(org-do-latex-and-special-faces)
5392 '(org-fontify-entities)
5393 '(org-raise-scripts)
5395 '(org-activate-code (1 'org-code t
))
5397 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5398 "\\|" org-quote-string
"\\)\\>")
5399 '(1 'org-special-keyword t
))
5400 '("^#.*" (0 'font-lock-comment-face t
))
5401 ;; Blocks and meta lines
5402 '(org-fontify-meta-lines-and-blocks)
5404 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5405 ;; Now set the full font-lock-keywords
5406 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5407 (org-set-local 'font-lock-defaults
5408 '(org-font-lock-keywords t nil nil backward-paragraph
))
5409 (kill-local-variable 'font-lock-keywords
) nil
))
5411 (defun org-toggle-pretty-entities ()
5412 "Toggle the compostion display of entities as UTF8 characters."
5414 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
5415 (org-restart-font-lock)
5416 (if org-pretty-entities
5417 (message "Entities are displayed as UTF8 characers")
5420 (decompose-region (point-min) (point-max))
5421 (message "Entities are displayed plain"))))
5423 (defun org-fontify-entities (limit)
5424 "Find an entity to fontify."
5426 (when org-pretty-entities
5428 (while (re-search-forward
5429 "\\\\\\([a-zA-Z][a-zA-Z0-9]*\\)\\($\\|[^[:alnum:]\n]\\)"
5431 (if (and (not (org-in-indented-comment-line))
5432 (setq ee
(org-entity-get (match-string 1)))
5433 (= (length (nth 6 ee
)) 1))
5435 (add-text-properties
5436 (match-beginning 0) (match-end 1)
5437 (list 'font-lock-fontified t
))
5438 (compose-region (match-beginning 0) (match-end 1)
5444 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
5445 "Fontify string S like in Org-mode"
5448 (let ((org-odd-levels-only odd-levels
))
5450 (font-lock-fontify-buffer)
5456 (defun org-get-level-face (n)
5457 "Get the right face for match N in font-lock matching of headlines."
5458 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
5459 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
5460 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
5462 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
5464 (t (if org-level-color-stars-only nil org-f
))))
5466 (defun org-get-todo-face (kwd)
5467 "Get the right face for a TODO keyword KWD.
5468 If KWD is a number, get the corresponding match group."
5469 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5470 (or (org-face-from-face-or-color
5471 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
5472 (and (member kwd org-done-keywords
) 'org-done
)
5475 (defun org-face-from-face-or-color (context inherit face-or-color
)
5476 "Create a face list that inherits INHERIT, but sets the foreground color.
5477 When FACE-OR-COLOR is not a string, just return it."
5478 (if (stringp face-or-color
)
5479 (list :inherit inherit
5480 (cdr (assoc context org-faces-easy-properties
))
5484 (defun org-font-lock-add-tag-faces (limit)
5485 "Add the special tag faces."
5486 (when (and org-tag-faces org-tags-special-faces-re
)
5487 (while (re-search-forward org-tags-special-faces-re limit t
)
5488 (add-text-properties (match-beginning 1) (match-end 1)
5489 (list 'face
(org-get-tag-face 1)
5490 'font-lock-fontified t
))
5491 (backward-char 1))))
5493 (defun org-font-lock-add-priority-faces (limit)
5494 "Add the special priority faces."
5495 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
5496 (add-text-properties
5497 (match-beginning 0) (match-end 0)
5498 (list 'face
(or (org-face-from-face-or-color
5499 'priority
'org-special-keyword
5500 (cdr (assoc (char-after (match-beginning 1))
5501 org-priority-faces
)))
5502 'org-special-keyword
)
5503 'font-lock-fontified t
))))
5505 (defun org-get-tag-face (kwd)
5506 "Get the right face for a TODO keyword KWD.
5507 If KWD is a number, get the corresponding match group."
5508 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5509 (or (org-face-from-face-or-color
5510 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
5513 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
5514 "Remove fontification and activation overlays from links."
5515 (font-lock-default-unfontify-region beg end
)
5516 (let* ((buffer-undo-list t
)
5517 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
5518 (inhibit-modification-hooks t
)
5519 deactivate-mark buffer-file-name buffer-file-truename
)
5520 (decompose-region beg end
)
5521 (remove-text-properties
5524 ;; also remove line-prefix and wrap-prefix properties
5525 '(mouse-face t keymap t org-linked-text t
5526 invisible t intangible t
5527 line-prefix t wrap-prefix t
5528 org-no-flyspell t org-emphasis t
)
5529 '(mouse-face t keymap t org-linked-text t
5530 invisible t intangible t
5531 org-no-flyspell t org-emphasis t
)))
5532 (org-remove-font-lock-display-properties beg end
)))
5534 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
5535 ((raise 0.3) (height 0.7))
5538 "Display properties for showing superscripts and subscripts.")
5540 (defun org-remove-font-lock-display-properties (beg end
)
5541 "Remove specific display properties that have been added by font lock.
5542 The will remove the raise properties that are used to show superscripts
5546 (setq next
(next-single-property-change beg
'display nil end
)
5547 prop
(get-text-property beg
'display
))
5548 (if (member prop org-script-display
)
5549 (put-text-property beg next
'display nil
))
5552 (defun org-raise-scripts (limit)
5553 "Add raise properties to sub/superscripts."
5554 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
5555 (if (re-search-forward
5556 (if (eq org-use-sub-superscripts t
)
5557 org-match-substring-regexp
5558 org-match-substring-with-braces-regexp
)
5560 (let* ((pos (point)) table-p comment-p
5561 (mpos (match-beginning 3))
5562 (emph-p (get-text-property mpos
'org-emphasis
))
5563 (link-p (get-text-property mpos
'mouse-face
))
5564 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
5565 (goto-char (point-at-bol))
5566 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
5567 comment-p
(org-looking-at-p "[ \t]*#"))
5569 (if (or comment-p emph-p link-p keyw-p
)
5571 (put-text-property (match-beginning 3) (match-end 0)
5573 (if (equal (char-after (match-beginning 2)) ?^
)
5574 (nth (if table-p
3 1) org-script-display
)
5575 (nth (if table-p
2 0) org-script-display
)))
5576 (add-text-properties (match-beginning 2) (match-end 2)
5578 'org-dwidth t
'org-dwidth-n
1))
5579 (if (and (eq (char-after (match-beginning 3)) ?
{)
5580 (eq (char-before (match-end 3)) ?
}))
5582 (add-text-properties
5583 (match-beginning 3) (1+ (match-beginning 3))
5584 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
5585 (add-text-properties
5586 (1- (match-end 3)) (match-end 3)
5587 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
5590 ;;;; Visibility cycling, including org-goto and indirect buffer
5594 (defvar org-cycle-global-status nil
)
5595 (make-variable-buffer-local 'org-cycle-global-status
)
5596 (defvar org-cycle-subtree-status nil
)
5597 (make-variable-buffer-local 'org-cycle-subtree-status
)
5601 (defvar org-inlinetask-min-level
)
5603 (defun org-cycle (&optional arg
)
5604 "TAB-action and visibility cycling for Org-mode.
5606 This is the command invoked in Org-mode by the TAB key. Its main purpose
5607 is outline visibility cycling, but it also invokes other actions
5608 in special contexts.
5610 - When this function is called with a prefix argument, rotate the entire
5611 buffer through 3 states (global cycling)
5612 1. OVERVIEW: Show only top-level headlines.
5613 2. CONTENTS: Show all headlines of all levels, but no body text.
5614 3. SHOW ALL: Show everything.
5615 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5616 determined by the variable `org-startup-folded', and by any VISIBILITY
5617 properties in the buffer.
5618 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5619 including any drawers.
5621 - When inside a table, re-align the table and move to the next field.
5623 - When point is at the beginning of a headline, rotate the subtree started
5624 by this line through 3 different states (local cycling)
5625 1. FOLDED: Only the main headline is shown.
5626 2. CHILDREN: The main headline and the direct children are shown.
5627 From this state, you can move to one of the children
5628 and zoom in further.
5629 3. SUBTREE: Show the entire subtree, including body text.
5630 If there is no subtree, switch directly from CHILDREN to FOLDED.
5632 - When point is at the beginning of an empty headline and the variable
5633 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5634 of the headline by demoting and promoting it to likely levels. This
5635 speeds up creation document structure by presing TAB once or several
5636 times right after creating a new headline.
5638 - When there is a numeric prefix, go up to a heading with level ARG, do
5639 a `show-subtree' and return to the previous cursor position. If ARG
5640 is negative, go up that many levels.
5642 - When point is not at the beginning of a headline, execute the global
5643 binding for TAB, which is re-indenting the line. See the option
5644 `org-cycle-emulate-tab' for details.
5646 - Special case: if point is at the beginning of the buffer and there is
5647 no headline in line 1, this function will act as if called with prefix arg.
5648 But only if also the variable `org-cycle-global-at-bob' is t."
5650 (org-load-modules-maybe)
5651 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
5652 (and org-cycle-level-after-item
/entry-creation
5653 (or (org-cycle-level)
5654 (org-cycle-item-indentation))))
5656 (or org-cycle-max-level
5657 (and (boundp 'org-inlinetask-min-level
)
5658 org-inlinetask-min-level
5659 (1- org-inlinetask-min-level
))))
5660 (nstars (and limit-level
5661 (if org-odd-levels-only
5662 (and limit-level
(1- (* limit-level
2)))
5666 ((not (org-mode-p)) outline-regexp
)
5667 ((or (eq org-cycle-include-plain-lists
'integrate
)
5668 (and org-cycle-include-plain-lists
(org-at-item-p)))
5670 (if nstars
(format "\\{1,%d\\}" nstars
) "+")
5671 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5672 (t (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ ")))))
5673 (bob-special (and org-cycle-global-at-bob
(bobp)
5674 (not (looking-at outline-regexp
))))
5677 (delq 'org-optimize-window-after-visibility-change
5678 (copy-sequence org-cycle-hook
))
5682 (if (or bob-special
(equal arg
'(4)))
5683 ;; special case: use global cycling
5689 (org-set-startup-visibility)
5690 (message "Startup visibility, plus VISIBILITY properties"))
5694 (message "Entire buffer visible, including drawers"))
5696 ((org-at-table-p 'any
)
5697 ;; Enter the table or move to the next field in the table
5698 (if (org-at-table.el-p
)
5699 (message "Use C-c ' to edit table.el tables")
5700 (if arg
(org-table-edit-field t
)
5701 (org-table-justify-field-maybe)
5702 (call-interactively 'org-table-next-field
))))
5704 ((run-hook-with-args-until-success
5705 'org-tab-after-check-for-table-hook
))
5707 ((eq arg t
) ;; Global cycling
5708 (org-cycle-internal-global))
5710 ((and org-drawers org-drawer-regexp
5712 (beginning-of-line 1)
5713 (looking-at org-drawer-regexp
)))
5714 ;; Toggle block visibility
5716 (not (get-char-property (match-end 0) 'invisible
))))
5719 ;; Show-subtree, ARG levels up from here.
5721 (org-back-to-heading)
5722 (outline-up-heading (if (< arg
0) (- arg
)
5723 (- (funcall outline-level
) arg
)))
5724 (org-show-subtree)))
5726 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp
))
5727 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
5729 (org-cycle-internal-local))
5731 ;; TAB emulation and template completion
5732 (buffer-read-only (org-back-to-heading))
5734 ((run-hook-with-args-until-success
5735 'org-tab-after-check-for-cycling-hook
))
5737 ((org-try-structure-completion))
5739 ((org-try-cdlatex-tab))
5741 ((run-hook-with-args-until-success
5742 'org-tab-before-tab-emulation-hook
))
5744 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
5746 (not (looking-at outline-regexp
))))
5747 (call-interactively (global-key-binding "\t")))
5749 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
5750 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5751 (or (and (eq org-cycle-emulate-tab
'white
)
5752 (= (match-end 0) (point-at-eol)))
5753 (and (eq org-cycle-emulate-tab
'whitestart
)
5754 (>= (match-end 0) pos
))))
5756 (eq org-cycle-emulate-tab t
))
5757 (call-interactively (global-key-binding "\t")))
5760 (org-back-to-heading)
5763 (defun org-cycle-internal-global ()
5764 "Do the global cycling action."
5766 ((and (eq last-command this-command
)
5767 (eq org-cycle-global-status
'overview
))
5768 ;; We just created the overview - now do table of contents
5769 ;; This can be slow in very large buffers, so indicate action
5770 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
5771 (message "CONTENTS...")
5773 (message "CONTENTS...done")
5774 (setq org-cycle-global-status
'contents
)
5775 (run-hook-with-args 'org-cycle-hook
'contents
))
5777 ((and (eq last-command this-command
)
5778 (eq org-cycle-global-status
'contents
))
5779 ;; We just showed the table of contents - now show everything
5780 (run-hook-with-args 'org-pre-cycle-hook
'all
)
5782 (message "SHOW ALL")
5783 (setq org-cycle-global-status
'all
)
5784 (run-hook-with-args 'org-cycle-hook
'all
))
5787 ;; Default action: go to overview
5788 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
5790 (message "OVERVIEW")
5791 (setq org-cycle-global-status
'overview
)
5792 (run-hook-with-args 'org-cycle-hook
'overview
))))
5794 (defun org-cycle-internal-local ()
5795 "Do the local cycling action."
5796 (org-back-to-heading)
5797 (let ((goal-column 0) eoh eol eos level has-children children-skipped
)
5798 ;; First, some boundaries
5800 (org-back-to-heading)
5801 (setq level
(funcall outline-level
))
5803 (beginning-of-line 2)
5804 (if (or (featurep 'xemacs
) (<= emacs-major-version
21))
5805 ; XEmacs does not have `next-single-char-property-change'
5806 ; I'm not sure about Emacs 21.
5807 (while (and (not (eobp)) ;; this is like `next-line'
5808 (get-char-property (1- (point)) 'invisible
))
5809 (beginning-of-line 2))
5810 (while (and (not (eobp)) ;; this is like `next-line'
5811 (get-char-property (1- (point)) 'invisible
))
5812 (goto-char (next-single-char-property-change (point) 'invisible
))
5813 (and (eolp) (beginning-of-line 2))))
5815 (outline-end-of-heading) (setq eoh
(point))
5817 (outline-next-heading)
5818 (setq has-children
(and (org-at-heading-p t
)
5819 (> (funcall outline-level
) level
))))
5820 (org-end-of-subtree t
)
5822 (skip-chars-forward " \t\n")
5823 (beginning-of-line 1) ; in case this is an item
5825 (setq eos
(if (eobp) (point) (1- (point)))))
5826 ;; Find out what to do next and set `this-command'
5829 ;; Nothing is hidden behind this heading
5830 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
5831 (message "EMPTY ENTRY")
5832 (setq org-cycle-subtree-status nil
)
5835 (outline-next-heading)
5836 (if (org-invisible-p) (org-flag-heading nil
))))
5837 ((and (or (>= eol eos
)
5838 (not (string-match "\\S-" (buffer-substring eol eos
))))
5840 (not (setq children-skipped
5841 org-cycle-skip-children-state-if-no-children
))))
5842 ;; Entire subtree is hidden in one line: children view
5843 (run-hook-with-args 'org-pre-cycle-hook
'children
)
5846 (message "CHILDREN")
5849 (outline-next-heading)
5850 (if (org-invisible-p) (org-flag-heading nil
)))
5851 (setq org-cycle-subtree-status
'children
)
5852 (run-hook-with-args 'org-cycle-hook
'children
))
5853 ((or children-skipped
5854 (and (eq last-command this-command
)
5855 (eq org-cycle-subtree-status
'children
)))
5856 ;; We just showed the children, or no children are there,
5857 ;; now show everything.
5858 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
5860 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
5861 (setq org-cycle-subtree-status
'subtree
)
5862 (run-hook-with-args 'org-cycle-hook
'subtree
))
5864 ;; Default action: hide the subtree.
5865 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
5868 (setq org-cycle-subtree-status
'folded
)
5869 (run-hook-with-args 'org-cycle-hook
'folded
)))))
5872 (defun org-global-cycle (&optional arg
)
5873 "Cycle the global visibility. For details see `org-cycle'.
5874 With C-u prefix arg, switch to startup visibility.
5875 With a numeric prefix, show all headlines up to that level."
5877 (let ((org-cycle-include-plain-lists
5878 (if (org-mode-p) org-cycle-include-plain-lists nil
)))
5882 (hide-sublevels arg
)
5883 (setq org-cycle-global-status
'contents
))
5885 (org-set-startup-visibility)
5886 (message "Startup visibility, plus VISIBILITY properties."))
5888 (org-cycle '(4))))))
5890 (defun org-set-startup-visibility ()
5891 "Set the visibility required by startup options and properties."
5893 ((eq org-startup-folded t
)
5895 ((eq org-startup-folded
'content
)
5896 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
5897 (org-cycle '(4)) (org-cycle '(4)))))
5898 (unless (eq org-startup-folded
'showeverything
)
5899 (if org-hide-block-startup
(org-hide-block-all))
5900 (org-set-visibility-according-to-property 'no-cleanup
)
5901 (org-cycle-hide-archived-subtrees 'all
)
5902 (org-cycle-hide-drawers 'all
)
5903 (org-cycle-show-empty-lines t
)))
5905 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
5906 "Switch subtree visibilities according to :VISIBILITY: property."
5908 (let (org-show-entry-below state
)
5910 (goto-char (point-min))
5911 (while (re-search-forward
5912 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5914 (setq state
(match-string 1))
5916 (org-back-to-heading t
)
5920 ((equal state
'("fold" "folded"))
5922 ((equal state
"children")
5923 (org-show-hidden-entry)
5925 ((equal state
"content")
5928 (org-narrow-to-subtree)
5930 ((member state
'("all" "showall"))
5933 (org-cycle-hide-archived-subtrees 'all
)
5934 (org-cycle-hide-drawers 'all
)
5935 (org-cycle-show-empty-lines 'all
)))))
5937 (defun org-overview ()
5938 "Switch to overview mode, showing only top-level headlines.
5939 Really, this shows all headlines with level equal or greater than the level
5940 of the first headline in the buffer. This is important, because if the
5941 first headline is not level one, then (hide-sublevels 1) gives confusing
5944 (let ((level (save-excursion
5945 (goto-char (point-min))
5946 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
5948 (goto-char (match-beginning 0))
5949 (funcall outline-level
))))))
5950 (and level
(hide-sublevels level
))))
5952 (defun org-content (&optional arg
)
5953 "Show all headlines in the buffer, like a table of contents.
5954 With numerical argument N, show content up to level N."
5957 ;; Visit all headings and show their offspring
5958 (and (integerp arg
) (org-overview))
5959 (goto-char (point-max))
5961 (while (and (progn (condition-case nil
5962 (outline-previous-visible-heading 1)
5963 (error (goto-char (point-min))))
5965 (looking-at outline-regexp
))
5967 (show-children (1- arg
))
5969 (if (bobp) (throw 'exit nil
))))))
5972 (defun org-optimize-window-after-visibility-change (state)
5973 "Adjust the window after a change in outline visibility.
5974 This function is the default value of the hook `org-cycle-hook'."
5975 (when (get-buffer-window (current-buffer))
5977 ((eq state
'content
) nil
)
5978 ((eq state
'all
) nil
)
5979 ((eq state
'folded
) nil
)
5980 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
5981 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
5983 (defun org-remove-empty-overlays-at (pos)
5984 "Remove outline overlays that do not contain non-white stuff."
5987 (and (eq 'outline
(overlay-get o
'invisible
))
5988 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
5990 (delete-overlay o
)))
5993 (defun org-clean-visibility-after-subtree-move ()
5994 "Fix visibility issues after moving a subtree."
5995 ;; First, find a reasonable region to look at:
5996 ;; Start two siblings above, end three below
5997 (let* ((beg (save-excursion
5998 (and (org-get-last-sibling)
5999 (org-get-last-sibling))
6001 (end (save-excursion
6002 (and (org-get-next-sibling)
6003 (org-get-next-sibling)
6004 (org-get-next-sibling))
6005 (if (org-at-heading-p)
6008 (level (looking-at "\\*+"))
6009 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6012 (narrow-to-region beg end
)
6014 ;; Properly fold already folded siblings
6015 (goto-char (point-min))
6016 (while (re-search-forward re nil t
)
6017 (if (and (not (org-invisible-p))
6019 (goto-char (point-at-eol)) (org-invisible-p)))
6021 (org-cycle-show-empty-lines 'overview
)
6022 (org-cycle-hide-drawers 'overview
)))))
6024 (defun org-cycle-show-empty-lines (state)
6025 "Show empty lines above all visible headlines.
6026 The region to be covered depends on STATE when called through
6027 `org-cycle-hook'. Lisp program can use t for STATE to get the
6028 entire buffer covered. Note that an empty line is only shown if there
6029 are at least `org-cycle-separator-lines' empty lines before the headline."
6030 (when (not (= org-cycle-separator-lines
0))
6032 (let* ((n (abs org-cycle-separator-lines
))
6034 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6035 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6036 (t (let ((ns (number-to-string (- n
2))))
6037 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6038 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6041 ((memq state
'(overview contents t
))
6042 (setq beg
(point-min) end
(point-max)))
6043 ((memq state
'(children folded
))
6044 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6045 (beginning-of-line 2)
6049 (while (re-search-forward re end t
)
6050 (unless (get-char-property (match-end 1) 'invisible
)
6051 (setq e
(match-end 1))
6052 (if (< org-cycle-separator-lines
0)
6053 (setq b
(save-excursion
6054 (goto-char (match-beginning 0))
6055 (org-back-over-empty-lines)
6057 (goto-char (max (point-min) (1- (point))))
6061 (setq b
(match-beginning 1)))
6062 (outline-flag-region b e nil
)))))))
6063 ;; Never hide empty lines at the end of the file.
6065 (goto-char (point-max))
6066 (outline-previous-heading)
6067 (outline-end-of-heading)
6068 (if (and (looking-at "[ \t\n]+")
6069 (= (match-end 0) (point-max)))
6070 (outline-flag-region (point) (match-end 0) nil
))))
6072 (defun org-show-empty-lines-in-parent ()
6073 "Move to the parent and re-show empty lines before visible headlines."
6075 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6076 (org-cycle-show-empty-lines context
))))
6078 (defun org-files-list ()
6079 "Return `org-agenda-files' list, plus all open org-mode files.
6080 This is useful for operations that need to scan all of a user's
6081 open and agenda-wise Org files."
6082 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6083 (dolist (buf (buffer-list))
6084 (with-current-buffer buf
6085 (if (and (eq major-mode
'org-mode
) (buffer-file-name))
6086 (let ((file (expand-file-name (buffer-file-name))))
6087 (unless (member file files
)
6088 (push file files
))))))
6091 (defsubst org-entry-beginning-position
()
6092 "Return the beginning position of the current entry."
6093 (save-excursion (outline-back-to-heading t
) (point)))
6095 (defsubst org-entry-end-position
()
6096 "Return the end position of the current entry."
6097 (save-excursion (outline-next-heading) (point)))
6099 (defun org-cycle-hide-drawers (state)
6100 "Re-hide all drawers after a visibility state change."
6101 (when (and (org-mode-p)
6102 (not (memq state
'(overview folded contents
))))
6104 (let* ((globalp (memq state
'(contents all
)))
6105 (beg (if globalp
(point-min) (point)))
6106 (end (if globalp
(point-max)
6107 (if (eq state
'children
)
6108 (save-excursion (outline-next-heading) (point))
6109 (org-end-of-subtree t
)))))
6111 (while (re-search-forward org-drawer-regexp end t
)
6112 (org-flag-drawer t
))))))
6114 (defun org-flag-drawer (flag)
6116 (beginning-of-line 1)
6117 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6118 (let ((b (match-end 0))
6119 (outline-regexp org-outline-regexp
))
6120 (if (re-search-forward
6122 (save-excursion (outline-next-heading) (point)) t
)
6123 (outline-flag-region b
(point-at-eol) flag
)
6124 (error ":END: line missing at position %s" b
))))))
6126 (defun org-subtree-end-visible-p ()
6127 "Is the end of the current subtree visible?"
6128 (pos-visible-in-window-p
6129 (save-excursion (org-end-of-subtree t
) (point))))
6131 (defun org-first-headline-recenter (&optional N
)
6132 "Move cursor to the first headline and recenter the headline.
6133 Optional argument N means put the headline into the Nth line of the window."
6134 (goto-char (point-min))
6135 (when (re-search-forward (concat "^\\(" outline-regexp
"\\)") nil t
)
6137 (recenter (prefix-numeric-value N
))))
6139 ;;; Saving and restoring visibility
6141 (defun org-outline-overlay-data (&optional use-markers
)
6142 "Return a list of the locations of all outline overlays.
6143 The are overlays with the `invisible' property value `outline'.
6144 The return valus is a list of cons cells, with start and stop
6145 positions for each overlay.
6146 If USE-MARKERS is set, return the positions as markers."
6153 (when (eq (overlay-get o
'invisible
) 'outline
)
6154 (setq beg
(overlay-start o
)
6155 end
(overlay-end o
))
6156 (and beg end
(> end beg
)
6158 (cons (move-marker (make-marker) beg
)
6159 (move-marker (make-marker) end
))
6161 (overlays-in (point-min) (point-max))))))))
6163 (defun org-set-outline-overlay-data (data)
6164 "Create visibility overlays for all positions in DATA.
6165 DATA should have been made by `org-outline-overlay-data'."
6172 (setq o
(make-overlay (car c
) (cdr c
)))
6173 (overlay-put o
'invisible
'outline
))
6176 (defmacro org-save-outline-visibility
(use-markers &rest body
)
6177 "Save and restore outline visibility around BODY.
6178 If USE-MARKERS is non-nil, use markers for the positions.
6179 This means that the buffer may change while running BODY,
6180 but it also means that the buffer should stay alive
6181 during the operation, because otherwise all these markers will
6183 (declare (indent 1))
6184 `(let ((data (org-outline-overlay-data ,use-markers
)))
6188 (org-set-outline-overlay-data data
))
6191 (and (markerp (car c
)) (move-marker (car c
) nil
))
6192 (and (markerp (cdr c
)) (move-marker (cdr c
) nil
)))
6196 ;;; Folding of blocks
6198 (defconst org-block-regexp
6200 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
6201 "Regular expression for hiding blocks.")
6203 (defvar org-hide-block-overlays nil
6204 "Overlays hiding blocks.")
6205 (make-variable-buffer-local 'org-hide-block-overlays
)
6207 (defun org-block-map (function &optional start end
)
6208 "Call func at the head of all source blocks in the current
6209 buffer. Optional arguments START and END can be used to limit
6211 (let ((start (or start
(point-min)))
6212 (end (or end
(point-max))))
6215 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6218 (goto-char (match-beginning 0))
6219 (funcall function
)))))))
6221 (defun org-hide-block-toggle-all ()
6222 "Toggle the visibility of all blocks in the current buffer."
6223 (org-block-map #'org-hide-block-toggle
))
6225 (defun org-hide-block-all ()
6226 "Fold all blocks in the current buffer."
6228 (org-show-block-all)
6229 (org-block-map #'org-hide-block-toggle-maybe
))
6231 (defun org-show-block-all ()
6232 "Unfold all blocks in the current buffer."
6234 (mapc 'delete-overlay org-hide-block-overlays
)
6235 (setq org-hide-block-overlays nil
))
6237 (defun org-hide-block-toggle-maybe ()
6238 "Toggle visibility of block at point."
6240 (let ((case-fold-search t
))
6242 (beginning-of-line 1)
6243 (looking-at org-block-regexp
))
6244 (progn (org-hide-block-toggle)
6245 t
) ;; to signal that we took action
6246 nil
))) ;; to signal that we did not
6248 (defun org-hide-block-toggle (&optional force
)
6249 "Toggle the visibility of the current block."
6253 (if (re-search-forward org-block-regexp nil t
)
6254 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6255 (end (match-end 0)) ;; end of entire body
6257 (if (memq t
(mapcar (lambda (overlay)
6258 (eq (overlay-get overlay
'invisible
)
6260 (overlays-at start
)))
6261 (if (or (not force
) (eq force
'off
))
6263 (when (member ov org-hide-block-overlays
)
6264 (setq org-hide-block-overlays
6265 (delq ov org-hide-block-overlays
)))
6266 (when (eq (overlay-get ov
'invisible
)
6268 (delete-overlay ov
)))
6269 (overlays-at start
)))
6270 (setq ov
(make-overlay start end
))
6271 (overlay-put ov
'invisible
'org-hide-block
)
6272 ;; make the block accessible to isearch
6274 ov
'isearch-open-invisible
6276 (when (member ov org-hide-block-overlays
)
6277 (setq org-hide-block-overlays
6278 (delq ov org-hide-block-overlays
)))
6279 (when (eq (overlay-get ov
'invisible
)
6281 (delete-overlay ov
))))
6282 (push ov org-hide-block-overlays
)))
6283 (error "Not looking at a source block"))))
6285 ;; org-tab-after-check-for-cycling-hook
6286 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6287 ;; Remove overlays when changing major mode
6288 (add-hook 'org-mode-hook
6289 (lambda () (org-add-hook 'change-major-mode-hook
6290 'org-show-block-all
'append
'local
)))
6294 (defvar org-goto-window-configuration nil
)
6295 (defvar org-goto-marker nil
)
6296 (defvar org-goto-map
6297 (let ((map (make-sparse-keymap)))
6298 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6299 (while (setq cmd
(pop cmds
))
6300 (substitute-key-definition cmd cmd map global-map
)))
6301 (suppress-keymap map
)
6302 (org-defkey map
"\C-m" 'org-goto-ret
)
6303 (org-defkey map
[(return)] 'org-goto-ret
)
6304 (org-defkey map
[(left)] 'org-goto-left
)
6305 (org-defkey map
[(right)] 'org-goto-right
)
6306 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6307 (org-defkey map
"\C-i" 'org-cycle
)
6308 (org-defkey map
[(tab)] 'org-cycle
)
6309 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6310 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6311 (if org-goto-auto-isearch
6312 (if (fboundp 'define-key-after
)
6313 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6315 (org-defkey map "q" 'org-goto-quit)
6316 (org-defkey map "n" 'outline-next-visible-heading)
6317 (org-defkey map "p" 'outline-previous-visible-heading)
6318 (org-defkey map "f" 'outline-forward-same-level)
6319 (org-defkey map "b" 'outline-backward-same-level)
6320 (org-defkey map "u" 'outline-up-heading))
6321 (org-defkey map "/" 'org-occur)
6322 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6323 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6324 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6325 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6326 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6329 (defconst org-goto-help
6330 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6331 RET=jump to location [Q]uit and return to previous location
6332 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6334 (defvar org-goto-start-pos) ; dynamically scoped parameter
6336 ;; FIXME: Docstring does not mention both interfaces
6337 (defun org-goto (&optional alternative-interface)
6338 "Look up a different location in the current file, keeping current visibility.
6340 When you want look-up or go to a different location in a document, the
6341 fastest way is often to fold the entire buffer and then dive into the tree.
6342 This method has the disadvantage, that the previous location will be folded,
6343 which may not be what you want.
6345 This command works around this by showing a copy of the current buffer
6346 in an indirect buffer, in overview mode. You can dive into the tree in
6347 that copy, use org-occur and incremental search to find a location.
6348 When pressing RET or `Q', the command returns to the original buffer in
6349 which the visibility is still unchanged. After RET is will also jump to
6350 the location selected in the indirect buffer and expose the
6351 the headline hierarchy above."
6353 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6354 (org-refile-use-outline-path t)
6355 (org-refile-target-verify-function nil)
6357 (if (not alternative-interface)
6359 (if (eq org-goto-interface 'outline)
6360 'outline-path-completion
6362 (org-goto-start-pos (point))
6364 (if (eq interface 'outline)
6365 (car (org-get-location (current-buffer) org-goto-help))
6366 (nth 3 (org-refile-get-location "Goto: ")))))
6369 (org-mark-ring-push org-goto-start-pos)
6370 (goto-char selected-point)
6371 (if (or (org-invisible-p) (org-invisible-p2))
6372 (org-show-context 'org-goto)))
6375 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6376 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6377 (defvar org-goto-local-auto-isearch-map) ; defined below
6379 (defun org-get-location (buf help)
6380 "Let the user select a location in the Org-mode buffer BUF.
6381 This function uses a recursive edit. It returns the selected position
6383 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6384 (isearch-hide-immediately nil)
6385 (isearch-search-fun-function
6386 (lambda () 'org-goto-local-search-headings))
6387 (org-goto-selected-point org-goto-exit-command)
6389 (special-display-buffer-names nil)
6390 (special-display-regexps nil)
6391 (special-display-function nil))
6393 (save-window-excursion
6394 (delete-other-windows)
6395 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6398 (make-indirect-buffer (current-buffer) "*org-goto*")
6399 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6400 (with-output-to-temp-buffer "*Help*"
6402 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6403 (setq buffer-read-only nil)
6404 (let ((org-startup-truncated t)
6405 (org-startup-folded nil)
6406 (org-startup-align-all-tables nil))
6409 (setq buffer-read-only t)
6410 (if (and (boundp 'org-goto-start-pos)
6411 (integer-or-marker-p org-goto-start-pos))
6412 (let ((org-show-hierarchy-above t)
6413 (org-show-siblings t)
6414 (org-show-following-heading t))
6415 (goto-char org-goto-start-pos)
6416 (and (org-invisible-p) (org-show-context)))
6417 (goto-char (point-min)))
6418 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6419 (message "Select location and press RET")
6420 (use-local-map org-goto-map)
6423 (kill-buffer "*org-goto*")
6424 (cons org-goto-selected-point org-goto-exit-command)))
6426 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6427 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6428 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6429 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6431 (defun org-goto-local-search-headings (string bound noerror)
6432 "Search and make sure that any matches are in headlines."
6434 (while (if isearch-forward
6435 (search-forward string bound noerror)
6436 (search-backward string bound noerror))
6437 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6438 (and (member :headline context)
6439 (not (member :tags context))))
6440 (throw 'return (point))))))
6442 (defun org-goto-local-auto-isearch ()
6445 (goto-char (point-min))
6446 (let ((keys (this-command-keys)))
6447 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6449 (isearch-process-search-char (string-to-char keys)))))
6451 (defun org-goto-ret (&optional arg)
6452 "Finish `org-goto' by going to the new location."
6454 (setq org-goto-selected-point (point)
6455 org-goto-exit-command 'return)
6458 (defun org-goto-left ()
6459 "Finish `org-goto' by going to the new location."
6461 (if (org-on-heading-p)
6463 (beginning-of-line 1)
6464 (setq org-goto-selected-point (point)
6465 org-goto-exit-command 'left)
6467 (error "Not on a heading")))
6469 (defun org-goto-right ()
6470 "Finish `org-goto' by going to the new location."
6472 (if (org-on-heading-p)
6474 (setq org-goto-selected-point (point)
6475 org-goto-exit-command 'right)
6477 (error "Not on a heading")))
6479 (defun org-goto-quit ()
6480 "Finish `org-goto' without cursor motion."
6482 (setq org-goto-selected-point nil)
6483 (setq org-goto-exit-command 'quit)
6486 ;;; Indirect buffer display of subtrees
6488 (defvar org-indirect-dedicated-frame nil
6489 "This is the frame being used for indirect tree display.")
6490 (defvar org-last-indirect-buffer nil)
6492 (defun org-tree-to-indirect-buffer (&optional arg)
6493 "Create indirect buffer and narrow it to current subtree.
6494 With numerical prefix ARG, go up to this level and then take that tree.
6495 If ARG is negative, go up that many levels.
6496 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6497 indirect buffer previously made with this command, to avoid proliferation of
6498 indirect buffers. However, when you call the command with a `C-u' prefix, or
6499 when `org-indirect-buffer-display' is `new-frame', the last buffer
6500 is kept so that you can work with several indirect buffers at the same time.
6501 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6502 requests that a new frame be made for the new buffer, so that the dedicated
6503 frame is not changed."
6505 (let ((cbuf (current-buffer))
6506 (cwin (selected-window))
6508 beg end level heading ibuf)
6510 (org-back-to-heading t)
6512 (setq level (org-outline-level))
6513 (if (< arg 0) (setq arg (+ level arg)))
6514 (while (> (setq level (org-outline-level)) arg)
6515 (outline-up-heading 1 t)))
6517 heading (org-get-heading))
6518 (org-end-of-subtree t t)
6519 (if (org-on-heading-p) (backward-char 1))
6521 (if (and (buffer-live-p org-last-indirect-buffer)
6522 (not (eq org-indirect-buffer-display 'new-frame))
6524 (kill-buffer org-last-indirect-buffer))
6525 (setq ibuf (org-get-indirect-buffer cbuf)
6526 org-last-indirect-buffer ibuf)
6528 ((or (eq org-indirect-buffer-display 'new-frame)
6529 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6530 (select-frame (make-frame))
6531 (delete-other-windows)
6532 (switch-to-buffer ibuf)
6533 (org-set-frame-title heading))
6534 ((eq org-indirect-buffer-display 'dedicated-frame)
6536 (select-frame (or (and org-indirect-dedicated-frame
6537 (frame-live-p org-indirect-dedicated-frame)
6538 org-indirect-dedicated-frame)
6539 (setq org-indirect-dedicated-frame (make-frame)))))
6540 (delete-other-windows)
6541 (switch-to-buffer ibuf)
6542 (org-set-frame-title (concat "Indirect: " heading)))
6543 ((eq org-indirect-buffer-display 'current-window)
6544 (switch-to-buffer ibuf))
6545 ((eq org-indirect-buffer-display 'other-window)
6546 (pop-to-buffer ibuf))
6547 (t (error "Invalid value")))
6548 (if (featurep 'xemacs)
6549 (save-excursion (org-mode) (turn-on-font-lock)))
6550 (narrow-to-region beg end)
6553 (and (window-live-p cwin) (select-window cwin))))
6555 (defun org-get-indirect-buffer (&optional buffer)
6556 (setq buffer (or buffer (current-buffer)))
6557 (let ((n 1) (base (buffer-name buffer)) bname)
6558 (while (buffer-live-p
6559 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6562 (make-indirect-buffer buffer bname 'clone)
6563 (error (make-indirect-buffer buffer bname)))))
6565 (defun org-set-frame-title (title)
6566 "Set the title of the current frame to the string TITLE."
6567 ;; FIXME: how to name a single frame in XEmacs???
6568 (unless (featurep 'xemacs)
6569 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6571 ;;;; Structure editing
6573 ;;; Inserting headlines
6575 (defun org-previous-line-empty-p ()
6578 (or (beginning-of-line 0) t)
6580 (looking-at "[ \t]*$")))))
6582 (defun org-insert-heading (&optional force-heading invisible-ok)
6583 "Insert a new heading or item with same depth at point.
6584 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6585 If point is at the beginning of a headline, insert a sibling before the
6586 current headline. If point is not at the beginning, do not split the line,
6587 but create the new headline after the current line.
6588 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6589 This is important for non-interactive uses of the command."
6591 (if (or (= (buffer-size) 0)
6592 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6593 (org-on-heading-p))))
6594 (not (org-in-item-p))))
6596 (when (or force-heading (not (org-insert-item)))
6597 (let* ((empty-line-p nil)
6598 (head (save-excursion
6601 (org-back-to-heading invisible-ok)
6602 (setq empty-line-p (org-previous-line-empty-p))
6605 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6606 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6607 pos hide-previous previous-pos)
6609 ((and (org-on-heading-p) (bolp)
6611 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6612 ;; insert before the current line
6613 (open-line (if blank 2 1)))
6615 (not org-insert-heading-respect-content)
6618 (backward-char 1) (not (org-invisible-p)))))
6619 ;; insert right here
6622 ;; somewhere in the line
6624 (setq previous-pos (point-at-bol))
6626 (setq hide-previous (org-invisible-p)))
6627 (and org-insert-heading-respect-content (org-show-subtree))
6629 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6632 (goto-char (point-at-bol))
6633 (and (looking-at org-complex-heading-regexp)
6634 (> p (match-beginning 4)))))))
6637 (org-insert-heading-respect-content
6638 (org-end-of-subtree nil t)
6639 (or (bolp) (newline))
6640 (or (org-previous-line-empty-p)
6641 (and blank (newline)))
6647 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6648 (setq tags (and (match-end 2) (match-string 2)))
6650 (delete-region (match-beginning 1) (match-end 1)))
6651 (setq pos (point-at-bol))
6652 (or split (end-of-line 1))
6653 (delete-horizontal-space)
6654 (if (string-match "\\`\\*+\\'"
6655 (buffer-substring (point-at-bol) (point)))
6657 (newline (if blank 2 1))
6663 (org-set-tags nil 'align))))
6665 (or split (end-of-line 1))
6666 (newline (if blank 2 1)))))))
6667 (insert head) (just-one-space)
6670 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6671 (when (and org-insert-heading-respect-content hide-previous)
6673 (goto-char previous-pos)
6675 (run-hooks 'org-insert-heading-hook)))))
6677 (defun org-get-heading (&optional no-tags)
6678 "Return the heading of the current entry, without the stars."
6680 (org-back-to-heading t)
6683 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6684 "\\*+[ \t]+\\([^\r\n]*\\)"))
6685 (match-string 1) "")))
6687 (defun org-heading-components ()
6688 "Return the components of the current heading.
6689 This is a list with the following elements:
6690 - the level as an integer
6691 - the reduced level, different if `org-odd-levels-only' is set.
6692 - the TODO keyword, or nil
6693 - the priority character, like ?A, or nil if no priority is given
6694 - the headline text itself, or the tags string if no headline text
6695 - the tags string, or nil."
6697 (org-back-to-heading t)
6698 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6699 (list (length (match-string 1))
6700 (org-reduced-level (length (match-string 1)))
6701 (org-match-string-no-properties 2)
6702 (and (match-end 3) (aref (match-string 3) 2))
6703 (org-match-string-no-properties 4)
6704 (org-match-string-no-properties 5)))))
6706 (defun org-get-entry ()
6707 "Get the entry text, after heading, entire subtree."
6709 (org-back-to-heading t)
6710 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6712 (defun org-insert-heading-after-current ()
6713 "Insert a new heading with same level as current, after current subtree."
6715 (org-back-to-heading)
6716 (org-insert-heading)
6717 (org-move-subtree-down)
6720 (defun org-insert-heading-respect-content ()
6722 (let ((org-insert-heading-respect-content t))
6723 (org-insert-heading t)))
6725 (defun org-insert-todo-heading-respect-content (&optional force-state)
6727 (let ((org-insert-heading-respect-content t))
6728 (org-insert-todo-heading force-state t)))
6730 (defun org-insert-todo-heading (arg &optional force-heading)
6731 "Insert a new heading with the same level and TODO state as current heading.
6732 If the heading has no TODO state, or if the state is DONE, use the first
6733 state (TODO by default). Also with prefix arg, force first state."
6735 (when (or force-heading (not (org-insert-item 'checkbox)))
6736 (org-insert-heading force-heading)
6738 (org-back-to-heading)
6739 (outline-previous-heading)
6740 (looking-at org-todo-line-regexp))
6744 (not (match-beginning 2))
6745 (member (match-string 2) org-done-keywords))
6746 (car org-todo-keywords-1)
6750 (run-hook-with-args-until-success
6751 'org-todo-get-default-hook new-mark-x nil)
6753 (beginning-of-line 1)
6754 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6755 (if org-treat-insert-todo-heading-as-state-change
6757 (insert new-mark " "))))
6758 (when org-provide-todo-statistics
6759 (org-update-parent-todo-statistics))))
6761 (defun org-insert-subheading (arg)
6762 "Insert a new subheading and demote it.
6763 Works for outline headings and for plain lists alike."
6765 (org-insert-heading arg)
6767 ((org-on-heading-p) (org-do-demote))
6768 ((org-at-item-p) (org-indent-item 1))))
6770 (defun org-insert-todo-subheading (arg)
6771 "Insert a new subheading with TODO keyword or checkbox and demote it.
6772 Works for outline headings and for plain lists alike."
6774 (org-insert-todo-heading arg)
6776 ((org-on-heading-p) (org-do-demote))
6777 ((org-at-item-p) (org-indent-item 1))))
6779 ;;; Promotion and Demotion
6781 (defvar org-after-demote-entry-hook nil
6782 "Hook run after an entry has been demoted.
6783 The cursor will be at the beginning of the entry.
6784 When a subtree is being demoted, the hook will be called for each node.")
6786 (defvar org-after-promote-entry-hook nil
6787 "Hook run after an entry has been promoted.
6788 The cursor will be at the beginning of the entry.
6789 When a subtree is being promoted, the hook will be called for each node.")
6791 (defun org-promote-subtree ()
6792 "Promote the entire subtree.
6793 See also `org-promote'."
6796 (org-map-tree 'org-promote))
6797 (org-fix-position-after-promote))
6799 (defun org-demote-subtree ()
6800 "Demote the entire subtree. See `org-demote'.
6801 See also `org-promote'."
6804 (org-map-tree 'org-demote))
6805 (org-fix-position-after-promote))
6808 (defun org-do-promote ()
6809 "Promote the current heading higher up the tree.
6810 If the region is active in `transient-mark-mode', promote all headings
6814 (if (org-region-active-p)
6815 (org-map-region 'org-promote (region-beginning) (region-end))
6817 (org-fix-position-after-promote))
6819 (defun org-do-demote ()
6820 "Demote the current heading lower down the tree.
6821 If the region is active in `transient-mark-mode', demote all headings
6825 (if (org-region-active-p)
6826 (org-map-region 'org-demote (region-beginning) (region-end))
6828 (org-fix-position-after-promote))
6830 (defun org-fix-position-after-promote ()
6831 "Make sure that after pro/demotion cursor position is right."
6832 (let ((pos (point)))
6833 (when (save-excursion
6834 (beginning-of-line 1)
6835 (looking-at org-todo-line-regexp)
6836 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6837 (cond ((eobp) (insert " "))
6838 ((eolp) (insert " "))
6839 ((equal (char-after) ?\ ) (forward-char 1))))))
6841 (defun org-current-level ()
6842 "Return the level of the current entry, or nil if before the first headline.
6843 The level is the number of stars at the beginning of the headline."
6847 (org-back-to-heading t)
6848 (funcall outline-level))
6851 (defun org-get-previous-line-level ()
6852 "Return the outline depth of the last headline before the current line.
6853 Returns 0 for the first headline in the buffer, and nil if before the
6855 (let ((current-level (org-current-level))
6856 (prev-level (when (> (line-number-at-pos) 1)
6858 (beginning-of-line 0)
6859 (org-current-level)))))
6860 (cond ((null current-level) nil) ; Before first headline
6861 ((null prev-level) 0) ; At first headline
6864 (defun org-reduced-level (l)
6865 "Compute the effective level of a heading.
6866 This takes into account the setting of `org-odd-levels-only'."
6867 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6869 (defun org-level-increment ()
6870 "Return the number of stars that will be added or removed at a
6871 time to headlines when structure editing, based on the value of
6872 `org-odd-levels-only'."
6873 (if org-odd-levels-only 2 1))
6875 (defun org-get-valid-level (level &optional change)
6876 "Rectify a level change under the influence of `org-odd-levels-only'
6877 LEVEL is a current level, CHANGE is by how much the level should be
6878 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6879 even level numbers will become the next higher odd number."
6880 (if org-odd-levels-only
6881 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6882 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6883 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6884 (max 1 (+ level (or change 0)))))
6886 (if (boundp 'define-obsolete-function-alias)
6887 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6888 (define-obsolete-function-alias 'org-get-legal-level
6889 'org-get-valid-level)
6890 (define-obsolete-function-alias 'org-get-legal-level
6891 'org-get-valid-level "23.1")))
6893 (defun org-promote ()
6894 "Promote the current heading higher up the tree.
6895 If the region is active in `transient-mark-mode', promote all headings
6897 (org-back-to-heading t)
6898 (let* ((level (save-match-data (funcall outline-level)))
6899 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6900 (diff (abs (- level (length up-head) -1))))
6901 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6902 (replace-match up-head nil t)
6903 ;; Fixup tag positioning
6904 (and org-auto-align-tags (org-set-tags nil t))
6905 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6906 (run-hooks 'org-after-promote-entry-hook)))
6908 (defun org-demote ()
6909 "Demote the current heading lower down the tree.
6910 If the region is active in `transient-mark-mode', demote all headings
6912 (org-back-to-heading t)
6913 (let* ((level (save-match-data (funcall outline-level)))
6914 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6915 (diff (abs (- level (length down-head) -1))))
6916 (replace-match down-head nil t)
6917 ;; Fixup tag positioning
6918 (and org-auto-align-tags (org-set-tags nil t))
6919 (if org-adapt-indentation (org-fixup-indentation diff))
6920 (run-hooks 'org-after-demote-entry-hook)))
6922 (defun org-cycle-level ()
6923 "Cycle the level of an empty headline through possible states.
6924 This goes first to child, then to parent, level, then up the hierarchy.
6925 After top level, it switches back to sibling level."
6927 (let ((org-adapt-indentation nil))
6928 (when (org-point-at-end-of-empty-headline)
6929 (setq this-command 'org-cycle-level) ; Only needed for caching
6930 (let ((cur-level (org-current-level))
6931 (prev-level (org-get-previous-line-level)))
6933 ;; If first headline in file, promote to top-level.
6935 (loop repeat (/ (- cur-level 1) (org-level-increment))
6936 do (org-do-promote)))
6937 ;; If same level as prev, demote one.
6938 ((= prev-level cur-level)
6940 ;; If parent is top-level, promote to top level if not already.
6942 (loop repeat (/ (- cur-level 1) (org-level-increment))
6943 do (org-do-promote)))
6944 ;; If top-level, return to prev-level.
6946 (loop repeat (/ (- prev-level 1) (org-level-increment))
6947 do (org-do-demote)))
6948 ;; If less than prev-level, promote one.
6949 ((< cur-level prev-level)
6951 ;; If deeper than prev-level, promote until higher than
6953 ((> cur-level prev-level)
6954 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6955 do (org-do-promote))))
6958 (defun org-map-tree (fun)
6959 "Call FUN for every heading underneath the current one."
6960 (org-back-to-heading)
6961 (let ((level (funcall outline-level)))
6965 (outline-next-heading)
6966 (> (funcall outline-level) level))
6970 (defun org-map-region (fun beg end)
6971 "Call FUN for every heading between BEG and END."
6972 (let ((org-ignore-region t))
6974 (setq end (copy-marker end))
6976 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6980 (outline-next-heading)
6985 (defun org-fixup-indentation (diff)
6986 "Change the indentation in the current entry by DIFF
6987 However, if any line in the current entry has no indentation, or if it
6988 would end up with no indentation after the change, nothing at all is done."
6990 (let ((end (save-excursion (outline-next-heading)
6992 (prohibit (if (> diff 0)
6994 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6996 (unless (save-excursion (end-of-line 1)
6997 (re-search-forward prohibit end t))
6998 (while (and (< (point) end)
6999 (re-search-forward "^[ \t]+" end t))
7000 (goto-char (match-end 0))
7001 (setq col (current-column))
7002 (if (< diff 0) (replace-match ""))
7003 (org-indent-to-column (+ diff col))))
7004 (move-marker end nil))))
7006 (defun org-convert-to-odd-levels ()
7007 "Convert an org-mode file with all levels allowed to one with odd levels.
7008 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7011 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7012 (let ((outline-regexp org-outline-regexp)
7013 (outline-level 'org-outline-level)
7014 (org-odd-levels-only nil) n)
7016 (goto-char (point-min))
7017 (while (re-search-forward "^\\*\\*+ " nil t)
7018 (setq n (- (length (match-string 0)) 2))
7019 (while (>= (setq n (1- n)) 0)
7021 (end-of-line 1))))))
7023 (defun org-convert-to-oddeven-levels ()
7024 "Convert an org-mode file with only odd levels to one with odd and even levels.
7025 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
7026 section with an even level, conversion would destroy the structure of the file. An error
7027 is signaled in this case."
7029 (goto-char (point-min))
7030 ;; First check if there are no even levels
7031 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7032 (org-show-context t)
7033 (error "Not all levels are odd in this file. Conversion not possible"))
7034 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7035 (let ((outline-regexp org-outline-regexp)
7036 (outline-level 'org-outline-level)
7037 (org-odd-levels-only nil) n)
7039 (goto-char (point-min))
7040 (while (re-search-forward "^\\*\\*+ " nil t)
7041 (setq n (/ (1- (length (match-string 0))) 2))
7042 (while (>= (setq n (1- n)) 0)
7044 (end-of-line 1))))))
7046 (defun org-tr-level (n)
7047 "Make N odd if required."
7048 (if org-odd-levels-only (1+ (/ n 2)) n))
7050 ;;; Vertical tree motion, cutting and pasting of subtrees
7052 (defun org-move-subtree-up (&optional arg)
7053 "Move the current subtree up past ARG headlines of the same level."
7055 (org-move-subtree-down (- (prefix-numeric-value arg))))
7057 (defun org-move-subtree-down (&optional arg)
7058 "Move the current subtree down past ARG headlines of the same level."
7060 (setq arg (prefix-numeric-value arg))
7061 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7062 'org-get-last-sibling))
7063 (ins-point (make-marker))
7065 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7067 (org-back-to-heading)
7070 (setq ne-beg (org-back-over-empty-lines))
7073 (save-excursion (outline-end-of-heading)
7074 (setq folded (org-invisible-p)))
7075 (outline-end-of-subtree))
7076 (outline-next-heading)
7077 (setq ne-end (org-back-over-empty-lines))
7080 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7081 ;; include less whitespace
7084 (forward-line (- ne-beg ne-end))
7085 (setq beg (point))))
7086 ;; Find insertion point, with error handling
7088 (or (and (funcall movfunc) (looking-at outline-regexp))
7089 (progn (goto-char beg0)
7090 (error "Cannot move past superior level or buffer limit")))
7091 (setq cnt (1- cnt)))
7093 ;; Moving forward - still need to move over subtree
7094 (progn (org-end-of-subtree t t)
7096 (org-back-over-empty-lines)
7097 (or (bolp) (newline)))))
7098 (setq ne-ins (org-back-over-empty-lines))
7099 (move-marker ins-point (point))
7100 (setq txt (buffer-substring beg end))
7101 (org-save-markers-in-region beg end)
7102 (delete-region beg end)
7103 (org-remove-empty-overlays-at beg)
7104 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7105 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7106 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7107 (let ((bbb (point)))
7108 (insert-before-markers txt)
7109 (org-reinstall-markers-in-region bbb)
7110 (move-marker ins-point bbb))
7111 (or (bolp) (insert "\n"))
7112 (setq ins-end (point))
7113 (goto-char ins-point)
7114 (org-skip-whitespace)
7115 (when (and (< arg 0)
7116 (org-first-sibling-p)
7118 ;; Move whitespace back to beginning
7121 (let ((kill-whole-line t))
7122 (kill-line (- ne-ins ne-beg)) (point)))
7123 (insert (make-string (- ne-ins ne-beg) ?\n)))
7124 (move-marker ins-point nil)
7129 (org-cycle-hide-drawers 'children))
7130 (org-clean-visibility-after-subtree-move)))
7132 (defvar org-subtree-clip ""
7133 "Clipboard for cut and paste of subtrees.
7134 This is actually only a copy of the kill, because we use the normal kill
7135 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7137 (defvar org-subtree-clip-folded nil
7138 "Was the last copied subtree folded?
7139 This is used to fold the tree back after pasting.")
7141 (defun org-cut-subtree (&optional n)
7142 "Cut the current subtree into the clipboard.
7143 With prefix arg N, cut this many sequential subtrees.
7144 This is a short-hand for marking the subtree and then cutting it."
7146 (org-copy-subtree n 'cut))
7148 (defun org-copy-subtree (&optional n cut force-store-markers)
7149 "Cut the current subtree into the clipboard.
7150 With prefix arg N, cut this many sequential subtrees.
7151 This is a short-hand for marking the subtree and then copying it.
7152 If CUT is non-nil, actually cut the subtree.
7153 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7154 of some markers in the region, even if CUT is non-nil. This is
7155 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7157 (let (beg end folded (beg0 (point)))
7159 (org-back-to-heading nil) ; take what looks like a subtree
7160 (org-back-to-heading t)) ; take what is really there
7161 (org-back-over-empty-lines)
7163 (skip-chars-forward " \t\r\n")
7165 (save-excursion (outline-end-of-heading)
7166 (setq folded (org-invisible-p)))
7168 (org-forward-same-level (1- n) t)
7170 (org-end-of-subtree t t))
7171 (org-back-over-empty-lines)
7175 (setq org-subtree-clip-folded folded)
7176 (when (or cut force-store-markers)
7177 (org-save-markers-in-region beg end))
7178 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7179 (setq org-subtree-clip (current-kill 0))
7180 (message "%s: Subtree(s) with %d characters"
7181 (if cut "Cut" "Copied")
7182 (length org-subtree-clip)))))
7184 (defun org-paste-subtree (&optional level tree for-yank)
7185 "Paste the clipboard as a subtree, with modification of headline level.
7186 The entire subtree is promoted or demoted in order to match a new headline
7189 If the cursor is at the beginning of a headline, the same level as
7190 that headline is used to paste the tree
7192 If not, the new level is derived from the *visible* headings
7193 before and after the insertion point, and taken to be the inferior headline
7194 level of the two. So if the previous visible heading is level 3 and the
7195 next is level 4 (or vice versa), level 4 will be used for insertion.
7196 This makes sure that the subtree remains an independent subtree and does
7197 not swallow low level entries.
7199 You can also force a different level, either by using a numeric prefix
7200 argument, or by inserting the heading marker by hand. For example, if the
7201 cursor is after \"*****\", then the tree will be shifted to level 5.
7203 If optional TREE is given, use this text instead of the kill ring.
7205 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7206 move back over whitespace before inserting, and move point to the end of
7207 the inserted text when done."
7209 (setq tree (or tree (and kill-ring (current-kill 0))))
7210 (unless (org-kill-is-subtree-p tree)
7212 (substitute-command-keys
7213 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7214 (let* ((visp (not (org-invisible-p)))
7216 (^re (concat "^\\(" outline-regexp "\\)"))
7217 (re (concat "\\(" outline-regexp "\\)"))
7218 (^re_ (concat "\\(\\*+\\)[ \t]*"))
7220 (old-level (if (string-match ^re txt)
7221 (- (match-end 0) (match-beginning 0) 1)
7223 (force-level (cond (level (prefix-numeric-value level))
7224 ((and (looking-at "[ \t]*$")
7226 ^re_ (buffer-substring
7227 (point-at-bol) (point))))
7228 (- (match-end 1) (match-beginning 1)))
7230 (looking-at org-outline-regexp))
7231 (- (match-end 0) (point) 1))
7233 (previous-level (save-excursion
7236 (outline-previous-visible-heading 1)
7238 (- (match-end 0) (match-beginning 0) 1)
7241 (next-level (save-excursion
7244 (or (looking-at outline-regexp)
7245 (outline-next-visible-heading 1))
7247 (- (match-end 0) (match-beginning 0) 1)
7250 (new-level (or force-level (max previous-level next-level)))
7251 (shift (if (or (= old-level -1)
7253 (= old-level new-level))
7255 (- new-level old-level)))
7256 (delta (if (> shift 0) -1 1))
7257 (func (if (> shift 0) 'org-demote 'org-promote))
7258 (org-odd-levels-only nil)
7260 ;; Remove the forced level indicator
7262 (delete-region (point-at-bol) (point)))
7264 (beginning-of-line 1)
7265 (unless for-yank (org-back-over-empty-lines))
7267 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7268 (insert-before-markers txt)
7269 (unless (string-match "\n\\'" txt) (insert "\n"))
7270 (setq newend (point))
7271 (org-reinstall-markers-in-region beg)
7274 (skip-chars-forward " \t\n\r")
7276 (if (and (org-invisible-p) visp)
7277 (save-excursion (outline-show-heading)))
7278 ;; Shift if necessary
7281 (narrow-to-region beg end)
7282 (while (not (= shift 0))
7283 (org-map-region func (point-min) (point-max))
7284 (setq shift (+ delta shift)))
7285 (goto-char (point-min))
7286 (setq newend (point-max))))
7287 (when (or (interactive-p) for-yank)
7288 (message "Clipboard pasted as level %d subtree" new-level))
7289 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7291 (eq org-subtree-clip (current-kill 0))
7292 org-subtree-clip-folded)
7293 ;; The tree was folded before it was killed/copied
7295 (and for-yank (goto-char newend))))
7297 (defun org-kill-is-subtree-p (&optional txt)
7298 "Check if the current kill is an outline subtree, or a set of trees.
7299 Returns nil if kill does not start with a headline, or if the first
7300 headline level is not the largest headline level in the tree.
7301 So this will actually accept several entries of equal levels as well,
7302 which is OK for `org-paste-subtree'.
7303 If optional TXT is given, check this string instead of the current kill."
7304 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7305 (start-level (and kill
7306 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
7307 org-outline-regexp "\\)")
7309 (- (match-end 2) (match-beginning 2) 1)))
7310 (re (concat "^" org-outline-regexp))
7311 (start (1+ (or (match-beginning 2) -1))))
7312 (if (not start-level)
7314 nil) ;; does not even start with a heading
7316 (while (setq start (string-match re kill (1+ start)))
7317 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7321 (defvar org-markers-to-move nil
7322 "Markers that should be moved with a cut-and-paste operation.
7323 Those markers are stored together with their positions relative to
7324 the start of the region.")
7326 (defun org-save-markers-in-region (beg end)
7327 "Check markers in region.
7328 If these markers are between BEG and END, record their position relative
7329 to BEG, so that after moving the block of text, we can put the markers back
7331 This function gets called just before an entry or tree gets cut from the
7332 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7333 called immediately, to move the markers with the entries."
7334 (setq org-markers-to-move nil)
7335 (when (featurep 'org-clock)
7336 (org-clock-save-markers-for-cut-and-paste beg end))
7337 (when (featurep 'org-agenda)
7338 (org-agenda-save-markers-for-cut-and-paste beg end)))
7340 (defun org-check-and-save-marker (marker beg end)
7341 "Check if MARKER is between BEG and END.
7342 If yes, remember the marker and the distance to BEG."
7343 (when (and (marker-buffer marker)
7344 (equal (marker-buffer marker) (current-buffer)))
7345 (if (and (>= marker beg) (< marker end))
7346 (push (cons marker (- marker beg)) org-markers-to-move))))
7348 (defun org-reinstall-markers-in-region (beg)
7349 "Move all remembered markers to their position relative to BEG."
7351 (move-marker (car x) (+ beg (cdr x))))
7352 org-markers-to-move)
7353 (setq org-markers-to-move nil))
7355 (defun org-narrow-to-subtree ()
7356 "Narrow buffer to the current subtree."
7361 (progn (org-back-to-heading t) (point))
7362 (progn (org-end-of-subtree t t)
7363 (if (org-on-heading-p) (backward-char 1))
7367 (defvar org-property-drawer-re))
7369 (defun org-clone-subtree-with-time-shift (n &optional shift)
7370 "Clone the task (subtree) at point N times.
7371 The clones will be inserted as siblings.
7373 In interactive use, the user will be prompted for the number of
7374 clones to be produced, and for a time SHIFT, which may be a
7375 repeater as used in time stamps, for example `+3d'.
7377 When a valid repeater is given and the entry contains any time
7378 stamps, the clones will become a sequence in time, with time
7379 stamps in the subtree shifted for each clone produced. If SHIFT
7380 is nil or the empty string, time stamps will be left alone. The
7381 ID property of the original subtree is removed.
7383 If the original subtree did contain time stamps with a repeater,
7384 the following will happen:
7385 - the repeater will be removed in each clone
7386 - an additional clone will be produced, with the current, unshifted
7387 date(s) in the entry.
7388 - the original entry will be placed *after* all the clones, with
7390 - the start days in the repeater in the original entry will be shifted
7391 to past the last clone.
7392 I this way you can spell out a number of instances of a repeating task,
7393 and still retain the repeater to cover future instances of the task."
7394 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7395 (let (beg end template task idprop
7396 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7397 (if (not (and (integerp n) (> n 0)))
7398 (error "Invalid number of replications %s" n))
7399 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7400 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7402 (error "Invalid shift specification %s" shift))
7404 (setq shift-n (string-to-number (match-string 1 shift))
7405 shift-what (cdr (assoc (match-string 2 shift)
7406 '(("d" . day) ("w" . week)
7407 ("m" . month) ("y" . year))))))
7408 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7409 (setq nmin 1 nmax n)
7410 (org-back-to-heading t)
7412 (setq idprop (org-entry-get nil "ID"))
7413 (org-end-of-subtree t t)
7414 (or (bolp) (insert "\n"))
7416 (setq template (buffer-substring beg end))
7418 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7419 (delete-region beg end)
7421 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7423 (loop for n from nmin to nmax do
7428 (goto-char (point-min))
7429 (and idprop (if org-clone-delete-id
7430 (org-entry-delete nil "ID")
7431 (org-id-get-create t)))
7432 (while (re-search-forward org-property-drawer-re nil t)
7433 (org-remove-empty-drawer-at "PROPERTIES" (point)))
7434 (goto-char (point-min))
7436 (while (re-search-forward org-ts-regexp-both nil t)
7437 (org-timestamp-change (* n shift-n) shift-what))
7438 (unless (= n n-no-remove)
7439 (goto-char (point-min))
7440 (while (re-search-forward org-ts-regexp nil t)
7442 (goto-char (match-beginning 0))
7443 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7444 (delete-region (match-beginning 1) (match-end 1)))))))
7445 (setq task (buffer-string)))
7451 (defun org-sort (with-case)
7452 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7453 Optional argument WITH-CASE means sort case-sensitively.
7454 With a double prefix argument, also remove duplicate entries."
7456 (if (org-at-table-p)
7457 (org-call-with-arg 'org-table-sort-lines with-case)
7458 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7460 (defun org-sort-remove-invisible (s)
7461 (remove-text-properties 0 (length s) org-rm-props s)
7462 (while (string-match org-bracket-link-regexp s)
7463 (setq s (replace-match (if (match-end 2)
7465 (match-string 1 s)) t t s)))
7468 (defvar org-priority-regexp) ; defined later in the file
7470 (defvar org-after-sorting-entries-or-items-hook nil
7471 "Hook that is run after a bunch of entries or items have been sorted.
7472 When children are sorted, the cursor is in the parent line when this
7473 hook gets called. When a region or a plain list is sorted, the cursor
7474 will be in the first entry of the sorted region/list.")
7476 (defun org-sort-entries-or-items
7477 (&optional with-case sorting-type getkey-func compare-func property)
7478 "Sort entries on a certain level of an outline tree, or plain list items.
7479 If there is an active region, the entries in the region are sorted.
7480 Else, if the cursor is before the first entry, sort the top-level items.
7481 Else, the children of the entry at point are sorted.
7482 If the cursor is at the first item in a plain list, the list items will be
7485 Sorting can be alphabetically, numerically, by date/time as given by
7486 a time stamp, by a property or by priority.
7488 The command prompts for the sorting type unless it has been given to the
7489 function through the SORTING-TYPE argument, which needs to be a character,
7490 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7491 precise meaning of each character:
7493 n Numerically, by converting the beginning of the entry/item to a number.
7494 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7495 t By date/time, either the first active time stamp in the entry, or, if
7496 none exist, by the first inactive one.
7497 In items, only the first line will be checked.
7498 s By the scheduled date/time.
7499 d By deadline date/time.
7500 c By creation time, which is assumed to be the first inactive time stamp
7501 at the beginning of a line.
7502 p By priority according to the cookie.
7503 r By the value of a property.
7505 Capital letters will reverse the sort order.
7507 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7508 called with point at the beginning of the record. It must return either
7509 a string or a number that should serve as the sorting key for that record.
7511 Comparing entries ignores case by default. However, with an optional argument
7512 WITH-CASE, the sorting considers case as well."
7514 (let ((case-func (if with-case 'identity 'downcase))
7515 start beg end stars re re2
7516 txt what tmp plain-list-p)
7517 ;; Find beginning and end of region to sort
7519 ((org-region-active-p)
7520 ;; we will sort the region
7521 (setq end (region-end)
7523 (goto-char (region-beginning))
7524 (if (not (org-on-heading-p)) (outline-next-heading))
7525 (setq start (point)))
7527 ;; we will sort this plain list
7528 (org-beginning-of-item-list) (setq start (point))
7529 (org-end-of-item-list)
7530 (or (bolp) (insert "\n"))
7533 (setq plain-list-p t
7535 ((or (org-on-heading-p)
7536 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7537 ;; we will sort the children of the current headline
7538 (org-back-to-heading)
7540 end (progn (org-end-of-subtree t t)
7541 (or (bolp) (insert "\n"))
7542 (org-back-over-empty-lines)
7547 (outline-next-heading))
7549 ;; we will sort the top-level entries in this file
7550 (goto-char (point-min))
7551 (or (org-on-heading-p) (outline-next-heading))
7552 (setq start (point))
7553 (goto-char (point-max))
7554 (beginning-of-line 1)
7555 (when (looking-at ".*?\\S-")
7556 ;; File ends in a non-white line
7559 (setq end (point-max))
7560 (setq what "top-level")
7565 (if (>= beg end) (error "Nothing to sort"))
7567 (unless plain-list-p
7568 (looking-at "\\(\\*+\\)")
7569 (setq stars (match-string 1)
7570 re (concat "^" (regexp-quote stars) " +")
7571 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7572 txt (buffer-substring beg end))
7573 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7574 (if (and (not (equal stars "*")) (string-match re2 txt))
7575 (error "Region to sort contains a level above the first entry")))
7577 (unless sorting-type
7580 "Sort %s: [a]lpha [n]umeric [t]ime
[f]unc A/N/T/F means reversed:"
7581 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7582 [t]ime [s]cheduled [d]eadline [c]reated
7583 A/N/T/S/D/C/P/O/F means reversed:")
7585 (setq sorting-type (read-char-exclusive))
7587 (and (= (downcase sorting-type) ?f)
7589 (org-icompleting-read "Sort using function: "
7590 obarray 'fboundp t nil nil))
7591 (setq getkey-func (intern getkey-func)))
7593 (and (= (downcase sorting-type) ?r)
7595 (org-icompleting-read "Property: "
7596 (mapcar 'list (org-buffer-property-keys t))
7599 (message "Sorting entries...")
7602 (narrow-to-region start end)
7604 (let ((dcst (downcase sorting-type))
7605 (case-fold-search nil)
7606 (now (current-time)))
7608 (/= dcst sorting-type)
7609 ;; This function moves to the beginning character of the "record" to
7613 (if (org-at-item-p) t (goto-char (point-max))))
7615 (if (re-search-forward re nil t)
7616 (goto-char (match-beginning 0))
7617 (goto-char (point-max)))))
7618 ;; This function moves to the last character of the "record" being
7625 (outline-forward-same-level 1)
7627 (goto-char (point-max)))))))
7629 ;; This function returns the value that gets sorted against.
7632 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7635 (string-to-number (buffer-substring (match-end 0)
7638 (buffer-substring (match-end 0) (point-at-eol)))
7640 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7641 (re-search-forward org-ts-regexp-both
7643 (org-time-string-to-seconds (match-string 0))
7644 (org-float-time now)))
7648 (setq tmp (funcall getkey-func))
7649 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7651 (error "Invalid key function `%s'" getkey-func)))
7652 (t (error "Invalid sorting type `%c'" sorting-type)))))
7656 (if (looking-at org-complex-heading-regexp)
7657 (string-to-number (match-string 4))
7660 (if (looking-at org-complex-heading-regexp)
7661 (funcall case-func (match-string 4))
7664 (let ((end (save-excursion (outline-next-heading) (point))))
7665 (if (or (re-search-forward org-ts-regexp end t)
7666 (re-search-forward org-ts-regexp-both end t))
7667 (org-time-string-to-seconds (match-string 0))
7668 (org-float-time now))))
7670 (let ((end (save-excursion (outline-next-heading) (point))))
7671 (if (re-search-forward
7672 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7674 (org-time-string-to-seconds (match-string 0))
7675 (org-float-time now))))
7677 (let ((end (save-excursion (outline-next-heading) (point))))
7678 (if (re-search-forward org-scheduled-time-regexp end t)
7679 (org-time-string-to-seconds (match-string 1))
7680 (org-float-time now))))
7682 (let ((end (save-excursion (outline-next-heading) (point))))
7683 (if (re-search-forward org-deadline-time-regexp end t)
7684 (org-time-string-to-seconds (match-string 1))
7685 (org-float-time now))))
7687 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7688 (string-to-char (match-string 2))
7689 org-default-priority))
7691 (or (org-entry-get nil property) ""))
7693 (if (looking-at org-complex-heading-regexp)
7694 (- 9999 (length (member (match-string 2)
7695 org-todo-keywords-1)))))
7699 (setq tmp (funcall getkey-func))
7700 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7702 (error "Invalid key function `%s'" getkey-func)))
7703 (t (error "Invalid sorting type `%c'" sorting-type)))))
7706 ((= dcst ?a) 'string<)
7707 ((= dcst ?f) compare-func)
7708 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7710 (run-hooks 'org-after-sorting-entries-or-items-hook)
7711 (message "Sorting entries...done")))
7713 (defun org-do-sort (table what &optional with-case sorting-type)
7714 "Sort TABLE of WHAT according to SORTING-TYPE.
7715 The user will be prompted for the SORTING-TYPE if the call to this
7716 function does not specify it. WHAT is only for the prompt, to indicate
7717 what is being sorted. The sorting key will be extracted from
7718 the car of the elements of the table.
7719 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7720 (unless sorting-type
7722 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A
/N
/T means reversed
:"
7724 (setq sorting-type (read-char-exclusive)))
7725 (let ((dcst (downcase sorting-type))
7726 extractfun comparefun)
7727 ;; Define the appropriate functions
7730 (setq extractfun 'string-to-number
7731 comparefun (if (= dcst sorting-type) '< '>)))
7733 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7734 (lambda(x) (downcase (org-sort-remove-invisible x))))
7735 comparefun (if (= dcst sorting-type)
7737 (lambda (a b) (and (not (string< a b))
7738 (not (string= a b)))))))
7742 (if (or (string-match org-ts-regexp x)
7743 (string-match org-ts-regexp-both x))
7745 (org-time-string-to-time (match-string 0 x)))
7747 comparefun (if (= dcst sorting-type) '< '>)))
7748 (t (error "Invalid sorting type
`%c
'" sorting-type)))
7750 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7752 (lambda (a b) (funcall comparefun (car a) (car b))))))
7755 ;;; The orgstruct minor mode
7757 ;; Define a minor mode which can be used in other modes in order to
7758 ;; integrate the org-mode structure editing commands.
7760 ;; This is really a hack, because the org-mode structure commands use
7761 ;; keys which normally belong to the major mode. Here is how it
7762 ;; works: The minor mode defines all the keys necessary to operate the
7763 ;; structure commands, but wraps the commands into a function which
7764 ;; tests if the cursor is currently at a headline or a plain list
7765 ;; item. If that is the case, the structure command is used,
7766 ;; temporarily setting many Org-mode variables like regular
7767 ;; expressions for filling etc. However, when any of those keys is
7768 ;; used at a different location, function uses `key-binding' to look
7769 ;; up if the key has an associated command in another currently active
7770 ;; keymap (minor modes, major mode, global), and executes that
7771 ;; command. There might be problems if any of the keys is otherwise
7772 ;; used as a prefix key.
7774 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7775 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7776 ;; addresses this by checking explicitly for both bindings.
7778 (defvar orgstruct-mode-map (make-sparse-keymap)
7779 "Keymap for the minor
`orgstruct-mode
'.
")
7781 (defvar org-local-vars nil
7782 "List of local variables
, for use by
`orgstruct-mode
'")
7785 (define-minor-mode orgstruct-mode
7786 "Toggle the minor mode
`orgstruct-mode
'.
7787 This mode is for using Org-mode structure commands in other
7788 modes. The following keys behave as if Org-mode were active
, if
7789 the cursor is on a headline
, or on a plain list item
(both as
7790 defined by Org-mode
).
7792 M-up Move entry
/item up
7793 M-down Move entry
/item down
7796 M-S-up Move entry
/item up
7797 M-S-down Move entry
/item down
7798 M-S-left Promote subtree
7799 M-S-right Demote subtree
7800 M-q Fill paragraph and items like in Org-mode
7802 C-c - Cycle list bullet
7803 TAB Cycle item visibility
7804 M-RET Insert new heading
/item
7805 S-M-RET Insert new TODO heading
/ Checkbox item
7806 C-c C-c Set tags
/ toggle checkbox
"
7807 nil " OrgStruct
" nil
7808 (org-load-modules-maybe)
7809 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7812 (defun turn-on-orgstruct ()
7813 "Unconditionally turn on
`orgstruct-mode
'.
"
7816 (defun orgstruct++-mode (&optional arg)
7817 "Toggle
`orgstruct-mode
', the enhanced version of it.
7818 In addition to setting orgstruct-mode
, this also exports all indentation
7819 and autofilling variables from org-mode into the buffer. It will also
7820 recognize item context in multiline items.
7821 Note that turning off orgstruct-mode will
*not
* remove the
7822 indentation
/paragraph settings. This can only be done by refreshing the
7823 major mode
, for example with
\\[normal-mode
].
"
7825 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7833 "^
\\(paragraph-\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7834 (symbol-name (car x)))
7835 (setq var (car x) val (nth 1 x))
7836 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7838 (org-set-local 'orgstruct-is-++ t))))
7840 (defvar orgstruct-is-++ nil
7841 "Is orgstruct-mode in
++ version in the current-buffer?
")
7842 (make-variable-buffer-local 'orgstruct-is-++)
7845 (defun turn-on-orgstruct++ ()
7846 "Unconditionally turn on
`orgstruct
++-mode
'.
"
7847 (orgstruct++-mode 1))
7849 (defun orgstruct-error ()
7850 "Error when there is no default binding for a structure key.
"
7852 (error "This key has no function outside structure elements
"))
7854 (defun orgstruct-setup ()
7855 "Setup orgstruct keymaps.
"
7859 '([(meta up)] org-metaup)
7860 '([(meta down)] org-metadown)
7861 '([(meta left)] org-metaleft)
7862 '([(meta right)] org-metaright)
7863 '([(meta shift up)] org-shiftmetaup)
7864 '([(meta shift down)] org-shiftmetadown)
7865 '([(meta shift left)] org-shiftmetaleft)
7866 '([(meta shift right)] org-shiftmetaright)
7867 '([?\e (up)] org-metaup)
7868 '([?\e (down)] org-metadown)
7869 '([?\e (left)] org-metaleft)
7870 '([?\e (right)] org-metaright)
7871 '([?\e (shift up)] org-shiftmetaup)
7872 '([?\e (shift down)] org-shiftmetadown)
7873 '([?\e (shift left)] org-shiftmetaleft)
7874 '([?\e (shift right)] org-shiftmetaright)
7875 '([(shift up)] org-shiftup)
7876 '([(shift down)] org-shiftdown)
7877 '([(shift left)] org-shiftleft)
7878 '([(shift right)] org-shiftright)
7879 '("\C-c\C-c
" org-ctrl-c-ctrl-c)
7880 '("\M-q
" fill-paragraph)
7882 '("\C-c-
" org-cycle-list-bullet)))
7884 (while (setq elt (pop bindings))
7885 (setq nfunc (1+ nfunc))
7886 (setq key (org-key (car elt))
7888 cmd (orgstruct-make-binding fun nfunc key))
7889 (org-defkey orgstruct-mode-map key cmd))
7891 ;; Special treatment needed for TAB and RET
7892 (org-defkey orgstruct-mode-map [(tab)]
7893 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i
"))
7894 (org-defkey orgstruct-mode-map "\C-i
"
7895 (orgstruct-make-binding 'org-cycle 103 "\C-i
" [(tab)]))
7897 (org-defkey orgstruct-mode-map "\M-\C-m
"
7898 (orgstruct-make-binding 'org-insert-heading 105
7899 "\M-\C-m
" [(meta return)]))
7900 (org-defkey orgstruct-mode-map [(meta return)]
7901 (orgstruct-make-binding 'org-insert-heading 106
7902 [(meta return)] "\M-\C-m
"))
7904 (org-defkey orgstruct-mode-map [(shift meta return)]
7905 (orgstruct-make-binding 'org-insert-todo-heading 107
7906 [(meta return)] "\M-\C-m
"))
7908 (org-defkey orgstruct-mode-map "\e\C-m
"
7909 (orgstruct-make-binding 'org-insert-heading 108
7910 "\e\C-m
" [?\e (return)]))
7911 (org-defkey orgstruct-mode-map [?\e (return)]
7912 (orgstruct-make-binding 'org-insert-heading 109
7913 [?\e (return)] "\e\C-m
"))
7914 (org-defkey orgstruct-mode-map [?\e (shift return)]
7915 (orgstruct-make-binding 'org-insert-todo-heading 110
7916 [?\e (return)] "\e\C-m
"))
7918 (unless org-local-vars
7919 (setq org-local-vars (org-get-local-variables)))
7923 (defun orgstruct-make-binding (fun n &rest keys)
7924 "Create a function for binding in the structure minor mode.
7925 FUN is the command to call inside a table. N is used to create a unique
7926 command name. KEYS are keys that should be checked in for a command
7927 to execute outside of tables.
"
7930 (intern (concat "orgstruct-hijacker-command-
" (int-to-string n)))
7932 (concat "In Structure
, run
`" (symbol-name fun) "'.
\n"
7933 "Outside of structure
, run the binding of
`"
7934 (mapconcat (lambda (x) (format "%s
" x)) keys "' or
`")
7938 `(org-context-p 'headline 'item
7939 (and orgstruct-is-++
7940 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7942 (list 'org-run-like-in-org-mode (list 'quote fun))
7943 (list 'let '(orgstruct-mode)
7944 (list 'call-interactively
7947 (list 'key-binding k))
7949 '('orgstruct-error))))))))
7951 (defun org-context-p (&rest contexts)
7952 "Check if local context is any of CONTEXTS.
7953 Possible values in the list of contexts are
`table
', `headline
', and
`item
'.
"
7954 (let ((pos (point)))
7955 (goto-char (point-at-bol))
7956 (prog1 (or (and (memq 'table contexts)
7957 (looking-at "[ \t]*|
"))
7958 (and (memq 'headline contexts)
7959 ;;????????? (looking-at "\\*+"))
7960 (looking-at outline-regexp))
7961 (and (memq 'item contexts)
7962 (looking-at "[ \t]*\\([-
+*] \\|
[0-
9]+[.
)] \\)"))
7963 (and (memq 'item-body contexts)
7967 (defun org-get-local-variables ()
7968 "Return a list of all local variables in an org-mode buffer.
"
7970 (with-current-buffer (get-buffer-create "*Org tmp
*")
7973 (setq varlist (buffer-local-variables)))
7974 (kill-buffer "*Org tmp
*")
7981 (list (car x) (list 'quote (cdr x)))))
7983 "^
\\(org-\\|orgtbl-
\\|outline-
\\|comment-
\\|paragraph-
\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7984 (symbol-name (car x)))
7989 (defun org-run-like-in-org-mode (cmd)
7990 "Run a command
, pretending that the current buffer is in Org-mode.
7991 This will temporarily bind local variables that are typically bound in
7992 Org-mode to the values they have in Org-mode
, and then interactively
7994 (org-load-modules-maybe)
7995 (unless org-local-vars
7996 (setq org-local-vars (org-get-local-variables)))
7997 (eval (list 'let org-local-vars
7998 (list 'call-interactively (list 'quote cmd)))))
8002 (defun org-get-category (&optional pos)
8003 "Get the category applying to position POS.
"
8004 (get-text-property (or pos (point)) 'org-category))
8006 (defun org-refresh-category-properties ()
8007 "Refresh category text properties in the buffer.
"
8008 (let ((def-cat (cond
8009 ((null org-category)
8010 (if buffer-file-name
8011 (file-name-sans-extension
8012 (file-name-nondirectory buffer-file-name))
8014 ((symbolp org-category) (symbol-name org-category))
8016 beg end cat pos optionp)
8021 (goto-char (point-min))
8022 (put-text-property (point) (point-max) 'org-category def-cat)
8023 (while (re-search-forward
8024 "^
\\(#\\+CATEGORY
:\\|
[ \t]*:CATEGORY
:\\)\\(.
*\\)" nil t)
8025 (setq pos (match-end 0)
8026 optionp (equal (char-after (match-beginning 0)) ?#)
8027 cat (org-trim (match-string 2)))
8029 (setq beg (point-at-bol) end (point-max))
8030 (org-back-to-heading t)
8031 (setq beg (point) end (org-end-of-subtree t t)))
8032 (put-text-property beg end 'org-category cat)
8033 (goto-char pos)))))))
8038 ;;; Link abbreviations
8040 (defun org-link-expand-abbrev (link)
8041 "Apply replacements as defined in
`org-link-abbrev-alist.
"
8042 (if (string-match "^
\\([a-zA-Z
][-_a-zA-Z0-9
]*\\)\\(::?
\\(.
*\\)\\)?$
" link)
8043 (let* ((key (match-string 1 link))
8044 (as (or (assoc key org-link-abbrev-alist-local)
8045 (assoc key org-link-abbrev-alist)))
8046 (tag (and (match-end 2) (match-string 3 link)))
8052 ((symbolp rpl) (funcall rpl tag))
8053 ((string-match "%s
" rpl) (replace-match (or tag "") t t rpl))
8054 ((string-match "%h
" rpl)
8055 (replace-match (url-hexify-string (or tag "")) t t rpl))
8056 (t (concat rpl tag)))))
8059 ;;; Storing and inserting links
8061 (defvar org-insert-link-history nil
8062 "Minibuffer history for links inserted with
`org-insert-link
'.
")
8064 (defvar org-stored-links nil
8065 "Contains the links stored with
`org-store-link
'.
")
8067 (defvar org-store-link-plist nil
8068 "Plist with info about the most recently link created with
`org-store-link
'.
")
8070 (defvar org-link-protocols nil
8071 "Link protocols added to Org-mode using
`org-add-link-type
'.
")
8073 (defvar org-store-link-functions nil
8074 "List of functions that are called to create and store a link.
8075 Each function will be called in turn until one returns a non-nil
8076 value. Each function should check if it is responsible for creating
8077 this link
(for example by looking at the major mode
).
8078 If not
, it must exit and return nil.
8079 If yes
, it should return a non-nil value after a calling
8080 `org-store-link-props
' with a list of properties and values.
8081 Special properties are
:
8083 :type The link prefix. like
\"http
\". This must be given.
8084 :link The link
, like
\"http
://www.astro.uva.nl
/~dominik
\".
8085 This is obligatory as well.
8086 :description Optional default description for the second pair
8087 of brackets in an Org-mode link. The user can still change
8088 this when inserting this link into an Org-mode buffer.
8090 In addition to these
, any additional properties can be specified
8091 and then used in remember templates.
")
8093 (defun org-add-link-type (type &optional follow export)
8094 "Add TYPE to the list of
`org-link-types
'.
8095 Re-compute all regular expressions depending on
`org-link-types
'
8097 FOLLOW and EXPORT are two functions.
8099 FOLLOW should take the link path as the single argument and do whatever
8100 is necessary to follow the link
, for example find a file or display
8103 EXPORT should format the link path for export to one of the export formats.
8104 It should be a function accepting three arguments
:
8106 path the path of the link
, the text after the prefix
(like \"http
:\")
8107 desc the description of the link
, if any
, nil if there was no description
8108 format the export format
, a symbol like
`html
' or
`latex
'.
8110 The function may use the FORMAT information to return different values
8111 depending on the format. The return value will be put literally into
8113 Org-mode has a built-in default for exporting links. If you are happy with
8114 this default
, there is no need to define an export function for the link
8115 type. For a simple example of an export function
, see
`org-bbdb.el
'.
"
8116 (add-to-list 'org-link-types type t)
8117 (org-make-link-regexps)
8118 (if (assoc type org-link-protocols)
8119 (setcdr (assoc type org-link-protocols) (list follow export))
8120 (push (list type follow export) org-link-protocols)))
8122 (defvar org-agenda-buffer-name)
8125 (defun org-store-link (arg)
8126 "\\<org-mode-map
>Store an org-link to the current location.
8127 This link is added to
`org-stored-links
' and can later be inserted
8128 into an org-buffer with
\\[org-insert-link
].
8130 For some link types
, a prefix arg is interpreted
:
8131 For links to usenet articles
, arg negates
`org-gnus-prefer-web-links
'.
8132 For file links
, arg negates
`org-context-in-file-links
'.
"
8134 (org-load-modules-maybe)
8135 (setq org-store-link-plist nil) ; reset
8136 (let ((outline-regexp (org-get-limited-outline-regexp))
8137 link cpltxt desc description search txt custom-id)
8140 ((run-hook-with-args-until-success 'org-store-link-functions)
8141 (setq link (plist-get org-store-link-plist :link)
8142 desc (or (plist-get org-store-link-plist :description) link)))
8144 ((equal (buffer-name) "*Org Edit Src Example
*")
8146 (while (or (not label)
8150 (goto-char (point-min))
8152 (regexp-quote (format org-coderef-label-format label))
8154 (when label (message "Label exists already
") (sit-for 2))
8155 (setq label (read-string "Code line label
: " label)))
8157 (setq link (format org-coderef-label-format label))
8158 (setq gc (- 79 (length link)))
8159 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8161 (setq link (concat "(" label ")") desc nil)))
8163 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8164 ;; We are in the agenda, link to referenced location
8165 (let ((m (or (get-text-property (point) 'org-hd-marker)
8166 (get-text-property (point) 'org-marker))))
8168 (org-with-point-at m
8170 (call-interactively 'org-store-link)
8171 (org-store-link nil))))))
8173 ((eq major-mode 'calendar-mode)
8174 (let ((cd (calendar-cursor-to-date)))
8177 (car org-time-stamp-formats)
8179 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8181 (org-store-link-props :type "calendar
" :date cd)))
8183 ((eq major-mode 'w3-mode)
8184 (setq cpltxt (if (and (buffer-name)
8185 (not (string-match "Untitled
" (buffer-name))))
8188 link (org-make-link (url-view-url t)))
8189 (org-store-link-props :type "w3
" :url (url-view-url t)))
8191 ((eq major-mode 'w3m-mode)
8192 (setq cpltxt (or w3m-current-title w3m-current-url)
8193 link (org-make-link w3m-current-url))
8194 (org-store-link-props :type "w3m
" :url (url-view-url t)))
8196 ((setq search (run-hook-with-args-until-success
8197 'org-create-file-search-functions))
8198 (setq link (concat "file
:" (abbreviate-file-name buffer-file-name)
8200 (setq cpltxt (or description link)))
8202 ((eq major-mode 'image-mode)
8203 (setq cpltxt (concat "file
:"
8204 (abbreviate-file-name buffer-file-name))
8205 link (org-make-link cpltxt))
8206 (org-store-link-props :type "image
" :file buffer-file-name))
8208 ((eq major-mode 'dired-mode)
8209 ;; link to the file in the current line
8210 (let ((file (dired-get-filename nil t)))
8212 (abbreviate-file-name
8213 (expand-file-name (dired-get-filename nil t)))
8214 ;; otherwise, no file so use current directory.
8216 (setq cpltxt (concat "file
:" file)
8217 link (org-make-link cpltxt))))
8219 ((and buffer-file-name (org-mode-p))
8220 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID
")))
8222 ((org-in-regexp "<<\\(.
*?
\\)>>")
8225 (abbreviate-file-name buffer-file-name)
8226 "::" (match-string 1))
8227 link (org-make-link cpltxt)))
8228 ((and (featurep 'org-id)
8229 (or (eq org-link-to-org-use-id t)
8230 (and (eq org-link-to-org-use-id 'create-if-interactive)
8232 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
8235 (and org-link-to-org-use-id
8237 (org-entry-get nil "ID
")
8239 ;; We can make a link using the ID.
8240 (setq link (condition-case nil
8241 (prog1 (org-id-store-link)
8242 (setq desc (plist-get org-store-link-plist
8245 ;; probably before first headline, link to file only
8247 (abbreviate-file-name buffer-file-name))))))
8249 ;; Just link to current headline
8250 (setq cpltxt (concat "file
:"
8251 (abbreviate-file-name buffer-file-name)))
8252 ;; Add a context search string
8253 (when (org-xor org-context-in-file-links arg)
8255 ((org-on-heading-p) nil)
8256 ((org-region-active-p)
8257 (buffer-substring (region-beginning) (region-end)))
8259 (when (or (null txt) (string-match "\\S-
" txt))
8263 (org-make-org-heading-search-string txt)
8265 desc (or (nth 4 (ignore-errors
8266 (org-heading-components))) "NONE
"))))
8267 (if (string-match "::\\'" cpltxt)
8268 (setq cpltxt (substring cpltxt 0 -2)))
8269 (setq link (org-make-link cpltxt)))))
8271 ((buffer-file-name (buffer-base-buffer))
8272 ;; Just link to this file here.
8273 (setq cpltxt (concat "file
:"
8274 (abbreviate-file-name
8275 (buffer-file-name (buffer-base-buffer)))))
8276 ;; Add a context string
8277 (when (org-xor org-context-in-file-links arg)
8278 (setq txt (if (org-region-active-p)
8279 (buffer-substring (region-beginning) (region-end))
8280 (buffer-substring (point-at-bol) (point-at-eol))))
8281 ;; Only use search option if there is some text.
8282 (when (string-match "\\S-
" txt)
8284 (concat cpltxt "::" (org-make-org-heading-search-string txt))
8286 (setq link (org-make-link cpltxt)))
8289 (error "Cannot link to a buffer which is not visiting a file
"))
8291 (t (setq link nil)))
8293 (if (consp link) (setq cpltxt (car link) link (cdr link)))
8294 (setq link (or link cpltxt)
8295 desc (or desc cpltxt))
8296 (if (equal desc "NONE
") (setq desc nil))
8298 (if (and (or (interactive-p) executing-kbd-macro) link)
8300 (setq org-stored-links
8301 (cons (list link desc) org-stored-links))
8302 (message "Stored
: %s
" (or desc link))
8304 (setq link (concat "file
:" (abbreviate-file-name (buffer-file-name))
8306 (setq org-stored-links
8307 (cons (list link desc) org-stored-links))))
8308 (and link (org-make-link-string link desc)))))
8310 (defun org-store-link-props (&rest plist)
8311 "Store link properties
, extract names and addresses.
"
8313 (when (setq x (plist-get plist :from))
8314 (setq adr (mail-extract-address-components x))
8315 (setq plist (plist-put plist :fromname (car adr)))
8316 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8317 (when (setq x (plist-get plist :to))
8318 (setq adr (mail-extract-address-components x))
8319 (setq plist (plist-put plist :toname (car adr)))
8320 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8321 (let ((from (plist-get plist :from))
8322 (to (plist-get plist :to)))
8323 (when (and from to org-from-is-user-regexp)
8325 (plist-put plist :fromto
8326 (if (string-match org-from-is-user-regexp from)
8328 (concat "from %f
"))))))
8329 (setq org-store-link-plist plist))
8331 (defun org-add-link-props (&rest plist)
8332 "Add these properties to the link property list.
"
8335 (setq key (pop plist) value (pop plist))
8336 (setq org-store-link-plist
8337 (plist-put org-store-link-plist key value)))))
8339 (defun org-email-link-description (&optional fmt)
8340 "Return the description part of an email link.
8341 This takes information from
`org-store-link-plist
' and formats it
8342 according to FMT
(default from
`org-email-link-description-format
').
"
8343 (setq fmt (or fmt org-email-link-description-format))
8344 (let* ((p org-store-link-plist)
8345 (to (plist-get p :toaddress))
8346 (from (plist-get p :fromaddress))
8349 (cons "%c
" (plist-get p :fromto))
8350 (cons "%F
" (plist-get p :from))
8351 (cons "%f
" (or (plist-get p :fromname) (plist-get p :fromaddress) "?
"))
8352 (cons "%T
" (plist-get p :to))
8353 (cons "%t
" (or (plist-get p :toname) (plist-get p :toaddress) "?
"))
8354 (cons "%s
" (plist-get p :subject))
8355 (cons "%m
" (plist-get p :message-id)))))
8356 (when (string-match "%c
" fmt)
8357 ;; Check if the user wrote this message
8358 (if (and org-from-is-user-regexp from to
8359 (save-match-data (string-match org-from-is-user-regexp from)))
8360 (setq fmt (replace-match "to %t
" t t fmt))
8361 (setq fmt (replace-match "from %f
" t t fmt))))
8362 (org-replace-escapes fmt table)))
8364 (defun org-make-org-heading-search-string (&optional string heading)
8365 "Make search string for STRING or current headline.
"
8367 (let ((s (or string (org-get-heading))))
8368 (unless (and string (not heading))
8369 ;; We are using a headline, clean up garbage in there.
8370 (if (string-match org-todo-regexp s)
8371 (setq s (replace-match "" t t s)))
8372 (if (string-match (org-re ":[[:alnum
:]_
@:]+:[ \t]*$
") s)
8373 (setq s (replace-match "" t t s)))
8374 (setq s (org-trim s))
8375 (if (string-match (concat "^
\\(" org-quote-string "\\|
"
8376 org-comment-string "\\)") s)
8377 (setq s (replace-match "" t t s)))
8378 (while (string-match org-ts-regexp s)
8379 (setq s (replace-match "" t t s))))
8380 (while (string-match "[^a-zA-Z_0-9
\t]+" s)
8381 (setq s (replace-match " " t t s)))
8382 (or string (setq s (concat "*" s))) ; Add * for headlines
8383 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8385 (defun org-make-link (&rest strings)
8386 "Concatenate STRINGS.
"
8387 (apply 'concat strings))
8389 (defun org-make-link-string (link &optional description)
8390 "Make a link with brackets
, consisting of LINK and DESCRIPTION.
"
8391 (unless (string-match "\\S-
" link)
8392 (error "Empty link
"))
8393 (when (and description
8394 (stringp description)
8395 (not (string-match "\\S-
" description)))
8396 (setq description nil))
8397 (when (stringp description)
8398 ;; Remove brackets from the description, they are fatal.
8399 (while (string-match "\\[" description)
8400 (setq description (replace-match "{" t t description)))
8401 (while (string-match "\\]" description)
8402 (setq description (replace-match "}" t t description))))
8403 (when (equal (org-link-escape link) description)
8404 ;; No description needed, it is identical
8405 (setq description nil))
8406 (when (and (not description)
8407 (not (equal link (org-link-escape link))))
8408 (setq description (org-extract-attributes link)))
8409 (concat "[[" (org-link-escape link) "]"
8410 (if description (concat "[" description "]") "")
8413 (defconst org-link-escape-chars
8417 (?\340 . "%E0
") ; `a
8418 (?\342 . "%E2
") ; ^a
8419 (?\347 . "%E7
") ; ,c
8420 (?\350 . "%E8
") ; `e
8421 (?\351 . "%E9
") ; 'e
8422 (?\352 . "%EA
") ; ^e
8423 (?\356 . "%EE
") ; ^i
8424 (?\364 . "%F4
") ; ^o
8425 (?\371 . "%F9
") ; `u
8426 (?\373 . "%FB
") ; ^u
8432 "Association list of escapes for some characters problematic in links.
8433 This is the list that is used for internal purposes.
")
8435 (defvar org-url-encoding-use-url-hexify nil)
8437 (defconst org-link-escape-chars-browser
8438 '((?\ . "%
20")) ; 32 for the SPC char
8439 "Association list of escapes for some characters problematic in links.
8440 This is the list that is used before handing over to the browser.
")
8442 (defun org-link-escape (text &optional table)
8443 "Escape characters in TEXT that are problematic for links.
"
8444 (if (and org-url-encoding-use-url-hexify (not table))
8445 (url-hexify-string text)
8446 (setq table (or table org-link-escape-chars))
8448 (let ((re (mapconcat (lambda (x) (regexp-quote
8449 (char-to-string (car x))))
8451 (while (string-match re text)
8454 (cdr (assoc (string-to-char (match-string 0 text))
8459 (defun org-link-unescape (text &optional table)
8460 "Reverse the action of
`org-link-escape
'.
"
8461 (if (and org-url-encoding-use-url-hexify (not table))
8462 (url-unhex-string text)
8463 (setq table (or table org-link-escape-chars))
8465 (let ((case-fold-search t)
8466 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8468 (while (string-match re text)
8471 (char-to-string (car (rassoc (upcase (match-string 0 text))
8476 (defun org-xor (a b)
8480 (defun org-fixup-message-id-for-http (s)
8481 "Replace special characters in a message id
, so it can be used in an http query.
"
8482 (when (string-match "%
" s)
8483 (setq s (mapconcat (lambda (c)
8486 (char-to-string c)))
8488 (while (string-match "<" s)
8489 (setq s (replace-match "%
3C
" t t s)))
8490 (while (string-match ">" s)
8491 (setq s (replace-match "%
3E
" t t s)))
8492 (while (string-match "@" s)
8493 (setq s (replace-match "%
40" t t s)))
8497 (defun org-insert-link-global ()
8498 "Insert a link like Org-mode does.
8499 This command can be called in any mode to insert a link in Org-mode syntax.
"
8501 (org-load-modules-maybe)
8502 (org-run-like-in-org-mode 'org-insert-link))
8504 (defun org-insert-link (&optional complete-file link-location)
8505 "Insert a link. At the prompt
, enter the link.
8507 Completion can be used to insert any of the link protocol prefixes like
8510 The history can be used to select a link previously stored with
8511 `org-store-link
'. When the empty string is entered
(i.e. if you just
8512 press RET at the prompt
), the link defaults to the most recently
8513 stored link. As SPC triggers completion in the minibuffer
, you need to
8514 use M-SPC or C-q SPC to force the insertion of a space character.
8516 You will also be prompted for a description
, and if one is given
, it will
8517 be displayed in the buffer instead of the link.
8519 If there is already a link at point
, this command will allow you to edit link
8520 and description parts.
8522 With a
\\[universal-argument
] prefix
, prompts for a file to link to. The file name can
8523 be selected using completion. The path to the file will be relative to the
8524 current directory if the file is in the current directory or a subdirectory.
8525 Otherwise
, the link will be the absolute path as completed in the minibuffer
8526 \
(i.e. normally ~
/path
/to
/file
). You can configure this behavior using the
8527 option
`org-link-file-path-type
'.
8529 With two
\\[universal-argument
] prefixes
, enforce an absolute path even if the file is in
8530 the current directory or below.
8532 With three
\\[universal-argument
] prefixes
, negate the meaning of
8533 `org-keep-stored-link-after-insertion
'.
8535 If
`org-make-link-description-function
' is non-nil
, this function will be
8536 called with the link target
, and the result will be the default
8539 If the LINK-LOCATION parameter is non-nil
, this value will be
8540 used as the link location instead of reading one interactively.
"
8542 (let* ((wcf (current-window-configuration))
8543 (region (if (org-region-active-p)
8544 (buffer-substring (region-beginning) (region-end))))
8545 (remove (and region (list (region-beginning) (region-end))))
8547 tmphist ; byte-compile incorrectly complains about this
8548 (link link-location)
8549 entry file all-prefixes)
8551 (link-location) ; specified by arg, just use it.
8552 ((org-in-regexp org-bracket-link-regexp 1)
8553 ;; We do have a link at point, and we are going to edit it.
8554 (setq remove (list (match-beginning 0) (match-end 0)))
8555 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8556 (setq link (read-string "Link
: "
8558 (org-match-string-no-properties 1)))))
8559 ((or (org-in-regexp org-angle-link-re)
8560 (org-in-regexp org-plain-link-re))
8561 ;; Convert to bracket link
8562 (setq remove (list (match-beginning 0) (match-end 0))
8563 link (read-string "Link
: "
8564 (org-remove-angle-brackets (match-string 0)))))
8565 ((member complete-file '((4) (16)))
8566 ;; Completing read for file names.
8567 (setq link (org-file-complete-link complete-file)))
8569 ;; Read link, with completion for stored links.
8570 (with-output-to-temp-buffer "*Org Links
*"
8571 (princ "Insert a link.
8572 Use TAB to complete link prefixes
, then RET for type-specific completion support
\n")
8573 (when org-stored-links
8574 (princ "\nStored links are available with
<up
>/<down
> or M-p
/n
(most recent with RET
):\n\n")
8577 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8578 (reverse org-stored-links) "\n"))))
8579 (let ((cw (selected-window)))
8580 (select-window (get-buffer-window "*Org Links
*" 'visible))
8581 (setq truncate-lines t)
8582 (unless (pos-visible-in-window-p (point-max))
8583 (org-fit-window-to-buffer))
8584 (and (window-live-p cw) (select-window cw)))
8585 ;; Fake a link history, containing the stored links.
8586 (setq tmphist (append (mapcar 'car org-stored-links)
8587 org-insert-link-history))
8588 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8589 (mapcar 'car org-link-abbrev-alist)
8594 (let ((org-completion-use-ido nil)
8595 (org-completion-use-iswitchb nil))
8596 (org-completing-read
8599 (mapcar (lambda (x) (list (concat x ":")))
8601 (mapcar 'car org-stored-links))
8604 (car (car org-stored-links)))))
8605 (if (not (string-match "\\S-
" link))
8606 (error "No link selected
"))
8607 (if (or (member link all-prefixes)
8608 (and (equal ":" (substring link -1))
8609 (member (substring link 0 -1) all-prefixes)
8610 (setq link (substring link 0 -1))))
8611 (setq link (org-link-try-special-completion link))))
8612 (set-window-configuration wcf)
8613 (kill-buffer "*Org Links
*"))
8614 (setq entry (assoc link org-stored-links))
8615 (or entry (push link org-insert-link-history))
8616 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8617 (not org-keep-stored-link-after-insertion))
8618 (setq org-stored-links (delq (assoc link org-stored-links)
8620 (setq desc (or desc (nth 1 entry)))))
8622 (if (string-match org-plain-link-re link)
8623 ;; URL-like link, normalize the use of angular brackets.
8624 (setq link (org-make-link (org-remove-angle-brackets link))))
8626 ;; Check if we are linking to the current file with a search option
8627 ;; If yes, simplify the link by using only the search option.
8628 (when (and buffer-file-name
8629 (string-match "^file
:\\(.
+?
\\)::\\([^
>]+\\)" link))
8630 (let* ((path (match-string 1 link))
8631 (case-fold-search nil)
8632 (search (match-string 2 link)))
8634 (if (equal (file-truename buffer-file-name) (file-truename path))
8635 ;; We are linking to this same file, with a search option
8636 (setq link search)))))
8638 ;; Check if we can/should use a relative path. If yes, simplify the link
8639 (when (string-match "^
\\(file:\\|docview
:\\)\\(.
*\\)" link)
8640 (let* ((type (match-string 1 link))
8641 (path (match-string 2 link))
8643 (case-fold-search nil))
8645 ((or (eq org-link-file-path-type 'absolute)
8646 (equal complete-file '(16)))
8647 (setq path (abbreviate-file-name (expand-file-name path))))
8648 ((eq org-link-file-path-type 'noabbrev)
8649 (setq path (expand-file-name path)))
8650 ((eq org-link-file-path-type 'relative)
8651 (setq path (file-relative-name path)))
8654 (if (string-match (concat "^
" (regexp-quote
8655 (file-name-as-directory
8656 default-directory)))
8657 (expand-file-name path))
8658 ;; We are linking a file with relative path name.
8659 (setq path (substring (expand-file-name path)
8661 (setq path (abbreviate-file-name (expand-file-name path)))))))
8662 (setq link (concat type path))
8663 (if (equal desc origpath)
8666 (if org-make-link-description-function
8667 (setq desc (funcall org-make-link-description-function link desc)))
8669 (setq desc (read-string "Description
: " desc))
8670 (unless (string-match "\\S-
" desc) (setq desc nil))
8671 (if remove (apply 'delete-region remove))
8672 (insert (org-make-link-string link desc))))
8674 (defun org-link-try-special-completion (type)
8675 "If there is completion support for link type TYPE
, offer it.
"
8676 (let ((fun (intern (concat "org-
" type "-complete-link
"))))
8679 (read-string "Link
(no completion support
): " (concat type ":")))))
8681 (defun org-file-complete-link (&optional arg)
8682 "Create a file link using completion.
"
8684 (setq file (read-file-name "File
: "))
8685 (let ((pwd (file-name-as-directory (expand-file-name ".
")))
8686 (pwd1 (file-name-as-directory (abbreviate-file-name
8687 (expand-file-name ".
")))))
8690 (setq link (org-make-link
8692 (abbreviate-file-name (expand-file-name file)))))
8693 ((string-match (concat "^
" (regexp-quote pwd1) "\\(.
+\\)") file)
8694 (setq link (org-make-link "file
:" (match-string 1 file))))
8695 ((string-match (concat "^
" (regexp-quote pwd) "\\(.
+\\)")
8696 (expand-file-name file))
8697 (setq link (org-make-link
8698 "file
:" (match-string 1 (expand-file-name file)))))
8699 (t (setq link (org-make-link "file
:" file)))))
8702 (defun org-completing-read (&rest args)
8703 "Completing-read with SPACE being a normal character.
"
8704 (let ((minibuffer-local-completion-map
8705 (copy-keymap minibuffer-local-completion-map)))
8706 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8707 (org-defkey minibuffer-local-completion-map "?
" 'self-insert-command)
8708 (apply 'org-icompleting-read args)))
8710 (defun org-completing-read-no-i (&rest args)
8711 (let (org-completion-use-ido org-completion-use-iswitchb)
8712 (apply 'org-completing-read args)))
8714 (defun org-iswitchb-completing-read (prompt choices &rest args)
8715 "Use iswitch as a completing-read replacement to choose from choices.
8716 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8718 (let* ((iswitchb-use-virtual-buffers nil)
8719 (iswitchb-make-buflist-hook
8721 (setq iswitchb-temp-buflist choices))))
8722 (iswitchb-read-buffer prompt)))
8724 (defun org-icompleting-read (&rest args)
8725 "Completing-read using
`ido-mode
' or
`iswitchb
' speedups if available.
"
8726 (org-without-partial-completion
8727 (if (and org-completion-use-ido
8728 (fboundp 'ido-completing-read)
8729 (boundp 'ido-mode) ido-mode
8730 (listp (second args)))
8731 (let ((ido-enter-matching-directory nil))
8732 (apply 'ido-completing-read (concat (car args))
8733 (if (consp (car (nth 1 args)))
8734 (mapcar (lambda (x) (car x)) (nth 1 args))
8737 (if (and org-completion-use-iswitchb
8738 (boundp 'iswitchb-mode) iswitchb-mode
8739 (listp (second args)))
8740 (apply 'org-iswitchb-completing-read (concat (car args))
8741 (if (consp (car (nth 1 args)))
8742 (mapcar (lambda (x) (car x)) (nth 1 args))
8745 (apply 'completing-read args)))))
8747 (defun org-extract-attributes (s)
8748 "Extract the attributes cookie from a string and set as text property.
"
8749 (let (a attr (start 0) key value)
8751 (when (string-match "{{\\([^
}]+\\)}}$
" s)
8752 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8753 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"" a start)
8754 (setq key (match-string 1 a) value (match-string 2 a)
8756 attr (plist-put attr (intern key) value))))
8757 (org-add-props s nil 'org-attr attr))
8760 (defun org-extract-attributes-from-string (tag)
8761 (let (key value attr)
8762 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"\\s-?
" tag)
8763 (setq key (match-string 1 tag) value (match-string 2 tag)
8764 tag (replace-match "" t t tag)
8765 attr (plist-put attr (intern key) value)))
8768 (defun org-attributes-to-string (plist)
8769 "Format a property list into an HTML attribute list.
"
8770 (let ((s "") key value)
8772 (setq key (pop plist) value (pop plist))
8774 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8777 ;;; Opening/following a link
8779 (defvar org-link-search-failed nil)
8781 (defvar org-open-link-functions nil
8782 "Hook for functions finding a plain text link.
8783 These functions must take a single argument
, the link content.
8784 They will be called for links that look like
[[link text
][description]]
8785 when LINK TEXT does not have a protocol like \"http:\" and does not look
8786 like a filename (e.g. \"./blue.png\").
8788 These functions will be called *before* Org attempts to resolve the
8789 link by doing text searches in the current buffer - so if you want a
8790 link \"[[target]]\" to still find \"<<target>>\", your function should
8791 handle this as a special case.
8793 When the function does handle the link, it must return a non-nil value.
8794 If it decides that it is not responsible for this link, it must return
8795 nil to indicate that that Org-mode can continue with other options
8796 like exact and fuzzy text search.")
8798 (defun org-next-link ()
8799 "Move forward to the next link.
8800 If the link is in hidden text, expose it."
8802 (when (and org-link-search-failed (eq this-command last-command))
8803 (goto-char (point-min))
8804 (message "Link search wrapped back to beginning of buffer"))
8805 (setq org-link-search-failed nil)
8806 (let* ((pos (point))
8808 (a (assoc :link ct)))
8809 (if a (goto-char (nth 2 a)))
8810 (if (re-search-forward org-any-link-re nil t)
8812 (goto-char (match-beginning 0))
8813 (if (org-invisible-p) (org-show-context)))
8815 (setq org-link-search-failed t)
8816 (error "No further link found"))))
8818 (defun org-previous-link ()
8819 "Move backward to the previous link.
8820 If the link is in hidden text, expose it."
8822 (when (and org-link-search-failed (eq this-command last-command))
8823 (goto-char (point-max))
8824 (message "Link search wrapped back to end of buffer"))
8825 (setq org-link-search-failed nil)
8826 (let* ((pos (point))
8828 (a (assoc :link ct)))
8829 (if a (goto-char (nth 1 a)))
8830 (if (re-search-backward org-any-link-re nil t)
8832 (goto-char (match-beginning 0))
8833 (if (org-invisible-p) (org-show-context)))
8835 (setq org-link-search-failed t)
8836 (error "No further link found"))))
8838 (defun org-translate-link (s)
8839 "Translate a link string if a translation function has been defined."
8840 (if (and org-link-translation-function
8841 (fboundp org-link-translation-function)
8842 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8844 (setq s (funcall org-link-translation-function
8845 (match-string 1) (match-string 2)))
8846 (concat (car s) ":" (cdr s)))
8849 (defun org-translate-link-from-planner (type path)
8850 "Translate a link from Emacs Planner syntax so that Org can follow it.
8851 This is still an experimental function, your mileage may vary."
8853 ((member type '("http" "https" "news" "ftp"))
8854 ;; standard Internet links are the same.
8856 ((and (equal type "irc") (string-match "^//" path))
8857 ;; Planner has two / at the beginning of an irc link, we have 1.
8858 ;; We should have zero, actually....
8859 (setq path (substring path 1)))
8860 ((and (equal type "lisp") (string-match "^/" path))
8861 ;; Planner has a slash, we do not.
8862 (setq type "elisp" path (substring path 1)))
8863 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8864 ;; A typical message link. Planner has the id after the final slash,
8865 ;; we separate it with a hash mark
8866 (setq path (concat (match-string 1 path) "#"
8867 (org-remove-angle-brackets (match-string 2 path)))))
8871 (defun org-find-file-at-mouse (ev)
8872 "Open file link or URL at mouse."
8874 (mouse-set-point ev)
8875 (org-open-at-point 'in-emacs))
8877 (defun org-open-at-mouse (ev)
8878 "Open file link or URL at mouse."
8880 (mouse-set-point ev)
8881 (if (eq major-mode 'org-agenda-mode)
8882 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8883 (org-open-at-point))
8885 (defvar org-window-config-before-follow-link nil
8886 "The window configuration before following a link.
8887 This is saved in case the need arises to restore it.")
8889 (defvar org-open-link-marker (make-marker)
8890 "Marker pointing to the location where `org-open-at-point; was called.")
8893 (defun org-open-at-point-global ()
8894 "Follow a link like Org-mode does.
8895 This command can be called in any mode to follow a link that has
8898 (org-run-like-in-org-mode 'org-open-at-point))
8901 (defun org-open-link-from-string (s &optional arg reference-buffer)
8902 "Open a link in the string S, as if it was in Org-mode."
8903 (interactive "sLink: \nP")
8904 (let ((reference-buffer (or reference-buffer (current-buffer))))
8906 (let ((org-inhibit-startup t))
8909 (goto-char (point-min))
8910 (when reference-buffer
8911 (setq org-link-abbrev-alist-local
8912 (with-current-buffer reference-buffer
8913 org-link-abbrev-alist-local)))
8914 (org-open-at-point arg reference-buffer)))))
8916 (defun org-open-at-point (&optional in-emacs reference-buffer)
8917 "Open link at or after point.
8918 If there is no link at point, this function will search forward up to
8919 the end of the current line.
8920 Normally, files will be opened by an appropriate application. If the
8921 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8922 With a double prefix argument, try to open outside of Emacs, in the
8923 application the system uses for this file type."
8925 ;; if in a code block, then open the block's results
8926 (unless (call-interactively #'org-babel-open-src-block-result)
8927 (org-load-modules-maybe)
8928 (move-marker org-open-link-marker (point))
8929 (setq org-window-config-before-follow-link (current-window-configuration))
8930 (org-remove-occur-highlights nil nil t)
8932 ((and (org-on-heading-p)
8934 (concat org-plain-link-re "\\|"
8935 org-bracket-link-regexp "\\|"
8936 org-angle-link-re "\\|"
8937 "[ \t]:[^ \t\n]+:[ \t]*$")))
8938 (not (get-text-property (point) 'org-linked-text)))
8939 (or (org-offer-links-in-entry in-emacs)
8940 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8941 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8942 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8943 (org-footnote-action))
8945 (let (type path link line search (pos (point)))
8948 (skip-chars-forward "^]\n\r")
8949 (when (org-in-regexp org-bracket-link-regexp 1)
8950 (setq link (org-extract-attributes
8951 (org-link-unescape (org-match-string-no-properties 1))))
8952 (while (string-match " *\n *" link)
8953 (setq link (replace-match " " t t link)))
8954 (setq link (org-link-expand-abbrev link))
8956 ((or (file-name-absolute-p link)
8957 (string-match "^\\.\\.?/" link))
8958 (setq type "file" path link))
8959 ((string-match org-link-re-with-space3 link)
8960 (setq type (match-string 1 link) path (match-string 2 link)))
8961 (t (setq type "thisfile" path link)))
8964 (when (get-text-property (point) 'org-linked-text)
8965 (setq type "thisfile"
8966 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8967 (1+ (point)) (point))
8968 path (buffer-substring
8969 (previous-single-property-change pos 'org-linked-text)
8970 (next-single-property-change pos 'org-linked-text)))
8974 (when (or (org-in-regexp org-angle-link-re)
8975 (org-in-regexp org-plain-link-re))
8976 (setq type (match-string 1) path (match-string 2))
8979 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8981 path (match-string 1))
8982 (while (string-match ":" path)
8983 (setq path (replace-match "+" t t path)))
8985 (when (org-in-regexp "<\\([^><\n]+\\)>")
8986 (setq type "tree-match"
8987 path (match-string 1))
8990 (error "No link found"))
8992 ;; switch back to reference buffer
8993 ;; needed when if called in a temporary buffer through
8994 ;; org-open-link-from-string
8995 (with-current-buffer (or reference-buffer (current-buffer))
8997 ;; Remove any trailing spaces in path
8998 (if (string-match " +\\'" path)
8999 (setq path (replace-match "" t t path)))
9000 (if (and org-link-translation-function
9001 (fboundp org-link-translation-function))
9002 ;; Check if we need to translate the link
9003 (let ((tmp (funcall org-link-translation-function type path)))
9004 (setq type (car tmp) path (cdr tmp))))
9008 ((assoc type org-link-protocols)
9009 (funcall (nth 1 (assoc type org-link-protocols)) path))
9011 ((equal type "mailto")
9012 (let ((cmd (car org-link-mailto-program))
9013 (args (cdr org-link-mailto-program)) args1
9014 (address path) (subject "") a)
9015 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9016 (setq address (match-string 1 path)
9017 subject (org-link-escape (match-string 2 path))))
9020 ((not (stringp (car args))) (push (pop args) args1))
9021 (t (setq a (pop args))
9022 (if (string-match "%a" a)
9023 (setq a (replace-match address t t a)))
9024 (if (string-match "%s" a)
9025 (setq a (replace-match subject t t a)))
9027 (apply cmd (nreverse args1))))
9029 ((member type '("http" "https" "ftp" "news"))
9030 (browse-url (concat type ":" (org-link-escape
9031 path org-link-escape-chars-browser))))
9033 ((string= type "doi")
9034 (browse-url (concat "http://dx.doi.org/"
9036 path org-link-escape-chars-browser))))
9038 ((member type '("message"))
9039 (browse-url (concat type ":" path)))
9041 ((string= type "tags")
9042 (org-tags-view in-emacs path))
9044 ((string= type "tree-match")
9045 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9047 ((string= type "file")
9048 (if (string-match "::\\([0-9]+\\)\\'" path)
9049 (setq line (string-to-number (match-string 1 path))
9050 path (substring path 0 (match-beginning 0)))
9051 (if (string-match "::\\(.+\\)\\'" path)
9052 (setq search (match-string 1 path)
9053 path (substring path 0 (match-beginning 0)))))
9054 (if (string-match "[*?{]" (file-name-nondirectory path))
9056 (org-open-file path in-emacs line search)))
9058 ((string= type "news")
9060 (org-gnus-follow-link path))
9062 ((string= type "shell")
9064 (if (or (not org-confirm-shell-link-function)
9065 (funcall org-confirm-shell-link-function
9066 (format "Execute \"%s\" in shell? "
9067 (org-add-props cmd nil
9068 'face 'org-warning))))
9070 (message "Executing %s" cmd)
9071 (shell-command cmd))
9074 ((string= type "elisp")
9076 (if (or (not org-confirm-elisp-link-function)
9077 (funcall org-confirm-elisp-link-function
9078 (format "Execute \"%s\" as elisp? "
9079 (org-add-props cmd nil
9080 'face 'org-warning))))
9081 (message "%s => %s" cmd
9082 (if (equal (string-to-char cmd) ?\()
9084 (call-interactively (read cmd))))
9087 ((and (string= type "thisfile")
9088 (run-hook-with-args-until-success
9089 'org-open-link-functions path)))
9091 ((string= type "thisfile")
9093 (switch-to-buffer-other-window
9094 (org-get-buffer-for-internal-link (current-buffer)))
9095 (org-mark-ring-push))
9096 (let ((cmd `(org-link-search
9098 ,(cond ((equal in-emacs '(4)) 'occur)
9099 ((equal in-emacs '(16)) 'org-occur)
9102 (condition-case nil (eval cmd)
9103 (error (progn (widen) (eval cmd))))))
9106 (browse-url-at-point)))))))
9107 (move-marker org-open-link-marker nil)
9108 (run-hook-with-args 'org-follow-link-hook)))
9110 (defun org-offer-links-in-entry (&optional nth zero)
9111 "Offer links in the current entry and follow the selected link.
9112 If there is only one link, follow it immediately as well.
9113 If NTH is an integer, immediately pick the NTH link found.
9114 If ZERO is a string, check also this string for a link, and if
9115 there is one, offer it as link number zero."
9116 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
9117 "\\(" org-angle-link-re "\\)\\|"
9118 "\\(" org-plain-link-re "\\)"))
9120 (in-emacs (if (integerp nth) nil nth))
9121 have-zero end links link c)
9122 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
9123 (push (match-string 0 zero) links)
9124 (setq cnt (1- cnt) have-zero t))
9126 (org-back-to-heading t)
9127 (setq end (save-excursion (outline-next-heading) (point)))
9128 (while (re-search-forward re end t)
9129 (push (match-string 0) links))
9130 (setq links (org-uniquify (reverse links))))
9134 (message "No links"))
9135 ((equal (length links) 1)
9136 (setq link (list (car links))))
9137 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
9138 (setq link (nth (if have-zero nth (1- nth)) links)))
9139 (t ; we have to select a link
9141 (save-window-excursion
9142 (delete-other-windows)
9143 (with-output-to-temp-buffer "*Select Link*"
9145 (if (not (string-match org-bracket-link-regexp l))
9146 (princ (format "[%c] %s\n" (incf cnt)
9147 (org-remove-angle-brackets l)))
9149 (princ (format "[%c] %s (%s)\n" (incf cnt)
9150 (match-string 3 l) (match-string 1 l)))
9151 (princ (format "[%c] %s\n" (incf cnt)
9152 (match-string 1 l))))))
9154 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
9155 (message "Select link to open, RET to open all:")
9156 (setq c (read-char-exclusive))
9157 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
9158 (when (equal c ?q) (error "Abort"))
9162 (if have-zero (setq nth (1+ nth)))
9163 (unless (and (integerp nth) (>= (length links) nth))
9164 (error "Invalid link selection"))
9165 (setq link (list (nth (1- nth) links))))))
9167 (let ((buf (current-buffer)))
9169 (org-open-link-from-string l in-emacs buf))
9173 ;; Add special file links that specify the way of opening
9175 (org-add-link-type "file+sys" 'org-open-file-with-system)
9176 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
9177 (defun org-open-file-with-system (path)
9178 "Open file at PATH using the system way of opeing it."
9179 (org-open-file path 'system))
9180 (defun org-open-file-with-emacs (path)
9181 "Open file at PATH in emacs."
9182 (org-open-file path 'emacs))
9183 (defun org-remove-file-link-modifiers ()
9184 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
9185 (goto-char (point-min))
9186 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
9188 (replace-match "file:" t t))))
9189 (eval-after-load "org-exp"
9190 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
9191 'org-remove-file-link-modifiers))
9195 (defun org-get-effort (&optional pom)
9196 "Get the effort estimate for the current entry."
9197 (org-entry-get pom org-effort-property))
9201 (defvar org-create-file-search-functions nil
9202 "List of functions to construct the right search string for a file link.
9203 These functions are called in turn with point at the location to
9204 which the link should point.
9206 A function in the hook should first test if it would like to
9207 handle this file type, for example by checking the major-mode or
9208 the file extension. If it decides not to handle this file, it
9209 should just return nil to give other functions a chance. If it
9210 does handle the file, it must return the search string to be used
9211 when following the link. The search string will be part of the
9212 file link, given after a double colon, and `org-open-at-point'
9213 will automatically search for it. If special measures must be
9214 taken to make the search successful, another function should be
9215 added to the companion hook `org-execute-file-search-functions',
9218 A function in this hook may also use `setq' to set the variable
9219 `description' to provide a suggestion for the descriptive text to
9220 be used for this link when it gets inserted into an Org-mode
9221 buffer with \\[org-insert-link].")
9223 (defvar org-execute-file-search-functions nil
9224 "List of functions to execute a file search triggered by a link.
9226 Functions added to this hook must accept a single argument, the
9227 search string that was part of the file link, the part after the
9228 double colon. The function must first check if it would like to
9229 handle this search, for example by checking the major-mode or the
9230 file extension. If it decides not to handle this search, it
9231 should just return nil to give other functions a chance. If it
9232 does handle the search, it must return a non-nil value to keep
9233 other functions from trying.
9235 Each function can access the current prefix argument through the
9236 variable `current-prefix-argument'. Note that a single prefix is
9237 used to force opening a link in Emacs, so it may be good to only
9238 use a numeric or double prefix to guide the search function.
9240 In case this is needed, a function in this hook can also restore
9241 the window configuration before `org-open-at-point' was called using:
9243 (set-window-configuration org-window-config-before-follow-link)")
9245 (defun org-link-search (s &optional type avoid-pos)
9246 "Search for a link search option.
9247 If S is surrounded by forward slashes, it is interpreted as a
9248 regular expression. In org-mode files, this will create an `org-occur'
9249 sparse tree. In ordinary files, `occur' will be used to list matches.
9250 If the current buffer is in `dired-mode', grep will be used to search
9251 in all files. If AVOID-POS is given, ignore matches near that position."
9252 (let ((case-fold-search t)
9253 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
9254 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
9255 (append '(("") (" ") ("\t") ("\n"))
9259 (pre nil) (post nil)
9260 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
9262 ;; First check if there are any special
9263 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
9264 ;; Now try the builtin stuff
9265 ((and (equal (string-to-char s0) ?#)
9268 (goto-char (point-min))
9271 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
9272 (setq type 'dedicated
9273 pos (match-beginning 0))))
9274 ;; There is an exact target for this
9276 (org-back-to-heading t)))
9278 (goto-char (point-min))
9281 (concat "<<" (regexp-quote s0) ">>") nil t)
9282 (setq type 'dedicated
9283 pos (match-beginning 0))))
9284 ;; There is an exact target for this
9286 ((and (string-match "^(\\(.*\\))$" s0)
9288 (goto-char (point-min))
9291 (concat "[^[]" (regexp-quote
9292 (format org-coderef-label-format
9293 (match-string 1 s0))))
9295 (setq type 'dedicated
9296 pos (1+ (match-beginning 0))))))
9297 ;; There is a coderef target for this
9299 ((string-match "^/\\(.*\\)/$" s)
9300 ;; A regular expression
9303 (org-occur (match-string 1 s)))
9304 ;;((eq major-mode 'dired-mode)
9305 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9306 (t (org-do-occur (match-string 1 s)))))
9308 ;; A normal search strings
9309 (when (equal (string-to-char s) ?*)
9310 ;; Anchor on headlines, post may include tags.
9311 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
9312 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
9314 (remove-text-properties
9316 '(face nil mouse-face nil keymap nil fontified nil) s)
9317 ;; Make a series of regular expressions to find a match
9318 (setq words (org-split-string s "[ \n\r\t]+")
9320 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
9321 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9323 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9324 re2a (concat "[ \t\r\n]" re2a_)
9325 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9326 re4 (concat "[^a-zA-Z_]" re4_)
9328 re1 (concat pre re2 post)
9329 re3 (concat pre (if pre re4_ re4) post)
9330 re5 (concat pre ".*" re4)
9331 re2 (concat pre re2)
9332 re2a (concat pre (if pre re2a_ re2a))
9333 re4 (concat pre (if pre re4_ re4))
9334 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9335 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9339 ((eq type 'org-occur) (org-occur reall))
9340 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9341 (t (goto-char (point-min))
9343 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9344 (org-search-not-self 1 re1 nil t)
9345 (org-search-not-self 1 re2 nil t)
9346 (org-search-not-self 1 re2a nil t)
9347 (org-search-not-self 1 re3 nil t)
9348 (org-search-not-self 1 re4 nil t)
9349 (org-search-not-self 1 re5 nil t)
9351 (goto-char (match-beginning 1))
9353 (error "No match")))))
9355 ;; Normal string-search
9356 (goto-char (point-min))
9357 (if (search-forward s nil t)
9358 (goto-char (match-beginning 0))
9359 (error "No match"))))
9360 (and (org-mode-p) (org-show-context 'link-search))
9363 (defun org-search-not-self (group &rest args)
9364 "Execute `re-search-forward', but only accept matches that do not
9365 enclose the position of `org-open-link-marker'."
9366 (let ((m org-open-link-marker))
9368 (while (apply 're-search-forward args)
9369 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9370 (goto-char (match-end group))
9371 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9372 (> (match-beginning 0) (marker-position m))
9373 (< (match-end 0) (marker-position m)))
9375 (or (not (org-in-regexp
9376 org-bracket-link-analytic-regexp 1))
9377 (not (match-end 4)) ; no description
9378 (and (<= (match-beginning 4) (point))
9379 (>= (match-end 4) (point))))))
9380 (throw 'exit (point))))))))
9382 (defun org-get-buffer-for-internal-link (buffer)
9383 "Return a buffer to be used for displaying the link target of internal links."
9385 ((not org-display-internal-link-with-indirect-buffer)
9387 ((string-match "(Clone)$" (buffer-name buffer))
9388 (message "Buffer is already a clone, not making another one")
9389 ;; we also do not modify visibility in this case
9391 (t ; make a new indirect buffer for displaying the link
9392 (let* ((bn (buffer-name buffer))
9393 (ibn (concat bn "(Clone)"))
9394 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9395 (with-current-buffer ib (org-overview))
9398 (defun org-do-occur (regexp &optional cleanup)
9399 "Call the Emacs command `occur'.
9400 If CLEANUP is non-nil, remove the printout of the regular expression
9401 in the *Occur* buffer. This is useful if the regex is long and not useful
9405 (let ((cwin (selected-window)) win beg end)
9406 (when (setq win (get-buffer-window "*Occur*"))
9407 (select-window win))
9408 (goto-char (point-min))
9409 (when (re-search-forward "match[a-z]+" nil t)
9410 (setq beg (match-end 0))
9411 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9412 (setq end (1- (match-beginning 0)))))
9413 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9414 (goto-char (point-min))
9415 (select-window cwin))))
9417 ;;; The mark ring for links jumps
9419 (defvar org-mark-ring nil
9420 "Mark ring for positions before jumps in Org-mode.")
9421 (defvar org-mark-ring-last-goto nil
9422 "Last position in the mark ring used to go back.")
9423 ;; Fill and close the ring
9424 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9425 (loop for i from 1 to org-mark-ring-length do
9426 (push (make-marker) org-mark-ring))
9427 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9430 (defun org-mark-ring-push (&optional pos buffer)
9431 "Put the current position or POS into the mark ring and rotate it."
9433 (setq pos (or pos (point)))
9434 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9435 (move-marker (car org-mark-ring)
9437 (or buffer (current-buffer)))
9439 (substitute-command-keys
9440 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9442 (defun org-mark-ring-goto (&optional n)
9443 "Jump to the previous position in the mark ring.
9444 With prefix arg N, jump back that many stored positions. When
9445 called several times in succession, walk through the entire ring.
9446 Org-mode commands jumping to a different position in the current file,
9447 or to another Org-mode file, automatically push the old position
9451 (if (eq last-command this-command)
9452 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9453 (setq p org-mark-ring))
9454 (setq org-mark-ring-last-goto p)
9456 (switch-to-buffer (marker-buffer m))
9458 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9460 (defun org-remove-angle-brackets (s)
9461 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9462 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9464 (defun org-add-angle-brackets (s)
9465 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9466 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9468 (defun org-remove-double-quotes (s)
9469 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9470 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9473 ;;; Following specific links
9475 (defun org-follow-timestamp-link ()
9477 ((org-at-date-range-p t)
9478 (let ((org-agenda-start-on-weekday)
9479 (t1 (match-string 1))
9480 (t2 (match-string 2)))
9481 (setq t1 (time-to-days (org-time-string-to-time t1))
9482 t2 (time-to-days (org-time-string-to-time t2)))
9483 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9484 ((org-at-timestamp-p t)
9485 (org-agenda-list nil (time-to-days (org-time-string-to-time
9486 (substring (match-string 1) 0 10)))
9488 (t (error "This should not happen"))))
9491 ;;; Following file links
9492 (defvar org-wait nil)
9493 (defun org-open-file (path &optional in-emacs line search)
9494 "Open the file at PATH.
9495 First, this expands any special file name abbreviations. Then the
9496 configuration variable `org-file-apps' is checked if it contains an
9497 entry for this file type, and if yes, the corresponding command is launched.
9499 If no application is found, Emacs simply visits the file.
9501 With optional prefix argument IN-EMACS, Emacs will visit the file.
9502 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9503 and to use an external application to visit the file.
9505 Optional LINE specifies a line to go to, optional SEARCH a string
9506 to search for. If LINE or SEARCH is given, the file will be
9507 opened in Emacs, unless an entry from org-file-apps that makes
9508 use of groups in a regexp matches.
9509 If the file does not exist, an error is thrown."
9510 (let* ((file (if (equal path "")
9512 (substitute-in-file-name (expand-file-name path))))
9513 (file-apps (append org-file-apps (org-default-apps)))
9514 (apps (org-remove-if
9515 'org-file-apps-entry-match-against-dlink-p file-apps))
9516 (apps-dlink (org-remove-if-not
9517 'org-file-apps-entry-match-against-dlink-p file-apps))
9518 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9519 (dirp (if remp nil (file-directory-p file)))
9520 (file (if (and dirp org-open-directory-means-index-dot-org)
9521 (concat (file-name-as-directory file) "index.org")
9523 (a-m-a-p (assq 'auto-mode apps))
9524 (dfile (downcase file))
9525 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9526 (link (cond ((and (eq line nil)
9530 (concat file "::" (number-to-string line)))
9532 (concat file "::" search))))
9533 (dlink (downcase link))
9534 (old-buffer (current-buffer))
9536 (old-mode major-mode)
9537 ext cmd link-match-data)
9538 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9539 (setq ext (match-string 1 dfile))
9540 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9541 (setq ext (match-string 1 dfile))))
9543 ((member in-emacs '((16) system))
9544 (setq cmd (cdr (assoc 'system apps))))
9545 (in-emacs (setq cmd 'emacs))
9547 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9548 (and dirp (cdr (assoc 'directory apps)))
9549 ; first, try matching against apps-dlink
9550 ; if we get a match here, store the match data for later
9551 (let ((match (assoc-default dlink apps-dlink
9554 (progn (setq link-match-data (match-data))
9556 (progn (setq in-emacs (or in-emacs line search))
9557 nil))) ; if we have no match in apps-dlink,
9558 ; always open the file in emacs if line or search
9559 ; is given (for backwards compatibility)
9560 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9562 (cdr (assoc ext apps))
9563 (cdr (assoc t apps))))))
9564 (when (eq cmd 'system)
9565 (setq cmd (cdr (assoc 'system apps))))
9566 (when (eq cmd 'default)
9567 (setq cmd (cdr (assoc t apps))))
9568 (when (eq cmd 'mailcap)
9570 (mailcap-parse-mailcaps)
9571 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9572 (command (mailcap-mime-info mime-type)))
9573 (if (stringp command)
9575 (setq cmd 'emacs))))
9576 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9577 (not (file-exists-p file))
9578 (not org-open-non-existing-files))
9579 (error "No such file: %s" file))
9581 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9582 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9583 (while (string-match "['\"]%s['\"]" cmd)
9584 (setq cmd (replace-match "%s" t t cmd)))
9585 (while (string-match "%s" cmd)
9586 (setq cmd (replace-match
9588 (shell-quote-argument
9589 (convert-standard-filename file)))
9592 ;; Replace "%1", "%2" etc. in command with group matches from regex
9594 (let ((match-index 1)
9595 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9596 (set-match-data link-match-data)
9597 (while (<= match-index number-of-groups)
9598 (let ((regex (concat "%" (number-to-string match-index)))
9599 (replace-with (match-string match-index dlink)))
9600 (while (string-match regex cmd)
9601 (setq cmd (replace-match replace-with t t cmd))))
9602 (setq match-index (+ match-index 1)))))
9604 (save-window-excursion
9605 (start-process-shell-command cmd nil cmd)
9606 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9610 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9612 (if line (org-goto-line line)
9613 (if search (org-link-search search))))
9615 (let ((file (convert-standard-filename file)))
9617 (set-match-data link-match-data)
9619 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9620 (and (org-mode-p) (eq old-mode 'org-mode)
9621 (or (not (equal old-buffer (current-buffer)))
9622 (not (equal old-pos (point))))
9623 (org-mark-ring-push old-pos old-buffer))))
9625 (defun org-file-apps-entry-match-against-dlink-p (entry)
9626 "This function returns non-nil if `entry' uses a regular
9627 expression which should be matched against the whole link by
9630 It assumes that is the case when the entry uses a regular
9631 expression which has at least one grouping construct and the
9632 action is either a lisp form or a command string containing
9633 '%1', i.e. using at least one subexpression match as a
9635 (let ((selector (car entry))
9636 (action (cdr entry)))
9637 (if (stringp selector)
9638 (and (> (regexp-opt-depth selector) 0)
9639 (or (and (stringp action)
9640 (string-match "%[0-9]" action))
9644 (defun org-default-apps ()
9645 "Return the default applications for this operating system."
9647 ((eq system-type 'darwin)
9648 org-file-apps-defaults-macosx)
9649 ((eq system-type 'windows-nt)
9650 org-file-apps-defaults-windowsnt)
9651 (t org-file-apps-defaults-gnu)))
9653 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9654 "Convert extensions to regular expressions in the cars of LIST.
9655 Also, weed out any non-string entries, because the return value is used
9656 only for regexp matching.
9657 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9658 point to the symbol `emacs', indicating that the file should
9659 be opened in Emacs."
9663 (if (not (stringp (car x)))
9665 (if (string-match "\\W" (car x))
9667 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9670 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9672 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9673 (defun org-file-remote-p (file)
9674 "Test whether FILE specifies a location on a remote system.
9675 Return non-nil if the location is indeed remote.
9677 For example, the filename \"/user@host:/foo\" specifies a location
9678 on the system \"/user@host:\"."
9679 (cond ((fboundp 'file-remote-p)
9680 (file-remote-p file))
9681 ((fboundp 'tramp-handle-file-remote-p)
9682 (tramp-handle-file-remote-p file))
9683 ((and (boundp 'ange-ftp-name-format)
9684 (string-match (car ange-ftp-name-format) file))
9691 (defun org-get-org-file ()
9692 "Read a filename, with default directory `org-directory'."
9693 (let ((default (or org-default-notes-file remember-data-file)))
9694 (read-file-name (format "File name [%s]: " default)
9695 (file-name-as-directory org-directory)
9698 (defun org-notes-order-reversed-p ()
9699 "Check if the current file should receive notes in reversed order."
9701 ((not org-reverse-note-order) nil)
9702 ((eq t org-reverse-note-order) t)
9703 ((not (listp org-reverse-note-order)) nil)
9705 (let ((all org-reverse-note-order)
9707 (while (setq entry (pop all))
9708 (if (string-match (car entry) buffer-file-name)
9709 (throw 'exit (cdr entry))))
9712 (defvar org-refile-target-table nil
9713 "The list of refile targets, created by `org-refile'.")
9715 (defvar org-agenda-new-buffers nil
9716 "Buffers created to visit agenda files.")
9718 (defvar org-refile-cache nil
9719 "Cache for refile targets.")
9722 (defvar org-refile-markers nil
9723 "All the markers used for caching refile locations.")
9725 (defun org-refile-marker (pos)
9726 "Get a new refile marker, but only if caching is in use."
9727 (if (not org-refile-use-cache)
9729 (let ((m (make-marker)))
9731 (push m org-refile-markers)
9734 (defun org-refile-cache-clear ()
9735 "Clear the refile cache and disable all the markers."
9736 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
9737 (setq org-refile-markers nil)
9738 (setq org-refile-cache nil)
9739 (message "Refile cache has been cleared"))
9741 (defun org-refile-cache-check-set (set)
9742 "Check if all the markers in the cache still have live buffers."
9745 (while (and set (setq marker (nth 3 (pop set))))
9746 ;; if org-refile-use-outline-path is 'file, marker may be nil
9747 (when (and marker (null (marker-buffer marker)))
9748 (message "not found") (sit-for 3)
9752 (defun org-refile-cache-put (set &rest identifiers)
9753 "Push the refile targets SET into the cache, under IDENTIFIERS."
9754 (let* ((key (sha1 (prin1-to-string identifiers)))
9755 (entry (assoc key org-refile-cache)))
9758 (push (cons key set) org-refile-cache))))
9760 (defun org-refile-cache-get (&rest identifiers)
9761 "Retrieve the cached value for refile targets given by IDENTIFIERS."
9763 ((not org-refile-cache) nil)
9764 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
9766 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
9767 org-refile-cache))))
9768 (and set (org-refile-cache-check-set set) set)))))
9770 (defun org-get-refile-targets (&optional default-buffer)
9771 "Produce a table with refile targets."
9772 (let ((case-fold-search nil)
9773 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9774 (entries (or org-refile-targets '((nil . (:level . 1)))))
9775 targets tgs txt re files f desc descre fast-path-p level pos0)
9776 (message "Getting targets...")
9777 (with-current-buffer (or default-buffer (current-buffer))
9778 (while (setq entry (pop entries))
9779 (setq files (car entry) desc (cdr entry))
9780 (setq fast-path-p nil)
9782 ((null files) (setq files (list (current-buffer))))
9783 ((eq files 'org-agenda-files)
9784 (setq files (org-agenda-files 'unrestricted)))
9785 ((and (symbolp files) (fboundp files))
9786 (setq files (funcall files)))
9787 ((and (symbolp files) (boundp files))
9788 (setq files (symbol-value files))))
9789 (if (stringp files) (setq files (list files)))
9791 ((eq (car desc) :tag)
9792 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9793 ((eq (car desc) :todo)
9794 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9795 ((eq (car desc) :regexp)
9796 (setq descre (cdr desc)))
9797 ((eq (car desc) :level)
9798 (setq descre (concat "^\\*\\{" (number-to-string
9799 (if org-odd-levels-only
9800 (1- (* 2 (cdr desc)))
9803 ((eq (car desc) :maxlevel)
9804 (setq fast-path-p t)
9805 (setq descre (concat "^\\*\\{1," (number-to-string
9806 (if org-odd-levels-only
9807 (1- (* 2 (cdr desc)))
9810 (t (error "Bad refiling target description %s" desc)))
9811 (while (setq f (pop files))
9812 (with-current-buffer
9813 (if (bufferp f) f (org-get-agenda-file-buffer f))
9815 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
9817 (if (bufferp f) (setq f (buffer-file-name
9818 (buffer-base-buffer f))))
9819 (setq f (and f (expand-file-name f)))
9820 (if (eq org-refile-use-outline-path 'file)
9821 (push (list (file-name-nondirectory f) f nil nil) tgs))
9825 (goto-char (point-min))
9826 (while (re-search-forward descre nil t)
9827 (goto-char (setq pos0 (point-at-bol)))
9829 (when org-refile-target-verify-function
9831 (or (funcall org-refile-target-verify-function)
9833 (when (looking-at org-complex-heading-regexp)
9834 (setq level (org-reduced-level
9835 (- (match-end 1) (match-beginning 1)))
9836 txt (org-link-display-format (match-string 4))
9837 re (concat "^" (regexp-quote
9841 (if (match-end 5) (setq re (concat
9844 (match-string 5)))))
9845 (setq re (concat re "[ \t]*$"))
9846 (when org-refile-use-outline-path
9847 (setq txt (mapconcat
9850 (if (eq org-refile-use-outline-path
9852 (list (file-name-nondirectory
9854 (buffer-base-buffer))))
9855 (if (eq org-refile-use-outline-path
9857 (list (buffer-file-name
9858 (buffer-base-buffer)))))
9859 (org-get-outline-path fast-path-p
9863 (push (list txt f re (org-refile-marker (point)))
9865 (when (= (point) pos0)
9866 ;; verification function has not moved point
9867 (goto-char (point-at-eol))))))))
9868 (when org-refile-use-cache
9869 (org-refile-cache-put tgs (buffer-file-name) descre))
9870 (setq targets (append tgs targets))
9872 (message "Getting targets...done")
9873 (nreverse targets)))
9875 (defun org-protect-slash (s)
9876 (while (string-match "/" s)
9877 (setq s (replace-match "\\" t t s)))
9880 (defvar org-olpa (make-vector 20 nil))
9882 (defun org-get-outline-path (&optional fastp level heading)
9883 "Return the outline path to the current entry, as a list.
9885 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
9886 routine which makes outline path derivations for an entire file,
9887 avoiding backtracing. Refile target collection makes use of that."
9891 (error "Outline path failure, more than 19 levels."))
9892 (loop for i from level upto 19 do
9893 (aset org-olpa i nil))
9895 (delq nil (append org-olpa nil))
9896 (aset org-olpa level heading)))
9897 (let (rtn case-fold-search)
9901 (while (org-up-heading-safe)
9902 (when (looking-at org-complex-heading-regexp)
9903 (push (org-match-string-no-properties 4) rtn)))
9906 (defun org-format-outline-path (path &optional width prefix)
9907 "Format the outlie path PATH for display.
9908 Width is the maximum number of characters that is available.
9909 Prefix is a prefix to be included in the returned string,
9910 such as the file name."
9911 (setq width (or width 79))
9912 (if prefix (setq width (- width (length prefix))))
9915 (let* ((nsteps (length path))
9916 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9917 (maxwidth (if (<= total-width width)
9918 10000 ;; everything fits
9919 ;; we need to shorten the level headings
9920 (/ (- width nsteps) nsteps)))
9921 (org-odd-levels-only nil)
9923 (total (1+ (length prefix))))
9924 (setq maxwidth (max maxwidth 10))
9929 (if (and (= n nsteps) (< maxwidth 10000))
9930 (setq maxwidth (- total-width total)))
9931 (if (< (length h) maxwidth)
9932 (progn (setq total (+ total (length h) 1)) h)
9933 (setq h (substring h 0 (- maxwidth 2))
9934 total (+ total maxwidth 1))
9935 (if (string-match "[ \t]+\\'" h)
9936 (setq h (substring h 0 (match-beginning 0))))
9937 (setq h (concat h "..")))
9938 (org-add-props h nil 'face
9939 (nth (% (1- n) org-n-level-faces)
9944 (defun org-display-outline-path (&optional file current)
9945 "Display the current outline path in the echo area."
9947 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9948 (case-fold-search nil)
9949 (path (and (org-mode-p) (org-get-outline-path))))
9950 (if current (setq path (append path
9952 (org-back-to-heading t)
9953 (if (looking-at org-complex-heading-regexp)
9954 (list (match-string 4)))))))
9956 (org-format-outline-path
9959 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9961 (defvar org-refile-history nil
9962 "History for refiling operations.")
9964 (defvar org-after-refile-insert-hook nil
9965 "Hook run after `org-refile' has inserted its stuff at the new location.
9966 Note that this is still *before* the stuff will be removed from
9967 the *old* location.")
9969 (defun org-refile (&optional goto default-buffer rfloc)
9970 "Move the entry at point to another heading.
9971 The list of target headings is compiled using the information in
9972 `org-refile-targets', which see. This list is created before each use
9973 and will therefore always be up-to-date.
9975 At the target location, the entry is filed as a subitem of the target heading.
9976 Depending on `org-reverse-note-order', the new subitem will either be the
9977 first or the last subitem.
9979 If there is an active region, all entries in that region will be moved.
9980 However, the region must fulfil the requirement that the first heading
9981 is the first one sets the top-level of the moved text - at most siblings
9982 below it are allowed.
9984 With prefix arg GOTO, the command will only visit the target location,
9985 not actually move anything.
9986 With a double prefix `C-u C-u', go to the location where the last refiling
9987 operation has put the subtree.
9988 With a prefix argument of `2', refile to the running clock.
9990 RFLOC can be a refile location obtained in a different way.
9992 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
9994 If you are using target caching (see `org-refile-use-cache'),
9995 You have to clear the target cache in order to find new targets.
9996 This can be done with a 0 prefix: `C-0 C-c C-w'"
9998 (if (member goto '(0 (64)))
9999 (org-refile-cache-clear)
10000 (let* ((cbuf (current-buffer))
10001 (regionp (org-region-active-p))
10002 (region-start (and regionp (region-beginning)))
10003 (region-end (and regionp (region-end)))
10004 (region-length (and regionp (- region-end region-start)))
10005 (filename (buffer-file-name (buffer-base-buffer cbuf)))
10006 pos it nbuf file re level reversed)
10007 (setq last-command nil)
10009 (goto-char region-start)
10010 (or (bolp) (goto-char (point-at-bol)))
10011 (setq region-start (point))
10012 (unless (org-kill-is-subtree-p
10013 (buffer-substring region-start region-end))
10014 (error "The region is not a (sequence of) subtree(s)")))
10015 (if (equal goto '(16))
10016 (org-refile-goto-last-stored)
10018 (and (equal goto 2)
10019 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10021 (setq it (list (or org-clock-heading "running clock")
10023 (marker-buffer org-clock-hd-marker))
10025 (marker-position org-clock-hd-marker)))
10029 (org-refile-get-location
10030 (if goto "Goto: " "Refile to: ") default-buffer
10031 org-refile-allow-creating-parent-nodes)))))
10032 (setq file (nth 1 it)
10035 (if (and (not goto)
10037 (equal (buffer-file-name) file)
10039 (and (>= pos region-start)
10040 (<= pos region-end))
10041 (and (>= pos (point))
10042 (< pos (save-excursion
10043 (org-end-of-subtree t t))))))
10044 (error "Cannot refile to position inside the tree or region"))
10046 (setq nbuf (or (find-buffer-visiting file)
10047 (find-file-noselect file)))
10050 (switch-to-buffer nbuf)
10052 (org-show-context 'org-goto))
10055 (org-kill-new (buffer-substring region-start region-end))
10056 (org-save-markers-in-region region-start region-end))
10057 (org-copy-subtree 1 nil t))
10058 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
10059 (find-file-noselect file)))
10060 (setq reversed (org-notes-order-reversed-p))
10067 (looking-at outline-regexp)
10068 (setq level (org-get-valid-level (funcall outline-level) 1))
10071 (or (outline-next-heading) (point-max))
10072 (or (save-excursion (org-get-next-sibling))
10073 (org-end-of-subtree t t)
10077 (goto-char (point-max))
10078 (goto-char (point-min))
10079 (or (outline-next-heading) (goto-char (point-max)))))
10080 (if (not (bolp)) (newline))
10081 (org-paste-subtree level)
10082 (when org-log-refile
10083 (org-add-log-setup 'refile nil nil 'findpos
10085 (unless (eq org-log-refile 'note)
10086 (save-excursion (org-add-log-note))))
10087 (and org-auto-align-tags (org-set-tags nil t))
10088 (bookmark-set "org-refile-last-stored")
10089 (if (fboundp 'deactivate-mark) (deactivate-mark))
10090 (run-hooks 'org-after-refile-insert-hook))))
10092 (delete-region (point) (+ (point) region-length))
10094 (when (featurep 'org-inlinetask)
10095 (org-inlinetask-remove-END-maybe))
10096 (setq org-markers-to-move nil)
10097 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
10099 (defun org-refile-goto-last-stored ()
10100 "Go to the location where the last refile was stored."
10102 (bookmark-jump "org-refile-last-stored")
10103 (message "This is the location of the last refile"))
10105 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
10106 "Prompt the user for a refile location, using PROMPT."
10107 (let ((org-refile-targets org-refile-targets)
10108 (org-refile-use-outline-path org-refile-use-outline-path))
10109 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
10110 (unless org-refile-target-table
10111 (error "No refile targets"))
10112 (let* ((cbuf (current-buffer))
10113 (partial-completion-mode nil)
10114 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
10115 (cfunc (if (and org-refile-use-outline-path
10116 org-outline-path-complete-in-steps)
10117 'org-olpath-completing-read
10118 'org-icompleting-read))
10119 (extra (if org-refile-use-outline-path "/" ""))
10120 (filename (and cfn (expand-file-name cfn)))
10123 (if (and (not (member org-refile-use-outline-path
10124 '(file full-file-path)))
10125 (not (equal filename (nth 1 x))))
10126 (cons (concat (car x) extra " ("
10127 (file-name-nondirectory (nth 1 x)) ")")
10129 (cons (concat (car x) extra) (cdr x))))
10130 org-refile-target-table))
10131 (completion-ignore-case t)
10132 pa answ parent-target child parent old-hist)
10133 (setq old-hist org-refile-history)
10134 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
10135 nil 'org-refile-history))
10136 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
10139 (when (or (not org-refile-history)
10140 (not (eq old-hist org-refile-history))
10141 (not (equal (car pa) (car org-refile-history))))
10142 (setq org-refile-history
10143 (cons (car pa) (if (assoc (car org-refile-history) tbl)
10145 (cdr org-refile-history))))
10146 (if (equal (car org-refile-history) (nth 1 org-refile-history))
10147 (pop org-refile-history)))
10149 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
10151 (setq parent (match-string 1 answ)
10152 child (match-string 2 answ))
10153 (setq parent-target (or (assoc parent tbl)
10154 (assoc (concat parent "/") tbl)))
10155 (when (and parent-target
10156 (or (eq new-nodes t)
10157 (and (eq new-nodes 'confirm)
10158 (y-or-n-p (format "Create new node \"%s\"? "
10160 (org-refile-new-child parent-target child)))
10161 (error "Invalid target location")))))
10163 (defun org-refile-new-child (parent-target child)
10164 "Use refile target PARENT-TARGET to add new CHILD below it."
10165 (unless parent-target
10166 (error "Cannot find parent for new node"))
10167 (let ((file (nth 1 parent-target))
10168 (pos (nth 3 parent-target))
10170 (with-current-buffer (or (find-buffer-visiting file)
10171 (find-file-noselect file))
10177 (goto-char (point-max))
10178 (if (not (bolp)) (newline)))
10179 (when (looking-at outline-regexp)
10180 (setq level (funcall outline-level))
10181 (org-end-of-subtree t t))
10182 (org-back-over-empty-lines)
10183 (insert "\n" (make-string
10184 (if pos (org-get-valid-level level 1) 1) ?*)
10186 (beginning-of-line 0)
10187 (list (concat (car parent-target) "/" child) file "" (point)))))))
10189 (defun org-olpath-completing-read (prompt collection &rest args)
10190 "Read an outline path like a file name."
10191 (let ((thetable collection)
10192 (org-completion-use-ido nil) ; does not work with ido.
10193 (org-completion-use-iswitchb nil)) ; or iswitchb
10195 'org-icompleting-read prompt
10196 (lambda (string predicate &optional flag)
10197 (let (rtn r f (l (length string)))
10201 (try-completion string thetable))
10204 (setq rtn (all-completions string thetable predicate))
10207 (setq r (substring x l))
10208 (if (string-match " ([^)]*)$" x)
10209 (setq f (match-string 0 x))
10211 (if (string-match "/" r)
10212 (concat string (substring r 0 (match-end 0)) f)
10217 (assoc string thetable)))
10221 ;;;; Dynamic blocks
10223 (defun org-find-dblock (name)
10224 "Find the first dynamic block with name NAME in the buffer.
10225 If not found, stay at current position and return nil."
10228 (goto-char (point-min))
10229 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
10231 (match-beginning 0))))
10232 (if pos (goto-char pos))
10235 (defconst org-dblock-start-re
10236 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
10237 "Matches the start line of a dynamic block, with parameters.")
10239 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
10240 "Matches the end of a dynamic block.")
10242 (defun org-create-dblock (plist)
10243 "Create a dynamic block section, with parameters taken from PLIST.
10244 PLIST must contain a :name entry which is used as name of the block."
10245 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
10248 (let ((col (current-column))
10249 (name (plist-get plist :name)))
10250 (insert "#+BEGIN: " name)
10252 (if (eq (car plist) :name)
10253 (setq plist (cddr plist))
10254 (insert " " (prin1-to-string (pop plist)))))
10255 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
10256 (beginning-of-line -2)))
10258 (defun org-prepare-dblock ()
10259 "Prepare dynamic block for refresh.
10260 This empties the block, puts the cursor at the insert position and returns
10261 the property list including an extra property :name with the block name."
10262 (unless (looking-at org-dblock-start-re)
10263 (error "Not at a dynamic block"))
10264 (let* ((begdel (1+ (match-end 0)))
10265 (name (org-no-properties (match-string 1)))
10266 (params (append (list :name name)
10267 (read (concat "(" (match-string 3) ")")))))
10269 (beginning-of-line 1)
10270 (skip-chars-forward " \t")
10271 (setq params (plist-put params :indentation-column (current-column))))
10272 (unless (re-search-forward org-dblock-end-re nil t)
10273 (error "Dynamic block not terminated"))
10276 (list :content (buffer-substring
10277 begdel (match-beginning 0)))))
10278 (delete-region begdel (match-beginning 0))
10283 (defun org-map-dblocks (&optional command)
10284 "Apply COMMAND to all dynamic blocks in the current buffer.
10285 If COMMAND is not given, use `org-update-dblock'."
10286 (let ((cmd (or command 'org-update-dblock)))
10288 (goto-char (point-min))
10289 (while (re-search-forward org-dblock-start-re nil t)
10290 (goto-char (match-beginning 0))
10292 (condition-case nil
10294 (error (message "Error during update of dynamic block"))))
10295 (unless (re-search-forward org-dblock-end-re nil t)
10296 (error "Dynamic block not terminated"))))))
10298 (defun org-dblock-update (&optional arg)
10299 "User command for updating dynamic blocks.
10300 Update the dynamic block at point. With prefix ARG, update all dynamic
10301 blocks in the buffer."
10304 (org-update-all-dblocks)
10305 (or (looking-at org-dblock-start-re)
10306 (org-beginning-of-dblock))
10307 (org-update-dblock)))
10309 (defun org-update-dblock ()
10310 "Update the dynamic block at point
10311 This means to empty the block, parse for parameters and then call
10312 the correct writing function."
10313 (save-window-excursion
10314 (let* ((pos (point))
10315 (line (org-current-line))
10316 (params (org-prepare-dblock))
10317 (name (plist-get params :name))
10318 (indent (plist-get params :indentation-column))
10319 (cmd (intern (concat "org-dblock-write:" name))))
10320 (message "Updating dynamic block `%s' at line %d..." name line)
10321 (funcall cmd params)
10322 (message "Updating dynamic block `%s' at line %d...done" name line)
10324 (when (and indent (> indent 0))
10325 (setq indent (make-string indent ?\ ))
10327 (org-beginning-of-dblock)
10329 (while (not (looking-at org-dblock-end-re))
10331 (beginning-of-line 2))
10332 (when (looking-at org-dblock-end-re)
10333 (and (looking-at "[ \t]+")
10334 (replace-match ""))
10335 (insert indent)))))))
10337 (defun org-beginning-of-dblock ()
10338 "Find the beginning of the dynamic block at point.
10339 Error if there is no such block at point."
10340 (let ((pos (point))
10343 (if (and (re-search-backward org-dblock-start-re nil t)
10344 (setq beg (match-beginning 0))
10345 (re-search-forward org-dblock-end-re nil t)
10346 (> (match-end 0) pos))
10349 (error "Not in a dynamic block"))))
10351 (defun org-update-all-dblocks ()
10352 "Update all dynamic blocks in the buffer.
10353 This function can be used in a hook."
10355 (org-map-dblocks 'org-update-dblock)))
10360 (defconst org-additional-option-like-keywords
10361 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
10362 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
10363 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
10364 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
10366 "ORGTBL" "TBLFM:" "TBLNAME:"
10367 "BEGIN_EXAMPLE" "END_EXAMPLE"
10368 "BEGIN_QUOTE" "END_QUOTE"
10369 "BEGIN_VERSE" "END_VERSE"
10370 "BEGIN_CENTER" "END_CENTER"
10371 "BEGIN_SRC" "END_SRC"
10372 "CATEGORY" "COLUMNS"
10378 (defcustom org-structure-template-alist
10380 ("s" "#+begin_src ?\n\n#+end_src"
10381 "<src lang=\"?\">\n\n</src>")
10382 ("e" "#+begin_example\n?\n#+end_example"
10383 "<example>\n?\n</example>")
10384 ("q" "#+begin_quote\n?\n#+end_quote"
10385 "<quote>\n?\n</quote>")
10386 ("v" "#+begin_verse\n?\n#+end_verse"
10387 "<verse>\n?\n/verse>")
10388 ("c" "#+begin_center\n?\n#+end_center"
10389 "<center>\n?\n/center>")
10390 ("l" "#+begin_latex\n?\n#+end_latex"
10391 "<literal style=\"latex\">\n?\n</literal>")
10393 "<literal style=\"latex\">?</literal>")
10394 ("h" "#+begin_html\n?\n#+end_html"
10395 "<literal style=\"html\">\n?\n</literal>")
10397 "<literal style=\"html\">?</literal>")
10398 ("a" "#+begin_ascii\n?\n#+end_ascii")
10400 ("i" "#+include %file ?"
10401 "<include file=%file markup=\"?\">")
10403 "Structure completion elements.
10404 This is a list of abbreviation keys and values. The value gets inserted
10405 if you type `<' followed by the key and then press the completion key,
10406 usually `M-TAB'. %file will be replaced by a file name after prompting
10407 for the file using completion.
10408 There are two templates for each key, the first uses the original Org syntax,
10409 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
10410 the default when the /org-mtags.el/ module has been loaded. See also the
10411 variable `org-mtags-prefer-muse-templates'.
10412 This is an experimental feature, it is undecided if it is going to stay in."
10413 :group 'org-completion
10415 (string :tag "Key")
10416 (string :tag "Template")
10417 (string :tag "Muse Template")))
10419 (defun org-try-structure-completion ()
10420 "Try to complete a structure template before point.
10421 This looks for strings like \"<e\" on an otherwise empty line and
10423 (let ((l (buffer-substring (point-at-bol) (point)))
10425 (when (and (looking-at "[ \t]*$")
10426 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
10427 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
10428 (org-complete-expand-structure-template (+ -1 (point-at-bol)
10429 (match-beginning 1)) a)
10432 (defun org-complete-expand-structure-template (start cell)
10433 "Expand a structure template."
10434 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10435 (rpl (nth (if musep 2 1) cell))
10437 (delete-region start (point))
10438 (when (string-match "\\`#\\+" rpl)
10441 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10442 (setq ind (buffer-substring (point-at-bol) (point))))
10444 (setq start (point))
10445 (if (string-match "%file" rpl)
10446 (setq rpl (replace-match
10450 (abbreviate-file-name (read-file-name "Include file: ")))
10453 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10454 (concat "\n" ind)))
10456 (if (re-search-backward "\\?" start t) (delete-char 1))))
10459 (defun org-complete (&optional arg)
10460 "Perform completion on word at point.
10461 At the beginning of a headline, this completes TODO keywords as given in
10462 `org-todo-keywords'.
10463 If the current word is preceded by a backslash, completes the TeX symbols
10464 that are supported for HTML support.
10465 If the current word is preceded by \"#+\", completes special words for
10466 setting file options.
10467 In the line after \"#+STARTUP:, complete valid keywords.\"
10468 At all other locations, this simply calls the value of
10469 `org-completion-fallback-command'."
10471 (org-without-partial-completion
10475 (beg1 (save-excursion
10476 (skip-chars-backward (org-re "[:alnum:]_@"))
10478 (beg (save-excursion
10479 (skip-chars-backward "a-zA-Z0-9_:$")
10481 (confirm (lambda (x) (stringp (car x))))
10482 (searchhead (equal (char-before beg) ?*))
10484 (when (and (member (char-before beg1) '(?. ?<))
10485 (setq a (assoc (buffer-substring beg1 (point))
10486 org-structure-template-alist)))
10487 (org-complete-expand-structure-template (1- beg1) a)
10489 (tag (and (equal (char-before beg1) ?:)
10490 (equal (char-after (point-at-bol)) ?*)))
10491 (prop (and (equal (char-before beg1) ?:)
10492 (not (equal (char-after (point-at-bol)) ?*))))
10493 (texp (equal (char-before beg) ?\\))
10494 (link (equal (char-before beg) ?\[))
10495 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10498 (startup (string-match "^#\\+STARTUP:.*"
10499 (buffer-substring (point-at-bol) (point))))
10500 (completion-ignore-case opt)
10512 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10513 (cons (match-string 2 x)
10514 (match-string 1 x))))
10515 (org-split-string (org-get-current-options) "\n")))
10516 (mapcar 'list org-additional-option-like-keywords)))
10518 (setq type :startup)
10519 org-startup-options)
10520 (link (append org-link-abbrev-alist-local
10521 org-link-abbrev-alist))
10524 (append org-entities-user org-entities))
10525 ((string-match "\\`\\*+[ \t]+\\'"
10526 (buffer-substring (point-at-bol) beg))
10528 (mapcar 'list org-todo-keywords-1))
10530 (setq type :searchhead)
10532 (goto-char (point-min))
10533 (while (re-search-forward org-todo-line-regexp nil t)
10535 (org-make-org-heading-search-string
10536 (match-string 3) t))
10539 (tag (setq type :tag beg beg1)
10540 (or org-tag-alist (org-get-buffer-tags)))
10541 (prop (setq type :prop beg beg1)
10542 (mapcar 'list (org-buffer-property-keys nil t t)))
10544 (call-interactively org-completion-fallback-command)
10545 (throw 'exit nil)))))
10546 (pattern (buffer-substring-no-properties beg end))
10547 (completion (try-completion pattern table confirm)))
10548 (cond ((eq completion t)
10549 (if (not (assoc (upcase pattern) table))
10550 (message "Already complete")
10551 (if (and (equal type :opt)
10552 (not (member (car (assoc (upcase pattern) table))
10553 org-additional-option-like-keywords)))
10554 (insert (substring (cdr (assoc (upcase pattern) table))
10556 (if (memq type '(:tag :prop)) (insert ":")))))
10558 (message "Can't find completion for \"%s\"" pattern)
10560 ((not (string= pattern completion))
10561 (delete-region beg end)
10562 (if (string-match " +$" completion)
10563 (setq completion (replace-match "" t t completion)))
10564 (insert completion)
10565 (if (get-buffer-window "*Completions*")
10566 (delete-window (get-buffer-window "*Completions*")))
10567 (if (assoc completion table)
10568 (if (eq type :todo) (insert " ")
10569 (if (memq type '(:tag :prop)) (insert ":"))))
10570 (if (and (equal type :opt) (assoc completion table))
10571 (message "%s" (substitute-command-keys
10572 "Press \\[org-complete] again to insert example settings"))))
10574 (message "Making completion list...")
10575 (let ((list (sort (all-completions pattern table confirm)
10577 (with-output-to-temp-buffer "*Completions*"
10578 (condition-case nil
10579 ;; Protection needed for XEmacs and emacs 21
10580 (display-completion-list list pattern)
10581 (error (display-completion-list list)))))
10582 (message "Making completion list...%s" "done")))))))
10584 ;;;; TODO, DEADLINE, Comments
10586 (defun org-toggle-comment ()
10587 "Change the COMMENT state of an entry."
10590 (org-back-to-heading)
10591 (let (case-fold-search)
10592 (if (looking-at (concat outline-regexp
10593 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10594 (replace-match "" t t nil 1)
10595 (if (looking-at outline-regexp)
10597 (goto-char (match-end 0))
10598 (insert org-comment-string " ")))))))
10600 (defvar org-last-todo-state-is-todo nil
10601 "This is non-nil when the last TODO state change led to a TODO state.
10602 If the last change removed the TODO tag or switched to DONE, then
10605 (defvar org-setting-tags nil) ; dynamically skipped
10607 (defun org-parse-local-options (string var)
10608 "Parse STRING for startup setting relevant for variable VAR."
10609 (let ((rtn (symbol-value var))
10612 (if (or (not string) (not (string-match "\\S-" string)))
10614 (setq opts (delq nil (mapcar (lambda (x)
10615 (setq e (assoc x org-startup-options))
10616 (if (eq (nth 1 e) var) e nil))
10617 (org-split-string string "[ \t]+"))))
10621 (while (setq e (pop opts))
10622 (if (not (nth 3 e))
10623 (setq rtn (nth 2 e))
10624 (if (not (listp rtn)) (setq rtn nil))
10625 (push (nth 2 e) rtn)))
10628 (defvar org-todo-setup-filter-hook nil
10629 "Hook for functions that pre-filter todo specs.
10631 Each function takes a todo spec and returns either `nil' or the spec
10632 transformed into canonical form." )
10634 (defvar org-todo-get-default-hook nil
10635 "Hook for functions that get a default item for todo.
10637 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10638 `nil' or a string to be used for the todo mark." )
10640 (defvar org-agenda-headline-snapshot-before-repeat)
10642 (defun org-todo (&optional arg)
10643 "Change the TODO state of an item.
10644 The state of an item is given by a keyword at the start of the heading,
10646 *** TODO Write paper
10649 The different keywords are specified in the variable `org-todo-keywords'.
10650 By default the available states are \"TODO\" and \"DONE\".
10651 So for this example: when the item starts with TODO, it is changed to DONE.
10652 When it starts with DONE, the DONE is removed. And when neither TODO nor
10653 DONE are present, add TODO at the beginning of the heading.
10655 With C-u prefix arg, use completion to determine the new state.
10656 With numeric prefix arg, switch to that state.
10657 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10658 With a triple C-u prefix, circumvent any state blocking.
10660 For calling through lisp, arg is also interpreted in the following way:
10661 'none -> empty state
10662 \"\"(empty string) -> switch to empty state
10663 'done -> switch to DONE
10664 'nextset -> switch to the next set of keywords
10665 'previousset -> switch to the previous set of keywords
10666 \"WAITING\" -> switch to the specified keyword, but only if it
10667 really is a member of `org-todo-keywords'."
10669 (if (equal arg '(16)) (setq arg 'nextset))
10670 (let ((org-blocker-hook org-blocker-hook)
10671 (case-fold-search nil))
10672 (when (equal arg '(64))
10673 (setq arg nil org-blocker-hook nil))
10674 (when (and org-blocker-hook
10675 (or org-inhibit-blocking
10676 (org-entry-get nil "NOBLOCKING")))
10677 (setq org-blocker-hook nil))
10680 (org-back-to-heading t)
10681 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10682 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10684 (let* ((match-data (match-data))
10685 (startpos (point-at-bol))
10686 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
10687 (org-log-done org-log-done)
10688 (org-log-repeat org-log-repeat)
10689 (org-todo-log-states org-todo-log-states)
10690 (this (match-string 1))
10691 (hl-pos (match-beginning 0))
10692 (head (org-get-todo-sequence-head this))
10693 (ass (assoc head org-todo-kwd-alist))
10694 (interpret (nth 1 ass))
10695 (done-word (nth 3 ass))
10696 (final-done-word (nth 4 ass))
10697 (last-state (or this ""))
10698 (completion-ignore-case t)
10699 (member (member this org-todo-keywords-1))
10700 (tail (cdr member))
10702 ((and org-todo-key-trigger
10703 (or (and (equal arg '(4))
10704 (eq org-use-fast-todo-selection 'prefix))
10705 (and (not arg) org-use-fast-todo-selection
10706 (not (eq org-use-fast-todo-selection
10708 ;; Use fast selection
10709 (org-fast-todo-selection))
10710 ((and (equal arg '(4))
10711 (or (not org-use-fast-todo-selection)
10712 (not org-todo-key-trigger)))
10713 ;; Read a state with completion
10714 (org-icompleting-read
10715 "State: " (mapcar (lambda(x) (list x))
10716 org-todo-keywords-1)
10720 (if tail (car tail) nil)
10721 (car org-todo-keywords-1)))
10723 (if (equal member org-todo-keywords-1)
10726 (nth (- (length org-todo-keywords-1)
10728 org-todo-keywords-1)
10729 (org-last org-todo-keywords-1))))
10730 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10731 (setq arg nil))) ; hack to fall back to cycling
10733 ;; user or caller requests a specific state
10735 ((equal arg "") nil)
10736 ((eq arg 'none) nil)
10737 ((eq arg 'done) (or done-word (car org-done-keywords)))
10739 (or (car (cdr (member head org-todo-heads)))
10740 (car org-todo-heads)))
10741 ((eq arg 'previousset)
10742 (let ((org-todo-heads (reverse org-todo-heads)))
10743 (or (car (cdr (member head org-todo-heads)))
10744 (car org-todo-heads))))
10745 ((car (member arg org-todo-keywords-1)))
10747 (error "State `%s' not valid in this file" arg))
10748 ((nth (1- (prefix-numeric-value arg))
10749 org-todo-keywords-1))))
10750 ((null member) (or head (car org-todo-keywords-1)))
10751 ((equal this final-done-word) nil) ;; -> make empty
10752 ((null tail) nil) ;; -> first entry
10753 ((memq interpret '(type priority))
10754 (if (eq this-command last-command)
10756 (if (> (length tail) 0)
10757 (or done-word (car org-done-keywords))
10762 (run-hook-with-args-until-success
10763 'org-todo-get-default-hook state last-state)
10765 (next (if state (concat " " state " ") " "))
10766 (change-plist (list :type 'todo-state-change :from this :to state
10767 :position startpos))
10769 (when org-blocker-hook
10770 (setq org-last-todo-state-is-todo
10771 (not (member this org-done-keywords)))
10772 (unless (save-excursion
10774 (run-hook-with-args-until-failure
10775 'org-blocker-hook change-plist)))
10776 (if (interactive-p)
10777 (error "TODO state change from %s to %s blocked" this state)
10779 (message "TODO state change from %s to %s blocked" this state)
10780 (throw 'exit nil))))
10781 (store-match-data match-data)
10782 (replace-match next t t)
10783 (unless (pos-visible-in-window-p hl-pos)
10784 (message "TODO state changed to %s" (org-trim next)))
10786 (setq head (org-get-todo-sequence-head state)
10787 ass (assoc head org-todo-kwd-alist)
10788 interpret (nth 1 ass)
10789 done-word (nth 3 ass)
10790 final-done-word (nth 4 ass)))
10791 (when (memq arg '(nextset previousset))
10792 (message "Keyword-Set %d/%d: %s"
10793 (- (length org-todo-sets) -1
10794 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10795 (length org-todo-sets)
10796 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10797 (setq org-last-todo-state-is-todo
10798 (not (member state org-done-keywords)))
10799 (setq now-done-p (and (member state org-done-keywords)
10800 (not (member this org-done-keywords))))
10801 (and logging (org-local-logging logging))
10802 (when (and (or org-todo-log-states org-log-done)
10803 (not (eq org-inhibit-logging t))
10804 (not (memq arg '(nextset previousset))))
10805 ;; we need to look at recording a time and note
10806 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10807 (nth 2 (assoc this org-todo-log-states))))
10808 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10809 (setq dolog 'time))
10811 (member state org-not-done-keywords)
10812 (not (member this org-not-done-keywords)))
10813 ;; This is now a todo state and was not one before
10814 ;; If there was a CLOSED time stamp, get rid of it.
10815 (org-add-planning-info nil nil 'closed))
10816 (when (and now-done-p org-log-done)
10817 ;; It is now done, and it was not done before
10818 (org-add-planning-info 'closed (org-current-time))
10819 (if (and (not dolog) (eq 'note org-log-done))
10820 (org-add-log-setup 'done state this 'findpos 'note)))
10821 (when (and state dolog)
10822 ;; This is a non-nil state, and we need to log it
10823 (org-add-log-setup 'state state this 'findpos dolog)))
10824 ;; Fixup tag positioning
10825 (org-todo-trigger-tag-changes state)
10826 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10827 (when org-provide-todo-statistics
10828 (org-update-parent-todo-statistics))
10829 (run-hooks 'org-after-todo-state-change-hook)
10830 (if (and arg (not (member state org-done-keywords)))
10831 (setq head (org-get-todo-sequence-head state)))
10832 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10833 ;; Do we need to trigger a repeat?
10835 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10836 ;; This is for the agenda, take a snapshot of the headline.
10838 (setq org-agenda-headline-snapshot-before-repeat
10839 (org-get-heading))))
10840 (org-auto-repeat-maybe state))
10841 ;; Fixup cursor location if close to the keyword
10842 (if (and (outline-on-heading-p)
10844 (save-excursion (beginning-of-line 1)
10845 (looking-at org-todo-line-regexp))
10846 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10848 (goto-char (or (match-end 2) (match-end 1)))
10849 (and (looking-at " ") (just-one-space))))
10850 (when org-trigger-hook
10852 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10854 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10855 "Block turning an entry into a TODO, using the hierarchy.
10856 This checks whether the current task should be blocked from state
10857 changes. Such blocking occurs when:
10859 1. The task has children which are not all in a completed state.
10861 2. A task has a parent with the property :ORDERED:, and there
10862 are siblings prior to the current task with incomplete
10865 3. The parent of the task is blocked because it has siblings that should
10866 be done first, or is child of a block grandparent TODO entry."
10868 (if (not org-enforce-todo-dependencies)
10869 t ; if locally turned off don't block
10871 ;; If this is not a todo state change, or if this entry is already DONE,
10873 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10874 (member (plist-get change-plist :from)
10875 (cons 'done org-done-keywords))
10876 (member (plist-get change-plist :to)
10877 (cons 'todo org-not-done-keywords))
10878 (not (plist-get change-plist :to)))
10879 (throw 'dont-block t))
10880 ;; If this task has children, and any are undone, it's blocked
10882 (org-back-to-heading t)
10883 (let ((this-level (funcall outline-level)))
10884 (outline-next-heading)
10885 (let ((child-level (funcall outline-level)))
10886 (while (and (not (eobp))
10887 (> child-level this-level))
10888 ;; this todo has children, check whether they are all
10890 (if (and (not (org-entry-is-done-p))
10891 (org-entry-is-todo-p))
10892 (throw 'dont-block nil))
10893 (outline-next-heading)
10894 (setq child-level (funcall outline-level))))))
10895 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10896 ;; any previous siblings are undone, it's blocked
10898 (org-back-to-heading t)
10899 (let* ((pos (point))
10900 (parent-pos (and (org-up-heading-safe) (point))))
10901 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10902 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10904 (re-search-forward org-not-done-heading-regexp pos t))
10905 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10906 ;; Search further up the hierarchy, to see if an anchestor is blocked
10908 (goto-char parent-pos)
10909 (if (not (looking-at org-not-done-heading-regexp))
10910 (throw 'dont-block t)) ; do not block, parent is not a TODO
10912 (setq parent-pos (and (org-up-heading-safe) (point)))
10913 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10914 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10916 (re-search-forward org-not-done-heading-regexp pos t))
10917 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10919 (defcustom org-track-ordered-property-with-tag nil
10920 "Should the ORDERED property also be shown as a tag?
10921 The ORDERED property decides if an entry should require subtasks to be
10922 completed in sequence. Since a property is not very visible, setting
10923 this option means that toggling the ORDERED property with the command
10924 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10925 not relevant for the behavior, but it makes things more visible.
10927 Note that toggling the tag with tags commands will not change the property
10928 and therefore not influence behavior!
10930 This can be t, meaning the tag ORDERED should be used, It can also be a
10931 string to select a different tag for this task."
10934 (const :tag "No tracking" nil)
10935 (const :tag "Track with ORDERED tag" t)
10936 (string :tag "Use other tag")))
10938 (defun org-toggle-ordered-property ()
10939 "Toggle the ORDERED property of the current entry.
10940 For better visibility, you can track the value of this property with a tag.
10941 See variable `org-track-ordered-property-with-tag'."
10943 (let* ((t1 org-track-ordered-property-with-tag)
10944 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10946 (org-back-to-heading)
10947 (if (org-entry-get nil "ORDERED")
10949 (org-delete-property "ORDERED")
10950 (and tag (org-toggle-tag tag 'off))
10951 (message "Subtasks can be completed in arbitrary order"))
10952 (org-entry-put nil "ORDERED" "t")
10953 (and tag (org-toggle-tag tag 'on))
10954 (message "Subtasks must be completed in sequence")))))
10956 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10957 (defun org-block-todo-from-checkboxes (change-plist)
10958 "Block turning an entry into a TODO, using checkboxes.
10959 This checks whether the current task should be blocked from state
10960 changes because there are unchecked boxes in this entry."
10961 (if (not org-enforce-todo-checkbox-dependencies)
10962 t ; if locally turned off don't block
10964 ;; If this is not a todo state change, or if this entry is already DONE,
10966 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10967 (member (plist-get change-plist :from)
10968 (cons 'done org-done-keywords))
10969 (member (plist-get change-plist :to)
10970 (cons 'todo org-not-done-keywords))
10971 (not (plist-get change-plist :to)))
10972 (throw 'dont-block t))
10973 ;; If this task has checkboxes that are not checked, it's blocked
10975 (org-back-to-heading t)
10976 (let ((beg (point)) end)
10977 (outline-next-heading)
10980 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10983 (if (boundp 'org-blocked-by-checkboxes)
10984 (setq org-blocked-by-checkboxes t))
10985 (throw 'dont-block nil)))))
10986 t))) ; do not block
10988 (defun org-entry-blocked-p ()
10989 "Is the current entry blocked?"
10990 (if (org-entry-get nil "NOBLOCKING")
10991 nil ;; Never block this entry
10993 (run-hook-with-args-until-failure
10995 (list :type 'todo-state-change
11000 (defun org-update-statistics-cookies (all)
11001 "Update the statistics cookie, either from TODO or from checkboxes.
11002 This should be called with the cursor in a line with a statistics cookie."
11006 (org-update-checkbox-count 'all)
11007 (org-map-entries 'org-update-parent-todo-statistics))
11008 (if (not (org-on-heading-p))
11009 (org-update-checkbox-count)
11010 (let ((pos (move-marker (make-marker) (point)))
11012 (ignore-errors (org-back-to-heading t))
11013 (if (not (org-on-heading-p))
11014 (org-update-checkbox-count)
11015 (setq l1 (org-outline-level))
11016 (setq end (save-excursion
11017 (outline-next-heading)
11018 (if (org-on-heading-p) (setq l2 (org-outline-level)))
11020 (if (and (save-excursion
11022 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11023 (not (save-excursion (re-search-forward
11024 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11025 (org-update-checkbox-count)
11026 (if (and l2 (> l2 l1))
11029 (org-update-parent-todo-statistics))
11031 (beginning-of-line 1)
11032 (while (re-search-forward
11033 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11035 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11037 (move-marker pos nil)))))
11039 (defvar org-entry-property-inherited-from) ;; defined below
11040 (defun org-update-parent-todo-statistics ()
11041 "Update any statistics cookie in the parent of the current headline.
11042 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11043 the entire subtree and this will travel up the hierarchy and update
11044 statistics everywhere."
11046 (let* ((lim 0) prop
11047 (recursive (or (not org-hierarchical-todo-statistics)
11050 (or (setq prop (org-entry-get
11051 nil "COOKIE_DATA" 'inherit)) ""))))
11052 (lim (or (and prop (marker-position
11053 org-entry-property-inherited-from))
11056 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11057 level ltoggle l1 new ndel
11058 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
11061 (beginning-of-line 1)
11062 (if (org-at-heading-p)
11063 (setq ltoggle (funcall outline-level))
11064 (error "This should not happen"))
11065 (while (and (setq level (org-up-heading-safe))
11066 (or recursive first)
11068 (setq first nil cookie-present nil)
11077 (while (re-search-forward box-re (point-at-eol) t)
11078 (setq cnt-all 0 cnt-done 0 cookie-present t)
11079 (setq is-percent (match-end 2))
11081 (unless (outline-next-heading) (throw 'exit nil))
11082 (while (and (looking-at org-complex-heading-regexp)
11083 (> (setq l1 (length (match-string 1))) level))
11084 (setq kwd (and (or recursive (= l1 ltoggle))
11086 (if (or (eq org-provide-todo-statistics 'all-headlines)
11087 (and (listp org-provide-todo-statistics)
11088 (or (member kwd org-provide-todo-statistics)
11089 (member kwd org-done-keywords))))
11090 (setq cnt-all (1+ cnt-all))
11091 (if (eq org-provide-todo-statistics t)
11092 (and kwd (setq cnt-all (1+ cnt-all)))))
11093 (and (member kwd org-done-keywords)
11094 (setq cnt-done (1+ cnt-done)))
11095 (outline-next-heading)))
11098 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
11099 (format "[%d/%d]" cnt-done cnt-all))
11100 ndel (- (match-end 0) (match-beginning 0)))
11101 (goto-char (match-beginning 0))
11103 (delete-region (point) (+ (point) ndel)))
11104 (when cookie-present
11105 (run-hook-with-args 'org-after-todo-statistics-hook
11106 cnt-done (- cnt-all cnt-done))))))
11107 (run-hooks 'org-todo-statistics-hook)))
11109 (defvar org-after-todo-statistics-hook nil
11110 "Hook that is called after a TODO statistics cookie has been updated.
11111 Each function is called with two arguments: the number of not-done entries
11112 and the number of done entries.
11114 For example, the following function, when added to this hook, will switch
11115 an entry to DONE when all children are done, and back to TODO when new
11116 entries are set to a TODO status. Note that this hook is only called
11117 when there is a statistics cookie in the headline!
11119 (defun org-summary-todo (n-done n-not-done)
11120 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
11121 (let (org-log-done org-log-states) ; turn off logging
11122 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
11125 (defvar org-todo-statistics-hook nil
11126 "Hook that is run whenever Org thinks TODO statistics should be updated.
11127 This hook runs even if there is no statistics cookie present, in which case
11128 `org-after-todo-statistics-hook' would not run.")
11130 (defun org-todo-trigger-tag-changes (state)
11131 "Apply the changes defined in `org-todo-state-tags-triggers'."
11132 (let ((l org-todo-state-tags-triggers)
11134 (when (or (not state) (equal state ""))
11135 (setq changes (append changes (cdr (assoc "" l)))))
11136 (when (and (stringp state) (> (length state) 0))
11137 (setq changes (append changes (cdr (assoc state l)))))
11138 (when (member state org-not-done-keywords)
11139 (setq changes (append changes (cdr (assoc 'todo l)))))
11140 (when (member state org-done-keywords)
11141 (setq changes (append changes (cdr (assoc 'done l)))))
11142 (dolist (c changes)
11143 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
11145 (defun org-local-logging (value)
11146 "Get logging settings from a property VALUE."
11148 ;; directly set the variables, they are already local.
11149 (setq org-log-done nil
11151 org-todo-log-states nil)
11152 (setq words (org-split-string value))
11153 (while (setq w (pop words))
11155 ((setq a (assoc w org-startup-options))
11156 (and (member (nth 1 a) '(org-log-done org-log-repeat))
11157 (set (nth 1 a) (nth 2 a))))
11158 ((setq a (org-extract-log-state-settings w))
11159 (and (member (car a) org-todo-keywords-1)
11160 (push a org-todo-log-states)))))))
11162 (defun org-get-todo-sequence-head (kwd)
11163 "Return the head of the TODO sequence to which KWD belongs.
11164 If KWD is not set, check if there is a text property remembering the
11169 (or (get-text-property (point-at-bol) 'org-todo-head)
11171 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
11172 nil (point-at-eol)))
11173 (get-text-property p 'org-todo-head))))
11174 ((not (member kwd org-todo-keywords-1))
11175 (car org-todo-keywords-1))
11176 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
11178 (defun org-fast-todo-selection ()
11179 "Fast TODO keyword selection with single keys.
11180 Returns the new TODO keyword, or nil if no state change should occur."
11181 (let* ((fulltable org-todo-key-alist)
11182 (done-keywords org-done-keywords) ;; needed for the faces.
11183 (maxlen (apply 'max (mapcar
11185 (if (stringp (car x)) (string-width (car x)) 0))
11188 (fwidth (+ maxlen 3 1 3))
11189 (ncol (/ (- (window-width) 4) fwidth))
11193 (save-window-excursion
11195 (set-buffer (get-buffer-create " *Org todo*"))
11196 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
11198 (org-set-local 'org-done-keywords done-keywords)
11199 (setq tbl fulltable cnt 0)
11200 (while (setq e (pop tbl))
11202 ((equal e '(:startgroup))
11203 (push '() groups) (setq ingroup t)
11204 (when (not (= cnt 0))
11208 ((equal e '(:endgroup))
11209 (setq ingroup nil cnt 0)
11211 ((equal e '(:newline))
11212 (when (not (= cnt 0))
11216 (while (equal (car tbl) '(:newline))
11218 (setq tbl (cdr tbl)))))
11220 (setq tg (car e) c (cdr e))
11221 (if ingroup (push tg (car groups)))
11222 (setq tg (org-add-props tg nil 'face
11223 (org-get-todo-face tg)))
11224 (if (and (= cnt 0) (not ingroup)) (insert " "))
11225 (insert "[" c "] " tg (make-string
11226 (- fwidth 4 (length tg)) ?\ ))
11227 (when (= (setq cnt (1+ cnt)) ncol)
11229 (if ingroup (insert " "))
11232 (goto-char (point-min))
11233 (if (not expert) (org-fit-window-to-buffer))
11234 (message "[a-z..]:Set [SPC]:clear")
11235 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
11238 (and (= c ?q) (not (rassoc c fulltable))))
11239 (setq quit-flag t))
11241 ((setq e (rassoc c fulltable) tg (car e))
11243 (t (setq quit-flag t)))))))
11245 (defun org-entry-is-todo-p ()
11246 (member (org-get-todo-state) org-not-done-keywords))
11248 (defun org-entry-is-done-p ()
11249 (member (org-get-todo-state) org-done-keywords))
11251 (defun org-get-todo-state ()
11253 (org-back-to-heading t)
11254 (and (looking-at org-todo-line-regexp)
11256 (match-string 2))))
11258 (defun org-at-date-range-p (&optional inactive-ok)
11259 "Is the cursor inside a date range?"
11263 (let ((pos (point)))
11264 (skip-chars-backward "^[<\r\n")
11265 (skip-chars-backward "<[")
11266 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11267 (>= (match-end 0) pos)
11269 (skip-chars-backward "^<[\r\n")
11270 (skip-chars-backward "<[")
11271 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11272 (>= (match-end 0) pos)
11276 (defun org-get-repeat (&optional tagline)
11277 "Check if there is a deadline/schedule with repeater in this entry."
11280 (org-back-to-heading t)
11281 (and (re-search-forward (if tagline
11282 (concat tagline "\\s-*" org-repeat-re)
11284 (org-entry-end-position) t)
11285 (match-string-no-properties 1)))))
11287 (defvar org-last-changed-timestamp)
11288 (defvar org-last-inserted-timestamp)
11289 (defvar org-log-post-message)
11290 (defvar org-log-note-purpose)
11291 (defvar org-log-note-how)
11292 (defvar org-log-note-extra)
11293 (defun org-auto-repeat-maybe (done-word)
11294 "Check if the current headline contains a repeated deadline/schedule.
11295 If yes, set TODO state back to what it was and change the base date
11296 of repeating deadline/scheduled time stamps to new date.
11297 This function is run automatically after each state change to a DONE state."
11298 ;; last-state is dynamically scoped into this function
11299 (let* ((repeat (org-get-repeat))
11300 (aa (assoc last-state org-todo-kwd-alist))
11301 (interpret (nth 1 aa))
11303 (whata '(("d" . day) ("m" . month) ("y" . year)))
11304 (msg "Entry repeats: ")
11306 (org-todo-log-states nil)
11307 (nshiftmax 10) (nshift 0)
11308 re type n what ts time to-state)
11310 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
11311 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
11312 org-todo-repeat-to-state))
11313 (unless (and to-state (member to-state org-todo-keywords-1))
11314 (setq to-state (if (eq interpret 'type) last-state head)))
11315 (org-todo to-state)
11316 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
11317 (org-entry-put nil "LAST_REPEAT" (format-time-string
11318 (org-time-stamp-format t t))))
11319 (when org-log-repeat
11320 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
11321 (memq 'org-add-log-note post-command-hook))
11322 ;; OK, we are already setup for some record
11323 (if (eq org-log-repeat 'note)
11324 ;; make sure we take a note, not only a time stamp
11325 (setq org-log-note-how 'note))
11326 ;; Set up for taking a record
11327 (org-add-log-setup 'state (or done-word (car org-done-keywords))
11329 'findpos org-log-repeat)))
11330 (org-back-to-heading t)
11331 (org-add-planning-info nil nil 'closed)
11332 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
11333 org-deadline-time-regexp "\\)\\|\\("
11334 org-ts-regexp "\\)"))
11335 (while (re-search-forward
11336 re (save-excursion (outline-next-heading) (point)) t)
11337 (setq type (if (match-end 1) org-scheduled-string
11338 (if (match-end 3) org-deadline-string "Plain:"))
11339 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
11340 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
11341 (setq n (string-to-number (match-string 2 ts))
11342 what (match-string 3 ts))
11343 (if (equal what "w") (setq n (* n 7) what "d"))
11344 ;; Preparation, see if we need to modify the start date for the change
11345 (when (match-end 1)
11346 (setq time (save-match-data (org-time-string-to-time ts)))
11348 ((equal (match-string 1 ts) ".")
11349 ;; Shift starting date to today
11350 (org-timestamp-change
11351 (- (time-to-days (current-time)) (time-to-days time))
11353 ((equal (match-string 1 ts) "+")
11354 (while (or (= nshift 0)
11355 (<= (time-to-days time) (time-to-days (current-time))))
11356 (when (= (incf nshift) nshiftmax)
11357 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
11359 (org-timestamp-change n (cdr (assoc what whata)))
11360 (org-at-timestamp-p t)
11361 (setq ts (match-string 1))
11362 (setq time (save-match-data (org-time-string-to-time ts))))
11363 (org-timestamp-change (- n) (cdr (assoc what whata)))
11364 ;; rematch, so that we have everything in place for the real shift
11365 (org-at-timestamp-p t)
11366 (setq ts (match-string 1))
11367 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
11368 (org-timestamp-change n (cdr (assoc what whata)))
11369 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
11370 (setq org-log-post-message msg)
11371 (message "%s" msg))))
11373 (defun org-show-todo-tree (arg)
11374 "Make a compact tree which shows all headlines marked with TODO.
11375 The tree will show the lines where the regexp matches, and all higher
11376 headlines above the match.
11377 With a \\[universal-argument] prefix, prompt for a regexp to match.
11378 With a numeric prefix N, construct a sparse tree for the Nth element
11379 of `org-todo-keywords-1'."
11381 (let ((case-fold-search nil)
11383 (cond ((null arg) org-not-done-regexp)
11385 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
11386 (mapcar 'list org-todo-keywords-1))))
11388 (mapconcat 'identity (org-split-string kwd "|") "\\|")
11390 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
11391 (regexp-quote (nth (1- (prefix-numeric-value arg))
11392 org-todo-keywords-1)))
11393 (t (error "Invalid prefix argument: %s" arg)))))
11394 (message "%d TODO entries found"
11395 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
11397 (defun org-deadline (&optional remove time)
11398 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
11399 With argument REMOVE, remove any deadline from the item.
11400 When TIME is set, it should be an internal time specification, and the
11401 scheduling will use the corresponding date."
11403 (let* ((old-date (org-entry-get nil "DEADLINE"))
11404 (repeater (and old-date
11405 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11406 (match-string 1 old-date))))
11409 (when (and old-date org-log-redeadline)
11410 (org-add-log-setup 'deldeadline nil old-date 'findpos
11411 org-log-redeadline))
11412 (org-remove-timestamp-with-keyword org-deadline-string)
11413 (message "Item no longer has a deadline."))
11414 (org-add-planning-info 'deadline time 'closed)
11415 (when (and old-date org-log-redeadline
11416 (not (equal old-date
11417 (substring org-last-inserted-timestamp 1 -1))))
11418 (org-add-log-setup 'redeadline nil old-date 'findpos
11419 org-log-redeadline))
11422 (org-back-to-heading t)
11423 (when (re-search-forward (concat org-deadline-string " "
11424 org-last-inserted-timestamp)
11426 (outline-next-heading) (point)) t)
11427 (goto-char (1- (match-end 0)))
11428 (insert " " repeater)
11429 (setq org-last-inserted-timestamp
11430 (concat (substring org-last-inserted-timestamp 0 -1)
11432 (substring org-last-inserted-timestamp -1))))))
11433 (message "Deadline on %s" org-last-inserted-timestamp))))
11435 (defun org-schedule (&optional remove time)
11436 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11437 With argument REMOVE, remove any scheduling date from the item.
11438 When TIME is set, it should be an internal time specification, and the
11439 scheduling will use the corresponding date."
11441 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11442 (repeater (and old-date
11443 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11444 (match-string 1 old-date))))
11447 (when (and old-date org-log-reschedule)
11448 (org-add-log-setup 'delschedule nil old-date 'findpos
11449 org-log-reschedule))
11450 (org-remove-timestamp-with-keyword org-scheduled-string)
11451 (message "Item is no longer scheduled."))
11452 (org-add-planning-info 'scheduled time 'closed)
11453 (when (and old-date org-log-reschedule
11454 (not (equal old-date
11455 (substring org-last-inserted-timestamp 1 -1))))
11456 (org-add-log-setup 'reschedule nil old-date 'findpos
11457 org-log-reschedule))
11460 (org-back-to-heading t)
11461 (when (re-search-forward (concat org-scheduled-string " "
11462 org-last-inserted-timestamp)
11464 (outline-next-heading) (point)) t)
11465 (goto-char (1- (match-end 0)))
11466 (insert " " repeater)
11467 (setq org-last-inserted-timestamp
11468 (concat (substring org-last-inserted-timestamp 0 -1)
11470 (substring org-last-inserted-timestamp -1))))))
11471 (message "Scheduled to %s" org-last-inserted-timestamp))))
11473 (defun org-get-scheduled-time (pom &optional inherit)
11474 "Get the scheduled time as a time tuple, of a format suitable
11475 for calling org-schedule with, or if there is no scheduling,
11477 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11479 (apply 'encode-time (org-parse-time-string time)))))
11481 (defun org-get-deadline-time (pom &optional inherit)
11482 "Get the deadine as a time tuple, of a format suitable for
11483 calling org-deadline with, or if there is no scheduling, returns
11485 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11487 (apply 'encode-time (org-parse-time-string time)))))
11489 (defun org-remove-timestamp-with-keyword (keyword)
11490 "Remove all time stamps with KEYWORD in the current entry."
11491 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11494 (org-back-to-heading t)
11496 (outline-next-heading)
11497 (while (re-search-backward re beg t)
11499 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11500 (equal (char-before) ?\ ))
11501 (backward-delete-char 1)
11502 (if (string-match "^[ \t]*$" (buffer-substring
11503 (point-at-bol) (point-at-eol)))
11504 (delete-region (point-at-bol)
11505 (min (point-max) (1+ (point-at-eol))))))))))
11507 (defun org-add-planning-info (what &optional time &rest remove)
11508 "Insert new timestamp with keyword in the line directly after the headline.
11509 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11510 If non is given, the user is prompted for a date.
11511 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11514 (let (org-time-was-given org-end-time-was-given ts
11515 end default-time default-input)
11518 (when (and (not time) (memq what '(scheduled deadline)))
11519 ;; Try to get a default date/time from existing timestamp
11521 (org-back-to-heading t)
11522 (setq end (save-excursion (outline-next-heading) (point)))
11523 (when (re-search-forward (if (eq what 'scheduled)
11524 org-scheduled-time-regexp
11525 org-deadline-time-regexp)
11527 (setq ts (match-string 1)
11529 (apply 'encode-time (org-parse-time-string ts))
11530 default-input (and ts (org-get-compact-tod ts))))))
11532 ;; If necessary, get the time from the user
11533 (setq time (or time (org-read-date nil 'to-time nil nil
11534 default-time default-input))))
11536 (when (and org-insert-labeled-timestamps-at-point
11537 (member what '(scheduled deadline)))
11539 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11540 (org-insert-time-stamp time org-time-was-given
11541 nil nil nil (list org-end-time-was-given))
11545 (let (col list elt ts buffer-invisibility-spec)
11546 (org-back-to-heading t)
11547 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11548 (goto-char (match-end 1))
11549 (setq col (current-column))
11550 (goto-char (match-end 0))
11551 (if (eobp) (insert "\n") (forward-char 1))
11552 (when (and (not what)
11555 org-keyword-time-not-clock-regexp))))
11556 ;; Nothing to add, nothing to remove...... :-)
11558 (if (and (not (looking-at outline-regexp))
11559 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11561 (not (equal (match-string 1) org-clock-string)))
11562 (narrow-to-region (match-beginning 0) (match-end 0))
11563 (insert-before-markers "\n")
11565 (narrow-to-region (point) (point))
11566 (and org-adapt-indentation (org-indent-to-column col)))
11567 ;; Check if we have to remove something.
11568 (setq list (cons what remove))
11570 (setq elt (pop list))
11571 (goto-char (point-min))
11572 (when (or (and (eq elt 'scheduled)
11573 (re-search-forward org-scheduled-time-regexp nil t))
11574 (and (eq elt 'deadline)
11575 (re-search-forward org-deadline-time-regexp nil t))
11576 (and (eq elt 'closed)
11577 (re-search-forward org-closed-time-regexp nil t)))
11579 (if (looking-at "--+<[^>]+>") (replace-match ""))
11580 (skip-chars-backward " ")
11581 (if (looking-at " +") (replace-match ""))))
11582 (goto-char (point-max))
11583 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11586 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11587 (cond ((eq what 'scheduled) org-scheduled-string)
11588 ((eq what 'deadline) org-deadline-string)
11589 ((eq what 'closed) org-closed-string))
11591 (setq ts (org-insert-time-stamp
11593 (or org-time-was-given
11594 (and (eq what 'closed) org-log-done-with-time))
11596 nil nil (list org-end-time-was-given)))
11598 (goto-char (point-min))
11600 (if (and (looking-at "[ \t]*\n")
11601 (equal (char-before) ?\n))
11602 (delete-region (1- (point)) (point-at-eol)))
11605 (defvar org-log-note-marker (make-marker))
11606 (defvar org-log-note-purpose nil)
11607 (defvar org-log-note-state nil)
11608 (defvar org-log-note-previous-state nil)
11609 (defvar org-log-note-how nil)
11610 (defvar org-log-note-extra nil)
11611 (defvar org-log-note-window-configuration nil)
11612 (defvar org-log-note-return-to (make-marker))
11613 (defvar org-log-post-message nil
11614 "Message to be displayed after a log note has been stored.
11615 The auto-repeater uses this.")
11617 (defun org-add-note ()
11618 "Add a note to the current entry.
11619 This is done in the same way as adding a state change note."
11621 (org-add-log-setup 'note nil nil 'findpos nil))
11623 (defvar org-property-end-re)
11624 (defun org-add-log-setup (&optional purpose state prev-state
11625 findpos how &optional extra)
11626 "Set up the post command hook to take a note.
11627 If this is about to TODO state change, the new state is expected in STATE.
11628 When FINDPOS is non-nil, find the correct position for the note in
11629 the current entry. If not, assume that it can be inserted at point.
11630 HOW is an indicator what kind of note should be created.
11631 EXTRA is additional text that will be inserted into the notes buffer."
11632 (let* ((org-log-into-drawer (org-log-into-drawer))
11633 (drawer (cond ((stringp org-log-into-drawer)
11634 org-log-into-drawer)
11635 (org-log-into-drawer "LOGBOOK")
11640 (org-back-to-heading t)
11641 (narrow-to-region (point) (save-excursion
11642 (outline-next-heading) (point)))
11643 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11644 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11646 (goto-char (match-end 0))
11649 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11652 (goto-char (match-end 0))
11653 (or org-log-states-order-reversed
11654 (and (re-search-forward org-property-end-re nil t)
11655 (goto-char (1- (match-beginning 0))))))
11656 (insert "\n:" drawer ":\n:END:")
11657 (beginning-of-line 0)
11658 (org-indent-line-function)
11659 (beginning-of-line 2)
11660 (org-indent-line-function)
11662 ((and org-log-state-notes-insert-after-drawers
11664 (forward-line) (looking-at org-drawer-regexp)))
11666 (while (looking-at org-drawer-regexp)
11667 (goto-char (match-end 0))
11668 (re-search-forward org-property-end-re (point-max) t)
11670 (forward-line -1)))
11671 (unless org-log-states-order-reversed
11672 (and (= (char-after) ?\n) (forward-char 1))
11673 (org-skip-over-state-notes)
11674 (skip-chars-backward " \t\n\r")))
11675 (move-marker org-log-note-marker (point))
11676 (setq org-log-note-purpose purpose
11677 org-log-note-state state
11678 org-log-note-previous-state prev-state
11679 org-log-note-how how
11680 org-log-note-extra extra)
11681 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11683 (defun org-skip-over-state-notes ()
11684 "Skip past the list of State notes in an entry."
11685 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11686 (while (looking-at "[ \t]*- State")
11687 (condition-case nil
11689 (error (org-end-of-item)))))
11691 (defun org-add-log-note (&optional purpose)
11692 "Pop up a window for taking a note, and add this note later at point."
11693 (remove-hook 'post-command-hook 'org-add-log-note)
11694 (setq org-log-note-window-configuration (current-window-configuration))
11695 (delete-other-windows)
11696 (move-marker org-log-note-return-to (point))
11697 (switch-to-buffer (marker-buffer org-log-note-marker))
11698 (goto-char org-log-note-marker)
11699 (org-switch-to-buffer-other-window "*Org Note*")
11701 (if (memq org-log-note-how '(time state))
11702 (let (current-prefix-arg) (org-store-log-note))
11703 (let ((org-inhibit-startup t)) (org-mode))
11704 (insert (format "# Insert note for %s.
11705 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11707 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11708 ((eq org-log-note-purpose 'done) "closed todo item")
11709 ((eq org-log-note-purpose 'state)
11710 (format "state change from \"%s\" to \"%s\""
11711 (or org-log-note-previous-state "")
11712 (or org-log-note-state "")))
11713 ((eq org-log-note-purpose 'reschedule)
11715 ((eq org-log-note-purpose 'delschedule)
11716 "no longer scheduled")
11717 ((eq org-log-note-purpose 'redeadline)
11718 "changing deadline")
11719 ((eq org-log-note-purpose 'deldeadline)
11720 "removing deadline")
11721 ((eq org-log-note-purpose 'refile)
11723 ((eq org-log-note-purpose 'note)
11725 (t (error "This should not happen")))))
11726 (if org-log-note-extra (insert org-log-note-extra))
11727 (org-set-local 'org-finish-function 'org-store-log-note)))
11729 (defvar org-note-abort nil) ; dynamically scoped
11730 (defun org-store-log-note ()
11731 "Finish taking a log note, and insert it to where it belongs."
11732 (let ((txt (buffer-string))
11733 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11735 (kill-buffer (current-buffer))
11736 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11737 (setq txt (replace-match "" t t txt)))
11738 (if (string-match "\\s-+\\'" txt)
11739 (setq txt (replace-match "" t t txt)))
11740 (setq lines (org-split-string txt "\n"))
11741 (when (and note (string-match "\\S-" note))
11743 (org-replace-escapes
11745 (list (cons "%u" (user-login-name))
11746 (cons "%U" user-full-name)
11747 (cons "%t" (format-time-string
11748 (org-time-stamp-format 'long 'inactive)
11750 (cons "%T" (format-time-string
11751 (org-time-stamp-format 'long nil)
11753 (cons "%s" (if org-log-note-state
11754 (concat "\"" org-log-note-state "\"")
11756 (cons "%S" (if org-log-note-previous-state
11757 (concat "\"" org-log-note-previous-state "\"")
11759 (if lines (setq note (concat note " \\\\")))
11761 (when (or current-prefix-arg org-note-abort)
11762 (when org-log-into-drawer
11763 (org-remove-empty-drawer-at
11764 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11765 org-log-note-marker))
11768 (with-current-buffer (marker-buffer org-log-note-marker)
11770 (goto-char org-log-note-marker)
11771 (move-marker org-log-note-marker nil)
11773 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11774 (insert "- " (pop lines))
11775 (org-indent-line-function)
11776 (beginning-of-line 1)
11777 (looking-at "[ \t]*")
11778 (setq ind (concat (match-string 0) " "))
11780 (while lines (insert "\n" ind (pop lines)))
11781 (message "Note stored")
11782 (org-back-to-heading t)
11783 (org-cycle-hide-drawers 'children)))))
11784 (set-window-configuration org-log-note-window-configuration)
11785 (with-current-buffer (marker-buffer org-log-note-return-to)
11786 (goto-char org-log-note-return-to))
11787 (move-marker org-log-note-return-to nil)
11788 (and org-log-post-message (message "%s" org-log-post-message)))
11790 (defun org-remove-empty-drawer-at (drawer pos)
11791 "Remove an empty drawer DRAWER at position POS.
11792 POS may also be a marker."
11793 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11799 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11800 (replace-match ""))))))
11802 (defun org-sparse-tree (&optional arg)
11803 "Create a sparse tree, prompt for the details.
11804 This command can create sparse trees. You first need to select the type
11805 of match used to create the tree:
11807 t Show all TODO entries.
11808 T Show entries with a specific TODO keyword.
11809 m Show entries selected by a tags/property match.
11810 p Enter a property name and its value (both with completion on existing
11811 names/values) and show entries with that property.
11812 / Show entries matching a regular expression (`r' can be used as well)
11813 d Show deadlines due within `org-deadline-warning-days'.
11814 b Show deadlines and scheduled items before a date.
11815 a Show deadlines and scheduled items after a date."
11817 (let (ans kwd value)
11818 (message "Sparse tree: [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty [d]eadlines\n [b]efore-date [a]fter-date")
11819 (setq ans (read-char-exclusive))
11822 (call-interactively 'org-check-deadlines))
11824 (call-interactively 'org-check-before-date))
11826 (call-interactively 'org-check-after-date))
11828 (org-show-todo-tree nil))
11830 (org-show-todo-tree '(4)))
11831 ((member ans '(?T ?m))
11832 (call-interactively 'org-match-sparse-tree))
11833 ((member ans '(?p ?P))
11834 (setq kwd (org-icompleting-read "Property: "
11835 (mapcar 'list (org-buffer-property-keys))))
11836 (setq value (org-icompleting-read "Value: "
11837 (mapcar 'list (org-property-values kwd))))
11838 (unless (string-match "\\`{.*}\\'" value)
11839 (setq value (concat "\"" value "\"")))
11840 (org-match-sparse-tree arg (concat kwd "=" value)))
11841 ((member ans '(?r ?R ?/))
11842 (call-interactively 'org-occur))
11843 (t (error "No such sparse tree command \"%c\"" ans)))))
11845 (defvar org-occur-highlights nil
11846 "List of overlays used for occur matches.")
11847 (make-variable-buffer-local 'org-occur-highlights)
11848 (defvar org-occur-parameters nil
11849 "Parameters of the active org-occur calls.
11850 This is a list, each call to org-occur pushes as cons cell,
11851 containing the regular expression and the callback, onto the list.
11852 The list can contain several entries if `org-occur' has been called
11853 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11854 will only contain one set of parameters. When the highlights are
11855 removed (for example with `C-c C-c', or with the next edit (depending
11856 on `org-remove-highlights-with-change'), this variable is emptied
11858 (make-variable-buffer-local 'org-occur-parameters)
11860 (defun org-occur (regexp &optional keep-previous callback)
11861 "Make a compact tree which shows all matches of REGEXP.
11862 The tree will show the lines where the regexp matches, and all higher
11863 headlines above the match. It will also show the heading after the match,
11864 to make sure editing the matching entry is easy.
11865 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11866 call to `org-occur' will be kept, to allow stacking of calls to this
11868 If CALLBACK is non-nil, it is a function which is called to confirm
11869 that the match should indeed be shown."
11870 (interactive "sRegexp: \nP")
11871 (when (equal regexp "")
11872 (error "Regexp cannot be empty"))
11873 (unless keep-previous
11874 (org-remove-occur-highlights nil nil t))
11875 (push (cons regexp callback) org-occur-parameters)
11878 (goto-char (point-min))
11879 (if (or (not keep-previous) ; do not want to keep
11880 (not org-occur-highlights)) ; no previous matches
11883 (while (re-search-forward regexp nil t)
11884 (when (or (not callback)
11885 (save-match-data (funcall callback)))
11886 (setq cnt (1+ cnt))
11887 (when org-highlight-sparse-tree-matches
11888 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11889 (org-show-context 'occur-tree))))
11890 (when org-remove-highlights-with-change
11891 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11893 (unless org-sparse-tree-open-archived-trees
11894 (org-hide-archived-subtrees (point-min) (point-max)))
11895 (run-hooks 'org-occur-hook)
11896 (if (interactive-p)
11897 (message "%d match(es) for regexp %s" cnt regexp))
11900 (defun org-show-context (&optional key)
11901 "Make sure point and context are visible.
11902 How much context is shown depends upon the variables
11903 `org-show-hierarchy-above', `org-show-following-heading'. and
11904 `org-show-siblings'."
11905 (let ((heading-p (org-on-heading-p t))
11906 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11907 (following-p (org-get-alist-option org-show-following-heading key))
11908 (entry-p (org-get-alist-option org-show-entry-below key))
11909 (siblings-p (org-get-alist-option org-show-siblings key)))
11911 ;; Show heading or entry text
11912 (if (and heading-p (not entry-p))
11913 (org-flag-heading nil) ; only show the heading
11914 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11915 (org-show-hidden-entry))) ; show entire entry
11917 ;; Show next sibling, or heading below text
11919 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11920 (org-flag-heading nil))))
11921 (when siblings-p (org-show-siblings))
11923 ;; show all higher headings, possibly with siblings
11925 (while (and (condition-case nil
11926 (progn (org-up-heading-all 1) t)
11929 (org-flag-heading nil)
11930 (when siblings-p (org-show-siblings))))))))
11932 (defvar org-reveal-start-hook nil
11933 "Hook run before revealing a location.")
11935 (defun org-reveal (&optional siblings)
11936 "Show current entry, hierarchy above it, and the following headline.
11937 This can be used to show a consistent set of context around locations
11938 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11939 not t for the search context.
11941 With optional argument SIBLINGS, on each level of the hierarchy all
11942 siblings are shown. This repairs the tree structure to what it would
11943 look like when opened with hierarchical calls to `org-cycle'.
11944 With double optional argument `C-u C-u', go to the parent and show the
11947 (run-hooks 'org-reveal-start-hook)
11948 (let ((org-show-hierarchy-above t)
11949 (org-show-following-heading t)
11950 (org-show-siblings (if siblings t org-show-siblings)))
11951 (org-show-context nil))
11952 (when (equal siblings '(16))
11954 (when (org-up-heading-safe)
11956 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11958 (defun org-highlight-new-match (beg end)
11959 "Highlight from BEG to END and mark the highlight is an occur headline."
11960 (let ((ov (make-overlay beg end)))
11961 (overlay-put ov 'face 'secondary-selection)
11962 (push ov org-occur-highlights)))
11964 (defun org-remove-occur-highlights (&optional beg end noremove)
11965 "Remove the occur highlights from the buffer.
11966 BEG and END are ignored. If NOREMOVE is nil, remove this function
11967 from the `before-change-functions' in the current buffer."
11969 (unless org-inhibit-highlight-removal
11970 (mapc 'delete-overlay org-occur-highlights)
11971 (setq org-occur-highlights nil)
11972 (setq org-occur-parameters nil)
11974 (remove-hook 'before-change-functions
11975 'org-remove-occur-highlights 'local))))
11979 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11980 "Regular expression matching the priority indicator.")
11982 (defvar org-remove-priority-next-time nil)
11984 (defun org-priority-up ()
11985 "Increase the priority of the current item."
11987 (org-priority 'up))
11989 (defun org-priority-down ()
11990 "Decrease the priority of the current item."
11992 (org-priority 'down))
11994 (defun org-priority (&optional action)
11995 "Change the priority of an item by ARG.
11996 ACTION can be `set', `up', `down', or a character."
11998 (unless org-enable-priority-commands
11999 (error "Priority commands are disabled"))
12000 (setq action (or action 'set))
12001 (let (current new news have remove)
12003 (org-back-to-heading t)
12004 (if (looking-at org-priority-regexp)
12005 (setq current (string-to-char (match-string 2))
12007 (setq current org-default-priority))
12009 ((eq action 'remove)
12010 (setq remove t new ?\ ))
12011 ((or (eq action 'set)
12012 (if (featurep 'xemacs) (characterp action) (integerp action)))
12013 (if (not (eq action 'set))
12015 (message "Priority %c-%c, SPC to remove: "
12016 org-highest-priority org-lowest-priority)
12017 (setq new (read-char-exclusive)))
12018 (if (and (= (upcase org-highest-priority) org-highest-priority)
12019 (= (upcase org-lowest-priority) org-lowest-priority))
12020 (setq new (upcase new)))
12021 (cond ((equal new ?\ ) (setq remove t))
12022 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
12023 (error "Priority must be between `%c' and `%c'"
12024 org-highest-priority org-lowest-priority))))
12026 (if (and (not have) (eq last-command this-command))
12027 (setq new org-lowest-priority)
12028 (setq new (if (and org-priority-start-cycle-with-default (not have))
12029 org-default-priority (1- current)))))
12031 (if (and (not have) (eq last-command this-command))
12032 (setq new org-highest-priority)
12033 (setq new (if (and org-priority-start-cycle-with-default (not have))
12034 org-default-priority (1+ current)))))
12035 (t (error "Invalid action")))
12036 (if (or (< (upcase new) org-highest-priority)
12037 (> (upcase new) org-lowest-priority))
12039 (setq news (format "%c" new))
12042 (replace-match "" t t nil 1)
12043 (replace-match news t t nil 2))
12045 (error "No priority cookie found in line")
12046 (let ((case-fold-search nil))
12047 (looking-at org-todo-line-regexp))
12050 (goto-char (match-end 2))
12051 (insert " [#" news "]"))
12052 (goto-char (match-beginning 3))
12053 (insert "[#" news "] "))))
12054 (org-preserve-lc (org-set-tags nil 'align)))
12056 (message "Priority removed")
12057 (message "Priority of current item set to %s" news))))
12059 (defun org-get-priority (s)
12060 "Find priority cookie and return priority."
12062 (if (not (string-match org-priority-regexp s))
12063 (* 1000 (- org-lowest-priority org-default-priority))
12064 (* 1000 (- org-lowest-priority
12065 (string-to-char (match-string 2 s)))))))
12069 (defvar org-agenda-archives-mode)
12070 (defvar org-map-continue-from nil
12071 "Position from where mapping should continue.
12072 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
12074 (defvar org-scanner-tags nil
12075 "The current tag list while the tags scanner is running.")
12076 (defvar org-trust-scanner-tags nil
12077 "Should `org-get-tags-at' use the tags fro the scanner.
12078 This is for internal dynamical scoping only.
12079 When this is non-nil, the function `org-get-tags-at' will return the value
12080 of `org-scanner-tags' instead of building the list by itself. This
12081 can lead to large speed-ups when the tags scanner is used in a file with
12082 many entries, and when the list of tags is retrieved, for example to
12083 obtain a list of properties. Building the tags list for each entry in such
12084 a file becomes an N^2 operation - but with this variable set, it scales
12087 (defun org-scan-tags (action matcher &optional todo-only)
12088 "Scan headline tags with inheritance and produce output ACTION.
12090 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
12091 or `agenda' to produce an entry list for an agenda view. It can also be
12092 a Lisp form or a function that should be called at each matched headline, in
12093 this case the return value is a list of all return values from these calls.
12095 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
12096 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
12097 only lines with a TODO keyword are included in the output."
12098 (require 'org-agenda)
12099 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
12100 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
12102 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
12103 (props (list 'face 'default
12104 'done-face 'org-agenda-done
12105 'undone-face 'default
12106 'mouse-face 'highlight
12107 'org-not-done-regexp org-not-done-regexp
12108 'org-todo-regexp org-todo-regexp
12110 (format "mouse-2 or RET jump to org file %s"
12111 (abbreviate-file-name
12112 (or (buffer-file-name (buffer-base-buffer))
12113 (buffer-name (buffer-base-buffer)))))))
12114 (case-fold-search nil)
12115 (org-map-continue-from nil)
12116 lspos tags tags-list
12117 (tags-alist (list (cons 0 org-file-tags)))
12118 (llast 0) rtn rtn1 level category i txt
12119 todo marker entry priority)
12120 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
12121 (setq action (list 'lambda nil action)))
12123 (goto-char (point-min))
12124 (when (eq action 'sparse-tree)
12126 (org-remove-occur-highlights))
12127 (while (re-search-forward re nil t)
12129 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
12130 tags (if (match-end 4) (org-match-string-no-properties 4)))
12131 (goto-char (setq lspos (match-beginning 0)))
12132 (setq level (org-reduced-level (funcall outline-level))
12133 category (org-get-category))
12134 (setq i llast llast level)
12135 ;; remove tag lists from same and sublevels
12136 (while (>= i level)
12137 (when (setq entry (assoc i tags-alist))
12138 (setq tags-alist (delete entry tags-alist)))
12140 ;; add the next tags
12142 (setq tags (org-split-string tags ":")
12144 (cons (cons level tags) tags-alist)))
12145 ;; compile tags for current headline
12147 (if org-use-tag-inheritance
12148 (apply 'append (mapcar 'cdr (reverse tags-alist)))
12150 org-scanner-tags tags-list)
12151 (when org-use-tag-inheritance
12152 (setcdr (car tags-alist)
12153 (mapcar (lambda (x)
12154 (setq x (copy-sequence x))
12155 (org-add-prop-inherited x))
12156 (cdar tags-alist))))
12157 (when (and tags org-use-tag-inheritance
12158 (or (not (eq t org-use-tag-inheritance))
12159 org-tags-exclude-from-inheritance))
12160 ;; selective inheritance, remove uninherited ones
12161 (setcdr (car tags-alist)
12162 (org-remove-uniherited-tags (cdar tags-alist))))
12163 (when (and (or (not todo-only)
12164 (and (member todo org-not-done-keywords)
12165 (or (not org-agenda-tags-todo-honor-ignore-options)
12166 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
12167 (let ((case-fold-search t)) (eval matcher))
12169 (not (member org-archive-tag tags-list))
12170 ;; we have an archive tag, should we use this anyway?
12171 (or (not org-agenda-skip-archived-trees)
12172 (and (eq action 'agenda) org-agenda-archives-mode))))
12173 (unless (eq action 'sparse-tree) (org-agenda-skip))
12175 ;; select this headline
12178 ((eq action 'sparse-tree)
12179 (and org-highlight-sparse-tree-matches
12180 (org-get-heading) (match-end 0)
12181 (org-highlight-new-match
12182 (match-beginning 0) (match-beginning 1)))
12183 (org-show-context 'tags-tree))
12184 ((eq action 'agenda)
12185 (setq txt (org-format-agenda-item
12188 (if (eq org-tags-match-list-sublevels 'indented)
12189 (make-string (1- level) ?.) "")
12194 priority (org-get-priority txt))
12196 (setq marker (org-agenda-new-marker))
12197 (org-add-props txt props
12198 'org-marker marker 'org-hd-marker marker 'org-category category
12200 'priority priority 'type "tagsmatch")
12202 ((functionp action)
12203 (setq org-map-continue-from nil)
12205 (setq rtn1 (funcall action))
12207 (t (error "Invalid action")))
12209 ;; if we are to skip sublevels, jump to end of subtree
12210 (unless org-tags-match-list-sublevels
12211 (org-end-of-subtree t)
12212 (backward-char 1))))
12213 ;; Get the correct position from where to continue
12214 (if org-map-continue-from
12215 (goto-char org-map-continue-from)
12216 (and (= (point) lspos) (end-of-line 1)))))
12217 (when (and (eq action 'sparse-tree)
12218 (not org-sparse-tree-open-archived-trees))
12219 (org-hide-archived-subtrees (point-min) (point-max)))
12222 (defun org-remove-uniherited-tags (tags)
12223 "Remove all tags that are not inherited from the list TAGS."
12225 ((eq org-use-tag-inheritance t)
12226 (if org-tags-exclude-from-inheritance
12227 (org-delete-all org-tags-exclude-from-inheritance tags)
12229 ((not org-use-tag-inheritance) nil)
12230 ((stringp org-use-tag-inheritance)
12233 (if (and (string-match org-use-tag-inheritance x)
12234 (not (member x org-tags-exclude-from-inheritance)))
12237 ((listp org-use-tag-inheritance)
12240 (if (member x org-use-tag-inheritance) x nil))
12243 (defvar todo-only) ;; dynamically scoped
12245 (defun org-match-sparse-tree (&optional todo-only match)
12246 "Create a sparse tree according to tags string MATCH.
12247 MATCH can contain positive and negative selection of tags, like
12248 \"+WORK+URGENT-WITHBOSS\".
12249 If optional argument TODO-ONLY is non-nil, only select lines that are
12252 (org-prepare-agenda-buffers (list (current-buffer)))
12253 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
12255 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
12257 (defvar org-cached-props nil)
12258 (defun org-cached-entry-get (pom property)
12259 (if (or (eq t org-use-property-inheritance)
12260 (and (stringp org-use-property-inheritance)
12261 (string-match org-use-property-inheritance property))
12262 (and (listp org-use-property-inheritance)
12263 (member property org-use-property-inheritance)))
12264 ;; Caching is not possible, check it directly
12265 (org-entry-get pom property 'inherit)
12266 ;; Get all properties, so that we can do complicated checks easily
12267 (cdr (assoc property (or org-cached-props
12268 (setq org-cached-props
12269 (org-entry-properties pom)))))))
12271 (defun org-global-tags-completion-table (&optional files)
12272 "Return the list of all tags in all agenda buffer/files."
12279 (set-buffer (find-file-noselect file))
12280 (append (org-get-buffer-tags)
12281 (mapcar (lambda (x) (if (stringp (car-safe x))
12282 (list (car-safe x)) nil))
12284 (if (and files (car files))
12286 (org-agenda-files))))))))
12288 (defun org-make-tags-matcher (match)
12289 "Create the TAGS//TODO matcher form for the selection string MATCH."
12290 ;; todo-only is scoped dynamically into this function, and the function
12291 ;; may change it if the matcher asks for it.
12293 ;; Get a new match request, with completion
12294 (let ((org-last-tags-completion-table
12295 (org-global-tags-completion-table)))
12296 (setq match (org-completing-read-no-i
12297 "Match: " 'org-tags-completion-function nil nil nil
12298 'org-tags-history))))
12300 ;; Parse the string and create a lisp form
12301 (let ((match0 match)
12302 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
12304 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
12305 orterms term orlist re-p str-p level-p level-op time-p
12306 prop-p pn pv po cat-p gv rest)
12307 (if (string-match "/+" match)
12308 ;; match contains also a todo-matching request
12310 (setq tagsmatch (substring match 0 (match-beginning 0))
12311 todomatch (substring match (match-end 0)))
12312 (if (string-match "^!" todomatch)
12313 (setq todo-only t todomatch (substring todomatch 1)))
12314 (if (string-match "^\\s-*$" todomatch)
12315 (setq todomatch nil)))
12316 ;; only matching tags
12317 (setq tagsmatch match todomatch nil))
12319 ;; Make the tags matcher
12320 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
12321 (setq tagsmatcher t)
12322 (setq orterms (org-split-string tagsmatch "|") orlist nil)
12323 (while (setq term (pop orterms))
12324 (while (and (equal (substring term -1) "\\") orterms)
12325 (setq term (concat term "|" (pop orterms)))) ; repair bad split
12326 (while (string-match re term)
12327 (setq rest (substring term (match-end 0))
12328 minus (and (match-end 1)
12329 (equal (match-string 1 term) "-"))
12330 tag (match-string 2 term)
12331 re-p (equal (string-to-char tag) ?{)
12332 level-p (match-end 4)
12333 prop-p (match-end 5)
12335 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
12337 (setq level-op (org-op-to-function (match-string 3 term)))
12338 `(,level-op level ,(string-to-number
12339 (match-string 4 term))))
12341 (setq pn (match-string 5 term)
12342 po (match-string 6 term)
12343 pv (match-string 7 term)
12344 cat-p (equal pn "CATEGORY")
12345 re-p (equal (string-to-char pv) ?{)
12346 str-p (equal (string-to-char pv) ?\")
12347 time-p (save-match-data
12348 (string-match "^\"[[<].*[]>]\"$" pv))
12349 pv (if (or re-p str-p) (substring pv 1 -1) pv))
12350 (if time-p (setq pv (org-matcher-time pv)))
12351 (setq po (org-op-to-function po (if time-p 'time str-p)))
12353 ((equal pn "CATEGORY")
12354 (setq gv '(get-text-property (point) 'org-category)))
12358 (setq gv `(org-cached-entry-get nil ,pn))))
12361 `(not (string-match ,pv (or ,gv "")))
12362 `(string-match ,pv (or ,gv "")))
12364 `(,po (or ,gv "") ,pv)
12365 `(,po (string-to-number (or ,gv ""))
12366 ,(string-to-number pv) ))))
12367 (t `(member ,tag tags-list)))
12368 mm (if minus (list 'not mm) mm)
12370 (push mm tagsmatcher))
12371 (push (if (> (length tagsmatcher) 1)
12372 (cons 'and tagsmatcher)
12375 (setq tagsmatcher nil))
12376 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
12378 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
12379 ;; Make the todo matcher
12380 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
12381 (setq todomatcher t)
12382 (setq orterms (org-split-string todomatch "|") orlist nil)
12383 (while (setq term (pop orterms))
12384 (while (string-match re term)
12385 (setq minus (and (match-end 1)
12386 (equal (match-string 1 term) "-"))
12387 kwd (match-string 2 term)
12388 re-p (equal (string-to-char kwd) ?{)
12389 term (substring term (match-end 0))
12391 `(string-match ,(substring kwd 1 -1) todo)
12392 (list 'equal 'todo kwd))
12393 mm (if minus (list 'not mm) mm))
12394 (push mm todomatcher))
12395 (push (if (> (length todomatcher) 1)
12396 (cons 'and todomatcher)
12399 (setq todomatcher nil))
12400 (setq todomatcher (if (> (length orlist) 1)
12401 (cons 'or orlist) (car orlist))))
12403 ;; Return the string and lisp forms of the matcher
12404 (setq matcher (if todomatcher
12405 (list 'and tagsmatcher todomatcher)
12407 (cons match0 matcher)))
12409 (defun org-op-to-function (op &optional stringp)
12410 "Turn an operator into the appropriate function."
12413 ((equal op "<" ) '(< string< org-time<))
12414 ((equal op ">" ) '(> org-string> org-time>))
12415 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
12416 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
12417 ((member op '("=" "==")) '(= string= org-time=))
12418 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
12419 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
12421 (defun org<> (a b) (not (= a b)))
12422 (defun org-string<= (a b) (or (string= a b) (string< a b)))
12423 (defun org-string>= (a b) (not (string< a b)))
12424 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
12425 (defun org-string<> (a b) (not (string= a b)))
12426 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
12427 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
12428 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
12429 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
12430 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
12431 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
12433 "Convert S to a floating point time.
12434 If S is already a number, just return it. If it is a string, parse
12435 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12439 (condition-case nil
12440 (float-time (apply 'encode-time (org-parse-time-string s)))
12444 (defun org-time-today ()
12445 "Time in seconds today at 0:00.
12446 Returns the float number of seconds since the beginning of the
12447 epoch to the beginning of today (00:00)."
12448 (float-time (apply 'encode-time
12449 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12451 (defun org-matcher-time (s)
12452 "Interpret a time comparison value."
12455 ((string= s "<now>") (float-time))
12456 ((string= s "<today>") (org-time-today))
12457 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12458 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12459 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12460 (+ (org-time-today)
12461 (* (string-to-number (match-string 1 s))
12462 (cdr (assoc (match-string 2 s)
12463 '(("d" . 86400.0) ("w" . 604800.0)
12464 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12467 (defun org-match-any-p (re list)
12468 "Does re match any element of list?"
12469 (setq list (mapcar (lambda (x) (string-match re x)) list))
12472 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12473 (defvar org-tags-overlay (make-overlay 1 1))
12474 (org-detach-overlay org-tags-overlay)
12476 (defun org-get-local-tags-at (&optional pos)
12477 "Get a list of tags defined in the current headline."
12478 (org-get-tags-at pos 'local))
12480 (defun org-get-local-tags ()
12481 "Get a list of tags defined in the current headline."
12482 (org-get-tags-at nil 'local))
12484 (defun org-get-tags-at (&optional pos local)
12485 "Get a list of all headline tags applicable at POS.
12486 POS defaults to point. If tags are inherited, the list contains
12487 the targets in the same sequence as the headlines appear, i.e.
12488 the tags of the current headline come last.
12489 When LOCAL is non-nil, only return tags from the current headline,
12490 ignore inherited ones."
12492 (if (and org-trust-scanner-tags
12493 (or (not pos) (equal pos (point)))
12496 (let (tags ltags lastpos parent)
12500 (goto-char (or pos (point)))
12503 (condition-case nil
12505 (org-back-to-heading t)
12506 (while (not (equal lastpos (point)))
12507 (setq lastpos (point))
12509 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12510 (setq ltags (org-split-string
12511 (org-match-string-no-properties 1) ":"))
12513 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12516 (org-remove-uniherited-tags ltags)
12519 (or org-use-tag-inheritance (throw 'done t))
12520 (if local (throw 'done t))
12521 (or (org-up-heading-safe) (error nil))
12524 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12526 (defun org-add-prop-inherited (s)
12527 (add-text-properties 0 (length s) '(inherited t) s)
12530 (defun org-toggle-tag (tag &optional onoff)
12531 "Toggle the tag TAG for the current line.
12532 If ONOFF is `on' or `off', don't toggle but set to this state."
12535 (org-back-to-heading t)
12536 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12539 (setq current (match-string 1))
12540 (replace-match ""))
12542 (setq current (nreverse (org-split-string current ":")))
12546 (or (member tag current) (push tag current)))
12548 (or (not (member tag current)) (setq current (delete tag current))))
12549 (t (if (member tag current)
12550 (setq current (delete tag current))
12552 (push tag current))))
12556 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12557 (org-set-tags nil t))
12558 (delete-horizontal-space))
12559 (run-hooks 'org-after-tags-change-hook))
12562 (defun org-align-tags-here (to-col)
12563 ;; Assumes that this is a headline
12564 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12565 (beginning-of-line 1)
12566 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12567 (< pos (match-beginning 2)))
12569 (setq tags-l (- (match-end 2) (match-beginning 2)))
12570 (goto-char (match-beginning 1))
12572 (delete-region (point) (1+ (match-beginning 2)))
12573 (setq ncol (max (1+ (current-column))
12577 (- (abs to-col) tags-l))))
12579 (insert (make-string (- ncol (current-column)) ?\ ))
12580 (setq ncol (current-column))
12581 (when indent-tabs-mode (tabify p (point-at-eol)))
12582 (org-move-to-column (min ncol col) t))
12585 (defun org-set-tags-command (&optional arg just-align)
12586 "Call the set-tags command for the current entry."
12588 (if (org-on-heading-p)
12589 (org-set-tags arg just-align)
12591 (org-back-to-heading t)
12592 (org-set-tags arg just-align))))
12594 (defun org-set-tags-to (data)
12595 "Set the tags of the current entry to DATA, replacing the current tags.
12596 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12597 If DATA is nil or the empty string, any tags will be removed."
12598 (interactive "sTags: ")
12602 ((equal data "") "")
12604 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12607 (concat ":" (mapconcat 'identity data ":") ":"))
12611 (org-back-to-heading t)
12612 (when (looking-at org-complex-heading-regexp)
12615 (goto-char (match-beginning 5))
12617 (delete-region (point) (point-at-eol))
12618 (org-set-tags nil 'align))
12619 (goto-char (point-at-eol))
12621 (org-set-tags nil 'align)))
12622 (beginning-of-line 1)
12623 (if (looking-at ".*?\\([ \t]+\\)$")
12624 (delete-region (match-beginning 1) (match-end 1))))))
12626 (defun org-align-all-tags ()
12627 "Align the tags i all headings."
12630 (or (ignore-errors (org-back-to-heading t))
12631 (outline-next-heading))
12632 (if (org-on-heading-p)
12634 (message "No headings"))))
12636 (defun org-set-tags (&optional arg just-align)
12637 "Set the tags for the current headline.
12638 With prefix ARG, realign all tags in headings in the current buffer."
12640 (let* ((re (concat "^" outline-regexp))
12641 (current (org-get-tags-string))
12642 (col (current-column))
12643 (org-setting-tags t)
12644 table current-tags inherited-tags ; computed below when needed
12648 (goto-char (point-min))
12649 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12650 (while (re-search-forward re nil t)
12651 (org-set-tags nil t)
12653 (message "All tags realigned to column %d" org-tags-column))
12655 (setq tags current)
12656 ;; Get a new set of tags from the user
12658 (setq table (append org-tag-persistent-alist
12659 (or org-tag-alist (org-get-buffer-tags))
12660 (and org-complete-tags-always-offer-all-agenda-tags
12661 (org-global-tags-completion-table (org-agenda-files))))
12662 org-last-tags-completion-table table
12663 current-tags (org-split-string current ":")
12664 inherited-tags (nreverse
12665 (nthcdr (length current-tags)
12666 (nreverse (org-get-tags-at))))
12668 (if (or (eq t org-use-fast-tag-selection)
12669 (and org-use-fast-tag-selection
12670 (delq nil (mapcar 'cdr table))))
12671 (org-fast-tag-selection
12672 current-tags inherited-tags table
12673 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12674 (let ((org-add-colon-after-tag-completion t))
12676 (org-without-partial-completion
12677 (org-icompleting-read "Tags: " 'org-tags-completion-function
12678 nil nil current 'org-tags-history)))))))
12679 (while (string-match "[-+&]+" tags)
12680 ;; No boolean logic, just a list
12681 (setq tags (replace-match ":" t t tags))))
12683 (if org-tags-sort-function
12684 (setq tags (mapconcat 'identity
12685 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12686 org-tags-sort-function) ":")))
12688 (if (string-match "\\`[\t ]*\\'" tags)
12690 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12691 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12693 ;; Insert new tags at the correct column
12694 (beginning-of-line 1)
12696 ((and (equal current "") (equal tags "")))
12697 ((re-search-forward
12698 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12700 (if (equal tags "")
12702 (goto-char (match-beginning 0))
12703 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12704 (1+ (point)) (point))
12705 c1 (max (1+ c0) (if (> org-tags-column 0)
12707 (- (- org-tags-column) (length tags))))
12708 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12709 (replace-match rpl t t)
12710 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12712 (t (error "Tags alignment failed")))
12713 (org-move-to-column col)
12715 (run-hooks 'org-after-tags-change-hook)))))
12717 (defun org-change-tag-in-region (beg end tag off)
12718 "Add or remove TAG for each entry in the region.
12719 This works in the agenda, and also in an org-mode buffer."
12721 (list (region-beginning) (region-end)
12722 (let ((org-last-tags-completion-table
12724 (org-get-buffer-tags)
12725 (org-global-tags-completion-table))))
12726 (org-icompleting-read
12727 "Tag: " 'org-tags-completion-function nil nil nil
12728 'org-tags-history))
12730 (message "[s]et or [r]emove? ")
12731 (equal (read-char-exclusive) ?r))))
12732 (if (fboundp 'deactivate-mark) (deactivate-mark))
12733 (let ((agendap (equal major-mode 'org-agenda-mode))
12734 l1 l2 m buf pos newhead (cnt 0))
12736 (setq l2 (1- (org-current-line)))
12738 (setq l1 (org-current-line))
12739 (loop for l from l1 to l2 do
12741 (setq m (get-text-property (point) 'org-hd-marker))
12742 (when (or (and (org-mode-p) (org-on-heading-p))
12744 (setq buf (if agendap (marker-buffer m) (current-buffer))
12745 pos (if agendap m (point)))
12746 (with-current-buffer buf
12750 (setq cnt (1+ cnt))
12751 (org-toggle-tag tag (if off 'off 'on))
12752 (setq newhead (org-get-heading)))))
12753 (and agendap (org-agenda-change-all-lines newhead m))))
12754 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12756 (defun org-tags-completion-function (string predicate &optional flag)
12757 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12758 (confirm (lambda (x) (stringp (car x)))))
12759 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12760 (setq s1 (match-string 1 string)
12761 s2 (match-string 2 string))
12762 (setq s1 "" s2 string))
12766 (setq rtn (try-completion s2 ctable confirm))
12769 (concat s1 s2 (substring rtn (length s2))
12770 (if (and org-add-colon-after-tag-completion
12771 (assoc rtn ctable))
12776 (all-completions s2 ctable confirm)
12780 (assoc s2 ctable)))
12783 (defun org-fast-tag-insert (kwd tags face &optional end)
12784 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12785 (insert (format "%-12s" (concat kwd ":"))
12786 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12789 (defun org-fast-tag-show-exit (flag)
12792 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12793 (replace-match ""))
12796 (org-move-to-column (- (window-width) 19) t)
12797 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12799 (defun org-set-current-tags-overlay (current prefix)
12800 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12801 (if (featurep 'xemacs)
12802 (org-overlay-display org-tags-overlay (concat prefix s)
12803 'secondary-selection)
12804 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12805 (org-overlay-display org-tags-overlay (concat prefix s)))))
12807 (defvar org-last-tag-selection-key nil)
12808 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12809 "Fast tag selection with single keys.
12810 CURRENT is the current list of tags in the headline, INHERITED is the
12811 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12812 possibly with grouping information. TODO-TABLE is a similar table with
12813 TODO keywords, should these have keys assigned to them.
12814 If the keys are nil, a-z are automatically assigned.
12815 Returns the new tags string, or nil to not change the current settings."
12816 (let* ((fulltable (append table todo-table))
12817 (maxlen (apply 'max (mapcar
12819 (if (stringp (car x)) (string-width (car x)) 0))
12821 (buf (current-buffer))
12822 (expert (eq org-fast-tag-selection-single-key 'expert))
12824 (fwidth (+ maxlen 3 1 3))
12825 (ncol (/ (- (window-width) 4) fwidth))
12828 tg cnt e c char c1 c2 ntable tbl rtn
12829 ov-start ov-end ov-prefix
12830 (exit-after-next org-fast-tag-selection-single-key)
12831 (done-keywords org-done-keywords)
12834 (beginning-of-line 1)
12836 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12837 (setq ov-start (match-beginning 1)
12838 ov-end (match-end 1)
12840 (setq ov-start (1- (point-at-eol))
12841 ov-end (1+ ov-start))
12842 (skip-chars-forward "^\n\r")
12845 (buffer-substring (1- (point)) (point))
12846 (if (> (current-column) org-tags-column)
12848 (make-string (- org-tags-column (current-column)) ?\ ))))))
12849 (move-overlay org-tags-overlay ov-start ov-end)
12850 (save-window-excursion
12852 (set-buffer (get-buffer-create " *Org tags*"))
12853 (delete-other-windows)
12854 (split-window-vertically)
12855 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12857 (org-set-local 'org-done-keywords done-keywords)
12858 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12859 (org-fast-tag-insert "Current" current c-face "\n\n")
12860 (org-fast-tag-show-exit exit-after-next)
12861 (org-set-current-tags-overlay current ov-prefix)
12862 (setq tbl fulltable char ?a cnt 0)
12863 (while (setq e (pop tbl))
12865 ((equal (car e) :startgroup)
12866 (push '() groups) (setq ingroup t)
12867 (when (not (= cnt 0))
12870 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12871 ((equal (car e) :endgroup)
12872 (setq ingroup nil cnt 0)
12873 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12874 ((equal e '(:newline))
12875 (when (not (= cnt 0))
12879 (while (equal (car tbl) '(:newline))
12881 (setq tbl (cdr tbl)))))
12883 (setq tg (copy-sequence (car e)) c2 nil)
12886 ;; automatically assign a character.
12887 (setq c1 (string-to-char
12888 (downcase (substring
12889 tg (if (= (string-to-char tg) ?@) 1 0)))))
12890 (if (or (rassoc c1 ntable) (rassoc c1 table))
12891 (while (or (rassoc char ntable) (rassoc char table))
12892 (setq char (1+ char)))
12894 (setq c (or c2 char)))
12895 (if ingroup (push tg (car groups)))
12896 (setq tg (org-add-props tg nil 'face
12898 ((not (assoc tg table))
12899 (org-get-todo-face tg))
12900 ((member tg current) c-face)
12901 ((member tg inherited) i-face)
12903 (if (and (= cnt 0) (not ingroup)) (insert " "))
12904 (insert "[" c "] " tg (make-string
12905 (- fwidth 4 (length tg)) ?\ ))
12906 (push (cons tg c) ntable)
12907 (when (= (setq cnt (1+ cnt)) ncol)
12909 (if ingroup (insert " "))
12911 (setq ntable (nreverse ntable))
12913 (goto-char (point-min))
12914 (if (not expert) (org-fit-window-to-buffer))
12918 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12919 (if (not groups) "no " "")
12920 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12921 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12922 (setq org-last-tag-selection-key c)
12924 ((= c ?\r) (throw 'exit t))
12926 (setq groups (not groups))
12927 (goto-char (point-min))
12928 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12931 (org-fast-tag-show-exit
12932 (setq exit-after-next (not exit-after-next)))
12934 (delete-other-windows)
12935 (split-window-vertically)
12936 (org-switch-to-buffer-other-window " *Org tags*")
12937 (org-fit-window-to-buffer)))
12939 (and (= c ?q) (not (rassoc c ntable))))
12940 (org-detach-overlay org-tags-overlay)
12941 (setq quit-flag t))
12944 (if exit-after-next (setq exit-after-next 'now)))
12946 (condition-case nil
12947 (setq tg (org-icompleting-read
12950 (with-current-buffer buf
12951 (org-get-buffer-tags)))))
12952 (quit (setq tg "")))
12953 (when (string-match "\\S-" tg)
12954 (add-to-list 'buffer-tags (list tg))
12955 (if (member tg current)
12956 (setq current (delete tg current))
12957 (push tg current)))
12958 (if exit-after-next (setq exit-after-next 'now)))
12959 ((setq e (rassoc c todo-table) tg (car e))
12960 (with-current-buffer buf
12961 (save-excursion (org-todo tg)))
12962 (if exit-after-next (setq exit-after-next 'now)))
12963 ((setq e (rassoc c ntable) tg (car e))
12964 (if (member tg current)
12965 (setq current (delete tg current))
12966 (loop for g in groups do
12969 (setq current (delete x current)))
12972 (if exit-after-next (setq exit-after-next 'now))))
12974 ;; Create a sorted list
12978 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12979 (if (eq exit-after-next 'now) (throw 'exit t))
12980 (goto-char (point-min))
12981 (beginning-of-line 2)
12982 (delete-region (point) (point-at-eol))
12983 (org-fast-tag-insert "Current" current c-face)
12984 (org-set-current-tags-overlay current ov-prefix)
12985 (while (re-search-forward
12986 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12987 (setq tg (match-string 1))
12988 (add-text-properties
12989 (match-beginning 1) (match-end 1)
12992 ((member tg current) c-face)
12993 ((member tg inherited) i-face)
12994 (t (get-text-property (match-beginning 1) 'face))))))
12995 (goto-char (point-min)))))
12996 (org-detach-overlay org-tags-overlay)
12998 (mapconcat 'identity current ":")
13001 (defun org-get-tags-string ()
13002 "Get the TAGS string in the current headline."
13003 (unless (org-on-heading-p t)
13004 (error "Not on a heading"))
13006 (beginning-of-line 1)
13007 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
13008 (org-match-string-no-properties 1)
13011 (defun org-get-tags ()
13012 "Get the list of tags specified in the current headline."
13013 (org-split-string (org-get-tags-string) ":"))
13015 (defun org-get-buffer-tags ()
13016 "Get a table of all tags used in the buffer, for completion."
13019 (goto-char (point-min))
13020 (while (re-search-forward
13021 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
13022 (when (equal (char-after (point-at-bol 0)) ?*)
13023 (mapc (lambda (x) (add-to-list 'tags x))
13024 (org-split-string (org-match-string-no-properties 1) ":")))))
13025 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
13026 (mapcar 'list tags)))
13028 ;;;; The mapping API
13031 (defun org-map-entries (func &optional match scope &rest skip)
13032 "Call FUNC at each headline selected by MATCH in SCOPE.
13034 FUNC is a function or a lisp form. The function will be called without
13035 arguments, with the cursor positioned at the beginning of the headline.
13036 The return values of all calls to the function will be collected and
13037 returned as a list.
13039 The call to FUNC will be wrapped into a save-excursion form, so FUNC
13040 does not need to preserve point. After evaluation, the cursor will be
13041 moved to the end of the line (presumably of the headline of the
13042 processed entry) and search continues from there. Under some
13043 circumstances, this may not produce the wanted results. For example,
13044 if you have removed (e.g. archived) the current (sub)tree it could
13045 mean that the next entry will be skipped entirely. In such cases, you
13046 can specify the position from where search should continue by making
13047 FUNC set the variable `org-map-continue-from' to the desired buffer
13050 MATCH is a tags/property/todo match as it is used in the agenda tags view.
13051 Only headlines that are matched by this query will be considered during
13052 the iteration. When MATCH is nil or t, all headlines will be
13053 visited by the iteration.
13055 SCOPE determines the scope of this command. It can be any of:
13057 nil The current buffer, respecting the restriction if any
13058 tree The subtree started with the entry at point
13059 file The current buffer, without restriction
13061 The current buffer, and any archives associated with it
13062 agenda All agenda files
13063 agenda-with-archives
13064 All agenda files with any archive files associated with them
13066 If this is a list, all files in the list will be scanned
13068 The remaining args are treated as settings for the skipping facilities of
13069 the scanner. The following items can be given here:
13071 archive skip trees with the archive tag.
13072 comment skip trees with the COMMENT keyword
13073 function or Emacs Lisp form:
13074 will be used as value for `org-agenda-skip-function', so whenever
13075 the function returns t, FUNC will not be called for that
13076 entry and search will continue from the point where the
13077 function leaves it.
13079 If your function needs to retrieve the tags including inherited tags
13080 at the *current* entry, you can use the value of the variable
13081 `org-scanner-tags' which will be much faster than getting the value
13082 with `org-get-tags-at'. If your function gets properties with
13083 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
13084 to t around the call to `org-entry-properties' to get the same speedup.
13085 Note that if your function moves around to retrieve tags and properties at
13086 a *different* entry, you cannot use these techniques."
13087 (let* ((org-agenda-archives-mode nil) ; just to make sure
13088 (org-agenda-skip-archived-trees (memq 'archive skip))
13089 (org-agenda-skip-comment-trees (memq 'comment skip))
13090 (org-agenda-skip-function
13091 (car (org-delete-all '(comment archive) skip)))
13092 (org-tags-match-list-sublevels t)
13094 org-todo-keywords-for-agenda
13095 org-done-keywords-for-agenda
13096 org-todo-keyword-alist-for-agenda
13097 org-drawers-for-agenda
13098 org-tag-alist-for-agenda)
13101 ((eq match t) (setq matcher t))
13102 ((eq match nil) (setq matcher t))
13103 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
13107 (when (eq scope 'tree)
13108 (org-back-to-heading t)
13109 (org-narrow-to-subtree)
13114 (org-prepare-agenda-buffers
13115 (list (buffer-file-name (current-buffer))))
13116 (setq res (org-scan-tags func matcher)))
13117 ;; Get the right scope
13119 ((and scope (listp scope) (symbolp (car scope)))
13120 (setq scope (eval scope)))
13121 ((eq scope 'agenda)
13122 (setq scope (org-agenda-files t)))
13123 ((eq scope 'agenda-with-archives)
13124 (setq scope (org-agenda-files t))
13125 (setq scope (org-add-archive-files scope)))
13127 (setq scope (list (buffer-file-name))))
13128 ((eq scope 'file-with-archives)
13129 (setq scope (org-add-archive-files (list (buffer-file-name))))))
13130 (org-prepare-agenda-buffers scope)
13131 (while (setq file (pop scope))
13132 (with-current-buffer (org-find-base-buffer-visiting file)
13136 (goto-char (point-min))
13137 (setq res (append res (org-scan-tags func matcher))))))))))
13142 ;;; Setting and retrieving properties
13144 (defconst org-special-properties
13145 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
13146 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
13147 "The special properties valid in Org-mode.
13149 These are properties that are not defined in the property drawer,
13150 but in some other way.")
13152 (defconst org-default-properties
13153 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
13154 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
13155 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
13156 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
13157 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
13158 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
13159 "Some properties that are used by Org-mode for various purposes.
13160 Being in this list makes sure that they are offered for completion.")
13162 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
13163 "Regular expression matching the first line of a property drawer.")
13165 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
13166 "Regular expression matching the last line of a property drawer.")
13168 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
13169 "Regular expression matching the first line of a property drawer.")
13171 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
13172 "Regular expression matching the first line of a property drawer.")
13174 (defconst org-property-drawer-re
13175 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
13176 org-property-end-re "\\)\n?")
13177 "Matches an entire property drawer.")
13179 (defconst org-clock-drawer-re
13180 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
13181 org-property-end-re "\\)\n?")
13182 "Matches an entire clock drawer.")
13184 (defun org-property-action ()
13185 "Do an action on properties."
13188 (org-at-property-p)
13189 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
13190 (setq c (read-char-exclusive))
13193 (call-interactively 'org-set-property))
13195 (call-interactively 'org-delete-property))
13197 (call-interactively 'org-delete-property-globally))
13199 (call-interactively 'org-compute-property-at-point))
13200 (t (error "No such property action %c" c)))))
13202 (defun org-set-effort (&optional value)
13203 "Set the effort property of the current entry.
13204 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
13207 (if (equal value 0) (setq value 10))
13208 (let* ((completion-ignore-case t)
13209 (prop org-effort-property)
13210 (cur (org-entry-get nil prop))
13211 (allowed (org-property-get-allowed-values nil prop 'table))
13212 (existing (mapcar 'list (org-property-values prop)))
13215 ((stringp value) value)
13216 ((and allowed (integerp value))
13217 (or (car (nth (1- value) allowed))
13218 (car (org-last allowed))))
13220 (message "Select 1-9,0, [RET%s]: %s"
13221 (if cur (concat "=" cur) "")
13222 (mapconcat 'car allowed " "))
13223 (setq rpl (read-char-exclusive))
13224 (if (equal rpl ?\r)
13226 (setq rpl (- rpl ?0))
13227 (if (equal rpl 0) (setq rpl 10))
13228 (if (and (> rpl 0) (<= rpl (length allowed)))
13229 (car (nth (1- rpl) allowed))
13230 (org-completing-read "Effort: " allowed nil))))
13232 (let (org-completion-use-ido org-completion-use-iswitchb)
13233 (org-completing-read
13234 (concat "Effort " (if (and cur (string-match "\\S-" cur))
13235 (concat "[" cur "]") "")
13237 existing nil nil "" nil cur))))))
13238 (unless (equal (org-entry-get nil prop) val)
13239 (org-entry-put nil prop val))
13240 (message "%s is now %s" prop val)))
13242 (defun org-at-property-p ()
13243 "Is cursor inside a property drawer?"
13245 (beginning-of-line 1)
13246 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
13247 (save-match-data ;; Used by calling procedures
13249 (range (unless (org-before-first-heading-p)
13250 (org-get-property-block))))
13251 (and range (<= (car range) p) (< p (cdr range))))))))
13253 (defun org-get-property-block (&optional beg end force)
13254 "Return the (beg . end) range of the body of the property drawer.
13255 BEG and END can be beginning and end of subtree, if not given
13256 they will be found.
13257 If the drawer does not exist and FORCE is non-nil, create the drawer."
13260 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
13261 (end (or end (progn (outline-next-heading) (point)))))
13263 (if (re-search-forward org-property-start-re end t)
13264 (setq beg (1+ (match-end 0)))
13267 (org-insert-property-drawer)
13268 (setq end (progn (outline-next-heading) (point))))
13271 (if (re-search-forward org-property-start-re end t)
13272 (setq beg (1+ (match-end 0)))))
13273 (if (re-search-forward org-property-end-re end t)
13274 (setq end (match-beginning 0))
13275 (or force (throw 'exit nil))
13278 (org-indent-line-function)
13279 (insert ":END:\n"))
13282 (defun org-entry-properties (&optional pom which specific)
13283 "Get all properties of the entry at point-or-marker POM.
13284 This includes the TODO keyword, the tags, time strings for deadline,
13285 scheduled, and clocking, and any additional properties defined in the
13286 entry. The return value is an alist, keys may occur multiple times
13287 if the property key was used several times.
13288 POM may also be nil, in which case the current entry is used.
13289 If WHICH is nil or `all', get all properties. If WHICH is
13290 `special' or `standard', only get that subclass. If WHICH
13291 is a string only get exactly this property. Specific can be a string, the
13292 specific property we are interested in. Specifying it can speed
13293 things up because then unnecessary parsing is avoided."
13294 (setq which (or which 'all))
13295 (org-with-point-at pom
13296 (let ((clockstr (substring org-clock-string 0 -1))
13297 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
13298 (case-fold-search nil)
13299 beg end range props sum-props key key1 value string clocksum)
13301 (when (condition-case nil
13302 (and (org-mode-p) (org-back-to-heading t))
13305 (setq sum-props (get-text-property (point) 'org-summaries))
13306 (setq clocksum (get-text-property (point) :org-clock-minutes))
13307 (outline-next-heading)
13309 (when (memq which '(all special))
13310 ;; Get the special properties, like TODO and tags
13312 (when (and (or (not specific) (string= specific "TODO"))
13313 (looking-at org-todo-line-regexp) (match-end 2))
13314 (push (cons "TODO" (org-match-string-no-properties 2)) props))
13315 (when (and (or (not specific) (string= specific "PRIORITY"))
13316 (looking-at org-priority-regexp))
13317 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
13318 (when (and (or (not specific) (string= specific "TAGS"))
13319 (setq value (org-get-tags-string))
13320 (string-match "\\S-" value))
13321 (push (cons "TAGS" value) props))
13322 (when (and (or (not specific) (string= specific "ALLTAGS"))
13323 (setq value (org-get-tags-at)))
13324 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
13327 (when (or (not specific) (string= specific "BLOCKED"))
13328 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
13329 (when (or (not specific)
13331 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
13332 "TIMESTAMP" "TIMESTAMP_IA")))
13333 (while (re-search-forward org-maybe-keyword-time-regexp end t)
13334 (setq key (if (match-end 1)
13335 (substring (org-match-string-no-properties 1)
13337 string (if (equal key clockstr)
13341 (match-beginning 3) (goto-char
13343 (substring (org-match-string-no-properties 3)
13345 ;; Get the correct property name from the key. This is
13346 ;; necessary if the user has configured time keywords.
13347 (setq key1 (concat key ":"))
13351 (if (= (char-after (match-beginning 3)) ?\[)
13352 "TIMESTAMP_IA" "TIMESTAMP")))
13353 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
13354 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
13355 ((equal key1 org-closed-string) (setq key "CLOSED"))
13356 ((equal key1 org-clock-string) (setq key "CLOCK")))
13357 (when (or (equal key "CLOCK") (not (assoc key props)))
13358 (push (cons key string) props))))
13361 (when (memq which '(all standard))
13362 ;; Get the standard properties, like :PROP: ...
13363 (setq range (org-get-property-block beg end))
13365 (goto-char (car range))
13366 (while (re-search-forward
13367 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
13369 (setq key (org-match-string-no-properties 1)
13370 value (org-trim (or (org-match-string-no-properties 2) "")))
13371 (unless (member key excluded)
13372 (push (cons key (or value "")) props)))))
13374 (push (cons "CLOCKSUM"
13375 (org-columns-number-to-string (/ (float clocksum) 60.)
13378 (unless (assoc "CATEGORY" props)
13379 (setq value (or (org-get-category)
13380 (progn (org-refresh-category-properties)
13381 (org-get-category))))
13382 (push (cons "CATEGORY" value) props))
13383 (append sum-props (nreverse props)))))))
13385 (defun org-entry-get (pom property &optional inherit literal-nil)
13386 "Get value of PROPERTY for entry at point-or-marker POM.
13387 If INHERIT is non-nil and the entry does not have the property,
13388 then also check higher levels of the hierarchy.
13389 If INHERIT is the symbol `selective', use inheritance only if the setting
13390 in `org-use-property-inheritance' selects PROPERTY for inheritance.
13391 If the property is present but empty, the return value is the empty string.
13392 If the property is not present at all, nil is returned.
13394 If LITERAL-NIL is set, return the string value \"nil\" as a string,
13395 do not interpret it as the list atom nil. This is used for inheritance
13396 when a \"nil\" value can supercede a non-nil value higher up the hierarchy."
13397 (org-with-point-at pom
13398 (if (and inherit (if (eq inherit 'selective)
13399 (org-property-inherit-p property)
13401 (org-entry-get-with-inheritance property)
13402 (if (member property org-special-properties)
13403 ;; We need a special property. Use `org-entry-properties' to
13404 ;; retrieve it, but specify the wanted property
13405 (cdr (assoc property (org-entry-properties nil 'special property)))
13406 (let ((range (org-get-property-block)))
13408 (goto-char (car range))
13410 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
13412 ;; Found the property, return it.
13415 (org-match-string-no-properties 1)
13416 (org-not-nil (org-match-string-no-properties 1)))
13419 (defun org-property-or-variable-value (var &optional inherit)
13420 "Check if there is a property fixing the value of VAR.
13421 If yes, return this value. If not, return the current value of the variable."
13422 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
13423 (if (and prop (stringp prop) (string-match "\\S-" prop))
13425 (symbol-value var))))
13427 (defun org-entry-delete (pom property)
13428 "Delete the property PROPERTY from entry at point-or-marker POM."
13429 (org-with-point-at pom
13430 (if (member property org-special-properties)
13431 nil ; cannot delete these properties.
13432 (let ((range (org-get-property-block)))
13434 (goto-char (car range))
13436 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
13439 (delete-region (match-beginning 0) (1+ (point-at-eol)))
13443 ;; Multi-values properties are properties that contain multiple values
13444 ;; These values are assumed to be single words, separated by whitespace.
13445 (defun org-entry-add-to-multivalued-property (pom property value)
13446 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
13447 (let* ((old (org-entry-get pom property))
13448 (values (and old (org-split-string old "[ \t]"))))
13449 (setq value (org-entry-protect-space value))
13450 (unless (member value values)
13451 (setq values (cons value values))
13452 (org-entry-put pom property
13453 (mapconcat 'identity values " ")))))
13455 (defun org-entry-remove-from-multivalued-property (pom property value)
13456 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
13457 (let* ((old (org-entry-get pom property))
13458 (values (and old (org-split-string old "[ \t]"))))
13459 (setq value (org-entry-protect-space value))
13460 (when (member value values)
13461 (setq values (delete value values))
13462 (org-entry-put pom property
13463 (mapconcat 'identity values " ")))))
13465 (defun org-entry-member-in-multivalued-property (pom property value)
13466 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
13467 (let* ((old (org-entry-get pom property))
13468 (values (and old (org-split-string old "[ \t]"))))
13469 (setq value (org-entry-protect-space value))
13470 (member value values)))
13472 (defun org-entry-get-multivalued-property (pom property)
13473 "Return a list of values in a multivalued property."
13474 (let* ((value (org-entry-get pom property))
13475 (values (and value (org-split-string value "[ \t]"))))
13476 (mapcar 'org-entry-restore-space values)))
13478 (defun org-entry-put-multivalued-property (pom property &rest values)
13479 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13480 VALUES should be a list of strings. Spaces will be protected."
13481 (org-entry-put pom property
13482 (mapconcat 'org-entry-protect-space values " "))
13483 (let* ((value (org-entry-get pom property))
13484 (values (and value (org-split-string value "[ \t]"))))
13485 (mapcar 'org-entry-restore-space values)))
13487 (defun org-entry-protect-space (s)
13488 "Protect spaces and newline in string S."
13489 (while (string-match " " s)
13490 (setq s (replace-match "%20" t t s)))
13491 (while (string-match "\n" s)
13492 (setq s (replace-match "%0A" t t s)))
13495 (defun org-entry-restore-space (s)
13496 "Restore spaces and newline in string S."
13497 (while (string-match "%20" s)
13498 (setq s (replace-match " " t t s)))
13499 (while (string-match "%0A" s)
13500 (setq s (replace-match "\n" t t s)))
13503 (defvar org-entry-property-inherited-from (make-marker)
13504 "Marker pointing to the entry from where a property was inherited.
13505 Each call to `org-entry-get-with-inheritance' will set this marker to the
13506 location of the entry where the inheritance search matched. If there was
13507 no match, the marker will point nowhere.
13508 Note that also `org-entry-get' calls this function, if the INHERIT flag
13511 (defun org-entry-get-with-inheritance (property)
13512 "Get entry property, and search higher levels if not present."
13513 (move-marker org-entry-property-inherited-from nil)
13520 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
13521 (org-back-to-heading t)
13522 (move-marker org-entry-property-inherited-from (point))
13524 (or (org-up-heading-safe) (throw 'ex nil)))))
13527 (cdr (assoc property org-file-properties))
13528 (cdr (assoc property org-global-properties))
13529 (cdr (assoc property org-global-properties-fixed)))))))
13531 (defvar org-property-changed-functions nil
13532 "Hook called when the value of a property has changed.
13533 Each hook function should accept two arguments, the name of the property
13534 and the new value.")
13536 (defun org-entry-put (pom property value)
13537 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13538 (org-with-point-at pom
13539 (org-back-to-heading t)
13540 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13543 ((equal property "TODO")
13544 (when (and (stringp value) (string-match "\\S-" value)
13545 (not (member value org-todo-keywords-1)))
13546 (error "\"%s\" is not a valid TODO state" value))
13547 (if (or (not value)
13548 (not (string-match "\\S-" value)))
13549 (setq value 'none))
13551 (org-set-tags nil 'align))
13552 ((equal property "PRIORITY")
13553 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13554 (string-to-char value) ?\ ))
13555 (org-set-tags nil 'align))
13556 ((equal property "SCHEDULED")
13557 (if (re-search-forward org-scheduled-time-regexp end t)
13559 ((eq value 'earlier) (org-timestamp-change -1 'day))
13560 ((eq value 'later) (org-timestamp-change 1 'day))
13561 (t (call-interactively 'org-schedule)))
13562 (call-interactively 'org-schedule)))
13563 ((equal property "DEADLINE")
13564 (if (re-search-forward org-deadline-time-regexp end t)
13566 ((eq value 'earlier) (org-timestamp-change -1 'day))
13567 ((eq value 'later) (org-timestamp-change 1 'day))
13568 (t (call-interactively 'org-deadline)))
13569 (call-interactively 'org-deadline)))
13570 ((member property org-special-properties)
13571 (error "The %s property can not yet be set with `org-entry-put'"
13573 (t ; a non-special property
13574 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13575 (setq range (org-get-property-block beg end 'force))
13576 (goto-char (car range))
13577 (if (re-search-forward
13578 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13580 (delete-region (match-beginning 1) (match-end 1))
13581 (goto-char (match-beginning 1)))
13582 (goto-char (cdr range))
13585 (org-indent-line-function)
13586 (insert ":" property ":"))
13587 (and value (insert " " value))
13588 (org-indent-line-function)))))
13589 (run-hook-with-args 'org-property-changed-functions property value)))
13591 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13592 "Get all property keys in the current buffer.
13593 With INCLUDE-SPECIALS, also list the special properties that reflect things
13594 like tags and TODO state.
13595 With INCLUDE-DEFAULTS, also include properties that has special meaning
13596 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13597 With INCLUDE-COLUMNS, also include property names given in COLUMN
13598 formats in the current buffer."
13599 (let (rtn range cfmt s p)
13603 (goto-char (point-min))
13604 (while (re-search-forward org-property-start-re nil t)
13605 (setq range (org-get-property-block))
13606 (goto-char (car range))
13607 (while (re-search-forward
13608 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13610 (add-to-list 'rtn (org-match-string-no-properties 1)))
13611 (outline-next-heading))))
13613 (when include-specials
13614 (setq rtn (append org-special-properties rtn)))
13616 (when include-defaults
13617 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13618 (add-to-list 'rtn org-effort-property))
13620 (when include-columns
13624 (goto-char (point-min))
13625 (while (re-search-forward
13626 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13628 (setq cfmt (match-string 2) s 0)
13629 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13631 (setq s (match-end 0)
13632 p (match-string 1 cfmt))
13633 (unless (or (equal p "ITEM")
13634 (member p org-special-properties))
13635 (add-to-list 'rtn (match-string 1 cfmt))))))))
13637 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13639 (defun org-property-values (key)
13640 "Return a list of all values of property KEY."
13644 (goto-char (point-min))
13645 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13647 (while (re-search-forward re nil t)
13648 (add-to-list 'values (org-trim (match-string 1))))
13649 (delete "" values)))))
13651 (defun org-insert-property-drawer ()
13652 "Insert a property drawer into the current entry."
13654 (org-back-to-heading t)
13655 (looking-at outline-regexp)
13656 (let ((indent (if org-adapt-indentation
13657 (- (match-end 0)(match-beginning 0))
13660 (re (concat "^[ \t]*" org-keyword-time-regexp))
13662 (outline-next-heading)
13665 (while (re-search-forward re end t))
13666 (setq hiddenp (org-invisible-p))
13668 (and (equal (char-after) ?\n) (forward-char 1))
13669 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13670 (if (member (match-string 1) '("CLOCK:" ":END:"))
13671 ;; just skip this line
13672 (beginning-of-line 2)
13673 ;; Drawer start, find the end
13674 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13675 (beginning-of-line 1)))
13676 (org-skip-over-state-notes)
13677 (skip-chars-backward " \t\n\r")
13678 (if (eq (char-before) ?*) (forward-char 1))
13679 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13680 (beginning-of-line 0)
13681 (org-indent-to-column indent)
13682 (beginning-of-line 2)
13683 (org-indent-to-column indent)
13684 (beginning-of-line 0)
13687 (org-back-to-heading t)
13689 (org-flag-drawer t))))
13691 (defun org-set-property (property value)
13692 "In the current entry, set PROPERTY to VALUE.
13693 When called interactively, this will prompt for a property name, offering
13694 completion on existing and default properties. And then it will prompt
13695 for a value, offering completion either on allowed values (via an inherited
13696 xxx_ALL property) or on existing values in other instances of this property
13697 in the current file."
13699 (let* ((completion-ignore-case t)
13700 (keys (org-buffer-property-keys nil t t))
13701 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13702 (prop (if (member prop0 keys)
13704 (or (cdr (assoc (downcase prop0)
13705 (mapcar (lambda (x) (cons (downcase x) x))
13708 (cur (org-entry-get nil prop))
13709 (prompt (concat prop " value"
13710 (if (and cur (string-match "\\S-" cur))
13711 (concat " [" cur "]") "") ": "))
13712 (allowed (org-property-get-allowed-values nil prop 'table))
13713 (existing (mapcar 'list (org-property-values prop)))
13715 (org-completing-read prompt allowed nil
13716 (not (get-text-property 0 'org-unrestricted
13718 (let (org-completion-use-ido org-completion-use-iswitchb)
13719 (org-completing-read prompt existing nil nil "" nil cur)))))
13720 (list prop (if (equal val "") cur val))))
13721 (unless (equal (org-entry-get nil property) value)
13722 (org-entry-put nil property value)))
13724 (defun org-delete-property (property)
13725 "In the current entry, delete PROPERTY."
13727 (let* ((completion-ignore-case t)
13728 (prop (org-icompleting-read "Property: "
13729 (org-entry-properties nil 'standard))))
13731 (message "Property %s %s" property
13732 (if (org-entry-delete nil property)
13734 "was not present in the entry")))
13736 (defun org-delete-property-globally (property)
13737 "Remove PROPERTY globally, from all entries."
13739 (let* ((completion-ignore-case t)
13740 (prop (org-icompleting-read
13741 "Globally remove property: "
13742 (mapcar 'list (org-buffer-property-keys)))))
13747 (goto-char (point-min))
13749 (while (re-search-forward
13750 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13752 (setq cnt (1+ cnt))
13753 (replace-match ""))
13754 (message "Property \"%s\" removed from %d entries" property cnt)))))
13756 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13758 (defun org-compute-property-at-point ()
13759 "Compute the property at point.
13760 This looks for an enclosing column format, extracts the operator and
13761 then applies it to the property in the column format's scope."
13763 (unless (org-at-property-p)
13764 (error "Not at a property"))
13765 (let ((prop (org-match-string-no-properties 2)))
13766 (org-columns-get-format-and-top-level)
13767 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13768 (error "No operator defined for property %s" prop))
13769 (org-columns-compute prop)))
13771 (defvar org-property-allowed-value-functions nil
13772 "Hook for functions supplying allowed values for a specific property.
13773 The functions must take a single argument, the name of the property, and
13774 return a flat list of allowed values. If \":ETC\" is one of
13775 the values, this means that these values are intended as defaults for
13776 completion, but that other values should be allowed too.
13777 The functions must return nil if they are not responsible for this
13780 (defun org-property-get-allowed-values (pom property &optional table)
13781 "Get allowed values for the property PROPERTY.
13782 When TABLE is non-nil, return an alist that can directly be used for
13786 ((equal property "TODO")
13787 (setq vals (org-with-point-at pom
13788 (append org-todo-keywords-1 '("")))))
13789 ((equal property "PRIORITY")
13790 (let ((n org-lowest-priority))
13791 (while (>= n org-highest-priority)
13792 (push (char-to-string n) vals)
13794 ((member property org-special-properties))
13795 ((setq vals (run-hook-with-args-until-success
13796 'org-property-allowed-value-functions property)))
13798 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13799 (when (and vals (string-match "\\S-" vals))
13800 (setq vals (car (read-from-string (concat "(" vals ")"))))
13801 (setq vals (mapcar (lambda (x)
13802 (cond ((stringp x) x)
13803 ((numberp x) (number-to-string x))
13804 ((symbolp x) (symbol-name x))
13807 (when (member ":ETC" vals)
13808 (setq vals (remove ":ETC" vals))
13809 (org-add-props (car vals) '(org-unrestricted t)))
13810 (if table (mapcar 'list vals) vals)))
13812 (defun org-property-previous-allowed-value (&optional previous)
13813 "Switch to the next allowed value for this property."
13815 (org-property-next-allowed-value t))
13817 (defun org-property-next-allowed-value (&optional previous)
13818 "Switch to the next allowed value for this property."
13820 (unless (org-at-property-p)
13821 (error "Not at a property"))
13822 (let* ((key (match-string 2))
13823 (value (match-string 3))
13824 (allowed (or (org-property-get-allowed-values (point) key)
13825 (and (member value '("[ ]" "[-]" "[X]"))
13829 (error "Allowed values for this property have not been defined"))
13830 (if previous (setq allowed (reverse allowed)))
13831 (if (member value allowed)
13832 (setq nval (car (cdr (member value allowed)))))
13833 (setq nval (or nval (car allowed)))
13834 (if (equal nval value)
13835 (error "Only one allowed value for this property"))
13836 (org-at-property-p)
13837 (replace-match (concat " :" key ": " nval) t t)
13838 (org-indent-line-function)
13839 (beginning-of-line 1)
13840 (skip-chars-forward " \t")
13841 (run-hook-with-args 'org-property-changed-functions key nval)))
13843 (defun org-find-olp (path &optional this-buffer)
13844 "Return a marker pointing to the entry at outline path OLP.
13845 If anything goes wrong, throw an error.
13846 You can wrap this call to cathc the error like this:
13848 (condition-case msg
13849 (org-mobile-locate-entry (match-string 4))
13850 (error (nth 1 msg)))
13852 The return value will then be either a string with the error message,
13853 or a marker if everyhing is OK.
13855 If THIS-BUFFER is set, the putline path does not contain a file,
13857 (let* ((file (if this-buffer buffer-file-name (pop path)))
13858 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
13862 limit re end found pos heading cnt)
13863 (unless buffer (error "File not found :%s" file))
13864 (with-current-buffer buffer
13868 (setq limit (point-max))
13869 (goto-char (point-min))
13870 (while (setq heading (pop path))
13871 (setq re (format org-complex-heading-regexp-format
13872 (regexp-quote heading)))
13873 (setq cnt 0 pos (point))
13874 (while (re-search-forward re end t)
13875 (setq level (- (match-end 1) (match-beginning 1)))
13876 (if (and (>= level lmin) (<= level lmax))
13877 (setq found (match-beginning 0) cnt (1+ cnt))))
13878 (when (= cnt 0) (error "Heading not found on level %d: %s"
13880 (when (> cnt 1) (error "Heading not unique on level %d: %s"
13883 (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0)))
13884 (setq end (save-excursion (org-end-of-subtree t t))))
13885 (when (org-on-heading-p)
13886 (move-marker (make-marker) (point))))))))
13888 (defun org-find-entry-with-id (ident)
13889 "Locate the entry that contains the ID property with exact value IDENT.
13890 IDENT can be a string, a symbol or a number, this function will search for
13891 the string representation of it.
13892 Return the position where this entry starts, or nil if there is no such entry."
13893 (interactive "sID: ")
13895 ((stringp ident) ident)
13896 ((symbol-name ident) (symbol-name ident))
13897 ((numberp ident) (number-to-string ident))
13898 (t (error "IDENT %s must be a string, symbol or number" ident))))
13899 (case-fold-search nil))
13903 (goto-char (point-min))
13904 (when (re-search-forward
13905 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13907 (org-back-to-heading t)
13912 (defvar org-last-changed-timestamp nil)
13913 (defvar org-last-inserted-timestamp nil
13914 "The last time stamp inserted with `org-insert-time-stamp'.")
13915 (defvar org-time-was-given) ; dynamically scoped parameter
13916 (defvar org-end-time-was-given) ; dynamically scoped parameter
13917 (defvar org-ts-what) ; dynamically scoped parameter
13919 (defun org-time-stamp (arg &optional inactive)
13920 "Prompt for a date/time and insert a time stamp.
13921 If the user specifies a time like HH:MM, or if this command is called
13922 with a prefix argument, the time stamp will contain date and time.
13923 Otherwise, only the date will be included. All parts of a date not
13924 specified by the user will be filled in from the current date/time.
13925 So if you press just return without typing anything, the time stamp
13926 will represent the current date/time. If there is already a timestamp
13927 at the cursor, it will be modified."
13931 ;; Default time is either today, or, when entering a range,
13932 ;; the range start.
13933 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13935 (re-search-backward
13936 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13937 (- (point) 20) t)))
13938 (apply 'encode-time (org-parse-time-string (match-string 1)))
13940 (default-input (and ts (org-get-compact-tod ts)))
13941 org-time-was-given org-end-time-was-given time)
13943 ((and (org-at-timestamp-p t)
13944 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13945 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13947 (setq time (let ((this-command this-command))
13948 (org-read-date arg 'totime nil nil
13949 default-time default-input)))
13950 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13951 ((org-at-timestamp-p t)
13952 (setq time (let ((this-command this-command))
13953 (org-read-date arg 'totime nil nil default-time default-input)))
13954 (when (org-at-timestamp-p t) ; just to get the match data
13955 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13957 (setq org-last-changed-timestamp
13958 (org-insert-time-stamp
13959 time (or org-time-was-given arg)
13960 inactive nil nil (list org-end-time-was-given))))
13961 (message "Timestamp updated"))
13963 (setq time (let ((this-command this-command))
13964 (org-read-date arg 'totime nil nil default-time default-input)))
13965 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13966 nil nil (list org-end-time-was-given))))))
13968 ;; FIXME: can we use this for something else, like computing time differences?
13969 (defun org-get-compact-tod (s)
13970 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13971 (let* ((t1 (match-string 1 s))
13972 (h1 (string-to-number (match-string 2 s)))
13973 (m1 (string-to-number (match-string 3 s)))
13974 (t2 (and (match-end 4) (match-string 5 s)))
13975 (h2 (and t2 (string-to-number (match-string 6 s))))
13976 (m2 (and t2 (string-to-number (match-string 7 s))))
13980 (setq dh (- h2 h1) dm (- m2 m1))
13981 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13982 (concat t1 "+" (number-to-string dh)
13983 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13985 (defun org-time-stamp-inactive (&optional arg)
13986 "Insert an inactive time stamp.
13987 An inactive time stamp is enclosed in square brackets instead of angle
13988 brackets. It is inactive in the sense that it does not trigger agenda entries,
13989 does not link to the calendar and cannot be changed with the S-cursor keys.
13990 So these are more for recording a certain time/date."
13992 (org-time-stamp arg 'inactive))
13994 (defvar org-date-ovl (make-overlay 1 1))
13995 (overlay-put org-date-ovl 'face 'org-warning)
13996 (org-detach-overlay org-date-ovl)
13998 (defvar org-ans1) ; dynamically scoped parameter
13999 (defvar org-ans2) ; dynamically scoped parameter
14001 (defvar org-plain-time-of-day-regexp) ; defined below
14003 (defvar org-overriding-default-time nil) ; dynamically scoped
14004 (defvar org-read-date-overlay nil)
14005 (defvar org-dcst nil) ; dynamically scoped
14006 (defvar org-read-date-history nil)
14007 (defvar org-read-date-final-answer nil)
14009 (defun org-read-date (&optional with-time to-time from-string prompt
14010 default-time default-input)
14011 "Read a date, possibly a time, and make things smooth for the user.
14012 The prompt will suggest to enter an ISO date, but you can also enter anything
14013 which will at least partially be understood by `parse-time-string'.
14014 Unrecognized parts of the date will default to the current day, month, year,
14015 hour and minute. If this command is called to replace a timestamp at point,
14016 of to enter the second timestamp of a range, the default time is taken
14017 from the existing stamp. Furthermore, the command prefers the future,
14018 so if you are giving a date where the year is not given, and the day-month
14019 combination is already past in the current year, it will assume you
14020 mean next year. For details, see the manual. A few examples:
14022 3-2-5 --> 2003-02-05
14023 feb 15 --> currentyear-02-15
14024 2/15 --> currentyear-02-15
14025 sep 12 9 --> 2009-09-12
14026 12:45 --> today 12:45
14027 22 sept 0:34 --> currentyear-09-22 0:34
14028 12 --> currentyear-currentmonth-12
14029 Fri --> nearest Friday (today or later)
14032 Furthermore you can specify a relative date by giving, as the *first* thing
14033 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
14034 change in days weeks, months, years.
14035 With a single plus or minus, the date is relative to today. With a double
14036 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
14037 +4d --> four days from today
14038 +4 --> same as above
14039 +2w --> two weeks from today
14040 ++5 --> five days from default date
14042 The function understands only English month and weekday abbreviations,
14043 but this can be configured with the variables `parse-time-months' and
14044 `parse-time-weekdays'.
14046 While prompting, a calendar is popped up - you can also select the
14047 date with the mouse (button 1). The calendar shows a period of three
14048 months. To scroll it to other months, use the keys `>' and `<'.
14049 If you don't like the calendar, turn it off with
14050 \(setq org-read-date-popup-calendar nil)
14052 With optional argument TO-TIME, the date will immediately be converted
14053 to an internal time.
14054 With an optional argument WITH-TIME, the prompt will suggest to also
14055 insert a time. Note that when WITH-TIME is not set, you can still
14056 enter a time, and this function will inform the calling routine about
14057 this change. The calling routine may then choose to change the format
14058 used to insert the time stamp into the buffer to include the time.
14059 With optional argument FROM-STRING, read from this string instead from
14060 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
14061 the time/date that is used for everything that is not specified by the
14063 (require 'parse-time)
14064 (let* ((org-time-stamp-rounding-minutes
14065 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
14066 (org-dcst org-display-custom-times)
14067 (ct (org-current-time))
14068 (def (or org-overriding-default-time default-time ct))
14069 (defdecode (decode-time def))
14071 (when (< (nth 2 defdecode) org-extend-today-until)
14072 (setcar (nthcdr 2 defdecode) -1)
14073 (setcar (nthcdr 1 defdecode) 59)
14074 (setq def (apply 'encode-time defdecode)
14075 defdecode (decode-time def)))))
14076 (calendar-frame-setup nil)
14077 (calendar-setup nil)
14078 (calendar-move-hook nil)
14079 (calendar-view-diary-initially-flag nil)
14080 (calendar-view-holidays-initially-flag nil)
14081 (timestr (format-time-string
14082 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
14083 (prompt (concat (if prompt (concat prompt " ") "")
14084 (format "Date+time [%s]: " timestr)))
14085 ans (org-ans0 "") org-ans1 org-ans2 final)
14088 (from-string (setq ans from-string))
14089 (org-read-date-popup-calendar
14091 (save-window-excursion
14093 (calendar-forward-day (- (time-to-days def)
14094 (calendar-absolute-from-gregorian
14095 (calendar-current-date))))
14096 (org-eval-in-calendar nil t)
14097 (let* ((old-map (current-local-map))
14098 (map (copy-keymap calendar-mode-map))
14099 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
14100 (org-defkey map (kbd "RET") 'org-calendar-select)
14101 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
14102 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
14103 (org-defkey minibuffer-local-map [(meta shift left)]
14104 (lambda () (interactive)
14105 (org-eval-in-calendar '(calendar-backward-month 1))))
14106 (org-defkey minibuffer-local-map [(meta shift right)]
14107 (lambda () (interactive)
14108 (org-eval-in-calendar '(calendar-forward-month 1))))
14109 (org-defkey minibuffer-local-map [(meta shift up)]
14110 (lambda () (interactive)
14111 (org-eval-in-calendar '(calendar-backward-year 1))))
14112 (org-defkey minibuffer-local-map [(meta shift down)]
14113 (lambda () (interactive)
14114 (org-eval-in-calendar '(calendar-forward-year 1))))
14115 (org-defkey minibuffer-local-map [?\e (shift left)]
14116 (lambda () (interactive)
14117 (org-eval-in-calendar '(calendar-backward-month 1))))
14118 (org-defkey minibuffer-local-map [?\e (shift right)]
14119 (lambda () (interactive)
14120 (org-eval-in-calendar '(calendar-forward-month 1))))
14121 (org-defkey minibuffer-local-map [?\e (shift up)]
14122 (lambda () (interactive)
14123 (org-eval-in-calendar '(calendar-backward-year 1))))
14124 (org-defkey minibuffer-local-map [?\e (shift down)]
14125 (lambda () (interactive)
14126 (org-eval-in-calendar '(calendar-forward-year 1))))
14127 (org-defkey minibuffer-local-map [(shift up)]
14128 (lambda () (interactive)
14129 (org-eval-in-calendar '(calendar-backward-week 1))))
14130 (org-defkey minibuffer-local-map [(shift down)]
14131 (lambda () (interactive)
14132 (org-eval-in-calendar '(calendar-forward-week 1))))
14133 (org-defkey minibuffer-local-map [(shift left)]
14134 (lambda () (interactive)
14135 (org-eval-in-calendar '(calendar-backward-day 1))))
14136 (org-defkey minibuffer-local-map [(shift right)]
14137 (lambda () (interactive)
14138 (org-eval-in-calendar '(calendar-forward-day 1))))
14139 (org-defkey minibuffer-local-map ">"
14140 (lambda () (interactive)
14141 (org-eval-in-calendar '(scroll-calendar-left 1))))
14142 (org-defkey minibuffer-local-map "<"
14143 (lambda () (interactive)
14144 (org-eval-in-calendar '(scroll-calendar-right 1))))
14145 (org-defkey minibuffer-local-map "\C-v"
14146 (lambda () (interactive)
14147 (org-eval-in-calendar
14148 '(calendar-scroll-left-three-months 1))))
14149 (org-defkey minibuffer-local-map "\M-v"
14150 (lambda () (interactive)
14151 (org-eval-in-calendar
14152 '(calendar-scroll-right-three-months 1))))
14153 (run-hooks 'org-read-date-minibuffer-setup-hook)
14156 (use-local-map map)
14157 (add-hook 'post-command-hook 'org-read-date-display)
14158 (setq org-ans0 (read-string prompt default-input
14159 'org-read-date-history nil))
14160 ;; org-ans0: from prompt
14161 ;; org-ans1: from mouse click
14162 ;; org-ans2: from calendar motion
14163 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
14164 (remove-hook 'post-command-hook 'org-read-date-display)
14165 (use-local-map old-map)
14166 (when org-read-date-overlay
14167 (delete-overlay org-read-date-overlay)
14168 (setq org-read-date-overlay nil)))))))
14170 (t ; Naked prompt only
14172 (setq ans (read-string prompt default-input
14173 'org-read-date-history timestr))
14174 (when org-read-date-overlay
14175 (delete-overlay org-read-date-overlay)
14176 (setq org-read-date-overlay nil)))))
14178 (setq final (org-read-date-analyze ans def defdecode))
14179 (setq org-read-date-final-answer ans)
14182 (apply 'encode-time final)
14183 (if (and (boundp 'org-time-was-given) org-time-was-given)
14184 (format "%04d-%02d-%02d %02d:%02d"
14185 (nth 5 final) (nth 4 final) (nth 3 final)
14186 (nth 2 final) (nth 1 final))
14187 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
14192 (defvar org-read-date-analyze-futurep nil)
14193 (defun org-read-date-display ()
14194 "Display the current date prompt interpretation in the minibuffer."
14195 (when org-read-date-display-live
14196 (when org-read-date-overlay
14197 (delete-overlay org-read-date-overlay))
14200 (while (not (equal (buffer-substring
14201 (max (point-min) (- (point) 4)) (point))
14205 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
14206 " " (or org-ans1 org-ans2)))
14207 (org-end-time-was-given nil)
14208 (f (org-read-date-analyze ans def defdecode))
14210 org-time-stamp-custom-formats
14211 org-time-stamp-formats))
14212 (fmt (if (or with-time
14213 (and (boundp 'org-time-was-given) org-time-was-given))
14216 (txt (concat "=> " (format-time-string fmt (apply 'encode-time f)))))
14217 (when (and org-end-time-was-given
14218 (string-match org-plain-time-of-day-regexp txt))
14219 (setq txt (concat (substring txt 0 (match-end 0)) "-"
14220 org-end-time-was-given
14221 (substring txt (match-end 0)))))
14222 (when org-read-date-analyze-futurep
14223 (setq txt (concat txt " (=>F)")))
14224 (setq org-read-date-overlay
14225 (make-overlay (1- (point-at-eol)) (point-at-eol)))
14226 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
14228 (defun org-read-date-analyze (ans def defdecode)
14229 "Analyse the combined answer of the date prompt."
14230 ;; FIXME: cleanup and comment
14231 (let ((nowdecode (decode-time (current-time)))
14232 delta deltan deltaw deltadef year month day
14233 hour minute second wday pm h2 m2 tl wday1
14234 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
14235 (setq org-read-date-analyze-futurep nil)
14236 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
14239 (when (setq delta (org-read-date-get-relative ans (current-time) def))
14240 (setq ans (replace-match "" t t ans)
14242 deltaw (nth 1 delta)
14243 deltadef (nth 2 delta)))
14245 ;; Check if there is an iso week date in there
14246 ;; If yes, store the info and postpone interpreting it until the rest
14247 ;; of the parsing is done
14248 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
14249 (setq iso-year (if (match-end 1)
14250 (org-small-year-to-year
14251 (string-to-number (match-string 1 ans))))
14252 iso-weekday (if (match-end 3)
14253 (string-to-number (match-string 3 ans)))
14254 iso-week (string-to-number (match-string 2 ans)))
14255 (setq ans (replace-match "" t t ans)))
14257 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
14258 (when (string-match
14259 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
14260 (setq year (if (match-end 2)
14261 (string-to-number (match-string 2 ans))
14262 (progn (setq kill-year t)
14263 (string-to-number (format-time-string "%Y"))))
14264 month (string-to-number (match-string 3 ans))
14265 day (string-to-number (match-string 4 ans)))
14266 (if (< year 100) (setq year (+ 2000 year)))
14267 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14269 ;; Help matching american dates, like 5/30 or 5/30/7
14270 (when (string-match
14271 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
14272 (setq year (if (match-end 4)
14273 (string-to-number (match-string 4 ans))
14274 (progn (setq kill-year t)
14275 (string-to-number (format-time-string "%Y"))))
14276 month (string-to-number (match-string 1 ans))
14277 day (string-to-number (match-string 2 ans)))
14278 (if (< year 100) (setq year (+ 2000 year)))
14279 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14281 ;; Help matching am/pm times, because `parse-time-string' does not do that.
14282 ;; If there is a time with am/pm, and *no* time without it, we convert
14283 ;; so that matching will be successful.
14284 (loop for i from 1 to 2 do ; twice, for end time as well
14285 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
14286 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
14287 (setq hour (string-to-number (match-string 1 ans))
14288 minute (if (match-end 3)
14289 (string-to-number (match-string 3 ans))
14292 (string-to-char (downcase (match-string 4 ans)))))
14293 (if (and (= hour 12) (not pm))
14295 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
14296 (setq ans (replace-match (format "%02d:%02d" hour minute)
14299 ;; Check if a time range is given as a duration
14300 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
14301 (setq hour (string-to-number (match-string 1 ans))
14302 h2 (+ hour (string-to-number (match-string 3 ans)))
14303 minute (string-to-number (match-string 2 ans))
14304 m2 (+ minute (if (match-end 5) (string-to-number
14305 (match-string 5 ans))0)))
14306 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
14307 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
14310 ;; Check if there is a time range
14311 (when (boundp 'org-end-time-was-given)
14312 (setq org-time-was-given nil)
14313 (when (and (string-match org-plain-time-of-day-regexp ans)
14315 (setq org-end-time-was-given (match-string 8 ans))
14316 (setq ans (concat (substring ans 0 (match-beginning 7))
14317 (substring ans (match-end 7))))))
14319 (setq tl (parse-time-string ans)
14320 day (or (nth 3 tl) (nth 3 defdecode))
14321 month (or (nth 4 tl)
14322 (if (and org-read-date-prefer-future
14323 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
14324 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
14325 (nth 4 defdecode)))
14326 year (or (and (not kill-year) (nth 5 tl))
14327 (if (and org-read-date-prefer-future
14328 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
14329 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
14330 (nth 5 defdecode)))
14331 hour (or (nth 2 tl) (nth 2 defdecode))
14332 minute (or (nth 1 tl) (nth 1 defdecode))
14333 second (or (nth 0 tl) 0)
14336 (when (and (eq org-read-date-prefer-future 'time)
14337 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
14338 (equal day (nth 3 nowdecode))
14339 (equal month (nth 4 nowdecode))
14340 (equal year (nth 5 nowdecode))
14342 (or (< (nth 2 tl) (nth 2 nowdecode))
14343 (and (= (nth 2 tl) (nth 2 nowdecode))
14345 (< (nth 1 tl) (nth 1 nowdecode)))))
14349 ;; Special date definitions below
14352 ;; There was an iso week
14355 (setq year (or iso-year year)
14356 day (or iso-weekday wday 1)
14357 wday nil ; to make sure that the trigger below does not match
14358 iso-date (calendar-gregorian-from-absolute
14359 (calendar-absolute-from-iso
14360 (list iso-week day year))))
14361 ; FIXME: Should we also push ISO weeks into the future?
14362 ; (when (and org-read-date-prefer-future
14364 ; (< (calendar-absolute-from-gregorian iso-date)
14365 ; (time-to-days (current-time))))
14366 ; (setq year (1+ year)
14367 ; iso-date (calendar-gregorian-from-absolute
14368 ; (calendar-absolute-from-iso
14369 ; (list iso-week day year)))))
14370 (setq month (car iso-date)
14371 year (nth 2 iso-date)
14372 day (nth 1 iso-date)))
14376 (let ((now (decode-time (current-time))))
14377 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
14378 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
14379 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
14380 ((equal deltaw "m") (setq month (+ month deltan)))
14381 ((equal deltaw "y") (setq year (+ year deltan)))))
14382 ((and wday (not (nth 3 tl)))
14384 ;; Weekday was given, but no day, so pick that day in the week
14385 ;; on or after the derived date.
14386 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
14387 (unless (equal wday wday1)
14388 (setq day (+ day (% (- wday wday1 -7) 7))))))
14389 (if (and (boundp 'org-time-was-given)
14391 (setq org-time-was-given t))
14392 (if (< year 100) (setq year (+ 2000 year)))
14393 (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
14394 (setq org-read-date-analyze-futurep futurep)
14395 (list second minute hour day month year)))
14397 (defvar parse-time-weekdays)
14399 (defun org-read-date-get-relative (s today default)
14400 "Check string S for special relative date string.
14401 TODAY and DEFAULT are internal times, for today and for a default.
14402 Return shift list (N what def-flag)
14403 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
14404 N is the number of WHATs to shift.
14405 DEF-FLAG is t when a double ++ or -- indicates shift relative to
14406 the DEFAULT date rather than TODAY."
14410 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
14412 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
14413 "\\([ \t]\\|$\\)") s)
14414 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
14415 (let* ((dir (if (> (match-end 1) (match-beginning 1))
14416 (string-to-char (substring (match-string 1 s) -1))
14418 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
14419 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
14420 (what (if (match-end 3) (match-string 3 s) "d"))
14421 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
14422 (date (if rel default today))
14423 (wday (nth 6 (decode-time date)))
14427 (setq delta (mod (+ 7 (- wday1 wday)) 7))
14428 (if (= dir ?-) (setq delta (- delta 7)))
14429 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
14430 (list delta "d" rel))
14431 (list (* n (if (= dir ?-) -1 1)) what rel)))))
14433 (defun org-order-calendar-date-args (arg1 arg2 arg3)
14434 "Turn a user-specified date into the internal representation.
14435 The internal representation needed by the calendar is (month day year).
14436 This is a wrapper to handle the brain-dead convention in calendar that
14437 user function argument order change dependent on argument order."
14438 (if (boundp 'calendar-date-style)
14440 ((eq calendar-date-style 'american)
14441 (list arg1 arg2 arg3))
14442 ((eq calendar-date-style 'european)
14443 (list arg2 arg1 arg3))
14444 ((eq calendar-date-style 'iso)
14445 (list arg2 arg3 arg1)))
14446 (if (org-bound-and-true-p european-calendar-style)
14447 (list arg2 arg1 arg3)
14448 (list arg1 arg2 arg3))))
14450 (defun org-eval-in-calendar (form &optional keepdate)
14451 "Eval FORM in the calendar window and return to current window.
14452 Also, store the cursor date in variable org-ans2."
14453 (let ((sf (selected-frame))
14454 (sw (selected-window)))
14455 (select-window (get-buffer-window "*Calendar*" t))
14457 (when (and (not keepdate) (calendar-cursor-to-date))
14458 (let* ((date (calendar-cursor-to-date))
14459 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14460 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
14461 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
14463 (org-select-frame-set-input-focus sf)))
14465 (defun org-calendar-select ()
14466 "Return to `org-read-date' with the date currently selected.
14467 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14469 (when (calendar-cursor-to-date)
14470 (let* ((date (calendar-cursor-to-date))
14471 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14472 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14473 (if (active-minibuffer-window) (exit-minibuffer))))
14475 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
14476 "Insert a date stamp for the date given by the internal TIME.
14477 WITH-HM means use the stamp format that includes the time of the day.
14478 INACTIVE means use square brackets instead of angular ones, so that the
14479 stamp will not contribute to the agenda.
14480 PRE and POST are optional strings to be inserted before and after the
14482 The command returns the inserted time stamp."
14483 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
14485 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
14486 (insert-before-markers (or pre ""))
14487 (insert-before-markers (setq stamp (format-time-string fmt time)))
14488 (when (listp extra)
14489 (setq extra (car extra))
14490 (if (and (stringp extra)
14491 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
14492 (setq extra (format "-%02d:%02d"
14493 (string-to-number (match-string 1 extra))
14494 (string-to-number (match-string 2 extra))))
14498 (insert-before-markers extra)
14500 (insert-before-markers (or post ""))
14501 (setq org-last-inserted-timestamp stamp)))
14503 (defun org-toggle-time-stamp-overlays ()
14504 "Toggle the use of custom time stamp formats."
14506 (setq org-display-custom-times (not org-display-custom-times))
14507 (unless org-display-custom-times
14508 (let ((p (point-min)) (bmp (buffer-modified-p)))
14509 (while (setq p (next-single-property-change p 'display))
14510 (if (and (get-text-property p 'display)
14511 (eq (get-text-property p 'face) 'org-date))
14512 (remove-text-properties
14513 p (setq p (next-single-property-change p 'display))
14515 (set-buffer-modified-p bmp)))
14516 (if (featurep 'xemacs)
14517 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
14518 (org-restart-font-lock)
14519 (setq org-table-may-need-update t)
14520 (if org-display-custom-times
14521 (message "Time stamps are overlayed with custom format")
14522 (message "Time stamp overlays removed")))
14524 (defun org-display-custom-time (beg end)
14525 "Overlay modified time stamp format over timestamp between BEG and END."
14526 (let* ((ts (buffer-substring beg end))
14527 t1 w1 with-hm tf time str w2 (off 0))
14529 (setq t1 (org-parse-time-string ts t))
14530 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
14531 (setq off (- (match-end 0) (match-beginning 0)))))
14532 (setq end (- end off))
14533 (setq w1 (- end beg)
14534 with-hm (and (nth 1 t1) (nth 2 t1))
14535 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
14536 time (org-fix-decoded-time t1)
14538 (format-time-string
14539 (substring tf 1 -1) (apply 'encode-time time))
14540 nil 'mouse-face 'highlight)
14542 (if (not (= w2 w1))
14543 (add-text-properties (1+ beg) (+ 2 beg)
14544 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
14545 (if (featurep 'xemacs)
14547 (put-text-property beg end 'invisible t)
14548 (put-text-property beg end 'end-glyph (make-glyph str)))
14549 (put-text-property beg end 'display str))))
14551 (defun org-translate-time (string)
14552 "Translate all timestamps in STRING to custom format.
14553 But do this only if the variable `org-display-custom-times' is set."
14554 (when org-display-custom-times
14557 (re org-ts-regexp-both)
14558 t1 with-hm inactive tf time str beg end)
14559 (while (setq start (string-match re string start))
14560 (setq beg (match-beginning 0)
14562 t1 (save-match-data
14563 (org-parse-time-string (substring string beg end) t))
14564 with-hm (and (nth 1 t1) (nth 2 t1))
14565 inactive (equal (substring string beg (1+ beg)) "[")
14566 tf (funcall (if with-hm 'cdr 'car)
14567 org-time-stamp-custom-formats)
14568 time (org-fix-decoded-time t1)
14569 str (format-time-string
14571 (if inactive "[" "<") (substring tf 1 -1)
14572 (if inactive "]" ">"))
14573 (apply 'encode-time time))
14574 string (replace-match str t t string)
14575 start (+ start (length str)))))))
14578 (defun org-fix-decoded-time (time)
14579 "Set 0 instead of nil for the first 6 elements of time.
14580 Don't touch the rest."
14582 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
14584 (defun org-days-to-time (timestamp-string)
14585 "Difference between TIMESTAMP-STRING and now in days."
14586 (- (time-to-days (org-time-string-to-time timestamp-string))
14587 (time-to-days (current-time))))
14589 (defun org-deadline-close (timestamp-string &optional ndays)
14590 "Is the time in TIMESTAMP-STRING close to the current date?"
14591 (setq ndays (or ndays (org-get-wdays timestamp-string)))
14592 (and (< (org-days-to-time timestamp-string) ndays)
14593 (not (org-entry-is-done-p))))
14595 (defun org-get-wdays (ts)
14596 "Get the deadline lead time appropriate for timestring TS."
14598 ((<= org-deadline-warning-days 0)
14599 ;; 0 or negative, enforce this value no matter what
14600 (- org-deadline-warning-days))
14601 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
14602 ;; lead time is specified.
14603 (floor (* (string-to-number (match-string 1 ts))
14604 (cdr (assoc (match-string 2 ts)
14605 '(("d" . 1) ("w" . 7)
14606 ("m" . 30.4) ("y" . 365.25)))))))
14607 ;; go for the default.
14608 (t org-deadline-warning-days)))
14610 (defun org-calendar-select-mouse (ev)
14611 "Return to `org-read-date' with the date currently selected.
14612 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14614 (mouse-set-point ev)
14615 (when (calendar-cursor-to-date)
14616 (let* ((date (calendar-cursor-to-date))
14617 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14618 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14619 (if (active-minibuffer-window) (exit-minibuffer))))
14621 (defun org-check-deadlines (ndays)
14622 "Check if there are any deadlines due or past due.
14623 A deadline is considered due if it happens within `org-deadline-warning-days'
14624 days from today's date. If the deadline appears in an entry marked DONE,
14625 it is not shown. The prefix arg NDAYS can be used to test that many
14626 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14628 (let* ((org-warn-days
14630 ((equal ndays '(4)) 100000)
14631 (ndays (prefix-numeric-value ndays))
14632 (t (abs org-deadline-warning-days))))
14633 (case-fold-search nil)
14634 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
14636 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
14638 (message "%d deadlines past-due or due within %d days"
14639 (org-occur regexp nil callback)
14642 (defun org-check-before-date (date)
14643 "Check if there are deadlines or scheduled entries before DATE."
14644 (interactive (list (org-read-date)))
14645 (let ((case-fold-search nil)
14646 (regexp (concat "\\<\\(" org-deadline-string
14647 "\\|" org-scheduled-string
14648 "\\) *<\\([^>]+\\)>"))
14650 (lambda () (time-less-p
14651 (org-time-string-to-time (match-string 2))
14652 (org-time-string-to-time date)))))
14653 (message "%d entries before %s"
14654 (org-occur regexp nil callback) date)))
14656 (defun org-check-after-date (date)
14657 "Check if there are deadlines or scheduled entries after DATE."
14658 (interactive (list (org-read-date)))
14659 (let ((case-fold-search nil)
14660 (regexp (concat "\\<\\(" org-deadline-string
14661 "\\|" org-scheduled-string
14662 "\\) *<\\([^>]+\\)>"))
14666 (org-time-string-to-time (match-string 2))
14667 (org-time-string-to-time date))))))
14668 (message "%d entries after %s"
14669 (org-occur regexp nil callback) date)))
14671 (defun org-evaluate-time-range (&optional to-buffer)
14672 "Evaluate a time range by computing the difference between start and end.
14673 Normally the result is just printed in the echo area, but with prefix arg
14674 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14675 If the time range is actually in a table, the result is inserted into the
14677 For time difference computation, a year is assumed to be exactly 365
14678 days in order to avoid rounding problems."
14681 (org-clock-update-time-maybe)
14683 (unless (org-at-date-range-p t)
14684 (goto-char (point-at-bol))
14685 (re-search-forward org-tr-regexp-both (point-at-eol) t))
14686 (if (not (org-at-date-range-p t))
14687 (error "Not at a time-stamp range, and none found in current line")))
14688 (let* ((ts1 (match-string 1))
14689 (ts2 (match-string 2))
14690 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
14691 (match-end (match-end 0))
14692 (time1 (org-time-string-to-time ts1))
14693 (time2 (org-time-string-to-time ts2))
14694 (t1 (org-float-time time1))
14695 (t2 (org-float-time time2))
14696 (diff (abs (- t2 t1)))
14697 (negative (< (- t2 t1) 0))
14698 ;; (ys (floor (* 365 24 60 60)))
14701 (fy "%dy %dd %02d:%02d")
14703 (fd "%dd %02d:%02d")
14708 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14710 d (floor (/ diff ds)) diff (mod diff ds)
14711 h (floor (/ diff hs)) diff (mod diff hs)
14712 m (floor (/ diff 60)))
14713 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14715 d (floor (+ (/ diff ds) 0.5))
14717 (if (not to-buffer)
14718 (message "%s" (org-make-tdiff-string y d h m))
14719 (if (org-at-table-p)
14721 (goto-char match-end)
14723 (and (looking-at " *|") (goto-char (match-end 0))))
14724 (goto-char match-end))
14726 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14727 (replace-match ""))
14728 (if negative (insert " -"))
14729 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
14730 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
14731 (insert " " (format fh h m))))
14732 (if align (org-table-align))
14733 (message "Time difference inserted")))))
14735 (defun org-make-tdiff-string (y d h m)
14738 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
14740 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
14742 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
14744 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
14746 (apply 'format fmt (nreverse l))))
14748 (defun org-time-string-to-time (s)
14749 (apply 'encode-time (org-parse-time-string s)))
14750 (defun org-time-string-to-seconds (s)
14751 (org-float-time (org-time-string-to-time s)))
14753 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
14754 "Convert a time stamp to an absolute day number.
14755 If there is a specifyer for a cyclic time stamp, get the closest date to
14757 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14758 the variable date is bound by the calendar when this is called."
14760 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
14761 (if (org-diary-sexp-entry (match-string 1 s) "" date)
14764 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
14765 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
14766 (time-to-days (current-time))) (match-string 0 s)
14768 (t (time-to-days (apply 'encode-time (org-parse-time-string s))))))
14770 (defun org-days-to-iso-week (days)
14771 "Return the iso week number."
14773 (car (calendar-iso-from-absolute days)))
14775 (defun org-small-year-to-year (year)
14776 "Convert 2-digit years into 4-digit years.
14777 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14778 The year 2000 cannot be abbreviated. Any year larger than 99
14779 is returned unchanged."
14781 (setq year (+ 2000 year))
14783 (setq year (+ 1900 year))))
14786 (defun org-time-from-absolute (d)
14787 "Return the time corresponding to date D.
14788 D may be an absolute day number, or a calendar-type list (month day year)."
14789 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
14790 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
14792 (defun org-calendar-holiday ()
14793 "List of holidays, for Diary display in Org-mode."
14794 (require 'holidays)
14796 (if (fboundp 'calendar-check-holidays)
14797 'calendar-check-holidays 'check-calendar-holidays) date)))
14798 (if hl (mapconcat 'identity hl "; "))))
14800 (defun org-diary-sexp-entry (sexp entry date)
14801 "Process a SEXP diary ENTRY for DATE."
14802 (require 'diary-lib)
14803 (let ((result (if calendar-debug-sexp
14804 (let ((stack-trace-on-error t))
14805 (eval (car (read-from-string sexp))))
14806 (condition-case nil
14807 (eval (car (read-from-string sexp)))
14810 (message "Bad sexp at line %d in %s: %s"
14812 (buffer-file-name) sexp)
14814 (cond ((stringp result) result)
14815 ((and (consp result)
14816 (stringp (cdr result))) (cdr result))
14820 (defun org-diary-to-ical-string (frombuf)
14821 "Get iCalendar entries from diary entries in buffer FROMBUF.
14822 This uses the icalendar.el library."
14823 (let* ((tmpdir (if (featurep 'xemacs)
14825 temporary-file-directory))
14826 (tmpfile (make-temp-name
14827 (expand-file-name "orgics" tmpdir)))
14829 (with-current-buffer frombuf
14830 (icalendar-export-region (point-min) (point-max) tmpfile)
14831 (setq buf (find-buffer-visiting tmpfile))
14833 (goto-char (point-min))
14834 (if (re-search-forward "^BEGIN:VEVENT" nil t)
14835 (setq b (match-beginning 0)))
14836 (goto-char (point-max))
14837 (if (re-search-backward "^END:VEVENT" nil t)
14838 (setq e (match-end 0)))
14839 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
14841 (delete-file tmpfile)
14844 (defun org-closest-date (start current change prefer show-all)
14845 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14846 When PREFER is `past' return a date that is either CURRENT or past.
14847 When PREFER is `future', return a date that is either CURRENT or future.
14848 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14849 ;; Make the proper lists from the dates
14851 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
14852 dn dw sday cday n1 n2 n0
14853 d m y y1 y2 date1 date2 nmonths nm ny m2)
14855 (setq start (org-date-to-gregorian start)
14856 current (org-date-to-gregorian
14859 (time-to-days (current-time))))
14860 sday (calendar-absolute-from-gregorian start)
14861 cday (calendar-absolute-from-gregorian current))
14863 (if (<= cday sday) (throw 'exit sday))
14865 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
14866 (setq dn (string-to-number (match-string 1 change))
14867 dw (cdr (assoc (match-string 2 change) a1)))
14868 (error "Invalid change specifyer: %s" change))
14869 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
14872 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
14875 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
14876 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
14877 (setq date1 (list m d y1)
14878 n1 (calendar-absolute-from-gregorian date1)
14879 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
14880 n2 (calendar-absolute-from-gregorian date2)))
14882 ;; approx number of month between the two dates
14883 (setq nmonths (floor (/ (- cday sday) 30.436875)))
14884 ;; How often does dn fit in there?
14885 (setq d (nth 1 start) m (car start) y (nth 2 start)
14886 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
14888 ny (floor (/ m 12))
14891 (while (> m 12) (setq m (- m 12) y (1+ y)))
14892 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
14893 (setq m2 (+ m dn) y2 y)
14894 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14895 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
14896 (while (<= n2 cday)
14897 (setq n1 n2 m m2 y y2)
14898 (setq m2 (+ m dn) y2 y)
14899 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14900 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
14901 ;; Make sure n1 is the earlier date
14902 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
14905 ((eq prefer 'past) (if (= cday n2) n2 n1))
14906 ((eq prefer 'future) (if (= cday n1) n1 n2))
14907 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
14909 ((eq prefer 'past) (if (= cday n2) n2 n1))
14910 ((eq prefer 'future) (if (= cday n1) n1 n2))
14911 (t (if (= cday n1) n1 n2)))))))
14913 (defun org-date-to-gregorian (date)
14914 "Turn any specification of DATE into a gregorian date for the calendar."
14915 (cond ((integerp date) (calendar-gregorian-from-absolute date))
14916 ((and (listp date) (= (length date) 3)) date)
14918 (setq date (org-parse-time-string date))
14919 (list (nth 4 date) (nth 3 date) (nth 5 date)))
14921 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
14923 (defun org-parse-time-string (s &optional nodefault)
14924 "Parse the standard Org-mode time string.
14925 This should be a lot faster than the normal `parse-time-string'.
14926 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14927 hour and minute fields will be nil if not given."
14928 (if (string-match org-ts-regexp0 s)
14930 (if (or (match-beginning 8) (not nodefault))
14931 (string-to-number (or (match-string 8 s) "0")))
14932 (if (or (match-beginning 7) (not nodefault))
14933 (string-to-number (or (match-string 7 s) "0")))
14934 (string-to-number (match-string 4 s))
14935 (string-to-number (match-string 3 s))
14936 (string-to-number (match-string 2 s))
14938 (error "Not a standard Org-mode time string: %s" s)))
14940 (defun org-timestamp-up (&optional arg)
14941 "Increase the date item at the cursor by one.
14942 If the cursor is on the year, change the year. If it is on the month or
14943 the day, change that.
14944 With prefix ARG, change by that many units."
14946 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
14948 (defun org-timestamp-down (&optional arg)
14949 "Decrease the date item at the cursor by one.
14950 If the cursor is on the year, change the year. If it is on the month or
14951 the day, change that.
14952 With prefix ARG, change by that many units."
14954 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
14956 (defun org-timestamp-up-day (&optional arg)
14957 "Increase the date in the time stamp by one day.
14958 With prefix ARG, change that many days."
14960 (if (and (not (org-at-timestamp-p t))
14961 (org-on-heading-p))
14963 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
14965 (defun org-timestamp-down-day (&optional arg)
14966 "Decrease the date in the time stamp by one day.
14967 With prefix ARG, change that many days."
14969 (if (and (not (org-at-timestamp-p t))
14970 (org-on-heading-p))
14972 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
14974 (defun org-at-timestamp-p (&optional inactive-ok)
14975 "Determine if the cursor is in or at a timestamp."
14977 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
14979 (ans (or (looking-at tsr)
14981 (skip-chars-backward "^[<\n\r\t")
14982 (if (> (point) (point-min)) (backward-char 1))
14983 (and (looking-at tsr)
14984 (> (- (match-end 0) pos) -1))))))
14986 (boundp 'org-ts-what)
14989 ((= pos (match-beginning 0)) 'bracket)
14990 ((= pos (1- (match-end 0))) 'bracket)
14991 ((org-pos-in-match-range pos 2) 'year)
14992 ((org-pos-in-match-range pos 3) 'month)
14993 ((org-pos-in-match-range pos 7) 'hour)
14994 ((org-pos-in-match-range pos 8) 'minute)
14995 ((or (org-pos-in-match-range pos 4)
14996 (org-pos-in-match-range pos 5)) 'day)
14997 ((and (> pos (or (match-end 8) (match-end 5)))
14998 (< pos (match-end 0)))
14999 (- pos (or (match-end 8) (match-end 5))))
15003 (defun org-toggle-timestamp-type ()
15004 "Toggle the type (<active> or [inactive]) of a time stamp."
15006 (when (org-at-timestamp-p t)
15007 (let ((beg (match-beginning 0)) (end (match-end 0))
15008 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
15011 (while (re-search-forward "[][<>]" end t)
15012 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
15014 (message "Timestamp is now %sactive"
15015 (if (equal (char-after beg) ?<) "" "in")))))
15017 (defun org-timestamp-change (n &optional what updown)
15018 "Change the date in the time stamp at point.
15019 The date will be changed by N times WHAT. WHAT can be `day', `month',
15020 `year', `minute', `second'. If WHAT is not given, the cursor position
15021 in the timestamp determines what will be changed."
15022 (let ((pos (point))
15024 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
15028 (if (not (org-at-timestamp-p t))
15029 (error "Not at a timestamp"))
15030 (if (and (not what) (eq org-ts-what 'bracket))
15031 (org-toggle-timestamp-type)
15032 (if (and (not what) (not (eq org-ts-what 'day))
15033 org-display-custom-times
15034 (get-text-property (point) 'display)
15035 (not (get-text-property (1- (point)) 'display)))
15036 (setq org-ts-what 'day))
15037 (setq org-ts-what (or what org-ts-what)
15038 inactive (= (char-after (match-beginning 0)) ?\[)
15039 ts (match-string 0))
15042 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
15044 (setq extra (match-string 1 ts)))
15045 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
15047 (setq time0 (org-parse-time-string ts))
15049 (eq org-ts-what 'minute)
15050 (not current-prefix-arg))
15051 ;; This looks like s-up and s-down. Change by one rounding step.
15052 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
15053 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
15054 (setcar (cdr time0) (+ (nth 1 time0)
15055 (if (> n 0) (- rem) (- dm rem))))))
15057 (encode-time (or (car time0) 0)
15058 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
15059 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
15060 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
15061 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
15062 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
15064 (when (and (member org-ts-what '(hour minute))
15066 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
15067 (setq extra (org-modify-ts-extra
15069 (if (eq org-ts-what 'hour) 2 5)
15071 (when (integerp org-ts-what)
15072 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
15073 (if (eq what 'calendar)
15074 (let ((cal-date (org-get-date-from-calendar)))
15075 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
15076 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
15077 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
15078 (setcar time0 (or (car time0) 0))
15079 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
15080 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
15081 (setq time (apply 'encode-time time0))))
15082 (setq org-last-changed-timestamp
15083 (org-insert-time-stamp time with-hm inactive nil nil extra))
15084 (org-clock-update-time-maybe)
15086 ;; Try to recenter the calendar window, if any
15087 (if (and org-calendar-follow-timestamp-change
15088 (get-buffer-window "*Calendar*" t)
15089 (memq org-ts-what '(day month year)))
15090 (org-recenter-calendar (time-to-days time))))))
15092 (defun org-modify-ts-extra (s pos n dm)
15093 "Change the different parts of the lead-time and repeat fields in timestamp."
15094 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
15096 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
15098 ((or (org-pos-in-match-range pos 2)
15099 (org-pos-in-match-range pos 3))
15100 (setq m (string-to-number (match-string 3 s))
15101 h (string-to-number (match-string 2 s)))
15102 (if (org-pos-in-match-range pos 2)
15104 (setq n (* dm (org-no-warnings (signum n))))
15105 (when (not (= 0 (setq rem (% m dm))))
15106 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
15108 (if (< m 0) (setq m (+ m 60) h (1- h)))
15109 (if (> m 59) (setq m (- m 60) h (1+ h)))
15110 (setq h (min 24 (max 0 h)))
15111 (setq ng 1 new (format "-%02d:%02d" h m)))
15112 ((org-pos-in-match-range pos 6)
15113 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
15114 ((org-pos-in-match-range pos 5)
15115 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
15117 ((org-pos-in-match-range pos 9)
15118 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
15119 ((org-pos-in-match-range pos 8)
15120 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
15124 (substring s 0 (match-beginning ng))
15126 (substring s (match-end ng))))))
15129 (defun org-recenter-calendar (date)
15130 "If the calendar is visible, recenter it to DATE."
15131 (let* ((win (selected-window))
15132 (cwin (get-buffer-window "*Calendar*" t))
15133 (calendar-move-hook nil))
15135 (select-window cwin)
15136 (calendar-goto-date (if (listp date) date
15137 (calendar-gregorian-from-absolute date)))
15138 (select-window win))))
15140 (defun org-goto-calendar (&optional arg)
15141 "Go to the Emacs calendar at the current date.
15142 If there is a time stamp in the current line, go to that date.
15143 A prefix ARG can be used to force the current date."
15145 (let ((tsr org-ts-regexp) diff
15146 (calendar-move-hook nil)
15147 (calendar-view-holidays-initially-flag nil)
15148 (calendar-view-diary-initially-flag nil))
15149 (if (or (org-at-timestamp-p)
15151 (beginning-of-line 1)
15152 (looking-at (concat ".*" tsr))))
15153 (let ((d1 (time-to-days (current-time)))
15155 (org-time-string-to-time (match-string 1)))))
15156 (setq diff (- d2 d1))))
15158 (calendar-goto-today)
15159 (if (and diff (not arg)) (calendar-forward-day diff))))
15161 (defun org-get-date-from-calendar ()
15162 "Return a list (month day year) of date at point in calendar."
15163 (with-current-buffer "*Calendar*"
15165 (calendar-cursor-to-date))))
15167 (defun org-date-from-calendar ()
15168 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
15169 If there is already a time stamp at the cursor position, update it."
15171 (if (org-at-timestamp-p t)
15172 (org-timestamp-change 0 'calendar)
15173 (let ((cal-date (org-get-date-from-calendar)))
15174 (org-insert-time-stamp
15175 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
15177 (defun org-minutes-to-hh:mm-string (m)
15178 "Compute H:MM from a number of minutes."
15179 (let ((h (/ m 60)))
15180 (setq m (- m (* 60 h)))
15181 (format org-time-clocksum-format h m)))
15183 (defun org-hh:mm-string-to-minutes (s)
15184 "Convert a string H:MM to a number of minutes.
15185 If the string is just a number, interpret it as minutes.
15186 In fact, the first hh:mm or number in the string will be taken,
15187 there can be extra stuff in the string.
15188 If no number is found, the return value is 0."
15190 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
15191 (+ (* (string-to-number (match-string 1 s)) 60)
15192 (string-to-number (match-string 2 s))))
15193 ((string-match "\\([0-9]+\\)" s)
15194 (string-to-number (match-string 1 s)))
15199 (defun org-save-all-org-buffers ()
15200 "Save all Org-mode buffers without user confirmation."
15202 (message "Saving all Org-mode buffers...")
15203 (save-some-buffers t 'org-mode-p)
15204 (when (featurep 'org-id) (org-id-locations-save))
15205 (message "Saving all Org-mode buffers... done"))
15207 (defun org-revert-all-org-buffers ()
15208 "Revert all Org-mode buffers.
15209 Prompt for confirmation when there are unsaved changes.
15210 Be sure you know what you are doing before letting this function
15211 overwrite your changes.
15213 This function is useful in a setup where one tracks org files
15214 with a version control system, to revert on one machine after pulling
15215 changes from another. I believe the procedure must be like this:
15217 1. M-x org-save-all-org-buffers
15218 2. Pull changes from the other machine, resolve conflicts
15219 3. M-x org-revert-all-org-buffers"
15221 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
15224 (save-window-excursion
15227 (when (and (with-current-buffer b (org-mode-p))
15228 (with-current-buffer b buffer-file-name))
15229 (switch-to-buffer b)
15230 (revert-buffer t 'no-confirm)))
15232 (when (and (featurep 'org-id) org-id-track-globally)
15233 (org-id-locations-load)))))
15238 (defun org-iswitchb (&optional arg)
15239 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
15240 With a prefix argument, restrict available to files.
15241 With two prefix arguments, restrict available buffers to agenda files.
15243 This will use iswitchb for buffer name completion, unless
15244 `org-completion-use-ido' is non-nil, to select ido completion."
15246 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
15247 ((equal arg '(16)) (org-buffer-list 'agenda))
15248 (t (org-buffer-list))))
15249 (org-completion-use-iswitchb org-completion-use-iswitchb)
15250 (org-completion-use-ido org-completion-use-ido))
15251 (unless (or org-completion-use-ido org-completion-use-iswitchb)
15252 (setq org-completion-use-iswitchb t))
15254 (org-icompleting-read "Org buffer: "
15255 (mapcar 'list (mapcar 'buffer-name blist))
15259 (defalias 'org-ido-switchb 'org-iswitchb)
15261 (defun org-buffer-list (&optional predicate exclude-tmp)
15262 "Return a list of Org buffers.
15263 PREDICATE can be `export', `files' or `agenda'.
15265 export restrict the list to Export buffers.
15266 files restrict the list to buffers visiting Org files.
15267 agenda restrict the list to buffers visiting agenda files.
15269 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
15271 (agenda-files (and (eq predicate 'agenda)
15272 (mapcar 'file-truename (org-agenda-files t))))
15275 ((eq predicate 'files)
15276 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
15277 ((eq predicate 'export)
15278 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
15279 ((eq predicate 'agenda)
15281 (with-current-buffer b
15282 (and (eq major-mode 'org-mode)
15283 (setq bfn (buffer-file-name b))
15284 (member (file-truename bfn) agenda-files)))))
15285 (t (lambda (b) (with-current-buffer b
15286 (or (eq major-mode 'org-mode)
15287 (string-match "\*Org .*Export"
15288 (buffer-name b)))))))))
15292 (if (and (funcall filter b)
15293 (or (not exclude-tmp)
15294 (not (string-match "tmp" (buffer-name b)))))
15299 (defun org-agenda-files (&optional unrestricted archives)
15300 "Get the list of agenda files.
15301 Optional UNRESTRICTED means return the full list even if a restriction
15302 is currently in place.
15303 When ARCHIVES is t, include all archive files that are really being
15304 used by the agenda files. If ARCHIVE is `ifmode', do this only if
15305 `org-agenda-archives-mode' is t."
15308 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
15309 ((stringp org-agenda-files) (org-read-agenda-file-list))
15310 ((listp org-agenda-files) org-agenda-files)
15311 (t (error "Invalid value of `org-agenda-files'")))))
15312 (setq files (apply 'append
15313 (mapcar (lambda (f)
15314 (if (file-directory-p f)
15316 f t org-agenda-file-regexp)
15319 (when org-agenda-skip-unavailable-files
15320 (setq files (delq nil
15323 (and (file-readable-p file) file)))
15325 (when (or (eq archives t)
15326 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
15327 (setq files (org-add-archive-files files)))
15330 (defun org-agenda-file-p (&optional file)
15331 "Return non-nil, if FILE is an agenda file.
15332 If FILE is omitted, use the file associated with the current
15334 (member (or file (buffer-file-name))
15335 (org-agenda-files t)))
15337 (defun org-edit-agenda-file-list ()
15338 "Edit the list of agenda files.
15339 Depending on setup, this either uses customize to edit the variable
15340 `org-agenda-files', or it visits the file that is holding the list. In the
15341 latter case, the buffer is set up in a way that saving it automatically kills
15342 the buffer and restores the previous window configuration."
15344 (if (stringp org-agenda-files)
15345 (let ((cw (current-window-configuration)))
15346 (find-file org-agenda-files)
15347 (org-set-local 'org-window-configuration cw)
15348 (org-add-hook 'after-save-hook
15350 (set-window-configuration
15351 (prog1 org-window-configuration
15352 (kill-buffer (current-buffer))))
15353 (org-install-agenda-files-menu)
15354 (message "New agenda file list installed"))
15356 (message "%s" (substitute-command-keys
15357 "Edit list and finish with \\[save-buffer]")))
15358 (customize-variable 'org-agenda-files)))
15360 (defun org-store-new-agenda-file-list (list)
15361 "Set new value for the agenda file list and save it correctly."
15362 (if (stringp org-agenda-files)
15363 (let ((fe (org-read-agenda-file-list t)) b u)
15364 (while (setq b (find-buffer-visiting org-agenda-files))
15366 (with-temp-file org-agenda-files
15369 (lambda (f) ;; Keep un-expanded entries.
15370 (if (setq u (assoc f fe))
15375 (let ((org-mode-hook nil) (org-inhibit-startup t)
15376 (org-insert-mode-line-in-empty-file nil))
15377 (setq org-agenda-files list)
15378 (customize-save-variable 'org-agenda-files org-agenda-files))))
15380 (defun org-read-agenda-file-list (&optional pair-with-expansion)
15381 "Read the list of agenda files from a file.
15382 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
15383 filenames, used by `org-store-new-agenda-file-list' to write back
15384 un-expanded file names."
15385 (when (file-directory-p org-agenda-files)
15386 (error "`org-agenda-files' cannot be a single directory"))
15387 (when (stringp org-agenda-files)
15389 (insert-file-contents org-agenda-files)
15392 (let ((e (expand-file-name (substitute-in-file-name f)
15394 (if pair-with-expansion
15397 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
15400 (defun org-cycle-agenda-files ()
15401 "Cycle through the files in `org-agenda-files'.
15402 If the current buffer visits an agenda file, find the next one in the list.
15403 If the current buffer does not, find the first agenda file."
15405 (let* ((fs (org-agenda-files t))
15406 (files (append fs (list (car fs))))
15407 (tcf (if buffer-file-name (file-truename buffer-file-name)))
15409 (unless files (error "No agenda files"))
15411 (while (setq file (pop files))
15412 (if (equal (file-truename file) tcf)
15414 (find-file (car files))
15416 (find-file (car fs)))
15417 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
15419 (defun org-agenda-file-to-front (&optional to-end)
15420 "Move/add the current file to the top of the agenda file list.
15421 If the file is not present in the list, it is added to the front. If it is
15422 present, it is moved there. With optional argument TO-END, add/move to the
15425 (let ((org-agenda-skip-unavailable-files nil)
15426 (file-alist (mapcar (lambda (x)
15427 (cons (file-truename x) x))
15428 (org-agenda-files t)))
15429 (ctf (file-truename buffer-file-name))
15431 (setq x (assoc ctf file-alist) had x)
15433 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
15435 (setq file-alist (append (delq x file-alist) (list x)))
15436 (setq file-alist (cons x (delq x file-alist))))
15437 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
15438 (org-install-agenda-files-menu)
15439 (message "File %s to %s of agenda file list"
15440 (if had "moved" "added") (if to-end "end" "front"))))
15442 (defun org-remove-file (&optional file)
15443 "Remove current file from the list of files in variable `org-agenda-files'.
15444 These are the files which are being checked for agenda entries.
15445 Optional argument FILE means use this file instead of the current."
15447 (let* ((org-agenda-skip-unavailable-files nil)
15448 (file (or file buffer-file-name))
15449 (true-file (file-truename file))
15450 (afile (abbreviate-file-name file))
15451 (files (delq nil (mapcar
15453 (if (equal true-file
15456 (org-agenda-files t)))))
15457 (if (not (= (length files) (length (org-agenda-files t))))
15459 (org-store-new-agenda-file-list files)
15460 (org-install-agenda-files-menu)
15461 (message "Removed file: %s" afile))
15462 (message "File was not in list: %s (not removed)" afile))))
15464 (defun org-file-menu-entry (file)
15465 (vector file (list 'find-file file) t))
15467 (defun org-check-agenda-file (file)
15468 "Make sure FILE exists. If not, ask user what to do."
15469 (when (not (file-exists-p file))
15470 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
15471 (abbreviate-file-name file))
15472 (let ((r (downcase (read-char-exclusive))))
15475 (org-remove-file file)
15476 (throw 'nextfile t))
15477 (t (error "Abort"))))))
15479 (defun org-get-agenda-file-buffer (file)
15480 "Get a buffer visiting FILE. If the buffer needs to be created, add
15481 it to the list of buffers which might be released later."
15482 (let ((buf (org-find-base-buffer-visiting file)))
15484 buf ; just return it
15485 ;; Make a new buffer and remember it
15486 (setq buf (find-file-noselect file))
15487 (if buf (push buf org-agenda-new-buffers))
15490 (defun org-release-buffers (blist)
15491 "Release all buffers in list, asking the user for confirmation when needed.
15492 When a buffer is unmodified, it is just killed. When modified, it is saved
15493 \(if the user agrees) and then killed."
15495 (while (setq buf (pop blist))
15496 (setq file (buffer-file-name buf))
15497 (when (and (buffer-modified-p buf)
15499 (y-or-n-p (format "Save file %s? " file)))
15500 (with-current-buffer buf (save-buffer)))
15501 (kill-buffer buf))))
15503 (defun org-prepare-agenda-buffers (files)
15504 "Create buffers for all agenda files, protect archived trees and comments."
15506 (let ((pa '(:org-archived t))
15507 (pc '(:org-comment t))
15508 (pall '(:org-archived t :org-comment t))
15509 (inhibit-read-only t)
15510 (rea (concat ":" org-archive-tag ":"))
15514 (while (setq file (pop files))
15518 (org-check-agenda-file file)
15519 (set-buffer (org-get-agenda-file-buffer file)))
15521 (setq bmp (buffer-modified-p))
15522 (org-refresh-category-properties)
15523 (setq org-todo-keywords-for-agenda
15524 (append org-todo-keywords-for-agenda org-todo-keywords-1))
15525 (setq org-done-keywords-for-agenda
15526 (append org-done-keywords-for-agenda org-done-keywords))
15527 (setq org-todo-keyword-alist-for-agenda
15528 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
15529 (setq org-drawers-for-agenda
15530 (append org-drawers-for-agenda org-drawers))
15531 (setq org-tag-alist-for-agenda
15532 (append org-tag-alist-for-agenda org-tag-alist))
15535 (remove-text-properties (point-min) (point-max) pall)
15536 (when org-agenda-skip-archived-trees
15537 (goto-char (point-min))
15538 (while (re-search-forward rea nil t)
15539 (if (org-on-heading-p t)
15540 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
15541 (goto-char (point-min))
15542 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
15543 (while (re-search-forward re nil t)
15544 (add-text-properties
15545 (match-beginning 0) (org-end-of-subtree t) pc)))
15546 (set-buffer-modified-p bmp)))))
15547 (setq org-todo-keywords-for-agenda
15548 (org-uniquify org-todo-keywords-for-agenda))
15549 (setq org-todo-keyword-alist-for-agenda
15550 (org-uniquify org-todo-keyword-alist-for-agenda)
15551 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
15553 ;;;; Embedded LaTeX
15555 (defvar org-cdlatex-mode-map (make-sparse-keymap)
15556 "Keymap for the minor `org-cdlatex-mode'.")
15558 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
15559 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
15560 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
15561 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
15562 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
15564 (defvar org-cdlatex-texmathp-advice-is-done nil
15565 "Flag remembering if we have applied the advice to texmathp already.")
15567 (define-minor-mode org-cdlatex-mode
15568 "Toggle the minor `org-cdlatex-mode'.
15569 This mode supports entering LaTeX environment and math in LaTeX fragments
15571 \\{org-cdlatex-mode-map}"
15573 (when org-cdlatex-mode (require 'cdlatex))
15574 (unless org-cdlatex-texmathp-advice-is-done
15575 (setq org-cdlatex-texmathp-advice-is-done t)
15576 (defadvice texmathp (around org-math-always-on activate)
15577 "Always return t in org-mode buffers.
15578 This is because we want to insert math symbols without dollars even outside
15579 the LaTeX math segments. If Orgmode thinks that point is actually inside
15580 an embedded LaTeX fragment, let texmathp do its job.
15581 \\[org-cdlatex-mode-map]"
15585 ((not (org-mode-p)) ad-do-it)
15586 ((eq this-command 'cdlatex-math-symbol)
15587 (setq ad-return-value t
15588 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
15590 (let ((p (org-inside-LaTeX-fragment-p)))
15591 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
15592 (setq ad-return-value t
15593 texmathp-why '("Org-mode embedded math" . 0))
15594 (if p ad-do-it)))))))))
15596 (defun turn-on-org-cdlatex ()
15597 "Unconditionally turn on `org-cdlatex-mode'."
15598 (org-cdlatex-mode 1))
15600 (defun org-inside-LaTeX-fragment-p ()
15601 "Test if point is inside a LaTeX fragment.
15602 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15603 sequence appearing also before point.
15604 Even though the matchers for math are configurable, this function assumes
15605 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15606 delimiters are skipped when they have been removed by customization.
15607 The return value is nil, or a cons cell with the delimiter and
15608 and the position of this delimiter.
15610 This function does a reasonably good job, but can locally be fooled by
15611 for example currency specifications. For example it will assume being in
15612 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15613 fragments that are properly closed, but during editing, we have to live
15614 with the uncertainty caused by missing closing delimiters. This function
15615 looks only before point, not after."
15617 (let ((pos (point))
15618 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
15620 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
15622 dd-on str (start 0) m re)
15625 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
15626 re (nth 1 (assoc "$" org-latex-regexps)))
15627 (while (string-match re str start)
15629 ((= (match-end 0) (length str))
15630 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
15631 ((= (match-end 0) (- (length str) 5))
15633 (t (setq start (match-end 0))))))
15634 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
15636 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
15637 (and (match-beginning 2) (throw 'exit nil))
15639 (while (re-search-backward "\\$\\$" lim t)
15640 (setq dd-on (not dd-on)))
15642 (if dd-on (cons "$$" m))))))
15644 (defun org-inside-latex-macro-p ()
15645 "Is point inside a LaTeX macro or its arguments?"
15648 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15650 (defun org-try-cdlatex-tab ()
15651 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15652 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15653 - inside a LaTeX fragment, or
15654 - after the first word in a line, where an abbreviation expansion could
15655 insert a LaTeX environment."
15656 (when org-cdlatex-mode
15659 (skip-chars-backward "a-zA-Z0-9*")
15660 (skip-chars-backward " \t")
15663 ((org-inside-LaTeX-fragment-p)
15667 (defun org-cdlatex-underscore-caret (&optional arg)
15668 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15669 Revert to the normal definition outside of these fragments."
15671 (if (org-inside-LaTeX-fragment-p)
15672 (call-interactively 'cdlatex-sub-superscript)
15673 (let (org-cdlatex-mode)
15674 (call-interactively (key-binding (vector last-input-event))))))
15676 (defun org-cdlatex-math-modify (&optional arg)
15677 "Execute `cdlatex-math-modify' in LaTeX fragments.
15678 Revert to the normal definition outside of these fragments."
15680 (if (org-inside-LaTeX-fragment-p)
15681 (call-interactively 'cdlatex-math-modify)
15682 (let (org-cdlatex-mode)
15683 (call-interactively (key-binding (vector last-input-event))))))
15685 (defvar org-latex-fragment-image-overlays nil
15686 "List of overlays carrying the images of latex fragments.")
15687 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
15689 (defun org-remove-latex-fragment-image-overlays ()
15690 "Remove all overlays with LaTeX fragment images in current buffer."
15691 (mapc 'delete-overlay org-latex-fragment-image-overlays)
15692 (setq org-latex-fragment-image-overlays nil))
15694 (defun org-preview-latex-fragment (&optional subtree)
15695 "Preview the LaTeX fragment at point, or all locally or globally.
15696 If the cursor is in a LaTeX fragment, create the image and overlay
15697 it over the source code. If there is no fragment at point, display
15698 all fragments in the current text, from one headline to the next. With
15699 prefix SUBTREE, display all fragments in the current subtree. With a
15700 double prefix `C-u C-u', or when the cursor is before the first headline,
15701 display all fragments in the buffer.
15702 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15704 (org-remove-latex-fragment-image-overlays)
15707 (let (beg end at msg)
15709 ((or (equal subtree '(16))
15710 (not (save-excursion
15711 (re-search-backward (concat "^" outline-regexp) nil t))))
15712 (setq beg (point-min) end (point-max)
15713 msg "Creating images for buffer...%s"))
15714 ((equal subtree '(4))
15715 (org-back-to-heading)
15716 (setq beg (point) end (org-end-of-subtree t)
15717 msg "Creating images for subtree...%s"))
15719 (if (setq at (org-inside-LaTeX-fragment-p))
15720 (goto-char (max (point-min) (- (cdr at) 2)))
15721 (org-back-to-heading))
15722 (setq beg (point) end (progn (outline-next-heading) (point))
15723 msg (if at "Creating image...%s"
15724 "Creating images for entry...%s"))))
15726 (narrow-to-region beg end)
15729 (concat "ltxpng/" (file-name-sans-extension
15730 (file-name-nondirectory
15731 buffer-file-name)))
15732 default-directory 'overlays msg at 'forbuffer)
15733 (message msg "done. Use `C-c C-c' to remove images.")))))
15735 (defvar org-latex-regexps
15736 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
15737 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15738 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15739 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15740 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15741 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
15742 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
15743 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
15744 "Regular expressions for matching embedded LaTeX.")
15746 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer)
15747 "Replace LaTeX fragments with links to an image, and produce images.
15748 Some of the options can be changed using the variable
15749 `org-format-latex-options'."
15750 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
15751 (let* ((prefixnodir (file-name-nondirectory prefix))
15752 (absprefix (expand-file-name prefix dir))
15753 (todir (file-name-directory absprefix))
15754 (opt org-format-latex-options)
15755 (matchers (plist-get opt :matchers))
15756 (re-list org-latex-regexps)
15757 (org-format-latex-header-extra
15758 (plist-get (org-infile-export-plist) :latex-header-extra))
15759 (cnt 0) txt hash link beg end re e checkdir
15760 executables-checked
15761 m n block linkfile movefile ov)
15762 ;; Check the different regular expressions
15763 (while (setq e (pop re-list))
15764 (setq m (car e) re (nth 1 e) n (nth 2 e)
15765 block (if (nth 3 e) "\n\n" ""))
15766 (when (member m matchers)
15767 (goto-char (point-min))
15768 (while (re-search-forward re nil t)
15769 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
15770 (not (get-text-property (match-beginning n)
15773 (not (eq (get-char-property (match-beginning n)
15775 'org-latex-overlay))))
15776 (setq txt (match-string n)
15777 beg (match-beginning n) end (match-end n)
15779 (let (print-length print-level) ; make sure full list is printed
15780 (setq hash (sha1 (prin1-to-string
15781 (list org-format-latex-header
15782 org-format-latex-header-extra
15783 org-export-latex-default-packages-alist
15784 org-export-latex-packages-alist
15785 org-format-latex-options
15787 linkfile (format "%s_%s.png" prefix hash)
15788 movefile (format "%s_%s.png" absprefix hash)))
15789 (setq link (concat block "[[file:" linkfile "]]" block))
15790 (if msg (message msg cnt))
15792 (unless checkdir ; make sure the directory exists
15794 (or (file-directory-p todir) (make-directory todir)))
15796 (unless executables-checked
15797 (org-check-external-command
15798 "latex" "needed to convert LaTeX fragments to images")
15799 (org-check-external-command
15800 "dvipng" "needed to convert LaTeX fragments to images")
15801 (setq executables-checked t))
15803 (unless (file-exists-p movefile)
15804 (org-create-formula-image
15805 txt movefile opt forbuffer))
15809 (if (eq (overlay-get o 'org-overlay-type)
15810 'org-latex-overlay)
15811 (delete-overlay o)))
15812 (overlays-in beg end))
15813 (setq ov (make-overlay beg end))
15814 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
15815 (if (featurep 'xemacs)
15817 (overlay-put ov 'invisible t)
15820 (make-glyph (vector 'png :file movefile))))
15823 (list 'image :type 'png :file movefile :ascent 'center)))
15824 (push ov org-latex-fragment-image-overlays)
15826 (delete-region beg end)
15827 (insert (org-add-props link
15828 (list 'org-latex-src
15829 (replace-regexp-in-string "\"" "" txt)))))))))))
15831 ;; This function borrows from Ganesh Swami's latex2png.el
15832 (defun org-create-formula-image (string tofile options buffer)
15833 "This calls dvipng."
15834 (require 'org-latex)
15835 (let* ((tmpdir (if (featurep 'xemacs)
15837 temporary-file-directory))
15838 (texfilebase (make-temp-name
15839 (expand-file-name "orgtex" tmpdir)))
15840 (texfile (concat texfilebase ".tex"))
15841 (dvifile (concat texfilebase ".dvi"))
15842 (pngfile (concat texfilebase ".png"))
15843 (fnh (if (featurep 'xemacs)
15844 (font-height (get-face-font 'default))
15845 (face-attribute 'default :height nil)))
15846 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
15847 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
15848 (fg (or (plist-get options (if buffer :foreground :html-foreground))
15850 (bg (or (plist-get options (if buffer :background :html-background))
15852 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
15853 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
15854 (with-temp-file texfile
15855 (insert (org-splice-latex-header
15856 org-format-latex-header
15857 org-export-latex-default-packages-alist
15858 org-export-latex-packages-alist t
15859 org-format-latex-header-extra))
15860 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
15861 (require 'org-latex)
15862 (org-export-latex-fix-inputenc))
15863 (let ((dir default-directory))
15864 (condition-case nil
15867 (call-process "latex" nil nil nil texfile))
15870 (if (not (file-exists-p dvifile))
15871 (progn (message "Failed to create dvi file from %s" texfile) nil)
15872 (condition-case nil
15873 (call-process "dvipng" nil nil nil
15876 ;;"-x" scale "-y" scale
15881 (if (not (file-exists-p pngfile))
15882 (if org-format-latex-signal-error
15883 (error "Failed to create png file from %s" texfile)
15884 (message "Failed to create png file from %s" texfile)
15886 ;; Use the requested file name and clean up
15887 (copy-file pngfile tofile 'replace)
15888 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
15889 (delete-file (concat texfilebase e)))
15892 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
15893 "Fill a LaTeX header template TPL.
15894 In the template, the following place holders will be recognized:
15896 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15897 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15898 [PACKAGES] \\usepackage statements for PKG
15899 [NO-PACKAGES] do not include PKG
15900 [EXTRA] the string EXTRA
15901 [NO-EXTRA] do not include EXTRA
15903 For backward compatibility, if both the positive and the negative place
15904 holder is missing, the positive one (without the \"NO-\") will be
15905 assumed to be present at the end of the template.
15906 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15908 SNIPPETS-P indicates if this is run to create snippet images for HTML."
15909 (let (rpl (end ""))
15910 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
15911 (setq rpl (if (or (match-end 1) (not def-pkg))
15912 "" (org-latex-packages-to-string def-pkg snippets-p t))
15913 tpl (replace-match rpl t t tpl))
15914 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
15916 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
15917 (setq rpl (if (or (match-end 1) (not pkg))
15918 "" (org-latex-packages-to-string pkg snippets-p t))
15919 tpl (replace-match rpl t t tpl))
15922 (org-latex-packages-to-string pkg snippets-p)))))
15924 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
15925 (setq rpl (if (or (match-end 1) (not extra))
15926 "" (concat extra "\n"))
15927 tpl (replace-match rpl t t tpl))
15928 (if (and extra (string-match "\\S-" extra))
15929 (setq end (concat end "\n" extra))))
15931 (if (string-match "\\S-" end)
15932 (concat tpl "\n" end)
15935 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
15936 "Turn an alist of packages into a string with the \\usepackage macros."
15937 (setq pkg (mapconcat (lambda(p)
15940 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
15941 (format "%% Package %s omitted" (cadr p)))
15942 ((equal "" (car p))
15943 (format "\\usepackage{%s}" (cadr p)))
15945 (format "\\usepackage[%s]{%s}"
15946 (car p) (cadr p)))))
15949 (if newline (concat pkg "\n") pkg))
15951 (defun org-dvipng-color (attr)
15952 "Return an rgb color specification for dvipng."
15953 (apply 'format "rgb %s %s %s"
15954 (mapcar 'org-normalize-color
15955 (color-values (face-attribute 'default attr nil)))))
15957 (defun org-normalize-color (value)
15958 "Return string to be used as color value for an RGB component."
15959 (format "%g" (/ value 65535.0)))
15964 (defvar org-inline-image-overlays nil)
15965 (make-variable-buffer-local 'org-inline-image-overlays)
15967 (defun org-toggle-inline-images (&optional include-linked)
15968 "Toggle the display of inline images.
15969 INCLUDE-LINKED is passed to `org-display-inline-images'."
15971 (if org-inline-image-overlays
15973 (org-remove-inline-images)
15974 (message "Inline image display turned off"))
15975 (org-display-inline-images include-linked)
15976 (if org-inline-image-overlays
15977 (message "%d images displayed inline"
15978 (length org-inline-image-overlays))
15979 (message "No images to display inline"))))
15981 (defun org-display-inline-images (&optional include-linked refresh beg end)
15982 "Display inline images.
15983 Normally only links without a description part are inlined, because this
15984 is how it will work for export. When INCLUDE-LINKED is set, also links
15985 with a description part will be inlined. This can be nice for a quick
15986 look at those images, but it does not reflect whatexported files will look
15988 When REFRESH is set, refresh existing images between BEG and END.
15989 This will create new image displays only if necessary.
15990 BEG and END default to the buffer boundaries."
15993 (org-remove-inline-images)
15994 (clear-image-cache))
15998 (setq beg (or beg (point-min)) end (or end (point-max)))
15999 (goto-char (point-min))
16000 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([-+~.:/\\_0-9a-zA-Z ]+"
16001 (substring (org-image-file-name-regexp) 0 -2)
16002 "\\)\\]" (if include-linked "" "\\]")))
16004 (while (re-search-forward re end t)
16005 (setq old (get-char-property-and-overlay (match-beginning 1)
16006 'org-image-overlay))
16007 (setq file (expand-file-name
16008 (concat (or (match-string 3) "") (match-string 4))))
16009 (when (file-exists-p file)
16010 (if (and (car-safe old) refresh)
16011 (image-refresh (overlay-get (cdr old) 'display))
16012 (setq img (create-image file))
16014 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
16015 (overlay-put ov 'display img)
16016 (overlay-put ov 'face 'default)
16017 (overlay-put ov 'org-image-overlay t)
16018 (overlay-put ov 'modification-hooks
16019 (list 'org-display-inline-modification-hook))
16020 (push ov org-inline-image-overlays)))))))))
16022 (defun org-display-inline-modification-hook (ov after beg end &optional len)
16023 "Remove inline-display overlay if a corresponding region is modified."
16024 (let ((inhibit-modification-hooks t))
16025 (when (and ov after)
16026 (delete ov org-inline-image-overlays)
16027 (delete-overlay ov))))
16029 (defun org-remove-inline-images ()
16030 "Remove inline display of images."
16032 (mapc 'delete-overlay org-inline-image-overlays)
16033 (setq org-inline-image-overlays nil))
16037 ;; Make `C-c C-x' a prefix key
16038 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
16040 ;; TAB key with modifiers
16041 (org-defkey org-mode-map "\C-i" 'org-cycle)
16042 (org-defkey org-mode-map [(tab)] 'org-cycle)
16043 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
16044 (org-defkey org-mode-map [(meta tab)] 'org-complete)
16045 (org-defkey org-mode-map "\M-\t" 'org-complete)
16046 (org-defkey org-mode-map "\M-\C-i" 'org-complete)
16047 ;; The following line is necessary under Suse GNU/Linux
16048 (unless (featurep 'xemacs)
16049 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
16050 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
16051 (define-key org-mode-map [backtab] 'org-shifttab)
16053 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
16054 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
16055 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
16057 ;; Cursor keys with modifiers
16058 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
16059 (org-defkey org-mode-map [(meta right)] 'org-metaright)
16060 (org-defkey org-mode-map [(meta up)] 'org-metaup)
16061 (org-defkey org-mode-map [(meta down)] 'org-metadown)
16063 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
16064 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
16065 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
16066 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
16068 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
16069 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
16070 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
16071 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
16073 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
16074 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
16077 (define-key org-mode-map org-babel-key-prefix org-babel-map)
16078 (mapc (lambda (pair)
16079 (define-key org-babel-map (car pair) (cdr pair)))
16080 org-babel-key-bindings)
16082 ;;; Extra keys for tty access.
16083 ;; We only set them when really needed because otherwise the
16084 ;; menus don't show the simple keys
16086 (when (or org-use-extra-keys
16087 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
16088 (not window-system))
16089 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
16090 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
16091 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
16092 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
16093 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
16094 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
16095 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
16096 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
16097 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
16098 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
16099 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
16100 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
16101 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
16102 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
16103 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
16104 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
16105 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
16106 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
16107 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
16108 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
16109 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
16110 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
16111 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
16112 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
16113 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
16114 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
16115 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
16116 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
16118 ;; All the other keys
16120 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
16121 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
16122 (if (boundp 'narrow-map)
16123 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
16124 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
16125 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
16126 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
16127 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
16128 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
16129 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
16130 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
16131 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
16132 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
16133 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
16134 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
16135 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
16136 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
16137 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
16138 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
16139 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
16140 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
16141 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
16142 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
16143 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
16144 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
16145 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
16146 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
16147 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
16148 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
16149 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
16150 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
16151 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
16152 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
16153 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
16154 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
16155 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
16156 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
16157 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
16158 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
16159 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
16160 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
16161 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
16162 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
16163 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
16164 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
16165 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
16166 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
16167 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
16168 (org-defkey org-mode-map "\C-c^" 'org-sort)
16169 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
16170 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
16171 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
16172 (org-defkey org-mode-map "\C-m" 'org-return)
16173 (org-defkey org-mode-map "\C-j" 'org-return-indent)
16174 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
16175 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
16176 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
16177 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
16178 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
16179 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
16180 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
16181 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
16182 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
16183 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
16184 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
16185 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
16186 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
16187 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
16188 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
16189 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
16190 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
16191 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
16192 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
16193 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
16195 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
16196 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
16197 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
16198 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
16200 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
16201 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
16202 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
16203 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
16204 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
16205 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
16206 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
16207 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
16208 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
16209 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
16210 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
16211 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
16212 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
16213 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
16214 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
16215 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
16216 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
16218 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
16219 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
16220 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
16221 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
16223 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
16225 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
16227 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
16228 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
16230 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
16233 (when (featurep 'xemacs)
16234 (org-defkey org-mode-map 'button3 'popup-mode-menu))
16237 (defconst org-speed-commands-default
16239 ("Outline Navigation")
16240 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
16241 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
16242 ("f" . (org-speed-move-safe 'org-forward-same-level))
16243 ("b" . (org-speed-move-safe 'org-backward-same-level))
16244 ("u" . (org-speed-move-safe 'outline-up-heading))
16246 ("g" . (org-refile t))
16247 ("Outline Visibility")
16249 ("C" . org-shifttab)
16250 (" " . org-display-outline-path)
16251 ("Outline Structure Editing")
16252 ("U" . org-shiftmetaup)
16253 ("D" . org-shiftmetadown)
16254 ("r" . org-metaright)
16255 ("l" . org-metaleft)
16256 ("R" . org-shiftmetaright)
16257 ("L" . org-shiftmetaleft)
16258 ("i" . (progn (forward-char 1) (call-interactively
16259 'org-insert-heading-respect-content)))
16262 ("a" . org-archive-subtree-default-with-confirmation)
16263 ("." . outline-mark-subtree)
16265 ("I" . org-clock-in)
16266 ("O" . org-clock-out)
16267 ("Meta Data Editing")
16269 ("0" . (org-priority ?\ ))
16270 ("1" . (org-priority ?A))
16271 ("2" . (org-priority ?B))
16272 ("3" . (org-priority ?C))
16273 (";" . org-set-tags-command)
16274 ("e" . org-set-effort)
16275 ("Agenda Views etc")
16277 ("/" . org-sparse-tree)
16279 ("o" . org-open-at-point)
16280 ("?" . org-speed-command-help)
16282 "The default speed commands.")
16284 (defun org-print-speed-command (e)
16285 (if (> (length (car e)) 1)
16290 (princ (make-string (length (car e)) ?-))
16294 (if (symbolp (cdr e))
16295 (princ (symbol-name (cdr e)))
16299 (defun org-speed-command-help ()
16300 "Show the available speed commands."
16302 (if (not org-use-speed-commands)
16303 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
16304 (with-output-to-temp-buffer "*Help*"
16305 (princ "User-defined Speed commands\n===========================\n")
16306 (mapc 'org-print-speed-command org-speed-commands-user)
16308 (princ "Built-in Speed commands\n=======================\n")
16309 (mapc 'org-print-speed-command org-speed-commands-default))
16310 (with-current-buffer "*Help*"
16311 (setq truncate-lines t))))
16313 (defun org-speed-move-safe (cmd)
16314 "Execute CMD, but make sure that the cursor always ends up in a headline.
16315 If not, return to the original position and throw an error."
16317 (let ((pos (point)))
16318 (call-interactively cmd)
16319 (unless (and (bolp) (org-on-heading-p))
16321 (error "Boundary reached while executing %s" cmd))))
16323 (defvar org-self-insert-command-undo-counter 0)
16325 (defvar org-table-auto-blank-field) ; defined in org-table.el
16326 (defvar org-speed-command nil)
16327 (defun org-self-insert-command (N)
16328 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
16329 If the cursor is in a table looking at whitespace, the whitespace is
16330 overwritten, and the table is not marked as requiring realignment."
16333 ((and org-use-speed-commands
16334 (or (and (bolp) (looking-at outline-regexp))
16335 (and (functionp org-use-speed-commands)
16336 (funcall org-use-speed-commands)))
16339 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
16340 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
16342 ((commandp org-speed-command)
16343 (setq this-command org-speed-command)
16344 (call-interactively org-speed-command))
16345 ((functionp org-speed-command)
16346 (funcall org-speed-command))
16347 ((and org-speed-command (listp org-speed-command))
16348 (eval org-speed-command))
16349 (t (let (org-use-speed-commands)
16350 (call-interactively 'org-self-insert-command)))))
16354 ;; check if we blank the field, and if that triggers align
16355 (and (featurep 'org-table) org-table-auto-blank-field
16356 (member last-command
16357 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
16358 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
16359 ;; got extra space, this field does not determine column width
16360 (let (org-table-may-need-update) (org-table-blank-field))
16361 ;; no extra space, this field may determine column width
16362 (org-table-blank-field)))
16365 (looking-at "[^|\n]* |"))
16366 (let (org-table-may-need-update)
16367 (goto-char (1- (match-end 0)))
16368 (delete-backward-char 1)
16369 (goto-char (match-beginning 0))
16370 (self-insert-command N)))
16372 (setq org-table-may-need-update t)
16373 (self-insert-command N)
16374 (org-fix-tags-on-the-fly)
16375 (if org-self-insert-cluster-for-undo
16376 (if (not (eq last-command 'org-self-insert-command))
16377 (setq org-self-insert-command-undo-counter 1)
16378 (if (>= org-self-insert-command-undo-counter 20)
16379 (setq org-self-insert-command-undo-counter 1)
16380 (and (> org-self-insert-command-undo-counter 0)
16382 (not (cadr buffer-undo-list)) ; remove nil entry
16383 (setcdr buffer-undo-list (cddr buffer-undo-list)))
16384 (setq org-self-insert-command-undo-counter
16385 (1+ org-self-insert-command-undo-counter))))))))
16387 (defun org-fix-tags-on-the-fly ()
16388 (when (and (equal (char-after (point-at-bol)) ?*)
16389 (org-on-heading-p))
16390 (org-align-tags-here org-tags-column)))
16392 (defun org-delete-backward-char (N)
16393 "Like `delete-backward-char', insert whitespace at field end in tables.
16394 When deleting backwards, in tables this function will insert whitespace in
16395 front of the next \"|\" separator, to keep the table aligned. The table will
16396 still be marked for re-alignment if the field did fill the entire column,
16397 because, in this case the deletion might narrow the column."
16399 (if (and (org-table-p)
16401 (string-match "|" (buffer-substring (point-at-bol) (point)))
16402 (looking-at ".*?|"))
16403 (let ((pos (point))
16404 (noalign (looking-at "[^|\n\r]* |"))
16405 (c org-table-may-need-update))
16406 (backward-delete-char N)
16407 (skip-chars-forward "^|")
16409 (goto-char (1- pos))
16410 ;; noalign: if there were two spaces at the end, this field
16411 ;; does not determine the width of the column.
16412 (if noalign (setq org-table-may-need-update c)))
16413 (backward-delete-char N)
16414 (org-fix-tags-on-the-fly)))
16416 (defun org-delete-char (N)
16417 "Like `delete-char', but insert whitespace at field end in tables.
16418 When deleting characters, in tables this function will insert whitespace in
16419 front of the next \"|\" separator, to keep the table aligned. The table will
16420 still be marked for re-alignment if the field did fill the entire column,
16421 because, in this case the deletion might narrow the column."
16423 (if (and (org-table-p)
16425 (not (= (char-after) ?|))
16427 (if (looking-at ".*?|")
16428 (let ((pos (point))
16429 (noalign (looking-at "[^|\n\r]* |"))
16430 (c org-table-may-need-update))
16431 (replace-match (concat
16432 (substring (match-string 0) 1 -1)
16435 ;; noalign: if there were two spaces at the end, this field
16436 ;; does not determine the width of the column.
16437 (if noalign (setq org-table-may-need-update c)))
16440 (org-fix-tags-on-the-fly)))
16442 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
16443 (put 'org-self-insert-command 'delete-selection t)
16444 (put 'orgtbl-self-insert-command 'delete-selection t)
16445 (put 'org-delete-char 'delete-selection 'supersede)
16446 (put 'org-delete-backward-char 'delete-selection 'supersede)
16447 (put 'org-yank 'delete-selection 'yank)
16449 ;; Make `flyspell-mode' delay after some commands
16450 (put 'org-self-insert-command 'flyspell-delayed t)
16451 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
16452 (put 'org-delete-char 'flyspell-delayed t)
16453 (put 'org-delete-backward-char 'flyspell-delayed t)
16455 ;; Make pabbrev-mode expand after org-mode commands
16456 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
16457 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
16459 ;; How to do this: Measure non-white length of current string
16460 ;; If equal to column width, we should realign.
16462 (defun org-remap (map &rest commands)
16463 "In MAP, remap the functions given in COMMANDS.
16464 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
16467 (setq old (pop commands) new (pop commands))
16468 (if (fboundp 'command-remapping)
16469 (org-defkey map (vector 'remap old) new)
16470 (substitute-key-definition old new map global-map)))))
16472 (when (eq org-enable-table-editor 'optimized)
16473 ;; If the user wants maximum table support, we need to hijack
16474 ;; some standard editing functions
16475 (org-remap org-mode-map
16476 'self-insert-command 'org-self-insert-command
16477 'delete-char 'org-delete-char
16478 'delete-backward-char 'org-delete-backward-char)
16479 (org-defkey org-mode-map "|" 'org-force-self-insert))
16481 (defvar org-ctrl-c-ctrl-c-hook nil
16482 "Hook for functions attaching themselves to `C-c C-c'.
16483 This can be used to add additional functionality to the C-c C-c key which
16484 executes context-dependent commands.
16485 Each function will be called with no arguments. The function must check
16486 if the context is appropriate for it to act. If yes, it should do its
16487 thing and then return a non-nil value. If the context is wrong,
16488 just do nothing and return nil.")
16490 (defvar org-tab-first-hook nil
16491 "Hook for functions to attach themselves to TAB.
16492 See `org-ctrl-c-ctrl-c-hook' for more information.
16493 This hook runs as the first action when TAB is pressed, even before
16494 `org-cycle' messes around with the `outline-regexp' to cater for
16495 inline tasks and plain list item folding.
16496 If any function in this hook returns t, any other actions that
16497 would have been caused by TAB (such as table field motion or visibility
16498 cycling) will not occur.")
16500 (defvar org-tab-after-check-for-table-hook nil
16501 "Hook for functions to attach themselves to TAB.
16502 See `org-ctrl-c-ctrl-c-hook' for more information.
16503 This hook runs after it has been established that the cursor is not in a
16504 table, but before checking if the cursor is in a headline or if global cycling
16506 If any function in this hook returns t, not other actions like visibility
16507 cycling will be done.")
16509 (defvar org-tab-after-check-for-cycling-hook nil
16510 "Hook for functions to attach themselves to TAB.
16511 See `org-ctrl-c-ctrl-c-hook' for more information.
16512 This hook runs after it has been established that not table field motion and
16513 not visibility should be done because of current context. This is probably
16514 the place where a package like yasnippets can hook in.")
16516 (defvar org-tab-before-tab-emulation-hook nil
16517 "Hook for functions to attach themselves to TAB.
16518 See `org-ctrl-c-ctrl-c-hook' for more information.
16519 This hook runs after every other options for TAB have been exhausted, but
16520 before indentation and \t insertion takes place.")
16522 (defvar org-metaleft-hook nil
16523 "Hook for functions attaching themselves to `M-left'.
16524 See `org-ctrl-c-ctrl-c-hook' for more information.")
16525 (defvar org-metaright-hook nil
16526 "Hook for functions attaching themselves to `M-right'.
16527 See `org-ctrl-c-ctrl-c-hook' for more information.")
16528 (defvar org-metaup-hook nil
16529 "Hook for functions attaching themselves to `M-up'.
16530 See `org-ctrl-c-ctrl-c-hook' for more information.")
16531 (defvar org-metadown-hook nil
16532 "Hook for functions attaching themselves to `M-down'.
16533 See `org-ctrl-c-ctrl-c-hook' for more information.")
16534 (defvar org-shiftmetaleft-hook nil
16535 "Hook for functions attaching themselves to `M-S-left'.
16536 See `org-ctrl-c-ctrl-c-hook' for more information.")
16537 (defvar org-shiftmetaright-hook nil
16538 "Hook for functions attaching themselves to `M-S-right'.
16539 See `org-ctrl-c-ctrl-c-hook' for more information.")
16540 (defvar org-shiftmetaup-hook nil
16541 "Hook for functions attaching themselves to `M-S-up'.
16542 See `org-ctrl-c-ctrl-c-hook' for more information.")
16543 (defvar org-shiftmetadown-hook nil
16544 "Hook for functions attaching themselves to `M-S-down'.
16545 See `org-ctrl-c-ctrl-c-hook' for more information.")
16546 (defvar org-metareturn-hook nil
16547 "Hook for functions attaching themselves to `M-RET'.
16548 See `org-ctrl-c-ctrl-c-hook' for more information.")
16549 (defvar org-shiftup-hook nil
16550 "Hook for functions attaching themselves to `S-up'.
16551 See `org-ctrl-c-ctrl-c-hook' for more information.")
16552 (defvar org-shiftup-final-hook nil
16553 "Hook for functions attaching themselves to `S-up'.
16554 This one runs after all other options except shift-select have been excluded.
16555 See `org-ctrl-c-ctrl-c-hook' for more information.")
16556 (defvar org-shiftdown-hook nil
16557 "Hook for functions attaching themselves to `S-down'.
16558 See `org-ctrl-c-ctrl-c-hook' for more information.")
16559 (defvar org-shiftdown-final-hook nil
16560 "Hook for functions attaching themselves to `S-down'.
16561 This one runs after all other options except shift-select have been excluded.
16562 See `org-ctrl-c-ctrl-c-hook' for more information.")
16563 (defvar org-shiftleft-hook nil
16564 "Hook for functions attaching themselves to `S-left'.
16565 See `org-ctrl-c-ctrl-c-hook' for more information.")
16566 (defvar org-shiftleft-final-hook nil
16567 "Hook for functions attaching themselves to `S-left'.
16568 This one runs after all other options except shift-select have been excluded.
16569 See `org-ctrl-c-ctrl-c-hook' for more information.")
16570 (defvar org-shiftright-hook nil
16571 "Hook for functions attaching themselves to `S-right'.
16572 See `org-ctrl-c-ctrl-c-hook' for more information.")
16573 (defvar org-shiftright-final-hook nil
16574 "Hook for functions attaching themselves to `S-right'.
16575 This one runs after all other options except shift-select have been excluded.
16576 See `org-ctrl-c-ctrl-c-hook' for more information.")
16578 (defun org-modifier-cursor-error ()
16579 "Throw an error, a modified cursor command was applied in wrong context."
16580 (error "This command is active in special context like tables, headlines or items"))
16582 (defun org-shiftselect-error ()
16583 "Throw an error because Shift-Cursor command was applied in wrong context."
16584 (if (and (boundp 'shift-select-mode) shift-select-mode)
16585 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
16586 (error "This command works only in special context like headlines or timestamps")))
16588 (defun org-call-for-shift-select (cmd)
16589 (let ((this-command-keys-shift-translated t))
16590 (call-interactively cmd)))
16592 (defun org-shifttab (&optional arg)
16593 "Global visibility cycling or move to previous table field.
16594 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
16596 See the individual commands for more information."
16599 ((org-at-table-p) (call-interactively 'org-table-previous-field))
16601 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
16602 (message "Content view to level: %d" arg)
16603 (org-content (prefix-numeric-value arg2))
16604 (setq org-cycle-global-status 'overview)))
16605 (t (call-interactively 'org-global-cycle))))
16607 (defun org-shiftmetaleft ()
16608 "Promote subtree or delete table column.
16609 Calls `org-promote-subtree', `org-outdent-item',
16610 or `org-table-delete-column', depending on context.
16611 See the individual commands for more information."
16614 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
16615 ((org-at-table-p) (call-interactively 'org-table-delete-column))
16616 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
16617 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
16618 (t (org-modifier-cursor-error))))
16620 (defun org-shiftmetaright ()
16621 "Demote subtree or insert table column.
16622 Calls `org-demote-subtree', `org-indent-item',
16623 or `org-table-insert-column', depending on context.
16624 See the individual commands for more information."
16627 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
16628 ((org-at-table-p) (call-interactively 'org-table-insert-column))
16629 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
16630 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
16631 (t (org-modifier-cursor-error))))
16633 (defun org-shiftmetaup (&optional arg)
16634 "Move subtree up or kill table row.
16635 Calls `org-move-subtree-up' or `org-table-kill-row' or
16636 `org-move-item-up' depending on context. See the individual commands
16637 for more information."
16640 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16641 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16642 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16643 ((org-at-item-p) (call-interactively 'org-move-item-up))
16644 (t (org-modifier-cursor-error))))
16646 (defun org-shiftmetadown (&optional arg)
16647 "Move subtree down or insert table row.
16648 Calls `org-move-subtree-down' or `org-table-insert-row' or
16649 `org-move-item-down', depending on context. See the individual
16650 commands for more information."
16653 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16654 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16655 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16656 ((org-at-item-p) (call-interactively 'org-move-item-down))
16657 (t (org-modifier-cursor-error))))
16659 (defsubst org-hidden-tree-error ()
16661 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
16663 (defun org-metaleft (&optional arg)
16664 "Promote heading or move table column to left.
16665 Calls `org-do-promote' or `org-table-move-column', depending on context.
16666 With no specific context, calls the Emacs default `backward-word'.
16667 See the individual commands for more information."
16670 ((run-hook-with-args-until-success 'org-metaleft-hook))
16671 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16672 ((or (org-on-heading-p)
16673 (and (org-region-active-p)
16675 (goto-char (region-beginning))
16676 (org-on-heading-p))))
16677 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16678 (call-interactively 'org-do-promote))
16679 ((or (org-at-item-p)
16680 (and (org-region-active-p)
16682 (goto-char (region-beginning))
16684 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16685 (call-interactively 'org-outdent-item))
16686 (t (call-interactively 'backward-word))))
16688 (defun org-metaright (&optional arg)
16689 "Demote subtree or move table column to right.
16690 Calls `org-do-demote' or `org-table-move-column', depending on context.
16691 With no specific context, calls the Emacs default `forward-word'.
16692 See the individual commands for more information."
16695 ((run-hook-with-args-until-success 'org-metaright-hook))
16696 ((org-at-table-p) (call-interactively 'org-table-move-column))
16697 ((or (org-on-heading-p)
16698 (and (org-region-active-p)
16700 (goto-char (region-beginning))
16701 (org-on-heading-p))))
16702 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16703 (call-interactively 'org-do-demote))
16704 ((or (org-at-item-p)
16705 (and (org-region-active-p)
16707 (goto-char (region-beginning))
16709 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16710 (call-interactively 'org-indent-item))
16711 (t (call-interactively 'forward-word))))
16713 (defun org-check-for-hidden (what)
16714 "Check if there are hidden headlines/items in the current visual line.
16715 WHAT can be either `headlines' or `items'. If the current line is
16716 an outline or item heading and it has a folded subtree below it,
16717 this fucntion returns t, nil otherwise."
16719 ((eq what 'headlines) (concat "^" org-outline-regexp))
16720 ((eq what 'items) (concat "^" (org-item-re t)))
16721 (t (error "This should not happen"))))
16725 (unless (org-region-active-p)
16726 (setq beg (point-at-bol))
16727 (beginning-of-line 2)
16728 (while (and (not (eobp)) ;; this is like `next-line'
16729 (get-char-property (1- (point)) 'invisible))
16730 (beginning-of-line 2))
16733 (goto-char (point-at-eol))
16734 (setq end (max end (point)))
16735 (while (re-search-forward re end t)
16736 (if (get-char-property (match-beginning 0) 'invisible)
16740 (defun org-metaup (&optional arg)
16741 "Move subtree up or move table row up.
16742 Calls `org-move-subtree-up' or `org-table-move-row' or
16743 `org-move-item-up', depending on context. See the individual commands
16744 for more information."
16747 ((run-hook-with-args-until-success 'org-metaup-hook))
16748 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16749 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16750 ((org-at-item-p) (call-interactively 'org-move-item-up))
16751 (t (transpose-lines 1) (beginning-of-line -1))))
16753 (defun org-metadown (&optional arg)
16754 "Move subtree down or move table row down.
16755 Calls `org-move-subtree-down' or `org-table-move-row' or
16756 `org-move-item-down', depending on context. See the individual
16757 commands for more information."
16760 ((run-hook-with-args-until-success 'org-metadown-hook))
16761 ((org-at-table-p) (call-interactively 'org-table-move-row))
16762 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16763 ((org-at-item-p) (call-interactively 'org-move-item-down))
16764 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16766 (defun org-shiftup (&optional arg)
16767 "Increase item in timestamp or increase priority of current headline.
16768 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16769 depending on context. See the individual commands for more information."
16772 ((run-hook-with-args-until-success 'org-shiftup-hook))
16773 ((and org-support-shift-select (org-region-active-p))
16774 (org-call-for-shift-select 'previous-line))
16775 ((org-at-timestamp-p t)
16776 (call-interactively (if org-edit-timestamp-down-means-later
16777 'org-timestamp-down 'org-timestamp-up)))
16778 ((and (not (eq org-support-shift-select 'always))
16779 org-enable-priority-commands
16780 (org-on-heading-p))
16781 (call-interactively 'org-priority-up))
16782 ((and (not org-support-shift-select) (org-at-item-p))
16783 (call-interactively 'org-previous-item))
16784 ((org-clocktable-try-shift 'up arg))
16785 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
16786 (org-support-shift-select
16787 (org-call-for-shift-select 'previous-line))
16788 (t (org-shiftselect-error))))
16790 (defun org-shiftdown (&optional arg)
16791 "Decrease item in timestamp or decrease priority of current headline.
16792 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16793 depending on context. See the individual commands for more information."
16796 ((run-hook-with-args-until-success 'org-shiftdown-hook))
16797 ((and org-support-shift-select (org-region-active-p))
16798 (org-call-for-shift-select 'next-line))
16799 ((org-at-timestamp-p t)
16800 (call-interactively (if org-edit-timestamp-down-means-later
16801 'org-timestamp-up 'org-timestamp-down)))
16802 ((and (not (eq org-support-shift-select 'always))
16803 org-enable-priority-commands
16804 (org-on-heading-p))
16805 (call-interactively 'org-priority-down))
16806 ((and (not org-support-shift-select) (org-at-item-p))
16807 (call-interactively 'org-next-item))
16808 ((org-clocktable-try-shift 'down arg))
16809 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
16810 (org-support-shift-select
16811 (org-call-for-shift-select 'next-line))
16812 (t (org-shiftselect-error))))
16814 (defun org-shiftright (&optional arg)
16815 "Cycle the thing at point or in the current line, depending on context.
16816 Depending on context, this does one of the following:
16818 - switch a timestamp at point one day into the future
16819 - on a headline, switch to the next TODO keyword.
16820 - on an item, switch entire list to the next bullet type
16821 - on a property line, switch to the next allowed value
16822 - on a clocktable definition line, move time block into the future"
16825 ((run-hook-with-args-until-success 'org-shiftright-hook))
16826 ((and org-support-shift-select (org-region-active-p))
16827 (org-call-for-shift-select 'forward-char))
16828 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16829 ((and (not (eq org-support-shift-select 'always))
16830 (org-on-heading-p))
16831 (let ((org-inhibit-logging
16832 (not org-treat-S-cursor-todo-selection-as-state-change))
16833 (org-inhibit-blocking
16834 (not org-treat-S-cursor-todo-selection-as-state-change)))
16835 (org-call-with-arg 'org-todo 'right)))
16836 ((or (and org-support-shift-select
16837 (not (eq org-support-shift-select 'always))
16838 (org-at-item-bullet-p))
16839 (and (not org-support-shift-select) (org-at-item-p)))
16840 (org-call-with-arg 'org-cycle-list-bullet nil))
16841 ((and (not (eq org-support-shift-select 'always))
16842 (org-at-property-p))
16843 (call-interactively 'org-property-next-allowed-value))
16844 ((org-clocktable-try-shift 'right arg))
16845 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
16846 (org-support-shift-select
16847 (org-call-for-shift-select 'forward-char))
16848 (t (org-shiftselect-error))))
16850 (defun org-shiftleft (&optional arg)
16851 "Cycle the thing at point or in the current line, depending on context.
16852 Depending on context, this does one of the following:
16854 - switch a timestamp at point one day into the past
16855 - on a headline, switch to the previous TODO keyword.
16856 - on an item, switch entire list to the previous bullet type
16857 - on a property line, switch to the previous allowed value
16858 - on a clocktable definition line, move time block into the past"
16861 ((run-hook-with-args-until-success 'org-shiftleft-hook))
16862 ((and org-support-shift-select (org-region-active-p))
16863 (org-call-for-shift-select 'backward-char))
16864 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16865 ((and (not (eq org-support-shift-select 'always))
16866 (org-on-heading-p))
16867 (let ((org-inhibit-logging
16868 (not org-treat-S-cursor-todo-selection-as-state-change))
16869 (org-inhibit-blocking
16870 (not org-treat-S-cursor-todo-selection-as-state-change)))
16871 (org-call-with-arg 'org-todo 'left)))
16872 ((or (and org-support-shift-select
16873 (not (eq org-support-shift-select 'always))
16874 (org-at-item-bullet-p))
16875 (and (not org-support-shift-select) (org-at-item-p)))
16876 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16877 ((and (not (eq org-support-shift-select 'always))
16878 (org-at-property-p))
16879 (call-interactively 'org-property-previous-allowed-value))
16880 ((org-clocktable-try-shift 'left arg))
16881 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
16882 (org-support-shift-select
16883 (org-call-for-shift-select 'backward-char))
16884 (t (org-shiftselect-error))))
16886 (defun org-shiftcontrolright ()
16887 "Switch to next TODO set."
16890 ((and org-support-shift-select (org-region-active-p))
16891 (org-call-for-shift-select 'forward-word))
16892 ((and (not (eq org-support-shift-select 'always))
16893 (org-on-heading-p))
16894 (org-call-with-arg 'org-todo 'nextset))
16895 (org-support-shift-select
16896 (org-call-for-shift-select 'forward-word))
16897 (t (org-shiftselect-error))))
16899 (defun org-shiftcontrolleft ()
16900 "Switch to previous TODO set."
16903 ((and org-support-shift-select (org-region-active-p))
16904 (org-call-for-shift-select 'backward-word))
16905 ((and (not (eq org-support-shift-select 'always))
16906 (org-on-heading-p))
16907 (org-call-with-arg 'org-todo 'previousset))
16908 (org-support-shift-select
16909 (org-call-for-shift-select 'backward-word))
16910 (t (org-shiftselect-error))))
16912 (defun org-ctrl-c-ret ()
16913 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16916 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16917 (t (call-interactively 'org-insert-heading))))
16919 (defun org-copy-special ()
16920 "Copy region in table or copy current subtree.
16921 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16922 See the individual commands for more information."
16924 (call-interactively
16925 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16927 (defun org-cut-special ()
16928 "Cut region in table or cut current subtree.
16929 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16930 See the individual commands for more information."
16932 (call-interactively
16933 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16935 (defun org-paste-special (arg)
16936 "Paste rectangular region into table, or past subtree relative to level.
16937 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16938 See the individual commands for more information."
16940 (if (org-at-table-p)
16941 (org-table-paste-rectangle)
16942 (org-paste-subtree arg)))
16944 (defun org-edit-special (&optional arg)
16945 "Call a special editor for the stuff at point.
16946 When at a table, call the formula editor with `org-table-edit-formulas'.
16947 When at the first line of an src example, call `org-edit-src-code'.
16948 When in an #+include line, visit the include file. Otherwise call
16949 `ffap' to visit the file at point."
16951 ;; possibly prep session before editing source
16953 (let* ((info (org-babel-get-src-block-info))
16954 (lang (nth 0 info))
16955 (params (nth 2 info))
16956 (session (cdr (assoc :session params))))
16957 (when (and info session) ;; we are in a source-code block with a session
16959 (intern (concat "org-babel-prep-session:" lang)) session params))))
16960 (cond ;; proceed with `org-edit-special'
16962 (beginning-of-line 1)
16963 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16964 (find-file (org-trim (match-string 1))))
16965 ((org-edit-src-code))
16966 ((org-edit-fixed-width-region))
16967 ((org-at-table.el-p)
16968 (org-edit-src-code))
16970 (call-interactively 'org-table-edit-formulas))
16971 (t (call-interactively 'ffap))))
16974 (defun org-ctrl-c-ctrl-c (&optional arg)
16975 "Set tags in headline, or update according to changed information at point.
16977 This command does many different things, depending on context:
16979 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
16980 this is what we do.
16982 - If the cursor is on a statistics cookie, update it.
16984 - If the cursor is in a headline, prompt for tags and insert them
16985 into the current line, aligned to `org-tags-column'. When called
16986 with prefix arg, realign all tags in the current buffer.
16988 - If the cursor is in one of the special #+KEYWORD lines, this
16989 triggers scanning the buffer for these lines and updating the
16992 - If the cursor is inside a table, realign the table. This command
16993 works even if the automatic table editor has been turned off.
16995 - If the cursor is on a #+TBLFM line, re-apply the formulas to
16998 - If the cursor is at a footnote reference or definition, jump to
16999 the corresponding definition or references, respectively.
17001 - If the cursor is a the beginning of a dynamic block, update it.
17003 - If the current buffer is a remember buffer, close note and file
17004 it. A prefix argument of 1 files to the default location
17005 without further interaction. A prefix argument of 2 files to
17006 the currently clocking task.
17008 - If the cursor is on a <<<target>>>, update radio targets and corresponding
17009 links in this buffer.
17011 - If the cursor is on a numbered item in a plain list, renumber the
17014 - If the cursor is on a checkbox, toggle it."
17016 (let ((org-enable-table-editor t))
17018 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
17019 org-occur-highlights
17020 org-latex-fragment-image-overlays)
17021 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
17022 (org-remove-occur-highlights)
17023 (org-remove-latex-fragment-image-overlays)
17024 (message "Temporary highlights/overlays removed from current buffer"))
17025 ((and (local-variable-p 'org-finish-function (current-buffer))
17026 (fboundp org-finish-function))
17027 (funcall org-finish-function))
17028 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
17029 ((or (looking-at org-property-start-re)
17030 (org-at-property-p))
17031 (call-interactively 'org-property-action))
17032 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
17033 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
17034 (or (org-on-heading-p) (org-at-item-p)))
17035 (call-interactively 'org-update-statistics-cookies))
17036 ((org-on-heading-p) (call-interactively 'org-set-tags))
17037 ((org-at-table.el-p)
17038 (message "Use C-c ' to edit table.el tables"))
17040 (org-table-maybe-eval-formula)
17042 (call-interactively 'org-table-recalculate)
17043 (org-table-maybe-recalculate-line))
17044 (call-interactively 'org-table-align))
17045 ((or (org-footnote-at-reference-p)
17046 (org-footnote-at-definition-p))
17047 (call-interactively 'org-footnote-action))
17048 ((org-at-item-checkbox-p)
17049 (call-interactively 'org-toggle-checkbox))
17052 (call-interactively 'org-toggle-checkbox)
17053 (call-interactively 'org-maybe-renumber-ordered-list)))
17054 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
17056 (beginning-of-line 1)
17057 (save-excursion (org-update-dblock)))
17059 (beginning-of-line 1)
17060 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
17062 ((equal (match-string 1) "TBLFM")
17063 ;; Recalculate the table before this line
17065 (beginning-of-line 1)
17066 (skip-chars-backward " \r\n\t")
17067 (if (org-at-table-p)
17068 (org-call-with-arg 'org-table-recalculate (or arg t)))))
17070 (let ((org-inhibit-startup-visibility-stuff t)
17071 (org-startup-align-all-tables nil))
17072 (org-save-outline-visibility 'use-markers (org-mode-restart)))
17073 (message "Local setup has been refreshed"))))
17074 ((org-clock-update-time-maybe))
17075 (t (error "C-c C-c can do nothing useful at this location")))))
17077 (defun org-mode-restart ()
17078 "Restart Org-mode, to scan again for special lines.
17079 Also updates the keyword regular expressions."
17082 (message "Org-mode restarted"))
17084 (defun org-kill-note-or-show-branches ()
17085 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
17087 (if (not org-finish-function)
17090 (call-interactively 'show-branches))
17091 (let ((org-note-abort t))
17092 (funcall org-finish-function))))
17094 (defun org-return (&optional indent)
17095 "Goto next table row or insert a newline.
17096 Calls `org-table-next-row' or `newline', depending on context.
17097 See the individual commands for more information."
17100 ((bobp) (if indent (newline-and-indent) (newline)))
17102 (org-table-justify-field-maybe)
17103 (call-interactively 'org-table-next-row))
17104 ((and org-return-follows-link
17105 (eq (get-text-property (point) 'face) 'org-link))
17106 (call-interactively 'org-open-at-point))
17107 ((and (org-at-heading-p)
17109 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
17113 (t (if indent (newline-and-indent) (newline)))))
17115 (defun org-return-indent ()
17116 "Goto next table row or insert a newline and indent.
17117 Calls `org-table-next-row' or `newline-and-indent', depending on
17118 context. See the individual commands for more information."
17122 (defun org-ctrl-c-star ()
17123 "Compute table, or change heading status of lines.
17124 Calls `org-table-recalculate' or `org-toggle-heading',
17125 depending on context."
17129 (call-interactively 'org-table-recalculate))
17131 ;; Convert all lines in region to list items
17132 (call-interactively 'org-toggle-heading))))
17134 (defun org-ctrl-c-minus ()
17135 "Insert separator line in table or modify bullet status of line.
17136 Also turns a plain line or a region of lines into list items.
17137 Calls `org-table-insert-hline', `org-toggle-item', or
17138 `org-cycle-list-bullet', depending on context."
17142 (call-interactively 'org-table-insert-hline))
17143 ((org-region-active-p)
17144 (call-interactively 'org-toggle-item))
17146 (call-interactively 'org-cycle-list-bullet))
17148 (call-interactively 'org-toggle-item))))
17150 (defun org-toggle-item ()
17151 "Convert headings or normal lines to items, items to normal lines.
17152 If there is no active region, only the current line is considered.
17154 If the first line in the region is a headline, convert all headlines to items.
17156 If the first line in the region is an item, convert all items to normal lines.
17158 If the first line is normal text, add an item bullet to each line."
17160 (let (l2 l beg end)
17161 (if (org-region-active-p)
17162 (setq beg (region-beginning) end (region-end))
17163 (setq beg (point-at-bol)
17164 end (min (1+ (point-at-eol)) (point-max))))
17167 (setq l2 (org-current-line))
17169 (beginning-of-line 1)
17170 (setq l (1- (org-current-line)))
17171 (if (org-at-item-p)
17172 ;; We already have items, de-itemize
17173 (while (< (setq l (1+ l)) l2)
17174 (when (org-at-item-p)
17175 (goto-char (match-beginning 2))
17176 (delete-region (match-beginning 2) (match-end 2))
17177 (and (looking-at "[ \t]+") (replace-match "")))
17178 (beginning-of-line 2))
17179 (if (org-on-heading-p)
17180 ;; Headings, convert to items
17181 (while (< (setq l (1+ l)) l2)
17182 (if (looking-at org-outline-regexp)
17183 (replace-match "- " t t))
17184 (beginning-of-line 2))
17185 ;; normal lines, turn them into items
17186 (while (< (setq l (1+ l)) l2)
17187 (unless (org-at-item-p)
17188 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17189 (replace-match "\\1- \\2")))
17190 (beginning-of-line 2)))))))
17192 (defun org-toggle-heading (&optional nstars)
17193 "Convert headings to normal text, or items or text to headings.
17194 If there is no active region, only the current line is considered.
17196 If the first line is a heading, remove the stars from all headlines
17199 If the first line is a plain list item, turn all plain list items
17202 If the first line is a normal line, turn each and every line in the
17203 region into a heading.
17205 When converting a line into a heading, the number of stars is chosen
17206 such that the lines become children of the current entry. However,
17207 when a prefix argument is given, its value determines the number of
17210 (let (l2 l itemp beg end)
17211 (if (org-region-active-p)
17212 (setq beg (region-beginning) end (region-end))
17213 (setq beg (point-at-bol)
17214 end (min (1+ (point-at-eol)) (point-max))))
17217 (setq l2 (org-current-line))
17219 (beginning-of-line 1)
17220 (setq l (1- (org-current-line)))
17221 (if (org-on-heading-p)
17222 ;; We already have headlines, de-star them
17223 (while (< (setq l (1+ l)) l2)
17224 (when (org-on-heading-p t)
17225 (and (looking-at outline-regexp) (replace-match "")))
17226 (beginning-of-line 2))
17227 (setq itemp (org-at-item-p))
17230 (make-string (prefix-numeric-value current-prefix-arg)
17233 (if (re-search-backward org-complex-heading-regexp nil t)
17234 (match-string 1) ""))))
17235 (add-stars (cond (nstars "")
17236 ((equal stars "") "*")
17237 (org-odd-levels-only "**")
17239 (rpl (concat stars add-stars " ")))
17240 (while (< (setq l (1+ l)) l2)
17242 (and (org-at-item-p) (replace-match rpl t t))
17243 (unless (org-on-heading-p)
17244 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17245 (replace-match (concat rpl (match-string 2))))))
17246 (beginning-of-line 2)))))))
17248 (defun org-meta-return (&optional arg)
17249 "Insert a new heading or wrap a region in a table.
17250 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
17251 See the individual commands for more information."
17254 ((run-hook-with-args-until-success 'org-metareturn-hook))
17256 (call-interactively 'org-table-wrap-region))
17257 (t (call-interactively 'org-insert-heading))))
17261 ;; Define the Org-mode menus
17262 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
17264 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
17265 ["Next Field" org-cycle (org-at-table-p)]
17266 ["Previous Field" org-shifttab (org-at-table-p)]
17267 ["Next Row" org-return (org-at-table-p)]
17269 ["Blank Field" org-table-blank-field (org-at-table-p)]
17270 ["Edit Field" org-table-edit-field (org-at-table-p)]
17271 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
17274 ["Move Column Left" org-metaleft (org-at-table-p)]
17275 ["Move Column Right" org-metaright (org-at-table-p)]
17276 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
17277 ["Insert Column" org-shiftmetaright (org-at-table-p)])
17279 ["Move Row Up" org-metaup (org-at-table-p)]
17280 ["Move Row Down" org-metadown (org-at-table-p)]
17281 ["Delete Row" org-shiftmetaup (org-at-table-p)]
17282 ["Insert Row" org-shiftmetadown (org-at-table-p)]
17283 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
17285 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
17287 ["Copy Rectangle" org-copy-special (org-at-table-p)]
17288 ["Cut Rectangle" org-cut-special (org-at-table-p)]
17289 ["Paste Rectangle" org-paste-special (org-at-table-p)]
17290 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
17293 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
17294 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
17295 ["Edit Formulas" org-edit-special (org-at-table-p)]
17297 ["Recalculate line" org-table-recalculate (org-at-table-p)]
17298 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
17299 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
17301 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
17303 ["Sum Column/Rectangle" org-table-sum
17304 (or (org-at-table-p) (org-region-active-p))]
17305 ["Which Column?" org-table-current-column (org-at-table-p)])
17307 org-table-toggle-formula-debugger
17308 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
17309 ["Show Col/Row Numbers"
17310 org-table-toggle-coordinate-overlays
17312 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
17314 ["Create" org-table-create (and (not (org-at-table-p))
17315 org-enable-table-editor)]
17316 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
17317 ["Import from File" org-table-import (not (org-at-table-p))]
17318 ["Export to File" org-table-export (org-at-table-p)]
17320 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
17322 (easy-menu-define org-org-menu org-mode-map "Org menu"
17325 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
17326 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
17327 ["Sparse Tree..." org-sparse-tree t]
17328 ["Reveal Context" org-reveal t]
17329 ["Show All" show-all t]
17331 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
17333 ["New Heading" org-insert-heading t]
17334 ("Navigate Headings"
17335 ["Up" outline-up-heading t]
17336 ["Next" outline-next-visible-heading t]
17337 ["Previous" outline-previous-visible-heading t]
17338 ["Next Same Level" outline-forward-same-level t]
17339 ["Previous Same Level" outline-backward-same-level t]
17341 ["Jump" org-goto t])
17343 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
17344 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
17346 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
17347 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
17348 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
17350 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
17352 ["Promote Heading" org-metaleft (not (org-at-table-p))]
17353 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
17354 ["Demote Heading" org-metaright (not (org-at-table-p))]
17355 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
17357 ["Sort Region/Children" org-sort (not (org-at-table-p))]
17359 ["Convert to odd levels" org-convert-to-odd-levels t]
17360 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
17362 ["Emphasis..." org-emphasize t]
17363 ["Edit Source Example" org-edit-special t]
17365 ["Footnote new/jump" org-footnote-action t]
17366 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
17368 ["Archive (default method)" org-archive-subtree-default t]
17370 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
17371 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
17372 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
17376 ["Store Link (Global)" org-store-link t]
17377 ["Find existing link to here" org-occur-link-in-agenda-files t]
17378 ["Insert Link" org-insert-link t]
17379 ["Follow Link" org-open-at-point t]
17381 ["Next link" org-next-link t]
17382 ["Previous link" org-previous-link t]
17384 ["Descriptive Links"
17385 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
17387 :selected (member '(org-link) buffer-invisibility-spec)]
17390 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
17392 :selected (not (member '(org-link) buffer-invisibility-spec))])
17395 ["TODO/DONE/-" org-todo t]
17397 ["Next keyword" org-shiftright (org-on-heading-p)]
17398 ["Previous keyword" org-shiftleft (org-on-heading-p)]
17399 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
17400 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
17401 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
17402 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
17403 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
17405 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
17406 :selected org-enforce-todo-dependencies :style toggle :active t]
17407 "Settings for tree at point"
17408 ["Do Children sequentially" org-toggle-ordered-property :style radio
17409 :selected (ignore-errors (org-entry-get nil "ORDERED"))
17410 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17411 ["Do Children parallel" org-toggle-ordered-property :style radio
17412 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
17413 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17415 ["Set Priority" org-priority t]
17416 ["Priority Up" org-shiftup t]
17417 ["Priority Down" org-shiftdown t]
17419 ["Get news from all feeds" org-feed-update-all t]
17420 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
17421 ["Customize feeds" (customize-variable 'org-feed-alist) t])
17422 ("TAGS and Properties"
17423 ["Set Tags" org-set-tags-command t]
17424 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
17426 ["Set property" org-set-property t]
17427 ["Column view of properties" org-columns t]
17428 ["Insert Column View DBlock" org-insert-columns-dblock t])
17429 ("Dates and Scheduling"
17430 ["Timestamp" org-time-stamp t]
17431 ["Timestamp (inactive)" org-time-stamp-inactive t]
17433 ["1 Day Later" org-shiftright t]
17434 ["1 Day Earlier" org-shiftleft t]
17435 ["1 ... Later" org-shiftup t]
17436 ["1 ... Earlier" org-shiftdown t])
17437 ["Compute Time Range" org-evaluate-time-range t]
17438 ["Schedule Item" org-schedule t]
17439 ["Deadline" org-deadline t]
17441 ["Custom time format" org-toggle-time-stamp-overlays
17442 :style radio :selected org-display-custom-times]
17444 ["Goto Calendar" org-goto-calendar t]
17445 ["Date from Calendar" org-date-from-calendar t]
17447 ["Start/Restart Timer" org-timer-start t]
17448 ["Pause/Continue Timer" org-timer-pause-or-continue t]
17449 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
17450 ["Insert Timer String" org-timer t]
17451 ["Insert Timer Item" org-timer-item t])
17453 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
17454 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
17455 ["Clock out" org-clock-out t]
17456 ["Clock cancel" org-clock-cancel t]
17458 ["Mark as default task" org-clock-mark-default-task t]
17459 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
17460 ["Goto running clock" org-clock-goto t]
17462 ["Display times" org-clock-display t]
17463 ["Create clock table" org-clock-report t]
17465 ["Record DONE time"
17466 (progn (setq org-log-done (not org-log-done))
17467 (message "Switching to %s will %s record a timestamp"
17468 (car org-done-keywords)
17469 (if org-log-done "automatically" "not")))
17470 :style toggle :selected org-log-done])
17472 ["Agenda Command..." org-agenda t]
17473 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
17474 ("File List for Agenda")
17475 ("Special views current file"
17476 ["TODO Tree" org-show-todo-tree t]
17477 ["Check Deadlines" org-check-deadlines t]
17478 ["Timeline" org-timeline t]
17479 ["Tags/Property tree" org-match-sparse-tree t])
17481 ["Export/Publish..." org-export t]
17483 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
17484 :selected org-cdlatex-mode]
17485 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
17486 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
17487 ["Modify math symbol" org-cdlatex-math-modify
17488 (org-inside-LaTeX-fragment-p)]
17489 ["Insert citation" org-reftex-citation t]
17491 ["Export LaTeX fragments as images"
17492 (if (featurep 'org-exp)
17493 (setq org-export-with-LaTeX-fragments
17494 (not org-export-with-LaTeX-fragments))
17495 (require 'org-exp))
17496 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
17497 org-export-with-LaTeX-fragments)]
17499 ["Template for BEAMER" org-insert-beamer-options-template t])
17502 ["Push Files and Views" org-mobile-push t]
17503 ["Get Captured and Flagged" org-mobile-pull t]
17504 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
17506 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
17509 ["Show Version" org-version t]
17510 ["Info Documentation" org-info t])
17512 ["Browse Org Group" org-customize t]
17514 ["Expand This Menu" org-create-customize-menu
17515 (fboundp 'customize-menu-create)])
17516 ["Send bug report" org-submit-bug-report t]
17519 ["Refresh setup current buffer" org-mode-restart t]
17520 ["Reload Org (after update)" org-reload t]
17521 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
17524 (defun org-info (&optional node)
17525 "Read documentation for Org-mode in the info system.
17526 With optional NODE, go directly to that node."
17528 (info (format "(org)%s" (or node ""))))
17531 (defun org-submit-bug-report ()
17532 "Submit a bug report on Org-mode via mail.
17534 Don't hesitate to report any problems or inaccurate documentation.
17536 If you don't have setup sending mail from (X)Emacs, please copy the
17537 output buffer into your mail program, as it gives us important
17538 information about your Org-mode version and configuration."
17540 (require 'reporter)
17541 (org-load-modules-maybe)
17542 (org-require-autoloaded-modules)
17543 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
17544 (reporter-submit-bug-report
17545 "emacs-orgmode@gnu.org"
17548 (save-window-excursion
17549 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
17550 (delete-other-windows)
17552 (insert "You are about to submit a bug report to the Org-mode mailing list.
17554 We would like to add your full Org-mode and Outline configuration to the
17555 bug report. This greatly simplifies the work of the maintainer and
17556 other experts on the mailing list.
17558 HOWEVER, some variables you have customized may contain private
17559 information. The names of customers, colleagues, or friends, might
17560 appear in the form of file names, tags, todo states, or search strings.
17561 If you answer yes to the prompt, you might want to check and remove
17562 such private information before sending the email.")
17563 (add-text-properties (point-min) (point-max) '(face org-warning))
17564 (when (yes-or-no-p "Include your Org-mode configuration ")
17568 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
17569 (or (and (symbol-value v)
17570 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
17572 (get v 'custom-type) (get v 'standard-value)
17573 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
17575 (kill-buffer (get-buffer "*Warn about privacy*"))
17578 "Remember to cover the basics, that is, what you expected to happen and
17579 what in fact did happen. You don't know how to make a good report? See
17581 http://orgmode.org/manual/Feedback.html#Feedback
17583 Your bug report will be posted to the Org-mode mailing list.
17584 ------------------------------------------------------------------------")
17586 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
17587 (replace-match "\\1Bug: \\3 [\\2]")))))
17590 (defun org-install-agenda-files-menu ()
17591 (let ((bl (buffer-list)))
17594 (set-buffer (pop bl))
17595 (if (org-mode-p) (setq bl nil)))
17598 '("Org") "File List for Agenda"
17601 ["Edit File List" (org-edit-agenda-file-list) t]
17602 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
17603 ["Remove Current File from List" org-remove-file t]
17604 ["Cycle through agenda files" org-cycle-agenda-files t]
17605 ["Occur in all agenda files" org-occur-in-agenda-files t]
17607 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
17612 (defun org-require-autoloaded-modules ()
17615 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
17616 org-docbook org-exp org-html org-icalendar
17618 org-publish org-remember org-table
17619 org-timer org-xoxo)))
17622 (defun org-reload (&optional uncompiled)
17623 "Reload all org lisp files.
17624 With prefix arg UNCOMPILED, load the uncompiled versions."
17626 (require 'find-func)
17627 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
17628 (dir-org (file-name-directory (org-find-library-name "org")))
17629 (dir-org-contrib (ignore-errors
17630 (file-name-directory
17631 (org-find-library-name "org-contribdir"))))
17633 (append (directory-files dir-org t file-re)
17634 (and dir-org-contrib
17635 (directory-files dir-org-contrib t file-re))))
17636 (remove-re (concat (if (featurep 'xemacs)
17637 "org-colview" "org-colview-xemacs")
17639 (setq files (mapcar 'file-name-sans-extension files))
17640 (setq files (mapcar
17641 (lambda (x) (if (string-match remove-re x) nil x))
17643 (setq files (delq nil files))
17646 (when (featurep (intern (file-name-nondirectory f)))
17647 (if (and (not uncompiled)
17648 (file-exists-p (concat f ".elc")))
17649 (load (concat f ".elc") nil nil t)
17650 (load (concat f ".el") nil nil t))))
17655 (defun org-customize ()
17656 "Call the customize function with org as argument."
17658 (org-load-modules-maybe)
17659 (org-require-autoloaded-modules)
17660 (customize-browse 'org))
17662 (defun org-create-customize-menu ()
17663 "Create a full customization menu for Org-mode, insert it into the menu."
17665 (org-load-modules-maybe)
17666 (org-require-autoloaded-modules)
17667 (if (fboundp 'customize-menu-create)
17670 '("Org") "Customize"
17671 `(["Browse Org group" org-customize t]
17673 ,(customize-menu-create 'org)
17674 ["Set" Custom-set t]
17675 ["Save" Custom-save t]
17676 ["Reset to Current" Custom-reset-current t]
17677 ["Reset to Saved" Custom-reset-saved t]
17678 ["Reset to Standard Settings" Custom-reset-standard t]))
17679 (message "\"Org\"-menu now contains full customization menu"))
17680 (error "Cannot expand menu (outdated version of cus-edit.el)")))
17682 ;;;; Miscellaneous stuff
17684 ;;; Generally useful functions
17686 (defun org-get-at-bol (property)
17687 "Get text property PROPERTY at beginning of line."
17688 (get-text-property (point-at-bol) property))
17690 (defun org-find-text-property-in-string (prop s)
17691 "Return the first non-nil value of property PROP in string S."
17692 (or (get-text-property 0 prop s)
17693 (get-text-property (or (next-single-property-change 0 prop s) 0)
17696 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17697 "Display the given MESSAGE as a warning."
17698 (if (fboundp 'display-warning)
17699 (display-warning 'org message
17700 (if (featurep 'xemacs) 'warning :warning))
17701 (let ((buf (get-buffer-create "*Org warnings*")))
17702 (with-current-buffer buf
17703 (goto-char (point-max))
17704 (insert "Warning (Org): " message)
17707 (display-buffer buf)
17710 (defun org-in-commented-line ()
17711 "Is point in a line starting with `#'?"
17712 (equal (char-after (point-at-bol)) ?#))
17714 (defun org-in-indented-comment-line ()
17715 "Is point in a line starting with `#' after some white space?"
17718 (goto-char (point-at-bol))
17719 (looking-at "[ \t]*#"))))
17721 (defun org-in-verbatim-emphasis ()
17723 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17725 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17726 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17727 (if (and marker (marker-buffer marker)
17728 (buffer-live-p (marker-buffer marker)))
17730 (switch-to-buffer (marker-buffer marker))
17731 (if (or (> marker (point-max)) (< marker (point-min)))
17734 (org-show-context 'org-goto))
17736 (bookmark-jump bookmark)
17737 (error "Cannot find location"))))
17739 (defun org-quote-csv-field (s)
17740 "Quote field for inclusion in CSV material."
17741 (if (string-match "[\",]" s)
17742 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17745 (defun org-plist-delete (plist property)
17746 "Delete PROPERTY from PLIST.
17747 This is in contrast to merely setting it to 0."
17750 (if (not (eq property (car plist)))
17751 (setq p (plist-put p (car plist) (nth 1 plist))))
17752 (setq plist (cddr plist)))
17755 (defun org-force-self-insert (N)
17756 "Needed to enforce self-insert under remapping."
17758 (self-insert-command N))
17760 (defun org-string-width (s)
17761 "Compute width of string, ignoring invisible characters.
17762 This ignores character with invisibility property `org-link', and also
17763 characters with property `org-cwidth', because these will become invisible
17764 upon the next fontification round."
17766 (when (or (eq t buffer-invisibility-spec)
17767 (assq 'org-link buffer-invisibility-spec))
17768 (while (setq b (text-property-any 0 (length s)
17769 'invisible 'org-link s))
17770 (setq s (concat (substring s 0 b)
17771 (substring s (or (next-single-property-change
17772 b 'invisible s) (length s)))))))
17773 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17774 (setq s (concat (substring s 0 b)
17775 (substring s (or (next-single-property-change
17776 b 'org-cwidth s) (length s))))))
17777 (setq l (string-width s) b -1)
17778 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17779 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17782 (defun org-get-indentation (&optional line)
17783 "Get the indentation of the current line, interpreting tabs.
17784 When LINE is given, assume it represents a line and compute its indentation."
17786 (if (string-match "^ *" (org-remove-tabs line))
17789 (beginning-of-line 1)
17790 (skip-chars-forward " \t")
17791 (current-column))))
17793 (defun org-remove-tabs (s &optional width)
17794 "Replace tabulators in S with spaces.
17795 Assumes that s is a single line, starting in column 0."
17796 (setq width (or width tab-width))
17797 (while (string-match "\t" s)
17798 (setq s (replace-match
17800 (- (* width (/ (+ (match-beginning 0) width) width))
17801 (match-beginning 0)) ?\ )
17805 (defun org-fix-indentation (line ind)
17806 "Fix indentation in LINE.
17807 IND is a cons cell with target and minimum indentation.
17808 If the current indentation in LINE is smaller than the minimum,
17809 leave it alone. If it is larger than ind, set it to the target."
17810 (let* ((l (org-remove-tabs line))
17811 (i (org-get-indentation l))
17812 (i1 (car ind)) (i2 (cdr ind)))
17813 (if (>= i i2) (setq l (substring line i2)))
17815 (concat (make-string i1 ?\ ) l)
17818 (defun org-remove-indentation (code &optional n)
17819 "Remove the maximum common indentation from the lines in CODE.
17820 N may optionally be the number of spaces to remove."
17823 (org-do-remove-indentation n)
17826 (defun org-do-remove-indentation (&optional n)
17827 "Remove the maximum common indentation from the buffer."
17828 (untabify (point-min) (point-max))
17829 (let ((min 10000) re)
17832 (goto-char (point-min))
17833 (while (re-search-forward "^ *[^ \n]" nil t)
17834 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17835 (unless (or (= min 0) (= min 10000))
17836 (setq re (format "^ \\{%d\\}" min))
17837 (goto-char (point-min))
17838 (while (re-search-forward re nil t)
17843 (defun org-fill-template (template alist)
17844 "Find each %key of ALIST in TEMPLATE and replace it."
17845 (let ((case-fold-search nil)
17847 (setq alist (sort (copy-sequence alist)
17848 (lambda (a b) (< (length (car a)) (length (car b))))))
17849 (while (setq entry (pop alist))
17851 (replace-regexp-in-string
17852 (concat "%" (regexp-quote (car entry)))
17853 (cdr entry) template t t)))
17856 (defun org-base-buffer (buffer)
17857 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17860 (or (buffer-base-buffer buffer)
17863 (defun org-trim (s)
17864 "Remove whitespace at beginning and end of string."
17865 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17866 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17869 (defun org-wrap (string &optional width lines)
17870 "Wrap string to either a number of lines, or a width in characters.
17871 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17872 that costs. If there is a word longer than WIDTH, the text is actually
17873 wrapped to the length of that word.
17874 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17875 many lines, whatever width that takes.
17876 The return value is a list of lines, without newlines at the end."
17877 (let* ((words (org-split-string string "[ \t\n]+"))
17878 (maxword (apply 'max (mapcar 'org-string-width words)))
17881 (org-do-wrap words (max maxword width)))
17884 (setq ll (org-do-wrap words maxword))
17885 (if (<= (length ll) lines)
17888 (while (> (length ll) lines)
17890 (setq ll (org-do-wrap words w)))
17892 (t (error "Cannot wrap this")))))
17894 (defun org-do-wrap (words width)
17895 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17898 (setq line (pop words))
17899 (while (and words (< (+ (length line) (length (car words))) width))
17900 (setq line (concat line " " (pop words))))
17901 (setq lines (push line lines)))
17904 (defun org-split-string (string &optional separators)
17905 "Splits STRING into substrings at SEPARATORS.
17906 No empty strings are returned if there are matches at the beginning
17907 and end of string."
17908 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17912 (while (and (string-match rexp string
17914 (= start (match-beginning 0))
17915 (< start (length string)))
17917 (< (match-beginning 0) (length string)))
17919 (or (eq (match-beginning 0) 0)
17920 (and (eq (match-beginning 0) (match-end 0))
17921 (eq (match-beginning 0) start))
17923 (cons (substring string start (match-beginning 0))
17925 (setq start (match-end 0)))
17926 (or (eq start (length string))
17928 (cons (substring string start)
17932 (defun org-quote-vert (s)
17933 "Replace \"|\" with \"\\vert\"."
17934 (while (string-match "|" s)
17935 (setq s (replace-match "\\vert" t t s)))
17938 (defun org-uuidgen-p (s)
17939 "Is S an ID created by UUIDGEN?"
17940 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17942 (defun org-context ()
17943 "Return a list of contexts of the current cursor position.
17944 If several contexts apply, all are returned.
17945 Each context entry is a list with a symbol naming the context, and
17946 two positions indicating start and end of the context. Possible
17949 :headline anywhere in a headline
17950 :headline-stars on the leading stars in a headline
17951 :todo-keyword on a TODO keyword (including DONE) in a headline
17952 :tags on the TAGS in a headline
17953 :priority on the priority cookie in a headline
17954 :item on the first line of a plain list item
17955 :item-bullet on the bullet/number of a plain list item
17956 :checkbox on the checkbox in a plain list item
17957 :table in an org-mode table
17958 :table-special on a special filed in a table
17959 :table-table in a table.el table
17960 :link on a hyperlink
17961 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
17962 :target on a <<target>>
17963 :radio-target on a <<<radio-target>>>
17964 :latex-fragment on a LaTeX fragment
17965 :latex-preview on a LaTeX fragment with overlayed preview image
17967 This function expects the position to be visible because it uses font-lock
17968 faces as a help to recognize the following contexts: :table-special, :link,
17970 (let* ((f (get-text-property (point) 'face))
17971 (faces (if (listp f) f (list f)))
17972 (p (point)) clist o)
17973 ;; First the large context
17975 ((org-on-heading-p t)
17976 (push (list :headline (point-at-bol) (point-at-eol)) clist)
17978 (beginning-of-line 1)
17979 (looking-at org-todo-line-tags-regexp))
17980 (push (org-point-in-group p 1 :headline-stars) clist)
17981 (push (org-point-in-group p 2 :todo-keyword) clist)
17982 (push (org-point-in-group p 4 :tags) clist))
17984 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
17985 (if (looking-at "\\[#[A-Z0-9]\\]")
17986 (push (org-point-in-group p 0 :priority) clist)))
17989 (push (org-point-in-group p 2 :item-bullet) clist)
17990 (push (list :item (point-at-bol)
17991 (save-excursion (org-end-of-item) (point)))
17993 (and (org-at-item-checkbox-p)
17994 (push (org-point-in-group p 0 :checkbox) clist)))
17997 (push (list :table (org-table-begin) (org-table-end)) clist)
17998 (if (memq 'org-formula faces)
17999 (push (list :table-special
18000 (previous-single-property-change p 'face)
18001 (next-single-property-change p 'face)) clist)))
18002 ((org-at-table-p 'any)
18003 (push (list :table-table) clist)))
18006 ;; Now the small context
18008 ((org-at-timestamp-p)
18009 (push (org-point-in-group p 0 :timestamp) clist))
18010 ((memq 'org-link faces)
18012 (previous-single-property-change p 'face)
18013 (next-single-property-change p 'face)) clist))
18014 ((memq 'org-special-keyword faces)
18015 (push (list :keyword
18016 (previous-single-property-change p 'face)
18017 (next-single-property-change p 'face)) clist))
18019 (push (org-point-in-group p 0 :target) clist)
18020 (goto-char (1- (match-beginning 0)))
18021 (if (looking-at org-radio-target-regexp)
18022 (push (org-point-in-group p 0 :radio-target) clist))
18024 ((setq o (car (delq nil
18027 (if (memq x org-latex-fragment-image-overlays) x))
18028 (overlays-at (point))))))
18029 (push (list :latex-fragment
18030 (overlay-start o) (overlay-end o)) clist)
18031 (push (list :latex-preview
18032 (overlay-start o) (overlay-end o)) clist))
18033 ((org-inside-LaTeX-fragment-p)
18034 ;; FIXME: positions wrong.
18035 (push (list :latex-fragment (point) (point)) clist)))
18037 (setq clist (nreverse (delq nil clist)))
18040 ;; FIXME: Compare with at-regexp-p Do we need both?
18041 (defun org-in-regexp (re &optional nlines visually)
18042 "Check if point is inside a match of regexp.
18043 Normally only the current line is checked, but you can include NLINES extra
18044 lines both before and after point into the search.
18045 If VISUALLY is set, require that the cursor is not after the match but
18046 really on, so that the block visually is on the match."
18048 (let ((pos (point))
18049 (eol (point-at-eol (+ 1 (or nlines 0))))
18050 (inc (if visually 1 0)))
18052 (beginning-of-line (- 1 (or nlines 0)))
18053 (while (re-search-forward re eol t)
18054 (if (and (<= (match-beginning 0) pos)
18055 (>= (+ inc (match-end 0)) pos))
18056 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
18058 (defun org-at-regexp-p (regexp)
18059 "Is point inside a match of REGEXP in the current line?"
18062 (let ((pos (point)) (end (point-at-eol)))
18063 (beginning-of-line 1)
18064 (while (re-search-forward regexp end t)
18065 (if (and (<= (match-beginning 0) pos)
18066 (>= (match-end 0) pos))
18070 (defun org-in-regexps-block-p (start-re end-re)
18071 "Returns t if the current point is between matches of START-RE and END-RE.
18072 This will also return to if point is on one of the two matches."
18076 (and (or (org-at-regexp-p start-re)
18077 (re-search-backward start-re nil t))
18078 (re-search-forward end-re nil t)
18081 (defun org-occur-in-agenda-files (regexp &optional nlines)
18082 "Call `multi-occur' with buffers for all agenda files."
18083 (interactive "sOrg-files matching: \np")
18084 (let* ((files (org-agenda-files))
18085 (tnames (mapcar 'file-truename files))
18086 (extra org-agenda-text-search-extra-files)
18088 (when (eq (car extra) 'agenda-archives)
18089 (setq extra (cdr extra))
18090 (setq files (org-add-archive-files files)))
18091 (while (setq f (pop extra))
18092 (unless (member (file-truename f) tnames)
18093 (add-to-list 'files f 'append)
18094 (add-to-list 'tnames (file-truename f) 'append)))
18096 (mapcar (lambda (x)
18097 (with-current-buffer
18098 (or (get-file-buffer x) (find-file-noselect x))
18104 (if (boundp 'occur-mode-find-occurrence-hook)
18106 (add-hook 'occur-mode-find-occurrence-hook
18111 (defadvice occur-mode-goto-occurrence
18112 (after org-occur-reveal activate)
18113 (and (org-mode-p) (org-reveal)))
18114 (defadvice occur-mode-goto-occurrence-other-window
18115 (after org-occur-reveal activate)
18116 (and (org-mode-p) (org-reveal)))
18117 (defadvice occur-mode-display-occurrence
18118 (after org-occur-reveal activate)
18120 (let ((pos (occur-mode-find-occurrence)))
18121 (with-current-buffer (marker-buffer pos)
18126 (defun org-occur-link-in-agenda-files ()
18127 "Create a link and search for it in the agendas.
18128 The link is not stored in `org-stored-links', it is just created
18129 for the search purpose."
18131 (let ((link (condition-case nil
18132 (org-store-link nil)
18133 (error "Unable to create a link to here"))))
18134 (org-occur-in-agenda-files (regexp-quote link))))
18136 (defun org-uniquify (list)
18137 "Remove duplicate elements from LIST."
18139 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
18142 (defun org-delete-all (elts list)
18143 "Remove all elements in ELTS from LIST."
18145 (setq list (delete (pop elts) list)))
18148 (defun org-remove-if (predicate seq)
18149 "Remove everything from SEQ that fulfills PREDICATE."
18153 (if (not (funcall predicate e)) (push e res)))
18156 (defun org-remove-if-not (predicate seq)
18157 "Remove everything from SEQ that does not fulfill PREDICATE."
18161 (if (funcall predicate e) (push e res)))
18164 (defun org-back-over-empty-lines ()
18165 "Move backwards over whitespace, to the beginning of the first empty line.
18166 Returns the number of empty lines passed."
18167 (let ((pos (point)))
18168 (skip-chars-backward " \t\n\r")
18169 (beginning-of-line 2)
18170 (goto-char (min (point) pos))
18171 (count-lines (point) pos)))
18173 (defun org-skip-whitespace ()
18174 (skip-chars-forward " \t\n\r"))
18176 (defun org-point-in-group (point group &optional context)
18177 "Check if POINT is in match-group GROUP.
18178 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
18179 match. If the match group does ot exist or point is not inside it,
18181 (and (match-beginning group)
18182 (>= point (match-beginning group))
18183 (<= point (match-end group))
18185 (list context (match-beginning group) (match-end group))
18188 (defun org-switch-to-buffer-other-window (&rest args)
18189 "Switch to buffer in a second window on the current frame.
18190 In particular, do not allow pop-up frames.
18191 Returns the newly created buffer."
18192 (let (pop-up-frames special-display-buffer-names special-display-regexps
18193 special-display-function)
18194 (apply 'switch-to-buffer-other-window args)))
18196 (defun org-combine-plists (&rest plists)
18197 "Create a single property list from all plists in PLISTS.
18198 The process starts by copying the first list, and then setting properties
18199 from the other lists. Settings in the last list are the most significant
18200 ones and overrule settings in the other lists."
18201 (let ((rtn (copy-sequence (pop plists)))
18204 (setq ls (pop plists))
18206 (setq p (pop ls) v (pop ls))
18207 (setq rtn (plist-put rtn p v))))
18210 (defun org-move-line-down (arg)
18211 "Move the current line down. With prefix argument, move it past ARG lines."
18213 (let ((col (current-column))
18215 (beginning-of-line 1) (setq beg (point))
18216 (beginning-of-line 2) (setq end (point))
18217 (beginning-of-line (+ 1 arg))
18218 (setq pos (move-marker (make-marker) (point)))
18219 (insert (delete-and-extract-region beg end))
18221 (org-move-to-column col)))
18223 (defun org-move-line-up (arg)
18224 "Move the current line up. With prefix argument, move it past ARG lines."
18226 (let ((col (current-column))
18228 (beginning-of-line 1) (setq beg (point))
18229 (beginning-of-line 2) (setq end (point))
18230 (beginning-of-line (- arg))
18231 (setq pos (move-marker (make-marker) (point)))
18232 (insert (delete-and-extract-region beg end))
18234 (org-move-to-column col)))
18236 (defun org-replace-escapes (string table)
18237 "Replace %-escapes in STRING with values in TABLE.
18238 TABLE is an association list with keys like \"%a\" and string values.
18239 The sequences in STRING may contain normal field width and padding information,
18240 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
18241 so values can contain further %-escapes if they are define later in TABLE."
18242 (let ((tbl (copy-alist table))
18243 (case-fold-search nil)
18246 (while (setq e (pop tbl))
18247 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
18248 (when (and (cdr e) (string-match re (cdr e)))
18249 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
18251 (add-text-properties 0 3 (list 'sref sref) safe)
18252 (setcdr e (replace-match safe t t (cdr e)))))
18253 (while (string-match re string)
18254 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
18256 (setq string (replace-match rpl t t string))))
18257 (while (setq pchg (next-property-change pchg string))
18258 (let ((sref (get-text-property pchg 'sref string)))
18259 (when (and sref (string-match "SREF" string pchg))
18260 (setq string (replace-match sref t t string)))))
18263 (defun org-sublist (list start end)
18264 "Return a section of LIST, from START to END.
18265 Counting starts at 1."
18266 (let (rtn (c start))
18267 (setq list (nthcdr (1- start) list))
18268 (while (and list (<= c end))
18269 (push (pop list) rtn)
18273 (defun org-find-base-buffer-visiting (file)
18274 "Like `find-buffer-visiting' but always return the base buffer and
18275 not an indirect buffer."
18276 (let ((buf (or (get-file-buffer file)
18277 (find-buffer-visiting file))))
18279 (or (buffer-base-buffer buf) buf)
18282 (defun org-image-file-name-regexp (&optional extensions)
18283 "Return regexp matching the file names of images.
18284 If EXTENSIONS is given, only match these."
18285 (if (and (not extensions) (fboundp 'image-file-name-regexp))
18286 (image-file-name-regexp)
18287 (let ((image-file-name-extensions
18289 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
18290 "xbm" "xpm" "pbm" "pgm" "ppm"))))
18292 (regexp-opt (nconc (mapcar 'upcase
18293 image-file-name-extensions)
18294 image-file-name-extensions)
18298 (defun org-file-image-p (file &optional extensions)
18299 "Return non-nil if FILE is an image."
18301 (string-match (org-image-file-name-regexp extensions) file)))
18303 (defun org-get-cursor-date ()
18304 "Return the date at cursor in as a time.
18305 This works in the calendar and in the agenda, anywhere else it just
18306 returns the current time."
18307 (let (date day defd)
18309 ((eq major-mode 'calendar-mode)
18310 (setq date (calendar-cursor-to-date)
18311 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
18312 ((eq major-mode 'org-agenda-mode)
18313 (setq day (get-text-property (point) 'day))
18315 (setq date (calendar-gregorian-from-absolute day)
18316 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
18318 (or defd (current-time))))
18320 (defvar org-agenda-action-marker (make-marker)
18321 "Marker pointing to the entry for the next agenda action.")
18323 (defun org-mark-entry-for-agenda-action ()
18324 "Mark the current entry as target of an agenda action.
18325 Agenda actions are actions executed from the agenda with the key `k',
18326 which make use of the date at the cursor."
18328 (move-marker org-agenda-action-marker
18329 (save-excursion (org-back-to-heading t) (point))
18332 "Entry marked for action; press `k' at desired date in agenda or calendar"))
18334 ;;; Paragraph filling stuff.
18335 ;; We want this to be just right, so use the full arsenal.
18337 (defun org-indent-line-function ()
18338 "Indent line like previous, but further if previous was headline or item."
18340 (let* ((pos (point))
18341 (itemp (org-at-item-p))
18342 (case-fold-search t)
18343 (org-drawer-regexp (or org-drawer-regexp "\000"))
18344 column bpos bcol tpos tcol bullet btype bullet-type)
18345 ;; Find the previous relevant line
18346 (beginning-of-line 1)
18348 ((looking-at "#") (setq column 0))
18349 ((looking-at "\\*+ ") (setq column 0))
18350 ((and (looking-at "[ \t]*:END:")
18351 (save-excursion (re-search-backward org-drawer-regexp nil t)))
18353 (goto-char (1- (match-beginning 1)))
18354 (setq column (current-column))))
18355 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
18357 (re-search-backward
18358 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
18359 (setq column (org-get-indentation (match-string 0))))
18361 (beginning-of-line 0)
18362 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
18363 (not (looking-at "[ \t]*:END:"))
18364 (not (looking-at org-drawer-regexp)))
18365 (beginning-of-line 0))
18367 ((looking-at "\\*+[ \t]+")
18368 (if (not org-adapt-indentation)
18370 (goto-char (match-end 0))
18371 (setq column (current-column))))
18372 ((looking-at org-drawer-regexp)
18373 (goto-char (1- (match-beginning 1)))
18374 (setq column (current-column)))
18375 ((looking-at "\\([ \t]*\\):END:")
18376 (goto-char (match-end 1))
18377 (setq column (current-column)))
18379 (org-beginning-of-item)
18380 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
18381 (setq bpos (match-beginning 1) tpos (match-end 0)
18382 bcol (progn (goto-char bpos) (current-column))
18383 tcol (progn (goto-char tpos) (current-column))
18384 bullet (match-string 1)
18385 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
18386 (if (> tcol (+ bcol org-description-max-indent))
18387 (setq tcol (+ bcol 5)))
18391 (beginning-of-line 1)
18392 (if (looking-at "\\S-")
18394 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
18395 (setq bullet (match-string 1)
18396 btype (if (string-match "[0-9]" bullet) "n" bullet))
18397 (setq column (if (equal btype bullet-type) bcol tcol)))
18398 (setq column (org-get-indentation)))))
18399 (t (setq column (org-get-indentation))))))
18401 (if (<= (current-column) (current-indentation))
18402 (org-indent-line-to column)
18403 (save-excursion (org-indent-line-to column)))
18404 (setq column (current-column))
18405 (beginning-of-line 1)
18407 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
18408 (replace-match (concat (match-string 1)
18409 (format org-property-format
18410 (match-string 2) (match-string 3)))
18412 (org-move-to-column column)))
18414 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
18415 "Variable to store copy of `adaptive-fill-regexp'.
18416 Since `adaptive-fill-regexp' is set to never match, we need to
18417 store a backup of its value before entering `org-mode' so that
18418 the functionality can be provided as a fall-back.")
18420 (defun org-set-autofill-regexps ()
18422 ;; In the paragraph separator we include headlines, because filling
18423 ;; text in a line directly attached to a headline would otherwise
18424 ;; fill the headline as well.
18425 (org-set-local 'comment-start-skip "^#+[ \t]*")
18426 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
18427 ;; The paragraph starter includes hand-formatted lists.
18435 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
18438 "\\\\\\(begin\\|end\\|[][]\\)"))
18439 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
18440 ;; But only if the user has not turned off tables or fixed-width regions
18442 'auto-fill-inhibit-regexp
18443 (concat "\\*+ \\|#\\+"
18444 "\\|[ \t]*" org-keyword-time-regexp
18445 (if (or org-enable-table-editor org-enable-fixed-width-editor)
18448 (if org-enable-table-editor "|" "")
18449 (if org-enable-fixed-width-editor ":" "")
18451 ;; We use our own fill-paragraph function, to make sure that tables
18452 ;; and fixed-width regions are not wrapped. That function will pass
18453 ;; through to `fill-paragraph' when appropriate.
18454 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
18455 ;; Adaptive filling: To get full control, first make sure that
18456 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
18457 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
18458 (org-set-local 'org-adaptive-fill-regexp-backup
18459 adaptive-fill-regexp))
18460 (org-set-local 'adaptive-fill-regexp "\000")
18461 (org-set-local 'adaptive-fill-function
18462 'org-adaptive-fill-function)
18464 'align-mode-rules-list
18465 '((org-in-buffer-settings
18466 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
18467 (modes . '(org-mode))))))
18469 (defun org-fill-paragraph (&optional justify)
18470 "Re-align a table, pass through to fill-paragraph if no table."
18471 (let ((table-p (org-at-table-p))
18472 (table.el-p (org-at-table.el-p)))
18473 (cond ((and (equal (char-after (point-at-bol)) ?*)
18474 (save-excursion (goto-char (point-at-bol))
18475 (looking-at outline-regexp)))
18476 t) ; skip headlines
18477 (table.el-p t) ; skip table.el tables
18478 (table-p (org-table-align) t) ; align org-mode tables
18479 (t nil)))) ; call paragraph-fill
18481 ;; For reference, this is the default value of adaptive-fill-regexp
18482 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
18484 (defun org-adaptive-fill-function ()
18485 "Return a fill prefix for org-mode files.
18486 In particular, this makes sure hanging paragraphs for hand-formatted lists
18490 ((looking-at "#[ \t]+")
18491 (match-string-no-properties 0))
18492 ;; Description list
18493 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
18495 (if (> (match-end 1) (+ (match-beginning 1)
18496 org-description-max-indent))
18497 (goto-char (+ (match-beginning 1) 5))
18498 (goto-char (match-end 0)))
18499 (make-string (current-column) ?\ )))
18500 ;; Ordered or unordered list
18501 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
18503 (goto-char (match-end 0))
18504 (make-string (current-column) ?\ )))
18506 ((looking-at org-adaptive-fill-regexp-backup)
18507 (match-string-no-properties 0))))
18511 (defun org-toggle-fixed-width-section (arg)
18512 "Toggle the fixed-width export.
18513 If there is no active region, the QUOTE keyword at the current headline is
18514 inserted or removed. When present, it causes the text between this headline
18515 and the next to be exported as fixed-width text, and unmodified.
18516 If there is an active region, this command adds or removes a colon as the
18517 first character of this line. If the first character of a line is a colon,
18518 this line is also exported in fixed-width font."
18521 (regionp (org-region-active-p))
18522 (beg (if regionp (region-beginning) (point)))
18523 (end (if regionp (region-end)))
18524 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
18525 (case-fold-search nil)
18526 (re "[ \t]*\\(: \\)")
18531 (setq cc (current-column))
18532 (beginning-of-line 1)
18533 (setq off (looking-at re))
18534 (while (> nlines 0)
18535 (setq nlines (1- nlines))
18536 (beginning-of-line 1)
18539 (org-move-to-column cc t)
18542 ((and off (looking-at re))
18543 (replace-match "" t t nil 1))
18544 ((not off) (org-move-to-column cc t) (insert ": ")))
18547 (org-back-to-heading)
18548 (if (looking-at (concat outline-regexp
18549 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
18550 (replace-match "" t t nil 1)
18551 (if (looking-at outline-regexp)
18553 (goto-char (match-end 0))
18554 (insert org-quote-string " "))))))))
18556 (defun org-reftex-citation ()
18557 "Use reftex-citation to insert a citation into the buffer.
18558 This looks for a line like
18560 #+BIBLIOGRAPHY: foo plain option:-d
18562 and derives from it that foo.bib is the bibliography file relevant
18563 for this document. It then installs the necessary environment for RefTeX
18564 to work in this buffer and calls `reftex-citation' to insert a citation
18567 Export of such citations to both LaTeX and HTML is handled by the contributed
18568 package org-exp-bibtex by Taru Karttunen."
18570 (let ((reftex-docstruct-symbol 'rds)
18571 (reftex-cite-format "\\cite{%l}")
18576 (let ((case-fold-search t)
18577 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
18578 (if (not (save-excursion
18579 (or (re-search-forward re nil t)
18580 (re-search-backward re nil t))))
18581 (error "No bibliography defined in file")
18582 (setq bib (concat (match-string 1) ".bib")
18583 rds (list (list 'bib bib)))))))
18584 (call-interactively 'reftex-citation)))
18586 ;;;; Functions extending outline functionality
18588 (defun org-beginning-of-line (&optional arg)
18589 "Go to the beginning of the current line. If that is invisible, continue
18590 to a visible line beginning. This makes the function of C-a more intuitive.
18591 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18592 first attempt, and only move to after the tags when the cursor is already
18593 beyond the end of the headline."
18595 (let ((pos (point))
18596 (special (if (consp org-special-ctrl-a/e)
18597 (car org-special-ctrl-a/e)
18598 org-special-ctrl-a/e))
18600 (if (org-bound-and-true-p line-move-visual)
18601 (beginning-of-visual-line 1)
18602 (beginning-of-line 1))
18603 (if (and arg (fboundp 'move-beginning-of-line))
18604 (call-interactively 'move-beginning-of-line)
18608 (if (org-truely-invisible-p)
18609 (while (and (not (bobp)) (org-truely-invisible-p))
18611 (beginning-of-line 1))
18612 (forward-char 1))))
18615 ((and (looking-at org-complex-heading-regexp)
18616 (= (char-after (match-end 1)) ?\ ))
18617 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
18621 (cond ((> pos refpos) refpos)
18622 ((= pos (point)) refpos)
18624 (cond ((> pos (point)) (point))
18625 ((not (eq last-command this-command)) (point))
18630 (cond ((> pos (match-end 4)) (match-end 4))
18631 ((= pos (point)) (match-end 4))
18633 (cond ((> pos (point)) (point))
18634 ((not (eq last-command this-command)) (point))
18635 (t (match-end 4))))))))
18637 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18639 (defun org-end-of-line (&optional arg)
18640 "Go to the end of the line.
18641 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18642 first attempt, and only move to after the tags when the cursor is already
18643 beyond the end of the headline."
18645 (let ((special (if (consp org-special-ctrl-a/e)
18646 (cdr org-special-ctrl-a/e)
18647 org-special-ctrl-a/e)))
18648 (if (or (not special)
18649 (not (org-on-heading-p))
18651 (call-interactively
18652 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
18653 ((fboundp 'move-end-of-line) 'move-end-of-line)
18655 (let ((pos (point)))
18656 (beginning-of-line 1)
18657 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
18659 (if (or (< pos (match-beginning 1))
18660 (= pos (match-end 0)))
18661 (goto-char (match-beginning 1))
18662 (goto-char (match-end 0)))
18663 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
18664 (goto-char (match-end 0))
18665 (goto-char (match-beginning 1))))
18666 (call-interactively (if (fboundp 'move-end-of-line)
18670 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18672 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
18673 (define-key org-mode-map "\C-e" 'org-end-of-line)
18674 (define-key org-mode-map [home] 'org-beginning-of-line)
18675 (define-key org-mode-map [end] 'org-end-of-line)
18677 (defun org-backward-sentence (&optional arg)
18678 "Go to beginning of sentence, or beginning of table field.
18679 This will call `backward-sentence' or `org-table-beginning-of-field',
18680 depending on context."
18683 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
18684 (t (call-interactively 'backward-sentence))))
18686 (defun org-forward-sentence (&optional arg)
18687 "Go to end of sentence, or end of table field.
18688 This will call `forward-sentence' or `org-table-end-of-field',
18689 depending on context."
18692 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
18693 (t (call-interactively 'forward-sentence))))
18695 (define-key org-mode-map "\M-a" 'org-backward-sentence)
18696 (define-key org-mode-map "\M-e" 'org-forward-sentence)
18698 (defun org-kill-line (&optional arg)
18699 "Kill line, to tags or end of line."
18702 ((or (not org-special-ctrl-k)
18704 (not (org-on-heading-p)))
18705 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
18706 org-ctrl-k-protect-subtree)
18707 (if (or (eq org-ctrl-k-protect-subtree 'error)
18708 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
18709 (error "C-k aborted - would kill hidden subtree")))
18710 (call-interactively 'kill-line))
18711 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
18712 (kill-region (point) (match-beginning 1))
18713 (org-set-tags nil t))
18714 (t (kill-region (point) (point-at-eol)))))
18716 (define-key org-mode-map "\C-k" 'org-kill-line)
18718 (defun org-yank (&optional arg)
18719 "Yank. If the kill is a subtree, treat it specially.
18720 This command will look at the current kill and check if is a single
18721 subtree, or a series of subtrees[1]. If it passes the test, and if the
18722 cursor is at the beginning of a line or after the stars of a currently
18723 empty headline, then the yank is handled specially. How exactly depends
18724 on the value of the following variables, both set by default.
18726 org-yank-folded-subtrees
18727 When set, the subtree(s) will be folded after insertion, but only
18728 if doing so would now swallow text after the yanked text.
18730 org-yank-adjusted-subtrees
18731 When set, the subtree will be promoted or demoted in order to
18732 fit into the local outline tree structure, which means that the level
18733 will be adjusted so that it becomes the smaller one of the two
18734 *visible* surrounding headings.
18736 Any prefix to this command will cause `yank' to be called directly with
18737 no special treatment. In particular, a simple `C-u' prefix will just
18738 plainly yank the text as it is.
18740 \[1] The test checks if the first non-white line is a heading
18741 and if there are no other headings with fewer stars."
18743 (org-yank-generic 'yank arg))
18745 (defun org-yank-generic (command arg)
18746 "Perform some yank-like command.
18748 This function implements the behavior described in the `org-yank'
18749 documentation. However, it has been generalized to work for any
18750 interactive command with similar behavior."
18752 ;; pretend to be command COMMAND
18753 (setq this-command command)
18756 (call-interactively command)
18758 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18759 (and (org-kill-is-subtree-p)
18761 (and (looking-at "[ \t]*$")
18764 (buffer-substring (point-at-bol) (point)))))))
18767 ((and subtreep org-yank-folded-subtrees)
18768 (let ((beg (point))
18770 (if (and subtreep org-yank-adjusted-subtrees)
18771 (org-paste-subtree nil nil 'for-yank)
18772 (call-interactively command))
18776 (when (and (bolp) subtreep
18777 (not (setq swallowp
18778 (org-yank-folding-would-swallow-text beg end))))
18779 (or (looking-at outline-regexp)
18780 (re-search-forward (concat "^" outline-regexp) end t))
18781 (while (and (< (point) end) (looking-at outline-regexp))
18783 (org-cycle-show-empty-lines 'folded)
18784 (condition-case nil
18785 (outline-forward-same-level 1)
18786 (error (goto-char end)))))
18789 "Inserted text not folded because that would swallow text"))
18792 (skip-chars-forward " \t\n\r")
18793 (beginning-of-line 1)
18794 (push-mark beg 'nomsg)))
18795 ((and subtreep org-yank-adjusted-subtrees)
18796 (let ((beg (point-at-bol)))
18797 (org-paste-subtree nil nil 'for-yank)
18798 (push-mark beg 'nomsg)))
18800 (call-interactively command))))))
18802 (defun org-yank-folding-would-swallow-text (beg end)
18803 "Would hide-subtree at BEG swallow any text after END?"
18807 (when (or (looking-at outline-regexp)
18808 (re-search-forward (concat "^" outline-regexp) end t))
18809 (setq level (org-outline-level)))
18811 (skip-chars-forward " \t\r\n\v\f")
18813 (and (bolp) (looking-at org-outline-regexp)
18814 (<= (org-outline-level) level)))
18815 nil ; Nothing would be swallowed
18816 t)))) ; something would swallow
18818 (define-key org-mode-map "\C-y" 'org-yank)
18820 (defun org-invisible-p ()
18821 "Check if point is at a character currently not visible."
18822 ;; Early versions of noutline don't have `outline-invisible-p'.
18823 (if (fboundp 'outline-invisible-p)
18824 (outline-invisible-p)
18825 (get-char-property (point) 'invisible)))
18827 (defun org-truely-invisible-p ()
18828 "Check if point is at a character currently not visible.
18829 This version does not only check the character property, but also
18831 ;; Early versions of noutline don't have `outline-invisible-p'.
18832 (if (org-bound-and-true-p visible-mode)
18834 (if (fboundp 'outline-invisible-p)
18835 (outline-invisible-p)
18836 (get-char-property (point) 'invisible))))
18838 (defun org-invisible-p2 ()
18839 "Check if point is at a character currently not visible."
18841 (if (and (eolp) (not (bobp))) (backward-char 1))
18842 ;; Early versions of noutline don't have `outline-invisible-p'.
18843 (if (fboundp 'outline-invisible-p)
18844 (outline-invisible-p)
18845 (get-char-property (point) 'invisible))))
18847 (defun org-back-to-heading (&optional invisible-ok)
18848 "Call `outline-back-to-heading', but provide a better error message."
18849 (condition-case nil
18850 (outline-back-to-heading invisible-ok)
18851 (error (error "Before first headline at position %d in buffer %s"
18852 (point) (current-buffer)))))
18854 (defun org-beginning-of-defun ()
18855 "Go to the beginning of the subtree, i.e. back to the heading."
18856 (org-back-to-heading))
18857 (defun org-end-of-defun ()
18858 "Go to the end of the subtree."
18859 (org-end-of-subtree nil t))
18861 (defun org-before-first-heading-p ()
18862 "Before first heading?"
18864 (null (re-search-backward "^\\*+ " nil t))))
18866 (defun org-on-heading-p (&optional ignored)
18867 (outline-on-heading-p t))
18868 (defun org-at-heading-p (&optional ignored)
18869 (outline-on-heading-p t))
18871 (defun org-point-at-end-of-empty-headline ()
18872 "If point is at the end of an empty headline, return t, else nil.
18873 If the heading only contains a TODO keyword, it is still still considered
18875 (and (looking-at "[ \t]*$")
18877 (beginning-of-line 1)
18878 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18880 (defun org-at-heading-or-item-p ()
18881 (or (org-on-heading-p) (org-at-item-p)))
18883 (defun org-on-target-p ()
18884 (or (org-in-regexp org-radio-target-regexp)
18885 (org-in-regexp org-target-regexp)))
18887 (defun org-up-heading-all (arg)
18888 "Move to the heading line of which the present line is a subheading.
18889 This function considers both visible and invisible heading lines.
18890 With argument, move up ARG levels."
18891 (if (fboundp 'outline-up-heading-all)
18892 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18893 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18895 (defun org-up-heading-safe ()
18896 "Move to the heading line of which the present line is a subheading.
18897 This version will not throw an error. It will return the level of the
18898 headline found, or nil if no higher level is found.
18900 Also, this function will be a lot faster than `outline-up-heading',
18901 because it relies on stars being the outline starters. This can really
18902 make a significant difference in outlines with very many siblings."
18903 (let (start-level re)
18904 (org-back-to-heading t)
18905 (setq start-level (funcall outline-level))
18906 (if (equal start-level 1)
18908 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18909 (if (re-search-backward re nil t)
18910 (funcall outline-level)))))
18912 (defun org-first-sibling-p ()
18913 "Is this heading the first child of its parents?"
18915 (let ((re (concat "^" outline-regexp))
18917 (unless (org-at-heading-p t)
18918 (error "Not at a heading"))
18919 (setq level (funcall outline-level))
18921 (if (not (re-search-backward re nil t))
18923 (setq l (funcall outline-level))
18926 (defun org-goto-sibling (&optional previous)
18927 "Goto the next sibling, even if it is invisible.
18928 When PREVIOUS is set, go to the previous sibling instead. Returns t
18929 when a sibling was found. When none is found, return nil and don't
18931 (let ((fun (if previous 're-search-backward 're-search-forward))
18933 (re (concat "^" outline-regexp))
18935 (when (condition-case nil (org-back-to-heading t) (error nil))
18936 (setq level (funcall outline-level))
18938 (or previous (forward-char 1))
18939 (while (funcall fun re nil t)
18940 (setq l (funcall outline-level))
18941 (when (< l level) (goto-char pos) (throw 'exit nil))
18942 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18946 (defun org-show-siblings ()
18947 "Show all siblings of the current headline."
18949 (while (org-goto-sibling) (org-flag-heading nil)))
18951 (while (org-goto-sibling 'previous)
18952 (org-flag-heading nil))))
18954 (defun org-show-hidden-entry ()
18955 "Show an entry where even the heading is hidden."
18959 (defun org-flag-heading (flag &optional entry)
18960 "Flag the current heading. FLAG non-nil means make invisible.
18961 When ENTRY is non-nil, show the entire entry."
18963 (org-back-to-heading t)
18964 ;; Check if we should show the entire entry
18969 (and (outline-next-heading)
18970 (org-flag-heading nil))))
18971 (outline-flag-region (max (point-min) (1- (point)))
18972 (save-excursion (outline-end-of-heading) (point))
18975 (defun org-get-next-sibling ()
18976 "Move to next heading of the same level, and return point.
18977 If there is no such heading, return nil.
18978 This is like outline-next-sibling, but invisible headings are ok."
18979 (let ((level (funcall outline-level)))
18980 (outline-next-heading)
18981 (while (and (not (eobp)) (> (funcall outline-level) level))
18982 (outline-next-heading))
18983 (if (or (eobp) (< (funcall outline-level) level))
18987 (defun org-get-last-sibling ()
18988 "Move to previous heading of the same level, and return point.
18989 If there is no such heading, return nil."
18990 (let ((opoint (point))
18991 (level (funcall outline-level)))
18992 (outline-previous-heading)
18993 (when (and (/= (point) opoint) (outline-on-heading-p t))
18994 (while (and (> (funcall outline-level) level)
18996 (outline-previous-heading))
18997 (if (< (funcall outline-level) level)
19001 (defun org-end-of-subtree (&optional invisible-OK to-heading)
19002 ;; This contains an exact copy of the original function, but it uses
19003 ;; `org-back-to-heading', to make it work also in invisible
19004 ;; trees. And is uses an invisible-OK argument.
19005 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
19006 ;; Furthermore, when used inside Org, finding the end of a large subtree
19007 ;; with many children and grandchildren etc, this can be much faster
19008 ;; than the outline version.
19009 (org-back-to-heading invisible-OK)
19011 (level (funcall outline-level)))
19012 (if (and (org-mode-p) (< level 1000))
19013 ;; A true heading (not a plain list item), in Org-mode
19014 ;; This means we can easily find the end by looking
19015 ;; only for the right number of stars. Using a regexp to do
19016 ;; this is so much faster than using a Lisp loop.
19017 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
19019 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
19020 ;; something else, do it the slow way
19021 (while (and (not (eobp))
19022 (or first (> (funcall outline-level) level)))
19024 (outline-next-heading)))
19026 (if (memq (preceding-char) '(?\n ?\^M))
19028 ;; Go to end of line before heading
19030 (if (memq (preceding-char) '(?\n ?\^M))
19031 ;; leave blank line before heading
19032 (forward-char -1))))))
19035 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
19036 "Use Org version in org-mode, for dramatic speed-up."
19037 (if (eq major-mode 'org-mode)
19039 (org-end-of-subtree nil t)
19040 (unless (eobp) (backward-char 1)))
19043 (defun org-forward-same-level (arg &optional invisible-ok)
19044 "Move forward to the arg'th subheading at same level as this one.
19045 Stop at the first and last subheadings of a superior heading."
19047 (org-back-to-heading invisible-ok)
19049 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19050 (re (format "^\\*\\{1,%d\\} " level))
19054 (while (and (re-search-forward re nil 'move)
19055 (setq l (- (match-end 0) (match-beginning 0) 1))
19058 (progn (backward-char 1) (org-invisible-p)))
19059 (if (< l level) (setq arg 1)))
19060 (setq arg (1- arg)))
19061 (beginning-of-line 1)))
19063 (defun org-backward-same-level (arg &optional invisible-ok)
19064 "Move backward to the arg'th subheading at same level as this one.
19065 Stop at the first and last subheadings of a superior heading."
19067 (org-back-to-heading)
19069 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19070 (re (format "^\\*\\{1,%d\\} " level))
19073 (while (and (re-search-backward re nil 'move)
19074 (setq l (- (match-end 0) (match-beginning 0) 1))
19078 (if (< l level) (setq arg 1)))
19079 (setq arg (1- arg)))))
19081 (defun org-show-subtree ()
19082 "Show everything after this heading at deeper levels."
19083 (outline-flag-region
19086 (org-end-of-subtree t t))
19089 (defun org-show-entry ()
19090 "Show the body directly following this heading.
19091 Show the heading too, if it is currently invisible."
19094 (condition-case nil
19096 (org-back-to-heading t)
19097 (outline-flag-region
19098 (max (point-min) (1- (point)))
19100 (if (re-search-forward
19101 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
19102 (match-beginning 1)
19105 (org-cycle-hide-drawers 'children))
19108 (defun org-make-options-regexp (kwds &optional extra)
19109 "Make a regular expression for keyword lines."
19113 (mapconcat 'regexp-quote kwds "\\|")
19114 (if extra (concat "\\|" extra))
19118 ;; Make isearch reveal the necessary context
19119 (defun org-isearch-end ()
19120 "Reveal context after isearch exits."
19121 (when isearch-success ; only if search was successful
19122 (if (featurep 'xemacs)
19123 ;; Under XEmacs, the hook is run in the correct place,
19124 ;; we directly show the context.
19125 (org-show-context 'isearch)
19126 ;; In Emacs the hook runs *before* restoring the overlays.
19127 ;; So we have to use a one-time post-command-hook to do this.
19128 ;; (Emacs 22 has a special variable, see function `org-mode')
19129 (unless (and (boundp 'isearch-mode-end-hook-quit)
19130 isearch-mode-end-hook-quit)
19131 ;; Only when the isearch was not quitted.
19132 (org-add-hook 'post-command-hook 'org-isearch-post-command
19133 'append 'local)))))
19135 (defun org-isearch-post-command ()
19136 "Remove self from hook, and show context."
19137 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
19138 (org-show-context 'isearch))
19141 ;;;; Integration with and fixes for other packages
19145 (defvar org-imenu-markers nil
19146 "All markers currently used by Imenu.")
19147 (make-variable-buffer-local 'org-imenu-markers)
19149 (defun org-imenu-new-marker (&optional pos)
19150 "Return a new marker for use by Imenu, and remember the marker."
19151 (let ((m (make-marker)))
19152 (move-marker m (or pos (point)))
19153 (push m org-imenu-markers)
19156 (defun org-imenu-get-tree ()
19157 "Produce the index for Imenu."
19158 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
19159 (setq org-imenu-markers nil)
19160 (let* ((n org-imenu-depth)
19161 (re (concat "^" outline-regexp))
19162 (subs (make-vector (1+ n) nil))
19168 (goto-char (point-max))
19169 (while (re-search-backward re nil t)
19170 (setq level (org-reduced-level (funcall outline-level)))
19172 (looking-at org-complex-heading-regexp)
19173 (setq head (org-link-display-format
19174 (org-match-string-no-properties 4))
19175 m (org-imenu-new-marker))
19176 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
19177 (if (>= level last-level)
19178 (push (cons head m) (aref subs level))
19179 (push (cons head (aref subs (1+ level))) (aref subs level))
19180 (loop for i from (1+ level) to n do (aset subs i nil)))
19181 (setq last-level level)))))
19184 (eval-after-load "imenu"
19186 (add-hook 'imenu-after-jump-hook
19188 (if (eq major-mode 'org-mode)
19189 (org-show-context 'org-goto))))))
19191 (defun org-link-display-format (link)
19192 "Replace a link with either the description, or the link target
19193 if no description is present"
19195 (if (string-match org-bracket-link-analytic-regexp link)
19196 (replace-match (if (match-end 5)
19197 (match-string 5 link)
19198 (concat (match-string 1 link)
19199 (match-string 3 link)))
19203 ;; Speedbar support
19205 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
19206 "Overlay marking the agenda restriction line in speedbar.")
19207 (overlay-put org-speedbar-restriction-lock-overlay
19208 'face 'org-agenda-restriction-lock)
19209 (overlay-put org-speedbar-restriction-lock-overlay
19210 'help-echo "Agendas are currently limited to this item.")
19211 (org-detach-overlay org-speedbar-restriction-lock-overlay)
19213 (defun org-speedbar-set-agenda-restriction ()
19214 "Restrict future agenda commands to the location at point in speedbar.
19215 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
19217 (require 'org-agenda)
19218 (let (p m tp np dir txt)
19220 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19222 (setq m (get-text-property p 'org-imenu-marker))
19223 (with-current-buffer (marker-buffer m)
19225 (org-agenda-set-restriction-lock 'subtree)))
19226 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19227 'speedbar-function 'speedbar-find-file))
19228 (setq tp (previous-single-property-change
19229 (1+ p) 'speedbar-function)
19230 np (next-single-property-change
19231 tp 'speedbar-function)
19232 dir (speedbar-line-directory)
19233 txt (buffer-substring-no-properties (or tp (point-min))
19234 (or np (point-max))))
19235 (with-current-buffer (find-file-noselect
19236 (let ((default-directory dir))
19237 (expand-file-name txt)))
19238 (unless (org-mode-p)
19239 (error "Cannot restrict to non-Org-mode file"))
19240 (org-agenda-set-restriction-lock 'file)))
19241 (t (error "Don't know how to restrict Org-mode's agenda")))
19242 (move-overlay org-speedbar-restriction-lock-overlay
19243 (point-at-bol) (point-at-eol))
19244 (setq current-prefix-arg nil)
19245 (org-agenda-maybe-redo)))
19247 (eval-after-load "speedbar"
19249 (speedbar-add-supported-extension ".org")
19250 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
19251 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
19252 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
19253 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
19254 (add-hook 'speedbar-visiting-tag-hook
19255 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
19257 ;;; Fixes and Hacks for problems with other packages
19259 ;; Make flyspell not check words in links, to not mess up our keymap
19260 (defun org-mode-flyspell-verify ()
19261 "Don't let flyspell put overlays at active buttons."
19262 (and (not (get-text-property (point) 'keymap))
19263 (not (get-text-property (point) 'org-no-flyspell))))
19265 (defun org-remove-flyspell-overlays-in (beg end)
19266 "Remove flyspell overlays in region."
19267 (and (org-bound-and-true-p flyspell-mode)
19268 (fboundp 'flyspell-delete-region-overlays)
19269 (flyspell-delete-region-overlays beg end))
19270 (add-text-properties beg end '(org-no-flyspell t)))
19272 ;; Make `bookmark-jump' shows the jump location if it was hidden.
19273 (eval-after-load "bookmark"
19274 '(if (boundp 'bookmark-after-jump-hook)
19275 ;; We can use the hook
19276 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
19277 ;; Hook not available, use advice
19278 (defadvice bookmark-jump (after org-make-visible activate)
19279 "Make the position visible."
19280 (org-bookmark-jump-unhide))))
19282 ;; Make sure saveplace shows the location if it was hidden
19283 (eval-after-load "saveplace"
19284 '(defadvice save-place-find-file-hook (after org-make-visible activate)
19285 "Make the position visible."
19286 (org-bookmark-jump-unhide)))
19288 ;; Make sure ecb shows the location if it was hidden
19289 (eval-after-load "ecb"
19290 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
19291 "Make hierarchy visible when jumping into location from ECB tree buffer."
19292 (if (eq major-mode 'org-mode)
19293 (org-show-context))))
19295 (defun org-bookmark-jump-unhide ()
19296 "Unhide the current position, to show the bookmark location."
19298 (or (org-invisible-p)
19299 (save-excursion (goto-char (max (point-min) (1- (point))))
19300 (org-invisible-p)))
19301 (org-show-context 'bookmark-jump)))
19303 ;; Make session.el ignore our circular variable
19304 (eval-after-load "session"
19305 '(add-to-list 'session-globals-exclude 'org-mark-ring))
19307 ;;;; Experimental code
19309 (defun org-closed-in-range ()
19310 "Sparse tree of items closed in a certain time range.
19311 Still experimental, may disappear in the future."
19313 ;; Get the time interval from the user.
19314 (let* ((time1 (org-float-time
19315 (org-read-date nil 'to-time nil "Starting date: ")))
19316 (time2 (org-float-time
19317 (org-read-date nil 'to-time nil "End date:")))
19318 ;; callback function
19319 (callback (lambda ()
19322 (apply 'encode-time
19323 (org-parse-time-string
19324 (match-string 1))))))
19325 ;; check if time in interval
19326 (and (>= time time1) (<= time time2))))))
19327 ;; make tree, check each match with the callback
19328 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
19334 (run-hooks 'org-load-hook)
19336 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
19338 ;;; org.el ends here