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
)))
1492 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1493 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1494 Elisp links can be dangerous: just think about a link
1496 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1498 This link would show up in your Org-mode document as \"Google Search\",
1499 but really it would remove your entire home directory.
1500 Therefore we advise against setting this variable to nil.
1501 Just change it to `y-or-n-p' if you want to confirm with a
1502 single keystroke rather than having to type \"yes\"."
1503 :group
'org-link-follow
1505 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1506 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1507 (const :tag
"no confirmation (dangerous)" nil
)))
1509 (defconst org-file-apps-defaults-gnu
1513 "Default file applications on a UNIX or GNU/Linux system.
1514 See `org-file-apps'.")
1516 (defconst org-file-apps-defaults-macosx
1519 (system .
"open %s")
1521 ("eps.gz" .
"gv %s")
1523 ("fig" .
"xfig %s"))
1524 "Default file applications on a MacOS X system.
1525 The system \"open\" is known as a default, but we use X11 applications
1526 for some files for which the OS does not have a good default.
1527 See `org-file-apps'.")
1529 (defconst org-file-apps-defaults-windowsnt
1533 (list (if (featurep 'xemacs
)
1534 'mswindows-shell-execute
1538 (list (if (featurep 'xemacs
)
1539 'mswindows-shell-execute
1542 "Default file applications on a Windows NT system.
1543 The system \"open\" is used for most files.
1544 See `org-file-apps'.")
1546 (defcustom org-file-apps
1549 ("\\.mm\\'" . default
)
1550 ("\\.x?html?\\'" . default
)
1551 ("\\.pdf\\'" . default
)
1553 "External applications for opening `file:path' items in a document.
1554 Org-mode uses system defaults for different file types, but
1555 you can use this variable to set the application for a given file
1556 extension. The entries in this list are cons cells where the car identifies
1557 files and the cdr the corresponding command. Possible values for the
1559 \"string\" A string as a file identifier can be interpreted in different
1560 ways, depending on its contents:
1562 - Alphanumeric characters only:
1563 Match links with this file extension.
1564 Example: (\"pdf\" . \"evince %s\")
1565 to open PDFs with evince.
1567 - Regular expression: Match links where the
1568 filename matches the regexp. If you want to
1569 use groups here, use shy groups.
1571 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1572 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1573 to open *.html and *.xhtml with firefox.
1575 - Regular expression which contains (non-shy) groups:
1576 Match links where the whole link, including \"::\", and
1577 anything after that, matches the regexp.
1578 In a custom command string, %1, %2, etc. are replaced with
1579 the parts of the link that were matched by the groups.
1580 For backwards compatibility, if a command string is given
1581 that does not use any of the group matches, this case is
1582 handled identically to the second one (i.e. match against
1585 In a custom lisp form, you can access the group matches with
1586 (match-string n link).
1588 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1589 to open [[file:document.pdf::5]] with evince at page 5.
1591 `directory' Matches a directory
1592 `remote' Matches a remote file, accessible through tramp or efs.
1593 Remote files most likely should be visited through Emacs
1594 because external applications cannot handle such paths.
1595 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1596 so all files Emacs knows how to handle. Using this with
1597 command `emacs' will open most files in Emacs. Beware that this
1598 will also open html files inside Emacs, unless you add
1599 (\"html\" . default) to the list as well.
1600 t Default for files not matched by any of the other options.
1601 `system' The system command to open files, like `open' on Windows
1602 and Mac OS X, and mailcap under GNU/Linux. This is the command
1603 that will be selected if you call `C-c C-o' with a double
1606 Possible values for the command are:
1607 `emacs' The file will be visited by the current Emacs process.
1608 `default' Use the default application for this file type, which is the
1609 association for t in the list, most likely in the system-specific
1611 This can be used to overrule an unwanted setting in the
1612 system-specific variable.
1613 `system' Use the system command for opening files, like \"open\".
1614 This command is specified by the entry whose car is `system'.
1615 Most likely, the system-specific version of this variable
1616 does define this command, but you can overrule/replace it
1618 string A command to be executed by a shell; %s will be replaced
1619 by the path to the file.
1620 sexp A Lisp form which will be evaluated. The file path will
1621 be available in the Lisp variable `file'.
1622 For more examples, see the system specific constants
1623 `org-file-apps-defaults-macosx'
1624 `org-file-apps-defaults-windowsnt'
1625 `org-file-apps-defaults-gnu'."
1626 :group
'org-link-follow
1628 (cons (choice :value
""
1629 (string :tag
"Extension")
1630 (const :tag
"System command to open files" system
)
1631 (const :tag
"Default for unrecognized files" t
)
1632 (const :tag
"Remote file" remote
)
1633 (const :tag
"Links to a directory" directory
)
1634 (const :tag
"Any files that have Emacs modes"
1637 (const :tag
"Visit with Emacs" emacs
)
1638 (const :tag
"Use default" default
)
1639 (const :tag
"Use the system command" system
)
1640 (string :tag
"Command")
1641 (sexp :tag
"Lisp form")))))
1645 (defgroup org-refile nil
1646 "Options concerning refiling entries in Org-mode."
1650 (defcustom org-directory
"~/org"
1651 "Directory with org files.
1652 This is just a default location to look for Org files. There is no need
1653 at all to put your files into this directory. It is only used in the
1654 following situations:
1656 1. When a remember template specifies a target file that is not an
1657 absolute path. The path will then be interpreted relative to
1659 2. When a remember note is filed away in an interactive way (when exiting the
1660 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1661 with `org-directory' as the default path."
1663 :group
'org-remember
1666 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1667 "Default target for storing notes.
1668 Used by the hooks for remember.el. This can be a string, or nil to mean
1669 the value of `remember-data-file'.
1670 You can set this on a per-template basis with the variable
1671 `org-remember-templates'."
1673 :group
'org-remember
1675 (const :tag
"Default from remember-data-file" nil
)
1678 (defcustom org-goto-interface
'outline
1679 "The default interface to be used for `org-goto'.
1681 outline The interface shows an outline of the relevant file
1682 and the correct heading is found by moving through
1683 the outline or by searching with incremental search.
1684 outline-path-completion Headlines in the current buffer are offered via
1685 completion. This is the interface also used by
1686 the refile command."
1689 (const :tag
"Outline" outline
)
1690 (const :tag
"Outline-path-completion" outline-path-completion
)))
1692 (defcustom org-goto-max-level
5
1693 "Maximum level to be considered when running org-goto with refile interface."
1697 (defcustom org-reverse-note-order nil
1698 "Non-nil means store new notes at the beginning of a file or entry.
1699 When nil, new notes will be filed to the end of a file or entry.
1700 This can also be a list with cons cells of regular expressions that
1701 are matched against file names, and values."
1702 :group
'org-remember
1705 (const :tag
"Reverse always" t
)
1706 (const :tag
"Reverse never" nil
)
1707 (repeat :tag
"By file name regexp"
1708 (cons regexp boolean
))))
1710 (defcustom org-log-refile nil
1711 "Information to record when a task is refiled.
1713 Possible values are:
1715 nil Don't add anything
1716 time Add a time stamp to the task
1717 note Prompt for a note and add it with template `org-log-note-headings'
1719 This option can also be set with on a per-file-basis with
1721 #+STARTUP: nologrefile
1722 #+STARTUP: logrefile
1723 #+STARTUP: lognoterefile
1725 You can have local logging settings for a subtree by setting the LOGGING
1726 property to one or more of these keywords.
1728 When bulk-refiling from the agenda, the value `note' is forbidden and
1729 will temporarily be changed to `time'."
1731 :group
'org-progress
1733 (const :tag
"No logging" nil
)
1734 (const :tag
"Record timestamp" time
)
1735 (const :tag
"Record timestamp with note." note
)))
1737 (defcustom org-refile-targets nil
1738 "Targets for refiling entries with \\[org-refile].
1739 This is list of cons cells. Each cell contains:
1740 - a specification of the files to be considered, either a list of files,
1741 or a symbol whose function or variable value will be used to retrieve
1742 a file name or a list of file names. If you use `org-agenda-files' for
1743 that, all agenda files will be scanned for targets. Nil means consider
1744 headings in the current buffer.
1745 - A specification of how to find candidate refile targets. This may be
1747 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1748 This tag has to be present in all target headlines, inheritance will
1750 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1752 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1753 headlines that are refiling targets.
1754 - a cons cell (:level . N). Any headline of level N is considered a target.
1755 Note that, when `org-odd-levels-only' is set, level corresponds to
1756 order in hierarchy, not to the number of stars.
1757 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1758 Note that, when `org-odd-levels-only' is set, level corresponds to
1759 order in hierarchy, not to the number of stars.
1761 You can set the variable `org-refile-target-verify-function' to a function
1762 to verify each headline found by the simple critery above.
1764 When this variable is nil, all top-level headlines in the current buffer
1765 are used, equivalent to the value `((nil . (:level . 1))'."
1769 (choice :value org-agenda-files
1770 (const :tag
"All agenda files" org-agenda-files
)
1771 (const :tag
"Current buffer" nil
)
1772 (function) (variable) (file))
1773 (choice :tag
"Identify target headline by"
1774 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1775 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1776 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1777 (cons :tag
"Level number" (const :value
:level
) (integer))
1778 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1780 (defcustom org-refile-target-verify-function nil
1781 "Function to verify if the headline at point should be a refile target.
1782 The function will be called without arguments, with point at the
1783 beginning of the headline. It should return t and leave point
1784 where it is if the headline is a valid target for refiling.
1786 If the target should not be selected, the function must return nil.
1787 In addition to this, it may move point to a place from where the search
1788 should be continued. For example, the function may decide that the entire
1789 subtree of the current entry should be excluded and move point to the end
1794 (defcustom org-refile-use-cache nil
1795 "Non-nil means cache refile targets to speed up the process.
1796 The cache for a particular file will be updated automatically when
1797 the buffer has been killed, or when any of the marker used for flagging
1798 refile targets no longer points at a live buffer.
1799 If you have added new entries to a buffer that might themselves be targets,
1800 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
1801 find that easier, `C-u C-u C-u C-c C-w'."
1805 (defcustom org-refile-use-outline-path nil
1806 "Non-nil means provide refile targets as paths.
1807 So a level 3 headline will be available as level1/level2/level3.
1809 When the value is `file', also include the file name (without directory)
1810 into the path. In this case, you can also stop the completion after
1811 the file name, to get entries inserted as top level in the file.
1813 When `full-file-path', include the full file path."
1816 (const :tag
"Not" nil
)
1817 (const :tag
"Yes" t
)
1818 (const :tag
"Start with file name" file
)
1819 (const :tag
"Start with full file path" full-file-path
)))
1821 (defcustom org-outline-path-complete-in-steps t
1822 "Non-nil means complete the outline path in hierarchical steps.
1823 When Org-mode uses the refile interface to select an outline path
1824 \(see variable `org-refile-use-outline-path'), the completion of
1825 the path can be done is a single go, or if can be done in steps down
1826 the headline hierarchy. Going in steps is probably the best if you
1827 do not use a special completion package like `ido' or `icicles'.
1828 However, when using these packages, going in one step can be very
1829 fast, while still showing the whole path to the entry."
1833 (defcustom org-refile-allow-creating-parent-nodes nil
1834 "Non-nil means allow to create new nodes as refile targets.
1835 New nodes are then created by adding \"/new node name\" to the completion
1836 of an existing node. When the value of this variable is `confirm',
1837 new node creation must be confirmed by the user (recommended)
1838 When nil, the completion must match an existing entry.
1840 Note that, if the new heading is not seen by the criteria
1841 listed in `org-refile-targets', multiple instances of the same
1842 heading would be created by trying again to file under the new
1846 (const :tag
"Never" nil
)
1847 (const :tag
"Always" t
)
1848 (const :tag
"Prompt for confirmation" confirm
)))
1850 (defgroup org-todo nil
1851 "Options concerning TODO items in Org-mode."
1855 (defgroup org-progress nil
1856 "Options concerning Progress logging in Org-mode."
1860 (defvar org-todo-interpretation-widgets
1862 (:tag
"Sequence (cycling hits every state)" sequence
)
1863 (:tag
"Type (cycling directly to DONE)" type
))
1864 "The available interpretation symbols for customizing
1865 `org-todo-keywords'.
1866 Interested libraries should add to this list.")
1868 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1869 "List of TODO entry keyword sequences and their interpretation.
1870 \\<org-mode-map>This is a list of sequences.
1872 Each sequence starts with a symbol, either `sequence' or `type',
1873 indicating if the keywords should be interpreted as a sequence of
1874 action steps, or as different types of TODO items. The first
1875 keywords are states requiring action - these states will select a headline
1876 for inclusion into the global TODO list Org-mode produces. If one of
1877 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1878 signify that no further action is necessary. If \"|\" is not found,
1879 the last keyword is treated as the only DONE state of the sequence.
1881 The command \\[org-todo] cycles an entry through these states, and one
1882 additional state where no keyword is present. For details about this
1883 cycling, see the manual.
1885 TODO keywords and interpretation can also be set on a per-file basis with
1886 the special #+SEQ_TODO and #+TYP_TODO lines.
1888 Each keyword can optionally specify a character for fast state selection
1889 \(in combination with the variable `org-use-fast-todo-selection')
1890 and specifiers for state change logging, using the same syntax
1891 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1892 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1893 indicates to record a time stamp each time this state is selected.
1895 Each keyword may also specify if a timestamp or a note should be
1896 recorded when entering or leaving the state, by adding additional
1897 characters in the parenthesis after the keyword. This looks like this:
1898 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1899 record only the time of the state change. With X and Y being either
1900 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1901 Y when leaving the state if and only if the *target* state does not
1902 define X. You may omit any of the fast-selection key or X or /Y,
1903 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1905 For backward compatibility, this variable may also be just a list
1906 of keywords - in this case the interpretation (sequence or type) will be
1907 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1909 :group
'org-keywords
1911 (repeat :tag
"Old syntax, just keywords"
1912 (string :tag
"Keyword"))
1913 (repeat :tag
"New syntax"
1916 :tag
"Interpretation"
1917 ;;Quick and dirty way to see
1918 ;;`org-todo-interpretations'. This takes the
1919 ;;place of item arguments
1927 org-todo-interpretation-widgets
))
1930 (string :tag
"Keyword"))))))
1932 (defvar org-todo-keywords-1 nil
1933 "All TODO and DONE keywords active in a buffer.")
1934 (make-variable-buffer-local 'org-todo-keywords-1
)
1935 (defvar org-todo-keywords-for-agenda nil
)
1936 (defvar org-done-keywords-for-agenda nil
)
1937 (defvar org-drawers-for-agenda nil
)
1938 (defvar org-todo-keyword-alist-for-agenda nil
)
1939 (defvar org-tag-alist-for-agenda nil
)
1940 (defvar org-agenda-contributing-files nil
)
1941 (defvar org-not-done-keywords nil
)
1942 (make-variable-buffer-local 'org-not-done-keywords
)
1943 (defvar org-done-keywords nil
)
1944 (make-variable-buffer-local 'org-done-keywords
)
1945 (defvar org-todo-heads nil
)
1946 (make-variable-buffer-local 'org-todo-heads
)
1947 (defvar org-todo-sets nil
)
1948 (make-variable-buffer-local 'org-todo-sets
)
1949 (defvar org-todo-log-states nil
)
1950 (make-variable-buffer-local 'org-todo-log-states
)
1951 (defvar org-todo-kwd-alist nil
)
1952 (make-variable-buffer-local 'org-todo-kwd-alist
)
1953 (defvar org-todo-key-alist nil
)
1954 (make-variable-buffer-local 'org-todo-key-alist
)
1955 (defvar org-todo-key-trigger nil
)
1956 (make-variable-buffer-local 'org-todo-key-trigger
)
1958 (defcustom org-todo-interpretation
'sequence
1959 "Controls how TODO keywords are interpreted.
1960 This variable is in principle obsolete and is only used for
1961 backward compatibility, if the interpretation of todo keywords is
1962 not given already in `org-todo-keywords'. See that variable for
1965 :group
'org-keywords
1966 :type
'(choice (const sequence
)
1969 (defcustom org-use-fast-todo-selection t
1970 "Non-nil means use the fast todo selection scheme with C-c C-t.
1971 This variable describes if and under what circumstances the cycling
1972 mechanism for TODO keywords will be replaced by a single-key, direct
1975 When nil, fast selection is never used.
1977 When the symbol `prefix', it will be used when `org-todo' is called with
1978 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1979 in an agenda buffer.
1981 When t, fast selection is used by default. In this case, the prefix
1982 argument forces cycling instead.
1984 In all cases, the special interface is only used if access keys have actually
1985 been assigned by the user, i.e. if keywords in the configuration are followed
1986 by a letter in parenthesis, like TODO(t)."
1989 (const :tag
"Never" nil
)
1990 (const :tag
"By default" t
)
1991 (const :tag
"Only with C-u C-c C-t" prefix
)))
1993 (defcustom org-provide-todo-statistics t
1994 "Non-nil means update todo statistics after insert and toggle.
1995 ALL-HEADLINES means update todo statistics by including headlines
1996 with no TODO keyword as well, counting them as not done.
1997 A list of TODO keywords means the same, but skip keywords that are
2000 When this is set, todo statistics is updated in the parent of the
2001 current entry each time a todo state is changed."
2004 (const :tag
"Yes, only for TODO entries" t
)
2005 (const :tag
"Yes, including all entries" 'all-headlines
)
2006 (repeat :tag
"Yes, for TODOs in this list"
2007 (string :tag
"TODO keyword"))
2008 (other :tag
"No TODO statistics" nil
)))
2010 (defcustom org-hierarchical-todo-statistics t
2011 "Non-nil means TODO statistics covers just direct children.
2012 When nil, all entries in the subtree are considered.
2013 This has only an effect if `org-provide-todo-statistics' is set.
2014 To set this to nil for only a single subtree, use a COOKIE_DATA
2015 property and include the word \"recursive\" into the value."
2019 (defcustom org-after-todo-state-change-hook nil
2020 "Hook which is run after the state of a TODO item was changed.
2021 The new state (a string with a TODO keyword, or nil) is available in the
2022 Lisp variable `state'."
2026 (defvar org-blocker-hook nil
2027 "Hook for functions that are allowed to block a state change.
2029 Each function gets as its single argument a property list, see
2030 `org-trigger-hook' for more information about this list.
2032 If any of the functions in this hook returns nil, the state change
2035 (defvar org-trigger-hook nil
2036 "Hook for functions that are triggered by a state change.
2038 Each function gets as its single argument a property list with at least
2039 the following elements:
2041 (:type type-of-change :position pos-at-entry-start
2042 :from old-state :to new-state)
2044 Depending on the type, more properties may be present.
2046 This mechanism is currently implemented for:
2050 :type todo-state-change
2051 :from previous state (keyword as a string), or nil, or a symbol
2052 'todo' or 'done', to indicate the general type of state.
2053 :to new state, like in :from")
2055 (defcustom org-enforce-todo-dependencies nil
2056 "Non-nil means undone TODO entries will block switching the parent to DONE.
2057 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2058 be blocked if any prior sibling is not yet done.
2059 Finally, if the parent is blocked because of ordered siblings of its own,
2060 the child will also be blocked.
2061 This variable needs to be set before org.el is loaded, and you need to
2062 restart Emacs after a change to make the change effective. The only way
2063 to change is while Emacs is running is through the customize interface."
2064 :set
(lambda (var val
)
2067 (add-hook 'org-blocker-hook
2068 'org-block-todo-from-children-or-siblings-or-parent
)
2069 (remove-hook 'org-blocker-hook
2070 'org-block-todo-from-children-or-siblings-or-parent
)))
2074 (defcustom org-enforce-todo-checkbox-dependencies nil
2075 "Non-nil means unchecked boxes will block switching the parent to DONE.
2076 When this is nil, checkboxes have no influence on switching TODO states.
2077 When non-nil, you first need to check off all check boxes before the TODO
2078 entry can be switched to DONE.
2079 This variable needs to be set before org.el is loaded, and you need to
2080 restart Emacs after a change to make the change effective. The only way
2081 to change is while Emacs is running is through the customize interface."
2082 :set
(lambda (var val
)
2085 (add-hook 'org-blocker-hook
2086 'org-block-todo-from-checkboxes
)
2087 (remove-hook 'org-blocker-hook
2088 'org-block-todo-from-checkboxes
)))
2092 (defcustom org-treat-insert-todo-heading-as-state-change nil
2093 "Non-nil means inserting a TODO heading is treated as state change.
2094 So when the command \\[org-insert-todo-heading] is used, state change
2095 logging will apply if appropriate. When nil, the new TODO item will
2096 be inserted directly, and no logging will take place."
2100 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2101 "Non-nil means switching TODO states with S-cursor counts as state change.
2102 This is the default behavior. However, setting this to nil allows a
2103 convenient way to select a TODO state and bypass any logging associated
2108 (defcustom org-todo-state-tags-triggers nil
2109 "Tag changes that should be triggered by TODO state changes.
2110 This is a list. Each entry is
2112 (state-change (tag . flag) .......)
2114 State-change can be a string with a state, and empty string to indicate the
2115 state that has no TODO keyword, or it can be one of the symbols `todo'
2116 or `done', meaning any not-done or done state, respectively."
2120 (cons (choice :tag
"When changing to"
2121 (const :tag
"Not-done state" todo
)
2122 (const :tag
"Done state" done
)
2123 (string :tag
"State"))
2125 (cons :tag
"Tag action"
2127 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2129 (defcustom org-log-done nil
2130 "Information to record when a task moves to the DONE state.
2132 Possible values are:
2134 nil Don't add anything, just change the keyword
2135 time Add a time stamp to the task
2136 note Prompt for a note and add it with template `org-log-note-headings'
2138 This option can also be set with on a per-file-basis with
2140 #+STARTUP: nologdone
2142 #+STARTUP: lognotedone
2144 You can have local logging settings for a subtree by setting the LOGGING
2145 property to one or more of these keywords."
2147 :group
'org-progress
2149 (const :tag
"No logging" nil
)
2150 (const :tag
"Record CLOSED timestamp" time
)
2151 (const :tag
"Record CLOSED timestamp with note." note
)))
2153 ;; Normalize old uses of org-log-done.
2155 ((eq org-log-done t
) (setq org-log-done
'time
))
2156 ((and (listp org-log-done
) (memq 'done org-log-done
))
2157 (setq org-log-done
'note
)))
2159 (defcustom org-log-reschedule nil
2160 "Information to record when the scheduling date of a tasks is modified.
2162 Possible values are:
2164 nil Don't add anything, just change the date
2165 time Add a time stamp to the task
2166 note Prompt for a note and add it with template `org-log-note-headings'
2168 This option can also be set with on a per-file-basis with
2170 #+STARTUP: nologreschedule
2171 #+STARTUP: logreschedule
2172 #+STARTUP: lognotereschedule"
2174 :group
'org-progress
2176 (const :tag
"No logging" nil
)
2177 (const :tag
"Record timestamp" time
)
2178 (const :tag
"Record timestamp with note." note
)))
2180 (defcustom org-log-redeadline nil
2181 "Information to record when the deadline date of a tasks is modified.
2183 Possible values are:
2185 nil Don't add anything, just change the date
2186 time Add a time stamp to the task
2187 note Prompt for a note and add it with template `org-log-note-headings'
2189 This option can also be set with on a per-file-basis with
2191 #+STARTUP: nologredeadline
2192 #+STARTUP: logredeadline
2193 #+STARTUP: lognoteredeadline
2195 You can have local logging settings for a subtree by setting the LOGGING
2196 property to one or more of these keywords."
2198 :group
'org-progress
2200 (const :tag
"No logging" nil
)
2201 (const :tag
"Record timestamp" time
)
2202 (const :tag
"Record timestamp with note." note
)))
2204 (defcustom org-log-note-clock-out nil
2205 "Non-nil means record a note when clocking out of an item.
2206 This can also be configured on a per-file basis by adding one of
2207 the following lines anywhere in the buffer:
2209 #+STARTUP: lognoteclock-out
2210 #+STARTUP: nolognoteclock-out"
2212 :group
'org-progress
2215 (defcustom org-log-done-with-time t
2216 "Non-nil means the CLOSED time stamp will contain date and time.
2217 When nil, only the date will be recorded."
2218 :group
'org-progress
2221 (defcustom org-log-note-headings
2222 '((done .
"CLOSING NOTE %t")
2223 (state .
"State %-12s from %-12S %t")
2224 (note .
"Note taken on %t")
2225 (reschedule .
"Rescheduled from %S on %t")
2226 (delschedule .
"Not scheduled, was %S on %t")
2227 (redeadline .
"New deadline from %S on %t")
2228 (deldeadline .
"Removed deadline, was %S on %t")
2229 (refile .
"Refiled on %t")
2231 "Headings for notes added to entries.
2232 The value is an alist, with the car being a symbol indicating the note
2233 context, and the cdr is the heading to be used. The heading may also be the
2235 %t in the heading will be replaced by a time stamp.
2236 %T will be an acive time stamp instead the default inacive one
2237 %s will be replaced by the new TODO state, in double quotes.
2238 %S will be replaced by the old TODO state, in double quotes.
2239 %u will be replaced by the user name.
2240 %U will be replaced by the full user name.
2242 In fact, it is not a good idea to change the `state' entry, because
2243 agenda log mode depends on the format of these entries."
2245 :group
'org-progress
2246 :type
'(list :greedy t
2247 (cons (const :tag
"Heading when closing an item" done
) string
)
2249 "Heading when changing todo state (todo sequence only)"
2251 (cons (const :tag
"Heading when just taking a note" note
) string
)
2252 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2253 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2254 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2255 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2256 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2257 (cons (const :tag
"Heading when refiling" refile
) string
)))
2259 (unless (assq 'note org-log-note-headings
)
2260 (push '(note .
"%t") org-log-note-headings
))
2262 (defcustom org-log-into-drawer nil
2263 "Non-nil means insert state change notes and time stamps into a drawer.
2264 When nil, state changes notes will be inserted after the headline and
2265 any scheduling and clock lines, but not inside a drawer.
2267 The value of this variable should be the name of the drawer to use.
2268 LOGBOOK is proposed at the default drawer for this purpose, you can
2269 also set this to a string to define the drawer of your choice.
2271 A value of t is also allowed, representing \"LOGBOOK\".
2273 If this variable is set, `org-log-state-notes-insert-after-drawers'
2276 You can set the property LOG_INTO_DRAWER to overrule this setting for
2279 :group
'org-progress
2281 (const :tag
"Not into a drawer" nil
)
2282 (const :tag
"LOGBOOK" t
)
2283 (string :tag
"Other")))
2285 (if (fboundp 'defvaralias
)
2286 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2288 (defun org-log-into-drawer ()
2289 "Return the value of `org-log-into-drawer', but let properties overrule.
2290 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2291 used instead of the default value."
2292 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2294 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2295 ((equal p
"t") "LOGBOOK")
2298 (defcustom org-log-state-notes-insert-after-drawers nil
2299 "Non-nil means insert state change notes after any drawers in entry.
2300 Only the drawers that *immediately* follow the headline and the
2301 deadline/scheduled line are skipped.
2302 When nil, insert notes right after the heading and perhaps the line
2303 with deadline/scheduling if present.
2305 This variable will have no effect if `org-log-into-drawer' is
2308 :group
'org-progress
2311 (defcustom org-log-states-order-reversed t
2312 "Non-nil means the latest state note will be directly after heading.
2313 When nil, the state change notes will be ordered according to time."
2315 :group
'org-progress
2318 (defcustom org-todo-repeat-to-state nil
2319 "The TODO state to which a repeater should return the repeating task.
2320 By default this is the first task in a TODO sequence, or the previous state
2321 in a TODO_TYP set. But you can specify another task here.
2322 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2324 :type
'(choice (const :tag
"Head of sequence" nil
)
2325 (string :tag
"Specific state")))
2327 (defcustom org-log-repeat
'time
2328 "Non-nil means record moving through the DONE state when triggering repeat.
2329 An auto-repeating task is immediately switched back to TODO when
2330 marked DONE. If you are not logging state changes (by adding \"@\"
2331 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2332 record a closing note, there will be no record of the task moving
2333 through DONE. This variable forces taking a note anyway.
2335 nil Don't force a record
2336 time Record a time stamp
2339 This option can also be set with on a per-file-basis with
2341 #+STARTUP: logrepeat
2342 #+STARTUP: lognoterepeat
2343 #+STARTUP: nologrepeat
2345 You can have local logging settings for a subtree by setting the LOGGING
2346 property to one or more of these keywords."
2348 :group
'org-progress
2350 (const :tag
"Don't force a record" nil
)
2351 (const :tag
"Force recording the DONE state" time
)
2352 (const :tag
"Force recording a note with the DONE state" note
)))
2355 (defgroup org-priorities nil
2356 "Priorities in Org-mode."
2357 :tag
"Org Priorities"
2360 (defcustom org-enable-priority-commands t
2361 "Non-nil means priority commands are active.
2362 When nil, these commands will be disabled, so that you never accidentally
2364 :group
'org-priorities
2367 (defcustom org-highest-priority ?A
2368 "The highest priority of TODO items. A character like ?A, ?B etc.
2369 Must have a smaller ASCII number than `org-lowest-priority'."
2370 :group
'org-priorities
2373 (defcustom org-lowest-priority ?C
2374 "The lowest priority of TODO items. A character like ?A, ?B etc.
2375 Must have a larger ASCII number than `org-highest-priority'."
2376 :group
'org-priorities
2379 (defcustom org-default-priority ?B
2380 "The default priority of TODO items.
2381 This is the priority an item get if no explicit priority is given."
2382 :group
'org-priorities
2385 (defcustom org-priority-start-cycle-with-default t
2386 "Non-nil means start with default priority when starting to cycle.
2387 When this is nil, the first step in the cycle will be (depending on the
2388 command used) one higher or lower that the default priority."
2389 :group
'org-priorities
2392 (defgroup org-time nil
2393 "Options concerning time stamps and deadlines in Org-mode."
2397 (defcustom org-insert-labeled-timestamps-at-point nil
2398 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2399 When nil, these labeled time stamps are forces into the second line of an
2400 entry, just after the headline. When scheduling from the global TODO list,
2401 the time stamp will always be forced into the second line."
2405 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2406 "Formats for `format-time-string' which are used for time stamps.
2407 It is not recommended to change this constant.")
2409 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2410 "Number of minutes to round time stamps to.
2411 These are two values, the first applies when first creating a time stamp.
2412 The second applies when changing it with the commands `S-up' and `S-down'.
2413 When changing the time stamp, this means that it will change in steps
2414 of N minutes, as given by the second value.
2416 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2417 numbers should be factors of 60, so for example 5, 10, 15.
2419 When this is larger than 1, you can still force an exact time-stamp by using
2420 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2421 and by using a prefix arg to `S-up/down' to specify the exact number
2422 of minutes to shift."
2424 :get
'(lambda (var) ; Make sure both elements are there
2425 (if (integerp (default-value var
))
2426 (list (default-value var
) 5)
2427 (default-value var
)))
2429 (integer :tag
"when inserting times")
2430 (integer :tag
"when modifying times")))
2432 ;; Normalize old customizations of this variable.
2433 (when (integerp org-time-stamp-rounding-minutes
)
2434 (setq org-time-stamp-rounding-minutes
2435 (list org-time-stamp-rounding-minutes
2436 org-time-stamp-rounding-minutes
)))
2438 (defcustom org-display-custom-times nil
2439 "Non-nil means overlay custom formats over all time stamps.
2440 The formats are defined through the variable `org-time-stamp-custom-formats'.
2441 To turn this on on a per-file basis, insert anywhere in the file:
2442 #+STARTUP: customtime"
2446 (make-variable-buffer-local 'org-display-custom-times
)
2448 (defcustom org-time-stamp-custom-formats
2449 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2450 "Custom formats for time stamps. See `format-time-string' for the syntax.
2451 These are overlayed over the default ISO format if the variable
2452 `org-display-custom-times' is set. Time like %H:%M should be at the
2453 end of the second format. The custom formats are also honored by export
2454 commands, if custom time display is turned on at the time of export."
2458 (defun org-time-stamp-format (&optional long inactive
)
2459 "Get the right format for a time string."
2460 (let ((f (if long
(cdr org-time-stamp-formats
)
2461 (car org-time-stamp-formats
))))
2463 (concat "[" (substring f
1 -
1) "]")
2466 (defcustom org-time-clocksum-format
"%d:%02d"
2467 "The format string used when creating CLOCKSUM lines, or when
2468 org-mode generates a time duration."
2472 (defcustom org-time-clocksum-use-fractional nil
2473 "If non-nil, \\[org-clock-display] uses fractional times.
2474 org-mode generates a time duration."
2478 (defcustom org-time-clocksum-fractional-format
"%.2f"
2479 "The format string used when creating CLOCKSUM lines, or when
2480 org-mode generates a time duration."
2484 (defcustom org-deadline-warning-days
14
2485 "No. of days before expiration during which a deadline becomes active.
2486 This variable governs the display in sparse trees and in the agenda.
2487 When 0 or negative, it means use this number (the absolute value of it)
2488 even if a deadline has a different individual lead time specified.
2490 Custom commands can set this variable in the options section."
2492 :group
'org-agenda-daily
/weekly
2495 (defcustom org-read-date-prefer-future t
2496 "Non-nil means assume future for incomplete date input from user.
2497 This affects the following situations:
2498 1. The user gives a month but not a year.
2499 For example, if it is april and you enter \"feb 2\", this will be read
2500 as feb 2, *next* year. \"May 5\", however, will be this year.
2501 2. The user gives a day, but no month.
2502 For example, if today is the 15th, and you enter \"3\", Org-mode will
2503 read this as the third of *next* month. However, if you enter \"17\",
2504 it will be considered as *this* month.
2506 If you set this variable to the symbol `time', then also the following
2509 3. If the user gives a time, but no day. If the time is before now,
2510 to will be interpreted as tomorrow.
2512 Currently none of this works for ISO week specifications.
2514 When this option is nil, the current day, month and year will always be
2518 (const :tag
"Never" nil
)
2519 (const :tag
"Check month and day" t
)
2520 (const :tag
"Check month, day, and time" time
)))
2522 (defcustom org-read-date-display-live t
2523 "Non-nil means display current interpretation of date prompt live.
2524 This display will be in an overlay, in the minibuffer."
2528 (defcustom org-read-date-popup-calendar t
2529 "Non-nil means pop up a calendar when prompting for a date.
2530 In the calendar, the date can be selected with mouse-1. However, the
2531 minibuffer will also be active, and you can simply enter the date as well.
2532 When nil, only the minibuffer will be available."
2535 (if (fboundp 'defvaralias
)
2536 (defvaralias 'org-popup-calendar-for-date-prompt
2537 'org-read-date-popup-calendar
))
2539 (defcustom org-read-date-minibuffer-setup-hook nil
2540 "Hook to be used to set up keys for the date/time interface.
2541 Add key definitions to `minibuffer-local-map', which will be a temporary
2546 (defcustom org-extend-today-until
0
2547 "The hour when your day really ends. Must be an integer.
2548 This has influence for the following applications:
2549 - When switching the agenda to \"today\". It it is still earlier than
2550 the time given here, the day recognized as TODAY is actually yesterday.
2551 - When a date is read from the user and it is still before the time given
2552 here, the current date and time will be assumed to be yesterday, 23:59.
2553 Also, timestamps inserted in remember templates follow this rule.
2555 IMPORTANT: This is a feature whose implementation is and likely will
2556 remain incomplete. Really, it is only here because past midnight seems to
2557 be the favorite working time of John Wiegley :-)"
2561 (defcustom org-edit-timestamp-down-means-later nil
2562 "Non-nil means S-down will increase the time in a time stamp.
2563 When nil, S-up will increase."
2567 (defcustom org-calendar-follow-timestamp-change t
2568 "Non-nil means make the calendar window follow timestamp changes.
2569 When a timestamp is modified and the calendar window is visible, it will be
2570 moved to the new date."
2574 (defgroup org-tags nil
2575 "Options concerning tags in Org-mode."
2579 (defcustom org-tag-alist nil
2580 "List of tags allowed in Org-mode files.
2581 When this list is nil, Org-mode will base TAG input on what is already in the
2583 The value of this variable is an alist, the car of each entry must be a
2584 keyword as a string, the cdr may be a character that is used to select
2585 that tag through the fast-tag-selection interface.
2586 See the manual for details."
2590 (cons (string :tag
"Tag name")
2591 (character :tag
"Access char"))
2592 (list :tag
"Start radio group"
2594 (option (string :tag
"Group description")))
2595 (list :tag
"End radio group"
2597 (option (string :tag
"Group description")))
2598 (const :tag
"New line" (:newline
)))))
2600 (defcustom org-tag-persistent-alist nil
2601 "List of tags that will always appear in all Org-mode files.
2602 This is in addition to any in buffer settings or customizations
2604 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2605 The value of this variable is an alist, the car of each entry must be a
2606 keyword as a string, the cdr may be a character that is used to select
2607 that tag through the fast-tag-selection interface.
2608 See the manual for details.
2609 To disable these tags on a per-file basis, insert anywhere in the file:
2614 (cons (string :tag
"Tag name")
2615 (character :tag
"Access char"))
2616 (const :tag
"Start radio group" (:startgroup
))
2617 (const :tag
"End radio group" (:endgroup
))
2618 (const :tag
"New line" (:newline
)))))
2620 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2621 "If non-nil, always offer completion for all tags of all agenda files.
2622 Instead of customizing this variable directly, you might want to
2623 set it locally for remember buffers, because there no list of
2624 tags in that file can be created dynamically (there are none).
2626 (add-hook 'org-remember-mode-hook
2628 (set (make-local-variable
2629 'org-complete-tags-always-offer-all-agenda-tags)
2634 (defvar org-file-tags nil
2635 "List of tags that can be inherited by all entries in the file.
2636 The tags will be inherited if the variable `org-use-tag-inheritance'
2637 says they should be.
2638 This variable is populated from #+FILETAGS lines.")
2640 (defcustom org-use-fast-tag-selection
'auto
2641 "Non-nil means use fast tag selection scheme.
2642 This is a special interface to select and deselect tags with single keys.
2643 When nil, fast selection is never used.
2644 When the symbol `auto', fast selection is used if and only if selection
2645 characters for tags have been configured, either through the variable
2646 `org-tag-alist' or through a #+TAGS line in the buffer.
2647 When t, fast selection is always used and selection keys are assigned
2648 automatically if necessary."
2651 (const :tag
"Always" t
)
2652 (const :tag
"Never" nil
)
2653 (const :tag
"When selection characters are configured" 'auto
)))
2655 (defcustom org-fast-tag-selection-single-key nil
2656 "Non-nil means fast tag selection exits after first change.
2657 When nil, you have to press RET to exit it.
2658 During fast tag selection, you can toggle this flag with `C-c'.
2659 This variable can also have the value `expert'. In this case, the window
2660 displaying the tags menu is not even shown, until you press C-c again."
2663 (const :tag
"No" nil
)
2664 (const :tag
"Yes" t
)
2665 (const :tag
"Expert" expert
)))
2667 (defvar org-fast-tag-selection-include-todo nil
2668 "Non-nil means fast tags selection interface will also offer TODO states.
2669 This is an undocumented feature, you should not rely on it.")
2671 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2672 "The column to which tags should be indented in a headline.
2673 If this number is positive, it specifies the column. If it is negative,
2674 it means that the tags should be flushright to that column. For example,
2675 -80 works well for a normal 80 character screen."
2679 (defcustom org-auto-align-tags t
2680 "Non-nil means realign tags after pro/demotion of TODO state change.
2681 These operations change the length of a headline and therefore shift
2682 the tags around. With this options turned on, after each such operation
2683 the tags are again aligned to `org-tags-column'."
2687 (defcustom org-use-tag-inheritance t
2688 "Non-nil means tags in levels apply also for sublevels.
2689 When nil, only the tags directly given in a specific line apply there.
2690 This may also be a list of tags that should be inherited, or a regexp that
2691 matches tags that should be inherited. Additional control is possible
2692 with the variable `org-tags-exclude-from-inheritance' which gives an
2693 explicit list of tags to be excluded from inheritance., even if the value of
2694 `org-use-tag-inheritance' would select it for inheritance.
2696 If this option is t, a match early-on in a tree can lead to a large
2697 number of matches in the subtree when constructing the agenda or creating
2698 a sparse tree. If you only want to see the first match in a tree during
2699 a search, check out the variable `org-tags-match-list-sublevels'."
2702 (const :tag
"Not" nil
)
2703 (const :tag
"Always" t
)
2704 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2705 (regexp :tag
"Tags matched by regexp")))
2707 (defcustom org-tags-exclude-from-inheritance nil
2708 "List of tags that should never be inherited.
2709 This is a way to exclude a few tags from inheritance. For way to do
2710 the opposite, to actively allow inheritance for selected tags,
2711 see the variable `org-use-tag-inheritance'."
2713 :type
'(repeat (string :tag
"Tag")))
2715 (defun org-tag-inherit-p (tag)
2716 "Check if TAG is one that should be inherited."
2718 ((member tag org-tags-exclude-from-inheritance
) nil
)
2719 ((eq org-use-tag-inheritance t
) t
)
2720 ((not org-use-tag-inheritance
) nil
)
2721 ((stringp org-use-tag-inheritance
)
2722 (string-match org-use-tag-inheritance tag
))
2723 ((listp org-use-tag-inheritance
)
2724 (member tag org-use-tag-inheritance
))
2725 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2727 (defcustom org-tags-match-list-sublevels t
2728 "Non-nil means list also sublevels of headlines matching a search.
2729 This variable applies to tags/property searches, and also to stuck
2730 projects because this search is based on a tags match as well.
2732 When set to the symbol `indented', sublevels are indented with
2735 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2736 the sublevels of a headline matching a tag search often also match
2737 the same search. Listing all of them can create very long lists.
2738 Setting this variable to nil causes subtrees of a match to be skipped.
2740 This variable is semi-obsolete and probably should always be true. It
2741 is better to limit inheritance to certain tags using the variables
2742 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2745 (const :tag
"No, don't list them" nil
)
2746 (const :tag
"Yes, do list them" t
)
2747 (const :tag
"List them, indented with leading dots" indented
)))
2749 (defcustom org-tags-sort-function nil
2750 "When set, tags are sorted using this function as a comparator"
2753 (const :tag
"No sorting" nil
)
2754 (const :tag
"Alphabetical" string
<)
2755 (const :tag
"Reverse alphabetical" string
>)
2756 (function :tag
"Custom function" nil
)))
2758 (defvar org-tags-history nil
2759 "History of minibuffer reads for tags.")
2760 (defvar org-last-tags-completion-table nil
2761 "The last used completion table for tags.")
2762 (defvar org-after-tags-change-hook nil
2763 "Hook that is run after the tags in a line have changed.")
2765 (defgroup org-properties nil
2766 "Options concerning properties in Org-mode."
2767 :tag
"Org Properties"
2770 (defcustom org-property-format
"%-10s %s"
2771 "How property key/value pairs should be formatted by `indent-line'.
2772 When `indent-line' hits a property definition, it will format the line
2773 according to this format, mainly to make sure that the values are
2774 lined-up with respect to each other."
2775 :group
'org-properties
2778 (defcustom org-use-property-inheritance nil
2779 "Non-nil means properties apply also for sublevels.
2781 This setting is chiefly used during property searches. Turning it on can
2782 cause significant overhead when doing a search, which is why it is not
2785 When nil, only the properties directly given in the current entry count.
2786 When t, every property is inherited. The value may also be a list of
2787 properties that should have inheritance, or a regular expression matching
2788 properties that should be inherited.
2790 However, note that some special properties use inheritance under special
2791 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2792 and the properties ending in \"_ALL\" when they are used as descriptor
2793 for valid values of a property.
2795 Note for programmers:
2796 When querying an entry with `org-entry-get', you can control if inheritance
2797 should be used. By default, `org-entry-get' looks only at the local
2798 properties. You can request inheritance by setting the inherit argument
2799 to t (to force inheritance) or to `selective' (to respect the setting
2801 :group
'org-properties
2803 (const :tag
"Not" nil
)
2804 (const :tag
"Always" t
)
2805 (repeat :tag
"Specific properties" (string :tag
"Property"))
2806 (regexp :tag
"Properties matched by regexp")))
2808 (defun org-property-inherit-p (property)
2809 "Check if PROPERTY is one that should be inherited."
2811 ((eq org-use-property-inheritance t
) t
)
2812 ((not org-use-property-inheritance
) nil
)
2813 ((stringp org-use-property-inheritance
)
2814 (string-match org-use-property-inheritance property
))
2815 ((listp org-use-property-inheritance
)
2816 (member property org-use-property-inheritance
))
2817 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2819 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2820 "The default column format, if no other format has been defined.
2821 This variable can be set on the per-file basis by inserting a line
2823 #+COLUMNS: %25ITEM ....."
2824 :group
'org-properties
2827 (defcustom org-columns-ellipses
".."
2828 "The ellipses to be used when a field in column view is truncated.
2829 When this is the empty string, as many characters as possible are shown,
2830 but then there will be no visual indication that the field has been truncated.
2831 When this is a string of length N, the last N characters of a truncated
2832 field are replaced by this string. If the column is narrower than the
2833 ellipses string, only part of the ellipses string will be shown."
2834 :group
'org-properties
2837 (defcustom org-columns-modify-value-for-display-function nil
2838 "Function that modifies values for display in column view.
2839 For example, it can be used to cut out a certain part from a time stamp.
2840 The function must take 2 arguments:
2842 column-title The title of the column (*not* the property name)
2843 value The value that should be modified.
2845 The function should return the value that should be displayed,
2846 or nil if the normal value should be used."
2847 :group
'org-properties
2850 (defcustom org-effort-property
"Effort"
2851 "The property that is being used to keep track of effort estimates.
2852 Effort estimates given in this property need to have the format H:MM."
2853 :group
'org-properties
2854 :group
'org-progress
2855 :type
'(string :tag
"Property"))
2857 (defconst org-global-properties-fixed
2858 '(("VISIBILITY_ALL" .
"folded children content all")
2859 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2860 "List of property/value pairs that can be inherited by any entry.
2862 These are fixed values, for the preset properties. The user variable
2863 that can be used to add to this list is `org-global-properties'.
2865 The entries in this list are cons cells where the car is a property
2866 name and cdr is a string with the value. If the value represents
2867 multiple items like an \"_ALL\" property, separate the items by
2870 (defcustom org-global-properties nil
2871 "List of property/value pairs that can be inherited by any entry.
2873 This list will be combined with the constant `org-global-properties-fixed'.
2875 The entries in this list are cons cells where the car is a property
2876 name and cdr is a string with the value.
2878 You can set buffer-local values for the same purpose in the variable
2879 `org-file-properties' this by adding lines like
2881 #+PROPERTY: NAME VALUE"
2882 :group
'org-properties
2884 (cons (string :tag
"Property")
2885 (string :tag
"Value"))))
2887 (defvar org-file-properties nil
2888 "List of property/value pairs that can be inherited by any entry.
2889 Valid for the current buffer.
2890 This variable is populated from #+PROPERTY lines.")
2891 (make-variable-buffer-local 'org-file-properties
)
2893 (defgroup org-agenda nil
2894 "Options concerning agenda views in Org-mode."
2898 (defvar org-category nil
2899 "Variable used by org files to set a category for agenda display.
2900 Such files should use a file variable to set it, for example
2902 # -*- mode: org; org-category: \"ELisp\"
2904 or contain a special line
2908 If the file does not specify a category, then file's base name
2910 (make-variable-buffer-local 'org-category
)
2911 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2913 (defcustom org-agenda-files nil
2914 "The files to be used for agenda display.
2915 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2916 \\[org-remove-file]. You can also use customize to edit the list.
2918 If an entry is a directory, all files in that directory that are matched by
2919 `org-agenda-file-regexp' will be part of the file list.
2921 If the value of the variable is not a list but a single file name, then
2922 the list of agenda files is actually stored and maintained in that file, one
2923 agenda file per line. In this file paths can be given relative to
2924 `org-directory'. Tilde expansion and environment variable substitution
2928 (repeat :tag
"List of files and directories" file
)
2929 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2931 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2932 "Regular expression to match files for `org-agenda-files'.
2933 If any element in the list in that variable contains a directory instead
2934 of a normal file, all files in that directory that are matched by this
2935 regular expression will be included."
2939 (defcustom org-agenda-text-search-extra-files nil
2940 "List of extra files to be searched by text search commands.
2941 These files will be search in addition to the agenda files by the
2942 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2943 Note that these files will only be searched for text search commands,
2944 not for the other agenda views like todo lists, tag searches or the weekly
2945 agenda. This variable is intended to list notes and possibly archive files
2946 that should also be searched by these two commands.
2947 In fact, if the first element in the list is the symbol `agenda-archives',
2948 than all archive files of all agenda files will be added to the search
2951 :type
'(set :greedy t
2952 (const :tag
"Agenda Archives" agenda-archives
)
2953 (repeat :inline t
(file))))
2955 (if (fboundp 'defvaralias
)
2956 (defvaralias 'org-agenda-multi-occur-extra-files
2957 'org-agenda-text-search-extra-files
))
2959 (defcustom org-agenda-skip-unavailable-files nil
2960 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2961 A nil value means to remove them, after a query, from the list."
2965 (defcustom org-calendar-to-agenda-key
[?c
]
2966 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2967 The command `org-calendar-goto-agenda' will be bound to this key. The
2968 default is the character `c' because then `c' can be used to switch back and
2969 forth between agenda and calendar."
2973 (defcustom org-calendar-agenda-action-key
[?k
]
2974 "The key to be installed in `calendar-mode-map' for agenda-action.
2975 The command `org-agenda-action' will be bound to this key. The
2976 default is the character `k' because we use the same key in the agenda."
2980 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2981 "The key to be installed in `calendar-mode-map' for adding diary entries.
2982 This option is irrelevant until `org-agenda-diary-file' has been configured
2983 to point to an Org-mode file. When that is the case, the command
2984 `org-agenda-diary-entry' will be bound to the key given here, by default
2985 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2986 if you want to continue doing this, you need to change this to a different
2991 (defcustom org-agenda-diary-file
'diary-file
2992 "File to which to add new entries with the `i' key in agenda and calendar.
2993 When this is the symbol `diary-file', the functionality in the Emacs
2994 calendar will be used to add entries to the `diary-file'. But when this
2995 points to a file, `org-agenda-diary-entry' will be used instead."
2998 (const :tag
"The standard Emacs diary file" diary-file
)
2999 (file :tag
"Special Org file diary entries")))
3001 (eval-after-load "calendar"
3003 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3004 'org-calendar-goto-agenda
)
3005 (org-defkey calendar-mode-map org-calendar-agenda-action-key
3007 (add-hook 'calendar-mode-hook
3009 (unless (eq org-agenda-diary-file
'diary-file
)
3010 (define-key calendar-mode-map
3011 org-calendar-insert-diary-entry-key
3012 'org-agenda-diary-entry
))))))
3014 (defgroup org-latex nil
3015 "Options for embedding LaTeX code into Org-mode."
3019 (defcustom org-format-latex-options
3020 '(:foreground default
:background default
:scale
1.0
3021 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
3022 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3023 "Options for creating images from LaTeX fragments.
3024 This is a property list with the following properties:
3025 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3026 `default' means use the foreground of the default face.
3027 :background the background color, or \"Transparent\".
3028 `default' means use the background of the default face.
3029 :scale a scaling factor for the size of the images.
3030 :html-foreground, :html-background, :html-scale
3031 the same numbers for HTML export.
3032 :matchers a list indicating which matchers should be used to
3033 find LaTeX fragments. Valid members of this list are:
3034 \"begin\" find environments
3035 \"$1\" find single characters surrounded by $.$
3036 \"$\" find math expressions surrounded by $...$
3037 \"$$\" find math expressions surrounded by $$....$$
3038 \"\\(\" find math expressions surrounded by \\(...\\)
3039 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3043 (defcustom org-format-latex-signal-error t
3044 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3045 When nil, just push out a message."
3049 (defcustom org-format-latex-header
"\\documentclass{article}
3050 \\usepackage[usenames]{color}
3051 \\usepackage{amsmath}
3052 \\usepackage[mathscr]{eucal}
3053 \\pagestyle{empty} % do not remove
3056 % The settings below are copied from fullpage.sty
3057 \\setlength{\\textwidth}{\\paperwidth}
3058 \\addtolength{\\textwidth}{-3cm}
3059 \\setlength{\\oddsidemargin}{1.5cm}
3060 \\addtolength{\\oddsidemargin}{-2.54cm}
3061 \\setlength{\\evensidemargin}{\\oddsidemargin}
3062 \\setlength{\\textheight}{\\paperheight}
3063 \\addtolength{\\textheight}{-\\headheight}
3064 \\addtolength{\\textheight}{-\\headsep}
3065 \\addtolength{\\textheight}{-\\footskip}
3066 \\addtolength{\\textheight}{-3cm}
3067 \\setlength{\\topmargin}{1.5cm}
3068 \\addtolength{\\topmargin}{-2.54cm}"
3069 "The document header used for processing LaTeX fragments.
3070 It is imperative that this header make sure that no page number
3071 appears on the page. The package defined in the variables
3072 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
3073 will either replace the placeholder \"[PACKAGES]\" in this header, or they
3078 (defvar org-format-latex-header-extra nil
)
3080 (defun org-set-packages-alist (var val
)
3081 "Set the packages alist and make sure it has 3 elements per entry."
3082 (set var
(mapcar (lambda (x)
3083 (if (and (consp x
) (= (length x
) 2))
3084 (list (car x
) (nth 1 x
) t
)
3088 (defun org-get-packages-alist (var)
3090 "Get the packages alist and make sure it has 3 elements per entry."
3092 (if (and (consp x
) (= (length x
) 2))
3093 (list (car x
) (nth 1 x
) t
)
3095 (default-value var
)))
3097 ;; The following variables are defined here because is it also used
3098 ;; when formatting latex fragments. Originally it was part of the
3099 ;; LaTeX exporter, which is why the name includes "export".
3100 (defcustom org-export-latex-default-packages-alist
3101 '(("AUTO" "inputenc" t
)
3105 ("" "longtable" nil
)
3118 "Alist of default packages to be inserted in the header.
3119 Change this only if one of the packages here causes an incompatibility
3120 with another package you are using.
3121 The packages in this list are needed by one part or another of Org-mode
3122 to function properly.
3124 - inputenc, fontenc, t1enc: for basic font and character selection
3125 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3126 for interpreting the entities in `org-entities'. You can skip some of these
3127 packages if you don't use any of the symbols in it.
3128 - graphicx: for including images
3129 - float, wrapfig: for figure placement
3130 - longtable: for long tables
3131 - hyperref: for cross references
3133 Therefore you should not modify this variable unless you know what you
3134 are doing. The one reason to change it anyway is that you might be loading
3135 some other package that conflicts with one of the default packages.
3136 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3137 If SNIPPET-FLAG is t, the package also needs to be included when
3138 compiling LaTeX snippets into images for inclusion into HTML."
3139 :group
'org-export-latex
3140 :set
'org-set-packages-alist
3141 :get
'org-get-packages-alist
3144 (list :tag
"options/package pair"
3145 (string :tag
"options")
3146 (string :tag
"package")
3147 (boolean :tag
"Snippet"))
3148 (string :tag
"A line of LaTeX"))))
3150 (defcustom org-export-latex-packages-alist nil
3151 "Alist of packages to be inserted in every LaTeX header.
3152 These will be inserted after `org-export-latex-default-packages-alist'.
3153 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3154 SNIPPET-FLAG, when t, indicates that this package is also needed when
3155 turning LaTeX snippets into images for inclusion into HTML.
3156 Make sure that you only list packages here which:
3157 - you want in every file
3158 - do not conflict with the default packages in
3159 `org-export-latex-default-packages-alist'
3160 - do not conflict with the setup in `org-format-latex-header'."
3161 :group
'org-export-latex
3162 :set
'org-set-packages-alist
3163 :get
'org-get-packages-alist
3166 (list :tag
"options/package pair"
3167 (string :tag
"options")
3168 (string :tag
"package")
3169 (boolean :tag
"Snippet"))
3170 (string :tag
"A line of LaTeX"))))
3173 (defgroup org-appearance nil
3174 "Settings for Org-mode appearance."
3175 :tag
"Org Appearance"
3178 (defcustom org-level-color-stars-only nil
3179 "Non-nil means fontify only the stars in each headline.
3180 When nil, the entire headline is fontified.
3181 Changing it requires restart of `font-lock-mode' to become effective
3182 also in regions already fontified."
3183 :group
'org-appearance
3186 (defcustom org-hide-leading-stars nil
3187 "Non-nil means hide the first N-1 stars in a headline.
3188 This works by using the face `org-hide' for these stars. This
3189 face is white for a light background, and black for a dark
3190 background. You may have to customize the face `org-hide' to
3192 Changing it requires restart of `font-lock-mode' to become effective
3193 also in regions already fontified.
3194 You may also set this on a per-file basis by adding one of the following
3195 lines to the buffer:
3197 #+STARTUP: hidestars
3198 #+STARTUP: showstars"
3199 :group
'org-appearance
3202 (defcustom org-hidden-keywords nil
3203 "List of keywords that should be hidden when typed in the org buffer.
3204 For example, add #+TITLE to this list in order to make the
3205 document title appear in the buffer without the initial #+TITLE:
3207 :group
'org-appearance
3208 :type
'(set (const :tag
"#+AUTHOR" author
)
3209 (const :tag
"#+DATE" date
)
3210 (const :tag
"#+EMAIL" email
)
3211 (const :tag
"#+TITLE" title
)))
3213 (defcustom org-fontify-done-headline nil
3214 "Non-nil means change the face of a headline if it is marked DONE.
3215 Normally, only the TODO/DONE keyword indicates the state of a headline.
3216 When this is non-nil, the headline after the keyword is set to the
3217 `org-headline-done' as an additional indication."
3218 :group
'org-appearance
3221 (defcustom org-fontify-emphasized-text t
3222 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3223 Changing this variable requires a restart of Emacs to take effect."
3224 :group
'org-appearance
3227 (defcustom org-fontify-whole-heading-line nil
3228 "Non-nil means fontify the whole line for headings.
3229 This is useful when setting a background color for the
3231 :group
'org-appearance
3234 (defcustom org-highlight-latex-fragments-and-specials nil
3235 "Non-nil means fontify what is treated specially by the exporters."
3236 :group
'org-appearance
3239 (defcustom org-hide-emphasis-markers nil
3240 "Non-nil mean font-lock should hide the emphasis marker characters."
3241 :group
'org-appearance
3244 (defcustom org-pretty-entities nil
3245 "Non-nil means show entities as UTF8 characters.
3246 When nil, the \\name form remains in the buffer."
3247 :group
'org-appearance
3250 (defcustom org-pretty-entities-include-sub-superscripts t
3251 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3252 :group
'org-appearance
3255 (defvar org-emph-re nil
3256 "Regular expression for matching emphasis.
3257 After a match, the match groups contain these elements:
3258 1 The character before the proper match, or empty at beginning of line
3259 2 The proper match, including the leading and trailing markers
3260 3 The leading marker like * or /, indicating the type of highlighting
3261 4 The text between the emphasis markers, not including the markers
3262 5 The character after the match, empty at the end of a line")
3263 (defvar org-verbatim-re nil
3264 "Regular expression for matching verbatim text.")
3265 (defvar org-emphasis-regexp-components
) ; defined just below
3266 (defvar org-emphasis-alist
) ; defined just below
3267 (defun org-set-emph-re (var val
)
3268 "Set variable and compute the emphasis regular expression."
3270 (when (and (boundp 'org-emphasis-alist
)
3271 (boundp 'org-emphasis-regexp-components
)
3272 org-emphasis-alist org-emphasis-regexp-components
)
3273 (let* ((e org-emphasis-regexp-components
)
3279 (body1 (concat body
"*?"))
3280 (markers (mapconcat 'car org-emphasis-alist
""))
3281 (vmarkers (mapconcat
3282 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3283 org-emphasis-alist
"")))
3284 ;; make sure special characters appear at the right position in the class
3285 (if (string-match "\\^" markers
)
3286 (setq markers
(concat (replace-match "" t t markers
) "^")))
3287 (if (string-match "-" markers
)
3288 (setq markers
(concat (replace-match "" t t markers
) "-")))
3289 (if (string-match "\\^" vmarkers
)
3290 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3291 (if (string-match "-" vmarkers
)
3292 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3294 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3295 (int-to-string nl
) "\\}")))
3298 (concat "\\([" pre
"]\\|^\\)"
3300 "\\([" markers
"]\\)"
3308 "\\([" post
"]\\|$\\)"))
3309 (setq org-verbatim-re
3310 (concat "\\([" pre
"]\\|^\\)"
3312 "\\([" vmarkers
"]\\)"
3320 "\\([" post
"]\\|$\\)")))))
3322 (defcustom org-emphasis-regexp-components
3323 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3324 "Components used to build the regular expression for emphasis.
3325 This is a list with 6 entries. Terminology: In an emphasis string
3326 like \" *strong word* \", we call the initial space PREMATCH, the final
3327 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3328 and \"trong wor\" is the body. The different components in this variable
3329 specify what is allowed/forbidden in each part:
3331 pre Chars allowed as prematch. Beginning of line will be allowed too.
3332 post Chars allowed as postmatch. End of line will be allowed too.
3333 border The chars *forbidden* as border characters.
3334 body-regexp A regexp like \".\" to match a body character. Don't use
3335 non-shy groups here, and don't allow newline here.
3336 newline The maximum number of newlines allowed in an emphasis exp.
3338 Use customize to modify this, or restart Emacs after changing it."
3339 :group
'org-appearance
3340 :set
'org-set-emph-re
3342 (sexp :tag
"Allowed chars in pre ")
3343 (sexp :tag
"Allowed chars in post ")
3344 (sexp :tag
"Forbidden chars in border ")
3345 (sexp :tag
"Regexp for body ")
3346 (integer :tag
"number of newlines allowed")
3347 (option (boolean :tag
"Please ignore this button"))))
3349 (defcustom org-emphasis-alist
3350 `(("*" bold
"<b>" "</b>")
3351 ("/" italic
"<i>" "</i>")
3352 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3353 ("=" org-code
"<code>" "</code>" verbatim
)
3354 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3355 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3358 "Special syntax for emphasized text.
3359 Text starting and ending with a special character will be emphasized, for
3360 example *bold*, _underlined_ and /italic/. This variable sets the marker
3361 characters, the face to be used by font-lock for highlighting in Org-mode
3362 Emacs buffers, and the HTML tags to be used for this.
3363 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3364 For DocBook export, see the variable `org-export-docbook-emphasis-alist'.
3365 Use customize to modify this, or restart Emacs after changing it."
3366 :group
'org-appearance
3367 :set
'org-set-emph-re
3370 (string :tag
"Marker character")
3372 (face :tag
"Font-lock-face")
3373 (plist :tag
"Face property list"))
3374 (string :tag
"HTML start tag")
3375 (string :tag
"HTML end tag")
3376 (option (const verbatim
)))))
3378 (defvar org-protecting-blocks
3379 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3380 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3381 This is needed for font-lock setup.")
3383 ;;; Miscellaneous options
3385 (defgroup org-completion nil
3386 "Completion in Org-mode."
3387 :tag
"Org Completion"
3390 (defcustom org-completion-use-ido nil
3391 "Non-nil means use ido completion wherever possible.
3392 Note that `ido-mode' must be active for this variable to be relevant.
3393 If you decide to turn this variable on, you might well want to turn off
3394 `org-outline-path-complete-in-steps'.
3395 See also `org-completion-use-iswitchb'."
3396 :group
'org-completion
3399 (defcustom org-completion-use-iswitchb nil
3400 "Non-nil means use iswitchb completion wherever possible.
3401 Note that `iswitchb-mode' must be active for this variable to be relevant.
3402 If you decide to turn this variable on, you might well want to turn off
3403 `org-outline-path-complete-in-steps'.
3404 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3405 :group
'org-completion
3408 (defcustom org-completion-fallback-command
'hippie-expand
3409 "The expansion command called by \\[org-complete] in normal context.
3410 Normal means no org-mode-specific context."
3411 :group
'org-completion
3414 ;;; Functions and variables from their packages
3415 ;; Declared here to avoid compiler warnings
3418 (defvar outline-mode-menu-heading
)
3419 (defvar outline-mode-menu-show
)
3420 (defvar outline-mode-menu-hide
)
3421 (defvar zmacs-regions
) ; XEmacs regions
3424 (defvar mark-active
)
3427 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3428 (declare-function calendar-forward-day
"cal-move" (arg))
3429 (declare-function calendar-goto-date
"cal-move" (date))
3430 (declare-function calendar-goto-today
"cal-move" ())
3431 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3432 (defvar calc-embedded-close-formula
)
3433 (defvar calc-embedded-open-formula
)
3434 (declare-function cdlatex-tab
"ext:cdlatex" ())
3435 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3436 (defvar font-lock-unfontify-region-function
)
3437 (declare-function iswitchb-read-buffer
"iswitchb"
3438 (prompt &optional default require-match start matches-set
))
3439 (defvar iswitchb-temp-buflist
)
3440 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3441 (defvar org-agenda-tags-todo-honor-ignore-options
)
3442 (declare-function org-agenda-skip
"org-agenda" ())
3444 org-format-agenda-item
"org-agenda"
3445 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3446 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3447 (declare-function org-agenda-change-all-lines
"org-agenda"
3448 (newhead hdmarker
&optional fixface just-this
))
3449 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3450 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3451 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3453 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3454 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3455 "org-agenda" (&optional end
))
3456 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3457 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3458 (declare-function parse-time-string
"parse-time" (string))
3459 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3460 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3461 (defvar remember-data-file
)
3462 (defvar texmathp-why
)
3463 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3464 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3466 (defvar w3m-current-url
)
3467 (defvar w3m-current-title
)
3469 (defvar org-latex-regexps
)
3471 ;;; Autoload and prepare some org modules
3473 ;; Some table stuff that needs to be defined here, because it is used
3474 ;; by the functions setting up org-mode or checking for table context.
3476 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3477 "Detects an org-type or table-type table.")
3478 (defconst org-table-line-regexp
"^[ \t]*|"
3479 "Detects an org-type table line.")
3480 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3481 "Detects an org-type table line.")
3482 (defconst org-table-hline-regexp
"^[ \t]*|-"
3483 "Detects an org-type table hline.")
3484 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3485 "Detects a table-type table hline.")
3486 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3487 "Searching from within a table (any type) this finds the first line
3488 outside the table.")
3490 ;; Autoload the functions in org-table.el that are needed by functions here.
3493 (org-autoload "org-table"
3494 '(org-table-align org-table-begin org-table-blank-field
3495 org-table-convert org-table-convert-region org-table-copy-down
3496 org-table-copy-region org-table-create
3497 org-table-create-or-convert-from-region
3498 org-table-create-with-table.el org-table-current-dline
3499 org-table-cut-region org-table-delete-column org-table-edit-field
3500 org-table-edit-formulas org-table-end org-table-eval-formula
3501 org-table-export org-table-field-info
3502 org-table-get-stored-formulas org-table-goto-column
3503 org-table-hline-and-move org-table-import org-table-insert-column
3504 org-table-insert-hline org-table-insert-row org-table-iterate
3505 org-table-justify-field-maybe org-table-kill-row
3506 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3507 org-table-move-column org-table-move-column-left
3508 org-table-move-column-right org-table-move-row
3509 org-table-move-row-down org-table-move-row-up
3510 org-table-next-field org-table-next-row org-table-paste-rectangle
3511 org-table-previous-field org-table-recalculate
3512 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3513 org-table-toggle-coordinate-overlays
3514 org-table-toggle-formula-debugger org-table-wrap-region
3515 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3517 (defun org-at-table-p (&optional table-type
)
3518 "Return t if the cursor is inside an org-type table.
3519 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3520 (if org-enable-table-editor
3522 (beginning-of-line 1)
3523 (looking-at (if table-type org-table-any-line-regexp
3524 org-table-line-regexp
)))
3526 (defsubst org-table-p
() (org-at-table-p))
3528 (defun org-at-table.el-p
()
3529 "Return t if and only if we are at a table.el table."
3530 (and (org-at-table-p 'any
)
3532 (goto-char (org-table-begin 'any
))
3533 (looking-at org-table1-hline-regexp
))))
3534 (defun org-table-recognize-table.el
()
3535 "If there is a table.el table nearby, recognize it and move into it."
3536 (if org-table-tab-recognizes-table.el
3537 (if (org-at-table.el-p
)
3539 (beginning-of-line 1)
3540 (if (looking-at org-table-dataline-regexp
)
3542 (if (looking-at org-table1-hline-regexp
)
3544 (beginning-of-line 2)
3545 (if (looking-at org-table-any-border-regexp
)
3546 (beginning-of-line -
1)))))
3547 (if (re-search-forward "|" (org-table-end t
) t
)
3550 (if (table--at-cell-p (point))
3552 (message "recognizing table.el table...")
3553 (table-recognize-table)
3554 (message "recognizing table.el table...done")))
3555 (error "This should not happen..."))
3560 (defun org-at-table-hline-p ()
3561 "Return t if the cursor is inside a hline in a table."
3562 (if org-enable-table-editor
3564 (beginning-of-line 1)
3565 (looking-at org-table-hline-regexp
))
3568 (defvar org-table-clean-did-remove-column nil
)
3570 (defun org-table-map-tables (function &optional quietly
)
3571 "Apply FUNCTION to the start of all tables in the buffer."
3575 (goto-char (point-min))
3576 (while (re-search-forward org-table-any-line-regexp nil t
)
3578 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3579 (beginning-of-line 1)
3580 (when (looking-at org-table-line-regexp
)
3581 (save-excursion (funcall function
))
3582 (or (looking-at org-table-line-regexp
)
3584 (re-search-forward org-table-any-border-regexp nil
1))))
3585 (unless quietly
(message "Mapping tables: done")))
3587 ;; Declare and autoload functions from org-exp.el & Co
3589 (declare-function org-default-export-plist
"org-exp")
3590 (declare-function org-infile-export-plist
"org-exp")
3591 (declare-function org-get-current-options
"org-exp")
3593 (org-autoload "org-exp"
3594 '(org-export org-export-visible
3595 org-insert-export-options-template
3596 org-table-clean-before-export
))
3597 (org-autoload "org-ascii"
3598 '(org-export-as-ascii org-export-ascii-preprocess
3599 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3600 org-export-region-as-ascii
))
3601 (org-autoload "org-latex"
3602 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3603 org-replace-region-by-latex org-export-region-as-latex
3604 org-export-as-latex org-export-as-pdf
3605 org-export-as-pdf-and-open
))
3606 (org-autoload "org-html"
3607 '(org-export-as-html-and-open
3608 org-export-as-html-batch org-export-as-html-to-buffer
3609 org-replace-region-by-html org-export-region-as-html
3610 org-export-as-html
))
3611 (org-autoload "org-docbook"
3612 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3613 org-replace-region-by-docbook org-export-region-as-docbook
3614 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3615 org-export-as-docbook
))
3616 (org-autoload "org-icalendar"
3617 '(org-export-icalendar-this-file
3618 org-export-icalendar-all-agenda-files
3619 org-export-icalendar-combine-agenda-files
))
3620 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3621 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3623 ;; Declare and autoload functions from org-agenda.el
3626 (org-autoload "org-agenda"
3627 '(org-agenda org-agenda-list org-search-view
3628 org-todo-list org-tags-view org-agenda-list-stuck-projects
3629 org-diary org-agenda-to-appt
3630 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3632 ;; Autoload org-remember
3635 (org-autoload "org-remember"
3636 '(org-remember-insinuate org-remember-annotation
3637 org-remember-apply-template org-remember org-remember-handler
)))
3640 (org-autoload "org-capture"
3641 '(org-capture org-capture-insert-template-here
3642 org-capture-import-remember-templates
)))
3644 ;; Autoload org-clock.el
3647 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3649 (declare-function org-clock-update-mode-line
"org-clock" ())
3650 (declare-function org-resolve-clocks
"org-clock"
3651 (&optional also-non-dangling-p prompt last-valid
))
3652 (defvar org-clock-start-time
)
3653 (defvar org-clock-marker
(make-marker)
3654 "Marker recording the last clock-in.")
3655 (defvar org-clock-hd-marker
(make-marker)
3656 "Marker recording the last clock-in, but the headline position.")
3657 (defvar org-clock-heading
""
3658 "The heading of the current clock entry.")
3659 (defun org-clock-is-active ()
3660 "Return non-nil if clock is currently running.
3661 The return value is actually the clock marker."
3662 (marker-buffer org-clock-marker
))
3667 '(org-clock-in org-clock-out org-clock-cancel
3668 org-clock-goto org-clock-sum org-clock-display
3669 org-clock-remove-overlays org-clock-report
3670 org-clocktable-shift org-dblock-write
:clocktable
3671 org-get-clocktable org-resolve-clocks
)))
3673 (defun org-clock-update-time-maybe ()
3674 "If this is a CLOCK line, update it and return t.
3675 Otherwise, return nil."
3678 (beginning-of-line 1)
3679 (skip-chars-forward " \t")
3680 (when (looking-at org-clock-string
)
3681 (let ((re (concat "[ \t]*" org-clock-string
3682 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3683 "\\([ \t]*=>.*\\)?\\)?"))
3686 ((not (looking-at re
))
3688 ((not (match-end 2))
3689 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3690 (> org-clock-marker
(point))
3691 (<= org-clock-marker
(point-at-eol)))
3692 ;; The clock is running here
3693 (setq org-clock-start-time
3695 (org-parse-time-string (match-string 1))))
3696 (org-clock-update-mode-line)))
3698 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3700 (setq ts
(match-string 1)
3701 te
(match-string 3))
3702 (setq s
(- (org-float-time
3703 (apply 'encode-time
(org-parse-time-string te
)))
3705 (apply 'encode-time
(org-parse-time-string ts
))))
3708 h
(floor (/ s
3600))
3712 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3715 (defun org-check-running-clock ()
3716 "Check if the current buffer contains the running clock.
3717 If yes, offer to stop it and to save the buffer with the changes."
3718 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3719 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3722 (when (y-or-n-p "Save changed buffer?")
3725 (defun org-clocktable-try-shift (dir n
)
3726 "Check if this line starts a clock table, if yes, shift the time block."
3727 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3728 (org-clocktable-shift dir n
)))
3730 ;; Autoload org-timer.el
3735 '(org-timer-start org-timer org-timer-item
3736 org-timer-change-times-in-region
3738 org-timer-reset-timers
3739 org-timer-show-remaining-time
)))
3741 ;; Autoload org-feed.el
3746 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3749 ;; Autoload org-indent.el
3751 ;; Define the variable already here, to make sure we have it.
3752 (defvar org-indent-mode nil
3753 "Non-nil if Org-Indent mode is enabled.
3754 Use the command `org-indent-mode' to change this variable.")
3759 '(org-indent-mode)))
3761 ;; Autoload org-mobile.el
3766 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3768 ;; Autoload archiving code
3769 ;; The stuff that is needed for cycling and tags has to be defined here.
3771 (defgroup org-archive nil
3772 "Options concerning archiving in Org-mode."
3774 :group
'org-structure
)
3776 (defcustom org-archive-location
"%s_archive::"
3777 "The location where subtrees should be archived.
3779 The value of this variable is a string, consisting of two parts,
3780 separated by a double-colon. The first part is a filename and
3781 the second part is a headline.
3783 When the filename is omitted, archiving happens in the same file.
3784 %s in the filename will be replaced by the current file
3785 name (without the directory part). Archiving to a different file
3786 is useful to keep archived entries from contributing to the
3789 The archived entries will be filed as subtrees of the specified
3790 headline. When the headline is omitted, the subtrees are simply
3791 filed away at the end of the file, as top-level entries. Also in
3792 the heading you can use %s to represent the file name, this can be
3793 useful when using the same archive for a number of different files.
3795 Here are a few examples:
3797 If the current file is Projects.org, archive in file
3798 Projects.org_archive, as top-level trees. This is the default.
3800 \"::* Archived Tasks\"
3801 Archive in the current file, under the top-level headline
3802 \"* Archived Tasks\".
3804 \"~/org/archive.org::\"
3805 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3807 \"~/org/archive.org::From %s\"
3808 Archive in file ~/org/archive.org (absolute path), under headlines
3809 \"From FILENAME\" where file name is the current file name.
3811 \"basement::** Finished Tasks\"
3812 Archive in file ./basement (relative path), as level 3 trees
3813 below the level 2 heading \"** Finished Tasks\".
3815 You may set this option on a per-file basis by adding to the buffer a
3818 #+ARCHIVE: basement::** Finished Tasks
3820 You may also define it locally for a subtree by setting an ARCHIVE property
3821 in the entry. If such a property is found in an entry, or anywhere up
3822 the hierarchy, it will be used."
3826 (defcustom org-archive-tag
"ARCHIVE"
3827 "The tag that marks a subtree as archived.
3828 An archived subtree does not open during visibility cycling, and does
3829 not contribute to the agenda listings.
3830 After changing this, font-lock must be restarted in the relevant buffers to
3831 get the proper fontification."
3833 :group
'org-keywords
3836 (defcustom org-agenda-skip-archived-trees t
3837 "Non-nil means the agenda will skip any items located in archived trees.
3838 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3839 variable is no longer recommended, you should leave it at the value t.
3840 Instead, use the key `v' to cycle the archives-mode in the agenda."
3842 :group
'org-agenda-skip
3845 (defcustom org-columns-skip-archived-trees t
3846 "Non-nil means ignore archived trees when creating column view."
3848 :group
'org-properties
3851 (defcustom org-cycle-open-archived-trees nil
3852 "Non-nil means `org-cycle' will open archived trees.
3853 An archived tree is a tree marked with the tag ARCHIVE.
3854 When nil, archived trees will stay folded. You can still open them with
3855 normal outline commands like `show-all', but not with the cycling commands."
3860 (defcustom org-sparse-tree-open-archived-trees nil
3861 "Non-nil means sparse tree construction shows matches in archived trees.
3862 When nil, matches in these trees are highlighted, but the trees are kept in
3865 :group
'org-sparse-trees
3868 (defun org-cycle-hide-archived-subtrees (state)
3869 "Re-hide all archived subtrees after a visibility state change."
3870 (when (and (not org-cycle-open-archived-trees
)
3871 (not (memq state
'(overview folded
))))
3873 (let* ((globalp (memq state
'(contents all
)))
3874 (beg (if globalp
(point-min) (point)))
3875 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3876 (org-hide-archived-subtrees beg end
)
3878 (if (looking-at (concat ".*:" org-archive-tag
":"))
3879 (message "%s" (substitute-command-keys
3880 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3882 (defun org-force-cycle-archived ()
3883 "Cycle subtree even if it is archived."
3885 (setq this-command
'org-cycle
)
3886 (let ((org-cycle-open-archived-trees t
))
3887 (call-interactively 'org-cycle
)))
3889 (defun org-hide-archived-subtrees (beg end
)
3890 "Re-hide all archived subtrees after a visibility state change."
3892 (let* ((re (concat ":" org-archive-tag
":")))
3894 (while (re-search-forward re end t
)
3895 (when (org-on-heading-p)
3896 (org-flag-subtree t
)
3897 (org-end-of-subtree t
))))))
3899 (defun org-flag-subtree (flag)
3901 (org-back-to-heading t
)
3902 (outline-end-of-heading)
3903 (outline-flag-region (point)
3904 (progn (org-end-of-subtree t
) (point))
3907 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3910 (org-autoload "org-archive"
3911 '(org-add-archive-files org-archive-subtree
3912 org-archive-to-archive-sibling org-toggle-archive-tag
3913 org-archive-subtree-default
3914 org-archive-subtree-default-with-confirmation
)))
3916 ;; Autoload Column View Code
3918 (declare-function org-columns-number-to-string
"org-colview")
3919 (declare-function org-columns-get-format-and-top-level
"org-colview")
3920 (declare-function org-columns-compute
"org-colview")
3922 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3923 '(org-columns-number-to-string org-columns-get-format-and-top-level
3924 org-columns-compute org-agenda-columns org-columns-remove-overlays
3925 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3929 (declare-function org-id-store-link
"org-id")
3930 (declare-function org-id-locations-load
"org-id")
3931 (declare-function org-id-locations-save
"org-id")
3932 (defvar org-id-track-globally
)
3933 (org-autoload "org-id"
3934 '(org-id-get-create org-id-new org-id-copy org-id-get
3935 org-id-get-with-outline-path-completion
3936 org-id-get-with-outline-drilling
3937 org-id-goto org-id-find org-id-store-link
))
3939 ;; Autoload Plotting Code
3941 (org-autoload "org-plot"
3942 '(org-plot/gnuplot
))
3944 ;;; Variables for pre-computed regular expressions, all buffer local
3946 (defvar org-drawer-regexp nil
3947 "Matches first line of a hidden block.")
3948 (make-variable-buffer-local 'org-drawer-regexp
)
3949 (defvar org-todo-regexp nil
3950 "Matches any of the TODO state keywords.")
3951 (make-variable-buffer-local 'org-todo-regexp
)
3952 (defvar org-not-done-regexp nil
3953 "Matches any of the TODO state keywords except the last one.")
3954 (make-variable-buffer-local 'org-not-done-regexp
)
3955 (defvar org-not-done-heading-regexp nil
3956 "Matches a TODO headline that is not done.")
3957 (make-variable-buffer-local 'org-not-done-regexp
)
3958 (defvar org-todo-line-regexp nil
3959 "Matches a headline and puts TODO state into group 2 if present.")
3960 (make-variable-buffer-local 'org-todo-line-regexp
)
3961 (defvar org-complex-heading-regexp nil
3962 "Matches a headline and puts everything into groups:
3964 group 2: The todo keyword, maybe
3965 group 3: Priority cookie
3966 group 4: True headline
3968 (make-variable-buffer-local 'org-complex-heading-regexp
)
3969 (defvar org-complex-heading-regexp-format nil
)
3970 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3971 (defvar org-todo-line-tags-regexp nil
3972 "Matches a headline and puts TODO state into group 2 if present.
3973 Also put tags into group 4 if tags are present.")
3974 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3975 (defvar org-nl-done-regexp nil
3976 "Matches newline followed by a headline with the DONE keyword.")
3977 (make-variable-buffer-local 'org-nl-done-regexp
)
3978 (defvar org-looking-at-done-regexp nil
3979 "Matches the DONE keyword a point.")
3980 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3981 (defvar org-ds-keyword-length
12
3982 "Maximum length of the Deadline and SCHEDULED keywords.")
3983 (make-variable-buffer-local 'org-ds-keyword-length
)
3984 (defvar org-deadline-regexp nil
3985 "Matches the DEADLINE keyword.")
3986 (make-variable-buffer-local 'org-deadline-regexp
)
3987 (defvar org-deadline-time-regexp nil
3988 "Matches the DEADLINE keyword together with a time stamp.")
3989 (make-variable-buffer-local 'org-deadline-time-regexp
)
3990 (defvar org-deadline-line-regexp nil
3991 "Matches the DEADLINE keyword and the rest of the line.")
3992 (make-variable-buffer-local 'org-deadline-line-regexp
)
3993 (defvar org-scheduled-regexp nil
3994 "Matches the SCHEDULED keyword.")
3995 (make-variable-buffer-local 'org-scheduled-regexp
)
3996 (defvar org-scheduled-time-regexp nil
3997 "Matches the SCHEDULED keyword together with a time stamp.")
3998 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3999 (defvar org-closed-time-regexp nil
4000 "Matches the CLOSED keyword together with a time stamp.")
4001 (make-variable-buffer-local 'org-closed-time-regexp
)
4003 (defvar org-keyword-time-regexp nil
4004 "Matches any of the 4 keywords, together with the time stamp.")
4005 (make-variable-buffer-local 'org-keyword-time-regexp
)
4006 (defvar org-keyword-time-not-clock-regexp nil
4007 "Matches any of the 3 keywords, together with the time stamp.")
4008 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4009 (defvar org-maybe-keyword-time-regexp nil
4010 "Matches a timestamp, possibly preceeded by a keyword.")
4011 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4012 (defvar org-planning-or-clock-line-re nil
4013 "Matches a line with planning or clock info.")
4014 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
4015 (defvar org-all-time-keywords nil
4016 "List of time keywords.")
4017 (make-variable-buffer-local 'org-all-time-keywords
)
4019 (defconst org-plain-time-of-day-regexp
4022 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4025 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4027 "Regular expression to match a plain time or time range.
4028 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4029 groups carry important information:
4031 1 the first time, range or not
4032 8 the second time, if it is a range.")
4034 (defconst org-plain-time-extension-regexp
4037 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4038 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4039 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4040 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4041 groups carry important information:
4044 9 minutes of duration")
4046 (defconst org-stamp-time-of-day-regexp
4048 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4049 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4051 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4052 "Regular expression to match a timestamp time or time range.
4053 After a match, the following groups carry important information:
4055 1 date plus weekday, for back referencing to make sure both times are on the same day
4056 2 the first time, range or not
4057 4 the second time, if it is a range.")
4059 (defconst org-startup-options
4060 '(("fold" org-startup-folded t
)
4061 ("overview" org-startup-folded t
)
4062 ("nofold" org-startup-folded nil
)
4063 ("showall" org-startup-folded nil
)
4064 ("showeverything" org-startup-folded showeverything
)
4065 ("content" org-startup-folded content
)
4066 ("indent" org-startup-indented t
)
4067 ("noindent" org-startup-indented nil
)
4068 ("hidestars" org-hide-leading-stars t
)
4069 ("showstars" org-hide-leading-stars nil
)
4070 ("odd" org-odd-levels-only t
)
4071 ("oddeven" org-odd-levels-only nil
)
4072 ("align" org-startup-align-all-tables t
)
4073 ("noalign" org-startup-align-all-tables nil
)
4074 ("customtime" org-display-custom-times t
)
4075 ("logdone" org-log-done time
)
4076 ("lognotedone" org-log-done note
)
4077 ("nologdone" org-log-done nil
)
4078 ("lognoteclock-out" org-log-note-clock-out t
)
4079 ("nolognoteclock-out" org-log-note-clock-out nil
)
4080 ("logrepeat" org-log-repeat state
)
4081 ("lognoterepeat" org-log-repeat note
)
4082 ("nologrepeat" org-log-repeat nil
)
4083 ("logreschedule" org-log-reschedule time
)
4084 ("lognotereschedule" org-log-reschedule note
)
4085 ("nologreschedule" org-log-reschedule nil
)
4086 ("logredeadline" org-log-redeadline time
)
4087 ("lognoteredeadline" org-log-redeadline note
)
4088 ("nologredeadline" org-log-redeadline nil
)
4089 ("logrefile" org-log-refile time
)
4090 ("lognoterefile" org-log-refile note
)
4091 ("nologrefile" org-log-refile nil
)
4092 ("fninline" org-footnote-define-inline t
)
4093 ("nofninline" org-footnote-define-inline nil
)
4094 ("fnlocal" org-footnote-section nil
)
4095 ("fnauto" org-footnote-auto-label t
)
4096 ("fnprompt" org-footnote-auto-label nil
)
4097 ("fnconfirm" org-footnote-auto-label confirm
)
4098 ("fnplain" org-footnote-auto-label plain
)
4099 ("fnadjust" org-footnote-auto-adjust t
)
4100 ("nofnadjust" org-footnote-auto-adjust nil
)
4101 ("constcgs" constants-unit-system cgs
)
4102 ("constSI" constants-unit-system SI
)
4103 ("noptag" org-tag-persistent-alist nil
)
4104 ("hideblocks" org-hide-block-startup t
)
4105 ("nohideblocks" org-hide-block-startup nil
)
4106 ("beamer" org-startup-with-beamer-mode t
)
4107 ("entitiespretty" org-pretty-entities t
)
4108 ("entitiesplain" org-pretty-entities nil
))
4109 "Variable associated with STARTUP options for org-mode.
4110 Each element is a list of three items: The startup options as written
4111 in the #+STARTUP line, the corresponding variable, and the value to
4112 set this variable to if the option is found. An optional forth element PUSH
4113 means to push this value onto the list in the variable.")
4115 (defun org-set-regexps-and-options ()
4116 "Precompute regular expressions for current buffer."
4118 (org-set-local 'org-todo-kwd-alist nil
)
4119 (org-set-local 'org-todo-key-alist nil
)
4120 (org-set-local 'org-todo-key-trigger nil
)
4121 (org-set-local 'org-todo-keywords-1 nil
)
4122 (org-set-local 'org-done-keywords nil
)
4123 (org-set-local 'org-todo-heads nil
)
4124 (org-set-local 'org-todo-sets nil
)
4125 (org-set-local 'org-todo-log-states nil
)
4126 (org-set-local 'org-file-properties nil
)
4127 (org-set-local 'org-file-tags nil
)
4128 (let ((re (org-make-options-regexp
4129 '("CATEGORY" "TODO" "COLUMNS"
4130 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
4131 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS"
4133 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4135 (scripts org-use-sub-superscripts
)
4136 kwds kws0 kwsa key log value cat arch tags const links hw dws
4137 tail sep kws1 prio props ftags drawers beamer-p
4138 ext-setup-or-nil setup-contents
(start 0))
4142 (goto-char (point-min))
4143 (while (or (and ext-setup-or-nil
4144 (string-match re ext-setup-or-nil start
)
4145 (setq start
(match-end 0)))
4146 (and (setq ext-setup-or-nil nil start
0)
4147 (re-search-forward re nil t
)))
4148 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4149 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4150 (if (stringp value
) (setq value
(org-trim value
)))
4152 ((equal key
"CATEGORY")
4154 ((member key
'("SEQ_TODO" "TODO"))
4155 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4156 ((equal key
"TYP_TODO")
4157 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4158 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4159 ;; general TODO-like setup
4160 (push (cons (intern (downcase (match-string 1 key
)))
4161 (org-split-string value splitre
)) kwds
))
4163 (setq tags
(append tags
(if tags
'("\\n") nil
)
4164 (org-split-string value splitre
))))
4165 ((equal key
"COLUMNS")
4166 (org-set-local 'org-columns-default-format value
))
4168 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4169 (push (cons (match-string 1 value
)
4170 (org-trim (match-string 2 value
)))
4172 ((equal key
"PRIORITIES")
4173 (setq prio
(org-split-string value
" +")))
4174 ((equal key
"PROPERTY")
4175 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4176 (push (cons (match-string 1 value
) (match-string 2 value
))
4178 ((equal key
"FILETAGS")
4179 (when (string-match "\\S-" value
)
4184 (mapcar (lambda (x) (org-split-string x
":"))
4185 (org-split-string value
)))))))
4186 ((equal key
"DRAWERS")
4187 (setq drawers
(org-split-string value splitre
)))
4188 ((equal key
"CONSTANTS")
4189 (setq const
(append const
(org-split-string value splitre
))))
4190 ((equal key
"STARTUP")
4191 (let ((opts (org-split-string value splitre
))
4193 (while (setq l
(pop opts
))
4194 (when (setq l
(assoc l org-startup-options
))
4195 (setq var
(nth 1 l
) val
(nth 2 l
))
4197 (set (make-local-variable var
) val
)
4198 (if (not (listp (symbol-value var
)))
4199 (set (make-local-variable var
) nil
))
4200 (set (make-local-variable var
) (symbol-value var
))
4201 (add-to-list var val
))))))
4202 ((equal key
"ARCHIVE")
4204 (remove-text-properties 0 (length arch
)
4205 '(face t fontified t
) arch
))
4206 ((equal key
"LATEX_CLASS")
4207 (setq beamer-p
(equal value
"beamer")))
4208 ((equal key
"OPTIONS")
4209 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4210 (setq scripts
(read (match-string 2 value
)))))
4211 ((equal key
"SETUPFILE")
4212 (setq setup-contents
(org-file-contents
4214 (org-remove-double-quotes value
))
4216 (if (not ext-setup-or-nil
)
4217 (setq ext-setup-or-nil setup-contents start
0)
4218 (setq ext-setup-or-nil
4219 (concat (substring ext-setup-or-nil
0 start
)
4220 "\n" setup-contents
"\n"
4221 (substring ext-setup-or-nil start
)))))
4223 (org-set-local 'org-use-sub-superscripts scripts
)
4225 (org-set-local 'org-category
(intern cat
))
4226 (push (cons "CATEGORY" cat
) props
))
4228 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4229 (setq prio
(mapcar 'string-to-char prio
))
4230 (org-set-local 'org-highest-priority
(nth 0 prio
))
4231 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4232 (org-set-local 'org-default-priority
(nth 2 prio
)))
4233 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4234 (and ftags
(org-set-local 'org-file-tags
4235 (mapcar 'org-add-prop-inherited ftags
)))
4236 (and drawers
(org-set-local 'org-drawers drawers
))
4237 (and arch
(org-set-local 'org-archive-location arch
))
4238 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4239 ;; Process the TODO keywords
4241 ;; Use the global values as if they had been given locally.
4242 (setq kwds
(default-value 'org-todo-keywords
))
4243 (if (stringp (car kwds
))
4244 (setq kwds
(list (cons org-todo-interpretation
4245 (default-value 'org-todo-keywords
)))))
4246 (setq kwds
(reverse kwds
)))
4247 (setq kwds
(nreverse kwds
))
4249 (while (setq kws
(pop kwds
))
4251 (run-hook-with-args-until-success
4252 'org-todo-setup-filter-hook kws
)
4254 (setq inter
(pop kws
) sep
(member "|" kws
)
4255 kws0
(delete "|" (copy-sequence kws
))
4260 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4262 (setq kw
(match-string 1 x
)
4263 key
(and (match-end 2) (match-string 2 x
))
4264 log
(org-extract-log-state-settings x
))
4265 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4266 (and log
(push log org-todo-log-states
))
4268 (error "Invalid TODO keyword %s" x
)))
4270 kwsa
(if kwsa
(append '((:startgroup
))
4274 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4275 tail
(list inter hw
(car dws
) (org-last dws
))))
4276 (add-to-list 'org-todo-heads hw
'append
)
4277 (push kws1 org-todo-sets
)
4278 (setq org-done-keywords
(append org-done-keywords dws nil
))
4279 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4280 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4281 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4282 (setq org-todo-sets
(nreverse org-todo-sets
)
4283 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4284 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4285 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4286 ;; Process the constants
4289 (while (setq e
(pop const
))
4290 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4291 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4292 (setq org-table-formula-constants-local cst
)))
4294 ;; Process the tags.
4297 (while (setq e
(pop tags
))
4299 ((equal e
"{") (push '(:startgroup
) tgs
))
4300 ((equal e
"}") (push '(:endgroup
) tgs
))
4301 ((equal e
"\\n") (push '(:newline
) tgs
))
4302 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4303 (push (cons (match-string 1 e
)
4304 (string-to-char (match-string 2 e
)))
4306 (t (push (list e
) tgs
))))
4307 (org-set-local 'org-tag-alist nil
)
4308 (while (setq e
(pop tgs
))
4309 (or (and (stringp (car e
))
4310 (assoc (car e
) org-tag-alist
))
4311 (push e org-tag-alist
)))))
4313 ;; Compute the regular expressions and other local variables
4314 (if (not org-done-keywords
)
4315 (setq org-done-keywords
(and org-todo-keywords-1
4316 (list (org-last org-todo-keywords-1
)))))
4317 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4318 (length org-scheduled-string
)
4319 (length org-clock-string
)
4320 (length org-closed-string
)))
4322 (concat "^[ \t]*:\\("
4323 (mapconcat 'regexp-quote org-drawers
"\\|")
4325 org-not-done-keywords
4326 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4328 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4332 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4334 org-not-done-heading-regexp
4335 (concat "^\\(\\*+\\)[ \t]+\\("
4336 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4338 org-todo-line-regexp
4339 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4340 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4341 "\\)\\>\\)?[ \t]*\\(.*\\)")
4342 org-complex-heading-regexp
4343 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4344 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4345 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4346 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4347 org-complex-heading-regexp-format
4348 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4349 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4351 "\\(?:[ \t]*\\(\\[#.\\]\\)\\)?"
4352 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4354 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4355 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4357 (concat "\n\\*+[ \t]+"
4358 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4360 org-todo-line-tags-regexp
4361 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4362 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4364 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4365 org-looking-at-done-regexp
4367 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4369 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4370 org-deadline-time-regexp
4371 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4372 org-deadline-line-regexp
4373 (concat "\\<\\(" org-deadline-string
"\\).*")
4374 org-scheduled-regexp
4375 (concat "\\<" org-scheduled-string
)
4376 org-scheduled-time-regexp
4377 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4378 org-closed-time-regexp
4379 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4380 org-keyword-time-regexp
4381 (concat "\\<\\(" org-scheduled-string
4382 "\\|" org-deadline-string
4383 "\\|" org-closed-string
4384 "\\|" org-clock-string
"\\)"
4385 " *[[<]\\([^]>]+\\)[]>]")
4386 org-keyword-time-not-clock-regexp
4387 (concat "\\<\\(" org-scheduled-string
4388 "\\|" org-deadline-string
4389 "\\|" org-closed-string
4391 " *[[<]\\([^]>]+\\)[]>]")
4392 org-maybe-keyword-time-regexp
4393 (concat "\\(\\<\\(" org-scheduled-string
4394 "\\|" org-deadline-string
4395 "\\|" org-closed-string
4396 "\\|" org-clock-string
"\\)\\)?"
4397 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4398 org-planning-or-clock-line-re
4399 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4400 "\\|" org-deadline-string
4401 "\\|" org-closed-string
"\\|" org-clock-string
4403 org-all-time-keywords
4404 (mapcar (lambda (w) (substring w
0 -
1))
4405 (list org-scheduled-string org-deadline-string
4406 org-clock-string org-closed-string
))
4408 (org-compute-latex-and-specials-regexp)
4409 (org-set-font-lock-defaults))))
4411 (defun org-file-contents (file &optional noerror
)
4412 "Return the contents of FILE, as a string."
4414 (not (file-readable-p file
)))
4417 (message "Cannot read file \"%s\"" file
)
4420 (error "Cannot read file \"%s\"" file
))
4422 (insert-file-contents file
)
4425 (defun org-extract-log-state-settings (x)
4426 "Extract the log state setting from a TODO keyword string.
4427 This will extract info from a string like \"WAIT(w@/!)\"."
4428 (let (kw key log1 log2
)
4429 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4430 (setq kw
(match-string 1 x
)
4431 key
(and (match-end 2) (match-string 2 x
))
4432 log1
(and (match-end 3) (match-string 3 x
))
4433 log2
(and (match-end 4) (match-string 4 x
)))
4436 (and log1
(if (equal log1
"!") 'time
'note
))
4437 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4439 (defun org-remove-keyword-keys (list)
4440 "Remove a pair of parenthesis at the end of each string in LIST."
4442 (if (string-match "(.*)$" x
)
4443 (substring x
0 (match-beginning 0))
4447 (defun org-assign-fast-keys (alist)
4448 "Assign fast keys to a keyword-key alist.
4449 Respect keys that are already there."
4450 (let (new e
(alt ?
0))
4451 (while (setq e
(pop alist
))
4452 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4453 (cdr e
)) ;; Key already assigned.
4455 (let ((clist (string-to-list (downcase (car e
))))
4456 (used (append new alist
)))
4457 (when (= (car clist
) ?
@)
4459 (while (and clist
(rassoc (car clist
) used
))
4462 (while (rassoc alt used
)
4464 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4467 ;;; Some variables used in various places
4469 (defvar org-window-configuration nil
4470 "Used in various places to store a window configuration.")
4471 (defvar org-selected-window nil
4472 "Used in various places to store a window configuration.")
4473 (defvar org-finish-function nil
4474 "Function to be called when `C-c C-c' is used.
4475 This is for getting out of special buffers like remember.")
4478 ;; FIXME: Occasionally check by commenting these, to make sure
4479 ;; no other functions uses these, forgetting to let-bind them.
4484 ;; Defined somewhere in this file, but used before definition.
4485 (defvar org-entities
) ;; defined in org-entities.el
4486 (defvar org-struct-menu
)
4487 (defvar org-org-menu
)
4488 (defvar org-tbl-menu
)
4490 ;;;; Define the Org-mode
4492 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4493 (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."))
4496 ;; We use a before-change function to check if a table might need
4498 (defvar org-table-may-need-update t
4499 "Indicates that a table might need an update.
4500 This variable is set by `org-before-change-function'.
4501 `org-table-align' sets it back to nil.")
4502 (defun org-before-change-function (beg end
)
4503 "Every change indicates that a table might need an update."
4504 (setq org-table-may-need-update t
))
4505 (defvar org-mode-map
)
4506 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4507 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4508 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4509 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4510 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4511 (defvar org-table-buffer-is-an nil
)
4512 (defconst org-outline-regexp
"\\*+ ")
4515 (define-derived-mode org-mode outline-mode
"Org"
4516 "Outline-based notes management and organizer, alias
4517 \"Carsten's outline-mode for keeping track of everything.\"
4519 Org-mode develops organizational tasks around a NOTES file which
4520 contains information about projects as plain text. Org-mode is
4521 implemented on top of outline-mode, which is ideal to keep the content
4522 of large files well structured. It supports ToDo items, deadlines and
4523 time stamps, which magically appear in the diary listing of the Emacs
4524 calendar. Tables are easily created with a built-in table editor.
4525 Plain text URL-like links connect to websites, emails (VM), Usenet
4526 messages (Gnus), BBDB entries, and any files related to the project.
4527 For printing and sharing of notes, an Org-mode file (or a part of it)
4528 can be exported as a structured ASCII or HTML file.
4530 The following commands are available:
4534 ;; Get rid of Outline menus, they are not needed
4535 ;; Need to do this here because define-derived-mode sets up
4536 ;; the keymap so late. Still, it is a waste to call this each time
4537 ;; we switch another buffer into org-mode.
4538 (if (featurep 'xemacs
)
4539 (when (boundp 'outline-mode-menu-heading
)
4540 ;; Assume this is Greg's port, it uses easymenu
4541 (easy-menu-remove outline-mode-menu-heading
)
4542 (easy-menu-remove outline-mode-menu-show
)
4543 (easy-menu-remove outline-mode-menu-hide
))
4544 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4545 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4546 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4548 (org-load-modules-maybe)
4549 (easy-menu-add org-org-menu
)
4550 (easy-menu-add org-tbl-menu
)
4551 (org-install-agenda-files-menu)
4552 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4553 (add-to-invisibility-spec '(org-cwidth))
4554 (add-to-invisibility-spec '(org-hide-block . t
))
4555 (when (featurep 'xemacs
)
4556 (org-set-local 'line-move-ignore-invisible t
))
4557 (org-set-local 'outline-regexp org-outline-regexp
)
4558 (org-set-local 'outline-level
'org-outline-level
)
4559 (when (and org-ellipsis
4560 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4561 (fboundp 'make-glyph-code
))
4562 (unless org-display-table
4563 (setq org-display-table
(make-display-table)))
4564 (set-display-table-slot
4567 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4569 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4570 (setq buffer-display-table org-display-table
))
4571 (org-set-regexps-and-options)
4572 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4573 ;; tag faces set outside customize.... force initialization.
4574 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4576 (org-set-local 'calc-embedded-open-mode
"# ")
4577 (modify-syntax-entry ?
@ "w")
4578 (if org-startup-truncated
(setq truncate-lines t
))
4579 (org-set-local 'font-lock-unfontify-region-function
4580 'org-unfontify-region
)
4581 ;; Activate before-change-function
4582 (org-set-local 'org-table-may-need-update t
)
4583 (org-add-hook 'before-change-functions
'org-before-change-function nil
4585 ;; Check for running clock before killing a buffer
4586 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4587 ;; Paragraphs and auto-filling
4588 (org-set-autofill-regexps)
4589 (setq indent-line-function
'org-indent-line-function
)
4590 (org-update-radio-target-regexp)
4591 ;; Beginning/end of defun
4592 (org-set-local 'beginning-of-defun-function
'org-beginning-of-defun
)
4593 (org-set-local 'end-of-defun-function
'org-end-of-defun
)
4594 ;; Make sure dependence stuff works reliably, even for users who set it
4596 (if org-enforce-todo-dependencies
4597 (add-hook 'org-blocker-hook
4598 'org-block-todo-from-children-or-siblings-or-parent
)
4599 (remove-hook 'org-blocker-hook
4600 'org-block-todo-from-children-or-siblings-or-parent
))
4601 (if org-enforce-todo-checkbox-dependencies
4602 (add-hook 'org-blocker-hook
4603 'org-block-todo-from-checkboxes
)
4604 (remove-hook 'org-blocker-hook
4605 'org-block-todo-from-checkboxes
))
4607 ;; Comment characters
4608 (org-set-local 'comment-start
"#")
4609 (org-set-local 'comment-padding
" ")
4611 ;; Align options lines
4613 'align-mode-rules-list
4614 '((org-in-buffer-settings
4615 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4616 (modes .
'(org-mode)))))
4619 (org-set-local 'imenu-create-index-function
4620 'org-imenu-get-tree
)
4622 ;; Make isearch reveal context
4623 (if (or (featurep 'xemacs
)
4624 (not (boundp 'outline-isearch-open-invisible-function
)))
4625 ;; Emacs 21 and XEmacs make use of the hook
4626 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4627 ;; Emacs 22 deals with this through a special variable
4628 (org-set-local 'outline-isearch-open-invisible-function
4629 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4631 ;; Turn on org-beamer-mode?
4632 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4634 ;; If empty file that did not turn on org-mode automatically, make it to.
4635 (if (and org-insert-mode-line-in-empty-file
4637 (= (point-min) (point-max)))
4638 (insert "# -*- mode: org -*-\n\n"))
4639 (unless org-inhibit-startup
4640 (when org-startup-align-all-tables
4641 (let ((bmp (buffer-modified-p)))
4642 (org-table-map-tables 'org-table-align
'quietly
)
4643 (set-buffer-modified-p bmp
)))
4644 (when org-startup-indented
4645 (require 'org-indent
)
4646 (org-indent-mode 1))
4647 (unless org-inhibit-startup-visibility-stuff
4648 (org-set-startup-visibility))))
4650 (when (fboundp 'abbrev-table-put
)
4651 (abbrev-table-put org-mode-abbrev-table
4652 :parents
(list text-mode-abbrev-table
)))
4654 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4656 (defun org-current-time ()
4657 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4658 (if (> (car org-time-stamp-rounding-minutes
) 1)
4659 (let ((r (car org-time-stamp-rounding-minutes
))
4660 (time (decode-time)))
4662 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4666 ;;;; Font-Lock stuff, including the activators
4668 (defvar org-mouse-map
(make-sparse-keymap))
4669 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
4670 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
4671 (when org-mouse-1-follows-link
4672 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
4673 (when org-tab-follows-link
4674 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
4675 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
4677 (require 'font-lock
)
4679 (defconst org-non-link-chars
"]\t\n\r<>")
4680 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
4681 "shell" "elisp" "doi"))
4682 (defvar org-link-types-re nil
4683 "Matches a link that has a url-like prefix like \"http:\"")
4684 (defvar org-link-re-with-space nil
4685 "Matches a link with spaces, optional angular brackets around it.")
4686 (defvar org-link-re-with-space2 nil
4687 "Matches a link with spaces, optional angular brackets around it.")
4688 (defvar org-link-re-with-space3 nil
4689 "Matches a link with spaces, only for internal part in bracket links.")
4690 (defvar org-angle-link-re nil
4691 "Matches link with angular brackets, spaces are allowed.")
4692 (defvar org-plain-link-re nil
4693 "Matches plain link, without spaces.")
4694 (defvar org-bracket-link-regexp nil
4695 "Matches a link in double brackets.")
4696 (defvar org-bracket-link-analytic-regexp nil
4697 "Regular expression used to analyze links.
4698 Here is what the match groups contain after a match:
4704 (defvar org-bracket-link-analytic-regexp
++ nil
4705 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4706 (defvar org-any-link-re nil
4707 "Regular expression matching any link.")
4709 (defcustom org-match-sexp-depth
3
4710 "Number of stacked braces for sub/superscript matching.
4711 This has to be set before loading org.el to be effective."
4712 :group
'org-export-translation
; ??????????????????????????/
4715 (defun org-create-multibrace-regexp (left right n
)
4716 "Create a regular expression which will match a balanced sexp.
4717 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4718 as single character strings.
4719 The regexp returned will match the entire expression including the
4720 delimiters. It will also define a single group which contains the
4721 match except for the outermost delimiters. The maximum depth of
4722 stacked delimiters is N. Escaping delimiters is not possible."
4723 (let* ((nothing (concat "[^" left right
"]*?"))
4726 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4729 re
(concat re or next
)
4730 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4731 (concat left
"\\(" re
"\\)" right
)))
4733 (defvar org-match-substring-regexp
4735 "\\([^\\]\\)\\([_^]\\)\\("
4736 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4738 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4740 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4741 "The regular expression matching a sub- or superscript.")
4743 (defvar org-match-substring-with-braces-regexp
4745 "\\([^\\]\\)\\([_^]\\)\\("
4746 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4748 "The regular expression matching a sub- or superscript, forcing braces.")
4750 (defun org-make-link-regexps ()
4751 "Update the link regular expressions.
4752 This should be called after the variable `org-link-types' has changed."
4753 (setq org-link-types-re
4755 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
4756 org-link-re-with-space
4758 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4759 "\\([^" org-non-link-chars
" ]"
4760 "[^" org-non-link-chars
"]*"
4761 "[^" org-non-link-chars
" ]\\)>?")
4762 org-link-re-with-space2
4764 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4765 "\\([^" org-non-link-chars
" ]"
4767 "[^" org-non-link-chars
" ]\\)>?")
4768 org-link-re-with-space3
4770 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4771 "\\([^" org-non-link-chars
" ]"
4775 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4776 "\\([^" org-non-link-chars
" ]"
4777 "[^" org-non-link-chars
"]*"
4781 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4782 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4783 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4784 org-bracket-link-regexp
4785 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4786 org-bracket-link-analytic-regexp
4789 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
4792 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4794 org-bracket-link-analytic-regexp
++
4797 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
4800 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4803 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
4804 org-angle-link-re
"\\)\\|\\("
4805 org-plain-link-re
"\\)")))
4807 (org-make-link-regexps)
4809 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4810 "Regular expression for fast time stamp matching.")
4811 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4812 "Regular expression for fast time stamp matching.")
4813 (defconst org-ts-regexp0
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4814 "Regular expression matching time strings for analysis.
4815 This one does not require the space after the date, so it can be used
4816 on a string that terminates immediately after the date.")
4817 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4818 "Regular expression matching time strings for analysis.")
4819 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
4820 "Regular expression matching time stamps, with groups.")
4821 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
4822 "Regular expression matching time stamps (also [..]), with groups.")
4823 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
4824 "Regular expression matching a time stamp range.")
4825 (defconst org-tr-regexp-both
4826 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
4827 "Regular expression matching a time stamp range.")
4828 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
4829 org-ts-regexp
"\\)?")
4830 "Regular expression matching a time stamp or time stamp range.")
4831 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
4832 org-ts-regexp-both
"\\)?")
4833 "Regular expression matching a time stamp or time stamp range.
4834 The time stamps may be either active or inactive.")
4836 (defvar org-emph-face nil
)
4838 (defun org-do-emphasis-faces (limit)
4839 "Run through the buffer and add overlays to links."
4841 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
4842 (if (not (= (char-after (match-beginning 3))
4843 (char-after (match-beginning 4))))
4846 (setq a
(assoc (match-string 3) org-emphasis-alist
))
4847 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4851 (org-remove-flyspell-overlays-in
4852 (match-beginning 0) (match-end 0)))
4853 (add-text-properties (match-beginning 2) (match-end 2)
4854 '(font-lock-multiline t org-emphasis t
))
4855 (when org-hide-emphasis-markers
4856 (add-text-properties (match-end 4) (match-beginning 5)
4857 '(invisible org-link
))
4858 (add-text-properties (match-beginning 3) (match-end 3)
4859 '(invisible org-link
)))))
4863 (defun org-emphasize (&optional char
)
4864 "Insert or change an emphasis, i.e. a font like bold or italic.
4865 If there is an active region, change that region to a new emphasis.
4866 If there is no region, just insert the marker characters and position
4867 the cursor between them.
4868 CHAR should be either the marker character, or the first character of the
4869 HTML tag associated with that emphasis. If CHAR is a space, the means
4870 to remove the emphasis of the selected region.
4871 If char is not given (for example in an interactive call) it
4872 will be prompted for."
4874 (let ((eal org-emphasis-alist
) e det
4875 (erc org-emphasis-regexp-components
)
4877 (string "") beg end move tag c s
)
4878 (if (org-region-active-p)
4879 (setq beg
(region-beginning) end
(region-end)
4880 string
(buffer-substring beg end
))
4883 (while (setq e
(pop eal
))
4884 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
4886 (push (cons c
(string-to-char (car e
))) det
)
4887 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
4888 (substring tag
1)))))
4889 (setq det
(nreverse det
))
4891 (message "%s" (concat "Emphasis marker or tag:" prompt
))
4892 (setq char
(read-char-exclusive)))
4893 (setq char
(or (cdr (assoc char det
)) char
))
4894 (if (equal char ?\
)
4895 (setq s
"" move nil
)
4896 (unless (assoc (char-to-string char
) org-emphasis-alist
)
4897 (error "No such emphasis marker: \"%c\"" char
))
4898 (setq s
(char-to-string char
)))
4899 (while (and (> (length string
) 1)
4900 (equal (substring string
0 1) (substring string -
1))
4901 (assoc (substring string
0 1) org-emphasis-alist
))
4902 (setq string
(substring string
1 -
1)))
4903 (setq string
(concat s string s
))
4904 (if beg
(delete-region beg end
))
4906 (string-match (concat "[" (nth 0 erc
) "\n]")
4907 (char-to-string (char-before (point)))))
4910 (string-match (concat "[" (nth 1 erc
) "\n]")
4911 (char-to-string (char-after (point)))))
4912 (insert " ") (backward-char 1))
4914 (and move
(backward-char 1))))
4916 (defconst org-nonsticky-props
4917 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
4919 (defsubst org-rear-nonsticky-at
(pos)
4920 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
4922 (defun org-activate-plain-links (limit)
4923 "Run through the buffer and add overlays to links."
4926 (if (re-search-forward org-plain-link-re limit t
)
4928 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4929 (setq f
(get-text-property (match-beginning 0) 'face
))
4930 (if (or (eq f
'org-tag
)
4931 (and (listp f
) (memq 'org-tag f
)))
4933 (add-text-properties (match-beginning 0) (match-end 0)
4934 (list 'mouse-face
'highlight
4936 'keymap org-mouse-map
))
4937 (org-rear-nonsticky-at (match-end 0)))
4940 (defun org-activate-code (limit)
4941 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t
)
4943 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4944 (remove-text-properties (match-beginning 0) (match-end 0)
4945 '(display t invisible t intangible t
))
4948 (defun org-fontify-meta-lines-and-blocks (limit)
4949 "Fontify #+ lines and blocks, in the correct ways."
4950 (let ((case-fold-search t
))
4951 (if (re-search-forward
4952 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4954 (let ((beg (match-beginning 0))
4955 (beg1 (line-beginning-position 2))
4956 (dc1 (downcase (match-string 2)))
4957 (dc3 (downcase (match-string 3)))
4958 end end1 quoting block-type
)
4960 ((member dc1
'("html:" "ascii:" "latex:" "docbook:"))
4961 ;; a single line of backend-specific content
4962 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4963 (remove-text-properties (match-beginning 0) (match-end 0)
4964 '(display t invisible t intangible t
))
4965 (add-text-properties (match-beginning 1) (match-end 3)
4966 '(font-lock-fontified t face org-meta-line
))
4967 (add-text-properties (match-beginning 6) (match-end 6)
4968 '(font-lock-fontified t face org-block
))
4970 ((and (match-end 4) (equal dc3
"begin"))
4972 (setq block-type
(downcase (match-string 5))
4973 quoting
(member block-type org-protecting-blocks
))
4974 (when (re-search-forward
4975 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4976 nil t
) ;; on purpose, we look further than LIMIT
4977 (setq end
(match-end 0) end1
(1- (match-beginning 0)))
4979 (remove-text-properties beg end
4980 '(display t invisible t intangible t
)))
4981 (add-text-properties
4983 '(font-lock-fontified t font-lock-multiline t
))
4984 (add-text-properties beg beg1
'(face org-meta-line
))
4985 (add-text-properties end1 end
'(face org-meta-line
))
4988 (add-text-properties beg1 end1
'(face org-block
)))
4989 ((not org-fontify-quote-and-verse-blocks
))
4990 ((string= block-type
"quote")
4991 (add-text-properties beg1 end1
'(face org-quote
)))
4992 ((string= block-type
"verse")
4993 (add-text-properties beg1 end1
'(face org-verse
))))
4995 ((member dc1
'("title:" "author:" "email:" "date:"))
4996 (add-text-properties
4998 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
4999 '(font-lock-fontified t invisible t
)
5000 '(font-lock-fontified t face org-document-info-keyword
)))
5001 (add-text-properties
5002 (match-beginning 6) (match-end 6)
5003 (if (string-equal dc1
"title:")
5004 '(font-lock-fontified t face org-document-title
)
5005 '(font-lock-fontified t face org-document-info
))))
5006 ((not (member (char-after beg
) '(?\ ?
\t)))
5007 ;; just any other in-buffer setting, but not indented
5008 (add-text-properties
5010 '(font-lock-fontified t face org-meta-line
))
5012 ((or (member dc1
'("begin:" "end:" "caption:" "label:"
5013 "orgtbl:" "tblfm:" "tblname:" "result:"
5014 "results:" "source:" "srcname:" "call:"))
5015 (and (match-end 4) (equal dc3
"attr")))
5016 (add-text-properties
5018 '(font-lock-fontified t face org-meta-line
))
5020 ((member dc3
'(" " ""))
5021 (add-text-properties
5023 '(font-lock-fontified t face font-lock-comment-face
)))
5026 (defun org-activate-angle-links (limit)
5027 "Run through the buffer and add overlays to links."
5028 (if (re-search-forward org-angle-link-re limit t
)
5030 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5031 (add-text-properties (match-beginning 0) (match-end 0)
5032 (list 'mouse-face
'highlight
5033 'keymap org-mouse-map
))
5034 (org-rear-nonsticky-at (match-end 0))
5037 (defun org-activate-footnote-links (limit)
5038 "Run through the buffer and add overlays to links."
5039 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
5042 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5043 (add-text-properties (match-beginning 2) (match-end 2)
5044 (list 'mouse-face
'highlight
5045 'keymap org-mouse-map
5047 (if (= (point-at-bol) (match-beginning 2))
5048 "Footnote definition"
5049 "Footnote reference")
5051 (org-rear-nonsticky-at (match-end 2))
5054 (defun org-activate-bracket-links (limit)
5055 "Run through the buffer and add overlays to bracketed links."
5056 (if (re-search-forward org-bracket-link-regexp limit t
)
5057 (let* ((help (concat "LINK: "
5058 (org-match-string-no-properties 1)))
5059 ;; FIXME: above we should remove the escapes.
5060 ;; but that requires another match, protecting match data,
5061 ;; a lot of overhead for font-lock.
5062 (ip (org-maybe-intangible
5063 (list 'invisible
'org-link
5064 'keymap org-mouse-map
'mouse-face
'highlight
5065 'font-lock-multiline t
'help-echo help
)))
5066 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5067 'font-lock-multiline t
'help-echo help
)))
5068 ;; We need to remove the invisible property here. Table narrowing
5069 ;; may have made some of this invisible.
5070 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5071 (remove-text-properties (match-beginning 0) (match-end 0)
5075 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5076 (org-rear-nonsticky-at (match-beginning 3))
5077 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5078 (org-rear-nonsticky-at (match-end 3))
5079 (add-text-properties (match-end 3) (match-end 0) ip
)
5080 (org-rear-nonsticky-at (match-end 0)))
5081 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5082 (org-rear-nonsticky-at (match-beginning 1))
5083 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5084 (org-rear-nonsticky-at (match-end 1))
5085 (add-text-properties (match-end 1) (match-end 0) ip
)
5086 (org-rear-nonsticky-at (match-end 0)))
5089 (defun org-activate-dates (limit)
5090 "Run through the buffer and add overlays to dates."
5091 (if (re-search-forward org-tsr-regexp-both limit t
)
5093 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5094 (add-text-properties (match-beginning 0) (match-end 0)
5095 (list 'mouse-face
'highlight
5096 'keymap org-mouse-map
))
5097 (org-rear-nonsticky-at (match-end 0))
5098 (when org-display-custom-times
5100 (org-display-custom-time (match-beginning 3) (match-end 3)))
5101 (org-display-custom-time (match-beginning 1) (match-end 1)))
5104 (defvar org-target-link-regexp nil
5105 "Regular expression matching radio targets in plain text.")
5106 (make-variable-buffer-local 'org-target-link-regexp
)
5107 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5108 "Regular expression matching a link target.")
5109 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5110 "Regular expression matching a radio target.")
5111 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5112 "Regular expression matching any target.")
5114 (defun org-activate-target-links (limit)
5115 "Run through the buffer and add overlays to target matches."
5116 (when org-target-link-regexp
5117 (let ((case-fold-search t
))
5118 (if (re-search-forward org-target-link-regexp limit t
)
5120 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5121 (add-text-properties (match-beginning 0) (match-end 0)
5122 (list 'mouse-face
'highlight
5123 'keymap org-mouse-map
5124 'help-echo
"Radio target link"
5125 'org-linked-text t
))
5126 (org-rear-nonsticky-at (match-end 0))
5129 (defun org-update-radio-target-regexp ()
5130 "Find all radio targets in this file and update the regular expression."
5132 (when (memq 'radio org-activate-links
)
5133 (setq org-target-link-regexp
5134 (org-make-target-link-regexp (org-all-targets 'radio
)))
5135 (org-restart-font-lock)))
5137 (defun org-hide-wide-columns (limit)
5139 (setq s
(text-property-any (point) (or limit
(point-max))
5142 (setq e
(next-single-property-change s
'org-cwidth
))
5143 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5147 (defvar org-latex-and-specials-regexp nil
5148 "Regular expression for highlighting export special stuff.")
5149 (defvar org-match-substring-regexp
)
5150 (defvar org-match-substring-with-braces-regexp
)
5152 ;; This should be with the exporter code, but we also use if for font-locking
5153 (defconst org-export-html-special-string-regexps
5154 '(("\\\\-" .
"­")
5155 ("---\\([^-]\\)" .
"—\\1")
5156 ("--\\([^-]\\)" .
"–\\1")
5157 ("\\.\\.\\." .
"…"))
5158 "Regular expressions for special string conversion.")
5161 (defun org-compute-latex-and-specials-regexp ()
5162 "Compute regular expression for stuff treated specially by exporters."
5163 (if (not org-highlight-latex-fragments-and-specials
)
5164 (org-set-local 'org-latex-and-specials-regexp nil
)
5167 ((matchers (plist-get org-format-latex-options
:matchers
))
5168 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
5169 org-latex-regexps
)))
5170 (org-export-allow-BIND nil
)
5171 (options (org-combine-plists (org-default-export-plist)
5172 (org-infile-export-plist)))
5173 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
5174 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
5175 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
5176 (org-export-html-expand (plist-get options
:expand-quoted-html
))
5177 (org-export-with-special-strings (plist-get options
:special-strings
))
5180 ((equal org-export-with-sub-superscripts
'{})
5181 (list org-match-substring-with-braces-regexp
))
5182 (org-export-with-sub-superscripts
5183 (list org-match-substring-regexp
))
5186 (if org-export-with-LaTeX-fragments
5187 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
5189 (if org-export-with-TeX-macros
5190 (list (concat "\\\\"
5192 (append (mapcar 'car
(append org-entities-user
5194 (if (boundp 'org-latex-entities
)
5196 (or (car-safe x
) x
))
5201 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5202 (re-special (if org-export-with-special-strings
5203 (mapcar (lambda (x) (car x
))
5204 org-export-html-special-string-regexps
)))
5208 (if org-export-html-expand
"@<[^>\n]+>")
5211 'org-latex-and-specials-regexp
5212 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5215 (defun org-do-latex-and-special-faces (limit)
5216 "Run through the buffer and add overlays to links."
5217 (when org-latex-and-specials-regexp
5219 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5221 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5223 '(org-code org-verbatim underline
)))
5226 d
(cond ((member (char-after (1+ (match-beginning 0)))
5229 (font-lock-prepend-text-property
5230 (+ d
(match-beginning 0)) (match-end 0)
5231 'face
'org-latex-and-export-specials
)
5232 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5233 '(font-lock-multiline t
)))))
5236 (defun org-restart-font-lock ()
5237 "Restart font-lock-mode, to force refontification."
5238 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5240 (font-lock-mode 1)))
5242 (defun org-all-targets (&optional radio
)
5243 "Return a list of all targets in this file.
5244 With optional argument RADIO, only find radio targets."
5245 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5248 (goto-char (point-min))
5249 (while (re-search-forward re nil t
)
5250 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5253 (defun org-make-target-link-regexp (targets)
5254 "Make regular expression matching all strings in TARGETS.
5255 The regular expression finds the targets also if there is a line break
5262 (while (string-match " +" x
)
5263 (setq x
(replace-match "\\s-+" t t x
)))
5269 (defun org-activate-tags (limit)
5270 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t
)
5272 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5273 (add-text-properties (match-beginning 1) (match-end 1)
5274 (list 'mouse-face
'highlight
5275 'keymap org-mouse-map
))
5276 (org-rear-nonsticky-at (match-end 1))
5279 (defun org-outline-level ()
5280 "Compute the outline level of the heading at point.
5281 This function assumes that the cursor is at the beginning of a line matched
5282 by outline-regexp. Otherwise it returns garbage.
5283 If this is called at a normal headline, the level is the number of stars.
5284 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5285 For plain list items, if they are matched by `outline-regexp', this returns
5286 1000 plus the line indentation."
5288 (looking-at outline-regexp
)
5289 (if (match-beginning 1)
5290 (+ (org-get-string-indentation (match-string 1)) 1000)
5291 (1- (- (match-end 0) (match-beginning 0))))))
5293 (defvar org-font-lock-keywords nil
)
5295 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5296 "Regular expression matching a property line.")
5298 (defvar org-font-lock-hook nil
5299 "Functions to be called for special font lock stuff.")
5301 (defun org-font-lock-hook (limit)
5302 (run-hook-with-args 'org-font-lock-hook limit
))
5304 (defun org-set-font-lock-defaults ()
5305 (let* ((em org-fontify-emphasized-text
)
5306 (lk org-activate-links
)
5307 (org-font-lock-extra-keywords
5310 '(org-font-lock-hook)
5312 `(,(if org-fontify-whole-heading-line
5313 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5314 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5315 (1 (org-get-level-face 1))
5316 (2 (org-get-level-face 2))
5317 (3 (org-get-level-face 3)))
5319 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5322 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5323 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5324 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5325 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t
))
5327 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5328 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5330 (list org-property-re
5331 '(1 'org-special-keyword t
)
5332 '(3 'org-property-value t
))
5334 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5335 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5336 (if (memq 'plain lk
) '(org-activate-plain-links))
5337 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5338 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5339 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5340 (if (memq 'footnote lk
) '(org-activate-footnote-links
5341 (2 'org-footnote t
)))
5342 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5343 '(org-hide-wide-columns (0 nil append
))
5345 (list (concat "^\\*+[ \t]+" org-todo-regexp
"\\([ \t]\\|$\\)")
5346 '(1 (org-get-todo-face 1) t
))
5348 (if org-fontify-done-headline
5349 (list (concat "^[*]+ +\\<\\("
5350 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5352 '(2 'org-headline-done t
))
5355 '(org-font-lock-add-priority-faces)
5357 '(org-font-lock-add-tag-faces)
5359 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5360 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5361 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5362 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5365 (if (featurep 'xemacs
)
5366 '(org-do-emphasis-faces (0 nil append
))
5367 '(org-do-emphasis-faces)))
5369 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5370 2 'org-checkbox prepend
)
5371 (if org-provide-checkbox-statistics
5372 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5373 (0 (org-get-checkbox-statistics-face) t
)))
5374 ;; Description list items
5375 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5377 ;; ARCHIVEd headings
5378 (list (concat "^\\*+ \\(.*:" org-archive-tag
":.*\\)")
5379 '(1 'org-archived prepend
))
5381 '(org-do-latex-and-special-faces)
5382 '(org-fontify-entities)
5383 '(org-raise-scripts)
5385 '(org-activate-code (1 'org-code t
))
5387 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5388 "\\|" org-quote-string
"\\)\\>")
5389 '(1 'org-special-keyword t
))
5390 '("^#.*" (0 'font-lock-comment-face t
))
5391 ;; Blocks and meta lines
5392 '(org-fontify-meta-lines-and-blocks)
5394 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5395 ;; Now set the full font-lock-keywords
5396 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5397 (org-set-local 'font-lock-defaults
5398 '(org-font-lock-keywords t nil nil backward-paragraph
))
5399 (kill-local-variable 'font-lock-keywords
) nil
))
5401 (defun org-toggle-pretty-entities ()
5402 "Toggle the compostion display of entities as UTF8 characters."
5404 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
5405 (org-restart-font-lock)
5406 (if org-pretty-entities
5407 (message "Entities are displayed as UTF8 characers")
5410 (decompose-region (point-min) (point-max))
5411 (message "Entities are displayed plain"))))
5413 (defun org-fontify-entities (limit)
5414 "Find an entity to fontify."
5416 (when org-pretty-entities
5418 (while (re-search-forward
5419 "\\\\\\([a-zA-Z][a-zA-Z0-9]*\\)\\($\\|[^[:alnum:]\n]\\)"
5421 (if (and (not (org-in-indented-comment-line))
5422 (setq ee
(org-entity-get (match-string 1)))
5423 (= (length (nth 6 ee
)) 1))
5425 (add-text-properties
5426 (match-beginning 0) (match-end 1)
5427 (list 'font-lock-fontified t
))
5428 (compose-region (match-beginning 0) (match-end 1)
5434 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
5435 "Fontify string S like in Org-mode"
5438 (let ((org-odd-levels-only odd-levels
))
5440 (font-lock-fontify-buffer)
5446 (defun org-get-level-face (n)
5447 "Get the right face for match N in font-lock matching of headlines."
5448 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
5449 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
5450 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
5452 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
5454 (t (if org-level-color-stars-only nil org-f
))))
5456 (defun org-get-todo-face (kwd)
5457 "Get the right face for a TODO keyword KWD.
5458 If KWD is a number, get the corresponding match group."
5459 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5460 (or (org-face-from-face-or-color
5461 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
5462 (and (member kwd org-done-keywords
) 'org-done
)
5465 (defun org-face-from-face-or-color (context inherit face-or-color
)
5466 "Create a face list that inherits INHERIT, but sets the foreground color.
5467 When FACE-OR-COLOR is not a string, just return it."
5468 (if (stringp face-or-color
)
5469 (list :inherit inherit
5470 (cdr (assoc context org-faces-easy-properties
))
5474 (defun org-font-lock-add-tag-faces (limit)
5475 "Add the special tag faces."
5476 (when (and org-tag-faces org-tags-special-faces-re
)
5477 (while (re-search-forward org-tags-special-faces-re limit t
)
5478 (add-text-properties (match-beginning 1) (match-end 1)
5479 (list 'face
(org-get-tag-face 1)
5480 'font-lock-fontified t
))
5481 (backward-char 1))))
5483 (defun org-font-lock-add-priority-faces (limit)
5484 "Add the special priority faces."
5485 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
5486 (add-text-properties
5487 (match-beginning 0) (match-end 0)
5488 (list 'face
(or (org-face-from-face-or-color
5489 'priority
'org-special-keyword
5490 (cdr (assoc (char-after (match-beginning 1))
5491 org-priority-faces
)))
5492 'org-special-keyword
)
5493 'font-lock-fontified t
))))
5495 (defun org-get-tag-face (kwd)
5496 "Get the right face for a TODO keyword KWD.
5497 If KWD is a number, get the corresponding match group."
5498 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5499 (or (org-face-from-face-or-color
5500 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
5503 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
5504 "Remove fontification and activation overlays from links."
5505 (font-lock-default-unfontify-region beg end
)
5506 (let* ((buffer-undo-list t
)
5507 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
5508 (inhibit-modification-hooks t
)
5509 deactivate-mark buffer-file-name buffer-file-truename
)
5510 (decompose-region beg end
)
5511 (remove-text-properties
5514 ;; also remove line-prefix and wrap-prefix properties
5515 '(mouse-face t keymap t org-linked-text t
5516 invisible t intangible t
5517 line-prefix t wrap-prefix t
5518 org-no-flyspell t org-emphasis t
)
5519 '(mouse-face t keymap t org-linked-text t
5520 invisible t intangible t
5521 org-no-flyspell t org-emphasis t
)))
5522 (org-remove-font-lock-display-properties beg end
)))
5524 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
5525 ((raise 0.3) (height 0.7))
5528 "Display properties for showing superscripts and subscripts.")
5530 (defun org-remove-font-lock-display-properties (beg end
)
5531 "Remove specific display properties that have been added by font lock.
5532 The will remove the raise properties that are used to show superscripts
5536 (setq next
(next-single-property-change beg
'display nil end
)
5537 prop
(get-text-property beg
'display
))
5538 (if (member prop org-script-display
)
5539 (put-text-property beg next
'display nil
))
5542 (defun org-raise-scripts (limit)
5543 "Add raise properties to sub/superscripts."
5544 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
5545 (if (re-search-forward
5546 (if (eq org-use-sub-superscripts t
)
5547 org-match-substring-regexp
5548 org-match-substring-with-braces-regexp
)
5550 (let* ((pos (point)) table-p comment-p
5551 (mpos (match-beginning 3))
5552 (emph-p (get-text-property mpos
'org-emphasis
))
5553 (link-p (get-text-property mpos
'mouse-face
))
5554 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
5555 (goto-char (point-at-bol))
5556 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
5557 comment-p
(org-looking-at-p "[ \t]*#"))
5559 (if (or comment-p emph-p link-p keyw-p
)
5561 (put-text-property (match-beginning 3) (match-end 0)
5563 (if (equal (char-after (match-beginning 2)) ?^
)
5564 (nth (if table-p
3 1) org-script-display
)
5565 (nth (if table-p
2 0) org-script-display
)))
5566 (add-text-properties (match-beginning 2) (match-end 2)
5568 'org-dwidth t
'org-dwidth-n
1))
5569 (if (and (eq (char-after (match-beginning 3)) ?
{)
5570 (eq (char-before (match-end 3)) ?
}))
5572 (add-text-properties
5573 (match-beginning 3) (1+ (match-beginning 3))
5574 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
5575 (add-text-properties
5576 (1- (match-end 3)) (match-end 3)
5577 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
5580 ;;;; Visibility cycling, including org-goto and indirect buffer
5584 (defvar org-cycle-global-status nil
)
5585 (make-variable-buffer-local 'org-cycle-global-status
)
5586 (defvar org-cycle-subtree-status nil
)
5587 (make-variable-buffer-local 'org-cycle-subtree-status
)
5591 (defvar org-inlinetask-min-level
)
5593 (defun org-cycle (&optional arg
)
5594 "TAB-action and visibility cycling for Org-mode.
5596 This is the command invoked in Org-mode by the TAB key. Its main purpose
5597 is outline visibility cycling, but it also invokes other actions
5598 in special contexts.
5600 - When this function is called with a prefix argument, rotate the entire
5601 buffer through 3 states (global cycling)
5602 1. OVERVIEW: Show only top-level headlines.
5603 2. CONTENTS: Show all headlines of all levels, but no body text.
5604 3. SHOW ALL: Show everything.
5605 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5606 determined by the variable `org-startup-folded', and by any VISIBILITY
5607 properties in the buffer.
5608 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5609 including any drawers.
5611 - When inside a table, re-align the table and move to the next field.
5613 - When point is at the beginning of a headline, rotate the subtree started
5614 by this line through 3 different states (local cycling)
5615 1. FOLDED: Only the main headline is shown.
5616 2. CHILDREN: The main headline and the direct children are shown.
5617 From this state, you can move to one of the children
5618 and zoom in further.
5619 3. SUBTREE: Show the entire subtree, including body text.
5620 If there is no subtree, switch directly from CHILDREN to FOLDED.
5622 - When point is at the beginning of an empty headline and the variable
5623 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5624 of the headline by demoting and promoting it to likely levels. This
5625 speeds up creation document structure by presing TAB once or several
5626 times right after creating a new headline.
5628 - When there is a numeric prefix, go up to a heading with level ARG, do
5629 a `show-subtree' and return to the previous cursor position. If ARG
5630 is negative, go up that many levels.
5632 - When point is not at the beginning of a headline, execute the global
5633 binding for TAB, which is re-indenting the line. See the option
5634 `org-cycle-emulate-tab' for details.
5636 - Special case: if point is at the beginning of the buffer and there is
5637 no headline in line 1, this function will act as if called with prefix arg.
5638 But only if also the variable `org-cycle-global-at-bob' is t."
5640 (org-load-modules-maybe)
5641 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
5642 (and org-cycle-level-after-item
/entry-creation
5643 (or (org-cycle-level)
5644 (org-cycle-item-indentation))))
5646 (or org-cycle-max-level
5647 (and (boundp 'org-inlinetask-min-level
)
5648 org-inlinetask-min-level
5649 (1- org-inlinetask-min-level
))))
5650 (nstars (and limit-level
5651 (if org-odd-levels-only
5652 (and limit-level
(1- (* limit-level
2)))
5656 ((not (org-mode-p)) outline-regexp
)
5657 ((or (eq org-cycle-include-plain-lists
'integrate
)
5658 (and org-cycle-include-plain-lists
(org-at-item-p)))
5660 (if nstars
(format "\\{1,%d\\}" nstars
) "+")
5661 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5662 (t (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ ")))))
5663 (bob-special (and org-cycle-global-at-bob
(bobp)
5664 (not (looking-at outline-regexp
))))
5667 (delq 'org-optimize-window-after-visibility-change
5668 (copy-sequence org-cycle-hook
))
5672 (if (or bob-special
(equal arg
'(4)))
5673 ;; special case: use global cycling
5679 (org-set-startup-visibility)
5680 (message "Startup visibility, plus VISIBILITY properties"))
5684 (message "Entire buffer visible, including drawers"))
5686 ((org-at-table-p 'any
)
5687 ;; Enter the table or move to the next field in the table
5688 (if (org-at-table.el-p
)
5689 (message "Use C-c ' to edit table.el tables")
5690 (if arg
(org-table-edit-field t
)
5691 (org-table-justify-field-maybe)
5692 (call-interactively 'org-table-next-field
))))
5694 ((run-hook-with-args-until-success
5695 'org-tab-after-check-for-table-hook
))
5697 ((eq arg t
) ;; Global cycling
5698 (org-cycle-internal-global))
5700 ((and org-drawers org-drawer-regexp
5702 (beginning-of-line 1)
5703 (looking-at org-drawer-regexp
)))
5704 ;; Toggle block visibility
5706 (not (get-char-property (match-end 0) 'invisible
))))
5709 ;; Show-subtree, ARG levels up from here.
5711 (org-back-to-heading)
5712 (outline-up-heading (if (< arg
0) (- arg
)
5713 (- (funcall outline-level
) arg
)))
5714 (org-show-subtree)))
5716 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp
))
5717 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
5719 (org-cycle-internal-local))
5721 ;; TAB emulation and template completion
5722 (buffer-read-only (org-back-to-heading))
5724 ((run-hook-with-args-until-success
5725 'org-tab-after-check-for-cycling-hook
))
5727 ((org-try-structure-completion))
5729 ((org-try-cdlatex-tab))
5731 ((run-hook-with-args-until-success
5732 'org-tab-before-tab-emulation-hook
))
5734 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
5736 (not (looking-at outline-regexp
))))
5737 (call-interactively (global-key-binding "\t")))
5739 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
5740 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5741 (or (and (eq org-cycle-emulate-tab
'white
)
5742 (= (match-end 0) (point-at-eol)))
5743 (and (eq org-cycle-emulate-tab
'whitestart
)
5744 (>= (match-end 0) pos
))))
5746 (eq org-cycle-emulate-tab t
))
5747 (call-interactively (global-key-binding "\t")))
5750 (org-back-to-heading)
5753 (defun org-cycle-internal-global ()
5754 "Do the global cycling action."
5756 ((and (eq last-command this-command
)
5757 (eq org-cycle-global-status
'overview
))
5758 ;; We just created the overview - now do table of contents
5759 ;; This can be slow in very large buffers, so indicate action
5760 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
5761 (message "CONTENTS...")
5763 (message "CONTENTS...done")
5764 (setq org-cycle-global-status
'contents
)
5765 (run-hook-with-args 'org-cycle-hook
'contents
))
5767 ((and (eq last-command this-command
)
5768 (eq org-cycle-global-status
'contents
))
5769 ;; We just showed the table of contents - now show everything
5770 (run-hook-with-args 'org-pre-cycle-hook
'all
)
5772 (message "SHOW ALL")
5773 (setq org-cycle-global-status
'all
)
5774 (run-hook-with-args 'org-cycle-hook
'all
))
5777 ;; Default action: go to overview
5778 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
5780 (message "OVERVIEW")
5781 (setq org-cycle-global-status
'overview
)
5782 (run-hook-with-args 'org-cycle-hook
'overview
))))
5784 (defun org-cycle-internal-local ()
5785 "Do the local cycling action."
5786 (org-back-to-heading)
5787 (let ((goal-column 0) eoh eol eos level has-children children-skipped
)
5788 ;; First, some boundaries
5790 (org-back-to-heading)
5791 (setq level
(funcall outline-level
))
5793 (beginning-of-line 2)
5794 (if (or (featurep 'xemacs
) (<= emacs-major-version
21))
5795 ; XEmacs does not have `next-single-char-property-change'
5796 ; I'm not sure about Emacs 21.
5797 (while (and (not (eobp)) ;; this is like `next-line'
5798 (get-char-property (1- (point)) 'invisible
))
5799 (beginning-of-line 2))
5800 (while (and (not (eobp)) ;; this is like `next-line'
5801 (get-char-property (1- (point)) 'invisible
))
5802 (goto-char (next-single-char-property-change (point) 'invisible
))
5803 (and (eolp) (beginning-of-line 2))))
5805 (outline-end-of-heading) (setq eoh
(point))
5807 (outline-next-heading)
5808 (setq has-children
(and (org-at-heading-p t
)
5809 (> (funcall outline-level
) level
))))
5810 (org-end-of-subtree t
)
5812 (skip-chars-forward " \t\n")
5813 (beginning-of-line 1) ; in case this is an item
5815 (setq eos
(if (eobp) (point) (1- (point)))))
5816 ;; Find out what to do next and set `this-command'
5819 ;; Nothing is hidden behind this heading
5820 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
5821 (message "EMPTY ENTRY")
5822 (setq org-cycle-subtree-status nil
)
5825 (outline-next-heading)
5826 (if (org-invisible-p) (org-flag-heading nil
))))
5827 ((and (or (>= eol eos
)
5828 (not (string-match "\\S-" (buffer-substring eol eos
))))
5830 (not (setq children-skipped
5831 org-cycle-skip-children-state-if-no-children
))))
5832 ;; Entire subtree is hidden in one line: children view
5833 (run-hook-with-args 'org-pre-cycle-hook
'children
)
5836 (message "CHILDREN")
5839 (outline-next-heading)
5840 (if (org-invisible-p) (org-flag-heading nil
)))
5841 (setq org-cycle-subtree-status
'children
)
5842 (run-hook-with-args 'org-cycle-hook
'children
))
5843 ((or children-skipped
5844 (and (eq last-command this-command
)
5845 (eq org-cycle-subtree-status
'children
)))
5846 ;; We just showed the children, or no children are there,
5847 ;; now show everything.
5848 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
5850 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
5851 (setq org-cycle-subtree-status
'subtree
)
5852 (run-hook-with-args 'org-cycle-hook
'subtree
))
5854 ;; Default action: hide the subtree.
5855 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
5858 (setq org-cycle-subtree-status
'folded
)
5859 (run-hook-with-args 'org-cycle-hook
'folded
)))))
5862 (defun org-global-cycle (&optional arg
)
5863 "Cycle the global visibility. For details see `org-cycle'.
5864 With C-u prefix arg, switch to startup visibility.
5865 With a numeric prefix, show all headlines up to that level."
5867 (let ((org-cycle-include-plain-lists
5868 (if (org-mode-p) org-cycle-include-plain-lists nil
)))
5872 (hide-sublevels arg
)
5873 (setq org-cycle-global-status
'contents
))
5875 (org-set-startup-visibility)
5876 (message "Startup visibility, plus VISIBILITY properties."))
5878 (org-cycle '(4))))))
5880 (defun org-set-startup-visibility ()
5881 "Set the visibility required by startup options and properties."
5883 ((eq org-startup-folded t
)
5885 ((eq org-startup-folded
'content
)
5886 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
5887 (org-cycle '(4)) (org-cycle '(4)))))
5888 (unless (eq org-startup-folded
'showeverything
)
5889 (if org-hide-block-startup
(org-hide-block-all))
5890 (org-set-visibility-according-to-property 'no-cleanup
)
5891 (org-cycle-hide-archived-subtrees 'all
)
5892 (org-cycle-hide-drawers 'all
)
5893 (org-cycle-show-empty-lines t
)))
5895 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
5896 "Switch subtree visibilities according to :VISIBILITY: property."
5898 (let (org-show-entry-below state
)
5900 (goto-char (point-min))
5901 (while (re-search-forward
5902 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5904 (setq state
(match-string 1))
5906 (org-back-to-heading t
)
5910 ((equal state
'("fold" "folded"))
5912 ((equal state
"children")
5913 (org-show-hidden-entry)
5915 ((equal state
"content")
5918 (org-narrow-to-subtree)
5920 ((member state
'("all" "showall"))
5923 (org-cycle-hide-archived-subtrees 'all
)
5924 (org-cycle-hide-drawers 'all
)
5925 (org-cycle-show-empty-lines 'all
)))))
5927 (defun org-overview ()
5928 "Switch to overview mode, showing only top-level headlines.
5929 Really, this shows all headlines with level equal or greater than the level
5930 of the first headline in the buffer. This is important, because if the
5931 first headline is not level one, then (hide-sublevels 1) gives confusing
5934 (let ((level (save-excursion
5935 (goto-char (point-min))
5936 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
5938 (goto-char (match-beginning 0))
5939 (funcall outline-level
))))))
5940 (and level
(hide-sublevels level
))))
5942 (defun org-content (&optional arg
)
5943 "Show all headlines in the buffer, like a table of contents.
5944 With numerical argument N, show content up to level N."
5947 ;; Visit all headings and show their offspring
5948 (and (integerp arg
) (org-overview))
5949 (goto-char (point-max))
5951 (while (and (progn (condition-case nil
5952 (outline-previous-visible-heading 1)
5953 (error (goto-char (point-min))))
5955 (looking-at outline-regexp
))
5957 (show-children (1- arg
))
5959 (if (bobp) (throw 'exit nil
))))))
5962 (defun org-optimize-window-after-visibility-change (state)
5963 "Adjust the window after a change in outline visibility.
5964 This function is the default value of the hook `org-cycle-hook'."
5965 (when (get-buffer-window (current-buffer))
5967 ((eq state
'content
) nil
)
5968 ((eq state
'all
) nil
)
5969 ((eq state
'folded
) nil
)
5970 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
5971 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
5973 (defun org-remove-empty-overlays-at (pos)
5974 "Remove outline overlays that do not contain non-white stuff."
5977 (and (eq 'outline
(overlay-get o
'invisible
))
5978 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
5980 (delete-overlay o
)))
5983 (defun org-clean-visibility-after-subtree-move ()
5984 "Fix visibility issues after moving a subtree."
5985 ;; First, find a reasonable region to look at:
5986 ;; Start two siblings above, end three below
5987 (let* ((beg (save-excursion
5988 (and (org-get-last-sibling)
5989 (org-get-last-sibling))
5991 (end (save-excursion
5992 (and (org-get-next-sibling)
5993 (org-get-next-sibling)
5994 (org-get-next-sibling))
5995 (if (org-at-heading-p)
5998 (level (looking-at "\\*+"))
5999 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6002 (narrow-to-region beg end
)
6004 ;; Properly fold already folded siblings
6005 (goto-char (point-min))
6006 (while (re-search-forward re nil t
)
6007 (if (and (not (org-invisible-p))
6009 (goto-char (point-at-eol)) (org-invisible-p)))
6011 (org-cycle-show-empty-lines 'overview
)
6012 (org-cycle-hide-drawers 'overview
)))))
6014 (defun org-cycle-show-empty-lines (state)
6015 "Show empty lines above all visible headlines.
6016 The region to be covered depends on STATE when called through
6017 `org-cycle-hook'. Lisp program can use t for STATE to get the
6018 entire buffer covered. Note that an empty line is only shown if there
6019 are at least `org-cycle-separator-lines' empty lines before the headline."
6020 (when (not (= org-cycle-separator-lines
0))
6022 (let* ((n (abs org-cycle-separator-lines
))
6024 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6025 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6026 (t (let ((ns (number-to-string (- n
2))))
6027 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6028 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6031 ((memq state
'(overview contents t
))
6032 (setq beg
(point-min) end
(point-max)))
6033 ((memq state
'(children folded
))
6034 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6035 (beginning-of-line 2)
6039 (while (re-search-forward re end t
)
6040 (unless (get-char-property (match-end 1) 'invisible
)
6041 (setq e
(match-end 1))
6042 (if (< org-cycle-separator-lines
0)
6043 (setq b
(save-excursion
6044 (goto-char (match-beginning 0))
6045 (org-back-over-empty-lines)
6047 (goto-char (max (point-min) (1- (point))))
6051 (setq b
(match-beginning 1)))
6052 (outline-flag-region b e nil
)))))))
6053 ;; Never hide empty lines at the end of the file.
6055 (goto-char (point-max))
6056 (outline-previous-heading)
6057 (outline-end-of-heading)
6058 (if (and (looking-at "[ \t\n]+")
6059 (= (match-end 0) (point-max)))
6060 (outline-flag-region (point) (match-end 0) nil
))))
6062 (defun org-show-empty-lines-in-parent ()
6063 "Move to the parent and re-show empty lines before visible headlines."
6065 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6066 (org-cycle-show-empty-lines context
))))
6068 (defun org-files-list ()
6069 "Return `org-agenda-files' list, plus all open org-mode files.
6070 This is useful for operations that need to scan all of a user's
6071 open and agenda-wise Org files."
6072 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6073 (dolist (buf (buffer-list))
6074 (with-current-buffer buf
6075 (if (and (eq major-mode
'org-mode
) (buffer-file-name))
6076 (let ((file (expand-file-name (buffer-file-name))))
6077 (unless (member file files
)
6078 (push file files
))))))
6081 (defsubst org-entry-beginning-position
()
6082 "Return the beginning position of the current entry."
6083 (save-excursion (outline-back-to-heading t
) (point)))
6085 (defsubst org-entry-end-position
()
6086 "Return the end position of the current entry."
6087 (save-excursion (outline-next-heading) (point)))
6089 (defun org-cycle-hide-drawers (state)
6090 "Re-hide all drawers after a visibility state change."
6091 (when (and (org-mode-p)
6092 (not (memq state
'(overview folded contents
))))
6094 (let* ((globalp (memq state
'(contents all
)))
6095 (beg (if globalp
(point-min) (point)))
6096 (end (if globalp
(point-max)
6097 (if (eq state
'children
)
6098 (save-excursion (outline-next-heading) (point))
6099 (org-end-of-subtree t
)))))
6101 (while (re-search-forward org-drawer-regexp end t
)
6102 (org-flag-drawer t
))))))
6104 (defun org-flag-drawer (flag)
6106 (beginning-of-line 1)
6107 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6108 (let ((b (match-end 0))
6109 (outline-regexp org-outline-regexp
))
6110 (if (re-search-forward
6112 (save-excursion (outline-next-heading) (point)) t
)
6113 (outline-flag-region b
(point-at-eol) flag
)
6114 (error ":END: line missing at position %s" b
))))))
6116 (defun org-subtree-end-visible-p ()
6117 "Is the end of the current subtree visible?"
6118 (pos-visible-in-window-p
6119 (save-excursion (org-end-of-subtree t
) (point))))
6121 (defun org-first-headline-recenter (&optional N
)
6122 "Move cursor to the first headline and recenter the headline.
6123 Optional argument N means put the headline into the Nth line of the window."
6124 (goto-char (point-min))
6125 (when (re-search-forward (concat "^\\(" outline-regexp
"\\)") nil t
)
6127 (recenter (prefix-numeric-value N
))))
6129 ;;; Saving and restoring visibility
6131 (defun org-outline-overlay-data (&optional use-markers
)
6132 "Return a list of the locations of all outline overlays.
6133 The are overlays with the `invisible' property value `outline'.
6134 The return valus is a list of cons cells, with start and stop
6135 positions for each overlay.
6136 If USE-MARKERS is set, return the positions as markers."
6143 (when (eq (overlay-get o
'invisible
) 'outline
)
6144 (setq beg
(overlay-start o
)
6145 end
(overlay-end o
))
6146 (and beg end
(> end beg
)
6148 (cons (move-marker (make-marker) beg
)
6149 (move-marker (make-marker) end
))
6151 (overlays-in (point-min) (point-max))))))))
6153 (defun org-set-outline-overlay-data (data)
6154 "Create visibility overlays for all positions in DATA.
6155 DATA should have been made by `org-outline-overlay-data'."
6162 (setq o
(make-overlay (car c
) (cdr c
)))
6163 (overlay-put o
'invisible
'outline
))
6166 (defmacro org-save-outline-visibility
(use-markers &rest body
)
6167 "Save and restore outline visibility around BODY.
6168 If USE-MARKERS is non-nil, use markers for the positions.
6169 This means that the buffer may change while running BODY,
6170 but it also means that the buffer should stay alive
6171 during the operation, because otherwise all these markers will
6173 (declare (indent 1))
6174 `(let ((data (org-outline-overlay-data ,use-markers
)))
6178 (org-set-outline-overlay-data data
))
6181 (and (markerp (car c
)) (move-marker (car c
) nil
))
6182 (and (markerp (cdr c
)) (move-marker (cdr c
) nil
)))
6186 ;;; Folding of blocks
6188 (defconst org-block-regexp
6190 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
6191 "Regular expression for hiding blocks.")
6193 (defvar org-hide-block-overlays nil
6194 "Overlays hiding blocks.")
6195 (make-variable-buffer-local 'org-hide-block-overlays
)
6197 (defun org-block-map (function &optional start end
)
6198 "Call func at the head of all source blocks in the current
6199 buffer. Optional arguments START and END can be used to limit
6201 (let ((start (or start
(point-min)))
6202 (end (or end
(point-max))))
6205 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6208 (goto-char (match-beginning 0))
6209 (funcall function
)))))))
6211 (defun org-hide-block-toggle-all ()
6212 "Toggle the visibility of all blocks in the current buffer."
6213 (org-block-map #'org-hide-block-toggle
))
6215 (defun org-hide-block-all ()
6216 "Fold all blocks in the current buffer."
6218 (org-show-block-all)
6219 (org-block-map #'org-hide-block-toggle-maybe
))
6221 (defun org-show-block-all ()
6222 "Unfold all blocks in the current buffer."
6224 (mapc 'delete-overlay org-hide-block-overlays
)
6225 (setq org-hide-block-overlays nil
))
6227 (defun org-hide-block-toggle-maybe ()
6228 "Toggle visibility of block at point."
6230 (let ((case-fold-search t
))
6232 (beginning-of-line 1)
6233 (looking-at org-block-regexp
))
6234 (progn (org-hide-block-toggle)
6235 t
) ;; to signal that we took action
6236 nil
))) ;; to signal that we did not
6238 (defun org-hide-block-toggle (&optional force
)
6239 "Toggle the visibility of the current block."
6243 (if (re-search-forward org-block-regexp nil t
)
6244 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6245 (end (match-end 0)) ;; end of entire body
6247 (if (memq t
(mapcar (lambda (overlay)
6248 (eq (overlay-get overlay
'invisible
)
6250 (overlays-at start
)))
6251 (if (or (not force
) (eq force
'off
))
6253 (when (member ov org-hide-block-overlays
)
6254 (setq org-hide-block-overlays
6255 (delq ov org-hide-block-overlays
)))
6256 (when (eq (overlay-get ov
'invisible
)
6258 (delete-overlay ov
)))
6259 (overlays-at start
)))
6260 (setq ov
(make-overlay start end
))
6261 (overlay-put ov
'invisible
'org-hide-block
)
6262 ;; make the block accessible to isearch
6264 ov
'isearch-open-invisible
6266 (when (member ov org-hide-block-overlays
)
6267 (setq org-hide-block-overlays
6268 (delq ov org-hide-block-overlays
)))
6269 (when (eq (overlay-get ov
'invisible
)
6271 (delete-overlay ov
))))
6272 (push ov org-hide-block-overlays
)))
6273 (error "Not looking at a source block"))))
6275 ;; org-tab-after-check-for-cycling-hook
6276 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6277 ;; Remove overlays when changing major mode
6278 (add-hook 'org-mode-hook
6279 (lambda () (org-add-hook 'change-major-mode-hook
6280 'org-show-block-all
'append
'local
)))
6284 (defvar org-goto-window-configuration nil
)
6285 (defvar org-goto-marker nil
)
6286 (defvar org-goto-map
6287 (let ((map (make-sparse-keymap)))
6288 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6289 (while (setq cmd
(pop cmds
))
6290 (substitute-key-definition cmd cmd map global-map
)))
6291 (suppress-keymap map
)
6292 (org-defkey map
"\C-m" 'org-goto-ret
)
6293 (org-defkey map
[(return)] 'org-goto-ret
)
6294 (org-defkey map
[(left)] 'org-goto-left
)
6295 (org-defkey map
[(right)] 'org-goto-right
)
6296 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6297 (org-defkey map
"\C-i" 'org-cycle
)
6298 (org-defkey map
[(tab)] 'org-cycle
)
6299 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6300 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6301 (if org-goto-auto-isearch
6302 (if (fboundp 'define-key-after
)
6303 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6305 (org-defkey map "q" 'org-goto-quit)
6306 (org-defkey map "n" 'outline-next-visible-heading)
6307 (org-defkey map "p" 'outline-previous-visible-heading)
6308 (org-defkey map "f" 'outline-forward-same-level)
6309 (org-defkey map "b" 'outline-backward-same-level)
6310 (org-defkey map "u" 'outline-up-heading))
6311 (org-defkey map "/" 'org-occur)
6312 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6313 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6314 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6315 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6316 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6319 (defconst org-goto-help
6320 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6321 RET=jump to location [Q]uit and return to previous location
6322 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6324 (defvar org-goto-start-pos) ; dynamically scoped parameter
6326 ;; FIXME: Docstring does not mention both interfaces
6327 (defun org-goto (&optional alternative-interface)
6328 "Look up a different location in the current file, keeping current visibility.
6330 When you want look-up or go to a different location in a document, the
6331 fastest way is often to fold the entire buffer and then dive into the tree.
6332 This method has the disadvantage, that the previous location will be folded,
6333 which may not be what you want.
6335 This command works around this by showing a copy of the current buffer
6336 in an indirect buffer, in overview mode. You can dive into the tree in
6337 that copy, use org-occur and incremental search to find a location.
6338 When pressing RET or `Q', the command returns to the original buffer in
6339 which the visibility is still unchanged. After RET is will also jump to
6340 the location selected in the indirect buffer and expose the
6341 the headline hierarchy above."
6343 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6344 (org-refile-use-outline-path t)
6345 (org-refile-target-verify-function nil)
6347 (if (not alternative-interface)
6349 (if (eq org-goto-interface 'outline)
6350 'outline-path-completion
6352 (org-goto-start-pos (point))
6354 (if (eq interface 'outline)
6355 (car (org-get-location (current-buffer) org-goto-help))
6356 (nth 3 (org-refile-get-location "Goto: ")))))
6359 (org-mark-ring-push org-goto-start-pos)
6360 (goto-char selected-point)
6361 (if (or (org-invisible-p) (org-invisible-p2))
6362 (org-show-context 'org-goto)))
6365 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6366 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6367 (defvar org-goto-local-auto-isearch-map) ; defined below
6369 (defun org-get-location (buf help)
6370 "Let the user select a location in the Org-mode buffer BUF.
6371 This function uses a recursive edit. It returns the selected position
6373 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6374 (isearch-hide-immediately nil)
6375 (isearch-search-fun-function
6376 (lambda () 'org-goto-local-search-headings))
6377 (org-goto-selected-point org-goto-exit-command)
6379 (special-display-buffer-names nil)
6380 (special-display-regexps nil)
6381 (special-display-function nil))
6383 (save-window-excursion
6384 (delete-other-windows)
6385 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6388 (make-indirect-buffer (current-buffer) "*org-goto*")
6389 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6390 (with-output-to-temp-buffer "*Help*"
6392 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6393 (setq buffer-read-only nil)
6394 (let ((org-startup-truncated t)
6395 (org-startup-folded nil)
6396 (org-startup-align-all-tables nil))
6399 (setq buffer-read-only t)
6400 (if (and (boundp 'org-goto-start-pos)
6401 (integer-or-marker-p org-goto-start-pos))
6402 (let ((org-show-hierarchy-above t)
6403 (org-show-siblings t)
6404 (org-show-following-heading t))
6405 (goto-char org-goto-start-pos)
6406 (and (org-invisible-p) (org-show-context)))
6407 (goto-char (point-min)))
6408 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6409 (message "Select location and press RET")
6410 (use-local-map org-goto-map)
6413 (kill-buffer "*org-goto*")
6414 (cons org-goto-selected-point org-goto-exit-command)))
6416 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6417 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6418 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6419 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6421 (defun org-goto-local-search-headings (string bound noerror)
6422 "Search and make sure that any matches are in headlines."
6424 (while (if isearch-forward
6425 (search-forward string bound noerror)
6426 (search-backward string bound noerror))
6427 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6428 (and (member :headline context)
6429 (not (member :tags context))))
6430 (throw 'return (point))))))
6432 (defun org-goto-local-auto-isearch ()
6435 (goto-char (point-min))
6436 (let ((keys (this-command-keys)))
6437 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6439 (isearch-process-search-char (string-to-char keys)))))
6441 (defun org-goto-ret (&optional arg)
6442 "Finish `org-goto' by going to the new location."
6444 (setq org-goto-selected-point (point)
6445 org-goto-exit-command 'return)
6448 (defun org-goto-left ()
6449 "Finish `org-goto' by going to the new location."
6451 (if (org-on-heading-p)
6453 (beginning-of-line 1)
6454 (setq org-goto-selected-point (point)
6455 org-goto-exit-command 'left)
6457 (error "Not on a heading")))
6459 (defun org-goto-right ()
6460 "Finish `org-goto' by going to the new location."
6462 (if (org-on-heading-p)
6464 (setq org-goto-selected-point (point)
6465 org-goto-exit-command 'right)
6467 (error "Not on a heading")))
6469 (defun org-goto-quit ()
6470 "Finish `org-goto' without cursor motion."
6472 (setq org-goto-selected-point nil)
6473 (setq org-goto-exit-command 'quit)
6476 ;;; Indirect buffer display of subtrees
6478 (defvar org-indirect-dedicated-frame nil
6479 "This is the frame being used for indirect tree display.")
6480 (defvar org-last-indirect-buffer nil)
6482 (defun org-tree-to-indirect-buffer (&optional arg)
6483 "Create indirect buffer and narrow it to current subtree.
6484 With numerical prefix ARG, go up to this level and then take that tree.
6485 If ARG is negative, go up that many levels.
6486 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6487 indirect buffer previously made with this command, to avoid proliferation of
6488 indirect buffers. However, when you call the command with a `C-u' prefix, or
6489 when `org-indirect-buffer-display' is `new-frame', the last buffer
6490 is kept so that you can work with several indirect buffers at the same time.
6491 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6492 requests that a new frame be made for the new buffer, so that the dedicated
6493 frame is not changed."
6495 (let ((cbuf (current-buffer))
6496 (cwin (selected-window))
6498 beg end level heading ibuf)
6500 (org-back-to-heading t)
6502 (setq level (org-outline-level))
6503 (if (< arg 0) (setq arg (+ level arg)))
6504 (while (> (setq level (org-outline-level)) arg)
6505 (outline-up-heading 1 t)))
6507 heading (org-get-heading))
6508 (org-end-of-subtree t t)
6509 (if (org-on-heading-p) (backward-char 1))
6511 (if (and (buffer-live-p org-last-indirect-buffer)
6512 (not (eq org-indirect-buffer-display 'new-frame))
6514 (kill-buffer org-last-indirect-buffer))
6515 (setq ibuf (org-get-indirect-buffer cbuf)
6516 org-last-indirect-buffer ibuf)
6518 ((or (eq org-indirect-buffer-display 'new-frame)
6519 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6520 (select-frame (make-frame))
6521 (delete-other-windows)
6522 (switch-to-buffer ibuf)
6523 (org-set-frame-title heading))
6524 ((eq org-indirect-buffer-display 'dedicated-frame)
6526 (select-frame (or (and org-indirect-dedicated-frame
6527 (frame-live-p org-indirect-dedicated-frame)
6528 org-indirect-dedicated-frame)
6529 (setq org-indirect-dedicated-frame (make-frame)))))
6530 (delete-other-windows)
6531 (switch-to-buffer ibuf)
6532 (org-set-frame-title (concat "Indirect: " heading)))
6533 ((eq org-indirect-buffer-display 'current-window)
6534 (switch-to-buffer ibuf))
6535 ((eq org-indirect-buffer-display 'other-window)
6536 (pop-to-buffer ibuf))
6537 (t (error "Invalid value")))
6538 (if (featurep 'xemacs)
6539 (save-excursion (org-mode) (turn-on-font-lock)))
6540 (narrow-to-region beg end)
6543 (and (window-live-p cwin) (select-window cwin))))
6545 (defun org-get-indirect-buffer (&optional buffer)
6546 (setq buffer (or buffer (current-buffer)))
6547 (let ((n 1) (base (buffer-name buffer)) bname)
6548 (while (buffer-live-p
6549 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6552 (make-indirect-buffer buffer bname 'clone)
6553 (error (make-indirect-buffer buffer bname)))))
6555 (defun org-set-frame-title (title)
6556 "Set the title of the current frame to the string TITLE."
6557 ;; FIXME: how to name a single frame in XEmacs???
6558 (unless (featurep 'xemacs)
6559 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6561 ;;;; Structure editing
6563 ;;; Inserting headlines
6565 (defun org-previous-line-empty-p ()
6568 (or (beginning-of-line 0) t)
6570 (looking-at "[ \t]*$")))))
6572 (defun org-insert-heading (&optional force-heading invisible-ok)
6573 "Insert a new heading or item with same depth at point.
6574 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6575 If point is at the beginning of a headline, insert a sibling before the
6576 current headline. If point is not at the beginning, do not split the line,
6577 but create the new headline after the current line.
6578 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6579 This is important for non-interactive uses of the command."
6581 (if (or (= (buffer-size) 0)
6582 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6583 (org-on-heading-p))))
6584 (not (org-in-item-p))))
6586 (when (or force-heading (not (org-insert-item)))
6587 (let* ((empty-line-p nil)
6588 (head (save-excursion
6591 (org-back-to-heading invisible-ok)
6592 (setq empty-line-p (org-previous-line-empty-p))
6595 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6596 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6597 pos hide-previous previous-pos)
6599 ((and (org-on-heading-p) (bolp)
6601 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6602 ;; insert before the current line
6603 (open-line (if blank 2 1)))
6605 (not org-insert-heading-respect-content)
6608 (backward-char 1) (not (org-invisible-p)))))
6609 ;; insert right here
6612 ;; somewhere in the line
6614 (setq previous-pos (point-at-bol))
6616 (setq hide-previous (org-invisible-p)))
6617 (and org-insert-heading-respect-content (org-show-subtree))
6619 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6622 (goto-char (point-at-bol))
6623 (and (looking-at org-complex-heading-regexp)
6624 (> p (match-beginning 4)))))))
6627 (org-insert-heading-respect-content
6628 (org-end-of-subtree nil t)
6629 (or (bolp) (newline))
6630 (or (org-previous-line-empty-p)
6631 (and blank (newline)))
6637 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6638 (setq tags (and (match-end 2) (match-string 2)))
6640 (delete-region (match-beginning 1) (match-end 1)))
6641 (setq pos (point-at-bol))
6642 (or split (end-of-line 1))
6643 (delete-horizontal-space)
6644 (if (string-match "\\`\\*+\\'"
6645 (buffer-substring (point-at-bol) (point)))
6647 (newline (if blank 2 1))
6653 (org-set-tags nil 'align))))
6655 (or split (end-of-line 1))
6656 (newline (if blank 2 1)))))))
6657 (insert head) (just-one-space)
6660 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6661 (when (and org-insert-heading-respect-content hide-previous)
6663 (goto-char previous-pos)
6665 (run-hooks 'org-insert-heading-hook)))))
6667 (defun org-get-heading (&optional no-tags)
6668 "Return the heading of the current entry, without the stars."
6670 (org-back-to-heading t)
6673 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6674 "\\*+[ \t]+\\([^\r\n]*\\)"))
6675 (match-string 1) "")))
6677 (defun org-heading-components ()
6678 "Return the components of the current heading.
6679 This is a list with the following elements:
6680 - the level as an integer
6681 - the reduced level, different if `org-odd-levels-only' is set.
6682 - the TODO keyword, or nil
6683 - the priority character, like ?A, or nil if no priority is given
6684 - the headline text itself, or the tags string if no headline text
6685 - the tags string, or nil."
6687 (org-back-to-heading t)
6688 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6689 (list (length (match-string 1))
6690 (org-reduced-level (length (match-string 1)))
6691 (org-match-string-no-properties 2)
6692 (and (match-end 3) (aref (match-string 3) 2))
6693 (org-match-string-no-properties 4)
6694 (org-match-string-no-properties 5)))))
6696 (defun org-get-entry ()
6697 "Get the entry text, after heading, entire subtree."
6699 (org-back-to-heading t)
6700 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6702 (defun org-insert-heading-after-current ()
6703 "Insert a new heading with same level as current, after current subtree."
6705 (org-back-to-heading)
6706 (org-insert-heading)
6707 (org-move-subtree-down)
6710 (defun org-insert-heading-respect-content ()
6712 (let ((org-insert-heading-respect-content t))
6713 (org-insert-heading t)))
6715 (defun org-insert-todo-heading-respect-content (&optional force-state)
6717 (let ((org-insert-heading-respect-content t))
6718 (org-insert-todo-heading force-state t)))
6720 (defun org-insert-todo-heading (arg &optional force-heading)
6721 "Insert a new heading with the same level and TODO state as current heading.
6722 If the heading has no TODO state, or if the state is DONE, use the first
6723 state (TODO by default). Also with prefix arg, force first state."
6725 (when (or force-heading (not (org-insert-item 'checkbox)))
6726 (org-insert-heading force-heading)
6728 (org-back-to-heading)
6729 (outline-previous-heading)
6730 (looking-at org-todo-line-regexp))
6734 (not (match-beginning 2))
6735 (member (match-string 2) org-done-keywords))
6736 (car org-todo-keywords-1)
6740 (run-hook-with-args-until-success
6741 'org-todo-get-default-hook new-mark-x nil)
6743 (beginning-of-line 1)
6744 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6745 (if org-treat-insert-todo-heading-as-state-change
6747 (insert new-mark " "))))
6748 (when org-provide-todo-statistics
6749 (org-update-parent-todo-statistics))))
6751 (defun org-insert-subheading (arg)
6752 "Insert a new subheading and demote it.
6753 Works for outline headings and for plain lists alike."
6755 (org-insert-heading arg)
6757 ((org-on-heading-p) (org-do-demote))
6758 ((org-at-item-p) (org-indent-item 1))))
6760 (defun org-insert-todo-subheading (arg)
6761 "Insert a new subheading with TODO keyword or checkbox and demote it.
6762 Works for outline headings and for plain lists alike."
6764 (org-insert-todo-heading arg)
6766 ((org-on-heading-p) (org-do-demote))
6767 ((org-at-item-p) (org-indent-item 1))))
6769 ;;; Promotion and Demotion
6771 (defvar org-after-demote-entry-hook nil
6772 "Hook run after an entry has been demoted.
6773 The cursor will be at the beginning of the entry.
6774 When a subtree is being demoted, the hook will be called for each node.")
6776 (defvar org-after-promote-entry-hook nil
6777 "Hook run after an entry has been promoted.
6778 The cursor will be at the beginning of the entry.
6779 When a subtree is being promoted, the hook will be called for each node.")
6781 (defun org-promote-subtree ()
6782 "Promote the entire subtree.
6783 See also `org-promote'."
6786 (org-map-tree 'org-promote))
6787 (org-fix-position-after-promote))
6789 (defun org-demote-subtree ()
6790 "Demote the entire subtree. See `org-demote'.
6791 See also `org-promote'."
6794 (org-map-tree 'org-demote))
6795 (org-fix-position-after-promote))
6798 (defun org-do-promote ()
6799 "Promote the current heading higher up the tree.
6800 If the region is active in `transient-mark-mode', promote all headings
6804 (if (org-region-active-p)
6805 (org-map-region 'org-promote (region-beginning) (region-end))
6807 (org-fix-position-after-promote))
6809 (defun org-do-demote ()
6810 "Demote the current heading lower down the tree.
6811 If the region is active in `transient-mark-mode', demote all headings
6815 (if (org-region-active-p)
6816 (org-map-region 'org-demote (region-beginning) (region-end))
6818 (org-fix-position-after-promote))
6820 (defun org-fix-position-after-promote ()
6821 "Make sure that after pro/demotion cursor position is right."
6822 (let ((pos (point)))
6823 (when (save-excursion
6824 (beginning-of-line 1)
6825 (looking-at org-todo-line-regexp)
6826 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6827 (cond ((eobp) (insert " "))
6828 ((eolp) (insert " "))
6829 ((equal (char-after) ?\ ) (forward-char 1))))))
6831 (defun org-current-level ()
6832 "Return the level of the current entry, or nil if before the first headline.
6833 The level is the number of stars at the beginning of the headline."
6837 (org-back-to-heading t)
6838 (funcall outline-level))
6841 (defun org-get-previous-line-level ()
6842 "Return the outline depth of the last headline before the current line.
6843 Returns 0 for the first headline in the buffer, and nil if before the
6845 (let ((current-level (org-current-level))
6846 (prev-level (when (> (line-number-at-pos) 1)
6848 (beginning-of-line 0)
6849 (org-current-level)))))
6850 (cond ((null current-level) nil) ; Before first headline
6851 ((null prev-level) 0) ; At first headline
6854 (defun org-reduced-level (l)
6855 "Compute the effective level of a heading.
6856 This takes into account the setting of `org-odd-levels-only'."
6857 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6859 (defun org-level-increment ()
6860 "Return the number of stars that will be added or removed at a
6861 time to headlines when structure editing, based on the value of
6862 `org-odd-levels-only'."
6863 (if org-odd-levels-only 2 1))
6865 (defun org-get-valid-level (level &optional change)
6866 "Rectify a level change under the influence of `org-odd-levels-only'
6867 LEVEL is a current level, CHANGE is by how much the level should be
6868 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6869 even level numbers will become the next higher odd number."
6870 (if org-odd-levels-only
6871 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6872 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6873 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6874 (max 1 (+ level (or change 0)))))
6876 (if (boundp 'define-obsolete-function-alias)
6877 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6878 (define-obsolete-function-alias 'org-get-legal-level
6879 'org-get-valid-level)
6880 (define-obsolete-function-alias 'org-get-legal-level
6881 'org-get-valid-level "23.1")))
6883 (defun org-promote ()
6884 "Promote the current heading higher up the tree.
6885 If the region is active in `transient-mark-mode', promote all headings
6887 (org-back-to-heading t)
6888 (let* ((level (save-match-data (funcall outline-level)))
6889 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6890 (diff (abs (- level (length up-head) -1))))
6891 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6892 (replace-match up-head nil t)
6893 ;; Fixup tag positioning
6894 (and org-auto-align-tags (org-set-tags nil t))
6895 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6896 (run-hooks 'org-after-promote-entry-hook)))
6898 (defun org-demote ()
6899 "Demote the current heading lower down the tree.
6900 If the region is active in `transient-mark-mode', demote all headings
6902 (org-back-to-heading t)
6903 (let* ((level (save-match-data (funcall outline-level)))
6904 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6905 (diff (abs (- level (length down-head) -1))))
6906 (replace-match down-head nil t)
6907 ;; Fixup tag positioning
6908 (and org-auto-align-tags (org-set-tags nil t))
6909 (if org-adapt-indentation (org-fixup-indentation diff))
6910 (run-hooks 'org-after-demote-entry-hook)))
6912 (defun org-cycle-level ()
6913 "Cycle the level of an empty headline through possible states.
6914 This goes first to child, then to parent, level, then up the hierarchy.
6915 After top level, it switches back to sibling level."
6917 (let ((org-adapt-indentation nil))
6918 (when (org-point-at-end-of-empty-headline)
6919 (setq this-command 'org-cycle-level) ; Only needed for caching
6920 (let ((cur-level (org-current-level))
6921 (prev-level (org-get-previous-line-level)))
6923 ;; If first headline in file, promote to top-level.
6925 (loop repeat (/ (- cur-level 1) (org-level-increment))
6926 do (org-do-promote)))
6927 ;; If same level as prev, demote one.
6928 ((= prev-level cur-level)
6930 ;; If parent is top-level, promote to top level if not already.
6932 (loop repeat (/ (- cur-level 1) (org-level-increment))
6933 do (org-do-promote)))
6934 ;; If top-level, return to prev-level.
6936 (loop repeat (/ (- prev-level 1) (org-level-increment))
6937 do (org-do-demote)))
6938 ;; If less than prev-level, promote one.
6939 ((< cur-level prev-level)
6941 ;; If deeper than prev-level, promote until higher than
6943 ((> cur-level prev-level)
6944 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6945 do (org-do-promote))))
6948 (defun org-map-tree (fun)
6949 "Call FUN for every heading underneath the current one."
6950 (org-back-to-heading)
6951 (let ((level (funcall outline-level)))
6955 (outline-next-heading)
6956 (> (funcall outline-level) level))
6960 (defun org-map-region (fun beg end)
6961 "Call FUN for every heading between BEG and END."
6962 (let ((org-ignore-region t))
6964 (setq end (copy-marker end))
6966 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6970 (outline-next-heading)
6975 (defun org-fixup-indentation (diff)
6976 "Change the indentation in the current entry by DIFF
6977 However, if any line in the current entry has no indentation, or if it
6978 would end up with no indentation after the change, nothing at all is done."
6980 (let ((end (save-excursion (outline-next-heading)
6982 (prohibit (if (> diff 0)
6984 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6986 (unless (save-excursion (end-of-line 1)
6987 (re-search-forward prohibit end t))
6988 (while (and (< (point) end)
6989 (re-search-forward "^[ \t]+" end t))
6990 (goto-char (match-end 0))
6991 (setq col (current-column))
6992 (if (< diff 0) (replace-match ""))
6993 (org-indent-to-column (+ diff col))))
6994 (move-marker end nil))))
6996 (defun org-convert-to-odd-levels ()
6997 "Convert an org-mode file with all levels allowed to one with odd levels.
6998 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7001 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7002 (let ((outline-regexp org-outline-regexp)
7003 (outline-level 'org-outline-level)
7004 (org-odd-levels-only nil) n)
7006 (goto-char (point-min))
7007 (while (re-search-forward "^\\*\\*+ " nil t)
7008 (setq n (- (length (match-string 0)) 2))
7009 (while (>= (setq n (1- n)) 0)
7011 (end-of-line 1))))))
7013 (defun org-convert-to-oddeven-levels ()
7014 "Convert an org-mode file with only odd levels to one with odd and even levels.
7015 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
7016 section with an even level, conversion would destroy the structure of the file. An error
7017 is signaled in this case."
7019 (goto-char (point-min))
7020 ;; First check if there are no even levels
7021 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7022 (org-show-context t)
7023 (error "Not all levels are odd in this file. Conversion not possible"))
7024 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7025 (let ((outline-regexp org-outline-regexp)
7026 (outline-level 'org-outline-level)
7027 (org-odd-levels-only nil) n)
7029 (goto-char (point-min))
7030 (while (re-search-forward "^\\*\\*+ " nil t)
7031 (setq n (/ (1- (length (match-string 0))) 2))
7032 (while (>= (setq n (1- n)) 0)
7034 (end-of-line 1))))))
7036 (defun org-tr-level (n)
7037 "Make N odd if required."
7038 (if org-odd-levels-only (1+ (/ n 2)) n))
7040 ;;; Vertical tree motion, cutting and pasting of subtrees
7042 (defun org-move-subtree-up (&optional arg)
7043 "Move the current subtree up past ARG headlines of the same level."
7045 (org-move-subtree-down (- (prefix-numeric-value arg))))
7047 (defun org-move-subtree-down (&optional arg)
7048 "Move the current subtree down past ARG headlines of the same level."
7050 (setq arg (prefix-numeric-value arg))
7051 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7052 'org-get-last-sibling))
7053 (ins-point (make-marker))
7055 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7057 (org-back-to-heading)
7060 (setq ne-beg (org-back-over-empty-lines))
7063 (save-excursion (outline-end-of-heading)
7064 (setq folded (org-invisible-p)))
7065 (outline-end-of-subtree))
7066 (outline-next-heading)
7067 (setq ne-end (org-back-over-empty-lines))
7070 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7071 ;; include less whitespace
7074 (forward-line (- ne-beg ne-end))
7075 (setq beg (point))))
7076 ;; Find insertion point, with error handling
7078 (or (and (funcall movfunc) (looking-at outline-regexp))
7079 (progn (goto-char beg0)
7080 (error "Cannot move past superior level or buffer limit")))
7081 (setq cnt (1- cnt)))
7083 ;; Moving forward - still need to move over subtree
7084 (progn (org-end-of-subtree t t)
7086 (org-back-over-empty-lines)
7087 (or (bolp) (newline)))))
7088 (setq ne-ins (org-back-over-empty-lines))
7089 (move-marker ins-point (point))
7090 (setq txt (buffer-substring beg end))
7091 (org-save-markers-in-region beg end)
7092 (delete-region beg end)
7093 (org-remove-empty-overlays-at beg)
7094 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7095 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7096 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7097 (let ((bbb (point)))
7098 (insert-before-markers txt)
7099 (org-reinstall-markers-in-region bbb)
7100 (move-marker ins-point bbb))
7101 (or (bolp) (insert "\n"))
7102 (setq ins-end (point))
7103 (goto-char ins-point)
7104 (org-skip-whitespace)
7105 (when (and (< arg 0)
7106 (org-first-sibling-p)
7108 ;; Move whitespace back to beginning
7111 (let ((kill-whole-line t))
7112 (kill-line (- ne-ins ne-beg)) (point)))
7113 (insert (make-string (- ne-ins ne-beg) ?\n)))
7114 (move-marker ins-point nil)
7119 (org-cycle-hide-drawers 'children))
7120 (org-clean-visibility-after-subtree-move)))
7122 (defvar org-subtree-clip ""
7123 "Clipboard for cut and paste of subtrees.
7124 This is actually only a copy of the kill, because we use the normal kill
7125 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7127 (defvar org-subtree-clip-folded nil
7128 "Was the last copied subtree folded?
7129 This is used to fold the tree back after pasting.")
7131 (defun org-cut-subtree (&optional n)
7132 "Cut the current subtree into the clipboard.
7133 With prefix arg N, cut this many sequential subtrees.
7134 This is a short-hand for marking the subtree and then cutting it."
7136 (org-copy-subtree n 'cut))
7138 (defun org-copy-subtree (&optional n cut force-store-markers)
7139 "Cut the current subtree into the clipboard.
7140 With prefix arg N, cut this many sequential subtrees.
7141 This is a short-hand for marking the subtree and then copying it.
7142 If CUT is non-nil, actually cut the subtree.
7143 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7144 of some markers in the region, even if CUT is non-nil. This is
7145 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7147 (let (beg end folded (beg0 (point)))
7149 (org-back-to-heading nil) ; take what looks like a subtree
7150 (org-back-to-heading t)) ; take what is really there
7151 (org-back-over-empty-lines)
7153 (skip-chars-forward " \t\r\n")
7155 (save-excursion (outline-end-of-heading)
7156 (setq folded (org-invisible-p)))
7158 (org-forward-same-level (1- n) t)
7160 (org-end-of-subtree t t))
7161 (org-back-over-empty-lines)
7165 (setq org-subtree-clip-folded folded)
7166 (when (or cut force-store-markers)
7167 (org-save-markers-in-region beg end))
7168 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7169 (setq org-subtree-clip (current-kill 0))
7170 (message "%s: Subtree(s) with %d characters"
7171 (if cut "Cut" "Copied")
7172 (length org-subtree-clip)))))
7174 (defun org-paste-subtree (&optional level tree for-yank)
7175 "Paste the clipboard as a subtree, with modification of headline level.
7176 The entire subtree is promoted or demoted in order to match a new headline
7179 If the cursor is at the beginning of a headline, the same level as
7180 that headline is used to paste the tree
7182 If not, the new level is derived from the *visible* headings
7183 before and after the insertion point, and taken to be the inferior headline
7184 level of the two. So if the previous visible heading is level 3 and the
7185 next is level 4 (or vice versa), level 4 will be used for insertion.
7186 This makes sure that the subtree remains an independent subtree and does
7187 not swallow low level entries.
7189 You can also force a different level, either by using a numeric prefix
7190 argument, or by inserting the heading marker by hand. For example, if the
7191 cursor is after \"*****\", then the tree will be shifted to level 5.
7193 If optional TREE is given, use this text instead of the kill ring.
7195 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7196 move back over whitespace before inserting, and move point to the end of
7197 the inserted text when done."
7199 (setq tree (or tree (and kill-ring (current-kill 0))))
7200 (unless (org-kill-is-subtree-p tree)
7202 (substitute-command-keys
7203 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7204 (let* ((visp (not (org-invisible-p)))
7206 (^re (concat "^\\(" outline-regexp "\\)"))
7207 (re (concat "\\(" outline-regexp "\\)"))
7208 (^re_ (concat "\\(\\*+\\)[ \t]*"))
7210 (old-level (if (string-match ^re txt)
7211 (- (match-end 0) (match-beginning 0) 1)
7213 (force-level (cond (level (prefix-numeric-value level))
7214 ((and (looking-at "[ \t]*$")
7216 ^re_ (buffer-substring
7217 (point-at-bol) (point))))
7218 (- (match-end 1) (match-beginning 1)))
7220 (looking-at org-outline-regexp))
7221 (- (match-end 0) (point) 1))
7223 (previous-level (save-excursion
7226 (outline-previous-visible-heading 1)
7228 (- (match-end 0) (match-beginning 0) 1)
7231 (next-level (save-excursion
7234 (or (looking-at outline-regexp)
7235 (outline-next-visible-heading 1))
7237 (- (match-end 0) (match-beginning 0) 1)
7240 (new-level (or force-level (max previous-level next-level)))
7241 (shift (if (or (= old-level -1)
7243 (= old-level new-level))
7245 (- new-level old-level)))
7246 (delta (if (> shift 0) -1 1))
7247 (func (if (> shift 0) 'org-demote 'org-promote))
7248 (org-odd-levels-only nil)
7250 ;; Remove the forced level indicator
7252 (delete-region (point-at-bol) (point)))
7254 (beginning-of-line 1)
7255 (unless for-yank (org-back-over-empty-lines))
7257 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7258 (insert-before-markers txt)
7259 (unless (string-match "\n\\'" txt) (insert "\n"))
7260 (setq newend (point))
7261 (org-reinstall-markers-in-region beg)
7264 (skip-chars-forward " \t\n\r")
7266 (if (and (org-invisible-p) visp)
7267 (save-excursion (outline-show-heading)))
7268 ;; Shift if necessary
7271 (narrow-to-region beg end)
7272 (while (not (= shift 0))
7273 (org-map-region func (point-min) (point-max))
7274 (setq shift (+ delta shift)))
7275 (goto-char (point-min))
7276 (setq newend (point-max))))
7277 (when (or (interactive-p) for-yank)
7278 (message "Clipboard pasted as level %d subtree" new-level))
7279 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7281 (eq org-subtree-clip (current-kill 0))
7282 org-subtree-clip-folded)
7283 ;; The tree was folded before it was killed/copied
7285 (and for-yank (goto-char newend))))
7287 (defun org-kill-is-subtree-p (&optional txt)
7288 "Check if the current kill is an outline subtree, or a set of trees.
7289 Returns nil if kill does not start with a headline, or if the first
7290 headline level is not the largest headline level in the tree.
7291 So this will actually accept several entries of equal levels as well,
7292 which is OK for `org-paste-subtree'.
7293 If optional TXT is given, check this string instead of the current kill."
7294 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7295 (start-level (and kill
7296 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
7297 org-outline-regexp "\\)")
7299 (- (match-end 2) (match-beginning 2) 1)))
7300 (re (concat "^" org-outline-regexp))
7301 (start (1+ (or (match-beginning 2) -1))))
7302 (if (not start-level)
7304 nil) ;; does not even start with a heading
7306 (while (setq start (string-match re kill (1+ start)))
7307 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7311 (defvar org-markers-to-move nil
7312 "Markers that should be moved with a cut-and-paste operation.
7313 Those markers are stored together with their positions relative to
7314 the start of the region.")
7316 (defun org-save-markers-in-region (beg end)
7317 "Check markers in region.
7318 If these markers are between BEG and END, record their position relative
7319 to BEG, so that after moving the block of text, we can put the markers back
7321 This function gets called just before an entry or tree gets cut from the
7322 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7323 called immediately, to move the markers with the entries."
7324 (setq org-markers-to-move nil)
7325 (when (featurep 'org-clock)
7326 (org-clock-save-markers-for-cut-and-paste beg end))
7327 (when (featurep 'org-agenda)
7328 (org-agenda-save-markers-for-cut-and-paste beg end)))
7330 (defun org-check-and-save-marker (marker beg end)
7331 "Check if MARKER is between BEG and END.
7332 If yes, remember the marker and the distance to BEG."
7333 (when (and (marker-buffer marker)
7334 (equal (marker-buffer marker) (current-buffer)))
7335 (if (and (>= marker beg) (< marker end))
7336 (push (cons marker (- marker beg)) org-markers-to-move))))
7338 (defun org-reinstall-markers-in-region (beg)
7339 "Move all remembered markers to their position relative to BEG."
7341 (move-marker (car x) (+ beg (cdr x))))
7342 org-markers-to-move)
7343 (setq org-markers-to-move nil))
7345 (defun org-narrow-to-subtree ()
7346 "Narrow buffer to the current subtree."
7351 (progn (org-back-to-heading t) (point))
7352 (progn (org-end-of-subtree t t)
7353 (if (org-on-heading-p) (backward-char 1))
7357 (defvar org-property-drawer-re))
7359 (defun org-clone-subtree-with-time-shift (n &optional shift)
7360 "Clone the task (subtree) at point N times.
7361 The clones will be inserted as siblings.
7363 In interactive use, the user will be prompted for the number of
7364 clones to be produced, and for a time SHIFT, which may be a
7365 repeater as used in time stamps, for example `+3d'.
7367 When a valid repeater is given and the entry contains any time
7368 stamps, the clones will become a sequence in time, with time
7369 stamps in the subtree shifted for each clone produced. If SHIFT
7370 is nil or the empty string, time stamps will be left alone. The
7371 ID property of the original subtree is removed.
7373 If the original subtree did contain time stamps with a repeater,
7374 the following will happen:
7375 - the repeater will be removed in each clone
7376 - an additional clone will be produced, with the current, unshifted
7377 date(s) in the entry.
7378 - the original entry will be placed *after* all the clones, with
7380 - the start days in the repeater in the original entry will be shifted
7381 to past the last clone.
7382 I this way you can spell out a number of instances of a repeating task,
7383 and still retain the repeater to cover future instances of the task."
7384 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7385 (let (beg end template task idprop
7386 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7387 (if (not (and (integerp n) (> n 0)))
7388 (error "Invalid number of replications %s" n))
7389 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7390 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7392 (error "Invalid shift specification %s" shift))
7394 (setq shift-n (string-to-number (match-string 1 shift))
7395 shift-what (cdr (assoc (match-string 2 shift)
7396 '(("d" . day) ("w" . week)
7397 ("m" . month) ("y" . year))))))
7398 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7399 (setq nmin 1 nmax n)
7400 (org-back-to-heading t)
7402 (setq idprop (org-entry-get nil "ID"))
7403 (org-end-of-subtree t t)
7404 (or (bolp) (insert "\n"))
7406 (setq template (buffer-substring beg end))
7408 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7409 (delete-region beg end)
7411 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7413 (loop for n from nmin to nmax do
7418 (goto-char (point-min))
7419 (and idprop (if org-clone-delete-id
7420 (org-entry-delete nil "ID")
7421 (org-id-get-create t)))
7422 (while (re-search-forward org-property-drawer-re nil t)
7423 (org-remove-empty-drawer-at "PROPERTIES" (point)))
7424 (goto-char (point-min))
7426 (while (re-search-forward org-ts-regexp-both nil t)
7427 (org-timestamp-change (* n shift-n) shift-what))
7428 (unless (= n n-no-remove)
7429 (goto-char (point-min))
7430 (while (re-search-forward org-ts-regexp nil t)
7432 (goto-char (match-beginning 0))
7433 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7434 (delete-region (match-beginning 1) (match-end 1)))))))
7435 (setq task (buffer-string)))
7441 (defun org-sort (with-case)
7442 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7443 Optional argument WITH-CASE means sort case-sensitively.
7444 With a double prefix argument, also remove duplicate entries."
7446 (if (org-at-table-p)
7447 (org-call-with-arg 'org-table-sort-lines with-case)
7448 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7450 (defun org-sort-remove-invisible (s)
7451 (remove-text-properties 0 (length s) org-rm-props s)
7452 (while (string-match org-bracket-link-regexp s)
7453 (setq s (replace-match (if (match-end 2)
7455 (match-string 1 s)) t t s)))
7458 (defvar org-priority-regexp) ; defined later in the file
7460 (defvar org-after-sorting-entries-or-items-hook nil
7461 "Hook that is run after a bunch of entries or items have been sorted.
7462 When children are sorted, the cursor is in the parent line when this
7463 hook gets called. When a region or a plain list is sorted, the cursor
7464 will be in the first entry of the sorted region/list.")
7466 (defun org-sort-entries-or-items
7467 (&optional with-case sorting-type getkey-func compare-func property)
7468 "Sort entries on a certain level of an outline tree, or plain list items.
7469 If there is an active region, the entries in the region are sorted.
7470 Else, if the cursor is before the first entry, sort the top-level items.
7471 Else, the children of the entry at point are sorted.
7472 If the cursor is at the first item in a plain list, the list items will be
7475 Sorting can be alphabetically, numerically, by date/time as given by
7476 a time stamp, by a property or by priority.
7478 The command prompts for the sorting type unless it has been given to the
7479 function through the SORTING-TYPE argument, which needs to be a character,
7480 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7481 precise meaning of each character:
7483 n Numerically, by converting the beginning of the entry/item to a number.
7484 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7485 t By date/time, either the first active time stamp in the entry, or, if
7486 none exist, by the first inactive one.
7487 In items, only the first line will be checked.
7488 s By the scheduled date/time.
7489 d By deadline date/time.
7490 c By creation time, which is assumed to be the first inactive time stamp
7491 at the beginning of a line.
7492 p By priority according to the cookie.
7493 r By the value of a property.
7495 Capital letters will reverse the sort order.
7497 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7498 called with point at the beginning of the record. It must return either
7499 a string or a number that should serve as the sorting key for that record.
7501 Comparing entries ignores case by default. However, with an optional argument
7502 WITH-CASE, the sorting considers case as well."
7504 (let ((case-func (if with-case 'identity 'downcase))
7505 start beg end stars re re2
7506 txt what tmp plain-list-p)
7507 ;; Find beginning and end of region to sort
7509 ((org-region-active-p)
7510 ;; we will sort the region
7511 (setq end (region-end)
7513 (goto-char (region-beginning))
7514 (if (not (org-on-heading-p)) (outline-next-heading))
7515 (setq start (point)))
7517 ;; we will sort this plain list
7518 (org-beginning-of-item-list) (setq start (point))
7519 (org-end-of-item-list)
7520 (or (bolp) (insert "\n"))
7523 (setq plain-list-p t
7525 ((or (org-on-heading-p)
7526 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7527 ;; we will sort the children of the current headline
7528 (org-back-to-heading)
7530 end (progn (org-end-of-subtree t t)
7531 (or (bolp) (insert "\n"))
7532 (org-back-over-empty-lines)
7537 (outline-next-heading))
7539 ;; we will sort the top-level entries in this file
7540 (goto-char (point-min))
7541 (or (org-on-heading-p) (outline-next-heading))
7542 (setq start (point))
7543 (goto-char (point-max))
7544 (beginning-of-line 1)
7545 (when (looking-at ".*?\\S-")
7546 ;; File ends in a non-white line
7549 (setq end (point-max))
7550 (setq what "top-level")
7555 (if (>= beg end) (error "Nothing to sort"))
7557 (unless plain-list-p
7558 (looking-at "\\(\\*+\\)")
7559 (setq stars (match-string 1)
7560 re (concat "^" (regexp-quote stars) " +")
7561 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7562 txt (buffer-substring beg end))
7563 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7564 (if (and (not (equal stars "*")) (string-match re2 txt))
7565 (error "Region to sort contains a level above the first entry")))
7567 (unless sorting-type
7570 "Sort %s: [a]lpha [n]umeric [t]ime
[f]unc A/N/T/F means reversed:"
7571 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7572 [t]ime [s]cheduled [d]eadline [c]reated
7573 A/N/T/S/D/C/P/O/F means reversed:")
7575 (setq sorting-type (read-char-exclusive))
7577 (and (= (downcase sorting-type) ?f)
7579 (org-icompleting-read "Sort using function: "
7580 obarray 'fboundp t nil nil))
7581 (setq getkey-func (intern getkey-func)))
7583 (and (= (downcase sorting-type) ?r)
7585 (org-icompleting-read "Property: "
7586 (mapcar 'list (org-buffer-property-keys t))
7589 (message "Sorting entries...")
7592 (narrow-to-region start end)
7594 (let ((dcst (downcase sorting-type))
7595 (case-fold-search nil)
7596 (now (current-time)))
7598 (/= dcst sorting-type)
7599 ;; This function moves to the beginning character of the "record" to
7603 (if (org-at-item-p) t (goto-char (point-max))))
7605 (if (re-search-forward re nil t)
7606 (goto-char (match-beginning 0))
7607 (goto-char (point-max)))))
7608 ;; This function moves to the last character of the "record" being
7615 (outline-forward-same-level 1)
7617 (goto-char (point-max)))))))
7619 ;; This function returns the value that gets sorted against.
7622 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7625 (string-to-number (buffer-substring (match-end 0)
7628 (buffer-substring (match-end 0) (point-at-eol)))
7630 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7631 (re-search-forward org-ts-regexp-both
7633 (org-time-string-to-seconds (match-string 0))
7634 (org-float-time now)))
7638 (setq tmp (funcall getkey-func))
7639 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7641 (error "Invalid key function `%s'" getkey-func)))
7642 (t (error "Invalid sorting type `%c'" sorting-type)))))
7646 (if (looking-at org-complex-heading-regexp)
7647 (string-to-number (match-string 4))
7650 (if (looking-at org-complex-heading-regexp)
7651 (funcall case-func (match-string 4))
7654 (let ((end (save-excursion (outline-next-heading) (point))))
7655 (if (or (re-search-forward org-ts-regexp end t)
7656 (re-search-forward org-ts-regexp-both end t))
7657 (org-time-string-to-seconds (match-string 0))
7658 (org-float-time now))))
7660 (let ((end (save-excursion (outline-next-heading) (point))))
7661 (if (re-search-forward
7662 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7664 (org-time-string-to-seconds (match-string 0))
7665 (org-float-time now))))
7667 (let ((end (save-excursion (outline-next-heading) (point))))
7668 (if (re-search-forward org-scheduled-time-regexp end t)
7669 (org-time-string-to-seconds (match-string 1))
7670 (org-float-time now))))
7672 (let ((end (save-excursion (outline-next-heading) (point))))
7673 (if (re-search-forward org-deadline-time-regexp end t)
7674 (org-time-string-to-seconds (match-string 1))
7675 (org-float-time now))))
7677 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7678 (string-to-char (match-string 2))
7679 org-default-priority))
7681 (or (org-entry-get nil property) ""))
7683 (if (looking-at org-complex-heading-regexp)
7684 (- 9999 (length (member (match-string 2)
7685 org-todo-keywords-1)))))
7689 (setq tmp (funcall getkey-func))
7690 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7692 (error "Invalid key function `%s'" getkey-func)))
7693 (t (error "Invalid sorting type `%c'" sorting-type)))))
7696 ((= dcst ?a) 'string<)
7697 ((= dcst ?f) compare-func)
7698 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7700 (run-hooks 'org-after-sorting-entries-or-items-hook)
7701 (message "Sorting entries...done")))
7703 (defun org-do-sort (table what &optional with-case sorting-type)
7704 "Sort TABLE of WHAT according to SORTING-TYPE.
7705 The user will be prompted for the SORTING-TYPE if the call to this
7706 function does not specify it. WHAT is only for the prompt, to indicate
7707 what is being sorted. The sorting key will be extracted from
7708 the car of the elements of the table.
7709 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7710 (unless sorting-type
7712 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A
/N
/T means reversed
:"
7714 (setq sorting-type (read-char-exclusive)))
7715 (let ((dcst (downcase sorting-type))
7716 extractfun comparefun)
7717 ;; Define the appropriate functions
7720 (setq extractfun 'string-to-number
7721 comparefun (if (= dcst sorting-type) '< '>)))
7723 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7724 (lambda(x) (downcase (org-sort-remove-invisible x))))
7725 comparefun (if (= dcst sorting-type)
7727 (lambda (a b) (and (not (string< a b))
7728 (not (string= a b)))))))
7732 (if (or (string-match org-ts-regexp x)
7733 (string-match org-ts-regexp-both x))
7735 (org-time-string-to-time (match-string 0 x)))
7737 comparefun (if (= dcst sorting-type) '< '>)))
7738 (t (error "Invalid sorting type
`%c
'" sorting-type)))
7740 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7742 (lambda (a b) (funcall comparefun (car a) (car b))))))
7745 ;;; The orgstruct minor mode
7747 ;; Define a minor mode which can be used in other modes in order to
7748 ;; integrate the org-mode structure editing commands.
7750 ;; This is really a hack, because the org-mode structure commands use
7751 ;; keys which normally belong to the major mode. Here is how it
7752 ;; works: The minor mode defines all the keys necessary to operate the
7753 ;; structure commands, but wraps the commands into a function which
7754 ;; tests if the cursor is currently at a headline or a plain list
7755 ;; item. If that is the case, the structure command is used,
7756 ;; temporarily setting many Org-mode variables like regular
7757 ;; expressions for filling etc. However, when any of those keys is
7758 ;; used at a different location, function uses `key-binding' to look
7759 ;; up if the key has an associated command in another currently active
7760 ;; keymap (minor modes, major mode, global), and executes that
7761 ;; command. There might be problems if any of the keys is otherwise
7762 ;; used as a prefix key.
7764 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7765 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7766 ;; addresses this by checking explicitly for both bindings.
7768 (defvar orgstruct-mode-map (make-sparse-keymap)
7769 "Keymap for the minor
`orgstruct-mode
'.
")
7771 (defvar org-local-vars nil
7772 "List of local variables
, for use by
`orgstruct-mode
'")
7775 (define-minor-mode orgstruct-mode
7776 "Toggle the minor mode
`orgstruct-mode
'.
7777 This mode is for using Org-mode structure commands in other
7778 modes. The following keys behave as if Org-mode were active
, if
7779 the cursor is on a headline
, or on a plain list item
(both as
7780 defined by Org-mode
).
7782 M-up Move entry
/item up
7783 M-down Move entry
/item down
7786 M-S-up Move entry
/item up
7787 M-S-down Move entry
/item down
7788 M-S-left Promote subtree
7789 M-S-right Demote subtree
7790 M-q Fill paragraph and items like in Org-mode
7792 C-c - Cycle list bullet
7793 TAB Cycle item visibility
7794 M-RET Insert new heading
/item
7795 S-M-RET Insert new TODO heading
/ Checkbox item
7796 C-c C-c Set tags
/ toggle checkbox
"
7797 nil " OrgStruct
" nil
7798 (org-load-modules-maybe)
7799 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7802 (defun turn-on-orgstruct ()
7803 "Unconditionally turn on
`orgstruct-mode
'.
"
7806 (defun orgstruct++-mode (&optional arg)
7807 "Toggle
`orgstruct-mode
', the enhanced version of it.
7808 In addition to setting orgstruct-mode
, this also exports all indentation
7809 and autofilling variables from org-mode into the buffer. It will also
7810 recognize item context in multiline items.
7811 Note that turning off orgstruct-mode will
*not
* remove the
7812 indentation
/paragraph settings. This can only be done by refreshing the
7813 major mode
, for example with
\\[normal-mode
].
"
7815 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7823 "^
\\(paragraph-\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7824 (symbol-name (car x)))
7825 (setq var (car x) val (nth 1 x))
7826 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7828 (org-set-local 'orgstruct-is-++ t))))
7830 (defvar orgstruct-is-++ nil
7831 "Is orgstruct-mode in
++ version in the current-buffer?
")
7832 (make-variable-buffer-local 'orgstruct-is-++)
7835 (defun turn-on-orgstruct++ ()
7836 "Unconditionally turn on
`orgstruct
++-mode
'.
"
7837 (orgstruct++-mode 1))
7839 (defun orgstruct-error ()
7840 "Error when there is no default binding for a structure key.
"
7842 (error "This key has no function outside structure elements
"))
7844 (defun orgstruct-setup ()
7845 "Setup orgstruct keymaps.
"
7849 '([(meta up)] org-metaup)
7850 '([(meta down)] org-metadown)
7851 '([(meta left)] org-metaleft)
7852 '([(meta right)] org-metaright)
7853 '([(meta shift up)] org-shiftmetaup)
7854 '([(meta shift down)] org-shiftmetadown)
7855 '([(meta shift left)] org-shiftmetaleft)
7856 '([(meta shift right)] org-shiftmetaright)
7857 '([?\e (up)] org-metaup)
7858 '([?\e (down)] org-metadown)
7859 '([?\e (left)] org-metaleft)
7860 '([?\e (right)] org-metaright)
7861 '([?\e (shift up)] org-shiftmetaup)
7862 '([?\e (shift down)] org-shiftmetadown)
7863 '([?\e (shift left)] org-shiftmetaleft)
7864 '([?\e (shift right)] org-shiftmetaright)
7865 '([(shift up)] org-shiftup)
7866 '([(shift down)] org-shiftdown)
7867 '([(shift left)] org-shiftleft)
7868 '([(shift right)] org-shiftright)
7869 '("\C-c\C-c
" org-ctrl-c-ctrl-c)
7870 '("\M-q
" fill-paragraph)
7872 '("\C-c-
" org-cycle-list-bullet)))
7874 (while (setq elt (pop bindings))
7875 (setq nfunc (1+ nfunc))
7876 (setq key (org-key (car elt))
7878 cmd (orgstruct-make-binding fun nfunc key))
7879 (org-defkey orgstruct-mode-map key cmd))
7881 ;; Special treatment needed for TAB and RET
7882 (org-defkey orgstruct-mode-map [(tab)]
7883 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i
"))
7884 (org-defkey orgstruct-mode-map "\C-i
"
7885 (orgstruct-make-binding 'org-cycle 103 "\C-i
" [(tab)]))
7887 (org-defkey orgstruct-mode-map "\M-\C-m
"
7888 (orgstruct-make-binding 'org-insert-heading 105
7889 "\M-\C-m
" [(meta return)]))
7890 (org-defkey orgstruct-mode-map [(meta return)]
7891 (orgstruct-make-binding 'org-insert-heading 106
7892 [(meta return)] "\M-\C-m
"))
7894 (org-defkey orgstruct-mode-map [(shift meta return)]
7895 (orgstruct-make-binding 'org-insert-todo-heading 107
7896 [(meta return)] "\M-\C-m
"))
7898 (org-defkey orgstruct-mode-map "\e\C-m
"
7899 (orgstruct-make-binding 'org-insert-heading 108
7900 "\e\C-m
" [?\e (return)]))
7901 (org-defkey orgstruct-mode-map [?\e (return)]
7902 (orgstruct-make-binding 'org-insert-heading 109
7903 [?\e (return)] "\e\C-m
"))
7904 (org-defkey orgstruct-mode-map [?\e (shift return)]
7905 (orgstruct-make-binding 'org-insert-todo-heading 110
7906 [?\e (return)] "\e\C-m
"))
7908 (unless org-local-vars
7909 (setq org-local-vars (org-get-local-variables)))
7913 (defun orgstruct-make-binding (fun n &rest keys)
7914 "Create a function for binding in the structure minor mode.
7915 FUN is the command to call inside a table. N is used to create a unique
7916 command name. KEYS are keys that should be checked in for a command
7917 to execute outside of tables.
"
7920 (intern (concat "orgstruct-hijacker-command-
" (int-to-string n)))
7922 (concat "In Structure
, run
`" (symbol-name fun) "'.
\n"
7923 "Outside of structure
, run the binding of
`"
7924 (mapconcat (lambda (x) (format "%s
" x)) keys "' or
`")
7928 `(org-context-p 'headline 'item
7929 (and orgstruct-is-++
7930 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7932 (list 'org-run-like-in-org-mode (list 'quote fun))
7933 (list 'let '(orgstruct-mode)
7934 (list 'call-interactively
7937 (list 'key-binding k))
7939 '('orgstruct-error))))))))
7941 (defun org-context-p (&rest contexts)
7942 "Check if local context is any of CONTEXTS.
7943 Possible values in the list of contexts are
`table
', `headline
', and
`item
'.
"
7944 (let ((pos (point)))
7945 (goto-char (point-at-bol))
7946 (prog1 (or (and (memq 'table contexts)
7947 (looking-at "[ \t]*|
"))
7948 (and (memq 'headline contexts)
7949 ;;????????? (looking-at "\\*+"))
7950 (looking-at outline-regexp))
7951 (and (memq 'item contexts)
7952 (looking-at "[ \t]*\\([-
+*] \\|
[0-
9]+[.
)] \\)"))
7953 (and (memq 'item-body contexts)
7957 (defun org-get-local-variables ()
7958 "Return a list of all local variables in an org-mode buffer.
"
7960 (with-current-buffer (get-buffer-create "*Org tmp
*")
7963 (setq varlist (buffer-local-variables)))
7964 (kill-buffer "*Org tmp
*")
7971 (list (car x) (list 'quote (cdr x)))))
7973 "^
\\(org-\\|orgtbl-
\\|outline-
\\|comment-
\\|paragraph-
\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7974 (symbol-name (car x)))
7979 (defun org-run-like-in-org-mode (cmd)
7980 "Run a command
, pretending that the current buffer is in Org-mode.
7981 This will temporarily bind local variables that are typically bound in
7982 Org-mode to the values they have in Org-mode
, and then interactively
7984 (org-load-modules-maybe)
7985 (unless org-local-vars
7986 (setq org-local-vars (org-get-local-variables)))
7987 (eval (list 'let org-local-vars
7988 (list 'call-interactively (list 'quote cmd)))))
7992 (defun org-get-category (&optional pos)
7993 "Get the category applying to position POS.
"
7994 (get-text-property (or pos (point)) 'org-category))
7996 (defun org-refresh-category-properties ()
7997 "Refresh category text properties in the buffer.
"
7998 (let ((def-cat (cond
7999 ((null org-category)
8000 (if buffer-file-name
8001 (file-name-sans-extension
8002 (file-name-nondirectory buffer-file-name))
8004 ((symbolp org-category) (symbol-name org-category))
8006 beg end cat pos optionp)
8011 (goto-char (point-min))
8012 (put-text-property (point) (point-max) 'org-category def-cat)
8013 (while (re-search-forward
8014 "^
\\(#\\+CATEGORY
:\\|
[ \t]*:CATEGORY
:\\)\\(.
*\\)" nil t)
8015 (setq pos (match-end 0)
8016 optionp (equal (char-after (match-beginning 0)) ?#)
8017 cat (org-trim (match-string 2)))
8019 (setq beg (point-at-bol) end (point-max))
8020 (org-back-to-heading t)
8021 (setq beg (point) end (org-end-of-subtree t t)))
8022 (put-text-property beg end 'org-category cat)
8023 (goto-char pos)))))))
8028 ;;; Link abbreviations
8030 (defun org-link-expand-abbrev (link)
8031 "Apply replacements as defined in
`org-link-abbrev-alist.
"
8032 (if (string-match "^
\\([a-zA-Z
][-_a-zA-Z0-9
]*\\)\\(::?
\\(.
*\\)\\)?$
" link)
8033 (let* ((key (match-string 1 link))
8034 (as (or (assoc key org-link-abbrev-alist-local)
8035 (assoc key org-link-abbrev-alist)))
8036 (tag (and (match-end 2) (match-string 3 link)))
8042 ((symbolp rpl) (funcall rpl tag))
8043 ((string-match "%s
" rpl) (replace-match (or tag "") t t rpl))
8044 ((string-match "%h
" rpl)
8045 (replace-match (url-hexify-string (or tag "")) t t rpl))
8046 (t (concat rpl tag)))))
8049 ;;; Storing and inserting links
8051 (defvar org-insert-link-history nil
8052 "Minibuffer history for links inserted with
`org-insert-link
'.
")
8054 (defvar org-stored-links nil
8055 "Contains the links stored with
`org-store-link
'.
")
8057 (defvar org-store-link-plist nil
8058 "Plist with info about the most recently link created with
`org-store-link
'.
")
8060 (defvar org-link-protocols nil
8061 "Link protocols added to Org-mode using
`org-add-link-type
'.
")
8063 (defvar org-store-link-functions nil
8064 "List of functions that are called to create and store a link.
8065 Each function will be called in turn until one returns a non-nil
8066 value. Each function should check if it is responsible for creating
8067 this link
(for example by looking at the major mode
).
8068 If not
, it must exit and return nil.
8069 If yes
, it should return a non-nil value after a calling
8070 `org-store-link-props
' with a list of properties and values.
8071 Special properties are
:
8073 :type The link prefix. like
\"http
\". This must be given.
8074 :link The link
, like
\"http
://www.astro.uva.nl
/~dominik
\".
8075 This is obligatory as well.
8076 :description Optional default description for the second pair
8077 of brackets in an Org-mode link. The user can still change
8078 this when inserting this link into an Org-mode buffer.
8080 In addition to these
, any additional properties can be specified
8081 and then used in remember templates.
")
8083 (defun org-add-link-type (type &optional follow export)
8084 "Add TYPE to the list of
`org-link-types
'.
8085 Re-compute all regular expressions depending on
`org-link-types
'
8087 FOLLOW and EXPORT are two functions.
8089 FOLLOW should take the link path as the single argument and do whatever
8090 is necessary to follow the link
, for example find a file or display
8093 EXPORT should format the link path for export to one of the export formats.
8094 It should be a function accepting three arguments
:
8096 path the path of the link
, the text after the prefix
(like \"http
:\")
8097 desc the description of the link
, if any
, nil if there was no description
8098 format the export format
, a symbol like
`html
' or
`latex
'.
8100 The function may use the FORMAT information to return different values
8101 depending on the format. The return value will be put literally into
8103 Org-mode has a built-in default for exporting links. If you are happy with
8104 this default
, there is no need to define an export function for the link
8105 type. For a simple example of an export function
, see
`org-bbdb.el
'.
"
8106 (add-to-list 'org-link-types type t)
8107 (org-make-link-regexps)
8108 (if (assoc type org-link-protocols)
8109 (setcdr (assoc type org-link-protocols) (list follow export))
8110 (push (list type follow export) org-link-protocols)))
8112 (defvar org-agenda-buffer-name)
8115 (defun org-store-link (arg)
8116 "\\<org-mode-map
>Store an org-link to the current location.
8117 This link is added to
`org-stored-links
' and can later be inserted
8118 into an org-buffer with
\\[org-insert-link
].
8120 For some link types
, a prefix arg is interpreted
:
8121 For links to usenet articles
, arg negates
`org-gnus-prefer-web-links
'.
8122 For file links
, arg negates
`org-context-in-file-links
'.
"
8124 (org-load-modules-maybe)
8125 (setq org-store-link-plist nil) ; reset
8126 (let ((outline-regexp (org-get-limited-outline-regexp))
8127 link cpltxt desc description search txt custom-id)
8130 ((run-hook-with-args-until-success 'org-store-link-functions)
8131 (setq link (plist-get org-store-link-plist :link)
8132 desc (or (plist-get org-store-link-plist :description) link)))
8134 ((equal (buffer-name) "*Org Edit Src Example
*")
8136 (while (or (not label)
8140 (goto-char (point-min))
8142 (regexp-quote (format org-coderef-label-format label))
8144 (when label (message "Label exists already
") (sit-for 2))
8145 (setq label (read-string "Code line label
: " label)))
8147 (setq link (format org-coderef-label-format label))
8148 (setq gc (- 79 (length link)))
8149 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8151 (setq link (concat "(" label ")") desc nil)))
8153 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8154 ;; We are in the agenda, link to referenced location
8155 (let ((m (or (get-text-property (point) 'org-hd-marker)
8156 (get-text-property (point) 'org-marker))))
8158 (org-with-point-at m
8160 (call-interactively 'org-store-link)
8161 (org-store-link nil))))))
8163 ((eq major-mode 'calendar-mode)
8164 (let ((cd (calendar-cursor-to-date)))
8167 (car org-time-stamp-formats)
8169 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8171 (org-store-link-props :type "calendar
" :date cd)))
8173 ((eq major-mode 'w3-mode)
8174 (setq cpltxt (if (and (buffer-name)
8175 (not (string-match "Untitled
" (buffer-name))))
8178 link (org-make-link (url-view-url t)))
8179 (org-store-link-props :type "w3
" :url (url-view-url t)))
8181 ((eq major-mode 'w3m-mode)
8182 (setq cpltxt (or w3m-current-title w3m-current-url)
8183 link (org-make-link w3m-current-url))
8184 (org-store-link-props :type "w3m
" :url (url-view-url t)))
8186 ((setq search (run-hook-with-args-until-success
8187 'org-create-file-search-functions))
8188 (setq link (concat "file
:" (abbreviate-file-name buffer-file-name)
8190 (setq cpltxt (or description link)))
8192 ((eq major-mode 'image-mode)
8193 (setq cpltxt (concat "file
:"
8194 (abbreviate-file-name buffer-file-name))
8195 link (org-make-link cpltxt))
8196 (org-store-link-props :type "image
" :file buffer-file-name))
8198 ((eq major-mode 'dired-mode)
8199 ;; link to the file in the current line
8200 (let ((file (dired-get-filename nil t)))
8202 (abbreviate-file-name
8203 (expand-file-name (dired-get-filename nil t)))
8204 ;; otherwise, no file so use current directory.
8206 (setq cpltxt (concat "file
:" file)
8207 link (org-make-link cpltxt))))
8209 ((and buffer-file-name (org-mode-p))
8210 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID
")))
8212 ((org-in-regexp "<<\\(.
*?
\\)>>")
8215 (abbreviate-file-name buffer-file-name)
8216 "::" (match-string 1))
8217 link (org-make-link cpltxt)))
8218 ((and (featurep 'org-id)
8219 (or (eq org-link-to-org-use-id t)
8220 (and (eq org-link-to-org-use-id 'create-if-interactive)
8222 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
8225 (and org-link-to-org-use-id
8227 (org-entry-get nil "ID
")
8229 ;; We can make a link using the ID.
8230 (setq link (condition-case nil
8231 (prog1 (org-id-store-link)
8232 (setq desc (plist-get org-store-link-plist
8235 ;; probably before first headline, link to file only
8237 (abbreviate-file-name buffer-file-name))))))
8239 ;; Just link to current headline
8240 (setq cpltxt (concat "file
:"
8241 (abbreviate-file-name buffer-file-name)))
8242 ;; Add a context search string
8243 (when (org-xor org-context-in-file-links arg)
8245 ((org-on-heading-p) nil)
8246 ((org-region-active-p)
8247 (buffer-substring (region-beginning) (region-end)))
8249 (when (or (null txt) (string-match "\\S-
" txt))
8253 (org-make-org-heading-search-string txt)
8255 desc (or (nth 4 (ignore-errors
8256 (org-heading-components))) "NONE
"))))
8257 (if (string-match "::\\'" cpltxt)
8258 (setq cpltxt (substring cpltxt 0 -2)))
8259 (setq link (org-make-link cpltxt)))))
8261 ((buffer-file-name (buffer-base-buffer))
8262 ;; Just link to this file here.
8263 (setq cpltxt (concat "file
:"
8264 (abbreviate-file-name
8265 (buffer-file-name (buffer-base-buffer)))))
8266 ;; Add a context string
8267 (when (org-xor org-context-in-file-links arg)
8268 (setq txt (if (org-region-active-p)
8269 (buffer-substring (region-beginning) (region-end))
8270 (buffer-substring (point-at-bol) (point-at-eol))))
8271 ;; Only use search option if there is some text.
8272 (when (string-match "\\S-
" txt)
8274 (concat cpltxt "::" (org-make-org-heading-search-string txt))
8276 (setq link (org-make-link cpltxt)))
8279 (error "Cannot link to a buffer which is not visiting a file
"))
8281 (t (setq link nil)))
8283 (if (consp link) (setq cpltxt (car link) link (cdr link)))
8284 (setq link (or link cpltxt)
8285 desc (or desc cpltxt))
8286 (if (equal desc "NONE
") (setq desc nil))
8288 (if (and (or (interactive-p) executing-kbd-macro) link)
8290 (setq org-stored-links
8291 (cons (list link desc) org-stored-links))
8292 (message "Stored
: %s
" (or desc link))
8294 (setq link (concat "file
:" (abbreviate-file-name (buffer-file-name))
8296 (setq org-stored-links
8297 (cons (list link desc) org-stored-links))))
8298 (and link (org-make-link-string link desc)))))
8300 (defun org-store-link-props (&rest plist)
8301 "Store link properties
, extract names and addresses.
"
8303 (when (setq x (plist-get plist :from))
8304 (setq adr (mail-extract-address-components x))
8305 (setq plist (plist-put plist :fromname (car adr)))
8306 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8307 (when (setq x (plist-get plist :to))
8308 (setq adr (mail-extract-address-components x))
8309 (setq plist (plist-put plist :toname (car adr)))
8310 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8311 (let ((from (plist-get plist :from))
8312 (to (plist-get plist :to)))
8313 (when (and from to org-from-is-user-regexp)
8315 (plist-put plist :fromto
8316 (if (string-match org-from-is-user-regexp from)
8318 (concat "from %f
"))))))
8319 (setq org-store-link-plist plist))
8321 (defun org-add-link-props (&rest plist)
8322 "Add these properties to the link property list.
"
8325 (setq key (pop plist) value (pop plist))
8326 (setq org-store-link-plist
8327 (plist-put org-store-link-plist key value)))))
8329 (defun org-email-link-description (&optional fmt)
8330 "Return the description part of an email link.
8331 This takes information from
`org-store-link-plist
' and formats it
8332 according to FMT
(default from
`org-email-link-description-format
').
"
8333 (setq fmt (or fmt org-email-link-description-format))
8334 (let* ((p org-store-link-plist)
8335 (to (plist-get p :toaddress))
8336 (from (plist-get p :fromaddress))
8339 (cons "%c
" (plist-get p :fromto))
8340 (cons "%F
" (plist-get p :from))
8341 (cons "%f
" (or (plist-get p :fromname) (plist-get p :fromaddress) "?
"))
8342 (cons "%T
" (plist-get p :to))
8343 (cons "%t
" (or (plist-get p :toname) (plist-get p :toaddress) "?
"))
8344 (cons "%s
" (plist-get p :subject))
8345 (cons "%m
" (plist-get p :message-id)))))
8346 (when (string-match "%c
" fmt)
8347 ;; Check if the user wrote this message
8348 (if (and org-from-is-user-regexp from to
8349 (save-match-data (string-match org-from-is-user-regexp from)))
8350 (setq fmt (replace-match "to %t
" t t fmt))
8351 (setq fmt (replace-match "from %f
" t t fmt))))
8352 (org-replace-escapes fmt table)))
8354 (defun org-make-org-heading-search-string (&optional string heading)
8355 "Make search string for STRING or current headline.
"
8357 (let ((s (or string (org-get-heading))))
8358 (unless (and string (not heading))
8359 ;; We are using a headline, clean up garbage in there.
8360 (if (string-match org-todo-regexp s)
8361 (setq s (replace-match "" t t s)))
8362 (if (string-match (org-re ":[[:alnum
:]_
@:]+:[ \t]*$
") s)
8363 (setq s (replace-match "" t t s)))
8364 (setq s (org-trim s))
8365 (if (string-match (concat "^
\\(" org-quote-string "\\|
"
8366 org-comment-string "\\)") s)
8367 (setq s (replace-match "" t t s)))
8368 (while (string-match org-ts-regexp s)
8369 (setq s (replace-match "" t t s))))
8370 (while (string-match "[^a-zA-Z_0-9
\t]+" s)
8371 (setq s (replace-match " " t t s)))
8372 (or string (setq s (concat "*" s))) ; Add * for headlines
8373 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8375 (defun org-make-link (&rest strings)
8376 "Concatenate STRINGS.
"
8377 (apply 'concat strings))
8379 (defun org-make-link-string (link &optional description)
8380 "Make a link with brackets
, consisting of LINK and DESCRIPTION.
"
8381 (unless (string-match "\\S-
" link)
8382 (error "Empty link
"))
8383 (when (and description
8384 (stringp description)
8385 (not (string-match "\\S-
" description)))
8386 (setq description nil))
8387 (when (stringp description)
8388 ;; Remove brackets from the description, they are fatal.
8389 (while (string-match "\\[" description)
8390 (setq description (replace-match "{" t t description)))
8391 (while (string-match "\\]" description)
8392 (setq description (replace-match "}" t t description))))
8393 (when (equal (org-link-escape link) description)
8394 ;; No description needed, it is identical
8395 (setq description nil))
8396 (when (and (not description)
8397 (not (equal link (org-link-escape link))))
8398 (setq description (org-extract-attributes link)))
8399 (concat "[[" (org-link-escape link) "]"
8400 (if description (concat "[" description "]") "")
8403 (defconst org-link-escape-chars
8407 (?\340 . "%E0
") ; `a
8408 (?\342 . "%E2
") ; ^a
8409 (?\347 . "%E7
") ; ,c
8410 (?\350 . "%E8
") ; `e
8411 (?\351 . "%E9
") ; 'e
8412 (?\352 . "%EA
") ; ^e
8413 (?\356 . "%EE
") ; ^i
8414 (?\364 . "%F4
") ; ^o
8415 (?\371 . "%F9
") ; `u
8416 (?\373 . "%FB
") ; ^u
8422 "Association list of escapes for some characters problematic in links.
8423 This is the list that is used for internal purposes.
")
8425 (defvar org-url-encoding-use-url-hexify nil)
8427 (defconst org-link-escape-chars-browser
8428 '((?\ . "%
20")) ; 32 for the SPC char
8429 "Association list of escapes for some characters problematic in links.
8430 This is the list that is used before handing over to the browser.
")
8432 (defun org-link-escape (text &optional table)
8433 "Escape characters in TEXT that are problematic for links.
"
8434 (if (and org-url-encoding-use-url-hexify (not table))
8435 (url-hexify-string text)
8436 (setq table (or table org-link-escape-chars))
8438 (let ((re (mapconcat (lambda (x) (regexp-quote
8439 (char-to-string (car x))))
8441 (while (string-match re text)
8444 (cdr (assoc (string-to-char (match-string 0 text))
8449 (defun org-link-unescape (text &optional table)
8450 "Reverse the action of
`org-link-escape
'.
"
8451 (if (and org-url-encoding-use-url-hexify (not table))
8452 (url-unhex-string text)
8453 (setq table (or table org-link-escape-chars))
8455 (let ((case-fold-search t)
8456 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8458 (while (string-match re text)
8461 (char-to-string (car (rassoc (upcase (match-string 0 text))
8466 (defun org-xor (a b)
8470 (defun org-fixup-message-id-for-http (s)
8471 "Replace special characters in a message id
, so it can be used in an http query.
"
8472 (when (string-match "%
" s)
8473 (setq s (mapconcat (lambda (c)
8476 (char-to-string c)))
8478 (while (string-match "<" s)
8479 (setq s (replace-match "%
3C
" t t s)))
8480 (while (string-match ">" s)
8481 (setq s (replace-match "%
3E
" t t s)))
8482 (while (string-match "@" s)
8483 (setq s (replace-match "%
40" t t s)))
8487 (defun org-insert-link-global ()
8488 "Insert a link like Org-mode does.
8489 This command can be called in any mode to insert a link in Org-mode syntax.
"
8491 (org-load-modules-maybe)
8492 (org-run-like-in-org-mode 'org-insert-link))
8494 (defun org-insert-link (&optional complete-file link-location)
8495 "Insert a link. At the prompt
, enter the link.
8497 Completion can be used to insert any of the link protocol prefixes like
8500 The history can be used to select a link previously stored with
8501 `org-store-link
'. When the empty string is entered
(i.e. if you just
8502 press RET at the prompt
), the link defaults to the most recently
8503 stored link. As SPC triggers completion in the minibuffer
, you need to
8504 use M-SPC or C-q SPC to force the insertion of a space character.
8506 You will also be prompted for a description
, and if one is given
, it will
8507 be displayed in the buffer instead of the link.
8509 If there is already a link at point
, this command will allow you to edit link
8510 and description parts.
8512 With a
\\[universal-argument
] prefix
, prompts for a file to link to. The file name can
8513 be selected using completion. The path to the file will be relative to the
8514 current directory if the file is in the current directory or a subdirectory.
8515 Otherwise
, the link will be the absolute path as completed in the minibuffer
8516 \
(i.e. normally ~
/path
/to
/file
). You can configure this behavior using the
8517 option
`org-link-file-path-type
'.
8519 With two
\\[universal-argument
] prefixes
, enforce an absolute path even if the file is in
8520 the current directory or below.
8522 With three
\\[universal-argument
] prefixes
, negate the meaning of
8523 `org-keep-stored-link-after-insertion
'.
8525 If
`org-make-link-description-function
' is non-nil
, this function will be
8526 called with the link target
, and the result will be the default
8529 If the LINK-LOCATION parameter is non-nil
, this value will be
8530 used as the link location instead of reading one interactively.
"
8532 (let* ((wcf (current-window-configuration))
8533 (region (if (org-region-active-p)
8534 (buffer-substring (region-beginning) (region-end))))
8535 (remove (and region (list (region-beginning) (region-end))))
8537 tmphist ; byte-compile incorrectly complains about this
8538 (link link-location)
8539 entry file all-prefixes)
8541 (link-location) ; specified by arg, just use it.
8542 ((org-in-regexp org-bracket-link-regexp 1)
8543 ;; We do have a link at point, and we are going to edit it.
8544 (setq remove (list (match-beginning 0) (match-end 0)))
8545 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8546 (setq link (read-string "Link
: "
8548 (org-match-string-no-properties 1)))))
8549 ((or (org-in-regexp org-angle-link-re)
8550 (org-in-regexp org-plain-link-re))
8551 ;; Convert to bracket link
8552 (setq remove (list (match-beginning 0) (match-end 0))
8553 link (read-string "Link
: "
8554 (org-remove-angle-brackets (match-string 0)))))
8555 ((member complete-file '((4) (16)))
8556 ;; Completing read for file names.
8557 (setq link (org-file-complete-link complete-file)))
8559 ;; Read link, with completion for stored links.
8560 (with-output-to-temp-buffer "*Org Links
*"
8561 (princ "Insert a link.
8562 Use TAB to complete link prefixes
, then RET for type-specific completion support
\n")
8563 (when org-stored-links
8564 (princ "\nStored links are available with
<up
>/<down
> or M-p
/n
(most recent with RET
):\n\n")
8567 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8568 (reverse org-stored-links) "\n"))))
8569 (let ((cw (selected-window)))
8570 (select-window (get-buffer-window "*Org Links
*" 'visible))
8571 (setq truncate-lines t)
8572 (unless (pos-visible-in-window-p (point-max))
8573 (org-fit-window-to-buffer))
8574 (and (window-live-p cw) (select-window cw)))
8575 ;; Fake a link history, containing the stored links.
8576 (setq tmphist (append (mapcar 'car org-stored-links)
8577 org-insert-link-history))
8578 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8579 (mapcar 'car org-link-abbrev-alist)
8584 (let ((org-completion-use-ido nil)
8585 (org-completion-use-iswitchb nil))
8586 (org-completing-read
8589 (mapcar (lambda (x) (list (concat x ":")))
8591 (mapcar 'car org-stored-links))
8594 (car (car org-stored-links)))))
8595 (if (not (string-match "\\S-
" link))
8596 (error "No link selected
"))
8597 (if (or (member link all-prefixes)
8598 (and (equal ":" (substring link -1))
8599 (member (substring link 0 -1) all-prefixes)
8600 (setq link (substring link 0 -1))))
8601 (setq link (org-link-try-special-completion link))))
8602 (set-window-configuration wcf)
8603 (kill-buffer "*Org Links
*"))
8604 (setq entry (assoc link org-stored-links))
8605 (or entry (push link org-insert-link-history))
8606 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8607 (not org-keep-stored-link-after-insertion))
8608 (setq org-stored-links (delq (assoc link org-stored-links)
8610 (setq desc (or desc (nth 1 entry)))))
8612 (if (string-match org-plain-link-re link)
8613 ;; URL-like link, normalize the use of angular brackets.
8614 (setq link (org-make-link (org-remove-angle-brackets link))))
8616 ;; Check if we are linking to the current file with a search option
8617 ;; If yes, simplify the link by using only the search option.
8618 (when (and buffer-file-name
8619 (string-match "^file
:\\(.
+?
\\)::\\([^
>]+\\)" link))
8620 (let* ((path (match-string 1 link))
8621 (case-fold-search nil)
8622 (search (match-string 2 link)))
8624 (if (equal (file-truename buffer-file-name) (file-truename path))
8625 ;; We are linking to this same file, with a search option
8626 (setq link search)))))
8628 ;; Check if we can/should use a relative path. If yes, simplify the link
8629 (when (string-match "^
\\(file:\\|docview
:\\)\\(.
*\\)" link)
8630 (let* ((type (match-string 1 link))
8631 (path (match-string 2 link))
8633 (case-fold-search nil))
8635 ((or (eq org-link-file-path-type 'absolute)
8636 (equal complete-file '(16)))
8637 (setq path (abbreviate-file-name (expand-file-name path))))
8638 ((eq org-link-file-path-type 'noabbrev)
8639 (setq path (expand-file-name path)))
8640 ((eq org-link-file-path-type 'relative)
8641 (setq path (file-relative-name path)))
8644 (if (string-match (concat "^
" (regexp-quote
8645 (file-name-as-directory
8646 default-directory)))
8647 (expand-file-name path))
8648 ;; We are linking a file with relative path name.
8649 (setq path (substring (expand-file-name path)
8651 (setq path (abbreviate-file-name (expand-file-name path)))))))
8652 (setq link (concat type path))
8653 (if (equal desc origpath)
8656 (if org-make-link-description-function
8657 (setq desc (funcall org-make-link-description-function link desc)))
8659 (setq desc (read-string "Description
: " desc))
8660 (unless (string-match "\\S-
" desc) (setq desc nil))
8661 (if remove (apply 'delete-region remove))
8662 (insert (org-make-link-string link desc))))
8664 (defun org-link-try-special-completion (type)
8665 "If there is completion support for link type TYPE
, offer it.
"
8666 (let ((fun (intern (concat "org-
" type "-complete-link
"))))
8669 (read-string "Link
(no completion support
): " (concat type ":")))))
8671 (defun org-file-complete-link (&optional arg)
8672 "Create a file link using completion.
"
8674 (setq file (read-file-name "File
: "))
8675 (let ((pwd (file-name-as-directory (expand-file-name ".
")))
8676 (pwd1 (file-name-as-directory (abbreviate-file-name
8677 (expand-file-name ".
")))))
8680 (setq link (org-make-link
8682 (abbreviate-file-name (expand-file-name file)))))
8683 ((string-match (concat "^
" (regexp-quote pwd1) "\\(.
+\\)") file)
8684 (setq link (org-make-link "file
:" (match-string 1 file))))
8685 ((string-match (concat "^
" (regexp-quote pwd) "\\(.
+\\)")
8686 (expand-file-name file))
8687 (setq link (org-make-link
8688 "file
:" (match-string 1 (expand-file-name file)))))
8689 (t (setq link (org-make-link "file
:" file)))))
8692 (defun org-completing-read (&rest args)
8693 "Completing-read with SPACE being a normal character.
"
8694 (let ((minibuffer-local-completion-map
8695 (copy-keymap minibuffer-local-completion-map)))
8696 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8697 (org-defkey minibuffer-local-completion-map "?
" 'self-insert-command)
8698 (apply 'org-icompleting-read args)))
8700 (defun org-completing-read-no-i (&rest args)
8701 (let (org-completion-use-ido org-completion-use-iswitchb)
8702 (apply 'org-completing-read args)))
8704 (defun org-iswitchb-completing-read (prompt choices &rest args)
8705 "Use iswitch as a completing-read replacement to choose from choices.
8706 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8708 (let* ((iswitchb-use-virtual-buffers nil)
8709 (iswitchb-make-buflist-hook
8711 (setq iswitchb-temp-buflist choices))))
8712 (iswitchb-read-buffer prompt)))
8714 (defun org-icompleting-read (&rest args)
8715 "Completing-read using
`ido-mode
' or
`iswitchb
' speedups if available.
"
8716 (org-without-partial-completion
8717 (if (and org-completion-use-ido
8718 (fboundp 'ido-completing-read)
8719 (boundp 'ido-mode) ido-mode
8720 (listp (second args)))
8721 (let ((ido-enter-matching-directory nil))
8722 (apply 'ido-completing-read (concat (car args))
8723 (if (consp (car (nth 1 args)))
8724 (mapcar (lambda (x) (car x)) (nth 1 args))
8727 (if (and org-completion-use-iswitchb
8728 (boundp 'iswitchb-mode) iswitchb-mode
8729 (listp (second args)))
8730 (apply 'org-iswitchb-completing-read (concat (car args))
8731 (if (consp (car (nth 1 args)))
8732 (mapcar (lambda (x) (car x)) (nth 1 args))
8735 (apply 'completing-read args)))))
8737 (defun org-extract-attributes (s)
8738 "Extract the attributes cookie from a string and set as text property.
"
8739 (let (a attr (start 0) key value)
8741 (when (string-match "{{\\([^
}]+\\)}}$
" s)
8742 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8743 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"" a start)
8744 (setq key (match-string 1 a) value (match-string 2 a)
8746 attr (plist-put attr (intern key) value))))
8747 (org-add-props s nil 'org-attr attr))
8750 (defun org-extract-attributes-from-string (tag)
8751 (let (key value attr)
8752 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"\\s-?
" tag)
8753 (setq key (match-string 1 tag) value (match-string 2 tag)
8754 tag (replace-match "" t t tag)
8755 attr (plist-put attr (intern key) value)))
8758 (defun org-attributes-to-string (plist)
8759 "Format a property list into an HTML attribute list.
"
8760 (let ((s "") key value)
8762 (setq key (pop plist) value (pop plist))
8764 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8767 ;;; Opening/following a link
8769 (defvar org-link-search-failed nil)
8771 (defvar org-open-link-functions nil
8772 "Hook for functions finding a plain text link.
8773 These functions must take a single argument
, the link content.
8774 They will be called for links that look like
[[link text
][description]]
8775 when LINK TEXT does not have a protocol like \"http:\" and does not look
8776 like a filename (e.g. \"./blue.png\").
8778 These functions will be called *before* Org attempts to resolve the
8779 link by doing text searches in the current buffer - so if you want a
8780 link \"[[target]]\" to still find \"<<target>>\", your function should
8781 handle this as a special case.
8783 When the function does handle the link, it must return a non-nil value.
8784 If it decides that it is not responsible for this link, it must return
8785 nil to indicate that that Org-mode can continue with other options
8786 like exact and fuzzy text search.")
8788 (defun org-next-link ()
8789 "Move forward to the next link.
8790 If the link is in hidden text, expose it."
8792 (when (and org-link-search-failed (eq this-command last-command))
8793 (goto-char (point-min))
8794 (message "Link search wrapped back to beginning of buffer"))
8795 (setq org-link-search-failed nil)
8796 (let* ((pos (point))
8798 (a (assoc :link ct)))
8799 (if a (goto-char (nth 2 a)))
8800 (if (re-search-forward org-any-link-re nil t)
8802 (goto-char (match-beginning 0))
8803 (if (org-invisible-p) (org-show-context)))
8805 (setq org-link-search-failed t)
8806 (error "No further link found"))))
8808 (defun org-previous-link ()
8809 "Move backward to the previous link.
8810 If the link is in hidden text, expose it."
8812 (when (and org-link-search-failed (eq this-command last-command))
8813 (goto-char (point-max))
8814 (message "Link search wrapped back to end of buffer"))
8815 (setq org-link-search-failed nil)
8816 (let* ((pos (point))
8818 (a (assoc :link ct)))
8819 (if a (goto-char (nth 1 a)))
8820 (if (re-search-backward org-any-link-re nil t)
8822 (goto-char (match-beginning 0))
8823 (if (org-invisible-p) (org-show-context)))
8825 (setq org-link-search-failed t)
8826 (error "No further link found"))))
8828 (defun org-translate-link (s)
8829 "Translate a link string if a translation function has been defined."
8830 (if (and org-link-translation-function
8831 (fboundp org-link-translation-function)
8832 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8834 (setq s (funcall org-link-translation-function
8835 (match-string 1) (match-string 2)))
8836 (concat (car s) ":" (cdr s)))
8839 (defun org-translate-link-from-planner (type path)
8840 "Translate a link from Emacs Planner syntax so that Org can follow it.
8841 This is still an experimental function, your mileage may vary."
8843 ((member type '("http" "https" "news" "ftp"))
8844 ;; standard Internet links are the same.
8846 ((and (equal type "irc") (string-match "^//" path))
8847 ;; Planner has two / at the beginning of an irc link, we have 1.
8848 ;; We should have zero, actually....
8849 (setq path (substring path 1)))
8850 ((and (equal type "lisp") (string-match "^/" path))
8851 ;; Planner has a slash, we do not.
8852 (setq type "elisp" path (substring path 1)))
8853 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8854 ;; A typical message link. Planner has the id after the final slash,
8855 ;; we separate it with a hash mark
8856 (setq path (concat (match-string 1 path) "#"
8857 (org-remove-angle-brackets (match-string 2 path)))))
8861 (defun org-find-file-at-mouse (ev)
8862 "Open file link or URL at mouse."
8864 (mouse-set-point ev)
8865 (org-open-at-point 'in-emacs))
8867 (defun org-open-at-mouse (ev)
8868 "Open file link or URL at mouse."
8870 (mouse-set-point ev)
8871 (if (eq major-mode 'org-agenda-mode)
8872 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8873 (org-open-at-point))
8875 (defvar org-window-config-before-follow-link nil
8876 "The window configuration before following a link.
8877 This is saved in case the need arises to restore it.")
8879 (defvar org-open-link-marker (make-marker)
8880 "Marker pointing to the location where `org-open-at-point; was called.")
8883 (defun org-open-at-point-global ()
8884 "Follow a link like Org-mode does.
8885 This command can be called in any mode to follow a link that has
8888 (org-run-like-in-org-mode 'org-open-at-point))
8891 (defun org-open-link-from-string (s &optional arg reference-buffer)
8892 "Open a link in the string S, as if it was in Org-mode."
8893 (interactive "sLink: \nP")
8894 (let ((reference-buffer (or reference-buffer (current-buffer))))
8896 (let ((org-inhibit-startup t))
8899 (goto-char (point-min))
8900 (when reference-buffer
8901 (setq org-link-abbrev-alist-local
8902 (with-current-buffer reference-buffer
8903 org-link-abbrev-alist-local)))
8904 (org-open-at-point arg reference-buffer)))))
8906 (defun org-open-at-point (&optional in-emacs reference-buffer)
8907 "Open link at or after point.
8908 If there is no link at point, this function will search forward up to
8909 the end of the current line.
8910 Normally, files will be opened by an appropriate application. If the
8911 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8912 With a double prefix argument, try to open outside of Emacs, in the
8913 application the system uses for this file type."
8915 ;; if in a code block, then open the block's results
8916 (unless (call-interactively #'org-babel-open-src-block-result)
8917 (org-load-modules-maybe)
8918 (move-marker org-open-link-marker (point))
8919 (setq org-window-config-before-follow-link (current-window-configuration))
8920 (org-remove-occur-highlights nil nil t)
8922 ((and (org-on-heading-p)
8924 (concat org-plain-link-re "\\|"
8925 org-bracket-link-regexp "\\|"
8926 org-angle-link-re "\\|"
8927 "[ \t]:[^ \t\n]+:[ \t]*$")))
8928 (not (get-text-property (point) 'org-linked-text)))
8929 (or (org-offer-links-in-entry in-emacs)
8930 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8931 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8932 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8933 (org-footnote-action))
8935 (let (type path link line search (pos (point)))
8938 (skip-chars-forward "^]\n\r")
8939 (when (org-in-regexp org-bracket-link-regexp 1)
8940 (setq link (org-extract-attributes
8941 (org-link-unescape (org-match-string-no-properties 1))))
8942 (while (string-match " *\n *" link)
8943 (setq link (replace-match " " t t link)))
8944 (setq link (org-link-expand-abbrev link))
8946 ((or (file-name-absolute-p link)
8947 (string-match "^\\.\\.?/" link))
8948 (setq type "file" path link))
8949 ((string-match org-link-re-with-space3 link)
8950 (setq type (match-string 1 link) path (match-string 2 link)))
8951 (t (setq type "thisfile" path link)))
8954 (when (get-text-property (point) 'org-linked-text)
8955 (setq type "thisfile"
8956 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8957 (1+ (point)) (point))
8958 path (buffer-substring
8959 (previous-single-property-change pos 'org-linked-text)
8960 (next-single-property-change pos 'org-linked-text)))
8964 (when (or (org-in-regexp org-angle-link-re)
8965 (org-in-regexp org-plain-link-re))
8966 (setq type (match-string 1) path (match-string 2))
8969 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8971 path (match-string 1))
8972 (while (string-match ":" path)
8973 (setq path (replace-match "+" t t path)))
8975 (when (org-in-regexp "<\\([^><\n]+\\)>")
8976 (setq type "tree-match"
8977 path (match-string 1))
8980 (error "No link found"))
8982 ;; switch back to reference buffer
8983 ;; needed when if called in a temporary buffer through
8984 ;; org-open-link-from-string
8985 (with-current-buffer (or reference-buffer (current-buffer))
8987 ;; Remove any trailing spaces in path
8988 (if (string-match " +\\'" path)
8989 (setq path (replace-match "" t t path)))
8990 (if (and org-link-translation-function
8991 (fboundp org-link-translation-function))
8992 ;; Check if we need to translate the link
8993 (let ((tmp (funcall org-link-translation-function type path)))
8994 (setq type (car tmp) path (cdr tmp))))
8998 ((assoc type org-link-protocols)
8999 (funcall (nth 1 (assoc type org-link-protocols)) path))
9001 ((equal type "mailto")
9002 (let ((cmd (car org-link-mailto-program))
9003 (args (cdr org-link-mailto-program)) args1
9004 (address path) (subject "") a)
9005 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9006 (setq address (match-string 1 path)
9007 subject (org-link-escape (match-string 2 path))))
9010 ((not (stringp (car args))) (push (pop args) args1))
9011 (t (setq a (pop args))
9012 (if (string-match "%a" a)
9013 (setq a (replace-match address t t a)))
9014 (if (string-match "%s" a)
9015 (setq a (replace-match subject t t a)))
9017 (apply cmd (nreverse args1))))
9019 ((member type '("http" "https" "ftp" "news"))
9020 (browse-url (concat type ":" (org-link-escape
9021 path org-link-escape-chars-browser))))
9023 ((string= type "doi")
9024 (browse-url (concat "http://dx.doi.org/"
9026 path org-link-escape-chars-browser))))
9028 ((member type '("message"))
9029 (browse-url (concat type ":" path)))
9031 ((string= type "tags")
9032 (org-tags-view in-emacs path))
9034 ((string= type "tree-match")
9035 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9037 ((string= type "file")
9038 (if (string-match "::\\([0-9]+\\)\\'" path)
9039 (setq line (string-to-number (match-string 1 path))
9040 path (substring path 0 (match-beginning 0)))
9041 (if (string-match "::\\(.+\\)\\'" path)
9042 (setq search (match-string 1 path)
9043 path (substring path 0 (match-beginning 0)))))
9044 (if (string-match "[*?{]" (file-name-nondirectory path))
9046 (org-open-file path in-emacs line search)))
9048 ((string= type "news")
9050 (org-gnus-follow-link path))
9052 ((string= type "shell")
9054 (if (or (not org-confirm-shell-link-function)
9055 (funcall org-confirm-shell-link-function
9056 (format "Execute \"%s\" in shell? "
9057 (org-add-props cmd nil
9058 'face 'org-warning))))
9060 (message "Executing %s" cmd)
9061 (shell-command cmd))
9064 ((string= type "elisp")
9066 (if (or (not org-confirm-elisp-link-function)
9067 (funcall org-confirm-elisp-link-function
9068 (format "Execute \"%s\" as elisp? "
9069 (org-add-props cmd nil
9070 'face 'org-warning))))
9071 (message "%s => %s" cmd
9072 (if (equal (string-to-char cmd) ?\()
9074 (call-interactively (read cmd))))
9077 ((and (string= type "thisfile")
9078 (run-hook-with-args-until-success
9079 'org-open-link-functions path)))
9081 ((string= type "thisfile")
9083 (switch-to-buffer-other-window
9084 (org-get-buffer-for-internal-link (current-buffer)))
9085 (org-mark-ring-push))
9086 (let ((cmd `(org-link-search
9088 ,(cond ((equal in-emacs '(4)) 'occur)
9089 ((equal in-emacs '(16)) 'org-occur)
9092 (condition-case nil (eval cmd)
9093 (error (progn (widen) (eval cmd))))))
9096 (browse-url-at-point)))))))
9097 (move-marker org-open-link-marker nil)
9098 (run-hook-with-args 'org-follow-link-hook)))
9100 (defun org-offer-links-in-entry (&optional nth zero)
9101 "Offer links in the current entry and follow the selected link.
9102 If there is only one link, follow it immediately as well.
9103 If NTH is an integer, immediately pick the NTH link found.
9104 If ZERO is a string, check also this string for a link, and if
9105 there is one, offer it as link number zero."
9106 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
9107 "\\(" org-angle-link-re "\\)\\|"
9108 "\\(" org-plain-link-re "\\)"))
9110 (in-emacs (if (integerp nth) nil nth))
9111 have-zero end links link c)
9112 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
9113 (push (match-string 0 zero) links)
9114 (setq cnt (1- cnt) have-zero t))
9116 (org-back-to-heading t)
9117 (setq end (save-excursion (outline-next-heading) (point)))
9118 (while (re-search-forward re end t)
9119 (push (match-string 0) links))
9120 (setq links (org-uniquify (reverse links))))
9124 (message "No links"))
9125 ((equal (length links) 1)
9126 (setq link (list (car links))))
9127 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
9128 (setq link (nth (if have-zero nth (1- nth)) links)))
9129 (t ; we have to select a link
9131 (save-window-excursion
9132 (delete-other-windows)
9133 (with-output-to-temp-buffer "*Select Link*"
9135 (if (not (string-match org-bracket-link-regexp l))
9136 (princ (format "[%c] %s\n" (incf cnt)
9137 (org-remove-angle-brackets l)))
9139 (princ (format "[%c] %s (%s)\n" (incf cnt)
9140 (match-string 3 l) (match-string 1 l)))
9141 (princ (format "[%c] %s\n" (incf cnt)
9142 (match-string 1 l))))))
9144 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
9145 (message "Select link to open, RET to open all:")
9146 (setq c (read-char-exclusive))
9147 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
9148 (when (equal c ?q) (error "Abort"))
9152 (if have-zero (setq nth (1+ nth)))
9153 (unless (and (integerp nth) (>= (length links) nth))
9154 (error "Invalid link selection"))
9155 (setq link (list (nth (1- nth) links))))))
9157 (let ((buf (current-buffer)))
9159 (org-open-link-from-string l in-emacs buf))
9163 ;; Add special file links that specify the way of opening
9165 (org-add-link-type "file+sys" 'org-open-file-with-system)
9166 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
9167 (defun org-open-file-with-system (path)
9168 "Open file at PATH using the system way of opeing it."
9169 (org-open-file path 'system))
9170 (defun org-open-file-with-emacs (path)
9171 "Open file at PATH in emacs."
9172 (org-open-file path 'emacs))
9173 (defun org-remove-file-link-modifiers ()
9174 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
9175 (goto-char (point-min))
9176 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
9178 (replace-match "file:" t t))))
9179 (eval-after-load "org-exp"
9180 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
9181 'org-remove-file-link-modifiers))
9185 (defun org-get-effort (&optional pom)
9186 "Get the effort estimate for the current entry."
9187 (org-entry-get pom org-effort-property))
9191 (defvar org-create-file-search-functions nil
9192 "List of functions to construct the right search string for a file link.
9193 These functions are called in turn with point at the location to
9194 which the link should point.
9196 A function in the hook should first test if it would like to
9197 handle this file type, for example by checking the major-mode or
9198 the file extension. If it decides not to handle this file, it
9199 should just return nil to give other functions a chance. If it
9200 does handle the file, it must return the search string to be used
9201 when following the link. The search string will be part of the
9202 file link, given after a double colon, and `org-open-at-point'
9203 will automatically search for it. If special measures must be
9204 taken to make the search successful, another function should be
9205 added to the companion hook `org-execute-file-search-functions',
9208 A function in this hook may also use `setq' to set the variable
9209 `description' to provide a suggestion for the descriptive text to
9210 be used for this link when it gets inserted into an Org-mode
9211 buffer with \\[org-insert-link].")
9213 (defvar org-execute-file-search-functions nil
9214 "List of functions to execute a file search triggered by a link.
9216 Functions added to this hook must accept a single argument, the
9217 search string that was part of the file link, the part after the
9218 double colon. The function must first check if it would like to
9219 handle this search, for example by checking the major-mode or the
9220 file extension. If it decides not to handle this search, it
9221 should just return nil to give other functions a chance. If it
9222 does handle the search, it must return a non-nil value to keep
9223 other functions from trying.
9225 Each function can access the current prefix argument through the
9226 variable `current-prefix-argument'. Note that a single prefix is
9227 used to force opening a link in Emacs, so it may be good to only
9228 use a numeric or double prefix to guide the search function.
9230 In case this is needed, a function in this hook can also restore
9231 the window configuration before `org-open-at-point' was called using:
9233 (set-window-configuration org-window-config-before-follow-link)")
9235 (defun org-link-search (s &optional type avoid-pos)
9236 "Search for a link search option.
9237 If S is surrounded by forward slashes, it is interpreted as a
9238 regular expression. In org-mode files, this will create an `org-occur'
9239 sparse tree. In ordinary files, `occur' will be used to list matches.
9240 If the current buffer is in `dired-mode', grep will be used to search
9241 in all files. If AVOID-POS is given, ignore matches near that position."
9242 (let ((case-fold-search t)
9243 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
9244 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
9245 (append '(("") (" ") ("\t") ("\n"))
9249 (pre nil) (post nil)
9250 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
9252 ;; First check if there are any special
9253 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
9254 ;; Now try the builtin stuff
9255 ((and (equal (string-to-char s0) ?#)
9258 (goto-char (point-min))
9261 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
9262 (setq type 'dedicated
9263 pos (match-beginning 0))))
9264 ;; There is an exact target for this
9266 (org-back-to-heading t)))
9268 (goto-char (point-min))
9271 (concat "<<" (regexp-quote s0) ">>") nil t)
9272 (setq type 'dedicated
9273 pos (match-beginning 0))))
9274 ;; There is an exact target for this
9276 ((and (string-match "^(\\(.*\\))$" s0)
9278 (goto-char (point-min))
9281 (concat "[^[]" (regexp-quote
9282 (format org-coderef-label-format
9283 (match-string 1 s0))))
9285 (setq type 'dedicated
9286 pos (1+ (match-beginning 0))))))
9287 ;; There is a coderef target for this
9289 ((string-match "^/\\(.*\\)/$" s)
9290 ;; A regular expression
9293 (org-occur (match-string 1 s)))
9294 ;;((eq major-mode 'dired-mode)
9295 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9296 (t (org-do-occur (match-string 1 s)))))
9298 ;; A normal search strings
9299 (when (equal (string-to-char s) ?*)
9300 ;; Anchor on headlines, post may include tags.
9301 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
9302 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
9304 (remove-text-properties
9306 '(face nil mouse-face nil keymap nil fontified nil) s)
9307 ;; Make a series of regular expressions to find a match
9308 (setq words (org-split-string s "[ \n\r\t]+")
9310 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
9311 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9313 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9314 re2a (concat "[ \t\r\n]" re2a_)
9315 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9316 re4 (concat "[^a-zA-Z_]" re4_)
9318 re1 (concat pre re2 post)
9319 re3 (concat pre (if pre re4_ re4) post)
9320 re5 (concat pre ".*" re4)
9321 re2 (concat pre re2)
9322 re2a (concat pre (if pre re2a_ re2a))
9323 re4 (concat pre (if pre re4_ re4))
9324 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9325 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9329 ((eq type 'org-occur) (org-occur reall))
9330 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9331 (t (goto-char (point-min))
9333 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9334 (org-search-not-self 1 re1 nil t)
9335 (org-search-not-self 1 re2 nil t)
9336 (org-search-not-self 1 re2a nil t)
9337 (org-search-not-self 1 re3 nil t)
9338 (org-search-not-self 1 re4 nil t)
9339 (org-search-not-self 1 re5 nil t)
9341 (goto-char (match-beginning 1))
9343 (error "No match")))))
9345 ;; Normal string-search
9346 (goto-char (point-min))
9347 (if (search-forward s nil t)
9348 (goto-char (match-beginning 0))
9349 (error "No match"))))
9350 (and (org-mode-p) (org-show-context 'link-search))
9353 (defun org-search-not-self (group &rest args)
9354 "Execute `re-search-forward', but only accept matches that do not
9355 enclose the position of `org-open-link-marker'."
9356 (let ((m org-open-link-marker))
9358 (while (apply 're-search-forward args)
9359 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9360 (goto-char (match-end group))
9361 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9362 (> (match-beginning 0) (marker-position m))
9363 (< (match-end 0) (marker-position m)))
9365 (or (not (org-in-regexp
9366 org-bracket-link-analytic-regexp 1))
9367 (not (match-end 4)) ; no description
9368 (and (<= (match-beginning 4) (point))
9369 (>= (match-end 4) (point))))))
9370 (throw 'exit (point))))))))
9372 (defun org-get-buffer-for-internal-link (buffer)
9373 "Return a buffer to be used for displaying the link target of internal links."
9375 ((not org-display-internal-link-with-indirect-buffer)
9377 ((string-match "(Clone)$" (buffer-name buffer))
9378 (message "Buffer is already a clone, not making another one")
9379 ;; we also do not modify visibility in this case
9381 (t ; make a new indirect buffer for displaying the link
9382 (let* ((bn (buffer-name buffer))
9383 (ibn (concat bn "(Clone)"))
9384 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9385 (with-current-buffer ib (org-overview))
9388 (defun org-do-occur (regexp &optional cleanup)
9389 "Call the Emacs command `occur'.
9390 If CLEANUP is non-nil, remove the printout of the regular expression
9391 in the *Occur* buffer. This is useful if the regex is long and not useful
9395 (let ((cwin (selected-window)) win beg end)
9396 (when (setq win (get-buffer-window "*Occur*"))
9397 (select-window win))
9398 (goto-char (point-min))
9399 (when (re-search-forward "match[a-z]+" nil t)
9400 (setq beg (match-end 0))
9401 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9402 (setq end (1- (match-beginning 0)))))
9403 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9404 (goto-char (point-min))
9405 (select-window cwin))))
9407 ;;; The mark ring for links jumps
9409 (defvar org-mark-ring nil
9410 "Mark ring for positions before jumps in Org-mode.")
9411 (defvar org-mark-ring-last-goto nil
9412 "Last position in the mark ring used to go back.")
9413 ;; Fill and close the ring
9414 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9415 (loop for i from 1 to org-mark-ring-length do
9416 (push (make-marker) org-mark-ring))
9417 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9420 (defun org-mark-ring-push (&optional pos buffer)
9421 "Put the current position or POS into the mark ring and rotate it."
9423 (setq pos (or pos (point)))
9424 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9425 (move-marker (car org-mark-ring)
9427 (or buffer (current-buffer)))
9429 (substitute-command-keys
9430 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9432 (defun org-mark-ring-goto (&optional n)
9433 "Jump to the previous position in the mark ring.
9434 With prefix arg N, jump back that many stored positions. When
9435 called several times in succession, walk through the entire ring.
9436 Org-mode commands jumping to a different position in the current file,
9437 or to another Org-mode file, automatically push the old position
9441 (if (eq last-command this-command)
9442 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9443 (setq p org-mark-ring))
9444 (setq org-mark-ring-last-goto p)
9446 (switch-to-buffer (marker-buffer m))
9448 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9450 (defun org-remove-angle-brackets (s)
9451 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9452 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9454 (defun org-add-angle-brackets (s)
9455 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9456 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9458 (defun org-remove-double-quotes (s)
9459 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9460 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9463 ;;; Following specific links
9465 (defun org-follow-timestamp-link ()
9467 ((org-at-date-range-p t)
9468 (let ((org-agenda-start-on-weekday)
9469 (t1 (match-string 1))
9470 (t2 (match-string 2)))
9471 (setq t1 (time-to-days (org-time-string-to-time t1))
9472 t2 (time-to-days (org-time-string-to-time t2)))
9473 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9474 ((org-at-timestamp-p t)
9475 (org-agenda-list nil (time-to-days (org-time-string-to-time
9476 (substring (match-string 1) 0 10)))
9478 (t (error "This should not happen"))))
9481 ;;; Following file links
9482 (defvar org-wait nil)
9483 (defun org-open-file (path &optional in-emacs line search)
9484 "Open the file at PATH.
9485 First, this expands any special file name abbreviations. Then the
9486 configuration variable `org-file-apps' is checked if it contains an
9487 entry for this file type, and if yes, the corresponding command is launched.
9489 If no application is found, Emacs simply visits the file.
9491 With optional prefix argument IN-EMACS, Emacs will visit the file.
9492 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9493 and to use an external application to visit the file.
9495 Optional LINE specifies a line to go to, optional SEARCH a string
9496 to search for. If LINE or SEARCH is given, the file will be
9497 opened in Emacs, unless an entry from org-file-apps that makes
9498 use of groups in a regexp matches.
9499 If the file does not exist, an error is thrown."
9500 (let* ((file (if (equal path "")
9502 (substitute-in-file-name (expand-file-name path))))
9503 (file-apps (append org-file-apps (org-default-apps)))
9504 (apps (org-remove-if
9505 'org-file-apps-entry-match-against-dlink-p file-apps))
9506 (apps-dlink (org-remove-if-not
9507 'org-file-apps-entry-match-against-dlink-p file-apps))
9508 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9509 (dirp (if remp nil (file-directory-p file)))
9510 (file (if (and dirp org-open-directory-means-index-dot-org)
9511 (concat (file-name-as-directory file) "index.org")
9513 (a-m-a-p (assq 'auto-mode apps))
9514 (dfile (downcase file))
9515 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9516 (link (cond ((and (eq line nil)
9520 (concat file "::" (number-to-string line)))
9522 (concat file "::" search))))
9523 (dlink (downcase link))
9524 (old-buffer (current-buffer))
9526 (old-mode major-mode)
9527 ext cmd link-match-data)
9528 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9529 (setq ext (match-string 1 dfile))
9530 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9531 (setq ext (match-string 1 dfile))))
9533 ((member in-emacs '((16) system))
9534 (setq cmd (cdr (assoc 'system apps))))
9535 (in-emacs (setq cmd 'emacs))
9537 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9538 (and dirp (cdr (assoc 'directory apps)))
9539 ; first, try matching against apps-dlink
9540 ; if we get a match here, store the match data for later
9541 (let ((match (assoc-default dlink apps-dlink
9544 (progn (setq link-match-data (match-data))
9546 (progn (setq in-emacs (or in-emacs line search))
9547 nil))) ; if we have no match in apps-dlink,
9548 ; always open the file in emacs if line or search
9549 ; is given (for backwards compatibility)
9550 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9552 (cdr (assoc ext apps))
9553 (cdr (assoc t apps))))))
9554 (when (eq cmd 'system)
9555 (setq cmd (cdr (assoc 'system apps))))
9556 (when (eq cmd 'default)
9557 (setq cmd (cdr (assoc t apps))))
9558 (when (eq cmd 'mailcap)
9560 (mailcap-parse-mailcaps)
9561 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9562 (command (mailcap-mime-info mime-type)))
9563 (if (stringp command)
9565 (setq cmd 'emacs))))
9566 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9567 (not (file-exists-p file))
9568 (not org-open-non-existing-files))
9569 (error "No such file: %s" file))
9571 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9572 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9573 (while (string-match "['\"]%s['\"]" cmd)
9574 (setq cmd (replace-match "%s" t t cmd)))
9575 (while (string-match "%s" cmd)
9576 (setq cmd (replace-match
9578 (shell-quote-argument
9579 (convert-standard-filename file)))
9582 ;; Replace "%1", "%2" etc. in command with group matches from regex
9584 (let ((match-index 1)
9585 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9586 (set-match-data link-match-data)
9587 (while (<= match-index number-of-groups)
9588 (let ((regex (concat "%" (number-to-string match-index)))
9589 (replace-with (match-string match-index dlink)))
9590 (while (string-match regex cmd)
9591 (setq cmd (replace-match replace-with t t cmd))))
9592 (setq match-index (+ match-index 1)))))
9594 (save-window-excursion
9595 (start-process-shell-command cmd nil cmd)
9596 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9600 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9602 (if line (org-goto-line line)
9603 (if search (org-link-search search))))
9605 (let ((file (convert-standard-filename file)))
9607 (set-match-data link-match-data)
9609 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9610 (and (org-mode-p) (eq old-mode 'org-mode)
9611 (or (not (equal old-buffer (current-buffer)))
9612 (not (equal old-pos (point))))
9613 (org-mark-ring-push old-pos old-buffer))))
9615 (defun org-file-apps-entry-match-against-dlink-p (entry)
9616 "This function returns non-nil if `entry' uses a regular
9617 expression which should be matched against the whole link by
9620 It assumes that is the case when the entry uses a regular
9621 expression which has at least one grouping construct and the
9622 action is either a lisp form or a command string containing
9623 '%1', i.e. using at least one subexpression match as a
9625 (let ((selector (car entry))
9626 (action (cdr entry)))
9627 (if (stringp selector)
9628 (and (> (regexp-opt-depth selector) 0)
9629 (or (and (stringp action)
9630 (string-match "%[0-9]" action))
9634 (defun org-default-apps ()
9635 "Return the default applications for this operating system."
9637 ((eq system-type 'darwin)
9638 org-file-apps-defaults-macosx)
9639 ((eq system-type 'windows-nt)
9640 org-file-apps-defaults-windowsnt)
9641 (t org-file-apps-defaults-gnu)))
9643 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9644 "Convert extensions to regular expressions in the cars of LIST.
9645 Also, weed out any non-string entries, because the return value is used
9646 only for regexp matching.
9647 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9648 point to the symbol `emacs', indicating that the file should
9649 be opened in Emacs."
9653 (if (not (stringp (car x)))
9655 (if (string-match "\\W" (car x))
9657 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9660 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9662 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9663 (defun org-file-remote-p (file)
9664 "Test whether FILE specifies a location on a remote system.
9665 Return non-nil if the location is indeed remote.
9667 For example, the filename \"/user@host:/foo\" specifies a location
9668 on the system \"/user@host:\"."
9669 (cond ((fboundp 'file-remote-p)
9670 (file-remote-p file))
9671 ((fboundp 'tramp-handle-file-remote-p)
9672 (tramp-handle-file-remote-p file))
9673 ((and (boundp 'ange-ftp-name-format)
9674 (string-match (car ange-ftp-name-format) file))
9681 (defun org-get-org-file ()
9682 "Read a filename, with default directory `org-directory'."
9683 (let ((default (or org-default-notes-file remember-data-file)))
9684 (read-file-name (format "File name [%s]: " default)
9685 (file-name-as-directory org-directory)
9688 (defun org-notes-order-reversed-p ()
9689 "Check if the current file should receive notes in reversed order."
9691 ((not org-reverse-note-order) nil)
9692 ((eq t org-reverse-note-order) t)
9693 ((not (listp org-reverse-note-order)) nil)
9695 (let ((all org-reverse-note-order)
9697 (while (setq entry (pop all))
9698 (if (string-match (car entry) buffer-file-name)
9699 (throw 'exit (cdr entry))))
9702 (defvar org-refile-target-table nil
9703 "The list of refile targets, created by `org-refile'.")
9705 (defvar org-agenda-new-buffers nil
9706 "Buffers created to visit agenda files.")
9708 (defvar org-refile-cache nil
9709 "Cache for refile targets.")
9712 (defvar org-refile-markers nil
9713 "All the markers used for caching refile locations.")
9715 (defun org-refile-marker (pos)
9716 "Get a new refile marker, but only if caching is in use."
9717 (if (not org-refile-use-cache)
9719 (let ((m (make-marker)))
9721 (push m org-refile-markers)
9724 (defun org-refile-cache-clear ()
9725 "Clear the refile cache and disable all the markers."
9726 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
9727 (setq org-refile-markers nil)
9728 (setq org-refile-cache nil)
9729 (message "Refile cache has been cleared"))
9731 (defun org-refile-cache-check-set (set)
9732 "Check if all the markers in the cache still have live buffers."
9735 (while (and set (setq marker (nth 3 (pop set))))
9736 ;; if org-refile-use-outline-path is 'file, marker may be nil
9737 (when (and marker (null (marker-buffer marker)))
9738 (message "not found") (sit-for 3)
9742 (defun org-refile-cache-put (set &rest identifiers)
9743 "Push the refile targets SET into the cache, under IDENTIFIERS."
9744 (let* ((key (sha1 (prin1-to-string identifiers)))
9745 (entry (assoc key org-refile-cache)))
9748 (push (cons key set) org-refile-cache))))
9750 (defun org-refile-cache-get (&rest identifiers)
9751 "Retrieve the cached value for refile targets given by IDENTIFIERS."
9753 ((not org-refile-cache) nil)
9754 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
9756 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
9757 org-refile-cache))))
9758 (and set (org-refile-cache-check-set set) set)))))
9760 (defun org-get-refile-targets (&optional default-buffer)
9761 "Produce a table with refile targets."
9762 (let ((case-fold-search nil)
9763 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9764 (entries (or org-refile-targets '((nil . (:level . 1)))))
9765 targets tgs txt re files f desc descre fast-path-p level pos0)
9766 (message "Getting targets...")
9767 (with-current-buffer (or default-buffer (current-buffer))
9768 (while (setq entry (pop entries))
9769 (setq files (car entry) desc (cdr entry))
9770 (setq fast-path-p nil)
9772 ((null files) (setq files (list (current-buffer))))
9773 ((eq files 'org-agenda-files)
9774 (setq files (org-agenda-files 'unrestricted)))
9775 ((and (symbolp files) (fboundp files))
9776 (setq files (funcall files)))
9777 ((and (symbolp files) (boundp files))
9778 (setq files (symbol-value files))))
9779 (if (stringp files) (setq files (list files)))
9781 ((eq (car desc) :tag)
9782 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9783 ((eq (car desc) :todo)
9784 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9785 ((eq (car desc) :regexp)
9786 (setq descre (cdr desc)))
9787 ((eq (car desc) :level)
9788 (setq descre (concat "^\\*\\{" (number-to-string
9789 (if org-odd-levels-only
9790 (1- (* 2 (cdr desc)))
9793 ((eq (car desc) :maxlevel)
9794 (setq fast-path-p t)
9795 (setq descre (concat "^\\*\\{1," (number-to-string
9796 (if org-odd-levels-only
9797 (1- (* 2 (cdr desc)))
9800 (t (error "Bad refiling target description %s" desc)))
9801 (while (setq f (pop files))
9802 (with-current-buffer
9803 (if (bufferp f) f (org-get-agenda-file-buffer f))
9805 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
9807 (if (bufferp f) (setq f (buffer-file-name
9808 (buffer-base-buffer f))))
9809 (setq f (and f (expand-file-name f)))
9810 (if (eq org-refile-use-outline-path 'file)
9811 (push (list (file-name-nondirectory f) f nil nil) tgs))
9815 (goto-char (point-min))
9816 (while (re-search-forward descre nil t)
9817 (goto-char (setq pos0 (point-at-bol)))
9819 (when org-refile-target-verify-function
9821 (or (funcall org-refile-target-verify-function)
9823 (when (looking-at org-complex-heading-regexp)
9824 (setq level (org-reduced-level
9825 (- (match-end 1) (match-beginning 1)))
9826 txt (org-link-display-format (match-string 4))
9827 re (concat "^" (regexp-quote
9831 (if (match-end 5) (setq re (concat
9834 (match-string 5)))))
9835 (setq re (concat re "[ \t]*$"))
9836 (when org-refile-use-outline-path
9837 (setq txt (mapconcat
9840 (if (eq org-refile-use-outline-path
9842 (list (file-name-nondirectory
9844 (buffer-base-buffer))))
9845 (if (eq org-refile-use-outline-path
9847 (list (buffer-file-name
9848 (buffer-base-buffer)))))
9849 (org-get-outline-path fast-path-p
9853 (push (list txt f re (org-refile-marker (point)))
9855 (when (= (point) pos0)
9856 ;; verification function has not moved point
9857 (goto-char (point-at-eol))))))))
9858 (when org-refile-use-cache
9859 (org-refile-cache-put tgs (buffer-file-name) descre))
9860 (setq targets (append tgs targets))
9862 (message "Getting targets...done")
9863 (nreverse targets)))
9865 (defun org-protect-slash (s)
9866 (while (string-match "/" s)
9867 (setq s (replace-match "\\" t t s)))
9870 (defvar org-olpa (make-vector 20 nil))
9872 (defun org-get-outline-path (&optional fastp level heading)
9873 "Return the outline path to the current entry, as a list.
9875 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
9876 routine which makes outline path derivations for an entire file,
9877 avoiding backtracing. Refile target collection makes use of that."
9881 (error "Outline path failure, more than 19 levels."))
9882 (loop for i from level upto 19 do
9883 (aset org-olpa i nil))
9885 (delq nil (append org-olpa nil))
9886 (aset org-olpa level heading)))
9887 (let (rtn case-fold-search)
9891 (while (org-up-heading-safe)
9892 (when (looking-at org-complex-heading-regexp)
9893 (push (org-match-string-no-properties 4) rtn)))
9896 (defun org-format-outline-path (path &optional width prefix)
9897 "Format the outlie path PATH for display.
9898 Width is the maximum number of characters that is available.
9899 Prefix is a prefix to be included in the returned string,
9900 such as the file name."
9901 (setq width (or width 79))
9902 (if prefix (setq width (- width (length prefix))))
9905 (let* ((nsteps (length path))
9906 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9907 (maxwidth (if (<= total-width width)
9908 10000 ;; everything fits
9909 ;; we need to shorten the level headings
9910 (/ (- width nsteps) nsteps)))
9911 (org-odd-levels-only nil)
9913 (total (1+ (length prefix))))
9914 (setq maxwidth (max maxwidth 10))
9919 (if (and (= n nsteps) (< maxwidth 10000))
9920 (setq maxwidth (- total-width total)))
9921 (if (< (length h) maxwidth)
9922 (progn (setq total (+ total (length h) 1)) h)
9923 (setq h (substring h 0 (- maxwidth 2))
9924 total (+ total maxwidth 1))
9925 (if (string-match "[ \t]+\\'" h)
9926 (setq h (substring h 0 (match-beginning 0))))
9927 (setq h (concat h "..")))
9928 (org-add-props h nil 'face
9929 (nth (% (1- n) org-n-level-faces)
9934 (defun org-display-outline-path (&optional file current)
9935 "Display the current outline path in the echo area."
9937 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9938 (case-fold-search nil)
9939 (path (and (org-mode-p) (org-get-outline-path))))
9940 (if current (setq path (append path
9942 (org-back-to-heading t)
9943 (if (looking-at org-complex-heading-regexp)
9944 (list (match-string 4)))))))
9946 (org-format-outline-path
9949 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9951 (defvar org-refile-history nil
9952 "History for refiling operations.")
9954 (defvar org-after-refile-insert-hook nil
9955 "Hook run after `org-refile' has inserted its stuff at the new location.
9956 Note that this is still *before* the stuff will be removed from
9957 the *old* location.")
9959 (defun org-refile (&optional goto default-buffer rfloc)
9960 "Move the entry at point to another heading.
9961 The list of target headings is compiled using the information in
9962 `org-refile-targets', which see. This list is created before each use
9963 and will therefore always be up-to-date.
9965 At the target location, the entry is filed as a subitem of the target heading.
9966 Depending on `org-reverse-note-order', the new subitem will either be the
9967 first or the last subitem.
9969 If there is an active region, all entries in that region will be moved.
9970 However, the region must fulfil the requirement that the first heading
9971 is the first one sets the top-level of the moved text - at most siblings
9972 below it are allowed.
9974 With prefix arg GOTO, the command will only visit the target location,
9975 not actually move anything.
9976 With a double prefix `C-u C-u', go to the location where the last refiling
9977 operation has put the subtree.
9978 With a prefix argument of `2', refile to the running clock.
9980 RFLOC can be a refile location obtained in a different way.
9982 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
9984 If you are using target caching (see `org-refile-use-cache'),
9985 You have to clear the target cache in order to find new targets.
9986 This can be done with a 0 prefix: `C-0 C-c C-w'"
9988 (if (member goto '(0 (64)))
9989 (org-refile-cache-clear)
9990 (let* ((cbuf (current-buffer))
9991 (regionp (org-region-active-p))
9992 (region-start (and regionp (region-beginning)))
9993 (region-end (and regionp (region-end)))
9994 (region-length (and regionp (- region-end region-start)))
9995 (filename (buffer-file-name (buffer-base-buffer cbuf)))
9996 pos it nbuf file re level reversed)
9997 (setq last-command nil)
9999 (goto-char region-start)
10000 (or (bolp) (goto-char (point-at-bol)))
10001 (setq region-start (point))
10002 (unless (org-kill-is-subtree-p
10003 (buffer-substring region-start region-end))
10004 (error "The region is not a (sequence of) subtree(s)")))
10005 (if (equal goto '(16))
10006 (org-refile-goto-last-stored)
10008 (and (equal goto 2)
10009 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10011 (setq it (list (or org-clock-heading "running clock")
10013 (marker-buffer org-clock-hd-marker))
10015 (marker-position org-clock-hd-marker)))
10019 (org-refile-get-location
10020 (if goto "Goto: " "Refile to: ") default-buffer
10021 org-refile-allow-creating-parent-nodes)))))
10022 (setq file (nth 1 it)
10025 (if (and (not goto)
10027 (equal (buffer-file-name) file)
10029 (and (>= pos region-start)
10030 (<= pos region-end))
10031 (and (>= pos (point))
10032 (< pos (save-excursion
10033 (org-end-of-subtree t t))))))
10034 (error "Cannot refile to position inside the tree or region"))
10036 (setq nbuf (or (find-buffer-visiting file)
10037 (find-file-noselect file)))
10040 (switch-to-buffer nbuf)
10042 (org-show-context 'org-goto))
10045 (org-kill-new (buffer-substring region-start region-end))
10046 (org-save-markers-in-region region-start region-end))
10047 (org-copy-subtree 1 nil t))
10048 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
10049 (find-file-noselect file)))
10050 (setq reversed (org-notes-order-reversed-p))
10057 (looking-at outline-regexp)
10058 (setq level (org-get-valid-level (funcall outline-level) 1))
10061 (or (outline-next-heading) (point-max))
10062 (or (save-excursion (org-get-next-sibling))
10063 (org-end-of-subtree t t)
10067 (goto-char (point-max))
10068 (goto-char (point-min))
10069 (or (outline-next-heading) (goto-char (point-max)))))
10070 (if (not (bolp)) (newline))
10071 (org-paste-subtree level)
10072 (when org-log-refile
10073 (org-add-log-setup 'refile nil nil 'findpos
10075 (unless (eq org-log-refile 'note)
10076 (save-excursion (org-add-log-note))))
10077 (and org-auto-align-tags (org-set-tags nil t))
10078 (bookmark-set "org-refile-last-stored")
10079 (if (fboundp 'deactivate-mark) (deactivate-mark))
10080 (run-hooks 'org-after-refile-insert-hook))))
10082 (delete-region (point) (+ (point) region-length))
10084 (when (featurep 'org-inlinetask)
10085 (org-inlinetask-remove-END-maybe))
10086 (setq org-markers-to-move nil)
10087 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
10089 (defun org-refile-goto-last-stored ()
10090 "Go to the location where the last refile was stored."
10092 (bookmark-jump "org-refile-last-stored")
10093 (message "This is the location of the last refile"))
10095 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
10096 "Prompt the user for a refile location, using PROMPT."
10097 (let ((org-refile-targets org-refile-targets)
10098 (org-refile-use-outline-path org-refile-use-outline-path))
10099 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
10100 (unless org-refile-target-table
10101 (error "No refile targets"))
10102 (let* ((cbuf (current-buffer))
10103 (partial-completion-mode nil)
10104 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
10105 (cfunc (if (and org-refile-use-outline-path
10106 org-outline-path-complete-in-steps)
10107 'org-olpath-completing-read
10108 'org-icompleting-read))
10109 (extra (if org-refile-use-outline-path "/" ""))
10110 (filename (and cfn (expand-file-name cfn)))
10113 (if (and (not (member org-refile-use-outline-path
10114 '(file full-file-path)))
10115 (not (equal filename (nth 1 x))))
10116 (cons (concat (car x) extra " ("
10117 (file-name-nondirectory (nth 1 x)) ")")
10119 (cons (concat (car x) extra) (cdr x))))
10120 org-refile-target-table))
10121 (completion-ignore-case t)
10122 pa answ parent-target child parent old-hist)
10123 (setq old-hist org-refile-history)
10124 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
10125 nil 'org-refile-history))
10126 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
10129 (when (or (not org-refile-history)
10130 (not (eq old-hist org-refile-history))
10131 (not (equal (car pa) (car org-refile-history))))
10132 (setq org-refile-history
10133 (cons (car pa) (if (assoc (car org-refile-history) tbl)
10135 (cdr org-refile-history))))
10136 (if (equal (car org-refile-history) (nth 1 org-refile-history))
10137 (pop org-refile-history)))
10139 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
10141 (setq parent (match-string 1 answ)
10142 child (match-string 2 answ))
10143 (setq parent-target (or (assoc parent tbl)
10144 (assoc (concat parent "/") tbl)))
10145 (when (and parent-target
10146 (or (eq new-nodes t)
10147 (and (eq new-nodes 'confirm)
10148 (y-or-n-p (format "Create new node \"%s\"? "
10150 (org-refile-new-child parent-target child)))
10151 (error "Invalid target location")))))
10153 (defun org-refile-new-child (parent-target child)
10154 "Use refile target PARENT-TARGET to add new CHILD below it."
10155 (unless parent-target
10156 (error "Cannot find parent for new node"))
10157 (let ((file (nth 1 parent-target))
10158 (pos (nth 3 parent-target))
10160 (with-current-buffer (or (find-buffer-visiting file)
10161 (find-file-noselect file))
10167 (goto-char (point-max))
10168 (if (not (bolp)) (newline)))
10169 (when (looking-at outline-regexp)
10170 (setq level (funcall outline-level))
10171 (org-end-of-subtree t t))
10172 (org-back-over-empty-lines)
10173 (insert "\n" (make-string
10174 (if pos (org-get-valid-level level 1) 1) ?*)
10176 (beginning-of-line 0)
10177 (list (concat (car parent-target) "/" child) file "" (point)))))))
10179 (defun org-olpath-completing-read (prompt collection &rest args)
10180 "Read an outline path like a file name."
10181 (let ((thetable collection)
10182 (org-completion-use-ido nil) ; does not work with ido.
10183 (org-completion-use-iswitchb nil)) ; or iswitchb
10185 'org-icompleting-read prompt
10186 (lambda (string predicate &optional flag)
10187 (let (rtn r f (l (length string)))
10191 (try-completion string thetable))
10194 (setq rtn (all-completions string thetable predicate))
10197 (setq r (substring x l))
10198 (if (string-match " ([^)]*)$" x)
10199 (setq f (match-string 0 x))
10201 (if (string-match "/" r)
10202 (concat string (substring r 0 (match-end 0)) f)
10207 (assoc string thetable)))
10211 ;;;; Dynamic blocks
10213 (defun org-find-dblock (name)
10214 "Find the first dynamic block with name NAME in the buffer.
10215 If not found, stay at current position and return nil."
10218 (goto-char (point-min))
10219 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
10221 (match-beginning 0))))
10222 (if pos (goto-char pos))
10225 (defconst org-dblock-start-re
10226 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
10227 "Matches the start line of a dynamic block, with parameters.")
10229 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
10230 "Matches the end of a dynamic block.")
10232 (defun org-create-dblock (plist)
10233 "Create a dynamic block section, with parameters taken from PLIST.
10234 PLIST must contain a :name entry which is used as name of the block."
10235 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
10238 (let ((col (current-column))
10239 (name (plist-get plist :name)))
10240 (insert "#+BEGIN: " name)
10242 (if (eq (car plist) :name)
10243 (setq plist (cddr plist))
10244 (insert " " (prin1-to-string (pop plist)))))
10245 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
10246 (beginning-of-line -2)))
10248 (defun org-prepare-dblock ()
10249 "Prepare dynamic block for refresh.
10250 This empties the block, puts the cursor at the insert position and returns
10251 the property list including an extra property :name with the block name."
10252 (unless (looking-at org-dblock-start-re)
10253 (error "Not at a dynamic block"))
10254 (let* ((begdel (1+ (match-end 0)))
10255 (name (org-no-properties (match-string 1)))
10256 (params (append (list :name name)
10257 (read (concat "(" (match-string 3) ")")))))
10259 (beginning-of-line 1)
10260 (skip-chars-forward " \t")
10261 (setq params (plist-put params :indentation-column (current-column))))
10262 (unless (re-search-forward org-dblock-end-re nil t)
10263 (error "Dynamic block not terminated"))
10266 (list :content (buffer-substring
10267 begdel (match-beginning 0)))))
10268 (delete-region begdel (match-beginning 0))
10273 (defun org-map-dblocks (&optional command)
10274 "Apply COMMAND to all dynamic blocks in the current buffer.
10275 If COMMAND is not given, use `org-update-dblock'."
10276 (let ((cmd (or command 'org-update-dblock)))
10278 (goto-char (point-min))
10279 (while (re-search-forward org-dblock-start-re nil t)
10280 (goto-char (match-beginning 0))
10282 (condition-case nil
10284 (error (message "Error during update of dynamic block"))))
10285 (unless (re-search-forward org-dblock-end-re nil t)
10286 (error "Dynamic block not terminated"))))))
10288 (defun org-dblock-update (&optional arg)
10289 "User command for updating dynamic blocks.
10290 Update the dynamic block at point. With prefix ARG, update all dynamic
10291 blocks in the buffer."
10294 (org-update-all-dblocks)
10295 (or (looking-at org-dblock-start-re)
10296 (org-beginning-of-dblock))
10297 (org-update-dblock)))
10299 (defun org-update-dblock ()
10300 "Update the dynamic block at point
10301 This means to empty the block, parse for parameters and then call
10302 the correct writing function."
10303 (save-window-excursion
10304 (let* ((pos (point))
10305 (line (org-current-line))
10306 (params (org-prepare-dblock))
10307 (name (plist-get params :name))
10308 (indent (plist-get params :indentation-column))
10309 (cmd (intern (concat "org-dblock-write:" name))))
10310 (message "Updating dynamic block `%s' at line %d..." name line)
10311 (funcall cmd params)
10312 (message "Updating dynamic block `%s' at line %d...done" name line)
10314 (when (and indent (> indent 0))
10315 (setq indent (make-string indent ?\ ))
10317 (org-beginning-of-dblock)
10319 (while (not (looking-at org-dblock-end-re))
10321 (beginning-of-line 2))
10322 (when (looking-at org-dblock-end-re)
10323 (and (looking-at "[ \t]+")
10324 (replace-match ""))
10325 (insert indent)))))))
10327 (defun org-beginning-of-dblock ()
10328 "Find the beginning of the dynamic block at point.
10329 Error if there is no such block at point."
10330 (let ((pos (point))
10333 (if (and (re-search-backward org-dblock-start-re nil t)
10334 (setq beg (match-beginning 0))
10335 (re-search-forward org-dblock-end-re nil t)
10336 (> (match-end 0) pos))
10339 (error "Not in a dynamic block"))))
10341 (defun org-update-all-dblocks ()
10342 "Update all dynamic blocks in the buffer.
10343 This function can be used in a hook."
10345 (org-map-dblocks 'org-update-dblock)))
10350 (defconst org-additional-option-like-keywords
10351 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
10352 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
10353 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
10354 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
10356 "ORGTBL" "TBLFM:" "TBLNAME:"
10357 "BEGIN_EXAMPLE" "END_EXAMPLE"
10358 "BEGIN_QUOTE" "END_QUOTE"
10359 "BEGIN_VERSE" "END_VERSE"
10360 "BEGIN_CENTER" "END_CENTER"
10361 "BEGIN_SRC" "END_SRC"
10362 "CATEGORY" "COLUMNS"
10368 (defcustom org-structure-template-alist
10370 ("s" "#+begin_src ?\n\n#+end_src"
10371 "<src lang=\"?\">\n\n</src>")
10372 ("e" "#+begin_example\n?\n#+end_example"
10373 "<example>\n?\n</example>")
10374 ("q" "#+begin_quote\n?\n#+end_quote"
10375 "<quote>\n?\n</quote>")
10376 ("v" "#+begin_verse\n?\n#+end_verse"
10377 "<verse>\n?\n/verse>")
10378 ("c" "#+begin_center\n?\n#+end_center"
10379 "<center>\n?\n/center>")
10380 ("l" "#+begin_latex\n?\n#+end_latex"
10381 "<literal style=\"latex\">\n?\n</literal>")
10383 "<literal style=\"latex\">?</literal>")
10384 ("h" "#+begin_html\n?\n#+end_html"
10385 "<literal style=\"html\">\n?\n</literal>")
10387 "<literal style=\"html\">?</literal>")
10388 ("a" "#+begin_ascii\n?\n#+end_ascii")
10390 ("i" "#+include %file ?"
10391 "<include file=%file markup=\"?\">")
10393 "Structure completion elements.
10394 This is a list of abbreviation keys and values. The value gets inserted
10395 if you type `<' followed by the key and then press the completion key,
10396 usually `M-TAB'. %file will be replaced by a file name after prompting
10397 for the file using completion.
10398 There are two templates for each key, the first uses the original Org syntax,
10399 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
10400 the default when the /org-mtags.el/ module has been loaded. See also the
10401 variable `org-mtags-prefer-muse-templates'.
10402 This is an experimental feature, it is undecided if it is going to stay in."
10403 :group 'org-completion
10405 (string :tag "Key")
10406 (string :tag "Template")
10407 (string :tag "Muse Template")))
10409 (defun org-try-structure-completion ()
10410 "Try to complete a structure template before point.
10411 This looks for strings like \"<e\" on an otherwise empty line and
10413 (let ((l (buffer-substring (point-at-bol) (point)))
10415 (when (and (looking-at "[ \t]*$")
10416 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
10417 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
10418 (org-complete-expand-structure-template (+ -1 (point-at-bol)
10419 (match-beginning 1)) a)
10422 (defun org-complete-expand-structure-template (start cell)
10423 "Expand a structure template."
10424 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10425 (rpl (nth (if musep 2 1) cell))
10427 (delete-region start (point))
10428 (when (string-match "\\`#\\+" rpl)
10431 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10432 (setq ind (buffer-substring (point-at-bol) (point))))
10434 (setq start (point))
10435 (if (string-match "%file" rpl)
10436 (setq rpl (replace-match
10440 (abbreviate-file-name (read-file-name "Include file: ")))
10443 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10444 (concat "\n" ind)))
10446 (if (re-search-backward "\\?" start t) (delete-char 1))))
10449 (defun org-complete (&optional arg)
10450 "Perform completion on word at point.
10451 At the beginning of a headline, this completes TODO keywords as given in
10452 `org-todo-keywords'.
10453 If the current word is preceded by a backslash, completes the TeX symbols
10454 that are supported for HTML support.
10455 If the current word is preceded by \"#+\", completes special words for
10456 setting file options.
10457 In the line after \"#+STARTUP:, complete valid keywords.\"
10458 At all other locations, this simply calls the value of
10459 `org-completion-fallback-command'."
10461 (org-without-partial-completion
10465 (beg1 (save-excursion
10466 (skip-chars-backward (org-re "[:alnum:]_@"))
10468 (beg (save-excursion
10469 (skip-chars-backward "a-zA-Z0-9_:$")
10471 (confirm (lambda (x) (stringp (car x))))
10472 (searchhead (equal (char-before beg) ?*))
10474 (when (and (member (char-before beg1) '(?. ?<))
10475 (setq a (assoc (buffer-substring beg1 (point))
10476 org-structure-template-alist)))
10477 (org-complete-expand-structure-template (1- beg1) a)
10479 (tag (and (equal (char-before beg1) ?:)
10480 (equal (char-after (point-at-bol)) ?*)))
10481 (prop (and (equal (char-before beg1) ?:)
10482 (not (equal (char-after (point-at-bol)) ?*))))
10483 (texp (equal (char-before beg) ?\\))
10484 (link (equal (char-before beg) ?\[))
10485 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10488 (startup (string-match "^#\\+STARTUP:.*"
10489 (buffer-substring (point-at-bol) (point))))
10490 (completion-ignore-case opt)
10502 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10503 (cons (match-string 2 x)
10504 (match-string 1 x))))
10505 (org-split-string (org-get-current-options) "\n")))
10506 (mapcar 'list org-additional-option-like-keywords)))
10508 (setq type :startup)
10509 org-startup-options)
10510 (link (append org-link-abbrev-alist-local
10511 org-link-abbrev-alist))
10514 (append org-entities-user org-entities))
10515 ((string-match "\\`\\*+[ \t]+\\'"
10516 (buffer-substring (point-at-bol) beg))
10518 (mapcar 'list org-todo-keywords-1))
10520 (setq type :searchhead)
10522 (goto-char (point-min))
10523 (while (re-search-forward org-todo-line-regexp nil t)
10525 (org-make-org-heading-search-string
10526 (match-string 3) t))
10529 (tag (setq type :tag beg beg1)
10530 (or org-tag-alist (org-get-buffer-tags)))
10531 (prop (setq type :prop beg beg1)
10532 (mapcar 'list (org-buffer-property-keys nil t t)))
10534 (call-interactively org-completion-fallback-command)
10535 (throw 'exit nil)))))
10536 (pattern (buffer-substring-no-properties beg end))
10537 (completion (try-completion pattern table confirm)))
10538 (cond ((eq completion t)
10539 (if (not (assoc (upcase pattern) table))
10540 (message "Already complete")
10541 (if (and (equal type :opt)
10542 (not (member (car (assoc (upcase pattern) table))
10543 org-additional-option-like-keywords)))
10544 (insert (substring (cdr (assoc (upcase pattern) table))
10546 (if (memq type '(:tag :prop)) (insert ":")))))
10548 (message "Can't find completion for \"%s\"" pattern)
10550 ((not (string= pattern completion))
10551 (delete-region beg end)
10552 (if (string-match " +$" completion)
10553 (setq completion (replace-match "" t t completion)))
10554 (insert completion)
10555 (if (get-buffer-window "*Completions*")
10556 (delete-window (get-buffer-window "*Completions*")))
10557 (if (assoc completion table)
10558 (if (eq type :todo) (insert " ")
10559 (if (memq type '(:tag :prop)) (insert ":"))))
10560 (if (and (equal type :opt) (assoc completion table))
10561 (message "%s" (substitute-command-keys
10562 "Press \\[org-complete] again to insert example settings"))))
10564 (message "Making completion list...")
10565 (let ((list (sort (all-completions pattern table confirm)
10567 (with-output-to-temp-buffer "*Completions*"
10568 (condition-case nil
10569 ;; Protection needed for XEmacs and emacs 21
10570 (display-completion-list list pattern)
10571 (error (display-completion-list list)))))
10572 (message "Making completion list...%s" "done")))))))
10574 ;;;; TODO, DEADLINE, Comments
10576 (defun org-toggle-comment ()
10577 "Change the COMMENT state of an entry."
10580 (org-back-to-heading)
10581 (let (case-fold-search)
10582 (if (looking-at (concat outline-regexp
10583 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10584 (replace-match "" t t nil 1)
10585 (if (looking-at outline-regexp)
10587 (goto-char (match-end 0))
10588 (insert org-comment-string " ")))))))
10590 (defvar org-last-todo-state-is-todo nil
10591 "This is non-nil when the last TODO state change led to a TODO state.
10592 If the last change removed the TODO tag or switched to DONE, then
10595 (defvar org-setting-tags nil) ; dynamically skipped
10597 (defun org-parse-local-options (string var)
10598 "Parse STRING for startup setting relevant for variable VAR."
10599 (let ((rtn (symbol-value var))
10602 (if (or (not string) (not (string-match "\\S-" string)))
10604 (setq opts (delq nil (mapcar (lambda (x)
10605 (setq e (assoc x org-startup-options))
10606 (if (eq (nth 1 e) var) e nil))
10607 (org-split-string string "[ \t]+"))))
10611 (while (setq e (pop opts))
10612 (if (not (nth 3 e))
10613 (setq rtn (nth 2 e))
10614 (if (not (listp rtn)) (setq rtn nil))
10615 (push (nth 2 e) rtn)))
10618 (defvar org-todo-setup-filter-hook nil
10619 "Hook for functions that pre-filter todo specs.
10621 Each function takes a todo spec and returns either `nil' or the spec
10622 transformed into canonical form." )
10624 (defvar org-todo-get-default-hook nil
10625 "Hook for functions that get a default item for todo.
10627 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10628 `nil' or a string to be used for the todo mark." )
10630 (defvar org-agenda-headline-snapshot-before-repeat)
10632 (defun org-todo (&optional arg)
10633 "Change the TODO state of an item.
10634 The state of an item is given by a keyword at the start of the heading,
10636 *** TODO Write paper
10639 The different keywords are specified in the variable `org-todo-keywords'.
10640 By default the available states are \"TODO\" and \"DONE\".
10641 So for this example: when the item starts with TODO, it is changed to DONE.
10642 When it starts with DONE, the DONE is removed. And when neither TODO nor
10643 DONE are present, add TODO at the beginning of the heading.
10645 With C-u prefix arg, use completion to determine the new state.
10646 With numeric prefix arg, switch to that state.
10647 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10648 With a triple C-u prefix, circumvent any state blocking.
10650 For calling through lisp, arg is also interpreted in the following way:
10651 'none -> empty state
10652 \"\"(empty string) -> switch to empty state
10653 'done -> switch to DONE
10654 'nextset -> switch to the next set of keywords
10655 'previousset -> switch to the previous set of keywords
10656 \"WAITING\" -> switch to the specified keyword, but only if it
10657 really is a member of `org-todo-keywords'."
10659 (if (equal arg '(16)) (setq arg 'nextset))
10660 (let ((org-blocker-hook org-blocker-hook)
10661 (case-fold-search nil))
10662 (when (equal arg '(64))
10663 (setq arg nil org-blocker-hook nil))
10664 (when (and org-blocker-hook
10665 (or org-inhibit-blocking
10666 (org-entry-get nil "NOBLOCKING")))
10667 (setq org-blocker-hook nil))
10670 (org-back-to-heading t)
10671 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10672 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10674 (let* ((match-data (match-data))
10675 (startpos (point-at-bol))
10676 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
10677 (org-log-done org-log-done)
10678 (org-log-repeat org-log-repeat)
10679 (org-todo-log-states org-todo-log-states)
10680 (this (match-string 1))
10681 (hl-pos (match-beginning 0))
10682 (head (org-get-todo-sequence-head this))
10683 (ass (assoc head org-todo-kwd-alist))
10684 (interpret (nth 1 ass))
10685 (done-word (nth 3 ass))
10686 (final-done-word (nth 4 ass))
10687 (last-state (or this ""))
10688 (completion-ignore-case t)
10689 (member (member this org-todo-keywords-1))
10690 (tail (cdr member))
10692 ((and org-todo-key-trigger
10693 (or (and (equal arg '(4))
10694 (eq org-use-fast-todo-selection 'prefix))
10695 (and (not arg) org-use-fast-todo-selection
10696 (not (eq org-use-fast-todo-selection
10698 ;; Use fast selection
10699 (org-fast-todo-selection))
10700 ((and (equal arg '(4))
10701 (or (not org-use-fast-todo-selection)
10702 (not org-todo-key-trigger)))
10703 ;; Read a state with completion
10704 (org-icompleting-read
10705 "State: " (mapcar (lambda(x) (list x))
10706 org-todo-keywords-1)
10710 (if tail (car tail) nil)
10711 (car org-todo-keywords-1)))
10713 (if (equal member org-todo-keywords-1)
10716 (nth (- (length org-todo-keywords-1)
10718 org-todo-keywords-1)
10719 (org-last org-todo-keywords-1))))
10720 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10721 (setq arg nil))) ; hack to fall back to cycling
10723 ;; user or caller requests a specific state
10725 ((equal arg "") nil)
10726 ((eq arg 'none) nil)
10727 ((eq arg 'done) (or done-word (car org-done-keywords)))
10729 (or (car (cdr (member head org-todo-heads)))
10730 (car org-todo-heads)))
10731 ((eq arg 'previousset)
10732 (let ((org-todo-heads (reverse org-todo-heads)))
10733 (or (car (cdr (member head org-todo-heads)))
10734 (car org-todo-heads))))
10735 ((car (member arg org-todo-keywords-1)))
10737 (error "State `%s' not valid in this file" arg))
10738 ((nth (1- (prefix-numeric-value arg))
10739 org-todo-keywords-1))))
10740 ((null member) (or head (car org-todo-keywords-1)))
10741 ((equal this final-done-word) nil) ;; -> make empty
10742 ((null tail) nil) ;; -> first entry
10743 ((memq interpret '(type priority))
10744 (if (eq this-command last-command)
10746 (if (> (length tail) 0)
10747 (or done-word (car org-done-keywords))
10752 (run-hook-with-args-until-success
10753 'org-todo-get-default-hook state last-state)
10755 (next (if state (concat " " state " ") " "))
10756 (change-plist (list :type 'todo-state-change :from this :to state
10757 :position startpos))
10759 (when org-blocker-hook
10760 (setq org-last-todo-state-is-todo
10761 (not (member this org-done-keywords)))
10762 (unless (save-excursion
10764 (run-hook-with-args-until-failure
10765 'org-blocker-hook change-plist)))
10766 (if (interactive-p)
10767 (error "TODO state change from %s to %s blocked" this state)
10769 (message "TODO state change from %s to %s blocked" this state)
10770 (throw 'exit nil))))
10771 (store-match-data match-data)
10772 (replace-match next t t)
10773 (unless (pos-visible-in-window-p hl-pos)
10774 (message "TODO state changed to %s" (org-trim next)))
10776 (setq head (org-get-todo-sequence-head state)
10777 ass (assoc head org-todo-kwd-alist)
10778 interpret (nth 1 ass)
10779 done-word (nth 3 ass)
10780 final-done-word (nth 4 ass)))
10781 (when (memq arg '(nextset previousset))
10782 (message "Keyword-Set %d/%d: %s"
10783 (- (length org-todo-sets) -1
10784 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10785 (length org-todo-sets)
10786 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10787 (setq org-last-todo-state-is-todo
10788 (not (member state org-done-keywords)))
10789 (setq now-done-p (and (member state org-done-keywords)
10790 (not (member this org-done-keywords))))
10791 (and logging (org-local-logging logging))
10792 (when (and (or org-todo-log-states org-log-done)
10793 (not (eq org-inhibit-logging t))
10794 (not (memq arg '(nextset previousset))))
10795 ;; we need to look at recording a time and note
10796 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10797 (nth 2 (assoc this org-todo-log-states))))
10798 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10799 (setq dolog 'time))
10801 (member state org-not-done-keywords)
10802 (not (member this org-not-done-keywords)))
10803 ;; This is now a todo state and was not one before
10804 ;; If there was a CLOSED time stamp, get rid of it.
10805 (org-add-planning-info nil nil 'closed))
10806 (when (and now-done-p org-log-done)
10807 ;; It is now done, and it was not done before
10808 (org-add-planning-info 'closed (org-current-time))
10809 (if (and (not dolog) (eq 'note org-log-done))
10810 (org-add-log-setup 'done state this 'findpos 'note)))
10811 (when (and state dolog)
10812 ;; This is a non-nil state, and we need to log it
10813 (org-add-log-setup 'state state this 'findpos dolog)))
10814 ;; Fixup tag positioning
10815 (org-todo-trigger-tag-changes state)
10816 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10817 (when org-provide-todo-statistics
10818 (org-update-parent-todo-statistics))
10819 (run-hooks 'org-after-todo-state-change-hook)
10820 (if (and arg (not (member state org-done-keywords)))
10821 (setq head (org-get-todo-sequence-head state)))
10822 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10823 ;; Do we need to trigger a repeat?
10825 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10826 ;; This is for the agenda, take a snapshot of the headline.
10828 (setq org-agenda-headline-snapshot-before-repeat
10829 (org-get-heading))))
10830 (org-auto-repeat-maybe state))
10831 ;; Fixup cursor location if close to the keyword
10832 (if (and (outline-on-heading-p)
10834 (save-excursion (beginning-of-line 1)
10835 (looking-at org-todo-line-regexp))
10836 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10838 (goto-char (or (match-end 2) (match-end 1)))
10839 (and (looking-at " ") (just-one-space))))
10840 (when org-trigger-hook
10842 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10844 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10845 "Block turning an entry into a TODO, using the hierarchy.
10846 This checks whether the current task should be blocked from state
10847 changes. Such blocking occurs when:
10849 1. The task has children which are not all in a completed state.
10851 2. A task has a parent with the property :ORDERED:, and there
10852 are siblings prior to the current task with incomplete
10855 3. The parent of the task is blocked because it has siblings that should
10856 be done first, or is child of a block grandparent TODO entry."
10858 (if (not org-enforce-todo-dependencies)
10859 t ; if locally turned off don't block
10861 ;; If this is not a todo state change, or if this entry is already DONE,
10863 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10864 (member (plist-get change-plist :from)
10865 (cons 'done org-done-keywords))
10866 (member (plist-get change-plist :to)
10867 (cons 'todo org-not-done-keywords))
10868 (not (plist-get change-plist :to)))
10869 (throw 'dont-block t))
10870 ;; If this task has children, and any are undone, it's blocked
10872 (org-back-to-heading t)
10873 (let ((this-level (funcall outline-level)))
10874 (outline-next-heading)
10875 (let ((child-level (funcall outline-level)))
10876 (while (and (not (eobp))
10877 (> child-level this-level))
10878 ;; this todo has children, check whether they are all
10880 (if (and (not (org-entry-is-done-p))
10881 (org-entry-is-todo-p))
10882 (throw 'dont-block nil))
10883 (outline-next-heading)
10884 (setq child-level (funcall outline-level))))))
10885 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10886 ;; any previous siblings are undone, it's blocked
10888 (org-back-to-heading t)
10889 (let* ((pos (point))
10890 (parent-pos (and (org-up-heading-safe) (point))))
10891 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10892 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10894 (re-search-forward org-not-done-heading-regexp pos t))
10895 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10896 ;; Search further up the hierarchy, to see if an anchestor is blocked
10898 (goto-char parent-pos)
10899 (if (not (looking-at org-not-done-heading-regexp))
10900 (throw 'dont-block t)) ; do not block, parent is not a TODO
10902 (setq parent-pos (and (org-up-heading-safe) (point)))
10903 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10904 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10906 (re-search-forward org-not-done-heading-regexp pos t))
10907 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10909 (defcustom org-track-ordered-property-with-tag nil
10910 "Should the ORDERED property also be shown as a tag?
10911 The ORDERED property decides if an entry should require subtasks to be
10912 completed in sequence. Since a property is not very visible, setting
10913 this option means that toggling the ORDERED property with the command
10914 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10915 not relevant for the behavior, but it makes things more visible.
10917 Note that toggling the tag with tags commands will not change the property
10918 and therefore not influence behavior!
10920 This can be t, meaning the tag ORDERED should be used, It can also be a
10921 string to select a different tag for this task."
10924 (const :tag "No tracking" nil)
10925 (const :tag "Track with ORDERED tag" t)
10926 (string :tag "Use other tag")))
10928 (defun org-toggle-ordered-property ()
10929 "Toggle the ORDERED property of the current entry.
10930 For better visibility, you can track the value of this property with a tag.
10931 See variable `org-track-ordered-property-with-tag'."
10933 (let* ((t1 org-track-ordered-property-with-tag)
10934 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10936 (org-back-to-heading)
10937 (if (org-entry-get nil "ORDERED")
10939 (org-delete-property "ORDERED")
10940 (and tag (org-toggle-tag tag 'off))
10941 (message "Subtasks can be completed in arbitrary order"))
10942 (org-entry-put nil "ORDERED" "t")
10943 (and tag (org-toggle-tag tag 'on))
10944 (message "Subtasks must be completed in sequence")))))
10946 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10947 (defun org-block-todo-from-checkboxes (change-plist)
10948 "Block turning an entry into a TODO, using checkboxes.
10949 This checks whether the current task should be blocked from state
10950 changes because there are unchecked boxes in this entry."
10951 (if (not org-enforce-todo-checkbox-dependencies)
10952 t ; if locally turned off don't block
10954 ;; If this is not a todo state change, or if this entry is already DONE,
10956 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10957 (member (plist-get change-plist :from)
10958 (cons 'done org-done-keywords))
10959 (member (plist-get change-plist :to)
10960 (cons 'todo org-not-done-keywords))
10961 (not (plist-get change-plist :to)))
10962 (throw 'dont-block t))
10963 ;; If this task has checkboxes that are not checked, it's blocked
10965 (org-back-to-heading t)
10966 (let ((beg (point)) end)
10967 (outline-next-heading)
10970 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10973 (if (boundp 'org-blocked-by-checkboxes)
10974 (setq org-blocked-by-checkboxes t))
10975 (throw 'dont-block nil)))))
10976 t))) ; do not block
10978 (defun org-entry-blocked-p ()
10979 "Is the current entry blocked?"
10980 (if (org-entry-get nil "NOBLOCKING")
10981 nil ;; Never block this entry
10983 (run-hook-with-args-until-failure
10985 (list :type 'todo-state-change
10990 (defun org-update-statistics-cookies (all)
10991 "Update the statistics cookie, either from TODO or from checkboxes.
10992 This should be called with the cursor in a line with a statistics cookie."
10996 (org-update-checkbox-count 'all)
10997 (org-map-entries 'org-update-parent-todo-statistics))
10998 (if (not (org-on-heading-p))
10999 (org-update-checkbox-count)
11000 (let ((pos (move-marker (make-marker) (point)))
11002 (ignore-errors (org-back-to-heading t))
11003 (if (not (org-on-heading-p))
11004 (org-update-checkbox-count)
11005 (setq l1 (org-outline-level))
11006 (setq end (save-excursion
11007 (outline-next-heading)
11008 (if (org-on-heading-p) (setq l2 (org-outline-level)))
11010 (if (and (save-excursion
11012 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11013 (not (save-excursion (re-search-forward
11014 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11015 (org-update-checkbox-count)
11016 (if (and l2 (> l2 l1))
11019 (org-update-parent-todo-statistics))
11021 (beginning-of-line 1)
11022 (while (re-search-forward
11023 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11025 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11027 (move-marker pos nil)))))
11029 (defvar org-entry-property-inherited-from) ;; defined below
11030 (defun org-update-parent-todo-statistics ()
11031 "Update any statistics cookie in the parent of the current headline.
11032 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11033 the entire subtree and this will travel up the hierarchy and update
11034 statistics everywhere."
11036 (let* ((lim 0) prop
11037 (recursive (or (not org-hierarchical-todo-statistics)
11040 (or (setq prop (org-entry-get
11041 nil "COOKIE_DATA" 'inherit)) ""))))
11042 (lim (or (and prop (marker-position
11043 org-entry-property-inherited-from))
11046 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11047 level ltoggle l1 new ndel
11048 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
11051 (beginning-of-line 1)
11052 (if (org-at-heading-p)
11053 (setq ltoggle (funcall outline-level))
11054 (error "This should not happen"))
11055 (while (and (setq level (org-up-heading-safe))
11056 (or recursive first)
11058 (setq first nil cookie-present nil)
11067 (while (re-search-forward box-re (point-at-eol) t)
11068 (setq cnt-all 0 cnt-done 0 cookie-present t)
11069 (setq is-percent (match-end 2))
11071 (unless (outline-next-heading) (throw 'exit nil))
11072 (while (and (looking-at org-complex-heading-regexp)
11073 (> (setq l1 (length (match-string 1))) level))
11074 (setq kwd (and (or recursive (= l1 ltoggle))
11076 (if (or (eq org-provide-todo-statistics 'all-headlines)
11077 (and (listp org-provide-todo-statistics)
11078 (or (member kwd org-provide-todo-statistics)
11079 (member kwd org-done-keywords))))
11080 (setq cnt-all (1+ cnt-all))
11081 (if (eq org-provide-todo-statistics t)
11082 (and kwd (setq cnt-all (1+ cnt-all)))))
11083 (and (member kwd org-done-keywords)
11084 (setq cnt-done (1+ cnt-done)))
11085 (outline-next-heading)))
11088 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
11089 (format "[%d/%d]" cnt-done cnt-all))
11090 ndel (- (match-end 0) (match-beginning 0)))
11091 (goto-char (match-beginning 0))
11093 (delete-region (point) (+ (point) ndel)))
11094 (when cookie-present
11095 (run-hook-with-args 'org-after-todo-statistics-hook
11096 cnt-done (- cnt-all cnt-done))))))
11097 (run-hooks 'org-todo-statistics-hook)))
11099 (defvar org-after-todo-statistics-hook nil
11100 "Hook that is called after a TODO statistics cookie has been updated.
11101 Each function is called with two arguments: the number of not-done entries
11102 and the number of done entries.
11104 For example, the following function, when added to this hook, will switch
11105 an entry to DONE when all children are done, and back to TODO when new
11106 entries are set to a TODO status. Note that this hook is only called
11107 when there is a statistics cookie in the headline!
11109 (defun org-summary-todo (n-done n-not-done)
11110 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
11111 (let (org-log-done org-log-states) ; turn off logging
11112 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
11115 (defvar org-todo-statistics-hook nil
11116 "Hook that is run whenever Org thinks TODO statistics should be updated.
11117 This hook runs even if there is no statistics cookie present, in which case
11118 `org-after-todo-statistics-hook' would not run.")
11120 (defun org-todo-trigger-tag-changes (state)
11121 "Apply the changes defined in `org-todo-state-tags-triggers'."
11122 (let ((l org-todo-state-tags-triggers)
11124 (when (or (not state) (equal state ""))
11125 (setq changes (append changes (cdr (assoc "" l)))))
11126 (when (and (stringp state) (> (length state) 0))
11127 (setq changes (append changes (cdr (assoc state l)))))
11128 (when (member state org-not-done-keywords)
11129 (setq changes (append changes (cdr (assoc 'todo l)))))
11130 (when (member state org-done-keywords)
11131 (setq changes (append changes (cdr (assoc 'done l)))))
11132 (dolist (c changes)
11133 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
11135 (defun org-local-logging (value)
11136 "Get logging settings from a property VALUE."
11138 ;; directly set the variables, they are already local.
11139 (setq org-log-done nil
11141 org-todo-log-states nil)
11142 (setq words (org-split-string value))
11143 (while (setq w (pop words))
11145 ((setq a (assoc w org-startup-options))
11146 (and (member (nth 1 a) '(org-log-done org-log-repeat))
11147 (set (nth 1 a) (nth 2 a))))
11148 ((setq a (org-extract-log-state-settings w))
11149 (and (member (car a) org-todo-keywords-1)
11150 (push a org-todo-log-states)))))))
11152 (defun org-get-todo-sequence-head (kwd)
11153 "Return the head of the TODO sequence to which KWD belongs.
11154 If KWD is not set, check if there is a text property remembering the
11159 (or (get-text-property (point-at-bol) 'org-todo-head)
11161 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
11162 nil (point-at-eol)))
11163 (get-text-property p 'org-todo-head))))
11164 ((not (member kwd org-todo-keywords-1))
11165 (car org-todo-keywords-1))
11166 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
11168 (defun org-fast-todo-selection ()
11169 "Fast TODO keyword selection with single keys.
11170 Returns the new TODO keyword, or nil if no state change should occur."
11171 (let* ((fulltable org-todo-key-alist)
11172 (done-keywords org-done-keywords) ;; needed for the faces.
11173 (maxlen (apply 'max (mapcar
11175 (if (stringp (car x)) (string-width (car x)) 0))
11178 (fwidth (+ maxlen 3 1 3))
11179 (ncol (/ (- (window-width) 4) fwidth))
11183 (save-window-excursion
11185 (set-buffer (get-buffer-create " *Org todo*"))
11186 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
11188 (org-set-local 'org-done-keywords done-keywords)
11189 (setq tbl fulltable cnt 0)
11190 (while (setq e (pop tbl))
11192 ((equal e '(:startgroup))
11193 (push '() groups) (setq ingroup t)
11194 (when (not (= cnt 0))
11198 ((equal e '(:endgroup))
11199 (setq ingroup nil cnt 0)
11201 ((equal e '(:newline))
11202 (when (not (= cnt 0))
11206 (while (equal (car tbl) '(:newline))
11208 (setq tbl (cdr tbl)))))
11210 (setq tg (car e) c (cdr e))
11211 (if ingroup (push tg (car groups)))
11212 (setq tg (org-add-props tg nil 'face
11213 (org-get-todo-face tg)))
11214 (if (and (= cnt 0) (not ingroup)) (insert " "))
11215 (insert "[" c "] " tg (make-string
11216 (- fwidth 4 (length tg)) ?\ ))
11217 (when (= (setq cnt (1+ cnt)) ncol)
11219 (if ingroup (insert " "))
11222 (goto-char (point-min))
11223 (if (not expert) (org-fit-window-to-buffer))
11224 (message "[a-z..]:Set [SPC]:clear")
11225 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
11228 (and (= c ?q) (not (rassoc c fulltable))))
11229 (setq quit-flag t))
11231 ((setq e (rassoc c fulltable) tg (car e))
11233 (t (setq quit-flag t)))))))
11235 (defun org-entry-is-todo-p ()
11236 (member (org-get-todo-state) org-not-done-keywords))
11238 (defun org-entry-is-done-p ()
11239 (member (org-get-todo-state) org-done-keywords))
11241 (defun org-get-todo-state ()
11243 (org-back-to-heading t)
11244 (and (looking-at org-todo-line-regexp)
11246 (match-string 2))))
11248 (defun org-at-date-range-p (&optional inactive-ok)
11249 "Is the cursor inside a date range?"
11253 (let ((pos (point)))
11254 (skip-chars-backward "^[<\r\n")
11255 (skip-chars-backward "<[")
11256 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11257 (>= (match-end 0) pos)
11259 (skip-chars-backward "^<[\r\n")
11260 (skip-chars-backward "<[")
11261 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11262 (>= (match-end 0) pos)
11266 (defun org-get-repeat (&optional tagline)
11267 "Check if there is a deadline/schedule with repeater in this entry."
11270 (org-back-to-heading t)
11271 (and (re-search-forward (if tagline
11272 (concat tagline "\\s-*" org-repeat-re)
11274 (org-entry-end-position) t)
11275 (match-string-no-properties 1)))))
11277 (defvar org-last-changed-timestamp)
11278 (defvar org-last-inserted-timestamp)
11279 (defvar org-log-post-message)
11280 (defvar org-log-note-purpose)
11281 (defvar org-log-note-how)
11282 (defvar org-log-note-extra)
11283 (defun org-auto-repeat-maybe (done-word)
11284 "Check if the current headline contains a repeated deadline/schedule.
11285 If yes, set TODO state back to what it was and change the base date
11286 of repeating deadline/scheduled time stamps to new date.
11287 This function is run automatically after each state change to a DONE state."
11288 ;; last-state is dynamically scoped into this function
11289 (let* ((repeat (org-get-repeat))
11290 (aa (assoc last-state org-todo-kwd-alist))
11291 (interpret (nth 1 aa))
11293 (whata '(("d" . day) ("m" . month) ("y" . year)))
11294 (msg "Entry repeats: ")
11296 (org-todo-log-states nil)
11297 (nshiftmax 10) (nshift 0)
11298 re type n what ts time to-state)
11300 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
11301 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
11302 org-todo-repeat-to-state))
11303 (unless (and to-state (member to-state org-todo-keywords-1))
11304 (setq to-state (if (eq interpret 'type) last-state head)))
11305 (org-todo to-state)
11306 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
11307 (org-entry-put nil "LAST_REPEAT" (format-time-string
11308 (org-time-stamp-format t t))))
11309 (when org-log-repeat
11310 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
11311 (memq 'org-add-log-note post-command-hook))
11312 ;; OK, we are already setup for some record
11313 (if (eq org-log-repeat 'note)
11314 ;; make sure we take a note, not only a time stamp
11315 (setq org-log-note-how 'note))
11316 ;; Set up for taking a record
11317 (org-add-log-setup 'state (or done-word (car org-done-keywords))
11319 'findpos org-log-repeat)))
11320 (org-back-to-heading t)
11321 (org-add-planning-info nil nil 'closed)
11322 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
11323 org-deadline-time-regexp "\\)\\|\\("
11324 org-ts-regexp "\\)"))
11325 (while (re-search-forward
11326 re (save-excursion (outline-next-heading) (point)) t)
11327 (setq type (if (match-end 1) org-scheduled-string
11328 (if (match-end 3) org-deadline-string "Plain:"))
11329 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
11330 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
11331 (setq n (string-to-number (match-string 2 ts))
11332 what (match-string 3 ts))
11333 (if (equal what "w") (setq n (* n 7) what "d"))
11334 ;; Preparation, see if we need to modify the start date for the change
11335 (when (match-end 1)
11336 (setq time (save-match-data (org-time-string-to-time ts)))
11338 ((equal (match-string 1 ts) ".")
11339 ;; Shift starting date to today
11340 (org-timestamp-change
11341 (- (time-to-days (current-time)) (time-to-days time))
11343 ((equal (match-string 1 ts) "+")
11344 (while (or (= nshift 0)
11345 (<= (time-to-days time) (time-to-days (current-time))))
11346 (when (= (incf nshift) nshiftmax)
11347 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
11349 (org-timestamp-change n (cdr (assoc what whata)))
11350 (org-at-timestamp-p t)
11351 (setq ts (match-string 1))
11352 (setq time (save-match-data (org-time-string-to-time ts))))
11353 (org-timestamp-change (- n) (cdr (assoc what whata)))
11354 ;; rematch, so that we have everything in place for the real shift
11355 (org-at-timestamp-p t)
11356 (setq ts (match-string 1))
11357 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
11358 (org-timestamp-change n (cdr (assoc what whata)))
11359 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
11360 (setq org-log-post-message msg)
11361 (message "%s" msg))))
11363 (defun org-show-todo-tree (arg)
11364 "Make a compact tree which shows all headlines marked with TODO.
11365 The tree will show the lines where the regexp matches, and all higher
11366 headlines above the match.
11367 With a \\[universal-argument] prefix, prompt for a regexp to match.
11368 With a numeric prefix N, construct a sparse tree for the Nth element
11369 of `org-todo-keywords-1'."
11371 (let ((case-fold-search nil)
11373 (cond ((null arg) org-not-done-regexp)
11375 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
11376 (mapcar 'list org-todo-keywords-1))))
11378 (mapconcat 'identity (org-split-string kwd "|") "\\|")
11380 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
11381 (regexp-quote (nth (1- (prefix-numeric-value arg))
11382 org-todo-keywords-1)))
11383 (t (error "Invalid prefix argument: %s" arg)))))
11384 (message "%d TODO entries found"
11385 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
11387 (defun org-deadline (&optional remove time)
11388 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
11389 With argument REMOVE, remove any deadline from the item.
11390 When TIME is set, it should be an internal time specification, and the
11391 scheduling will use the corresponding date."
11393 (let* ((old-date (org-entry-get nil "DEADLINE"))
11394 (repeater (and old-date
11395 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11396 (match-string 1 old-date))))
11399 (when (and old-date org-log-redeadline)
11400 (org-add-log-setup 'deldeadline nil old-date 'findpos
11401 org-log-redeadline))
11402 (org-remove-timestamp-with-keyword org-deadline-string)
11403 (message "Item no longer has a deadline."))
11404 (org-add-planning-info 'deadline time 'closed)
11405 (when (and old-date org-log-redeadline
11406 (not (equal old-date
11407 (substring org-last-inserted-timestamp 1 -1))))
11408 (org-add-log-setup 'redeadline nil old-date 'findpos
11409 org-log-redeadline))
11412 (org-back-to-heading t)
11413 (when (re-search-forward (concat org-deadline-string " "
11414 org-last-inserted-timestamp)
11416 (outline-next-heading) (point)) t)
11417 (goto-char (1- (match-end 0)))
11418 (insert " " repeater)
11419 (setq org-last-inserted-timestamp
11420 (concat (substring org-last-inserted-timestamp 0 -1)
11422 (substring org-last-inserted-timestamp -1))))))
11423 (message "Deadline on %s" org-last-inserted-timestamp))))
11425 (defun org-schedule (&optional remove time)
11426 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11427 With argument REMOVE, remove any scheduling date from the item.
11428 When TIME is set, it should be an internal time specification, and the
11429 scheduling will use the corresponding date."
11431 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11432 (repeater (and old-date
11433 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11434 (match-string 1 old-date))))
11437 (when (and old-date org-log-reschedule)
11438 (org-add-log-setup 'delschedule nil old-date 'findpos
11439 org-log-reschedule))
11440 (org-remove-timestamp-with-keyword org-scheduled-string)
11441 (message "Item is no longer scheduled."))
11442 (org-add-planning-info 'scheduled time 'closed)
11443 (when (and old-date org-log-reschedule
11444 (not (equal old-date
11445 (substring org-last-inserted-timestamp 1 -1))))
11446 (org-add-log-setup 'reschedule nil old-date 'findpos
11447 org-log-reschedule))
11450 (org-back-to-heading t)
11451 (when (re-search-forward (concat org-scheduled-string " "
11452 org-last-inserted-timestamp)
11454 (outline-next-heading) (point)) t)
11455 (goto-char (1- (match-end 0)))
11456 (insert " " repeater)
11457 (setq org-last-inserted-timestamp
11458 (concat (substring org-last-inserted-timestamp 0 -1)
11460 (substring org-last-inserted-timestamp -1))))))
11461 (message "Scheduled to %s" org-last-inserted-timestamp))))
11463 (defun org-get-scheduled-time (pom &optional inherit)
11464 "Get the scheduled time as a time tuple, of a format suitable
11465 for calling org-schedule with, or if there is no scheduling,
11467 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11469 (apply 'encode-time (org-parse-time-string time)))))
11471 (defun org-get-deadline-time (pom &optional inherit)
11472 "Get the deadine as a time tuple, of a format suitable for
11473 calling org-deadline with, or if there is no scheduling, returns
11475 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11477 (apply 'encode-time (org-parse-time-string time)))))
11479 (defun org-remove-timestamp-with-keyword (keyword)
11480 "Remove all time stamps with KEYWORD in the current entry."
11481 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11484 (org-back-to-heading t)
11486 (outline-next-heading)
11487 (while (re-search-backward re beg t)
11489 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11490 (equal (char-before) ?\ ))
11491 (backward-delete-char 1)
11492 (if (string-match "^[ \t]*$" (buffer-substring
11493 (point-at-bol) (point-at-eol)))
11494 (delete-region (point-at-bol)
11495 (min (point-max) (1+ (point-at-eol))))))))))
11497 (defun org-add-planning-info (what &optional time &rest remove)
11498 "Insert new timestamp with keyword in the line directly after the headline.
11499 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11500 If non is given, the user is prompted for a date.
11501 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11504 (let (org-time-was-given org-end-time-was-given ts
11505 end default-time default-input)
11508 (when (and (not time) (memq what '(scheduled deadline)))
11509 ;; Try to get a default date/time from existing timestamp
11511 (org-back-to-heading t)
11512 (setq end (save-excursion (outline-next-heading) (point)))
11513 (when (re-search-forward (if (eq what 'scheduled)
11514 org-scheduled-time-regexp
11515 org-deadline-time-regexp)
11517 (setq ts (match-string 1)
11519 (apply 'encode-time (org-parse-time-string ts))
11520 default-input (and ts (org-get-compact-tod ts))))))
11522 ;; If necessary, get the time from the user
11523 (setq time (or time (org-read-date nil 'to-time nil nil
11524 default-time default-input))))
11526 (when (and org-insert-labeled-timestamps-at-point
11527 (member what '(scheduled deadline)))
11529 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11530 (org-insert-time-stamp time org-time-was-given
11531 nil nil nil (list org-end-time-was-given))
11535 (let (col list elt ts buffer-invisibility-spec)
11536 (org-back-to-heading t)
11537 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11538 (goto-char (match-end 1))
11539 (setq col (current-column))
11540 (goto-char (match-end 0))
11541 (if (eobp) (insert "\n") (forward-char 1))
11542 (when (and (not what)
11545 org-keyword-time-not-clock-regexp))))
11546 ;; Nothing to add, nothing to remove...... :-)
11548 (if (and (not (looking-at outline-regexp))
11549 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11551 (not (equal (match-string 1) org-clock-string)))
11552 (narrow-to-region (match-beginning 0) (match-end 0))
11553 (insert-before-markers "\n")
11555 (narrow-to-region (point) (point))
11556 (and org-adapt-indentation (org-indent-to-column col)))
11557 ;; Check if we have to remove something.
11558 (setq list (cons what remove))
11560 (setq elt (pop list))
11561 (goto-char (point-min))
11562 (when (or (and (eq elt 'scheduled)
11563 (re-search-forward org-scheduled-time-regexp nil t))
11564 (and (eq elt 'deadline)
11565 (re-search-forward org-deadline-time-regexp nil t))
11566 (and (eq elt 'closed)
11567 (re-search-forward org-closed-time-regexp nil t)))
11569 (if (looking-at "--+<[^>]+>") (replace-match ""))
11570 (skip-chars-backward " ")
11571 (if (looking-at " +") (replace-match ""))))
11572 (goto-char (point-max))
11573 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11576 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11577 (cond ((eq what 'scheduled) org-scheduled-string)
11578 ((eq what 'deadline) org-deadline-string)
11579 ((eq what 'closed) org-closed-string))
11581 (setq ts (org-insert-time-stamp
11583 (or org-time-was-given
11584 (and (eq what 'closed) org-log-done-with-time))
11586 nil nil (list org-end-time-was-given)))
11588 (goto-char (point-min))
11590 (if (and (looking-at "[ \t]*\n")
11591 (equal (char-before) ?\n))
11592 (delete-region (1- (point)) (point-at-eol)))
11595 (defvar org-log-note-marker (make-marker))
11596 (defvar org-log-note-purpose nil)
11597 (defvar org-log-note-state nil)
11598 (defvar org-log-note-previous-state nil)
11599 (defvar org-log-note-how nil)
11600 (defvar org-log-note-extra nil)
11601 (defvar org-log-note-window-configuration nil)
11602 (defvar org-log-note-return-to (make-marker))
11603 (defvar org-log-post-message nil
11604 "Message to be displayed after a log note has been stored.
11605 The auto-repeater uses this.")
11607 (defun org-add-note ()
11608 "Add a note to the current entry.
11609 This is done in the same way as adding a state change note."
11611 (org-add-log-setup 'note nil nil 'findpos nil))
11613 (defvar org-property-end-re)
11614 (defun org-add-log-setup (&optional purpose state prev-state
11615 findpos how &optional extra)
11616 "Set up the post command hook to take a note.
11617 If this is about to TODO state change, the new state is expected in STATE.
11618 When FINDPOS is non-nil, find the correct position for the note in
11619 the current entry. If not, assume that it can be inserted at point.
11620 HOW is an indicator what kind of note should be created.
11621 EXTRA is additional text that will be inserted into the notes buffer."
11622 (let* ((org-log-into-drawer (org-log-into-drawer))
11623 (drawer (cond ((stringp org-log-into-drawer)
11624 org-log-into-drawer)
11625 (org-log-into-drawer "LOGBOOK")
11630 (org-back-to-heading t)
11631 (narrow-to-region (point) (save-excursion
11632 (outline-next-heading) (point)))
11633 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11634 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11636 (goto-char (match-end 0))
11639 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11642 (goto-char (match-end 0))
11643 (or org-log-states-order-reversed
11644 (and (re-search-forward org-property-end-re nil t)
11645 (goto-char (1- (match-beginning 0))))))
11646 (insert "\n:" drawer ":\n:END:")
11647 (beginning-of-line 0)
11648 (org-indent-line-function)
11649 (beginning-of-line 2)
11650 (org-indent-line-function)
11652 ((and org-log-state-notes-insert-after-drawers
11654 (forward-line) (looking-at org-drawer-regexp)))
11656 (while (looking-at org-drawer-regexp)
11657 (goto-char (match-end 0))
11658 (re-search-forward org-property-end-re (point-max) t)
11660 (forward-line -1)))
11661 (unless org-log-states-order-reversed
11662 (and (= (char-after) ?\n) (forward-char 1))
11663 (org-skip-over-state-notes)
11664 (skip-chars-backward " \t\n\r")))
11665 (move-marker org-log-note-marker (point))
11666 (setq org-log-note-purpose purpose
11667 org-log-note-state state
11668 org-log-note-previous-state prev-state
11669 org-log-note-how how
11670 org-log-note-extra extra)
11671 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11673 (defun org-skip-over-state-notes ()
11674 "Skip past the list of State notes in an entry."
11675 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11676 (while (looking-at "[ \t]*- State")
11677 (condition-case nil
11679 (error (org-end-of-item)))))
11681 (defun org-add-log-note (&optional purpose)
11682 "Pop up a window for taking a note, and add this note later at point."
11683 (remove-hook 'post-command-hook 'org-add-log-note)
11684 (setq org-log-note-window-configuration (current-window-configuration))
11685 (delete-other-windows)
11686 (move-marker org-log-note-return-to (point))
11687 (switch-to-buffer (marker-buffer org-log-note-marker))
11688 (goto-char org-log-note-marker)
11689 (org-switch-to-buffer-other-window "*Org Note*")
11691 (if (memq org-log-note-how '(time state))
11692 (let (current-prefix-arg) (org-store-log-note))
11693 (let ((org-inhibit-startup t)) (org-mode))
11694 (insert (format "# Insert note for %s.
11695 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11697 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11698 ((eq org-log-note-purpose 'done) "closed todo item")
11699 ((eq org-log-note-purpose 'state)
11700 (format "state change from \"%s\" to \"%s\""
11701 (or org-log-note-previous-state "")
11702 (or org-log-note-state "")))
11703 ((eq org-log-note-purpose 'reschedule)
11705 ((eq org-log-note-purpose 'delschedule)
11706 "no longer scheduled")
11707 ((eq org-log-note-purpose 'redeadline)
11708 "changing deadline")
11709 ((eq org-log-note-purpose 'deldeadline)
11710 "removing deadline")
11711 ((eq org-log-note-purpose 'refile)
11713 ((eq org-log-note-purpose 'note)
11715 (t (error "This should not happen")))))
11716 (if org-log-note-extra (insert org-log-note-extra))
11717 (org-set-local 'org-finish-function 'org-store-log-note)))
11719 (defvar org-note-abort nil) ; dynamically scoped
11720 (defun org-store-log-note ()
11721 "Finish taking a log note, and insert it to where it belongs."
11722 (let ((txt (buffer-string))
11723 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11725 (kill-buffer (current-buffer))
11726 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11727 (setq txt (replace-match "" t t txt)))
11728 (if (string-match "\\s-+\\'" txt)
11729 (setq txt (replace-match "" t t txt)))
11730 (setq lines (org-split-string txt "\n"))
11731 (when (and note (string-match "\\S-" note))
11733 (org-replace-escapes
11735 (list (cons "%u" (user-login-name))
11736 (cons "%U" user-full-name)
11737 (cons "%t" (format-time-string
11738 (org-time-stamp-format 'long 'inactive)
11740 (cons "%T" (format-time-string
11741 (org-time-stamp-format 'long nil)
11743 (cons "%s" (if org-log-note-state
11744 (concat "\"" org-log-note-state "\"")
11746 (cons "%S" (if org-log-note-previous-state
11747 (concat "\"" org-log-note-previous-state "\"")
11749 (if lines (setq note (concat note " \\\\")))
11751 (when (or current-prefix-arg org-note-abort)
11752 (when org-log-into-drawer
11753 (org-remove-empty-drawer-at
11754 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11755 org-log-note-marker))
11758 (with-current-buffer (marker-buffer org-log-note-marker)
11760 (goto-char org-log-note-marker)
11761 (move-marker org-log-note-marker nil)
11763 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11764 (insert "- " (pop lines))
11765 (org-indent-line-function)
11766 (beginning-of-line 1)
11767 (looking-at "[ \t]*")
11768 (setq ind (concat (match-string 0) " "))
11770 (while lines (insert "\n" ind (pop lines)))
11771 (message "Note stored")
11772 (org-back-to-heading t)
11773 (org-cycle-hide-drawers 'children)))))
11774 (set-window-configuration org-log-note-window-configuration)
11775 (with-current-buffer (marker-buffer org-log-note-return-to)
11776 (goto-char org-log-note-return-to))
11777 (move-marker org-log-note-return-to nil)
11778 (and org-log-post-message (message "%s" org-log-post-message)))
11780 (defun org-remove-empty-drawer-at (drawer pos)
11781 "Remove an empty drawer DRAWER at position POS.
11782 POS may also be a marker."
11783 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11789 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11790 (replace-match ""))))))
11792 (defun org-sparse-tree (&optional arg)
11793 "Create a sparse tree, prompt for the details.
11794 This command can create sparse trees. You first need to select the type
11795 of match used to create the tree:
11797 t Show all TODO entries.
11798 T Show entries with a specific TODO keyword.
11799 m Show entries selected by a tags/property match.
11800 p Enter a property name and its value (both with completion on existing
11801 names/values) and show entries with that property.
11802 / Show entries matching a regular expression (`r' can be used as well)
11803 d Show deadlines due within `org-deadline-warning-days'.
11804 b Show deadlines and scheduled items before a date.
11805 a Show deadlines and scheduled items after a date."
11807 (let (ans kwd value)
11808 (message "Sparse tree: [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty [d]eadlines\n [b]efore-date [a]fter-date")
11809 (setq ans (read-char-exclusive))
11812 (call-interactively 'org-check-deadlines))
11814 (call-interactively 'org-check-before-date))
11816 (call-interactively 'org-check-after-date))
11818 (org-show-todo-tree nil))
11820 (org-show-todo-tree '(4)))
11821 ((member ans '(?T ?m))
11822 (call-interactively 'org-match-sparse-tree))
11823 ((member ans '(?p ?P))
11824 (setq kwd (org-icompleting-read "Property: "
11825 (mapcar 'list (org-buffer-property-keys))))
11826 (setq value (org-icompleting-read "Value: "
11827 (mapcar 'list (org-property-values kwd))))
11828 (unless (string-match "\\`{.*}\\'" value)
11829 (setq value (concat "\"" value "\"")))
11830 (org-match-sparse-tree arg (concat kwd "=" value)))
11831 ((member ans '(?r ?R ?/))
11832 (call-interactively 'org-occur))
11833 (t (error "No such sparse tree command \"%c\"" ans)))))
11835 (defvar org-occur-highlights nil
11836 "List of overlays used for occur matches.")
11837 (make-variable-buffer-local 'org-occur-highlights)
11838 (defvar org-occur-parameters nil
11839 "Parameters of the active org-occur calls.
11840 This is a list, each call to org-occur pushes as cons cell,
11841 containing the regular expression and the callback, onto the list.
11842 The list can contain several entries if `org-occur' has been called
11843 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11844 will only contain one set of parameters. When the highlights are
11845 removed (for example with `C-c C-c', or with the next edit (depending
11846 on `org-remove-highlights-with-change'), this variable is emptied
11848 (make-variable-buffer-local 'org-occur-parameters)
11850 (defun org-occur (regexp &optional keep-previous callback)
11851 "Make a compact tree which shows all matches of REGEXP.
11852 The tree will show the lines where the regexp matches, and all higher
11853 headlines above the match. It will also show the heading after the match,
11854 to make sure editing the matching entry is easy.
11855 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11856 call to `org-occur' will be kept, to allow stacking of calls to this
11858 If CALLBACK is non-nil, it is a function which is called to confirm
11859 that the match should indeed be shown."
11860 (interactive "sRegexp: \nP")
11861 (when (equal regexp "")
11862 (error "Regexp cannot be empty"))
11863 (unless keep-previous
11864 (org-remove-occur-highlights nil nil t))
11865 (push (cons regexp callback) org-occur-parameters)
11868 (goto-char (point-min))
11869 (if (or (not keep-previous) ; do not want to keep
11870 (not org-occur-highlights)) ; no previous matches
11873 (while (re-search-forward regexp nil t)
11874 (when (or (not callback)
11875 (save-match-data (funcall callback)))
11876 (setq cnt (1+ cnt))
11877 (when org-highlight-sparse-tree-matches
11878 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11879 (org-show-context 'occur-tree))))
11880 (when org-remove-highlights-with-change
11881 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11883 (unless org-sparse-tree-open-archived-trees
11884 (org-hide-archived-subtrees (point-min) (point-max)))
11885 (run-hooks 'org-occur-hook)
11886 (if (interactive-p)
11887 (message "%d match(es) for regexp %s" cnt regexp))
11890 (defun org-show-context (&optional key)
11891 "Make sure point and context are visible.
11892 How much context is shown depends upon the variables
11893 `org-show-hierarchy-above', `org-show-following-heading'. and
11894 `org-show-siblings'."
11895 (let ((heading-p (org-on-heading-p t))
11896 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11897 (following-p (org-get-alist-option org-show-following-heading key))
11898 (entry-p (org-get-alist-option org-show-entry-below key))
11899 (siblings-p (org-get-alist-option org-show-siblings key)))
11901 ;; Show heading or entry text
11902 (if (and heading-p (not entry-p))
11903 (org-flag-heading nil) ; only show the heading
11904 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11905 (org-show-hidden-entry))) ; show entire entry
11907 ;; Show next sibling, or heading below text
11909 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11910 (org-flag-heading nil))))
11911 (when siblings-p (org-show-siblings))
11913 ;; show all higher headings, possibly with siblings
11915 (while (and (condition-case nil
11916 (progn (org-up-heading-all 1) t)
11919 (org-flag-heading nil)
11920 (when siblings-p (org-show-siblings))))))))
11922 (defvar org-reveal-start-hook nil
11923 "Hook run before revealing a location.")
11925 (defun org-reveal (&optional siblings)
11926 "Show current entry, hierarchy above it, and the following headline.
11927 This can be used to show a consistent set of context around locations
11928 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11929 not t for the search context.
11931 With optional argument SIBLINGS, on each level of the hierarchy all
11932 siblings are shown. This repairs the tree structure to what it would
11933 look like when opened with hierarchical calls to `org-cycle'.
11934 With double optional argument `C-u C-u', go to the parent and show the
11937 (run-hooks 'org-reveal-start-hook)
11938 (let ((org-show-hierarchy-above t)
11939 (org-show-following-heading t)
11940 (org-show-siblings (if siblings t org-show-siblings)))
11941 (org-show-context nil))
11942 (when (equal siblings '(16))
11944 (when (org-up-heading-safe)
11946 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11948 (defun org-highlight-new-match (beg end)
11949 "Highlight from BEG to END and mark the highlight is an occur headline."
11950 (let ((ov (make-overlay beg end)))
11951 (overlay-put ov 'face 'secondary-selection)
11952 (push ov org-occur-highlights)))
11954 (defun org-remove-occur-highlights (&optional beg end noremove)
11955 "Remove the occur highlights from the buffer.
11956 BEG and END are ignored. If NOREMOVE is nil, remove this function
11957 from the `before-change-functions' in the current buffer."
11959 (unless org-inhibit-highlight-removal
11960 (mapc 'delete-overlay org-occur-highlights)
11961 (setq org-occur-highlights nil)
11962 (setq org-occur-parameters nil)
11964 (remove-hook 'before-change-functions
11965 'org-remove-occur-highlights 'local))))
11969 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11970 "Regular expression matching the priority indicator.")
11972 (defvar org-remove-priority-next-time nil)
11974 (defun org-priority-up ()
11975 "Increase the priority of the current item."
11977 (org-priority 'up))
11979 (defun org-priority-down ()
11980 "Decrease the priority of the current item."
11982 (org-priority 'down))
11984 (defun org-priority (&optional action)
11985 "Change the priority of an item by ARG.
11986 ACTION can be `set', `up', `down', or a character."
11988 (unless org-enable-priority-commands
11989 (error "Priority commands are disabled"))
11990 (setq action (or action 'set))
11991 (let (current new news have remove)
11993 (org-back-to-heading t)
11994 (if (looking-at org-priority-regexp)
11995 (setq current (string-to-char (match-string 2))
11997 (setq current org-default-priority))
11999 ((eq action 'remove)
12000 (setq remove t new ?\ ))
12001 ((or (eq action 'set)
12002 (if (featurep 'xemacs) (characterp action) (integerp action)))
12003 (if (not (eq action 'set))
12005 (message "Priority %c-%c, SPC to remove: "
12006 org-highest-priority org-lowest-priority)
12007 (setq new (read-char-exclusive)))
12008 (if (and (= (upcase org-highest-priority) org-highest-priority)
12009 (= (upcase org-lowest-priority) org-lowest-priority))
12010 (setq new (upcase new)))
12011 (cond ((equal new ?\ ) (setq remove t))
12012 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
12013 (error "Priority must be between `%c' and `%c'"
12014 org-highest-priority org-lowest-priority))))
12016 (if (and (not have) (eq last-command this-command))
12017 (setq new org-lowest-priority)
12018 (setq new (if (and org-priority-start-cycle-with-default (not have))
12019 org-default-priority (1- current)))))
12021 (if (and (not have) (eq last-command this-command))
12022 (setq new org-highest-priority)
12023 (setq new (if (and org-priority-start-cycle-with-default (not have))
12024 org-default-priority (1+ current)))))
12025 (t (error "Invalid action")))
12026 (if (or (< (upcase new) org-highest-priority)
12027 (> (upcase new) org-lowest-priority))
12029 (setq news (format "%c" new))
12032 (replace-match "" t t nil 1)
12033 (replace-match news t t nil 2))
12035 (error "No priority cookie found in line")
12036 (let ((case-fold-search nil))
12037 (looking-at org-todo-line-regexp))
12040 (goto-char (match-end 2))
12041 (insert " [#" news "]"))
12042 (goto-char (match-beginning 3))
12043 (insert "[#" news "] "))))
12044 (org-preserve-lc (org-set-tags nil 'align)))
12046 (message "Priority removed")
12047 (message "Priority of current item set to %s" news))))
12049 (defun org-get-priority (s)
12050 "Find priority cookie and return priority."
12052 (if (not (string-match org-priority-regexp s))
12053 (* 1000 (- org-lowest-priority org-default-priority))
12054 (* 1000 (- org-lowest-priority
12055 (string-to-char (match-string 2 s)))))))
12059 (defvar org-agenda-archives-mode)
12060 (defvar org-map-continue-from nil
12061 "Position from where mapping should continue.
12062 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
12064 (defvar org-scanner-tags nil
12065 "The current tag list while the tags scanner is running.")
12066 (defvar org-trust-scanner-tags nil
12067 "Should `org-get-tags-at' use the tags fro the scanner.
12068 This is for internal dynamical scoping only.
12069 When this is non-nil, the function `org-get-tags-at' will return the value
12070 of `org-scanner-tags' instead of building the list by itself. This
12071 can lead to large speed-ups when the tags scanner is used in a file with
12072 many entries, and when the list of tags is retrieved, for example to
12073 obtain a list of properties. Building the tags list for each entry in such
12074 a file becomes an N^2 operation - but with this variable set, it scales
12077 (defun org-scan-tags (action matcher &optional todo-only)
12078 "Scan headline tags with inheritance and produce output ACTION.
12080 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
12081 or `agenda' to produce an entry list for an agenda view. It can also be
12082 a Lisp form or a function that should be called at each matched headline, in
12083 this case the return value is a list of all return values from these calls.
12085 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
12086 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
12087 only lines with a TODO keyword are included in the output."
12088 (require 'org-agenda)
12089 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
12090 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
12092 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
12093 (props (list 'face 'default
12094 'done-face 'org-agenda-done
12095 'undone-face 'default
12096 'mouse-face 'highlight
12097 'org-not-done-regexp org-not-done-regexp
12098 'org-todo-regexp org-todo-regexp
12100 (format "mouse-2 or RET jump to org file %s"
12101 (abbreviate-file-name
12102 (or (buffer-file-name (buffer-base-buffer))
12103 (buffer-name (buffer-base-buffer)))))))
12104 (case-fold-search nil)
12105 (org-map-continue-from nil)
12106 lspos tags tags-list
12107 (tags-alist (list (cons 0 org-file-tags)))
12108 (llast 0) rtn rtn1 level category i txt
12109 todo marker entry priority)
12110 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
12111 (setq action (list 'lambda nil action)))
12113 (goto-char (point-min))
12114 (when (eq action 'sparse-tree)
12116 (org-remove-occur-highlights))
12117 (while (re-search-forward re nil t)
12119 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
12120 tags (if (match-end 4) (org-match-string-no-properties 4)))
12121 (goto-char (setq lspos (match-beginning 0)))
12122 (setq level (org-reduced-level (funcall outline-level))
12123 category (org-get-category))
12124 (setq i llast llast level)
12125 ;; remove tag lists from same and sublevels
12126 (while (>= i level)
12127 (when (setq entry (assoc i tags-alist))
12128 (setq tags-alist (delete entry tags-alist)))
12130 ;; add the next tags
12132 (setq tags (org-split-string tags ":")
12134 (cons (cons level tags) tags-alist)))
12135 ;; compile tags for current headline
12137 (if org-use-tag-inheritance
12138 (apply 'append (mapcar 'cdr (reverse tags-alist)))
12140 org-scanner-tags tags-list)
12141 (when org-use-tag-inheritance
12142 (setcdr (car tags-alist)
12143 (mapcar (lambda (x)
12144 (setq x (copy-sequence x))
12145 (org-add-prop-inherited x))
12146 (cdar tags-alist))))
12147 (when (and tags org-use-tag-inheritance
12148 (or (not (eq t org-use-tag-inheritance))
12149 org-tags-exclude-from-inheritance))
12150 ;; selective inheritance, remove uninherited ones
12151 (setcdr (car tags-alist)
12152 (org-remove-uniherited-tags (cdar tags-alist))))
12153 (when (and (or (not todo-only)
12154 (and (member todo org-not-done-keywords)
12155 (or (not org-agenda-tags-todo-honor-ignore-options)
12156 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
12157 (let ((case-fold-search t)) (eval matcher))
12159 (not (member org-archive-tag tags-list))
12160 ;; we have an archive tag, should we use this anyway?
12161 (or (not org-agenda-skip-archived-trees)
12162 (and (eq action 'agenda) org-agenda-archives-mode))))
12163 (unless (eq action 'sparse-tree) (org-agenda-skip))
12165 ;; select this headline
12168 ((eq action 'sparse-tree)
12169 (and org-highlight-sparse-tree-matches
12170 (org-get-heading) (match-end 0)
12171 (org-highlight-new-match
12172 (match-beginning 0) (match-beginning 1)))
12173 (org-show-context 'tags-tree))
12174 ((eq action 'agenda)
12175 (setq txt (org-format-agenda-item
12178 (if (eq org-tags-match-list-sublevels 'indented)
12179 (make-string (1- level) ?.) "")
12184 priority (org-get-priority txt))
12186 (setq marker (org-agenda-new-marker))
12187 (org-add-props txt props
12188 'org-marker marker 'org-hd-marker marker 'org-category category
12190 'priority priority 'type "tagsmatch")
12192 ((functionp action)
12193 (setq org-map-continue-from nil)
12195 (setq rtn1 (funcall action))
12197 (t (error "Invalid action")))
12199 ;; if we are to skip sublevels, jump to end of subtree
12200 (unless org-tags-match-list-sublevels
12201 (org-end-of-subtree t)
12202 (backward-char 1))))
12203 ;; Get the correct position from where to continue
12204 (if org-map-continue-from
12205 (goto-char org-map-continue-from)
12206 (and (= (point) lspos) (end-of-line 1)))))
12207 (when (and (eq action 'sparse-tree)
12208 (not org-sparse-tree-open-archived-trees))
12209 (org-hide-archived-subtrees (point-min) (point-max)))
12212 (defun org-remove-uniherited-tags (tags)
12213 "Remove all tags that are not inherited from the list TAGS."
12215 ((eq org-use-tag-inheritance t)
12216 (if org-tags-exclude-from-inheritance
12217 (org-delete-all org-tags-exclude-from-inheritance tags)
12219 ((not org-use-tag-inheritance) nil)
12220 ((stringp org-use-tag-inheritance)
12223 (if (and (string-match org-use-tag-inheritance x)
12224 (not (member x org-tags-exclude-from-inheritance)))
12227 ((listp org-use-tag-inheritance)
12230 (if (member x org-use-tag-inheritance) x nil))
12233 (defvar todo-only) ;; dynamically scoped
12235 (defun org-match-sparse-tree (&optional todo-only match)
12236 "Create a sparse tree according to tags string MATCH.
12237 MATCH can contain positive and negative selection of tags, like
12238 \"+WORK+URGENT-WITHBOSS\".
12239 If optional argument TODO-ONLY is non-nil, only select lines that are
12242 (org-prepare-agenda-buffers (list (current-buffer)))
12243 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
12245 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
12247 (defvar org-cached-props nil)
12248 (defun org-cached-entry-get (pom property)
12249 (if (or (eq t org-use-property-inheritance)
12250 (and (stringp org-use-property-inheritance)
12251 (string-match org-use-property-inheritance property))
12252 (and (listp org-use-property-inheritance)
12253 (member property org-use-property-inheritance)))
12254 ;; Caching is not possible, check it directly
12255 (org-entry-get pom property 'inherit)
12256 ;; Get all properties, so that we can do complicated checks easily
12257 (cdr (assoc property (or org-cached-props
12258 (setq org-cached-props
12259 (org-entry-properties pom)))))))
12261 (defun org-global-tags-completion-table (&optional files)
12262 "Return the list of all tags in all agenda buffer/files."
12269 (set-buffer (find-file-noselect file))
12270 (append (org-get-buffer-tags)
12271 (mapcar (lambda (x) (if (stringp (car-safe x))
12272 (list (car-safe x)) nil))
12274 (if (and files (car files))
12276 (org-agenda-files))))))))
12278 (defun org-make-tags-matcher (match)
12279 "Create the TAGS//TODO matcher form for the selection string MATCH."
12280 ;; todo-only is scoped dynamically into this function, and the function
12281 ;; may change it if the matcher asks for it.
12283 ;; Get a new match request, with completion
12284 (let ((org-last-tags-completion-table
12285 (org-global-tags-completion-table)))
12286 (setq match (org-completing-read-no-i
12287 "Match: " 'org-tags-completion-function nil nil nil
12288 'org-tags-history))))
12290 ;; Parse the string and create a lisp form
12291 (let ((match0 match)
12292 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
12294 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
12295 orterms term orlist re-p str-p level-p level-op time-p
12296 prop-p pn pv po cat-p gv rest)
12297 (if (string-match "/+" match)
12298 ;; match contains also a todo-matching request
12300 (setq tagsmatch (substring match 0 (match-beginning 0))
12301 todomatch (substring match (match-end 0)))
12302 (if (string-match "^!" todomatch)
12303 (setq todo-only t todomatch (substring todomatch 1)))
12304 (if (string-match "^\\s-*$" todomatch)
12305 (setq todomatch nil)))
12306 ;; only matching tags
12307 (setq tagsmatch match todomatch nil))
12309 ;; Make the tags matcher
12310 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
12311 (setq tagsmatcher t)
12312 (setq orterms (org-split-string tagsmatch "|") orlist nil)
12313 (while (setq term (pop orterms))
12314 (while (and (equal (substring term -1) "\\") orterms)
12315 (setq term (concat term "|" (pop orterms)))) ; repair bad split
12316 (while (string-match re term)
12317 (setq rest (substring term (match-end 0))
12318 minus (and (match-end 1)
12319 (equal (match-string 1 term) "-"))
12320 tag (match-string 2 term)
12321 re-p (equal (string-to-char tag) ?{)
12322 level-p (match-end 4)
12323 prop-p (match-end 5)
12325 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
12327 (setq level-op (org-op-to-function (match-string 3 term)))
12328 `(,level-op level ,(string-to-number
12329 (match-string 4 term))))
12331 (setq pn (match-string 5 term)
12332 po (match-string 6 term)
12333 pv (match-string 7 term)
12334 cat-p (equal pn "CATEGORY")
12335 re-p (equal (string-to-char pv) ?{)
12336 str-p (equal (string-to-char pv) ?\")
12337 time-p (save-match-data
12338 (string-match "^\"[[<].*[]>]\"$" pv))
12339 pv (if (or re-p str-p) (substring pv 1 -1) pv))
12340 (if time-p (setq pv (org-matcher-time pv)))
12341 (setq po (org-op-to-function po (if time-p 'time str-p)))
12343 ((equal pn "CATEGORY")
12344 (setq gv '(get-text-property (point) 'org-category)))
12348 (setq gv `(org-cached-entry-get nil ,pn))))
12351 `(not (string-match ,pv (or ,gv "")))
12352 `(string-match ,pv (or ,gv "")))
12354 `(,po (or ,gv "") ,pv)
12355 `(,po (string-to-number (or ,gv ""))
12356 ,(string-to-number pv) ))))
12357 (t `(member ,tag tags-list)))
12358 mm (if minus (list 'not mm) mm)
12360 (push mm tagsmatcher))
12361 (push (if (> (length tagsmatcher) 1)
12362 (cons 'and tagsmatcher)
12365 (setq tagsmatcher nil))
12366 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
12368 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
12369 ;; Make the todo matcher
12370 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
12371 (setq todomatcher t)
12372 (setq orterms (org-split-string todomatch "|") orlist nil)
12373 (while (setq term (pop orterms))
12374 (while (string-match re term)
12375 (setq minus (and (match-end 1)
12376 (equal (match-string 1 term) "-"))
12377 kwd (match-string 2 term)
12378 re-p (equal (string-to-char kwd) ?{)
12379 term (substring term (match-end 0))
12381 `(string-match ,(substring kwd 1 -1) todo)
12382 (list 'equal 'todo kwd))
12383 mm (if minus (list 'not mm) mm))
12384 (push mm todomatcher))
12385 (push (if (> (length todomatcher) 1)
12386 (cons 'and todomatcher)
12389 (setq todomatcher nil))
12390 (setq todomatcher (if (> (length orlist) 1)
12391 (cons 'or orlist) (car orlist))))
12393 ;; Return the string and lisp forms of the matcher
12394 (setq matcher (if todomatcher
12395 (list 'and tagsmatcher todomatcher)
12397 (cons match0 matcher)))
12399 (defun org-op-to-function (op &optional stringp)
12400 "Turn an operator into the appropriate function."
12403 ((equal op "<" ) '(< string< org-time<))
12404 ((equal op ">" ) '(> org-string> org-time>))
12405 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
12406 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
12407 ((member op '("=" "==")) '(= string= org-time=))
12408 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
12409 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
12411 (defun org<> (a b) (not (= a b)))
12412 (defun org-string<= (a b) (or (string= a b) (string< a b)))
12413 (defun org-string>= (a b) (not (string< a b)))
12414 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
12415 (defun org-string<> (a b) (not (string= a b)))
12416 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
12417 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
12418 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
12419 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
12420 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
12421 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
12423 "Convert S to a floating point time.
12424 If S is already a number, just return it. If it is a string, parse
12425 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12429 (condition-case nil
12430 (float-time (apply 'encode-time (org-parse-time-string s)))
12434 (defun org-time-today ()
12435 "Time in seconds today at 0:00.
12436 Returns the float number of seconds since the beginning of the
12437 epoch to the beginning of today (00:00)."
12438 (float-time (apply 'encode-time
12439 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12441 (defun org-matcher-time (s)
12442 "Interpret a time comparison value."
12445 ((string= s "<now>") (float-time))
12446 ((string= s "<today>") (org-time-today))
12447 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12448 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12449 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12450 (+ (org-time-today)
12451 (* (string-to-number (match-string 1 s))
12452 (cdr (assoc (match-string 2 s)
12453 '(("d" . 86400.0) ("w" . 604800.0)
12454 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12457 (defun org-match-any-p (re list)
12458 "Does re match any element of list?"
12459 (setq list (mapcar (lambda (x) (string-match re x)) list))
12462 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12463 (defvar org-tags-overlay (make-overlay 1 1))
12464 (org-detach-overlay org-tags-overlay)
12466 (defun org-get-local-tags-at (&optional pos)
12467 "Get a list of tags defined in the current headline."
12468 (org-get-tags-at pos 'local))
12470 (defun org-get-local-tags ()
12471 "Get a list of tags defined in the current headline."
12472 (org-get-tags-at nil 'local))
12474 (defun org-get-tags-at (&optional pos local)
12475 "Get a list of all headline tags applicable at POS.
12476 POS defaults to point. If tags are inherited, the list contains
12477 the targets in the same sequence as the headlines appear, i.e.
12478 the tags of the current headline come last.
12479 When LOCAL is non-nil, only return tags from the current headline,
12480 ignore inherited ones."
12482 (if (and org-trust-scanner-tags
12483 (or (not pos) (equal pos (point)))
12486 (let (tags ltags lastpos parent)
12490 (goto-char (or pos (point)))
12493 (condition-case nil
12495 (org-back-to-heading t)
12496 (while (not (equal lastpos (point)))
12497 (setq lastpos (point))
12499 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12500 (setq ltags (org-split-string
12501 (org-match-string-no-properties 1) ":"))
12503 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12506 (org-remove-uniherited-tags ltags)
12509 (or org-use-tag-inheritance (throw 'done t))
12510 (if local (throw 'done t))
12511 (or (org-up-heading-safe) (error nil))
12514 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12516 (defun org-add-prop-inherited (s)
12517 (add-text-properties 0 (length s) '(inherited t) s)
12520 (defun org-toggle-tag (tag &optional onoff)
12521 "Toggle the tag TAG for the current line.
12522 If ONOFF is `on' or `off', don't toggle but set to this state."
12525 (org-back-to-heading t)
12526 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12529 (setq current (match-string 1))
12530 (replace-match ""))
12532 (setq current (nreverse (org-split-string current ":")))
12536 (or (member tag current) (push tag current)))
12538 (or (not (member tag current)) (setq current (delete tag current))))
12539 (t (if (member tag current)
12540 (setq current (delete tag current))
12542 (push tag current))))
12546 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12547 (org-set-tags nil t))
12548 (delete-horizontal-space))
12549 (run-hooks 'org-after-tags-change-hook))
12552 (defun org-align-tags-here (to-col)
12553 ;; Assumes that this is a headline
12554 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12555 (beginning-of-line 1)
12556 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12557 (< pos (match-beginning 2)))
12559 (setq tags-l (- (match-end 2) (match-beginning 2)))
12560 (goto-char (match-beginning 1))
12562 (delete-region (point) (1+ (match-beginning 2)))
12563 (setq ncol (max (1+ (current-column))
12567 (- (abs to-col) tags-l))))
12569 (insert (make-string (- ncol (current-column)) ?\ ))
12570 (setq ncol (current-column))
12571 (when indent-tabs-mode (tabify p (point-at-eol)))
12572 (org-move-to-column (min ncol col) t))
12575 (defun org-set-tags-command (&optional arg just-align)
12576 "Call the set-tags command for the current entry."
12578 (if (org-on-heading-p)
12579 (org-set-tags arg just-align)
12581 (org-back-to-heading t)
12582 (org-set-tags arg just-align))))
12584 (defun org-set-tags-to (data)
12585 "Set the tags of the current entry to DATA, replacing the current tags.
12586 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12587 If DATA is nil or the empty string, any tags will be removed."
12588 (interactive "sTags: ")
12592 ((equal data "") "")
12594 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12597 (concat ":" (mapconcat 'identity data ":") ":"))
12601 (org-back-to-heading t)
12602 (when (looking-at org-complex-heading-regexp)
12605 (goto-char (match-beginning 5))
12607 (delete-region (point) (point-at-eol))
12608 (org-set-tags nil 'align))
12609 (goto-char (point-at-eol))
12611 (org-set-tags nil 'align)))
12612 (beginning-of-line 1)
12613 (if (looking-at ".*?\\([ \t]+\\)$")
12614 (delete-region (match-beginning 1) (match-end 1))))))
12616 (defun org-align-all-tags ()
12617 "Align the tags i all headings."
12620 (or (ignore-errors (org-back-to-heading t))
12621 (outline-next-heading))
12622 (if (org-on-heading-p)
12624 (message "No headings"))))
12626 (defun org-set-tags (&optional arg just-align)
12627 "Set the tags for the current headline.
12628 With prefix ARG, realign all tags in headings in the current buffer."
12630 (let* ((re (concat "^" outline-regexp))
12631 (current (org-get-tags-string))
12632 (col (current-column))
12633 (org-setting-tags t)
12634 table current-tags inherited-tags ; computed below when needed
12638 (goto-char (point-min))
12639 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12640 (while (re-search-forward re nil t)
12641 (org-set-tags nil t)
12643 (message "All tags realigned to column %d" org-tags-column))
12645 (setq tags current)
12646 ;; Get a new set of tags from the user
12648 (setq table (append org-tag-persistent-alist
12649 (or org-tag-alist (org-get-buffer-tags))
12650 (and org-complete-tags-always-offer-all-agenda-tags
12651 (org-global-tags-completion-table (org-agenda-files))))
12652 org-last-tags-completion-table table
12653 current-tags (org-split-string current ":")
12654 inherited-tags (nreverse
12655 (nthcdr (length current-tags)
12656 (nreverse (org-get-tags-at))))
12658 (if (or (eq t org-use-fast-tag-selection)
12659 (and org-use-fast-tag-selection
12660 (delq nil (mapcar 'cdr table))))
12661 (org-fast-tag-selection
12662 current-tags inherited-tags table
12663 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12664 (let ((org-add-colon-after-tag-completion t))
12666 (org-without-partial-completion
12667 (org-icompleting-read "Tags: " 'org-tags-completion-function
12668 nil nil current 'org-tags-history)))))))
12669 (while (string-match "[-+&]+" tags)
12670 ;; No boolean logic, just a list
12671 (setq tags (replace-match ":" t t tags))))
12673 (if org-tags-sort-function
12674 (setq tags (mapconcat 'identity
12675 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12676 org-tags-sort-function) ":")))
12678 (if (string-match "\\`[\t ]*\\'" tags)
12680 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12681 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12683 ;; Insert new tags at the correct column
12684 (beginning-of-line 1)
12686 ((and (equal current "") (equal tags "")))
12687 ((re-search-forward
12688 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12690 (if (equal tags "")
12692 (goto-char (match-beginning 0))
12693 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12694 (1+ (point)) (point))
12695 c1 (max (1+ c0) (if (> org-tags-column 0)
12697 (- (- org-tags-column) (length tags))))
12698 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12699 (replace-match rpl t t)
12700 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12702 (t (error "Tags alignment failed")))
12703 (org-move-to-column col)
12705 (run-hooks 'org-after-tags-change-hook)))))
12707 (defun org-change-tag-in-region (beg end tag off)
12708 "Add or remove TAG for each entry in the region.
12709 This works in the agenda, and also in an org-mode buffer."
12711 (list (region-beginning) (region-end)
12712 (let ((org-last-tags-completion-table
12714 (org-get-buffer-tags)
12715 (org-global-tags-completion-table))))
12716 (org-icompleting-read
12717 "Tag: " 'org-tags-completion-function nil nil nil
12718 'org-tags-history))
12720 (message "[s]et or [r]emove? ")
12721 (equal (read-char-exclusive) ?r))))
12722 (if (fboundp 'deactivate-mark) (deactivate-mark))
12723 (let ((agendap (equal major-mode 'org-agenda-mode))
12724 l1 l2 m buf pos newhead (cnt 0))
12726 (setq l2 (1- (org-current-line)))
12728 (setq l1 (org-current-line))
12729 (loop for l from l1 to l2 do
12731 (setq m (get-text-property (point) 'org-hd-marker))
12732 (when (or (and (org-mode-p) (org-on-heading-p))
12734 (setq buf (if agendap (marker-buffer m) (current-buffer))
12735 pos (if agendap m (point)))
12736 (with-current-buffer buf
12740 (setq cnt (1+ cnt))
12741 (org-toggle-tag tag (if off 'off 'on))
12742 (setq newhead (org-get-heading)))))
12743 (and agendap (org-agenda-change-all-lines newhead m))))
12744 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12746 (defun org-tags-completion-function (string predicate &optional flag)
12747 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12748 (confirm (lambda (x) (stringp (car x)))))
12749 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12750 (setq s1 (match-string 1 string)
12751 s2 (match-string 2 string))
12752 (setq s1 "" s2 string))
12756 (setq rtn (try-completion s2 ctable confirm))
12759 (concat s1 s2 (substring rtn (length s2))
12760 (if (and org-add-colon-after-tag-completion
12761 (assoc rtn ctable))
12766 (all-completions s2 ctable confirm)
12770 (assoc s2 ctable)))
12773 (defun org-fast-tag-insert (kwd tags face &optional end)
12774 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12775 (insert (format "%-12s" (concat kwd ":"))
12776 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12779 (defun org-fast-tag-show-exit (flag)
12782 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12783 (replace-match ""))
12786 (org-move-to-column (- (window-width) 19) t)
12787 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12789 (defun org-set-current-tags-overlay (current prefix)
12790 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12791 (if (featurep 'xemacs)
12792 (org-overlay-display org-tags-overlay (concat prefix s)
12793 'secondary-selection)
12794 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12795 (org-overlay-display org-tags-overlay (concat prefix s)))))
12797 (defvar org-last-tag-selection-key nil)
12798 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12799 "Fast tag selection with single keys.
12800 CURRENT is the current list of tags in the headline, INHERITED is the
12801 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12802 possibly with grouping information. TODO-TABLE is a similar table with
12803 TODO keywords, should these have keys assigned to them.
12804 If the keys are nil, a-z are automatically assigned.
12805 Returns the new tags string, or nil to not change the current settings."
12806 (let* ((fulltable (append table todo-table))
12807 (maxlen (apply 'max (mapcar
12809 (if (stringp (car x)) (string-width (car x)) 0))
12811 (buf (current-buffer))
12812 (expert (eq org-fast-tag-selection-single-key 'expert))
12814 (fwidth (+ maxlen 3 1 3))
12815 (ncol (/ (- (window-width) 4) fwidth))
12818 tg cnt e c char c1 c2 ntable tbl rtn
12819 ov-start ov-end ov-prefix
12820 (exit-after-next org-fast-tag-selection-single-key)
12821 (done-keywords org-done-keywords)
12824 (beginning-of-line 1)
12826 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12827 (setq ov-start (match-beginning 1)
12828 ov-end (match-end 1)
12830 (setq ov-start (1- (point-at-eol))
12831 ov-end (1+ ov-start))
12832 (skip-chars-forward "^\n\r")
12835 (buffer-substring (1- (point)) (point))
12836 (if (> (current-column) org-tags-column)
12838 (make-string (- org-tags-column (current-column)) ?\ ))))))
12839 (move-overlay org-tags-overlay ov-start ov-end)
12840 (save-window-excursion
12842 (set-buffer (get-buffer-create " *Org tags*"))
12843 (delete-other-windows)
12844 (split-window-vertically)
12845 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12847 (org-set-local 'org-done-keywords done-keywords)
12848 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12849 (org-fast-tag-insert "Current" current c-face "\n\n")
12850 (org-fast-tag-show-exit exit-after-next)
12851 (org-set-current-tags-overlay current ov-prefix)
12852 (setq tbl fulltable char ?a cnt 0)
12853 (while (setq e (pop tbl))
12855 ((equal (car e) :startgroup)
12856 (push '() groups) (setq ingroup t)
12857 (when (not (= cnt 0))
12860 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12861 ((equal (car e) :endgroup)
12862 (setq ingroup nil cnt 0)
12863 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12864 ((equal e '(:newline))
12865 (when (not (= cnt 0))
12869 (while (equal (car tbl) '(:newline))
12871 (setq tbl (cdr tbl)))))
12873 (setq tg (copy-sequence (car e)) c2 nil)
12876 ;; automatically assign a character.
12877 (setq c1 (string-to-char
12878 (downcase (substring
12879 tg (if (= (string-to-char tg) ?@) 1 0)))))
12880 (if (or (rassoc c1 ntable) (rassoc c1 table))
12881 (while (or (rassoc char ntable) (rassoc char table))
12882 (setq char (1+ char)))
12884 (setq c (or c2 char)))
12885 (if ingroup (push tg (car groups)))
12886 (setq tg (org-add-props tg nil 'face
12888 ((not (assoc tg table))
12889 (org-get-todo-face tg))
12890 ((member tg current) c-face)
12891 ((member tg inherited) i-face)
12893 (if (and (= cnt 0) (not ingroup)) (insert " "))
12894 (insert "[" c "] " tg (make-string
12895 (- fwidth 4 (length tg)) ?\ ))
12896 (push (cons tg c) ntable)
12897 (when (= (setq cnt (1+ cnt)) ncol)
12899 (if ingroup (insert " "))
12901 (setq ntable (nreverse ntable))
12903 (goto-char (point-min))
12904 (if (not expert) (org-fit-window-to-buffer))
12908 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12909 (if (not groups) "no " "")
12910 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12911 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12912 (setq org-last-tag-selection-key c)
12914 ((= c ?\r) (throw 'exit t))
12916 (setq groups (not groups))
12917 (goto-char (point-min))
12918 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12921 (org-fast-tag-show-exit
12922 (setq exit-after-next (not exit-after-next)))
12924 (delete-other-windows)
12925 (split-window-vertically)
12926 (org-switch-to-buffer-other-window " *Org tags*")
12927 (org-fit-window-to-buffer)))
12929 (and (= c ?q) (not (rassoc c ntable))))
12930 (org-detach-overlay org-tags-overlay)
12931 (setq quit-flag t))
12934 (if exit-after-next (setq exit-after-next 'now)))
12936 (condition-case nil
12937 (setq tg (org-icompleting-read
12940 (with-current-buffer buf
12941 (org-get-buffer-tags)))))
12942 (quit (setq tg "")))
12943 (when (string-match "\\S-" tg)
12944 (add-to-list 'buffer-tags (list tg))
12945 (if (member tg current)
12946 (setq current (delete tg current))
12947 (push tg current)))
12948 (if exit-after-next (setq exit-after-next 'now)))
12949 ((setq e (rassoc c todo-table) tg (car e))
12950 (with-current-buffer buf
12951 (save-excursion (org-todo tg)))
12952 (if exit-after-next (setq exit-after-next 'now)))
12953 ((setq e (rassoc c ntable) tg (car e))
12954 (if (member tg current)
12955 (setq current (delete tg current))
12956 (loop for g in groups do
12959 (setq current (delete x current)))
12962 (if exit-after-next (setq exit-after-next 'now))))
12964 ;; Create a sorted list
12968 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12969 (if (eq exit-after-next 'now) (throw 'exit t))
12970 (goto-char (point-min))
12971 (beginning-of-line 2)
12972 (delete-region (point) (point-at-eol))
12973 (org-fast-tag-insert "Current" current c-face)
12974 (org-set-current-tags-overlay current ov-prefix)
12975 (while (re-search-forward
12976 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12977 (setq tg (match-string 1))
12978 (add-text-properties
12979 (match-beginning 1) (match-end 1)
12982 ((member tg current) c-face)
12983 ((member tg inherited) i-face)
12984 (t (get-text-property (match-beginning 1) 'face))))))
12985 (goto-char (point-min)))))
12986 (org-detach-overlay org-tags-overlay)
12988 (mapconcat 'identity current ":")
12991 (defun org-get-tags-string ()
12992 "Get the TAGS string in the current headline."
12993 (unless (org-on-heading-p t)
12994 (error "Not on a heading"))
12996 (beginning-of-line 1)
12997 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12998 (org-match-string-no-properties 1)
13001 (defun org-get-tags ()
13002 "Get the list of tags specified in the current headline."
13003 (org-split-string (org-get-tags-string) ":"))
13005 (defun org-get-buffer-tags ()
13006 "Get a table of all tags used in the buffer, for completion."
13009 (goto-char (point-min))
13010 (while (re-search-forward
13011 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
13012 (when (equal (char-after (point-at-bol 0)) ?*)
13013 (mapc (lambda (x) (add-to-list 'tags x))
13014 (org-split-string (org-match-string-no-properties 1) ":")))))
13015 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
13016 (mapcar 'list tags)))
13018 ;;;; The mapping API
13021 (defun org-map-entries (func &optional match scope &rest skip)
13022 "Call FUNC at each headline selected by MATCH in SCOPE.
13024 FUNC is a function or a lisp form. The function will be called without
13025 arguments, with the cursor positioned at the beginning of the headline.
13026 The return values of all calls to the function will be collected and
13027 returned as a list.
13029 The call to FUNC will be wrapped into a save-excursion form, so FUNC
13030 does not need to preserve point. After evaluation, the cursor will be
13031 moved to the end of the line (presumably of the headline of the
13032 processed entry) and search continues from there. Under some
13033 circumstances, this may not produce the wanted results. For example,
13034 if you have removed (e.g. archived) the current (sub)tree it could
13035 mean that the next entry will be skipped entirely. In such cases, you
13036 can specify the position from where search should continue by making
13037 FUNC set the variable `org-map-continue-from' to the desired buffer
13040 MATCH is a tags/property/todo match as it is used in the agenda tags view.
13041 Only headlines that are matched by this query will be considered during
13042 the iteration. When MATCH is nil or t, all headlines will be
13043 visited by the iteration.
13045 SCOPE determines the scope of this command. It can be any of:
13047 nil The current buffer, respecting the restriction if any
13048 tree The subtree started with the entry at point
13049 file The current buffer, without restriction
13051 The current buffer, and any archives associated with it
13052 agenda All agenda files
13053 agenda-with-archives
13054 All agenda files with any archive files associated with them
13056 If this is a list, all files in the list will be scanned
13058 The remaining args are treated as settings for the skipping facilities of
13059 the scanner. The following items can be given here:
13061 archive skip trees with the archive tag.
13062 comment skip trees with the COMMENT keyword
13063 function or Emacs Lisp form:
13064 will be used as value for `org-agenda-skip-function', so whenever
13065 the function returns t, FUNC will not be called for that
13066 entry and search will continue from the point where the
13067 function leaves it.
13069 If your function needs to retrieve the tags including inherited tags
13070 at the *current* entry, you can use the value of the variable
13071 `org-scanner-tags' which will be much faster than getting the value
13072 with `org-get-tags-at'. If your function gets properties with
13073 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
13074 to t around the call to `org-entry-properties' to get the same speedup.
13075 Note that if your function moves around to retrieve tags and properties at
13076 a *different* entry, you cannot use these techniques."
13077 (let* ((org-agenda-archives-mode nil) ; just to make sure
13078 (org-agenda-skip-archived-trees (memq 'archive skip))
13079 (org-agenda-skip-comment-trees (memq 'comment skip))
13080 (org-agenda-skip-function
13081 (car (org-delete-all '(comment archive) skip)))
13082 (org-tags-match-list-sublevels t)
13084 org-todo-keywords-for-agenda
13085 org-done-keywords-for-agenda
13086 org-todo-keyword-alist-for-agenda
13087 org-drawers-for-agenda
13088 org-tag-alist-for-agenda)
13091 ((eq match t) (setq matcher t))
13092 ((eq match nil) (setq matcher t))
13093 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
13097 (when (eq scope 'tree)
13098 (org-back-to-heading t)
13099 (org-narrow-to-subtree)
13104 (org-prepare-agenda-buffers
13105 (list (buffer-file-name (current-buffer))))
13106 (setq res (org-scan-tags func matcher)))
13107 ;; Get the right scope
13109 ((and scope (listp scope) (symbolp (car scope)))
13110 (setq scope (eval scope)))
13111 ((eq scope 'agenda)
13112 (setq scope (org-agenda-files t)))
13113 ((eq scope 'agenda-with-archives)
13114 (setq scope (org-agenda-files t))
13115 (setq scope (org-add-archive-files scope)))
13117 (setq scope (list (buffer-file-name))))
13118 ((eq scope 'file-with-archives)
13119 (setq scope (org-add-archive-files (list (buffer-file-name))))))
13120 (org-prepare-agenda-buffers scope)
13121 (while (setq file (pop scope))
13122 (with-current-buffer (org-find-base-buffer-visiting file)
13126 (goto-char (point-min))
13127 (setq res (append res (org-scan-tags func matcher))))))))))
13132 ;;; Setting and retrieving properties
13134 (defconst org-special-properties
13135 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
13136 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
13137 "The special properties valid in Org-mode.
13139 These are properties that are not defined in the property drawer,
13140 but in some other way.")
13142 (defconst org-default-properties
13143 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
13144 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
13145 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
13146 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
13147 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
13148 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
13149 "Some properties that are used by Org-mode for various purposes.
13150 Being in this list makes sure that they are offered for completion.")
13152 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
13153 "Regular expression matching the first line of a property drawer.")
13155 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
13156 "Regular expression matching the last line of a property drawer.")
13158 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
13159 "Regular expression matching the first line of a property drawer.")
13161 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
13162 "Regular expression matching the first line of a property drawer.")
13164 (defconst org-property-drawer-re
13165 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
13166 org-property-end-re "\\)\n?")
13167 "Matches an entire property drawer.")
13169 (defconst org-clock-drawer-re
13170 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
13171 org-property-end-re "\\)\n?")
13172 "Matches an entire clock drawer.")
13174 (defun org-property-action ()
13175 "Do an action on properties."
13178 (org-at-property-p)
13179 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
13180 (setq c (read-char-exclusive))
13183 (call-interactively 'org-set-property))
13185 (call-interactively 'org-delete-property))
13187 (call-interactively 'org-delete-property-globally))
13189 (call-interactively 'org-compute-property-at-point))
13190 (t (error "No such property action %c" c)))))
13192 (defun org-set-effort (&optional value)
13193 "Set the effort property of the current entry.
13194 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
13197 (if (equal value 0) (setq value 10))
13198 (let* ((completion-ignore-case t)
13199 (prop org-effort-property)
13200 (cur (org-entry-get nil prop))
13201 (allowed (org-property-get-allowed-values nil prop 'table))
13202 (existing (mapcar 'list (org-property-values prop)))
13205 ((stringp value) value)
13206 ((and allowed (integerp value))
13207 (or (car (nth (1- value) allowed))
13208 (car (org-last allowed))))
13210 (message "Select 1-9,0, [RET%s]: %s"
13211 (if cur (concat "=" cur) "")
13212 (mapconcat 'car allowed " "))
13213 (setq rpl (read-char-exclusive))
13214 (if (equal rpl ?\r)
13216 (setq rpl (- rpl ?0))
13217 (if (equal rpl 0) (setq rpl 10))
13218 (if (and (> rpl 0) (<= rpl (length allowed)))
13219 (car (nth (1- rpl) allowed))
13220 (org-completing-read "Effort: " allowed nil))))
13222 (let (org-completion-use-ido org-completion-use-iswitchb)
13223 (org-completing-read
13224 (concat "Effort " (if (and cur (string-match "\\S-" cur))
13225 (concat "[" cur "]") "")
13227 existing nil nil "" nil cur))))))
13228 (unless (equal (org-entry-get nil prop) val)
13229 (org-entry-put nil prop val))
13230 (message "%s is now %s" prop val)))
13232 (defun org-at-property-p ()
13233 "Is cursor inside a property drawer?"
13235 (beginning-of-line 1)
13236 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
13237 (save-match-data ;; Used by calling procedures
13239 (range (unless (org-before-first-heading-p)
13240 (org-get-property-block))))
13241 (and range (<= (car range) p) (< p (cdr range))))))))
13243 (defun org-get-property-block (&optional beg end force)
13244 "Return the (beg . end) range of the body of the property drawer.
13245 BEG and END can be beginning and end of subtree, if not given
13246 they will be found.
13247 If the drawer does not exist and FORCE is non-nil, create the drawer."
13250 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
13251 (end (or end (progn (outline-next-heading) (point)))))
13253 (if (re-search-forward org-property-start-re end t)
13254 (setq beg (1+ (match-end 0)))
13257 (org-insert-property-drawer)
13258 (setq end (progn (outline-next-heading) (point))))
13261 (if (re-search-forward org-property-start-re end t)
13262 (setq beg (1+ (match-end 0)))))
13263 (if (re-search-forward org-property-end-re end t)
13264 (setq end (match-beginning 0))
13265 (or force (throw 'exit nil))
13268 (org-indent-line-function)
13269 (insert ":END:\n"))
13272 (defun org-entry-properties (&optional pom which specific)
13273 "Get all properties of the entry at point-or-marker POM.
13274 This includes the TODO keyword, the tags, time strings for deadline,
13275 scheduled, and clocking, and any additional properties defined in the
13276 entry. The return value is an alist, keys may occur multiple times
13277 if the property key was used several times.
13278 POM may also be nil, in which case the current entry is used.
13279 If WHICH is nil or `all', get all properties. If WHICH is
13280 `special' or `standard', only get that subclass. If WHICH
13281 is a string only get exactly this property. Specific can be a string, the
13282 specific property we are interested in. Specifying it can speed
13283 things up because then unnecessary parsing is avoided."
13284 (setq which (or which 'all))
13285 (org-with-point-at pom
13286 (let ((clockstr (substring org-clock-string 0 -1))
13287 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
13288 (case-fold-search nil)
13289 beg end range props sum-props key key1 value string clocksum)
13291 (when (condition-case nil
13292 (and (org-mode-p) (org-back-to-heading t))
13295 (setq sum-props (get-text-property (point) 'org-summaries))
13296 (setq clocksum (get-text-property (point) :org-clock-minutes))
13297 (outline-next-heading)
13299 (when (memq which '(all special))
13300 ;; Get the special properties, like TODO and tags
13302 (when (and (or (not specific) (string= specific "TODO"))
13303 (looking-at org-todo-line-regexp) (match-end 2))
13304 (push (cons "TODO" (org-match-string-no-properties 2)) props))
13305 (when (and (or (not specific) (string= specific "PRIORITY"))
13306 (looking-at org-priority-regexp))
13307 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
13308 (when (and (or (not specific) (string= specific "TAGS"))
13309 (setq value (org-get-tags-string))
13310 (string-match "\\S-" value))
13311 (push (cons "TAGS" value) props))
13312 (when (and (or (not specific) (string= specific "ALLTAGS"))
13313 (setq value (org-get-tags-at)))
13314 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
13317 (when (or (not specific) (string= specific "BLOCKED"))
13318 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
13319 (when (or (not specific)
13321 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
13322 "TIMESTAMP" "TIMESTAMP_IA")))
13323 (while (re-search-forward org-maybe-keyword-time-regexp end t)
13324 (setq key (if (match-end 1)
13325 (substring (org-match-string-no-properties 1)
13327 string (if (equal key clockstr)
13331 (match-beginning 3) (goto-char
13333 (substring (org-match-string-no-properties 3)
13335 ;; Get the correct property name from the key. This is
13336 ;; necessary if the user has configured time keywords.
13337 (setq key1 (concat key ":"))
13341 (if (= (char-after (match-beginning 3)) ?\[)
13342 "TIMESTAMP_IA" "TIMESTAMP")))
13343 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
13344 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
13345 ((equal key1 org-closed-string) (setq key "CLOSED"))
13346 ((equal key1 org-clock-string) (setq key "CLOCK")))
13347 (when (or (equal key "CLOCK") (not (assoc key props)))
13348 (push (cons key string) props))))
13351 (when (memq which '(all standard))
13352 ;; Get the standard properties, like :PROP: ...
13353 (setq range (org-get-property-block beg end))
13355 (goto-char (car range))
13356 (while (re-search-forward
13357 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
13359 (setq key (org-match-string-no-properties 1)
13360 value (org-trim (or (org-match-string-no-properties 2) "")))
13361 (unless (member key excluded)
13362 (push (cons key (or value "")) props)))))
13364 (push (cons "CLOCKSUM"
13365 (org-columns-number-to-string (/ (float clocksum) 60.)
13368 (unless (assoc "CATEGORY" props)
13369 (setq value (or (org-get-category)
13370 (progn (org-refresh-category-properties)
13371 (org-get-category))))
13372 (push (cons "CATEGORY" value) props))
13373 (append sum-props (nreverse props)))))))
13375 (defun org-entry-get (pom property &optional inherit literal-nil)
13376 "Get value of PROPERTY for entry at point-or-marker POM.
13377 If INHERIT is non-nil and the entry does not have the property,
13378 then also check higher levels of the hierarchy.
13379 If INHERIT is the symbol `selective', use inheritance only if the setting
13380 in `org-use-property-inheritance' selects PROPERTY for inheritance.
13381 If the property is present but empty, the return value is the empty string.
13382 If the property is not present at all, nil is returned.
13384 If LITERAL-NIL is set, return the string value \"nil\" as a string,
13385 do not interpret it as the list atom nil. This is used for inheritance
13386 when a \"nil\" value can supercede a non-nil value higher up the hierarchy."
13387 (org-with-point-at pom
13388 (if (and inherit (if (eq inherit 'selective)
13389 (org-property-inherit-p property)
13391 (org-entry-get-with-inheritance property)
13392 (if (member property org-special-properties)
13393 ;; We need a special property. Use `org-entry-properties' to
13394 ;; retrieve it, but specify the wanted property
13395 (cdr (assoc property (org-entry-properties nil 'special property)))
13396 (let ((range (org-get-property-block)))
13398 (goto-char (car range))
13400 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
13402 ;; Found the property, return it.
13405 (org-match-string-no-properties 1)
13406 (org-not-nil (org-match-string-no-properties 1)))
13409 (defun org-property-or-variable-value (var &optional inherit)
13410 "Check if there is a property fixing the value of VAR.
13411 If yes, return this value. If not, return the current value of the variable."
13412 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
13413 (if (and prop (stringp prop) (string-match "\\S-" prop))
13415 (symbol-value var))))
13417 (defun org-entry-delete (pom property)
13418 "Delete the property PROPERTY from entry at point-or-marker POM."
13419 (org-with-point-at pom
13420 (if (member property org-special-properties)
13421 nil ; cannot delete these properties.
13422 (let ((range (org-get-property-block)))
13424 (goto-char (car range))
13426 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
13429 (delete-region (match-beginning 0) (1+ (point-at-eol)))
13433 ;; Multi-values properties are properties that contain multiple values
13434 ;; These values are assumed to be single words, separated by whitespace.
13435 (defun org-entry-add-to-multivalued-property (pom property value)
13436 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
13437 (let* ((old (org-entry-get pom property))
13438 (values (and old (org-split-string old "[ \t]"))))
13439 (setq value (org-entry-protect-space value))
13440 (unless (member value values)
13441 (setq values (cons value values))
13442 (org-entry-put pom property
13443 (mapconcat 'identity values " ")))))
13445 (defun org-entry-remove-from-multivalued-property (pom property value)
13446 "Remove VALUE from 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 (when (member value values)
13451 (setq values (delete value values))
13452 (org-entry-put pom property
13453 (mapconcat 'identity values " ")))))
13455 (defun org-entry-member-in-multivalued-property (pom property value)
13456 "Is VALUE one of the 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 (member value values)))
13462 (defun org-entry-get-multivalued-property (pom property)
13463 "Return a list of values in a multivalued property."
13464 (let* ((value (org-entry-get pom property))
13465 (values (and value (org-split-string value "[ \t]"))))
13466 (mapcar 'org-entry-restore-space values)))
13468 (defun org-entry-put-multivalued-property (pom property &rest values)
13469 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13470 VALUES should be a list of strings. Spaces will be protected."
13471 (org-entry-put pom property
13472 (mapconcat 'org-entry-protect-space values " "))
13473 (let* ((value (org-entry-get pom property))
13474 (values (and value (org-split-string value "[ \t]"))))
13475 (mapcar 'org-entry-restore-space values)))
13477 (defun org-entry-protect-space (s)
13478 "Protect spaces and newline in string S."
13479 (while (string-match " " s)
13480 (setq s (replace-match "%20" t t s)))
13481 (while (string-match "\n" s)
13482 (setq s (replace-match "%0A" t t s)))
13485 (defun org-entry-restore-space (s)
13486 "Restore spaces and newline in string S."
13487 (while (string-match "%20" s)
13488 (setq s (replace-match " " t t s)))
13489 (while (string-match "%0A" s)
13490 (setq s (replace-match "\n" t t s)))
13493 (defvar org-entry-property-inherited-from (make-marker)
13494 "Marker pointing to the entry from where a property was inherited.
13495 Each call to `org-entry-get-with-inheritance' will set this marker to the
13496 location of the entry where the inheritance search matched. If there was
13497 no match, the marker will point nowhere.
13498 Note that also `org-entry-get' calls this function, if the INHERIT flag
13501 (defun org-entry-get-with-inheritance (property)
13502 "Get entry property, and search higher levels if not present."
13503 (move-marker org-entry-property-inherited-from nil)
13510 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
13511 (org-back-to-heading t)
13512 (move-marker org-entry-property-inherited-from (point))
13514 (or (org-up-heading-safe) (throw 'ex nil)))))
13517 (cdr (assoc property org-file-properties))
13518 (cdr (assoc property org-global-properties))
13519 (cdr (assoc property org-global-properties-fixed)))))))
13521 (defvar org-property-changed-functions nil
13522 "Hook called when the value of a property has changed.
13523 Each hook function should accept two arguments, the name of the property
13524 and the new value.")
13526 (defun org-entry-put (pom property value)
13527 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13528 (org-with-point-at pom
13529 (org-back-to-heading t)
13530 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13533 ((equal property "TODO")
13534 (when (and (stringp value) (string-match "\\S-" value)
13535 (not (member value org-todo-keywords-1)))
13536 (error "\"%s\" is not a valid TODO state" value))
13537 (if (or (not value)
13538 (not (string-match "\\S-" value)))
13539 (setq value 'none))
13541 (org-set-tags nil 'align))
13542 ((equal property "PRIORITY")
13543 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13544 (string-to-char value) ?\ ))
13545 (org-set-tags nil 'align))
13546 ((equal property "SCHEDULED")
13547 (if (re-search-forward org-scheduled-time-regexp end t)
13549 ((eq value 'earlier) (org-timestamp-change -1 'day))
13550 ((eq value 'later) (org-timestamp-change 1 'day))
13551 (t (call-interactively 'org-schedule)))
13552 (call-interactively 'org-schedule)))
13553 ((equal property "DEADLINE")
13554 (if (re-search-forward org-deadline-time-regexp end t)
13556 ((eq value 'earlier) (org-timestamp-change -1 'day))
13557 ((eq value 'later) (org-timestamp-change 1 'day))
13558 (t (call-interactively 'org-deadline)))
13559 (call-interactively 'org-deadline)))
13560 ((member property org-special-properties)
13561 (error "The %s property can not yet be set with `org-entry-put'"
13563 (t ; a non-special property
13564 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13565 (setq range (org-get-property-block beg end 'force))
13566 (goto-char (car range))
13567 (if (re-search-forward
13568 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13570 (delete-region (match-beginning 1) (match-end 1))
13571 (goto-char (match-beginning 1)))
13572 (goto-char (cdr range))
13575 (org-indent-line-function)
13576 (insert ":" property ":"))
13577 (and value (insert " " value))
13578 (org-indent-line-function)))))
13579 (run-hook-with-args 'org-property-changed-functions property value)))
13581 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13582 "Get all property keys in the current buffer.
13583 With INCLUDE-SPECIALS, also list the special properties that reflect things
13584 like tags and TODO state.
13585 With INCLUDE-DEFAULTS, also include properties that has special meaning
13586 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13587 With INCLUDE-COLUMNS, also include property names given in COLUMN
13588 formats in the current buffer."
13589 (let (rtn range cfmt s p)
13593 (goto-char (point-min))
13594 (while (re-search-forward org-property-start-re nil t)
13595 (setq range (org-get-property-block))
13596 (goto-char (car range))
13597 (while (re-search-forward
13598 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13600 (add-to-list 'rtn (org-match-string-no-properties 1)))
13601 (outline-next-heading))))
13603 (when include-specials
13604 (setq rtn (append org-special-properties rtn)))
13606 (when include-defaults
13607 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13608 (add-to-list 'rtn org-effort-property))
13610 (when include-columns
13614 (goto-char (point-min))
13615 (while (re-search-forward
13616 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13618 (setq cfmt (match-string 2) s 0)
13619 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13621 (setq s (match-end 0)
13622 p (match-string 1 cfmt))
13623 (unless (or (equal p "ITEM")
13624 (member p org-special-properties))
13625 (add-to-list 'rtn (match-string 1 cfmt))))))))
13627 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13629 (defun org-property-values (key)
13630 "Return a list of all values of property KEY."
13634 (goto-char (point-min))
13635 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13637 (while (re-search-forward re nil t)
13638 (add-to-list 'values (org-trim (match-string 1))))
13639 (delete "" values)))))
13641 (defun org-insert-property-drawer ()
13642 "Insert a property drawer into the current entry."
13644 (org-back-to-heading t)
13645 (looking-at outline-regexp)
13646 (let ((indent (if org-adapt-indentation
13647 (- (match-end 0)(match-beginning 0))
13650 (re (concat "^[ \t]*" org-keyword-time-regexp))
13652 (outline-next-heading)
13655 (while (re-search-forward re end t))
13656 (setq hiddenp (org-invisible-p))
13658 (and (equal (char-after) ?\n) (forward-char 1))
13659 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13660 (if (member (match-string 1) '("CLOCK:" ":END:"))
13661 ;; just skip this line
13662 (beginning-of-line 2)
13663 ;; Drawer start, find the end
13664 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13665 (beginning-of-line 1)))
13666 (org-skip-over-state-notes)
13667 (skip-chars-backward " \t\n\r")
13668 (if (eq (char-before) ?*) (forward-char 1))
13669 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13670 (beginning-of-line 0)
13671 (org-indent-to-column indent)
13672 (beginning-of-line 2)
13673 (org-indent-to-column indent)
13674 (beginning-of-line 0)
13677 (org-back-to-heading t)
13679 (org-flag-drawer t))))
13681 (defun org-set-property (property value)
13682 "In the current entry, set PROPERTY to VALUE.
13683 When called interactively, this will prompt for a property name, offering
13684 completion on existing and default properties. And then it will prompt
13685 for a value, offering completion either on allowed values (via an inherited
13686 xxx_ALL property) or on existing values in other instances of this property
13687 in the current file."
13689 (let* ((completion-ignore-case t)
13690 (keys (org-buffer-property-keys nil t t))
13691 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13692 (prop (if (member prop0 keys)
13694 (or (cdr (assoc (downcase prop0)
13695 (mapcar (lambda (x) (cons (downcase x) x))
13698 (cur (org-entry-get nil prop))
13699 (prompt (concat prop " value"
13700 (if (and cur (string-match "\\S-" cur))
13701 (concat " [" cur "]") "") ": "))
13702 (allowed (org-property-get-allowed-values nil prop 'table))
13703 (existing (mapcar 'list (org-property-values prop)))
13705 (org-completing-read prompt allowed nil
13706 (not (get-text-property 0 'org-unrestricted
13708 (let (org-completion-use-ido org-completion-use-iswitchb)
13709 (org-completing-read prompt existing nil nil "" nil cur)))))
13710 (list prop (if (equal val "") cur val))))
13711 (unless (equal (org-entry-get nil property) value)
13712 (org-entry-put nil property value)))
13714 (defun org-delete-property (property)
13715 "In the current entry, delete PROPERTY."
13717 (let* ((completion-ignore-case t)
13718 (prop (org-icompleting-read "Property: "
13719 (org-entry-properties nil 'standard))))
13721 (message "Property %s %s" property
13722 (if (org-entry-delete nil property)
13724 "was not present in the entry")))
13726 (defun org-delete-property-globally (property)
13727 "Remove PROPERTY globally, from all entries."
13729 (let* ((completion-ignore-case t)
13730 (prop (org-icompleting-read
13731 "Globally remove property: "
13732 (mapcar 'list (org-buffer-property-keys)))))
13737 (goto-char (point-min))
13739 (while (re-search-forward
13740 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13742 (setq cnt (1+ cnt))
13743 (replace-match ""))
13744 (message "Property \"%s\" removed from %d entries" property cnt)))))
13746 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13748 (defun org-compute-property-at-point ()
13749 "Compute the property at point.
13750 This looks for an enclosing column format, extracts the operator and
13751 then applies it to the property in the column format's scope."
13753 (unless (org-at-property-p)
13754 (error "Not at a property"))
13755 (let ((prop (org-match-string-no-properties 2)))
13756 (org-columns-get-format-and-top-level)
13757 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13758 (error "No operator defined for property %s" prop))
13759 (org-columns-compute prop)))
13761 (defvar org-property-allowed-value-functions nil
13762 "Hook for functions supplying allowed values for a specific property.
13763 The functions must take a single argument, the name of the property, and
13764 return a flat list of allowed values. If \":ETC\" is one of
13765 the values, this means that these values are intended as defaults for
13766 completion, but that other values should be allowed too.
13767 The functions must return nil if they are not responsible for this
13770 (defun org-property-get-allowed-values (pom property &optional table)
13771 "Get allowed values for the property PROPERTY.
13772 When TABLE is non-nil, return an alist that can directly be used for
13776 ((equal property "TODO")
13777 (setq vals (org-with-point-at pom
13778 (append org-todo-keywords-1 '("")))))
13779 ((equal property "PRIORITY")
13780 (let ((n org-lowest-priority))
13781 (while (>= n org-highest-priority)
13782 (push (char-to-string n) vals)
13784 ((member property org-special-properties))
13785 ((setq vals (run-hook-with-args-until-success
13786 'org-property-allowed-value-functions property)))
13788 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13789 (when (and vals (string-match "\\S-" vals))
13790 (setq vals (car (read-from-string (concat "(" vals ")"))))
13791 (setq vals (mapcar (lambda (x)
13792 (cond ((stringp x) x)
13793 ((numberp x) (number-to-string x))
13794 ((symbolp x) (symbol-name x))
13797 (when (member ":ETC" vals)
13798 (setq vals (remove ":ETC" vals))
13799 (org-add-props (car vals) '(org-unrestricted t)))
13800 (if table (mapcar 'list vals) vals)))
13802 (defun org-property-previous-allowed-value (&optional previous)
13803 "Switch to the next allowed value for this property."
13805 (org-property-next-allowed-value t))
13807 (defun org-property-next-allowed-value (&optional previous)
13808 "Switch to the next allowed value for this property."
13810 (unless (org-at-property-p)
13811 (error "Not at a property"))
13812 (let* ((key (match-string 2))
13813 (value (match-string 3))
13814 (allowed (or (org-property-get-allowed-values (point) key)
13815 (and (member value '("[ ]" "[-]" "[X]"))
13819 (error "Allowed values for this property have not been defined"))
13820 (if previous (setq allowed (reverse allowed)))
13821 (if (member value allowed)
13822 (setq nval (car (cdr (member value allowed)))))
13823 (setq nval (or nval (car allowed)))
13824 (if (equal nval value)
13825 (error "Only one allowed value for this property"))
13826 (org-at-property-p)
13827 (replace-match (concat " :" key ": " nval) t t)
13828 (org-indent-line-function)
13829 (beginning-of-line 1)
13830 (skip-chars-forward " \t")
13831 (run-hook-with-args 'org-property-changed-functions key nval)))
13833 (defun org-find-olp (path &optional this-buffer)
13834 "Return a marker pointing to the entry at outline path OLP.
13835 If anything goes wrong, throw an error.
13836 You can wrap this call to cathc the error like this:
13838 (condition-case msg
13839 (org-mobile-locate-entry (match-string 4))
13840 (error (nth 1 msg)))
13842 The return value will then be either a string with the error message,
13843 or a marker if everyhing is OK.
13845 If THIS-BUFFER is set, the putline path does not contain a file,
13847 (let* ((file (if this-buffer buffer-file-name (pop path)))
13848 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
13852 limit re end found pos heading cnt)
13853 (unless buffer (error "File not found :%s" file))
13854 (with-current-buffer buffer
13858 (setq limit (point-max))
13859 (goto-char (point-min))
13860 (while (setq heading (pop path))
13861 (setq re (format org-complex-heading-regexp-format
13862 (regexp-quote heading)))
13863 (setq cnt 0 pos (point))
13864 (while (re-search-forward re end t)
13865 (setq level (- (match-end 1) (match-beginning 1)))
13866 (if (and (>= level lmin) (<= level lmax))
13867 (setq found (match-beginning 0) cnt (1+ cnt))))
13868 (when (= cnt 0) (error "Heading not found on level %d: %s"
13870 (when (> cnt 1) (error "Heading not unique on level %d: %s"
13873 (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0)))
13874 (setq end (save-excursion (org-end-of-subtree t t))))
13875 (when (org-on-heading-p)
13876 (move-marker (make-marker) (point))))))))
13878 (defun org-find-entry-with-id (ident)
13879 "Locate the entry that contains the ID property with exact value IDENT.
13880 IDENT can be a string, a symbol or a number, this function will search for
13881 the string representation of it.
13882 Return the position where this entry starts, or nil if there is no such entry."
13883 (interactive "sID: ")
13885 ((stringp ident) ident)
13886 ((symbol-name ident) (symbol-name ident))
13887 ((numberp ident) (number-to-string ident))
13888 (t (error "IDENT %s must be a string, symbol or number" ident))))
13889 (case-fold-search nil))
13893 (goto-char (point-min))
13894 (when (re-search-forward
13895 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13897 (org-back-to-heading t)
13902 (defvar org-last-changed-timestamp nil)
13903 (defvar org-last-inserted-timestamp nil
13904 "The last time stamp inserted with `org-insert-time-stamp'.")
13905 (defvar org-time-was-given) ; dynamically scoped parameter
13906 (defvar org-end-time-was-given) ; dynamically scoped parameter
13907 (defvar org-ts-what) ; dynamically scoped parameter
13909 (defun org-time-stamp (arg &optional inactive)
13910 "Prompt for a date/time and insert a time stamp.
13911 If the user specifies a time like HH:MM, or if this command is called
13912 with a prefix argument, the time stamp will contain date and time.
13913 Otherwise, only the date will be included. All parts of a date not
13914 specified by the user will be filled in from the current date/time.
13915 So if you press just return without typing anything, the time stamp
13916 will represent the current date/time. If there is already a timestamp
13917 at the cursor, it will be modified."
13921 ;; Default time is either today, or, when entering a range,
13922 ;; the range start.
13923 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13925 (re-search-backward
13926 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13927 (- (point) 20) t)))
13928 (apply 'encode-time (org-parse-time-string (match-string 1)))
13930 (default-input (and ts (org-get-compact-tod ts)))
13931 org-time-was-given org-end-time-was-given time)
13933 ((and (org-at-timestamp-p t)
13934 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13935 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13937 (setq time (let ((this-command this-command))
13938 (org-read-date arg 'totime nil nil
13939 default-time default-input)))
13940 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13941 ((org-at-timestamp-p t)
13942 (setq time (let ((this-command this-command))
13943 (org-read-date arg 'totime nil nil default-time default-input)))
13944 (when (org-at-timestamp-p t) ; just to get the match data
13945 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13947 (setq org-last-changed-timestamp
13948 (org-insert-time-stamp
13949 time (or org-time-was-given arg)
13950 inactive nil nil (list org-end-time-was-given))))
13951 (message "Timestamp updated"))
13953 (setq time (let ((this-command this-command))
13954 (org-read-date arg 'totime nil nil default-time default-input)))
13955 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13956 nil nil (list org-end-time-was-given))))))
13958 ;; FIXME: can we use this for something else, like computing time differences?
13959 (defun org-get-compact-tod (s)
13960 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13961 (let* ((t1 (match-string 1 s))
13962 (h1 (string-to-number (match-string 2 s)))
13963 (m1 (string-to-number (match-string 3 s)))
13964 (t2 (and (match-end 4) (match-string 5 s)))
13965 (h2 (and t2 (string-to-number (match-string 6 s))))
13966 (m2 (and t2 (string-to-number (match-string 7 s))))
13970 (setq dh (- h2 h1) dm (- m2 m1))
13971 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13972 (concat t1 "+" (number-to-string dh)
13973 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13975 (defun org-time-stamp-inactive (&optional arg)
13976 "Insert an inactive time stamp.
13977 An inactive time stamp is enclosed in square brackets instead of angle
13978 brackets. It is inactive in the sense that it does not trigger agenda entries,
13979 does not link to the calendar and cannot be changed with the S-cursor keys.
13980 So these are more for recording a certain time/date."
13982 (org-time-stamp arg 'inactive))
13984 (defvar org-date-ovl (make-overlay 1 1))
13985 (overlay-put org-date-ovl 'face 'org-warning)
13986 (org-detach-overlay org-date-ovl)
13988 (defvar org-ans1) ; dynamically scoped parameter
13989 (defvar org-ans2) ; dynamically scoped parameter
13991 (defvar org-plain-time-of-day-regexp) ; defined below
13993 (defvar org-overriding-default-time nil) ; dynamically scoped
13994 (defvar org-read-date-overlay nil)
13995 (defvar org-dcst nil) ; dynamically scoped
13996 (defvar org-read-date-history nil)
13997 (defvar org-read-date-final-answer nil)
13999 (defun org-read-date (&optional with-time to-time from-string prompt
14000 default-time default-input)
14001 "Read a date, possibly a time, and make things smooth for the user.
14002 The prompt will suggest to enter an ISO date, but you can also enter anything
14003 which will at least partially be understood by `parse-time-string'.
14004 Unrecognized parts of the date will default to the current day, month, year,
14005 hour and minute. If this command is called to replace a timestamp at point,
14006 of to enter the second timestamp of a range, the default time is taken
14007 from the existing stamp. Furthermore, the command prefers the future,
14008 so if you are giving a date where the year is not given, and the day-month
14009 combination is already past in the current year, it will assume you
14010 mean next year. For details, see the manual. A few examples:
14012 3-2-5 --> 2003-02-05
14013 feb 15 --> currentyear-02-15
14014 2/15 --> currentyear-02-15
14015 sep 12 9 --> 2009-09-12
14016 12:45 --> today 12:45
14017 22 sept 0:34 --> currentyear-09-22 0:34
14018 12 --> currentyear-currentmonth-12
14019 Fri --> nearest Friday (today or later)
14022 Furthermore you can specify a relative date by giving, as the *first* thing
14023 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
14024 change in days weeks, months, years.
14025 With a single plus or minus, the date is relative to today. With a double
14026 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
14027 +4d --> four days from today
14028 +4 --> same as above
14029 +2w --> two weeks from today
14030 ++5 --> five days from default date
14032 The function understands only English month and weekday abbreviations,
14033 but this can be configured with the variables `parse-time-months' and
14034 `parse-time-weekdays'.
14036 While prompting, a calendar is popped up - you can also select the
14037 date with the mouse (button 1). The calendar shows a period of three
14038 months. To scroll it to other months, use the keys `>' and `<'.
14039 If you don't like the calendar, turn it off with
14040 \(setq org-read-date-popup-calendar nil)
14042 With optional argument TO-TIME, the date will immediately be converted
14043 to an internal time.
14044 With an optional argument WITH-TIME, the prompt will suggest to also
14045 insert a time. Note that when WITH-TIME is not set, you can still
14046 enter a time, and this function will inform the calling routine about
14047 this change. The calling routine may then choose to change the format
14048 used to insert the time stamp into the buffer to include the time.
14049 With optional argument FROM-STRING, read from this string instead from
14050 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
14051 the time/date that is used for everything that is not specified by the
14053 (require 'parse-time)
14054 (let* ((org-time-stamp-rounding-minutes
14055 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
14056 (org-dcst org-display-custom-times)
14057 (ct (org-current-time))
14058 (def (or org-overriding-default-time default-time ct))
14059 (defdecode (decode-time def))
14061 (when (< (nth 2 defdecode) org-extend-today-until)
14062 (setcar (nthcdr 2 defdecode) -1)
14063 (setcar (nthcdr 1 defdecode) 59)
14064 (setq def (apply 'encode-time defdecode)
14065 defdecode (decode-time def)))))
14066 (calendar-frame-setup nil)
14067 (calendar-setup nil)
14068 (calendar-move-hook nil)
14069 (calendar-view-diary-initially-flag nil)
14070 (calendar-view-holidays-initially-flag nil)
14071 (timestr (format-time-string
14072 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
14073 (prompt (concat (if prompt (concat prompt " ") "")
14074 (format "Date+time [%s]: " timestr)))
14075 ans (org-ans0 "") org-ans1 org-ans2 final)
14078 (from-string (setq ans from-string))
14079 (org-read-date-popup-calendar
14081 (save-window-excursion
14083 (calendar-forward-day (- (time-to-days def)
14084 (calendar-absolute-from-gregorian
14085 (calendar-current-date))))
14086 (org-eval-in-calendar nil t)
14087 (let* ((old-map (current-local-map))
14088 (map (copy-keymap calendar-mode-map))
14089 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
14090 (org-defkey map (kbd "RET") 'org-calendar-select)
14091 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
14092 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
14093 (org-defkey minibuffer-local-map [(meta shift left)]
14094 (lambda () (interactive)
14095 (org-eval-in-calendar '(calendar-backward-month 1))))
14096 (org-defkey minibuffer-local-map [(meta shift right)]
14097 (lambda () (interactive)
14098 (org-eval-in-calendar '(calendar-forward-month 1))))
14099 (org-defkey minibuffer-local-map [(meta shift up)]
14100 (lambda () (interactive)
14101 (org-eval-in-calendar '(calendar-backward-year 1))))
14102 (org-defkey minibuffer-local-map [(meta shift down)]
14103 (lambda () (interactive)
14104 (org-eval-in-calendar '(calendar-forward-year 1))))
14105 (org-defkey minibuffer-local-map [?\e (shift left)]
14106 (lambda () (interactive)
14107 (org-eval-in-calendar '(calendar-backward-month 1))))
14108 (org-defkey minibuffer-local-map [?\e (shift right)]
14109 (lambda () (interactive)
14110 (org-eval-in-calendar '(calendar-forward-month 1))))
14111 (org-defkey minibuffer-local-map [?\e (shift up)]
14112 (lambda () (interactive)
14113 (org-eval-in-calendar '(calendar-backward-year 1))))
14114 (org-defkey minibuffer-local-map [?\e (shift down)]
14115 (lambda () (interactive)
14116 (org-eval-in-calendar '(calendar-forward-year 1))))
14117 (org-defkey minibuffer-local-map [(shift up)]
14118 (lambda () (interactive)
14119 (org-eval-in-calendar '(calendar-backward-week 1))))
14120 (org-defkey minibuffer-local-map [(shift down)]
14121 (lambda () (interactive)
14122 (org-eval-in-calendar '(calendar-forward-week 1))))
14123 (org-defkey minibuffer-local-map [(shift left)]
14124 (lambda () (interactive)
14125 (org-eval-in-calendar '(calendar-backward-day 1))))
14126 (org-defkey minibuffer-local-map [(shift right)]
14127 (lambda () (interactive)
14128 (org-eval-in-calendar '(calendar-forward-day 1))))
14129 (org-defkey minibuffer-local-map ">"
14130 (lambda () (interactive)
14131 (org-eval-in-calendar '(scroll-calendar-left 1))))
14132 (org-defkey minibuffer-local-map "<"
14133 (lambda () (interactive)
14134 (org-eval-in-calendar '(scroll-calendar-right 1))))
14135 (org-defkey minibuffer-local-map "\C-v"
14136 (lambda () (interactive)
14137 (org-eval-in-calendar
14138 '(calendar-scroll-left-three-months 1))))
14139 (org-defkey minibuffer-local-map "\M-v"
14140 (lambda () (interactive)
14141 (org-eval-in-calendar
14142 '(calendar-scroll-right-three-months 1))))
14143 (run-hooks 'org-read-date-minibuffer-setup-hook)
14146 (use-local-map map)
14147 (add-hook 'post-command-hook 'org-read-date-display)
14148 (setq org-ans0 (read-string prompt default-input
14149 'org-read-date-history nil))
14150 ;; org-ans0: from prompt
14151 ;; org-ans1: from mouse click
14152 ;; org-ans2: from calendar motion
14153 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
14154 (remove-hook 'post-command-hook 'org-read-date-display)
14155 (use-local-map old-map)
14156 (when org-read-date-overlay
14157 (delete-overlay org-read-date-overlay)
14158 (setq org-read-date-overlay nil)))))))
14160 (t ; Naked prompt only
14162 (setq ans (read-string prompt default-input
14163 'org-read-date-history timestr))
14164 (when org-read-date-overlay
14165 (delete-overlay org-read-date-overlay)
14166 (setq org-read-date-overlay nil)))))
14168 (setq final (org-read-date-analyze ans def defdecode))
14169 (setq org-read-date-final-answer ans)
14172 (apply 'encode-time final)
14173 (if (and (boundp 'org-time-was-given) org-time-was-given)
14174 (format "%04d-%02d-%02d %02d:%02d"
14175 (nth 5 final) (nth 4 final) (nth 3 final)
14176 (nth 2 final) (nth 1 final))
14177 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
14182 (defvar org-read-date-analyze-futurep nil)
14183 (defun org-read-date-display ()
14184 "Display the current date prompt interpretation in the minibuffer."
14185 (when org-read-date-display-live
14186 (when org-read-date-overlay
14187 (delete-overlay org-read-date-overlay))
14190 (while (not (equal (buffer-substring
14191 (max (point-min) (- (point) 4)) (point))
14195 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
14196 " " (or org-ans1 org-ans2)))
14197 (org-end-time-was-given nil)
14198 (f (org-read-date-analyze ans def defdecode))
14200 org-time-stamp-custom-formats
14201 org-time-stamp-formats))
14202 (fmt (if (or with-time
14203 (and (boundp 'org-time-was-given) org-time-was-given))
14206 (txt (concat "=> " (format-time-string fmt (apply 'encode-time f)))))
14207 (when (and org-end-time-was-given
14208 (string-match org-plain-time-of-day-regexp txt))
14209 (setq txt (concat (substring txt 0 (match-end 0)) "-"
14210 org-end-time-was-given
14211 (substring txt (match-end 0)))))
14212 (when org-read-date-analyze-futurep
14213 (setq txt (concat txt " (=>F)")))
14214 (setq org-read-date-overlay
14215 (make-overlay (1- (point-at-eol)) (point-at-eol)))
14216 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
14218 (defun org-read-date-analyze (ans def defdecode)
14219 "Analyse the combined answer of the date prompt."
14220 ;; FIXME: cleanup and comment
14221 (let ((nowdecode (decode-time (current-time)))
14222 delta deltan deltaw deltadef year month day
14223 hour minute second wday pm h2 m2 tl wday1
14224 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
14225 (setq org-read-date-analyze-futurep nil)
14226 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
14229 (when (setq delta (org-read-date-get-relative ans (current-time) def))
14230 (setq ans (replace-match "" t t ans)
14232 deltaw (nth 1 delta)
14233 deltadef (nth 2 delta)))
14235 ;; Check if there is an iso week date in there
14236 ;; If yes, store the info and postpone interpreting it until the rest
14237 ;; of the parsing is done
14238 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
14239 (setq iso-year (if (match-end 1)
14240 (org-small-year-to-year
14241 (string-to-number (match-string 1 ans))))
14242 iso-weekday (if (match-end 3)
14243 (string-to-number (match-string 3 ans)))
14244 iso-week (string-to-number (match-string 2 ans)))
14245 (setq ans (replace-match "" t t ans)))
14247 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
14248 (when (string-match
14249 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
14250 (setq year (if (match-end 2)
14251 (string-to-number (match-string 2 ans))
14252 (progn (setq kill-year t)
14253 (string-to-number (format-time-string "%Y"))))
14254 month (string-to-number (match-string 3 ans))
14255 day (string-to-number (match-string 4 ans)))
14256 (if (< year 100) (setq year (+ 2000 year)))
14257 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14259 ;; Help matching american dates, like 5/30 or 5/30/7
14260 (when (string-match
14261 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
14262 (setq year (if (match-end 4)
14263 (string-to-number (match-string 4 ans))
14264 (progn (setq kill-year t)
14265 (string-to-number (format-time-string "%Y"))))
14266 month (string-to-number (match-string 1 ans))
14267 day (string-to-number (match-string 2 ans)))
14268 (if (< year 100) (setq year (+ 2000 year)))
14269 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14271 ;; Help matching am/pm times, because `parse-time-string' does not do that.
14272 ;; If there is a time with am/pm, and *no* time without it, we convert
14273 ;; so that matching will be successful.
14274 (loop for i from 1 to 2 do ; twice, for end time as well
14275 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
14276 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
14277 (setq hour (string-to-number (match-string 1 ans))
14278 minute (if (match-end 3)
14279 (string-to-number (match-string 3 ans))
14282 (string-to-char (downcase (match-string 4 ans)))))
14283 (if (and (= hour 12) (not pm))
14285 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
14286 (setq ans (replace-match (format "%02d:%02d" hour minute)
14289 ;; Check if a time range is given as a duration
14290 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
14291 (setq hour (string-to-number (match-string 1 ans))
14292 h2 (+ hour (string-to-number (match-string 3 ans)))
14293 minute (string-to-number (match-string 2 ans))
14294 m2 (+ minute (if (match-end 5) (string-to-number
14295 (match-string 5 ans))0)))
14296 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
14297 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
14300 ;; Check if there is a time range
14301 (when (boundp 'org-end-time-was-given)
14302 (setq org-time-was-given nil)
14303 (when (and (string-match org-plain-time-of-day-regexp ans)
14305 (setq org-end-time-was-given (match-string 8 ans))
14306 (setq ans (concat (substring ans 0 (match-beginning 7))
14307 (substring ans (match-end 7))))))
14309 (setq tl (parse-time-string ans)
14310 day (or (nth 3 tl) (nth 3 defdecode))
14311 month (or (nth 4 tl)
14312 (if (and org-read-date-prefer-future
14313 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
14314 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
14315 (nth 4 defdecode)))
14316 year (or (and (not kill-year) (nth 5 tl))
14317 (if (and org-read-date-prefer-future
14318 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
14319 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
14320 (nth 5 defdecode)))
14321 hour (or (nth 2 tl) (nth 2 defdecode))
14322 minute (or (nth 1 tl) (nth 1 defdecode))
14323 second (or (nth 0 tl) 0)
14326 (when (and (eq org-read-date-prefer-future 'time)
14327 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
14328 (equal day (nth 3 nowdecode))
14329 (equal month (nth 4 nowdecode))
14330 (equal year (nth 5 nowdecode))
14332 (or (< (nth 2 tl) (nth 2 nowdecode))
14333 (and (= (nth 2 tl) (nth 2 nowdecode))
14335 (< (nth 1 tl) (nth 1 nowdecode)))))
14339 ;; Special date definitions below
14342 ;; There was an iso week
14345 (setq year (or iso-year year)
14346 day (or iso-weekday wday 1)
14347 wday nil ; to make sure that the trigger below does not match
14348 iso-date (calendar-gregorian-from-absolute
14349 (calendar-absolute-from-iso
14350 (list iso-week day year))))
14351 ; FIXME: Should we also push ISO weeks into the future?
14352 ; (when (and org-read-date-prefer-future
14354 ; (< (calendar-absolute-from-gregorian iso-date)
14355 ; (time-to-days (current-time))))
14356 ; (setq year (1+ year)
14357 ; iso-date (calendar-gregorian-from-absolute
14358 ; (calendar-absolute-from-iso
14359 ; (list iso-week day year)))))
14360 (setq month (car iso-date)
14361 year (nth 2 iso-date)
14362 day (nth 1 iso-date)))
14366 (let ((now (decode-time (current-time))))
14367 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
14368 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
14369 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
14370 ((equal deltaw "m") (setq month (+ month deltan)))
14371 ((equal deltaw "y") (setq year (+ year deltan)))))
14372 ((and wday (not (nth 3 tl)))
14374 ;; Weekday was given, but no day, so pick that day in the week
14375 ;; on or after the derived date.
14376 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
14377 (unless (equal wday wday1)
14378 (setq day (+ day (% (- wday wday1 -7) 7))))))
14379 (if (and (boundp 'org-time-was-given)
14381 (setq org-time-was-given t))
14382 (if (< year 100) (setq year (+ 2000 year)))
14383 (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
14384 (setq org-read-date-analyze-futurep futurep)
14385 (list second minute hour day month year)))
14387 (defvar parse-time-weekdays)
14389 (defun org-read-date-get-relative (s today default)
14390 "Check string S for special relative date string.
14391 TODAY and DEFAULT are internal times, for today and for a default.
14392 Return shift list (N what def-flag)
14393 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
14394 N is the number of WHATs to shift.
14395 DEF-FLAG is t when a double ++ or -- indicates shift relative to
14396 the DEFAULT date rather than TODAY."
14400 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
14402 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
14403 "\\([ \t]\\|$\\)") s)
14404 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
14405 (let* ((dir (if (> (match-end 1) (match-beginning 1))
14406 (string-to-char (substring (match-string 1 s) -1))
14408 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
14409 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
14410 (what (if (match-end 3) (match-string 3 s) "d"))
14411 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
14412 (date (if rel default today))
14413 (wday (nth 6 (decode-time date)))
14417 (setq delta (mod (+ 7 (- wday1 wday)) 7))
14418 (if (= dir ?-) (setq delta (- delta 7)))
14419 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
14420 (list delta "d" rel))
14421 (list (* n (if (= dir ?-) -1 1)) what rel)))))
14423 (defun org-order-calendar-date-args (arg1 arg2 arg3)
14424 "Turn a user-specified date into the internal representation.
14425 The internal representation needed by the calendar is (month day year).
14426 This is a wrapper to handle the brain-dead convention in calendar that
14427 user function argument order change dependent on argument order."
14428 (if (boundp 'calendar-date-style)
14430 ((eq calendar-date-style 'american)
14431 (list arg1 arg2 arg3))
14432 ((eq calendar-date-style 'european)
14433 (list arg2 arg1 arg3))
14434 ((eq calendar-date-style 'iso)
14435 (list arg2 arg3 arg1)))
14436 (if (org-bound-and-true-p european-calendar-style)
14437 (list arg2 arg1 arg3)
14438 (list arg1 arg2 arg3))))
14440 (defun org-eval-in-calendar (form &optional keepdate)
14441 "Eval FORM in the calendar window and return to current window.
14442 Also, store the cursor date in variable org-ans2."
14443 (let ((sf (selected-frame))
14444 (sw (selected-window)))
14445 (select-window (get-buffer-window "*Calendar*" t))
14447 (when (and (not keepdate) (calendar-cursor-to-date))
14448 (let* ((date (calendar-cursor-to-date))
14449 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14450 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
14451 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
14453 (org-select-frame-set-input-focus sf)))
14455 (defun org-calendar-select ()
14456 "Return to `org-read-date' with the date currently selected.
14457 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14459 (when (calendar-cursor-to-date)
14460 (let* ((date (calendar-cursor-to-date))
14461 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14462 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14463 (if (active-minibuffer-window) (exit-minibuffer))))
14465 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
14466 "Insert a date stamp for the date given by the internal TIME.
14467 WITH-HM means use the stamp format that includes the time of the day.
14468 INACTIVE means use square brackets instead of angular ones, so that the
14469 stamp will not contribute to the agenda.
14470 PRE and POST are optional strings to be inserted before and after the
14472 The command returns the inserted time stamp."
14473 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
14475 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
14476 (insert-before-markers (or pre ""))
14477 (insert-before-markers (setq stamp (format-time-string fmt time)))
14478 (when (listp extra)
14479 (setq extra (car extra))
14480 (if (and (stringp extra)
14481 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
14482 (setq extra (format "-%02d:%02d"
14483 (string-to-number (match-string 1 extra))
14484 (string-to-number (match-string 2 extra))))
14488 (insert-before-markers extra)
14490 (insert-before-markers (or post ""))
14491 (setq org-last-inserted-timestamp stamp)))
14493 (defun org-toggle-time-stamp-overlays ()
14494 "Toggle the use of custom time stamp formats."
14496 (setq org-display-custom-times (not org-display-custom-times))
14497 (unless org-display-custom-times
14498 (let ((p (point-min)) (bmp (buffer-modified-p)))
14499 (while (setq p (next-single-property-change p 'display))
14500 (if (and (get-text-property p 'display)
14501 (eq (get-text-property p 'face) 'org-date))
14502 (remove-text-properties
14503 p (setq p (next-single-property-change p 'display))
14505 (set-buffer-modified-p bmp)))
14506 (if (featurep 'xemacs)
14507 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
14508 (org-restart-font-lock)
14509 (setq org-table-may-need-update t)
14510 (if org-display-custom-times
14511 (message "Time stamps are overlayed with custom format")
14512 (message "Time stamp overlays removed")))
14514 (defun org-display-custom-time (beg end)
14515 "Overlay modified time stamp format over timestamp between BEG and END."
14516 (let* ((ts (buffer-substring beg end))
14517 t1 w1 with-hm tf time str w2 (off 0))
14519 (setq t1 (org-parse-time-string ts t))
14520 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
14521 (setq off (- (match-end 0) (match-beginning 0)))))
14522 (setq end (- end off))
14523 (setq w1 (- end beg)
14524 with-hm (and (nth 1 t1) (nth 2 t1))
14525 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
14526 time (org-fix-decoded-time t1)
14528 (format-time-string
14529 (substring tf 1 -1) (apply 'encode-time time))
14530 nil 'mouse-face 'highlight)
14532 (if (not (= w2 w1))
14533 (add-text-properties (1+ beg) (+ 2 beg)
14534 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
14535 (if (featurep 'xemacs)
14537 (put-text-property beg end 'invisible t)
14538 (put-text-property beg end 'end-glyph (make-glyph str)))
14539 (put-text-property beg end 'display str))))
14541 (defun org-translate-time (string)
14542 "Translate all timestamps in STRING to custom format.
14543 But do this only if the variable `org-display-custom-times' is set."
14544 (when org-display-custom-times
14547 (re org-ts-regexp-both)
14548 t1 with-hm inactive tf time str beg end)
14549 (while (setq start (string-match re string start))
14550 (setq beg (match-beginning 0)
14552 t1 (save-match-data
14553 (org-parse-time-string (substring string beg end) t))
14554 with-hm (and (nth 1 t1) (nth 2 t1))
14555 inactive (equal (substring string beg (1+ beg)) "[")
14556 tf (funcall (if with-hm 'cdr 'car)
14557 org-time-stamp-custom-formats)
14558 time (org-fix-decoded-time t1)
14559 str (format-time-string
14561 (if inactive "[" "<") (substring tf 1 -1)
14562 (if inactive "]" ">"))
14563 (apply 'encode-time time))
14564 string (replace-match str t t string)
14565 start (+ start (length str)))))))
14568 (defun org-fix-decoded-time (time)
14569 "Set 0 instead of nil for the first 6 elements of time.
14570 Don't touch the rest."
14572 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
14574 (defun org-days-to-time (timestamp-string)
14575 "Difference between TIMESTAMP-STRING and now in days."
14576 (- (time-to-days (org-time-string-to-time timestamp-string))
14577 (time-to-days (current-time))))
14579 (defun org-deadline-close (timestamp-string &optional ndays)
14580 "Is the time in TIMESTAMP-STRING close to the current date?"
14581 (setq ndays (or ndays (org-get-wdays timestamp-string)))
14582 (and (< (org-days-to-time timestamp-string) ndays)
14583 (not (org-entry-is-done-p))))
14585 (defun org-get-wdays (ts)
14586 "Get the deadline lead time appropriate for timestring TS."
14588 ((<= org-deadline-warning-days 0)
14589 ;; 0 or negative, enforce this value no matter what
14590 (- org-deadline-warning-days))
14591 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
14592 ;; lead time is specified.
14593 (floor (* (string-to-number (match-string 1 ts))
14594 (cdr (assoc (match-string 2 ts)
14595 '(("d" . 1) ("w" . 7)
14596 ("m" . 30.4) ("y" . 365.25)))))))
14597 ;; go for the default.
14598 (t org-deadline-warning-days)))
14600 (defun org-calendar-select-mouse (ev)
14601 "Return to `org-read-date' with the date currently selected.
14602 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14604 (mouse-set-point ev)
14605 (when (calendar-cursor-to-date)
14606 (let* ((date (calendar-cursor-to-date))
14607 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14608 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14609 (if (active-minibuffer-window) (exit-minibuffer))))
14611 (defun org-check-deadlines (ndays)
14612 "Check if there are any deadlines due or past due.
14613 A deadline is considered due if it happens within `org-deadline-warning-days'
14614 days from today's date. If the deadline appears in an entry marked DONE,
14615 it is not shown. The prefix arg NDAYS can be used to test that many
14616 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14618 (let* ((org-warn-days
14620 ((equal ndays '(4)) 100000)
14621 (ndays (prefix-numeric-value ndays))
14622 (t (abs org-deadline-warning-days))))
14623 (case-fold-search nil)
14624 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
14626 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
14628 (message "%d deadlines past-due or due within %d days"
14629 (org-occur regexp nil callback)
14632 (defun org-check-before-date (date)
14633 "Check if there are deadlines or scheduled entries before DATE."
14634 (interactive (list (org-read-date)))
14635 (let ((case-fold-search nil)
14636 (regexp (concat "\\<\\(" org-deadline-string
14637 "\\|" org-scheduled-string
14638 "\\) *<\\([^>]+\\)>"))
14640 (lambda () (time-less-p
14641 (org-time-string-to-time (match-string 2))
14642 (org-time-string-to-time date)))))
14643 (message "%d entries before %s"
14644 (org-occur regexp nil callback) date)))
14646 (defun org-check-after-date (date)
14647 "Check if there are deadlines or scheduled entries after DATE."
14648 (interactive (list (org-read-date)))
14649 (let ((case-fold-search nil)
14650 (regexp (concat "\\<\\(" org-deadline-string
14651 "\\|" org-scheduled-string
14652 "\\) *<\\([^>]+\\)>"))
14656 (org-time-string-to-time (match-string 2))
14657 (org-time-string-to-time date))))))
14658 (message "%d entries after %s"
14659 (org-occur regexp nil callback) date)))
14661 (defun org-evaluate-time-range (&optional to-buffer)
14662 "Evaluate a time range by computing the difference between start and end.
14663 Normally the result is just printed in the echo area, but with prefix arg
14664 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14665 If the time range is actually in a table, the result is inserted into the
14667 For time difference computation, a year is assumed to be exactly 365
14668 days in order to avoid rounding problems."
14671 (org-clock-update-time-maybe)
14673 (unless (org-at-date-range-p t)
14674 (goto-char (point-at-bol))
14675 (re-search-forward org-tr-regexp-both (point-at-eol) t))
14676 (if (not (org-at-date-range-p t))
14677 (error "Not at a time-stamp range, and none found in current line")))
14678 (let* ((ts1 (match-string 1))
14679 (ts2 (match-string 2))
14680 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
14681 (match-end (match-end 0))
14682 (time1 (org-time-string-to-time ts1))
14683 (time2 (org-time-string-to-time ts2))
14684 (t1 (org-float-time time1))
14685 (t2 (org-float-time time2))
14686 (diff (abs (- t2 t1)))
14687 (negative (< (- t2 t1) 0))
14688 ;; (ys (floor (* 365 24 60 60)))
14691 (fy "%dy %dd %02d:%02d")
14693 (fd "%dd %02d:%02d")
14698 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14700 d (floor (/ diff ds)) diff (mod diff ds)
14701 h (floor (/ diff hs)) diff (mod diff hs)
14702 m (floor (/ diff 60)))
14703 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14705 d (floor (+ (/ diff ds) 0.5))
14707 (if (not to-buffer)
14708 (message "%s" (org-make-tdiff-string y d h m))
14709 (if (org-at-table-p)
14711 (goto-char match-end)
14713 (and (looking-at " *|") (goto-char (match-end 0))))
14714 (goto-char match-end))
14716 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14717 (replace-match ""))
14718 (if negative (insert " -"))
14719 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
14720 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
14721 (insert " " (format fh h m))))
14722 (if align (org-table-align))
14723 (message "Time difference inserted")))))
14725 (defun org-make-tdiff-string (y d h m)
14728 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
14730 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
14732 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
14734 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
14736 (apply 'format fmt (nreverse l))))
14738 (defun org-time-string-to-time (s)
14739 (apply 'encode-time (org-parse-time-string s)))
14740 (defun org-time-string-to-seconds (s)
14741 (org-float-time (org-time-string-to-time s)))
14743 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
14744 "Convert a time stamp to an absolute day number.
14745 If there is a specifyer for a cyclic time stamp, get the closest date to
14747 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14748 the variable date is bound by the calendar when this is called."
14750 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
14751 (if (org-diary-sexp-entry (match-string 1 s) "" date)
14754 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
14755 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
14756 (time-to-days (current-time))) (match-string 0 s)
14758 (t (time-to-days (apply 'encode-time (org-parse-time-string s))))))
14760 (defun org-days-to-iso-week (days)
14761 "Return the iso week number."
14763 (car (calendar-iso-from-absolute days)))
14765 (defun org-small-year-to-year (year)
14766 "Convert 2-digit years into 4-digit years.
14767 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14768 The year 2000 cannot be abbreviated. Any year larger than 99
14769 is returned unchanged."
14771 (setq year (+ 2000 year))
14773 (setq year (+ 1900 year))))
14776 (defun org-time-from-absolute (d)
14777 "Return the time corresponding to date D.
14778 D may be an absolute day number, or a calendar-type list (month day year)."
14779 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
14780 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
14782 (defun org-calendar-holiday ()
14783 "List of holidays, for Diary display in Org-mode."
14784 (require 'holidays)
14786 (if (fboundp 'calendar-check-holidays)
14787 'calendar-check-holidays 'check-calendar-holidays) date)))
14788 (if hl (mapconcat 'identity hl "; "))))
14790 (defun org-diary-sexp-entry (sexp entry date)
14791 "Process a SEXP diary ENTRY for DATE."
14792 (require 'diary-lib)
14793 (let ((result (if calendar-debug-sexp
14794 (let ((stack-trace-on-error t))
14795 (eval (car (read-from-string sexp))))
14796 (condition-case nil
14797 (eval (car (read-from-string sexp)))
14800 (message "Bad sexp at line %d in %s: %s"
14802 (buffer-file-name) sexp)
14804 (cond ((stringp result) result)
14805 ((and (consp result)
14806 (stringp (cdr result))) (cdr result))
14810 (defun org-diary-to-ical-string (frombuf)
14811 "Get iCalendar entries from diary entries in buffer FROMBUF.
14812 This uses the icalendar.el library."
14813 (let* ((tmpdir (if (featurep 'xemacs)
14815 temporary-file-directory))
14816 (tmpfile (make-temp-name
14817 (expand-file-name "orgics" tmpdir)))
14819 (with-current-buffer frombuf
14820 (icalendar-export-region (point-min) (point-max) tmpfile)
14821 (setq buf (find-buffer-visiting tmpfile))
14823 (goto-char (point-min))
14824 (if (re-search-forward "^BEGIN:VEVENT" nil t)
14825 (setq b (match-beginning 0)))
14826 (goto-char (point-max))
14827 (if (re-search-backward "^END:VEVENT" nil t)
14828 (setq e (match-end 0)))
14829 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
14831 (delete-file tmpfile)
14834 (defun org-closest-date (start current change prefer show-all)
14835 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14836 When PREFER is `past' return a date that is either CURRENT or past.
14837 When PREFER is `future', return a date that is either CURRENT or future.
14838 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14839 ;; Make the proper lists from the dates
14841 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
14842 dn dw sday cday n1 n2 n0
14843 d m y y1 y2 date1 date2 nmonths nm ny m2)
14845 (setq start (org-date-to-gregorian start)
14846 current (org-date-to-gregorian
14849 (time-to-days (current-time))))
14850 sday (calendar-absolute-from-gregorian start)
14851 cday (calendar-absolute-from-gregorian current))
14853 (if (<= cday sday) (throw 'exit sday))
14855 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
14856 (setq dn (string-to-number (match-string 1 change))
14857 dw (cdr (assoc (match-string 2 change) a1)))
14858 (error "Invalid change specifyer: %s" change))
14859 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
14862 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
14865 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
14866 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
14867 (setq date1 (list m d y1)
14868 n1 (calendar-absolute-from-gregorian date1)
14869 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
14870 n2 (calendar-absolute-from-gregorian date2)))
14872 ;; approx number of month between the two dates
14873 (setq nmonths (floor (/ (- cday sday) 30.436875)))
14874 ;; How often does dn fit in there?
14875 (setq d (nth 1 start) m (car start) y (nth 2 start)
14876 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
14878 ny (floor (/ m 12))
14881 (while (> m 12) (setq m (- m 12) y (1+ y)))
14882 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
14883 (setq m2 (+ m dn) y2 y)
14884 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14885 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
14886 (while (<= n2 cday)
14887 (setq n1 n2 m m2 y y2)
14888 (setq m2 (+ m dn) y2 y)
14889 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14890 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
14891 ;; Make sure n1 is the earlier date
14892 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
14895 ((eq prefer 'past) (if (= cday n2) n2 n1))
14896 ((eq prefer 'future) (if (= cday n1) n1 n2))
14897 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
14899 ((eq prefer 'past) (if (= cday n2) n2 n1))
14900 ((eq prefer 'future) (if (= cday n1) n1 n2))
14901 (t (if (= cday n1) n1 n2)))))))
14903 (defun org-date-to-gregorian (date)
14904 "Turn any specification of DATE into a gregorian date for the calendar."
14905 (cond ((integerp date) (calendar-gregorian-from-absolute date))
14906 ((and (listp date) (= (length date) 3)) date)
14908 (setq date (org-parse-time-string date))
14909 (list (nth 4 date) (nth 3 date) (nth 5 date)))
14911 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
14913 (defun org-parse-time-string (s &optional nodefault)
14914 "Parse the standard Org-mode time string.
14915 This should be a lot faster than the normal `parse-time-string'.
14916 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14917 hour and minute fields will be nil if not given."
14918 (if (string-match org-ts-regexp0 s)
14920 (if (or (match-beginning 8) (not nodefault))
14921 (string-to-number (or (match-string 8 s) "0")))
14922 (if (or (match-beginning 7) (not nodefault))
14923 (string-to-number (or (match-string 7 s) "0")))
14924 (string-to-number (match-string 4 s))
14925 (string-to-number (match-string 3 s))
14926 (string-to-number (match-string 2 s))
14928 (error "Not a standard Org-mode time string: %s" s)))
14930 (defun org-timestamp-up (&optional arg)
14931 "Increase the date item at the cursor by one.
14932 If the cursor is on the year, change the year. If it is on the month or
14933 the day, change that.
14934 With prefix ARG, change by that many units."
14936 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
14938 (defun org-timestamp-down (&optional arg)
14939 "Decrease the date item at the cursor by one.
14940 If the cursor is on the year, change the year. If it is on the month or
14941 the day, change that.
14942 With prefix ARG, change by that many units."
14944 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
14946 (defun org-timestamp-up-day (&optional arg)
14947 "Increase the date in the time stamp by one day.
14948 With prefix ARG, change that many days."
14950 (if (and (not (org-at-timestamp-p t))
14951 (org-on-heading-p))
14953 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
14955 (defun org-timestamp-down-day (&optional arg)
14956 "Decrease the date in the time stamp by one day.
14957 With prefix ARG, change that many days."
14959 (if (and (not (org-at-timestamp-p t))
14960 (org-on-heading-p))
14962 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
14964 (defun org-at-timestamp-p (&optional inactive-ok)
14965 "Determine if the cursor is in or at a timestamp."
14967 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
14969 (ans (or (looking-at tsr)
14971 (skip-chars-backward "^[<\n\r\t")
14972 (if (> (point) (point-min)) (backward-char 1))
14973 (and (looking-at tsr)
14974 (> (- (match-end 0) pos) -1))))))
14976 (boundp 'org-ts-what)
14979 ((= pos (match-beginning 0)) 'bracket)
14980 ((= pos (1- (match-end 0))) 'bracket)
14981 ((org-pos-in-match-range pos 2) 'year)
14982 ((org-pos-in-match-range pos 3) 'month)
14983 ((org-pos-in-match-range pos 7) 'hour)
14984 ((org-pos-in-match-range pos 8) 'minute)
14985 ((or (org-pos-in-match-range pos 4)
14986 (org-pos-in-match-range pos 5)) 'day)
14987 ((and (> pos (or (match-end 8) (match-end 5)))
14988 (< pos (match-end 0)))
14989 (- pos (or (match-end 8) (match-end 5))))
14993 (defun org-toggle-timestamp-type ()
14994 "Toggle the type (<active> or [inactive]) of a time stamp."
14996 (when (org-at-timestamp-p t)
14997 (let ((beg (match-beginning 0)) (end (match-end 0))
14998 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
15001 (while (re-search-forward "[][<>]" end t)
15002 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
15004 (message "Timestamp is now %sactive"
15005 (if (equal (char-after beg) ?<) "" "in")))))
15007 (defun org-timestamp-change (n &optional what updown)
15008 "Change the date in the time stamp at point.
15009 The date will be changed by N times WHAT. WHAT can be `day', `month',
15010 `year', `minute', `second'. If WHAT is not given, the cursor position
15011 in the timestamp determines what will be changed."
15012 (let ((pos (point))
15014 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
15018 (if (not (org-at-timestamp-p t))
15019 (error "Not at a timestamp"))
15020 (if (and (not what) (eq org-ts-what 'bracket))
15021 (org-toggle-timestamp-type)
15022 (if (and (not what) (not (eq org-ts-what 'day))
15023 org-display-custom-times
15024 (get-text-property (point) 'display)
15025 (not (get-text-property (1- (point)) 'display)))
15026 (setq org-ts-what 'day))
15027 (setq org-ts-what (or what org-ts-what)
15028 inactive (= (char-after (match-beginning 0)) ?\[)
15029 ts (match-string 0))
15032 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
15034 (setq extra (match-string 1 ts)))
15035 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
15037 (setq time0 (org-parse-time-string ts))
15039 (eq org-ts-what 'minute)
15040 (not current-prefix-arg))
15041 ;; This looks like s-up and s-down. Change by one rounding step.
15042 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
15043 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
15044 (setcar (cdr time0) (+ (nth 1 time0)
15045 (if (> n 0) (- rem) (- dm rem))))))
15047 (encode-time (or (car time0) 0)
15048 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
15049 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
15050 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
15051 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
15052 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
15054 (when (and (member org-ts-what '(hour minute))
15056 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
15057 (setq extra (org-modify-ts-extra
15059 (if (eq org-ts-what 'hour) 2 5)
15061 (when (integerp org-ts-what)
15062 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
15063 (if (eq what 'calendar)
15064 (let ((cal-date (org-get-date-from-calendar)))
15065 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
15066 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
15067 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
15068 (setcar time0 (or (car time0) 0))
15069 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
15070 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
15071 (setq time (apply 'encode-time time0))))
15072 (setq org-last-changed-timestamp
15073 (org-insert-time-stamp time with-hm inactive nil nil extra))
15074 (org-clock-update-time-maybe)
15076 ;; Try to recenter the calendar window, if any
15077 (if (and org-calendar-follow-timestamp-change
15078 (get-buffer-window "*Calendar*" t)
15079 (memq org-ts-what '(day month year)))
15080 (org-recenter-calendar (time-to-days time))))))
15082 (defun org-modify-ts-extra (s pos n dm)
15083 "Change the different parts of the lead-time and repeat fields in timestamp."
15084 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
15086 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
15088 ((or (org-pos-in-match-range pos 2)
15089 (org-pos-in-match-range pos 3))
15090 (setq m (string-to-number (match-string 3 s))
15091 h (string-to-number (match-string 2 s)))
15092 (if (org-pos-in-match-range pos 2)
15094 (setq n (* dm (org-no-warnings (signum n))))
15095 (when (not (= 0 (setq rem (% m dm))))
15096 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
15098 (if (< m 0) (setq m (+ m 60) h (1- h)))
15099 (if (> m 59) (setq m (- m 60) h (1+ h)))
15100 (setq h (min 24 (max 0 h)))
15101 (setq ng 1 new (format "-%02d:%02d" h m)))
15102 ((org-pos-in-match-range pos 6)
15103 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
15104 ((org-pos-in-match-range pos 5)
15105 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
15107 ((org-pos-in-match-range pos 9)
15108 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
15109 ((org-pos-in-match-range pos 8)
15110 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
15114 (substring s 0 (match-beginning ng))
15116 (substring s (match-end ng))))))
15119 (defun org-recenter-calendar (date)
15120 "If the calendar is visible, recenter it to DATE."
15121 (let* ((win (selected-window))
15122 (cwin (get-buffer-window "*Calendar*" t))
15123 (calendar-move-hook nil))
15125 (select-window cwin)
15126 (calendar-goto-date (if (listp date) date
15127 (calendar-gregorian-from-absolute date)))
15128 (select-window win))))
15130 (defun org-goto-calendar (&optional arg)
15131 "Go to the Emacs calendar at the current date.
15132 If there is a time stamp in the current line, go to that date.
15133 A prefix ARG can be used to force the current date."
15135 (let ((tsr org-ts-regexp) diff
15136 (calendar-move-hook nil)
15137 (calendar-view-holidays-initially-flag nil)
15138 (calendar-view-diary-initially-flag nil))
15139 (if (or (org-at-timestamp-p)
15141 (beginning-of-line 1)
15142 (looking-at (concat ".*" tsr))))
15143 (let ((d1 (time-to-days (current-time)))
15145 (org-time-string-to-time (match-string 1)))))
15146 (setq diff (- d2 d1))))
15148 (calendar-goto-today)
15149 (if (and diff (not arg)) (calendar-forward-day diff))))
15151 (defun org-get-date-from-calendar ()
15152 "Return a list (month day year) of date at point in calendar."
15153 (with-current-buffer "*Calendar*"
15155 (calendar-cursor-to-date))))
15157 (defun org-date-from-calendar ()
15158 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
15159 If there is already a time stamp at the cursor position, update it."
15161 (if (org-at-timestamp-p t)
15162 (org-timestamp-change 0 'calendar)
15163 (let ((cal-date (org-get-date-from-calendar)))
15164 (org-insert-time-stamp
15165 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
15167 (defun org-minutes-to-hh:mm-string (m)
15168 "Compute H:MM from a number of minutes."
15169 (let ((h (/ m 60)))
15170 (setq m (- m (* 60 h)))
15171 (format org-time-clocksum-format h m)))
15173 (defun org-hh:mm-string-to-minutes (s)
15174 "Convert a string H:MM to a number of minutes.
15175 If the string is just a number, interpret it as minutes.
15176 In fact, the first hh:mm or number in the string will be taken,
15177 there can be extra stuff in the string.
15178 If no number is found, the return value is 0."
15180 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
15181 (+ (* (string-to-number (match-string 1 s)) 60)
15182 (string-to-number (match-string 2 s))))
15183 ((string-match "\\([0-9]+\\)" s)
15184 (string-to-number (match-string 1 s)))
15189 (defun org-save-all-org-buffers ()
15190 "Save all Org-mode buffers without user confirmation."
15192 (message "Saving all Org-mode buffers...")
15193 (save-some-buffers t 'org-mode-p)
15194 (when (featurep 'org-id) (org-id-locations-save))
15195 (message "Saving all Org-mode buffers... done"))
15197 (defun org-revert-all-org-buffers ()
15198 "Revert all Org-mode buffers.
15199 Prompt for confirmation when there are unsaved changes.
15200 Be sure you know what you are doing before letting this function
15201 overwrite your changes.
15203 This function is useful in a setup where one tracks org files
15204 with a version control system, to revert on one machine after pulling
15205 changes from another. I believe the procedure must be like this:
15207 1. M-x org-save-all-org-buffers
15208 2. Pull changes from the other machine, resolve conflicts
15209 3. M-x org-revert-all-org-buffers"
15211 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
15214 (save-window-excursion
15217 (when (and (with-current-buffer b (org-mode-p))
15218 (with-current-buffer b buffer-file-name))
15219 (switch-to-buffer b)
15220 (revert-buffer t 'no-confirm)))
15222 (when (and (featurep 'org-id) org-id-track-globally)
15223 (org-id-locations-load)))))
15228 (defun org-iswitchb (&optional arg)
15229 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
15230 With a prefix argument, restrict available to files.
15231 With two prefix arguments, restrict available buffers to agenda files."
15233 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
15234 ((equal arg '(16)) (org-buffer-list 'agenda))
15235 (t (org-buffer-list)))))
15237 (org-icompleting-read "Org buffer: "
15238 (mapcar 'list (mapcar 'buffer-name blist))
15242 (defalias 'org-ido-switchb 'org-iswitchb)
15244 (defun org-buffer-list (&optional predicate exclude-tmp)
15245 "Return a list of Org buffers.
15246 PREDICATE can be `export', `files' or `agenda'.
15248 export restrict the list to Export buffers.
15249 files restrict the list to buffers visiting Org files.
15250 agenda restrict the list to buffers visiting agenda files.
15252 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
15254 (agenda-files (and (eq predicate 'agenda)
15255 (mapcar 'file-truename (org-agenda-files t))))
15258 ((eq predicate 'files)
15259 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
15260 ((eq predicate 'export)
15261 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
15262 ((eq predicate 'agenda)
15264 (with-current-buffer b
15265 (and (eq major-mode 'org-mode)
15266 (setq bfn (buffer-file-name b))
15267 (member (file-truename bfn) agenda-files)))))
15268 (t (lambda (b) (with-current-buffer b
15269 (or (eq major-mode 'org-mode)
15270 (string-match "\*Org .*Export"
15271 (buffer-name b)))))))))
15275 (if (and (funcall filter b)
15276 (or (not exclude-tmp)
15277 (not (string-match "tmp" (buffer-name b)))))
15282 (defun org-agenda-files (&optional unrestricted archives)
15283 "Get the list of agenda files.
15284 Optional UNRESTRICTED means return the full list even if a restriction
15285 is currently in place.
15286 When ARCHIVES is t, include all archive files that are really being
15287 used by the agenda files. If ARCHIVE is `ifmode', do this only if
15288 `org-agenda-archives-mode' is t."
15291 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
15292 ((stringp org-agenda-files) (org-read-agenda-file-list))
15293 ((listp org-agenda-files) org-agenda-files)
15294 (t (error "Invalid value of `org-agenda-files'")))))
15295 (setq files (apply 'append
15296 (mapcar (lambda (f)
15297 (if (file-directory-p f)
15299 f t org-agenda-file-regexp)
15302 (when org-agenda-skip-unavailable-files
15303 (setq files (delq nil
15306 (and (file-readable-p file) file)))
15308 (when (or (eq archives t)
15309 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
15310 (setq files (org-add-archive-files files)))
15313 (defun org-agenda-file-p (&optional file)
15314 "Return non-nil, if FILE is an agenda file.
15315 If FILE is omitted, use the file associated with the current
15317 (member (or file (buffer-file-name))
15318 (org-agenda-files t)))
15320 (defun org-edit-agenda-file-list ()
15321 "Edit the list of agenda files.
15322 Depending on setup, this either uses customize to edit the variable
15323 `org-agenda-files', or it visits the file that is holding the list. In the
15324 latter case, the buffer is set up in a way that saving it automatically kills
15325 the buffer and restores the previous window configuration."
15327 (if (stringp org-agenda-files)
15328 (let ((cw (current-window-configuration)))
15329 (find-file org-agenda-files)
15330 (org-set-local 'org-window-configuration cw)
15331 (org-add-hook 'after-save-hook
15333 (set-window-configuration
15334 (prog1 org-window-configuration
15335 (kill-buffer (current-buffer))))
15336 (org-install-agenda-files-menu)
15337 (message "New agenda file list installed"))
15339 (message "%s" (substitute-command-keys
15340 "Edit list and finish with \\[save-buffer]")))
15341 (customize-variable 'org-agenda-files)))
15343 (defun org-store-new-agenda-file-list (list)
15344 "Set new value for the agenda file list and save it correctly."
15345 (if (stringp org-agenda-files)
15346 (let ((fe (org-read-agenda-file-list t)) b u)
15347 (while (setq b (find-buffer-visiting org-agenda-files))
15349 (with-temp-file org-agenda-files
15352 (lambda (f) ;; Keep un-expanded entries.
15353 (if (setq u (assoc f fe))
15358 (let ((org-mode-hook nil) (org-inhibit-startup t)
15359 (org-insert-mode-line-in-empty-file nil))
15360 (setq org-agenda-files list)
15361 (customize-save-variable 'org-agenda-files org-agenda-files))))
15363 (defun org-read-agenda-file-list (&optional pair-with-expansion)
15364 "Read the list of agenda files from a file.
15365 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
15366 filenames, used by `org-store-new-agenda-file-list' to write back
15367 un-expanded file names."
15368 (when (file-directory-p org-agenda-files)
15369 (error "`org-agenda-files' cannot be a single directory"))
15370 (when (stringp org-agenda-files)
15372 (insert-file-contents org-agenda-files)
15375 (let ((e (expand-file-name (substitute-in-file-name f)
15377 (if pair-with-expansion
15380 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
15383 (defun org-cycle-agenda-files ()
15384 "Cycle through the files in `org-agenda-files'.
15385 If the current buffer visits an agenda file, find the next one in the list.
15386 If the current buffer does not, find the first agenda file."
15388 (let* ((fs (org-agenda-files t))
15389 (files (append fs (list (car fs))))
15390 (tcf (if buffer-file-name (file-truename buffer-file-name)))
15392 (unless files (error "No agenda files"))
15394 (while (setq file (pop files))
15395 (if (equal (file-truename file) tcf)
15397 (find-file (car files))
15399 (find-file (car fs)))
15400 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
15402 (defun org-agenda-file-to-front (&optional to-end)
15403 "Move/add the current file to the top of the agenda file list.
15404 If the file is not present in the list, it is added to the front. If it is
15405 present, it is moved there. With optional argument TO-END, add/move to the
15408 (let ((org-agenda-skip-unavailable-files nil)
15409 (file-alist (mapcar (lambda (x)
15410 (cons (file-truename x) x))
15411 (org-agenda-files t)))
15412 (ctf (file-truename buffer-file-name))
15414 (setq x (assoc ctf file-alist) had x)
15416 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
15418 (setq file-alist (append (delq x file-alist) (list x)))
15419 (setq file-alist (cons x (delq x file-alist))))
15420 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
15421 (org-install-agenda-files-menu)
15422 (message "File %s to %s of agenda file list"
15423 (if had "moved" "added") (if to-end "end" "front"))))
15425 (defun org-remove-file (&optional file)
15426 "Remove current file from the list of files in variable `org-agenda-files'.
15427 These are the files which are being checked for agenda entries.
15428 Optional argument FILE means use this file instead of the current."
15430 (let* ((org-agenda-skip-unavailable-files nil)
15431 (file (or file buffer-file-name))
15432 (true-file (file-truename file))
15433 (afile (abbreviate-file-name file))
15434 (files (delq nil (mapcar
15436 (if (equal true-file
15439 (org-agenda-files t)))))
15440 (if (not (= (length files) (length (org-agenda-files t))))
15442 (org-store-new-agenda-file-list files)
15443 (org-install-agenda-files-menu)
15444 (message "Removed file: %s" afile))
15445 (message "File was not in list: %s (not removed)" afile))))
15447 (defun org-file-menu-entry (file)
15448 (vector file (list 'find-file file) t))
15450 (defun org-check-agenda-file (file)
15451 "Make sure FILE exists. If not, ask user what to do."
15452 (when (not (file-exists-p file))
15453 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
15454 (abbreviate-file-name file))
15455 (let ((r (downcase (read-char-exclusive))))
15458 (org-remove-file file)
15459 (throw 'nextfile t))
15460 (t (error "Abort"))))))
15462 (defun org-get-agenda-file-buffer (file)
15463 "Get a buffer visiting FILE. If the buffer needs to be created, add
15464 it to the list of buffers which might be released later."
15465 (let ((buf (org-find-base-buffer-visiting file)))
15467 buf ; just return it
15468 ;; Make a new buffer and remember it
15469 (setq buf (find-file-noselect file))
15470 (if buf (push buf org-agenda-new-buffers))
15473 (defun org-release-buffers (blist)
15474 "Release all buffers in list, asking the user for confirmation when needed.
15475 When a buffer is unmodified, it is just killed. When modified, it is saved
15476 \(if the user agrees) and then killed."
15478 (while (setq buf (pop blist))
15479 (setq file (buffer-file-name buf))
15480 (when (and (buffer-modified-p buf)
15482 (y-or-n-p (format "Save file %s? " file)))
15483 (with-current-buffer buf (save-buffer)))
15484 (kill-buffer buf))))
15486 (defun org-prepare-agenda-buffers (files)
15487 "Create buffers for all agenda files, protect archived trees and comments."
15489 (let ((pa '(:org-archived t))
15490 (pc '(:org-comment t))
15491 (pall '(:org-archived t :org-comment t))
15492 (inhibit-read-only t)
15493 (rea (concat ":" org-archive-tag ":"))
15497 (while (setq file (pop files))
15501 (org-check-agenda-file file)
15502 (set-buffer (org-get-agenda-file-buffer file)))
15504 (setq bmp (buffer-modified-p))
15505 (org-refresh-category-properties)
15506 (setq org-todo-keywords-for-agenda
15507 (append org-todo-keywords-for-agenda org-todo-keywords-1))
15508 (setq org-done-keywords-for-agenda
15509 (append org-done-keywords-for-agenda org-done-keywords))
15510 (setq org-todo-keyword-alist-for-agenda
15511 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
15512 (setq org-drawers-for-agenda
15513 (append org-drawers-for-agenda org-drawers))
15514 (setq org-tag-alist-for-agenda
15515 (append org-tag-alist-for-agenda org-tag-alist))
15518 (remove-text-properties (point-min) (point-max) pall)
15519 (when org-agenda-skip-archived-trees
15520 (goto-char (point-min))
15521 (while (re-search-forward rea nil t)
15522 (if (org-on-heading-p t)
15523 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
15524 (goto-char (point-min))
15525 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
15526 (while (re-search-forward re nil t)
15527 (add-text-properties
15528 (match-beginning 0) (org-end-of-subtree t) pc)))
15529 (set-buffer-modified-p bmp)))))
15530 (setq org-todo-keywords-for-agenda
15531 (org-uniquify org-todo-keywords-for-agenda))
15532 (setq org-todo-keyword-alist-for-agenda
15533 (org-uniquify org-todo-keyword-alist-for-agenda)
15534 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
15536 ;;;; Embedded LaTeX
15538 (defvar org-cdlatex-mode-map (make-sparse-keymap)
15539 "Keymap for the minor `org-cdlatex-mode'.")
15541 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
15542 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
15543 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
15544 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
15545 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
15547 (defvar org-cdlatex-texmathp-advice-is-done nil
15548 "Flag remembering if we have applied the advice to texmathp already.")
15550 (define-minor-mode org-cdlatex-mode
15551 "Toggle the minor `org-cdlatex-mode'.
15552 This mode supports entering LaTeX environment and math in LaTeX fragments
15554 \\{org-cdlatex-mode-map}"
15556 (when org-cdlatex-mode (require 'cdlatex))
15557 (unless org-cdlatex-texmathp-advice-is-done
15558 (setq org-cdlatex-texmathp-advice-is-done t)
15559 (defadvice texmathp (around org-math-always-on activate)
15560 "Always return t in org-mode buffers.
15561 This is because we want to insert math symbols without dollars even outside
15562 the LaTeX math segments. If Orgmode thinks that point is actually inside
15563 an embedded LaTeX fragment, let texmathp do its job.
15564 \\[org-cdlatex-mode-map]"
15568 ((not (org-mode-p)) ad-do-it)
15569 ((eq this-command 'cdlatex-math-symbol)
15570 (setq ad-return-value t
15571 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
15573 (let ((p (org-inside-LaTeX-fragment-p)))
15574 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
15575 (setq ad-return-value t
15576 texmathp-why '("Org-mode embedded math" . 0))
15577 (if p ad-do-it)))))))))
15579 (defun turn-on-org-cdlatex ()
15580 "Unconditionally turn on `org-cdlatex-mode'."
15581 (org-cdlatex-mode 1))
15583 (defun org-inside-LaTeX-fragment-p ()
15584 "Test if point is inside a LaTeX fragment.
15585 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15586 sequence appearing also before point.
15587 Even though the matchers for math are configurable, this function assumes
15588 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15589 delimiters are skipped when they have been removed by customization.
15590 The return value is nil, or a cons cell with the delimiter and
15591 and the position of this delimiter.
15593 This function does a reasonably good job, but can locally be fooled by
15594 for example currency specifications. For example it will assume being in
15595 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15596 fragments that are properly closed, but during editing, we have to live
15597 with the uncertainty caused by missing closing delimiters. This function
15598 looks only before point, not after."
15600 (let ((pos (point))
15601 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
15603 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
15605 dd-on str (start 0) m re)
15608 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
15609 re (nth 1 (assoc "$" org-latex-regexps)))
15610 (while (string-match re str start)
15612 ((= (match-end 0) (length str))
15613 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
15614 ((= (match-end 0) (- (length str) 5))
15616 (t (setq start (match-end 0))))))
15617 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
15619 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
15620 (and (match-beginning 2) (throw 'exit nil))
15622 (while (re-search-backward "\\$\\$" lim t)
15623 (setq dd-on (not dd-on)))
15625 (if dd-on (cons "$$" m))))))
15627 (defun org-inside-latex-macro-p ()
15628 "Is point inside a LaTeX macro or its arguments?"
15631 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15633 (defun org-try-cdlatex-tab ()
15634 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15635 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15636 - inside a LaTeX fragment, or
15637 - after the first word in a line, where an abbreviation expansion could
15638 insert a LaTeX environment."
15639 (when org-cdlatex-mode
15642 (skip-chars-backward "a-zA-Z0-9*")
15643 (skip-chars-backward " \t")
15646 ((org-inside-LaTeX-fragment-p)
15650 (defun org-cdlatex-underscore-caret (&optional arg)
15651 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15652 Revert to the normal definition outside of these fragments."
15654 (if (org-inside-LaTeX-fragment-p)
15655 (call-interactively 'cdlatex-sub-superscript)
15656 (let (org-cdlatex-mode)
15657 (call-interactively (key-binding (vector last-input-event))))))
15659 (defun org-cdlatex-math-modify (&optional arg)
15660 "Execute `cdlatex-math-modify' in LaTeX fragments.
15661 Revert to the normal definition outside of these fragments."
15663 (if (org-inside-LaTeX-fragment-p)
15664 (call-interactively 'cdlatex-math-modify)
15665 (let (org-cdlatex-mode)
15666 (call-interactively (key-binding (vector last-input-event))))))
15668 (defvar org-latex-fragment-image-overlays nil
15669 "List of overlays carrying the images of latex fragments.")
15670 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
15672 (defun org-remove-latex-fragment-image-overlays ()
15673 "Remove all overlays with LaTeX fragment images in current buffer."
15674 (mapc 'delete-overlay org-latex-fragment-image-overlays)
15675 (setq org-latex-fragment-image-overlays nil))
15677 (defun org-preview-latex-fragment (&optional subtree)
15678 "Preview the LaTeX fragment at point, or all locally or globally.
15679 If the cursor is in a LaTeX fragment, create the image and overlay
15680 it over the source code. If there is no fragment at point, display
15681 all fragments in the current text, from one headline to the next. With
15682 prefix SUBTREE, display all fragments in the current subtree. With a
15683 double prefix `C-u C-u', or when the cursor is before the first headline,
15684 display all fragments in the buffer.
15685 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15687 (org-remove-latex-fragment-image-overlays)
15690 (let (beg end at msg)
15692 ((or (equal subtree '(16))
15693 (not (save-excursion
15694 (re-search-backward (concat "^" outline-regexp) nil t))))
15695 (setq beg (point-min) end (point-max)
15696 msg "Creating images for buffer...%s"))
15697 ((equal subtree '(4))
15698 (org-back-to-heading)
15699 (setq beg (point) end (org-end-of-subtree t)
15700 msg "Creating images for subtree...%s"))
15702 (if (setq at (org-inside-LaTeX-fragment-p))
15703 (goto-char (max (point-min) (- (cdr at) 2)))
15704 (org-back-to-heading))
15705 (setq beg (point) end (progn (outline-next-heading) (point))
15706 msg (if at "Creating image...%s"
15707 "Creating images for entry...%s"))))
15709 (narrow-to-region beg end)
15712 (concat "ltxpng/" (file-name-sans-extension
15713 (file-name-nondirectory
15714 buffer-file-name)))
15715 default-directory 'overlays msg at 'forbuffer)
15716 (message msg "done. Use `C-c C-c' to remove images.")))))
15718 (defvar org-latex-regexps
15719 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
15720 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15721 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15722 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15723 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15724 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
15725 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
15726 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
15727 "Regular expressions for matching embedded LaTeX.")
15729 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer)
15730 "Replace LaTeX fragments with links to an image, and produce images.
15731 Some of the options can be changed using the variable
15732 `org-format-latex-options'."
15733 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
15734 (let* ((prefixnodir (file-name-nondirectory prefix))
15735 (absprefix (expand-file-name prefix dir))
15736 (todir (file-name-directory absprefix))
15737 (opt org-format-latex-options)
15738 (matchers (plist-get opt :matchers))
15739 (re-list org-latex-regexps)
15740 (org-format-latex-header-extra
15741 (plist-get (org-infile-export-plist) :latex-header-extra))
15742 (cnt 0) txt hash link beg end re e checkdir
15743 executables-checked
15744 m n block linkfile movefile ov)
15745 ;; Check the different regular expressions
15746 (while (setq e (pop re-list))
15747 (setq m (car e) re (nth 1 e) n (nth 2 e)
15748 block (if (nth 3 e) "\n\n" ""))
15749 (when (member m matchers)
15750 (goto-char (point-min))
15751 (while (re-search-forward re nil t)
15752 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
15753 (not (get-text-property (match-beginning n)
15756 (not (eq (get-char-property (match-beginning n)
15758 'org-latex-overlay))))
15759 (setq txt (match-string n)
15760 beg (match-beginning n) end (match-end n)
15762 (let (print-length print-level) ; make sure full list is printed
15763 (setq hash (sha1 (prin1-to-string
15764 (list org-format-latex-header
15765 org-format-latex-header-extra
15766 org-export-latex-default-packages-alist
15767 org-export-latex-packages-alist
15768 org-format-latex-options
15770 linkfile (format "%s_%s.png" prefix hash)
15771 movefile (format "%s_%s.png" absprefix hash)))
15772 (setq link (concat block "[[file:" linkfile "]]" block))
15773 (if msg (message msg cnt))
15775 (unless checkdir ; make sure the directory exists
15777 (or (file-directory-p todir) (make-directory todir)))
15779 (unless executables-checked
15780 (org-check-external-command
15781 "latex" "needed to convert LaTeX fragments to images")
15782 (org-check-external-command
15783 "dvipng" "needed to convert LaTeX fragments to images")
15784 (setq executables-checked t))
15786 (unless (file-exists-p movefile)
15787 (org-create-formula-image
15788 txt movefile opt forbuffer))
15792 (if (eq (overlay-get o 'org-overlay-type)
15793 'org-latex-overlay)
15794 (delete-overlay o)))
15795 (overlays-in beg end))
15796 (setq ov (make-overlay beg end))
15797 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
15798 (if (featurep 'xemacs)
15800 (overlay-put ov 'invisible t)
15803 (make-glyph (vector 'png :file movefile))))
15806 (list 'image :type 'png :file movefile :ascent 'center)))
15807 (push ov org-latex-fragment-image-overlays)
15809 (delete-region beg end)
15810 (insert (org-add-props link
15811 (list 'org-latex-src
15812 (replace-regexp-in-string "\"" "" txt)))))))))))
15814 ;; This function borrows from Ganesh Swami's latex2png.el
15815 (defun org-create-formula-image (string tofile options buffer)
15816 "This calls dvipng."
15817 (require 'org-latex)
15818 (let* ((tmpdir (if (featurep 'xemacs)
15820 temporary-file-directory))
15821 (texfilebase (make-temp-name
15822 (expand-file-name "orgtex" tmpdir)))
15823 (texfile (concat texfilebase ".tex"))
15824 (dvifile (concat texfilebase ".dvi"))
15825 (pngfile (concat texfilebase ".png"))
15826 (fnh (if (featurep 'xemacs)
15827 (font-height (get-face-font 'default))
15828 (face-attribute 'default :height nil)))
15829 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
15830 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
15831 (fg (or (plist-get options (if buffer :foreground :html-foreground))
15833 (bg (or (plist-get options (if buffer :background :html-background))
15835 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
15836 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
15837 (with-temp-file texfile
15838 (insert (org-splice-latex-header
15839 org-format-latex-header
15840 org-export-latex-default-packages-alist
15841 org-export-latex-packages-alist t
15842 org-format-latex-header-extra))
15843 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
15844 (require 'org-latex)
15845 (org-export-latex-fix-inputenc))
15846 (let ((dir default-directory))
15847 (condition-case nil
15850 (call-process "latex" nil nil nil texfile))
15853 (if (not (file-exists-p dvifile))
15854 (progn (message "Failed to create dvi file from %s" texfile) nil)
15855 (condition-case nil
15856 (call-process "dvipng" nil nil nil
15859 ;;"-x" scale "-y" scale
15864 (if (not (file-exists-p pngfile))
15865 (if org-format-latex-signal-error
15866 (error "Failed to create png file from %s" texfile)
15867 (message "Failed to create png file from %s" texfile)
15869 ;; Use the requested file name and clean up
15870 (copy-file pngfile tofile 'replace)
15871 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
15872 (delete-file (concat texfilebase e)))
15875 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
15876 "Fill a LaTeX header template TPL.
15877 In the template, the following place holders will be recognized:
15879 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15880 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15881 [PACKAGES] \\usepackage statements for PKG
15882 [NO-PACKAGES] do not include PKG
15883 [EXTRA] the string EXTRA
15884 [NO-EXTRA] do not include EXTRA
15886 For backward compatibility, if both the positive and the negative place
15887 holder is missing, the positive one (without the \"NO-\") will be
15888 assumed to be present at the end of the template.
15889 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15891 SNIPPETS-P indicates if this is run to create snippet images for HTML."
15892 (let (rpl (end ""))
15893 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
15894 (setq rpl (if (or (match-end 1) (not def-pkg))
15895 "" (org-latex-packages-to-string def-pkg snippets-p t))
15896 tpl (replace-match rpl t t tpl))
15897 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
15899 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
15900 (setq rpl (if (or (match-end 1) (not pkg))
15901 "" (org-latex-packages-to-string pkg snippets-p t))
15902 tpl (replace-match rpl t t tpl))
15905 (org-latex-packages-to-string pkg snippets-p)))))
15907 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
15908 (setq rpl (if (or (match-end 1) (not extra))
15909 "" (concat extra "\n"))
15910 tpl (replace-match rpl t t tpl))
15911 (if (and extra (string-match "\\S-" extra))
15912 (setq end (concat end "\n" extra))))
15914 (if (string-match "\\S-" end)
15915 (concat tpl "\n" end)
15918 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
15919 "Turn an alist of packages into a string with the \\usepackage macros."
15920 (setq pkg (mapconcat (lambda(p)
15923 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
15924 (format "%% Package %s omitted" (cadr p)))
15925 ((equal "" (car p))
15926 (format "\\usepackage{%s}" (cadr p)))
15928 (format "\\usepackage[%s]{%s}"
15929 (car p) (cadr p)))))
15932 (if newline (concat pkg "\n") pkg))
15934 (defun org-dvipng-color (attr)
15935 "Return an rgb color specification for dvipng."
15936 (apply 'format "rgb %s %s %s"
15937 (mapcar 'org-normalize-color
15938 (color-values (face-attribute 'default attr nil)))))
15940 (defun org-normalize-color (value)
15941 "Return string to be used as color value for an RGB component."
15942 (format "%g" (/ value 65535.0)))
15947 (defvar org-inline-image-overlays nil)
15948 (make-variable-buffer-local 'org-inline-image-overlays)
15950 (defun org-toggle-inline-images (&optional include-linked)
15951 "Toggle the display of inline images.
15952 INCLUDE-LINKED is passed to `org-display-inline-images'."
15954 (if org-inline-image-overlays
15956 (org-remove-inline-images)
15957 (message "Inline image display turned off"))
15958 (org-display-inline-images include-linked)
15959 (if org-inline-image-overlays
15960 (message "%d images displayed inline"
15961 (length org-inline-image-overlays))
15962 (message "No images to display inline"))))
15964 (defun org-display-inline-images (&optional include-linked refresh beg end)
15965 "Display inline images.
15966 Normally only links without a description part are inlined, because this
15967 is how it will work for export. When INCLUDE-LINKED is set, also links
15968 with a description part will be inlined. This can be nice for a quick
15969 look at those images, but it does not reflect whatexported files will look
15971 When REFRESH is set, refresh existing images between BEG and END.
15972 This will create new image displays only if necessary.
15973 BEG and END default to the buffer boundaries."
15976 (org-remove-inline-images)
15977 (clear-image-cache))
15981 (setq beg (or beg (point-min)) end (or end (point-max)))
15982 (goto-char (point-min))
15983 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([-+~.:/\\_0-9a-zA-Z ]+"
15984 (substring (org-image-file-name-regexp) 0 -2)
15985 "\\)\\]" (if include-linked "" "\\]")))
15987 (while (re-search-forward re end t)
15988 (setq old (get-char-property-and-overlay (match-beginning 1)
15989 'org-image-overlay))
15990 (setq file (expand-file-name
15991 (concat (or (match-string 3) "") (match-string 4))))
15992 (when (file-exists-p file)
15993 (if (and (car-safe old) refresh)
15994 (image-refresh (overlay-get (cdr old) 'display))
15995 (setq img (create-image file))
15997 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
15998 (overlay-put ov 'display img)
15999 (overlay-put ov 'face 'default)
16000 (overlay-put ov 'org-image-overlay t)
16001 (overlay-put ov 'modification-hooks
16002 (list 'org-display-inline-modification-hook))
16003 (push ov org-inline-image-overlays)))))))))
16005 (defun org-display-inline-modification-hook (ov after beg end &optional len)
16006 "Remove inline-display overlay if a corresponding region is modified."
16007 (let ((inhibit-modification-hooks t))
16008 (when (and ov after)
16009 (delete ov org-inline-image-overlays)
16010 (delete-overlay ov))))
16012 (defun org-remove-inline-images ()
16013 "Remove inline display of images."
16015 (mapc 'delete-overlay org-inline-image-overlays)
16016 (setq org-inline-image-overlays nil))
16020 ;; Make `C-c C-x' a prefix key
16021 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
16023 ;; TAB key with modifiers
16024 (org-defkey org-mode-map "\C-i" 'org-cycle)
16025 (org-defkey org-mode-map [(tab)] 'org-cycle)
16026 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
16027 (org-defkey org-mode-map [(meta tab)] 'org-complete)
16028 (org-defkey org-mode-map "\M-\t" 'org-complete)
16029 (org-defkey org-mode-map "\M-\C-i" 'org-complete)
16030 ;; The following line is necessary under Suse GNU/Linux
16031 (unless (featurep 'xemacs)
16032 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
16033 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
16034 (define-key org-mode-map [backtab] 'org-shifttab)
16036 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
16037 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
16038 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
16040 ;; Cursor keys with modifiers
16041 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
16042 (org-defkey org-mode-map [(meta right)] 'org-metaright)
16043 (org-defkey org-mode-map [(meta up)] 'org-metaup)
16044 (org-defkey org-mode-map [(meta down)] 'org-metadown)
16046 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
16047 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
16048 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
16049 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
16051 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
16052 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
16053 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
16054 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
16056 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
16057 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
16060 (define-key org-mode-map org-babel-key-prefix org-babel-map)
16061 (mapc (lambda (pair)
16062 (define-key org-babel-map (car pair) (cdr pair)))
16063 org-babel-key-bindings)
16065 ;;; Extra keys for tty access.
16066 ;; We only set them when really needed because otherwise the
16067 ;; menus don't show the simple keys
16069 (when (or org-use-extra-keys
16070 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
16071 (not window-system))
16072 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
16073 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
16074 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
16075 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
16076 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
16077 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
16078 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
16079 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
16080 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
16081 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
16082 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
16083 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
16084 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
16085 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
16086 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
16087 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
16088 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
16089 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
16090 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
16091 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
16092 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
16093 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
16094 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
16095 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
16096 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
16097 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
16098 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
16099 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
16101 ;; All the other keys
16103 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
16104 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
16105 (if (boundp 'narrow-map)
16106 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
16107 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
16108 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
16109 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
16110 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
16111 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
16112 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
16113 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
16114 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
16115 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
16116 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
16117 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
16118 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
16119 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
16120 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
16121 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
16122 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
16123 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
16124 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
16125 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
16126 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
16127 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
16128 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
16129 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
16130 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
16131 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
16132 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
16133 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
16134 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
16135 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
16136 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
16137 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
16138 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
16139 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
16140 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
16141 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
16142 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
16143 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
16144 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
16145 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
16146 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
16147 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
16148 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
16149 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
16150 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
16151 (org-defkey org-mode-map "\C-c^" 'org-sort)
16152 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
16153 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
16154 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
16155 (org-defkey org-mode-map "\C-m" 'org-return)
16156 (org-defkey org-mode-map "\C-j" 'org-return-indent)
16157 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
16158 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
16159 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
16160 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
16161 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
16162 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
16163 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
16164 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
16165 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
16166 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
16167 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
16168 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
16169 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
16170 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
16171 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
16172 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
16173 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
16174 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
16175 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
16176 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
16178 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
16179 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
16180 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
16181 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
16183 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
16184 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
16185 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
16186 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
16187 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
16188 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
16189 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
16190 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
16191 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
16192 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
16193 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
16194 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
16195 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
16196 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
16197 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
16198 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
16199 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
16201 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
16202 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
16203 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
16204 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
16206 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
16208 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
16210 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
16211 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
16213 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
16216 (when (featurep 'xemacs)
16217 (org-defkey org-mode-map 'button3 'popup-mode-menu))
16220 (defconst org-speed-commands-default
16222 ("Outline Navigation")
16223 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
16224 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
16225 ("f" . (org-speed-move-safe 'org-forward-same-level))
16226 ("b" . (org-speed-move-safe 'org-backward-same-level))
16227 ("u" . (org-speed-move-safe 'outline-up-heading))
16229 ("g" . (org-refile t))
16230 ("Outline Visibility")
16232 ("C" . org-shifttab)
16233 (" " . org-display-outline-path)
16234 ("Outline Structure Editing")
16235 ("U" . org-shiftmetaup)
16236 ("D" . org-shiftmetadown)
16237 ("r" . org-metaright)
16238 ("l" . org-metaleft)
16239 ("R" . org-shiftmetaright)
16240 ("L" . org-shiftmetaleft)
16241 ("i" . (progn (forward-char 1) (call-interactively
16242 'org-insert-heading-respect-content)))
16245 ("a" . org-archive-subtree-default-with-confirmation)
16246 ("." . outline-mark-subtree)
16248 ("I" . org-clock-in)
16249 ("O" . org-clock-out)
16250 ("Meta Data Editing")
16252 ("0" . (org-priority ?\ ))
16253 ("1" . (org-priority ?A))
16254 ("2" . (org-priority ?B))
16255 ("3" . (org-priority ?C))
16256 (";" . org-set-tags-command)
16257 ("e" . org-set-effort)
16258 ("Agenda Views etc")
16260 ("/" . org-sparse-tree)
16262 ("o" . org-open-at-point)
16263 ("?" . org-speed-command-help)
16265 "The default speed commands.")
16267 (defun org-print-speed-command (e)
16268 (if (> (length (car e)) 1)
16273 (princ (make-string (length (car e)) ?-))
16277 (if (symbolp (cdr e))
16278 (princ (symbol-name (cdr e)))
16282 (defun org-speed-command-help ()
16283 "Show the available speed commands."
16285 (if (not org-use-speed-commands)
16286 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
16287 (with-output-to-temp-buffer "*Help*"
16288 (princ "User-defined Speed commands\n===========================\n")
16289 (mapc 'org-print-speed-command org-speed-commands-user)
16291 (princ "Built-in Speed commands\n=======================\n")
16292 (mapc 'org-print-speed-command org-speed-commands-default))
16293 (with-current-buffer "*Help*"
16294 (setq truncate-lines t))))
16296 (defun org-speed-move-safe (cmd)
16297 "Execute CMD, but make sure that the cursor always ends up in a headline.
16298 If not, return to the original position and throw an error."
16300 (let ((pos (point)))
16301 (call-interactively cmd)
16302 (unless (and (bolp) (org-on-heading-p))
16304 (error "Boundary reached while executing %s" cmd))))
16306 (defvar org-self-insert-command-undo-counter 0)
16308 (defvar org-table-auto-blank-field) ; defined in org-table.el
16309 (defvar org-speed-command nil)
16310 (defun org-self-insert-command (N)
16311 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
16312 If the cursor is in a table looking at whitespace, the whitespace is
16313 overwritten, and the table is not marked as requiring realignment."
16316 ((and org-use-speed-commands
16317 (or (and (bolp) (looking-at outline-regexp))
16318 (and (functionp org-use-speed-commands)
16319 (funcall org-use-speed-commands)))
16322 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
16323 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
16325 ((commandp org-speed-command)
16326 (setq this-command org-speed-command)
16327 (call-interactively org-speed-command))
16328 ((functionp org-speed-command)
16329 (funcall org-speed-command))
16330 ((and org-speed-command (listp org-speed-command))
16331 (eval org-speed-command))
16332 (t (let (org-use-speed-commands)
16333 (call-interactively 'org-self-insert-command)))))
16337 ;; check if we blank the field, and if that triggers align
16338 (and (featurep 'org-table) org-table-auto-blank-field
16339 (member last-command
16340 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
16341 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
16342 ;; got extra space, this field does not determine column width
16343 (let (org-table-may-need-update) (org-table-blank-field))
16344 ;; no extra space, this field may determine column width
16345 (org-table-blank-field)))
16348 (looking-at "[^|\n]* |"))
16349 (let (org-table-may-need-update)
16350 (goto-char (1- (match-end 0)))
16351 (delete-backward-char 1)
16352 (goto-char (match-beginning 0))
16353 (self-insert-command N)))
16355 (setq org-table-may-need-update t)
16356 (self-insert-command N)
16357 (org-fix-tags-on-the-fly)
16358 (if org-self-insert-cluster-for-undo
16359 (if (not (eq last-command 'org-self-insert-command))
16360 (setq org-self-insert-command-undo-counter 1)
16361 (if (>= org-self-insert-command-undo-counter 20)
16362 (setq org-self-insert-command-undo-counter 1)
16363 (and (> org-self-insert-command-undo-counter 0)
16365 (not (cadr buffer-undo-list)) ; remove nil entry
16366 (setcdr buffer-undo-list (cddr buffer-undo-list)))
16367 (setq org-self-insert-command-undo-counter
16368 (1+ org-self-insert-command-undo-counter))))))))
16370 (defun org-fix-tags-on-the-fly ()
16371 (when (and (equal (char-after (point-at-bol)) ?*)
16372 (org-on-heading-p))
16373 (org-align-tags-here org-tags-column)))
16375 (defun org-delete-backward-char (N)
16376 "Like `delete-backward-char', insert whitespace at field end in tables.
16377 When deleting backwards, in tables this function will insert whitespace in
16378 front of the next \"|\" separator, to keep the table aligned. The table will
16379 still be marked for re-alignment if the field did fill the entire column,
16380 because, in this case the deletion might narrow the column."
16382 (if (and (org-table-p)
16384 (string-match "|" (buffer-substring (point-at-bol) (point)))
16385 (looking-at ".*?|"))
16386 (let ((pos (point))
16387 (noalign (looking-at "[^|\n\r]* |"))
16388 (c org-table-may-need-update))
16389 (backward-delete-char N)
16390 (skip-chars-forward "^|")
16392 (goto-char (1- pos))
16393 ;; noalign: if there were two spaces at the end, this field
16394 ;; does not determine the width of the column.
16395 (if noalign (setq org-table-may-need-update c)))
16396 (backward-delete-char N)
16397 (org-fix-tags-on-the-fly)))
16399 (defun org-delete-char (N)
16400 "Like `delete-char', but insert whitespace at field end in tables.
16401 When deleting characters, in tables this function will insert whitespace in
16402 front of the next \"|\" separator, to keep the table aligned. The table will
16403 still be marked for re-alignment if the field did fill the entire column,
16404 because, in this case the deletion might narrow the column."
16406 (if (and (org-table-p)
16408 (not (= (char-after) ?|))
16410 (if (looking-at ".*?|")
16411 (let ((pos (point))
16412 (noalign (looking-at "[^|\n\r]* |"))
16413 (c org-table-may-need-update))
16414 (replace-match (concat
16415 (substring (match-string 0) 1 -1)
16418 ;; noalign: if there were two spaces at the end, this field
16419 ;; does not determine the width of the column.
16420 (if noalign (setq org-table-may-need-update c)))
16423 (org-fix-tags-on-the-fly)))
16425 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
16426 (put 'org-self-insert-command 'delete-selection t)
16427 (put 'orgtbl-self-insert-command 'delete-selection t)
16428 (put 'org-delete-char 'delete-selection 'supersede)
16429 (put 'org-delete-backward-char 'delete-selection 'supersede)
16430 (put 'org-yank 'delete-selection 'yank)
16432 ;; Make `flyspell-mode' delay after some commands
16433 (put 'org-self-insert-command 'flyspell-delayed t)
16434 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
16435 (put 'org-delete-char 'flyspell-delayed t)
16436 (put 'org-delete-backward-char 'flyspell-delayed t)
16438 ;; Make pabbrev-mode expand after org-mode commands
16439 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
16440 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
16442 ;; How to do this: Measure non-white length of current string
16443 ;; If equal to column width, we should realign.
16445 (defun org-remap (map &rest commands)
16446 "In MAP, remap the functions given in COMMANDS.
16447 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
16450 (setq old (pop commands) new (pop commands))
16451 (if (fboundp 'command-remapping)
16452 (org-defkey map (vector 'remap old) new)
16453 (substitute-key-definition old new map global-map)))))
16455 (when (eq org-enable-table-editor 'optimized)
16456 ;; If the user wants maximum table support, we need to hijack
16457 ;; some standard editing functions
16458 (org-remap org-mode-map
16459 'self-insert-command 'org-self-insert-command
16460 'delete-char 'org-delete-char
16461 'delete-backward-char 'org-delete-backward-char)
16462 (org-defkey org-mode-map "|" 'org-force-self-insert))
16464 (defvar org-ctrl-c-ctrl-c-hook nil
16465 "Hook for functions attaching themselves to `C-c C-c'.
16466 This can be used to add additional functionality to the C-c C-c key which
16467 executes context-dependent commands.
16468 Each function will be called with no arguments. The function must check
16469 if the context is appropriate for it to act. If yes, it should do its
16470 thing and then return a non-nil value. If the context is wrong,
16471 just do nothing and return nil.")
16473 (defvar org-tab-first-hook nil
16474 "Hook for functions to attach themselves to TAB.
16475 See `org-ctrl-c-ctrl-c-hook' for more information.
16476 This hook runs as the first action when TAB is pressed, even before
16477 `org-cycle' messes around with the `outline-regexp' to cater for
16478 inline tasks and plain list item folding.
16479 If any function in this hook returns t, any other actions that
16480 would have been caused by TAB (such as table field motion or visibility
16481 cycling) will not occur.")
16483 (defvar org-tab-after-check-for-table-hook nil
16484 "Hook for functions to attach themselves to TAB.
16485 See `org-ctrl-c-ctrl-c-hook' for more information.
16486 This hook runs after it has been established that the cursor is not in a
16487 table, but before checking if the cursor is in a headline or if global cycling
16489 If any function in this hook returns t, not other actions like visibility
16490 cycling will be done.")
16492 (defvar org-tab-after-check-for-cycling-hook nil
16493 "Hook for functions to attach themselves to TAB.
16494 See `org-ctrl-c-ctrl-c-hook' for more information.
16495 This hook runs after it has been established that not table field motion and
16496 not visibility should be done because of current context. This is probably
16497 the place where a package like yasnippets can hook in.")
16499 (defvar org-tab-before-tab-emulation-hook nil
16500 "Hook for functions to attach themselves to TAB.
16501 See `org-ctrl-c-ctrl-c-hook' for more information.
16502 This hook runs after every other options for TAB have been exhausted, but
16503 before indentation and \t insertion takes place.")
16505 (defvar org-metaleft-hook nil
16506 "Hook for functions attaching themselves to `M-left'.
16507 See `org-ctrl-c-ctrl-c-hook' for more information.")
16508 (defvar org-metaright-hook nil
16509 "Hook for functions attaching themselves to `M-right'.
16510 See `org-ctrl-c-ctrl-c-hook' for more information.")
16511 (defvar org-metaup-hook nil
16512 "Hook for functions attaching themselves to `M-up'.
16513 See `org-ctrl-c-ctrl-c-hook' for more information.")
16514 (defvar org-metadown-hook nil
16515 "Hook for functions attaching themselves to `M-down'.
16516 See `org-ctrl-c-ctrl-c-hook' for more information.")
16517 (defvar org-shiftmetaleft-hook nil
16518 "Hook for functions attaching themselves to `M-S-left'.
16519 See `org-ctrl-c-ctrl-c-hook' for more information.")
16520 (defvar org-shiftmetaright-hook nil
16521 "Hook for functions attaching themselves to `M-S-right'.
16522 See `org-ctrl-c-ctrl-c-hook' for more information.")
16523 (defvar org-shiftmetaup-hook nil
16524 "Hook for functions attaching themselves to `M-S-up'.
16525 See `org-ctrl-c-ctrl-c-hook' for more information.")
16526 (defvar org-shiftmetadown-hook nil
16527 "Hook for functions attaching themselves to `M-S-down'.
16528 See `org-ctrl-c-ctrl-c-hook' for more information.")
16529 (defvar org-metareturn-hook nil
16530 "Hook for functions attaching themselves to `M-RET'.
16531 See `org-ctrl-c-ctrl-c-hook' for more information.")
16532 (defvar org-shiftup-hook nil
16533 "Hook for functions attaching themselves to `S-up'.
16534 See `org-ctrl-c-ctrl-c-hook' for more information.")
16535 (defvar org-shiftup-final-hook nil
16536 "Hook for functions attaching themselves to `S-up'.
16537 This one runs after all other options except shift-select have been excluded.
16538 See `org-ctrl-c-ctrl-c-hook' for more information.")
16539 (defvar org-shiftdown-hook nil
16540 "Hook for functions attaching themselves to `S-down'.
16541 See `org-ctrl-c-ctrl-c-hook' for more information.")
16542 (defvar org-shiftdown-final-hook nil
16543 "Hook for functions attaching themselves to `S-down'.
16544 This one runs after all other options except shift-select have been excluded.
16545 See `org-ctrl-c-ctrl-c-hook' for more information.")
16546 (defvar org-shiftleft-hook nil
16547 "Hook for functions attaching themselves to `S-left'.
16548 See `org-ctrl-c-ctrl-c-hook' for more information.")
16549 (defvar org-shiftleft-final-hook nil
16550 "Hook for functions attaching themselves to `S-left'.
16551 This one runs after all other options except shift-select have been excluded.
16552 See `org-ctrl-c-ctrl-c-hook' for more information.")
16553 (defvar org-shiftright-hook nil
16554 "Hook for functions attaching themselves to `S-right'.
16555 See `org-ctrl-c-ctrl-c-hook' for more information.")
16556 (defvar org-shiftright-final-hook nil
16557 "Hook for functions attaching themselves to `S-right'.
16558 This one runs after all other options except shift-select have been excluded.
16559 See `org-ctrl-c-ctrl-c-hook' for more information.")
16561 (defun org-modifier-cursor-error ()
16562 "Throw an error, a modified cursor command was applied in wrong context."
16563 (error "This command is active in special context like tables, headlines or items"))
16565 (defun org-shiftselect-error ()
16566 "Throw an error because Shift-Cursor command was applied in wrong context."
16567 (if (and (boundp 'shift-select-mode) shift-select-mode)
16568 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
16569 (error "This command works only in special context like headlines or timestamps")))
16571 (defun org-call-for-shift-select (cmd)
16572 (let ((this-command-keys-shift-translated t))
16573 (call-interactively cmd)))
16575 (defun org-shifttab (&optional arg)
16576 "Global visibility cycling or move to previous table field.
16577 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
16579 See the individual commands for more information."
16582 ((org-at-table-p) (call-interactively 'org-table-previous-field))
16584 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
16585 (message "Content view to level: %d" arg)
16586 (org-content (prefix-numeric-value arg2))
16587 (setq org-cycle-global-status 'overview)))
16588 (t (call-interactively 'org-global-cycle))))
16590 (defun org-shiftmetaleft ()
16591 "Promote subtree or delete table column.
16592 Calls `org-promote-subtree', `org-outdent-item',
16593 or `org-table-delete-column', depending on context.
16594 See the individual commands for more information."
16597 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
16598 ((org-at-table-p) (call-interactively 'org-table-delete-column))
16599 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
16600 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
16601 (t (org-modifier-cursor-error))))
16603 (defun org-shiftmetaright ()
16604 "Demote subtree or insert table column.
16605 Calls `org-demote-subtree', `org-indent-item',
16606 or `org-table-insert-column', depending on context.
16607 See the individual commands for more information."
16610 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
16611 ((org-at-table-p) (call-interactively 'org-table-insert-column))
16612 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
16613 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
16614 (t (org-modifier-cursor-error))))
16616 (defun org-shiftmetaup (&optional arg)
16617 "Move subtree up or kill table row.
16618 Calls `org-move-subtree-up' or `org-table-kill-row' or
16619 `org-move-item-up' depending on context. See the individual commands
16620 for more information."
16623 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16624 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16625 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16626 ((org-at-item-p) (call-interactively 'org-move-item-up))
16627 (t (org-modifier-cursor-error))))
16629 (defun org-shiftmetadown (&optional arg)
16630 "Move subtree down or insert table row.
16631 Calls `org-move-subtree-down' or `org-table-insert-row' or
16632 `org-move-item-down', depending on context. See the individual
16633 commands for more information."
16636 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16637 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16638 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16639 ((org-at-item-p) (call-interactively 'org-move-item-down))
16640 (t (org-modifier-cursor-error))))
16642 (defsubst org-hidden-tree-error ()
16644 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
16646 (defun org-metaleft (&optional arg)
16647 "Promote heading or move table column to left.
16648 Calls `org-do-promote' or `org-table-move-column', depending on context.
16649 With no specific context, calls the Emacs default `backward-word'.
16650 See the individual commands for more information."
16653 ((run-hook-with-args-until-success 'org-metaleft-hook))
16654 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16655 ((or (org-on-heading-p)
16656 (and (org-region-active-p)
16658 (goto-char (region-beginning))
16659 (org-on-heading-p))))
16660 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16661 (call-interactively 'org-do-promote))
16662 ((or (org-at-item-p)
16663 (and (org-region-active-p)
16665 (goto-char (region-beginning))
16667 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16668 (call-interactively 'org-outdent-item))
16669 (t (call-interactively 'backward-word))))
16671 (defun org-metaright (&optional arg)
16672 "Demote subtree or move table column to right.
16673 Calls `org-do-demote' or `org-table-move-column', depending on context.
16674 With no specific context, calls the Emacs default `forward-word'.
16675 See the individual commands for more information."
16678 ((run-hook-with-args-until-success 'org-metaright-hook))
16679 ((org-at-table-p) (call-interactively 'org-table-move-column))
16680 ((or (org-on-heading-p)
16681 (and (org-region-active-p)
16683 (goto-char (region-beginning))
16684 (org-on-heading-p))))
16685 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16686 (call-interactively 'org-do-demote))
16687 ((or (org-at-item-p)
16688 (and (org-region-active-p)
16690 (goto-char (region-beginning))
16692 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16693 (call-interactively 'org-indent-item))
16694 (t (call-interactively 'forward-word))))
16696 (defun org-check-for-hidden (what)
16697 "Check if there are hidden headlines/items in the current visual line.
16698 WHAT can be either `headlines' or `items'. If the current line is
16699 an outline or item heading and it has a folded subtree below it,
16700 this fucntion returns t, nil otherwise."
16702 ((eq what 'headlines) (concat "^" org-outline-regexp))
16703 ((eq what 'items) (concat "^" (org-item-re t)))
16704 (t (error "This should not happen"))))
16708 (unless (org-region-active-p)
16709 (setq beg (point-at-bol))
16710 (beginning-of-line 2)
16711 (while (and (not (eobp)) ;; this is like `next-line'
16712 (get-char-property (1- (point)) 'invisible))
16713 (beginning-of-line 2))
16716 (goto-char (point-at-eol))
16717 (setq end (max end (point)))
16718 (while (re-search-forward re end t)
16719 (if (get-char-property (match-beginning 0) 'invisible)
16723 (defun org-metaup (&optional arg)
16724 "Move subtree up or move table row up.
16725 Calls `org-move-subtree-up' or `org-table-move-row' or
16726 `org-move-item-up', depending on context. See the individual commands
16727 for more information."
16730 ((run-hook-with-args-until-success 'org-metaup-hook))
16731 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16732 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16733 ((org-at-item-p) (call-interactively 'org-move-item-up))
16734 (t (transpose-lines 1) (beginning-of-line -1))))
16736 (defun org-metadown (&optional arg)
16737 "Move subtree down or move table row down.
16738 Calls `org-move-subtree-down' or `org-table-move-row' or
16739 `org-move-item-down', depending on context. See the individual
16740 commands for more information."
16743 ((run-hook-with-args-until-success 'org-metadown-hook))
16744 ((org-at-table-p) (call-interactively 'org-table-move-row))
16745 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16746 ((org-at-item-p) (call-interactively 'org-move-item-down))
16747 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16749 (defun org-shiftup (&optional arg)
16750 "Increase item in timestamp or increase priority of current headline.
16751 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16752 depending on context. See the individual commands for more information."
16755 ((run-hook-with-args-until-success 'org-shiftup-hook))
16756 ((and org-support-shift-select (org-region-active-p))
16757 (org-call-for-shift-select 'previous-line))
16758 ((org-at-timestamp-p t)
16759 (call-interactively (if org-edit-timestamp-down-means-later
16760 'org-timestamp-down 'org-timestamp-up)))
16761 ((and (not (eq org-support-shift-select 'always))
16762 org-enable-priority-commands
16763 (org-on-heading-p))
16764 (call-interactively 'org-priority-up))
16765 ((and (not org-support-shift-select) (org-at-item-p))
16766 (call-interactively 'org-previous-item))
16767 ((org-clocktable-try-shift 'up arg))
16768 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
16769 (org-support-shift-select
16770 (org-call-for-shift-select 'previous-line))
16771 (t (org-shiftselect-error))))
16773 (defun org-shiftdown (&optional arg)
16774 "Decrease item in timestamp or decrease priority of current headline.
16775 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16776 depending on context. See the individual commands for more information."
16779 ((run-hook-with-args-until-success 'org-shiftdown-hook))
16780 ((and org-support-shift-select (org-region-active-p))
16781 (org-call-for-shift-select 'next-line))
16782 ((org-at-timestamp-p t)
16783 (call-interactively (if org-edit-timestamp-down-means-later
16784 'org-timestamp-up 'org-timestamp-down)))
16785 ((and (not (eq org-support-shift-select 'always))
16786 org-enable-priority-commands
16787 (org-on-heading-p))
16788 (call-interactively 'org-priority-down))
16789 ((and (not org-support-shift-select) (org-at-item-p))
16790 (call-interactively 'org-next-item))
16791 ((org-clocktable-try-shift 'down arg))
16792 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
16793 (org-support-shift-select
16794 (org-call-for-shift-select 'next-line))
16795 (t (org-shiftselect-error))))
16797 (defun org-shiftright (&optional arg)
16798 "Cycle the thing at point or in the current line, depending on context.
16799 Depending on context, this does one of the following:
16801 - switch a timestamp at point one day into the future
16802 - on a headline, switch to the next TODO keyword.
16803 - on an item, switch entire list to the next bullet type
16804 - on a property line, switch to the next allowed value
16805 - on a clocktable definition line, move time block into the future"
16808 ((run-hook-with-args-until-success 'org-shiftright-hook))
16809 ((and org-support-shift-select (org-region-active-p))
16810 (org-call-for-shift-select 'forward-char))
16811 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16812 ((and (not (eq org-support-shift-select 'always))
16813 (org-on-heading-p))
16814 (let ((org-inhibit-logging
16815 (not org-treat-S-cursor-todo-selection-as-state-change))
16816 (org-inhibit-blocking
16817 (not org-treat-S-cursor-todo-selection-as-state-change)))
16818 (org-call-with-arg 'org-todo 'right)))
16819 ((or (and org-support-shift-select
16820 (not (eq org-support-shift-select 'always))
16821 (org-at-item-bullet-p))
16822 (and (not org-support-shift-select) (org-at-item-p)))
16823 (org-call-with-arg 'org-cycle-list-bullet nil))
16824 ((and (not (eq org-support-shift-select 'always))
16825 (org-at-property-p))
16826 (call-interactively 'org-property-next-allowed-value))
16827 ((org-clocktable-try-shift 'right arg))
16828 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
16829 (org-support-shift-select
16830 (org-call-for-shift-select 'forward-char))
16831 (t (org-shiftselect-error))))
16833 (defun org-shiftleft (&optional arg)
16834 "Cycle the thing at point or in the current line, depending on context.
16835 Depending on context, this does one of the following:
16837 - switch a timestamp at point one day into the past
16838 - on a headline, switch to the previous TODO keyword.
16839 - on an item, switch entire list to the previous bullet type
16840 - on a property line, switch to the previous allowed value
16841 - on a clocktable definition line, move time block into the past"
16844 ((run-hook-with-args-until-success 'org-shiftleft-hook))
16845 ((and org-support-shift-select (org-region-active-p))
16846 (org-call-for-shift-select 'backward-char))
16847 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16848 ((and (not (eq org-support-shift-select 'always))
16849 (org-on-heading-p))
16850 (let ((org-inhibit-logging
16851 (not org-treat-S-cursor-todo-selection-as-state-change))
16852 (org-inhibit-blocking
16853 (not org-treat-S-cursor-todo-selection-as-state-change)))
16854 (org-call-with-arg 'org-todo 'left)))
16855 ((or (and org-support-shift-select
16856 (not (eq org-support-shift-select 'always))
16857 (org-at-item-bullet-p))
16858 (and (not org-support-shift-select) (org-at-item-p)))
16859 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16860 ((and (not (eq org-support-shift-select 'always))
16861 (org-at-property-p))
16862 (call-interactively 'org-property-previous-allowed-value))
16863 ((org-clocktable-try-shift 'left arg))
16864 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
16865 (org-support-shift-select
16866 (org-call-for-shift-select 'backward-char))
16867 (t (org-shiftselect-error))))
16869 (defun org-shiftcontrolright ()
16870 "Switch to next TODO set."
16873 ((and org-support-shift-select (org-region-active-p))
16874 (org-call-for-shift-select 'forward-word))
16875 ((and (not (eq org-support-shift-select 'always))
16876 (org-on-heading-p))
16877 (org-call-with-arg 'org-todo 'nextset))
16878 (org-support-shift-select
16879 (org-call-for-shift-select 'forward-word))
16880 (t (org-shiftselect-error))))
16882 (defun org-shiftcontrolleft ()
16883 "Switch to previous TODO set."
16886 ((and org-support-shift-select (org-region-active-p))
16887 (org-call-for-shift-select 'backward-word))
16888 ((and (not (eq org-support-shift-select 'always))
16889 (org-on-heading-p))
16890 (org-call-with-arg 'org-todo 'previousset))
16891 (org-support-shift-select
16892 (org-call-for-shift-select 'backward-word))
16893 (t (org-shiftselect-error))))
16895 (defun org-ctrl-c-ret ()
16896 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16899 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16900 (t (call-interactively 'org-insert-heading))))
16902 (defun org-copy-special ()
16903 "Copy region in table or copy current subtree.
16904 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16905 See the individual commands for more information."
16907 (call-interactively
16908 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16910 (defun org-cut-special ()
16911 "Cut region in table or cut current subtree.
16912 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16913 See the individual commands for more information."
16915 (call-interactively
16916 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16918 (defun org-paste-special (arg)
16919 "Paste rectangular region into table, or past subtree relative to level.
16920 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16921 See the individual commands for more information."
16923 (if (org-at-table-p)
16924 (org-table-paste-rectangle)
16925 (org-paste-subtree arg)))
16927 (defun org-edit-special (&optional arg)
16928 "Call a special editor for the stuff at point.
16929 When at a table, call the formula editor with `org-table-edit-formulas'.
16930 When at the first line of an src example, call `org-edit-src-code'.
16931 When in an #+include line, visit the include file. Otherwise call
16932 `ffap' to visit the file at point."
16934 ;; possibly prep session before editing source
16936 (let* ((info (org-babel-get-src-block-info))
16937 (lang (nth 0 info))
16938 (params (nth 2 info))
16939 (session (cdr (assoc :session params))))
16940 (when (and info session) ;; we are in a source-code block with a session
16942 (intern (concat "org-babel-prep-session:" lang)) session params))))
16943 (cond ;; proceed with `org-edit-special'
16945 (beginning-of-line 1)
16946 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16947 (find-file (org-trim (match-string 1))))
16948 ((org-edit-src-code))
16949 ((org-edit-fixed-width-region))
16950 ((org-at-table.el-p)
16951 (org-edit-src-code))
16953 (call-interactively 'org-table-edit-formulas))
16954 (t (call-interactively 'ffap))))
16957 (defun org-ctrl-c-ctrl-c (&optional arg)
16958 "Set tags in headline, or update according to changed information at point.
16960 This command does many different things, depending on context:
16962 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
16963 this is what we do.
16965 - If the cursor is on a statistics cookie, update it.
16967 - If the cursor is in a headline, prompt for tags and insert them
16968 into the current line, aligned to `org-tags-column'. When called
16969 with prefix arg, realign all tags in the current buffer.
16971 - If the cursor is in one of the special #+KEYWORD lines, this
16972 triggers scanning the buffer for these lines and updating the
16975 - If the cursor is inside a table, realign the table. This command
16976 works even if the automatic table editor has been turned off.
16978 - If the cursor is on a #+TBLFM line, re-apply the formulas to
16981 - If the cursor is at a footnote reference or definition, jump to
16982 the corresponding definition or references, respectively.
16984 - If the cursor is a the beginning of a dynamic block, update it.
16986 - If the current buffer is a remember buffer, close note and file
16987 it. A prefix argument of 1 files to the default location
16988 without further interaction. A prefix argument of 2 files to
16989 the currently clocking task.
16991 - If the cursor is on a <<<target>>>, update radio targets and corresponding
16992 links in this buffer.
16994 - If the cursor is on a numbered item in a plain list, renumber the
16997 - If the cursor is on a checkbox, toggle it."
16999 (let ((org-enable-table-editor t))
17001 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
17002 org-occur-highlights
17003 org-latex-fragment-image-overlays)
17004 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
17005 (org-remove-occur-highlights)
17006 (org-remove-latex-fragment-image-overlays)
17007 (message "Temporary highlights/overlays removed from current buffer"))
17008 ((and (local-variable-p 'org-finish-function (current-buffer))
17009 (fboundp org-finish-function))
17010 (funcall org-finish-function))
17011 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
17012 ((or (looking-at org-property-start-re)
17013 (org-at-property-p))
17014 (call-interactively 'org-property-action))
17015 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
17016 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
17017 (or (org-on-heading-p) (org-at-item-p)))
17018 (call-interactively 'org-update-statistics-cookies))
17019 ((org-on-heading-p) (call-interactively 'org-set-tags))
17020 ((org-at-table.el-p)
17021 (message "Use C-c ' to edit table.el tables"))
17023 (org-table-maybe-eval-formula)
17025 (call-interactively 'org-table-recalculate)
17026 (org-table-maybe-recalculate-line))
17027 (call-interactively 'org-table-align))
17028 ((or (org-footnote-at-reference-p)
17029 (org-footnote-at-definition-p))
17030 (call-interactively 'org-footnote-action))
17031 ((org-at-item-checkbox-p)
17032 (call-interactively 'org-toggle-checkbox))
17035 (call-interactively 'org-toggle-checkbox)
17036 (call-interactively 'org-maybe-renumber-ordered-list)))
17037 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
17039 (beginning-of-line 1)
17040 (save-excursion (org-update-dblock)))
17042 (beginning-of-line 1)
17043 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
17045 ((equal (match-string 1) "TBLFM")
17046 ;; Recalculate the table before this line
17048 (beginning-of-line 1)
17049 (skip-chars-backward " \r\n\t")
17050 (if (org-at-table-p)
17051 (org-call-with-arg 'org-table-recalculate (or arg t)))))
17053 (let ((org-inhibit-startup-visibility-stuff t)
17054 (org-startup-align-all-tables nil))
17055 (org-save-outline-visibility 'use-markers (org-mode-restart)))
17056 (message "Local setup has been refreshed"))))
17057 ((org-clock-update-time-maybe))
17058 (t (error "C-c C-c can do nothing useful at this location")))))
17060 (defun org-mode-restart ()
17061 "Restart Org-mode, to scan again for special lines.
17062 Also updates the keyword regular expressions."
17065 (message "Org-mode restarted"))
17067 (defun org-kill-note-or-show-branches ()
17068 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
17070 (if (not org-finish-function)
17073 (call-interactively 'show-branches))
17074 (let ((org-note-abort t))
17075 (funcall org-finish-function))))
17077 (defun org-return (&optional indent)
17078 "Goto next table row or insert a newline.
17079 Calls `org-table-next-row' or `newline', depending on context.
17080 See the individual commands for more information."
17083 ((bobp) (if indent (newline-and-indent) (newline)))
17085 (org-table-justify-field-maybe)
17086 (call-interactively 'org-table-next-row))
17087 ((and org-return-follows-link
17088 (eq (get-text-property (point) 'face) 'org-link))
17089 (call-interactively 'org-open-at-point))
17090 ((and (org-at-heading-p)
17092 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
17096 (t (if indent (newline-and-indent) (newline)))))
17098 (defun org-return-indent ()
17099 "Goto next table row or insert a newline and indent.
17100 Calls `org-table-next-row' or `newline-and-indent', depending on
17101 context. See the individual commands for more information."
17105 (defun org-ctrl-c-star ()
17106 "Compute table, or change heading status of lines.
17107 Calls `org-table-recalculate' or `org-toggle-heading',
17108 depending on context."
17112 (call-interactively 'org-table-recalculate))
17114 ;; Convert all lines in region to list items
17115 (call-interactively 'org-toggle-heading))))
17117 (defun org-ctrl-c-minus ()
17118 "Insert separator line in table or modify bullet status of line.
17119 Also turns a plain line or a region of lines into list items.
17120 Calls `org-table-insert-hline', `org-toggle-item', or
17121 `org-cycle-list-bullet', depending on context."
17125 (call-interactively 'org-table-insert-hline))
17126 ((org-region-active-p)
17127 (call-interactively 'org-toggle-item))
17129 (call-interactively 'org-cycle-list-bullet))
17131 (call-interactively 'org-toggle-item))))
17133 (defun org-toggle-item ()
17134 "Convert headings or normal lines to items, items to normal lines.
17135 If there is no active region, only the current line is considered.
17137 If the first line in the region is a headline, convert all headlines to items.
17139 If the first line in the region is an item, convert all items to normal lines.
17141 If the first line is normal text, add an item bullet to each line."
17143 (let (l2 l beg end)
17144 (if (org-region-active-p)
17145 (setq beg (region-beginning) end (region-end))
17146 (setq beg (point-at-bol)
17147 end (min (1+ (point-at-eol)) (point-max))))
17150 (setq l2 (org-current-line))
17152 (beginning-of-line 1)
17153 (setq l (1- (org-current-line)))
17154 (if (org-at-item-p)
17155 ;; We already have items, de-itemize
17156 (while (< (setq l (1+ l)) l2)
17157 (when (org-at-item-p)
17158 (goto-char (match-beginning 2))
17159 (delete-region (match-beginning 2) (match-end 2))
17160 (and (looking-at "[ \t]+") (replace-match "")))
17161 (beginning-of-line 2))
17162 (if (org-on-heading-p)
17163 ;; Headings, convert to items
17164 (while (< (setq l (1+ l)) l2)
17165 (if (looking-at org-outline-regexp)
17166 (replace-match "- " t t))
17167 (beginning-of-line 2))
17168 ;; normal lines, turn them into items
17169 (while (< (setq l (1+ l)) l2)
17170 (unless (org-at-item-p)
17171 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17172 (replace-match "\\1- \\2")))
17173 (beginning-of-line 2)))))))
17175 (defun org-toggle-heading (&optional nstars)
17176 "Convert headings to normal text, or items or text to headings.
17177 If there is no active region, only the current line is considered.
17179 If the first line is a heading, remove the stars from all headlines
17182 If the first line is a plain list item, turn all plain list items
17185 If the first line is a normal line, turn each and every line in the
17186 region into a heading.
17188 When converting a line into a heading, the number of stars is chosen
17189 such that the lines become children of the current entry. However,
17190 when a prefix argument is given, its value determines the number of
17193 (let (l2 l itemp beg end)
17194 (if (org-region-active-p)
17195 (setq beg (region-beginning) end (region-end))
17196 (setq beg (point-at-bol)
17197 end (min (1+ (point-at-eol)) (point-max))))
17200 (setq l2 (org-current-line))
17202 (beginning-of-line 1)
17203 (setq l (1- (org-current-line)))
17204 (if (org-on-heading-p)
17205 ;; We already have headlines, de-star them
17206 (while (< (setq l (1+ l)) l2)
17207 (when (org-on-heading-p t)
17208 (and (looking-at outline-regexp) (replace-match "")))
17209 (beginning-of-line 2))
17210 (setq itemp (org-at-item-p))
17213 (make-string (prefix-numeric-value current-prefix-arg)
17216 (if (re-search-backward org-complex-heading-regexp nil t)
17217 (match-string 1) ""))))
17218 (add-stars (cond (nstars "")
17219 ((equal stars "") "*")
17220 (org-odd-levels-only "**")
17222 (rpl (concat stars add-stars " ")))
17223 (while (< (setq l (1+ l)) l2)
17225 (and (org-at-item-p) (replace-match rpl t t))
17226 (unless (org-on-heading-p)
17227 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17228 (replace-match (concat rpl (match-string 2))))))
17229 (beginning-of-line 2)))))))
17231 (defun org-meta-return (&optional arg)
17232 "Insert a new heading or wrap a region in a table.
17233 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
17234 See the individual commands for more information."
17237 ((run-hook-with-args-until-success 'org-metareturn-hook))
17239 (call-interactively 'org-table-wrap-region))
17240 (t (call-interactively 'org-insert-heading))))
17244 ;; Define the Org-mode menus
17245 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
17247 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
17248 ["Next Field" org-cycle (org-at-table-p)]
17249 ["Previous Field" org-shifttab (org-at-table-p)]
17250 ["Next Row" org-return (org-at-table-p)]
17252 ["Blank Field" org-table-blank-field (org-at-table-p)]
17253 ["Edit Field" org-table-edit-field (org-at-table-p)]
17254 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
17257 ["Move Column Left" org-metaleft (org-at-table-p)]
17258 ["Move Column Right" org-metaright (org-at-table-p)]
17259 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
17260 ["Insert Column" org-shiftmetaright (org-at-table-p)])
17262 ["Move Row Up" org-metaup (org-at-table-p)]
17263 ["Move Row Down" org-metadown (org-at-table-p)]
17264 ["Delete Row" org-shiftmetaup (org-at-table-p)]
17265 ["Insert Row" org-shiftmetadown (org-at-table-p)]
17266 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
17268 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
17270 ["Copy Rectangle" org-copy-special (org-at-table-p)]
17271 ["Cut Rectangle" org-cut-special (org-at-table-p)]
17272 ["Paste Rectangle" org-paste-special (org-at-table-p)]
17273 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
17276 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
17277 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
17278 ["Edit Formulas" org-edit-special (org-at-table-p)]
17280 ["Recalculate line" org-table-recalculate (org-at-table-p)]
17281 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
17282 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
17284 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
17286 ["Sum Column/Rectangle" org-table-sum
17287 (or (org-at-table-p) (org-region-active-p))]
17288 ["Which Column?" org-table-current-column (org-at-table-p)])
17290 org-table-toggle-formula-debugger
17291 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
17292 ["Show Col/Row Numbers"
17293 org-table-toggle-coordinate-overlays
17295 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
17297 ["Create" org-table-create (and (not (org-at-table-p))
17298 org-enable-table-editor)]
17299 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
17300 ["Import from File" org-table-import (not (org-at-table-p))]
17301 ["Export to File" org-table-export (org-at-table-p)]
17303 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
17305 (easy-menu-define org-org-menu org-mode-map "Org menu"
17308 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
17309 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
17310 ["Sparse Tree..." org-sparse-tree t]
17311 ["Reveal Context" org-reveal t]
17312 ["Show All" show-all t]
17314 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
17316 ["New Heading" org-insert-heading t]
17317 ("Navigate Headings"
17318 ["Up" outline-up-heading t]
17319 ["Next" outline-next-visible-heading t]
17320 ["Previous" outline-previous-visible-heading t]
17321 ["Next Same Level" outline-forward-same-level t]
17322 ["Previous Same Level" outline-backward-same-level t]
17324 ["Jump" org-goto t])
17326 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
17327 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
17329 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
17330 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
17331 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
17333 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
17335 ["Promote Heading" org-metaleft (not (org-at-table-p))]
17336 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
17337 ["Demote Heading" org-metaright (not (org-at-table-p))]
17338 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
17340 ["Sort Region/Children" org-sort (not (org-at-table-p))]
17342 ["Convert to odd levels" org-convert-to-odd-levels t]
17343 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
17345 ["Emphasis..." org-emphasize t]
17346 ["Edit Source Example" org-edit-special t]
17348 ["Footnote new/jump" org-footnote-action t]
17349 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
17351 ["Archive (default method)" org-archive-subtree-default t]
17353 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
17354 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
17355 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
17359 ["Store Link (Global)" org-store-link t]
17360 ["Find existing link to here" org-occur-link-in-agenda-files t]
17361 ["Insert Link" org-insert-link t]
17362 ["Follow Link" org-open-at-point t]
17364 ["Next link" org-next-link t]
17365 ["Previous link" org-previous-link t]
17367 ["Descriptive Links"
17368 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
17370 :selected (member '(org-link) buffer-invisibility-spec)]
17373 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
17375 :selected (not (member '(org-link) buffer-invisibility-spec))])
17378 ["TODO/DONE/-" org-todo t]
17380 ["Next keyword" org-shiftright (org-on-heading-p)]
17381 ["Previous keyword" org-shiftleft (org-on-heading-p)]
17382 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
17383 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
17384 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
17385 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
17386 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
17388 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
17389 :selected org-enforce-todo-dependencies :style toggle :active t]
17390 "Settings for tree at point"
17391 ["Do Children sequentially" org-toggle-ordered-property :style radio
17392 :selected (ignore-errors (org-entry-get nil "ORDERED"))
17393 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17394 ["Do Children parallel" org-toggle-ordered-property :style radio
17395 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
17396 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17398 ["Set Priority" org-priority t]
17399 ["Priority Up" org-shiftup t]
17400 ["Priority Down" org-shiftdown t]
17402 ["Get news from all feeds" org-feed-update-all t]
17403 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
17404 ["Customize feeds" (customize-variable 'org-feed-alist) t])
17405 ("TAGS and Properties"
17406 ["Set Tags" org-set-tags-command t]
17407 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
17409 ["Set property" org-set-property t]
17410 ["Column view of properties" org-columns t]
17411 ["Insert Column View DBlock" org-insert-columns-dblock t])
17412 ("Dates and Scheduling"
17413 ["Timestamp" org-time-stamp t]
17414 ["Timestamp (inactive)" org-time-stamp-inactive t]
17416 ["1 Day Later" org-shiftright t]
17417 ["1 Day Earlier" org-shiftleft t]
17418 ["1 ... Later" org-shiftup t]
17419 ["1 ... Earlier" org-shiftdown t])
17420 ["Compute Time Range" org-evaluate-time-range t]
17421 ["Schedule Item" org-schedule t]
17422 ["Deadline" org-deadline t]
17424 ["Custom time format" org-toggle-time-stamp-overlays
17425 :style radio :selected org-display-custom-times]
17427 ["Goto Calendar" org-goto-calendar t]
17428 ["Date from Calendar" org-date-from-calendar t]
17430 ["Start/Restart Timer" org-timer-start t]
17431 ["Pause/Continue Timer" org-timer-pause-or-continue t]
17432 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
17433 ["Insert Timer String" org-timer t]
17434 ["Insert Timer Item" org-timer-item t])
17436 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
17437 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
17438 ["Clock out" org-clock-out t]
17439 ["Clock cancel" org-clock-cancel t]
17441 ["Mark as default task" org-clock-mark-default-task t]
17442 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
17443 ["Goto running clock" org-clock-goto t]
17445 ["Display times" org-clock-display t]
17446 ["Create clock table" org-clock-report t]
17448 ["Record DONE time"
17449 (progn (setq org-log-done (not org-log-done))
17450 (message "Switching to %s will %s record a timestamp"
17451 (car org-done-keywords)
17452 (if org-log-done "automatically" "not")))
17453 :style toggle :selected org-log-done])
17455 ["Agenda Command..." org-agenda t]
17456 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
17457 ("File List for Agenda")
17458 ("Special views current file"
17459 ["TODO Tree" org-show-todo-tree t]
17460 ["Check Deadlines" org-check-deadlines t]
17461 ["Timeline" org-timeline t]
17462 ["Tags/Property tree" org-match-sparse-tree t])
17464 ["Export/Publish..." org-export t]
17466 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
17467 :selected org-cdlatex-mode]
17468 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
17469 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
17470 ["Modify math symbol" org-cdlatex-math-modify
17471 (org-inside-LaTeX-fragment-p)]
17472 ["Insert citation" org-reftex-citation t]
17474 ["Export LaTeX fragments as images"
17475 (if (featurep 'org-exp)
17476 (setq org-export-with-LaTeX-fragments
17477 (not org-export-with-LaTeX-fragments))
17478 (require 'org-exp))
17479 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
17480 org-export-with-LaTeX-fragments)]
17482 ["Template for BEAMER" org-insert-beamer-options-template t])
17485 ["Push Files and Views" org-mobile-push t]
17486 ["Get Captured and Flagged" org-mobile-pull t]
17487 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
17489 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
17492 ["Show Version" org-version t]
17493 ["Info Documentation" org-info t])
17495 ["Browse Org Group" org-customize t]
17497 ["Expand This Menu" org-create-customize-menu
17498 (fboundp 'customize-menu-create)])
17499 ["Send bug report" org-submit-bug-report t]
17502 ["Refresh setup current buffer" org-mode-restart t]
17503 ["Reload Org (after update)" org-reload t]
17504 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
17507 (defun org-info (&optional node)
17508 "Read documentation for Org-mode in the info system.
17509 With optional NODE, go directly to that node."
17511 (info (format "(org)%s" (or node ""))))
17514 (defun org-submit-bug-report ()
17515 "Submit a bug report on Org-mode via mail.
17517 Don't hesitate to report any problems or inaccurate documentation.
17519 If you don't have setup sending mail from (X)Emacs, please copy the
17520 output buffer into your mail program, as it gives us important
17521 information about your Org-mode version and configuration."
17523 (require 'reporter)
17524 (org-load-modules-maybe)
17525 (org-require-autoloaded-modules)
17526 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
17527 (reporter-submit-bug-report
17528 "emacs-orgmode@gnu.org"
17531 (save-window-excursion
17532 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
17533 (delete-other-windows)
17535 (insert "You are about to submit a bug report to the Org-mode mailing list.
17537 We would like to add your full Org-mode and Outline configuration to the
17538 bug report. This greatly simplifies the work of the maintainer and
17539 other experts on the mailing list.
17541 HOWEVER, some variables you have customized may contain private
17542 information. The names of customers, colleagues, or friends, might
17543 appear in the form of file names, tags, todo states, or search strings.
17544 If you answer yes to the prompt, you might want to check and remove
17545 such private information before sending the email.")
17546 (add-text-properties (point-min) (point-max) '(face org-warning))
17547 (when (yes-or-no-p "Include your Org-mode configuration ")
17551 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
17552 (or (and (symbol-value v)
17553 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
17555 (get v 'custom-type) (get v 'standard-value)
17556 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
17558 (kill-buffer (get-buffer "*Warn about privacy*"))
17561 "Remember to cover the basics, that is, what you expected to happen and
17562 what in fact did happen. You don't know how to make a good report? See
17564 http://orgmode.org/manual/Feedback.html#Feedback
17566 Your bug report will be posted to the Org-mode mailing list.
17567 ------------------------------------------------------------------------")
17569 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
17570 (replace-match "\\1Bug: \\3 [\\2]")))))
17573 (defun org-install-agenda-files-menu ()
17574 (let ((bl (buffer-list)))
17577 (set-buffer (pop bl))
17578 (if (org-mode-p) (setq bl nil)))
17581 '("Org") "File List for Agenda"
17584 ["Edit File List" (org-edit-agenda-file-list) t]
17585 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
17586 ["Remove Current File from List" org-remove-file t]
17587 ["Cycle through agenda files" org-cycle-agenda-files t]
17588 ["Occur in all agenda files" org-occur-in-agenda-files t]
17590 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
17595 (defun org-require-autoloaded-modules ()
17598 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
17599 org-docbook org-exp org-html org-icalendar
17601 org-publish org-remember org-table
17602 org-timer org-xoxo)))
17605 (defun org-reload (&optional uncompiled)
17606 "Reload all org lisp files.
17607 With prefix arg UNCOMPILED, load the uncompiled versions."
17609 (require 'find-func)
17610 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
17611 (dir-org (file-name-directory (org-find-library-name "org")))
17612 (dir-org-contrib (ignore-errors
17613 (file-name-directory
17614 (org-find-library-name "org-contribdir"))))
17616 (append (directory-files dir-org t file-re)
17617 (and dir-org-contrib
17618 (directory-files dir-org-contrib t file-re))))
17619 (remove-re (concat (if (featurep 'xemacs)
17620 "org-colview" "org-colview-xemacs")
17622 (setq files (mapcar 'file-name-sans-extension files))
17623 (setq files (mapcar
17624 (lambda (x) (if (string-match remove-re x) nil x))
17626 (setq files (delq nil files))
17629 (when (featurep (intern (file-name-nondirectory f)))
17630 (if (and (not uncompiled)
17631 (file-exists-p (concat f ".elc")))
17632 (load (concat f ".elc") nil nil t)
17633 (load (concat f ".el") nil nil t))))
17638 (defun org-customize ()
17639 "Call the customize function with org as argument."
17641 (org-load-modules-maybe)
17642 (org-require-autoloaded-modules)
17643 (customize-browse 'org))
17645 (defun org-create-customize-menu ()
17646 "Create a full customization menu for Org-mode, insert it into the menu."
17648 (org-load-modules-maybe)
17649 (org-require-autoloaded-modules)
17650 (if (fboundp 'customize-menu-create)
17653 '("Org") "Customize"
17654 `(["Browse Org group" org-customize t]
17656 ,(customize-menu-create 'org)
17657 ["Set" Custom-set t]
17658 ["Save" Custom-save t]
17659 ["Reset to Current" Custom-reset-current t]
17660 ["Reset to Saved" Custom-reset-saved t]
17661 ["Reset to Standard Settings" Custom-reset-standard t]))
17662 (message "\"Org\"-menu now contains full customization menu"))
17663 (error "Cannot expand menu (outdated version of cus-edit.el)")))
17665 ;;;; Miscellaneous stuff
17667 ;;; Generally useful functions
17669 (defun org-get-at-bol (property)
17670 "Get text property PROPERTY at beginning of line."
17671 (get-text-property (point-at-bol) property))
17673 (defun org-find-text-property-in-string (prop s)
17674 "Return the first non-nil value of property PROP in string S."
17675 (or (get-text-property 0 prop s)
17676 (get-text-property (or (next-single-property-change 0 prop s) 0)
17679 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17680 "Display the given MESSAGE as a warning."
17681 (if (fboundp 'display-warning)
17682 (display-warning 'org message
17683 (if (featurep 'xemacs) 'warning :warning))
17684 (let ((buf (get-buffer-create "*Org warnings*")))
17685 (with-current-buffer buf
17686 (goto-char (point-max))
17687 (insert "Warning (Org): " message)
17690 (display-buffer buf)
17693 (defun org-in-commented-line ()
17694 "Is point in a line starting with `#'?"
17695 (equal (char-after (point-at-bol)) ?#))
17697 (defun org-in-indented-comment-line ()
17698 "Is point in a line starting with `#' after some white space?"
17701 (goto-char (point-at-bol))
17702 (looking-at "[ \t]*#"))))
17704 (defun org-in-verbatim-emphasis ()
17706 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17708 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17709 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17710 (if (and marker (marker-buffer marker)
17711 (buffer-live-p (marker-buffer marker)))
17713 (switch-to-buffer (marker-buffer marker))
17714 (if (or (> marker (point-max)) (< marker (point-min)))
17717 (org-show-context 'org-goto))
17719 (bookmark-jump bookmark)
17720 (error "Cannot find location"))))
17722 (defun org-quote-csv-field (s)
17723 "Quote field for inclusion in CSV material."
17724 (if (string-match "[\",]" s)
17725 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17728 (defun org-plist-delete (plist property)
17729 "Delete PROPERTY from PLIST.
17730 This is in contrast to merely setting it to 0."
17733 (if (not (eq property (car plist)))
17734 (setq p (plist-put p (car plist) (nth 1 plist))))
17735 (setq plist (cddr plist)))
17738 (defun org-force-self-insert (N)
17739 "Needed to enforce self-insert under remapping."
17741 (self-insert-command N))
17743 (defun org-string-width (s)
17744 "Compute width of string, ignoring invisible characters.
17745 This ignores character with invisibility property `org-link', and also
17746 characters with property `org-cwidth', because these will become invisible
17747 upon the next fontification round."
17749 (when (or (eq t buffer-invisibility-spec)
17750 (assq 'org-link buffer-invisibility-spec))
17751 (while (setq b (text-property-any 0 (length s)
17752 'invisible 'org-link s))
17753 (setq s (concat (substring s 0 b)
17754 (substring s (or (next-single-property-change
17755 b 'invisible s) (length s)))))))
17756 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17757 (setq s (concat (substring s 0 b)
17758 (substring s (or (next-single-property-change
17759 b 'org-cwidth s) (length s))))))
17760 (setq l (string-width s) b -1)
17761 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17762 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17765 (defun org-get-indentation (&optional line)
17766 "Get the indentation of the current line, interpreting tabs.
17767 When LINE is given, assume it represents a line and compute its indentation."
17769 (if (string-match "^ *" (org-remove-tabs line))
17772 (beginning-of-line 1)
17773 (skip-chars-forward " \t")
17774 (current-column))))
17776 (defun org-remove-tabs (s &optional width)
17777 "Replace tabulators in S with spaces.
17778 Assumes that s is a single line, starting in column 0."
17779 (setq width (or width tab-width))
17780 (while (string-match "\t" s)
17781 (setq s (replace-match
17783 (- (* width (/ (+ (match-beginning 0) width) width))
17784 (match-beginning 0)) ?\ )
17788 (defun org-fix-indentation (line ind)
17789 "Fix indentation in LINE.
17790 IND is a cons cell with target and minimum indentation.
17791 If the current indentation in LINE is smaller than the minimum,
17792 leave it alone. If it is larger than ind, set it to the target."
17793 (let* ((l (org-remove-tabs line))
17794 (i (org-get-indentation l))
17795 (i1 (car ind)) (i2 (cdr ind)))
17796 (if (>= i i2) (setq l (substring line i2)))
17798 (concat (make-string i1 ?\ ) l)
17801 (defun org-remove-indentation (code &optional n)
17802 "Remove the maximum common indentation from the lines in CODE.
17803 N may optionally be the number of spaces to remove."
17806 (org-do-remove-indentation n)
17809 (defun org-do-remove-indentation (&optional n)
17810 "Remove the maximum common indentation from the buffer."
17811 (untabify (point-min) (point-max))
17812 (let ((min 10000) re)
17815 (goto-char (point-min))
17816 (while (re-search-forward "^ *[^ \n]" nil t)
17817 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17818 (unless (or (= min 0) (= min 10000))
17819 (setq re (format "^ \\{%d\\}" min))
17820 (goto-char (point-min))
17821 (while (re-search-forward re nil t)
17826 (defun org-fill-template (template alist)
17827 "Find each %key of ALIST in TEMPLATE and replace it."
17828 (let ((case-fold-search nil)
17830 (setq alist (sort (copy-sequence alist)
17831 (lambda (a b) (< (length (car a)) (length (car b))))))
17832 (while (setq entry (pop alist))
17834 (replace-regexp-in-string
17835 (concat "%" (regexp-quote (car entry)))
17836 (cdr entry) template t t)))
17839 (defun org-base-buffer (buffer)
17840 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17843 (or (buffer-base-buffer buffer)
17846 (defun org-trim (s)
17847 "Remove whitespace at beginning and end of string."
17848 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17849 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17852 (defun org-wrap (string &optional width lines)
17853 "Wrap string to either a number of lines, or a width in characters.
17854 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17855 that costs. If there is a word longer than WIDTH, the text is actually
17856 wrapped to the length of that word.
17857 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17858 many lines, whatever width that takes.
17859 The return value is a list of lines, without newlines at the end."
17860 (let* ((words (org-split-string string "[ \t\n]+"))
17861 (maxword (apply 'max (mapcar 'org-string-width words)))
17864 (org-do-wrap words (max maxword width)))
17867 (setq ll (org-do-wrap words maxword))
17868 (if (<= (length ll) lines)
17871 (while (> (length ll) lines)
17873 (setq ll (org-do-wrap words w)))
17875 (t (error "Cannot wrap this")))))
17877 (defun org-do-wrap (words width)
17878 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17881 (setq line (pop words))
17882 (while (and words (< (+ (length line) (length (car words))) width))
17883 (setq line (concat line " " (pop words))))
17884 (setq lines (push line lines)))
17887 (defun org-split-string (string &optional separators)
17888 "Splits STRING into substrings at SEPARATORS.
17889 No empty strings are returned if there are matches at the beginning
17890 and end of string."
17891 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17895 (while (and (string-match rexp string
17897 (= start (match-beginning 0))
17898 (< start (length string)))
17900 (< (match-beginning 0) (length string)))
17902 (or (eq (match-beginning 0) 0)
17903 (and (eq (match-beginning 0) (match-end 0))
17904 (eq (match-beginning 0) start))
17906 (cons (substring string start (match-beginning 0))
17908 (setq start (match-end 0)))
17909 (or (eq start (length string))
17911 (cons (substring string start)
17915 (defun org-quote-vert (s)
17916 "Replace \"|\" with \"\\vert\"."
17917 (while (string-match "|" s)
17918 (setq s (replace-match "\\vert" t t s)))
17921 (defun org-uuidgen-p (s)
17922 "Is S an ID created by UUIDGEN?"
17923 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17925 (defun org-context ()
17926 "Return a list of contexts of the current cursor position.
17927 If several contexts apply, all are returned.
17928 Each context entry is a list with a symbol naming the context, and
17929 two positions indicating start and end of the context. Possible
17932 :headline anywhere in a headline
17933 :headline-stars on the leading stars in a headline
17934 :todo-keyword on a TODO keyword (including DONE) in a headline
17935 :tags on the TAGS in a headline
17936 :priority on the priority cookie in a headline
17937 :item on the first line of a plain list item
17938 :item-bullet on the bullet/number of a plain list item
17939 :checkbox on the checkbox in a plain list item
17940 :table in an org-mode table
17941 :table-special on a special filed in a table
17942 :table-table in a table.el table
17943 :link on a hyperlink
17944 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
17945 :target on a <<target>>
17946 :radio-target on a <<<radio-target>>>
17947 :latex-fragment on a LaTeX fragment
17948 :latex-preview on a LaTeX fragment with overlayed preview image
17950 This function expects the position to be visible because it uses font-lock
17951 faces as a help to recognize the following contexts: :table-special, :link,
17953 (let* ((f (get-text-property (point) 'face))
17954 (faces (if (listp f) f (list f)))
17955 (p (point)) clist o)
17956 ;; First the large context
17958 ((org-on-heading-p t)
17959 (push (list :headline (point-at-bol) (point-at-eol)) clist)
17961 (beginning-of-line 1)
17962 (looking-at org-todo-line-tags-regexp))
17963 (push (org-point-in-group p 1 :headline-stars) clist)
17964 (push (org-point-in-group p 2 :todo-keyword) clist)
17965 (push (org-point-in-group p 4 :tags) clist))
17967 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
17968 (if (looking-at "\\[#[A-Z0-9]\\]")
17969 (push (org-point-in-group p 0 :priority) clist)))
17972 (push (org-point-in-group p 2 :item-bullet) clist)
17973 (push (list :item (point-at-bol)
17974 (save-excursion (org-end-of-item) (point)))
17976 (and (org-at-item-checkbox-p)
17977 (push (org-point-in-group p 0 :checkbox) clist)))
17980 (push (list :table (org-table-begin) (org-table-end)) clist)
17981 (if (memq 'org-formula faces)
17982 (push (list :table-special
17983 (previous-single-property-change p 'face)
17984 (next-single-property-change p 'face)) clist)))
17985 ((org-at-table-p 'any)
17986 (push (list :table-table) clist)))
17989 ;; Now the small context
17991 ((org-at-timestamp-p)
17992 (push (org-point-in-group p 0 :timestamp) clist))
17993 ((memq 'org-link faces)
17995 (previous-single-property-change p 'face)
17996 (next-single-property-change p 'face)) clist))
17997 ((memq 'org-special-keyword faces)
17998 (push (list :keyword
17999 (previous-single-property-change p 'face)
18000 (next-single-property-change p 'face)) clist))
18002 (push (org-point-in-group p 0 :target) clist)
18003 (goto-char (1- (match-beginning 0)))
18004 (if (looking-at org-radio-target-regexp)
18005 (push (org-point-in-group p 0 :radio-target) clist))
18007 ((setq o (car (delq nil
18010 (if (memq x org-latex-fragment-image-overlays) x))
18011 (overlays-at (point))))))
18012 (push (list :latex-fragment
18013 (overlay-start o) (overlay-end o)) clist)
18014 (push (list :latex-preview
18015 (overlay-start o) (overlay-end o)) clist))
18016 ((org-inside-LaTeX-fragment-p)
18017 ;; FIXME: positions wrong.
18018 (push (list :latex-fragment (point) (point)) clist)))
18020 (setq clist (nreverse (delq nil clist)))
18023 ;; FIXME: Compare with at-regexp-p Do we need both?
18024 (defun org-in-regexp (re &optional nlines visually)
18025 "Check if point is inside a match of regexp.
18026 Normally only the current line is checked, but you can include NLINES extra
18027 lines both before and after point into the search.
18028 If VISUALLY is set, require that the cursor is not after the match but
18029 really on, so that the block visually is on the match."
18031 (let ((pos (point))
18032 (eol (point-at-eol (+ 1 (or nlines 0))))
18033 (inc (if visually 1 0)))
18035 (beginning-of-line (- 1 (or nlines 0)))
18036 (while (re-search-forward re eol t)
18037 (if (and (<= (match-beginning 0) pos)
18038 (>= (+ inc (match-end 0)) pos))
18039 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
18041 (defun org-at-regexp-p (regexp)
18042 "Is point inside a match of REGEXP in the current line?"
18045 (let ((pos (point)) (end (point-at-eol)))
18046 (beginning-of-line 1)
18047 (while (re-search-forward regexp end t)
18048 (if (and (<= (match-beginning 0) pos)
18049 (>= (match-end 0) pos))
18053 (defun org-in-regexps-block-p (start-re end-re)
18054 "Returns t if the current point is between matches of START-RE and END-RE.
18055 This will also return to if point is on one of the two matches."
18059 (and (or (org-at-regexp-p start-re)
18060 (re-search-backward start-re nil t))
18061 (re-search-forward end-re nil t)
18064 (defun org-occur-in-agenda-files (regexp &optional nlines)
18065 "Call `multi-occur' with buffers for all agenda files."
18066 (interactive "sOrg-files matching: \np")
18067 (let* ((files (org-agenda-files))
18068 (tnames (mapcar 'file-truename files))
18069 (extra org-agenda-text-search-extra-files)
18071 (when (eq (car extra) 'agenda-archives)
18072 (setq extra (cdr extra))
18073 (setq files (org-add-archive-files files)))
18074 (while (setq f (pop extra))
18075 (unless (member (file-truename f) tnames)
18076 (add-to-list 'files f 'append)
18077 (add-to-list 'tnames (file-truename f) 'append)))
18079 (mapcar (lambda (x)
18080 (with-current-buffer
18081 (or (get-file-buffer x) (find-file-noselect x))
18087 (if (boundp 'occur-mode-find-occurrence-hook)
18089 (add-hook 'occur-mode-find-occurrence-hook
18094 (defadvice occur-mode-goto-occurrence
18095 (after org-occur-reveal activate)
18096 (and (org-mode-p) (org-reveal)))
18097 (defadvice occur-mode-goto-occurrence-other-window
18098 (after org-occur-reveal activate)
18099 (and (org-mode-p) (org-reveal)))
18100 (defadvice occur-mode-display-occurrence
18101 (after org-occur-reveal activate)
18103 (let ((pos (occur-mode-find-occurrence)))
18104 (with-current-buffer (marker-buffer pos)
18109 (defun org-occur-link-in-agenda-files ()
18110 "Create a link and search for it in the agendas.
18111 The link is not stored in `org-stored-links', it is just created
18112 for the search purpose."
18114 (let ((link (condition-case nil
18115 (org-store-link nil)
18116 (error "Unable to create a link to here"))))
18117 (org-occur-in-agenda-files (regexp-quote link))))
18119 (defun org-uniquify (list)
18120 "Remove duplicate elements from LIST."
18122 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
18125 (defun org-delete-all (elts list)
18126 "Remove all elements in ELTS from LIST."
18128 (setq list (delete (pop elts) list)))
18131 (defun org-remove-if (predicate seq)
18132 "Remove everything from SEQ that fulfills PREDICATE."
18136 (if (not (funcall predicate e)) (push e res)))
18139 (defun org-remove-if-not (predicate seq)
18140 "Remove everything from SEQ that does not fulfill PREDICATE."
18144 (if (funcall predicate e) (push e res)))
18147 (defun org-back-over-empty-lines ()
18148 "Move backwards over whitespace, to the beginning of the first empty line.
18149 Returns the number of empty lines passed."
18150 (let ((pos (point)))
18151 (skip-chars-backward " \t\n\r")
18152 (beginning-of-line 2)
18153 (goto-char (min (point) pos))
18154 (count-lines (point) pos)))
18156 (defun org-skip-whitespace ()
18157 (skip-chars-forward " \t\n\r"))
18159 (defun org-point-in-group (point group &optional context)
18160 "Check if POINT is in match-group GROUP.
18161 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
18162 match. If the match group does ot exist or point is not inside it,
18164 (and (match-beginning group)
18165 (>= point (match-beginning group))
18166 (<= point (match-end group))
18168 (list context (match-beginning group) (match-end group))
18171 (defun org-switch-to-buffer-other-window (&rest args)
18172 "Switch to buffer in a second window on the current frame.
18173 In particular, do not allow pop-up frames.
18174 Returns the newly created buffer."
18175 (let (pop-up-frames special-display-buffer-names special-display-regexps
18176 special-display-function)
18177 (apply 'switch-to-buffer-other-window args)))
18179 (defun org-combine-plists (&rest plists)
18180 "Create a single property list from all plists in PLISTS.
18181 The process starts by copying the first list, and then setting properties
18182 from the other lists. Settings in the last list are the most significant
18183 ones and overrule settings in the other lists."
18184 (let ((rtn (copy-sequence (pop plists)))
18187 (setq ls (pop plists))
18189 (setq p (pop ls) v (pop ls))
18190 (setq rtn (plist-put rtn p v))))
18193 (defun org-move-line-down (arg)
18194 "Move the current line down. With prefix argument, move it past ARG lines."
18196 (let ((col (current-column))
18198 (beginning-of-line 1) (setq beg (point))
18199 (beginning-of-line 2) (setq end (point))
18200 (beginning-of-line (+ 1 arg))
18201 (setq pos (move-marker (make-marker) (point)))
18202 (insert (delete-and-extract-region beg end))
18204 (org-move-to-column col)))
18206 (defun org-move-line-up (arg)
18207 "Move the current line up. With prefix argument, move it past ARG lines."
18209 (let ((col (current-column))
18211 (beginning-of-line 1) (setq beg (point))
18212 (beginning-of-line 2) (setq end (point))
18213 (beginning-of-line (- arg))
18214 (setq pos (move-marker (make-marker) (point)))
18215 (insert (delete-and-extract-region beg end))
18217 (org-move-to-column col)))
18219 (defun org-replace-escapes (string table)
18220 "Replace %-escapes in STRING with values in TABLE.
18221 TABLE is an association list with keys like \"%a\" and string values.
18222 The sequences in STRING may contain normal field width and padding information,
18223 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
18224 so values can contain further %-escapes if they are define later in TABLE."
18225 (let ((tbl (copy-alist table))
18226 (case-fold-search nil)
18229 (while (setq e (pop tbl))
18230 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
18231 (when (and (cdr e) (string-match re (cdr e)))
18232 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
18234 (add-text-properties 0 3 (list 'sref sref) safe)
18235 (setcdr e (replace-match safe t t (cdr e)))))
18236 (while (string-match re string)
18237 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
18239 (setq string (replace-match rpl t t string))))
18240 (while (setq pchg (next-property-change pchg string))
18241 (let ((sref (get-text-property pchg 'sref string)))
18242 (when (and sref (string-match "SREF" string pchg))
18243 (setq string (replace-match sref t t string)))))
18246 (defun org-sublist (list start end)
18247 "Return a section of LIST, from START to END.
18248 Counting starts at 1."
18249 (let (rtn (c start))
18250 (setq list (nthcdr (1- start) list))
18251 (while (and list (<= c end))
18252 (push (pop list) rtn)
18256 (defun org-find-base-buffer-visiting (file)
18257 "Like `find-buffer-visiting' but always return the base buffer and
18258 not an indirect buffer."
18259 (let ((buf (or (get-file-buffer file)
18260 (find-buffer-visiting file))))
18262 (or (buffer-base-buffer buf) buf)
18265 (defun org-image-file-name-regexp (&optional extensions)
18266 "Return regexp matching the file names of images.
18267 If EXTENSIONS is given, only match these."
18268 (if (and (not extensions) (fboundp 'image-file-name-regexp))
18269 (image-file-name-regexp)
18270 (let ((image-file-name-extensions
18272 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
18273 "xbm" "xpm" "pbm" "pgm" "ppm"))))
18275 (regexp-opt (nconc (mapcar 'upcase
18276 image-file-name-extensions)
18277 image-file-name-extensions)
18281 (defun org-file-image-p (file &optional extensions)
18282 "Return non-nil if FILE is an image."
18284 (string-match (org-image-file-name-regexp extensions) file)))
18286 (defun org-get-cursor-date ()
18287 "Return the date at cursor in as a time.
18288 This works in the calendar and in the agenda, anywhere else it just
18289 returns the current time."
18290 (let (date day defd)
18292 ((eq major-mode 'calendar-mode)
18293 (setq date (calendar-cursor-to-date)
18294 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
18295 ((eq major-mode 'org-agenda-mode)
18296 (setq day (get-text-property (point) 'day))
18298 (setq date (calendar-gregorian-from-absolute day)
18299 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
18301 (or defd (current-time))))
18303 (defvar org-agenda-action-marker (make-marker)
18304 "Marker pointing to the entry for the next agenda action.")
18306 (defun org-mark-entry-for-agenda-action ()
18307 "Mark the current entry as target of an agenda action.
18308 Agenda actions are actions executed from the agenda with the key `k',
18309 which make use of the date at the cursor."
18311 (move-marker org-agenda-action-marker
18312 (save-excursion (org-back-to-heading t) (point))
18315 "Entry marked for action; press `k' at desired date in agenda or calendar"))
18317 ;;; Paragraph filling stuff.
18318 ;; We want this to be just right, so use the full arsenal.
18320 (defun org-indent-line-function ()
18321 "Indent line like previous, but further if previous was headline or item."
18323 (let* ((pos (point))
18324 (itemp (org-at-item-p))
18325 (case-fold-search t)
18326 (org-drawer-regexp (or org-drawer-regexp "\000"))
18327 column bpos bcol tpos tcol bullet btype bullet-type)
18328 ;; Find the previous relevant line
18329 (beginning-of-line 1)
18331 ((looking-at "#") (setq column 0))
18332 ((looking-at "\\*+ ") (setq column 0))
18333 ((and (looking-at "[ \t]*:END:")
18334 (save-excursion (re-search-backward org-drawer-regexp nil t)))
18336 (goto-char (1- (match-beginning 1)))
18337 (setq column (current-column))))
18338 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
18340 (re-search-backward
18341 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
18342 (setq column (org-get-indentation (match-string 0))))
18344 (beginning-of-line 0)
18345 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
18346 (not (looking-at "[ \t]*:END:"))
18347 (not (looking-at org-drawer-regexp)))
18348 (beginning-of-line 0))
18350 ((looking-at "\\*+[ \t]+")
18351 (if (not org-adapt-indentation)
18353 (goto-char (match-end 0))
18354 (setq column (current-column))))
18355 ((looking-at org-drawer-regexp)
18356 (goto-char (1- (match-beginning 1)))
18357 (setq column (current-column)))
18358 ((looking-at "\\([ \t]*\\):END:")
18359 (goto-char (match-end 1))
18360 (setq column (current-column)))
18362 (org-beginning-of-item)
18363 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
18364 (setq bpos (match-beginning 1) tpos (match-end 0)
18365 bcol (progn (goto-char bpos) (current-column))
18366 tcol (progn (goto-char tpos) (current-column))
18367 bullet (match-string 1)
18368 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
18369 (if (> tcol (+ bcol org-description-max-indent))
18370 (setq tcol (+ bcol 5)))
18374 (beginning-of-line 1)
18375 (if (looking-at "\\S-")
18377 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
18378 (setq bullet (match-string 1)
18379 btype (if (string-match "[0-9]" bullet) "n" bullet))
18380 (setq column (if (equal btype bullet-type) bcol tcol)))
18381 (setq column (org-get-indentation)))))
18382 (t (setq column (org-get-indentation))))))
18384 (if (<= (current-column) (current-indentation))
18385 (org-indent-line-to column)
18386 (save-excursion (org-indent-line-to column)))
18387 (setq column (current-column))
18388 (beginning-of-line 1)
18390 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
18391 (replace-match (concat (match-string 1)
18392 (format org-property-format
18393 (match-string 2) (match-string 3)))
18395 (org-move-to-column column)))
18397 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
18398 "Variable to store copy of `adaptive-fill-regexp'.
18399 Since `adaptive-fill-regexp' is set to never match, we need to
18400 store a backup of its value before entering `org-mode' so that
18401 the functionality can be provided as a fall-back.")
18403 (defun org-set-autofill-regexps ()
18405 ;; In the paragraph separator we include headlines, because filling
18406 ;; text in a line directly attached to a headline would otherwise
18407 ;; fill the headline as well.
18408 (org-set-local 'comment-start-skip "^#+[ \t]*")
18409 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
18410 ;; The paragraph starter includes hand-formatted lists.
18418 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
18421 "\\\\\\(begin\\|end\\|[][]\\)"))
18422 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
18423 ;; But only if the user has not turned off tables or fixed-width regions
18425 'auto-fill-inhibit-regexp
18426 (concat "\\*+ \\|#\\+"
18427 "\\|[ \t]*" org-keyword-time-regexp
18428 (if (or org-enable-table-editor org-enable-fixed-width-editor)
18431 (if org-enable-table-editor "|" "")
18432 (if org-enable-fixed-width-editor ":" "")
18434 ;; We use our own fill-paragraph function, to make sure that tables
18435 ;; and fixed-width regions are not wrapped. That function will pass
18436 ;; through to `fill-paragraph' when appropriate.
18437 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
18438 ;; Adaptive filling: To get full control, first make sure that
18439 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
18440 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
18441 (org-set-local 'org-adaptive-fill-regexp-backup
18442 adaptive-fill-regexp))
18443 (org-set-local 'adaptive-fill-regexp "\000")
18444 (org-set-local 'adaptive-fill-function
18445 'org-adaptive-fill-function)
18447 'align-mode-rules-list
18448 '((org-in-buffer-settings
18449 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
18450 (modes . '(org-mode))))))
18452 (defun org-fill-paragraph (&optional justify)
18453 "Re-align a table, pass through to fill-paragraph if no table."
18454 (let ((table-p (org-at-table-p))
18455 (table.el-p (org-at-table.el-p)))
18456 (cond ((and (equal (char-after (point-at-bol)) ?*)
18457 (save-excursion (goto-char (point-at-bol))
18458 (looking-at outline-regexp)))
18459 t) ; skip headlines
18460 (table.el-p t) ; skip table.el tables
18461 (table-p (org-table-align) t) ; align org-mode tables
18462 (t nil)))) ; call paragraph-fill
18464 ;; For reference, this is the default value of adaptive-fill-regexp
18465 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
18467 (defun org-adaptive-fill-function ()
18468 "Return a fill prefix for org-mode files.
18469 In particular, this makes sure hanging paragraphs for hand-formatted lists
18473 ((looking-at "#[ \t]+")
18474 (match-string-no-properties 0))
18475 ;; Description list
18476 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
18478 (if (> (match-end 1) (+ (match-beginning 1)
18479 org-description-max-indent))
18480 (goto-char (+ (match-beginning 1) 5))
18481 (goto-char (match-end 0)))
18482 (make-string (current-column) ?\ )))
18483 ;; Ordered or unordered list
18484 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
18486 (goto-char (match-end 0))
18487 (make-string (current-column) ?\ )))
18489 ((looking-at org-adaptive-fill-regexp-backup)
18490 (match-string-no-properties 0))))
18494 (defun org-toggle-fixed-width-section (arg)
18495 "Toggle the fixed-width export.
18496 If there is no active region, the QUOTE keyword at the current headline is
18497 inserted or removed. When present, it causes the text between this headline
18498 and the next to be exported as fixed-width text, and unmodified.
18499 If there is an active region, this command adds or removes a colon as the
18500 first character of this line. If the first character of a line is a colon,
18501 this line is also exported in fixed-width font."
18504 (regionp (org-region-active-p))
18505 (beg (if regionp (region-beginning) (point)))
18506 (end (if regionp (region-end)))
18507 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
18508 (case-fold-search nil)
18509 (re "[ \t]*\\(: \\)")
18514 (setq cc (current-column))
18515 (beginning-of-line 1)
18516 (setq off (looking-at re))
18517 (while (> nlines 0)
18518 (setq nlines (1- nlines))
18519 (beginning-of-line 1)
18522 (org-move-to-column cc t)
18525 ((and off (looking-at re))
18526 (replace-match "" t t nil 1))
18527 ((not off) (org-move-to-column cc t) (insert ": ")))
18530 (org-back-to-heading)
18531 (if (looking-at (concat outline-regexp
18532 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
18533 (replace-match "" t t nil 1)
18534 (if (looking-at outline-regexp)
18536 (goto-char (match-end 0))
18537 (insert org-quote-string " "))))))))
18539 (defun org-reftex-citation ()
18540 "Use reftex-citation to insert a citation into the buffer.
18541 This looks for a line like
18543 #+BIBLIOGRAPHY: foo plain option:-d
18545 and derives from it that foo.bib is the bibliography file relevant
18546 for this document. It then installs the necessary environment for RefTeX
18547 to work in this buffer and calls `reftex-citation' to insert a citation
18550 Export of such citations to both LaTeX and HTML is handled by the contributed
18551 package org-exp-bibtex by Taru Karttunen."
18553 (let ((reftex-docstruct-symbol 'rds)
18554 (reftex-cite-format "\\cite{%l}")
18559 (let ((case-fold-search t)
18560 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
18561 (if (not (save-excursion
18562 (or (re-search-forward re nil t)
18563 (re-search-backward re nil t))))
18564 (error "No bibliography defined in file")
18565 (setq bib (concat (match-string 1) ".bib")
18566 rds (list (list 'bib bib)))))))
18567 (call-interactively 'reftex-citation)))
18569 ;;;; Functions extending outline functionality
18571 (defun org-beginning-of-line (&optional arg)
18572 "Go to the beginning of the current line. If that is invisible, continue
18573 to a visible line beginning. This makes the function of C-a more intuitive.
18574 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18575 first attempt, and only move to after the tags when the cursor is already
18576 beyond the end of the headline."
18578 (let ((pos (point))
18579 (special (if (consp org-special-ctrl-a/e)
18580 (car org-special-ctrl-a/e)
18581 org-special-ctrl-a/e))
18583 (if (org-bound-and-true-p line-move-visual)
18584 (beginning-of-visual-line 1)
18585 (beginning-of-line 1))
18586 (if (and arg (fboundp 'move-beginning-of-line))
18587 (call-interactively 'move-beginning-of-line)
18591 (if (org-truely-invisible-p)
18592 (while (and (not (bobp)) (org-truely-invisible-p))
18594 (beginning-of-line 1))
18595 (forward-char 1))))
18598 ((and (looking-at org-complex-heading-regexp)
18599 (= (char-after (match-end 1)) ?\ ))
18600 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
18604 (cond ((> pos refpos) refpos)
18605 ((= pos (point)) refpos)
18607 (cond ((> pos (point)) (point))
18608 ((not (eq last-command this-command)) (point))
18613 (cond ((> pos (match-end 4)) (match-end 4))
18614 ((= pos (point)) (match-end 4))
18616 (cond ((> pos (point)) (point))
18617 ((not (eq last-command this-command)) (point))
18618 (t (match-end 4))))))))
18620 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18622 (defun org-end-of-line (&optional arg)
18623 "Go to the end of the line.
18624 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18625 first attempt, and only move to after the tags when the cursor is already
18626 beyond the end of the headline."
18628 (let ((special (if (consp org-special-ctrl-a/e)
18629 (cdr org-special-ctrl-a/e)
18630 org-special-ctrl-a/e)))
18631 (if (or (not special)
18632 (not (org-on-heading-p))
18634 (call-interactively
18635 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
18636 ((fboundp 'move-end-of-line) 'move-end-of-line)
18638 (let ((pos (point)))
18639 (beginning-of-line 1)
18640 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
18642 (if (or (< pos (match-beginning 1))
18643 (= pos (match-end 0)))
18644 (goto-char (match-beginning 1))
18645 (goto-char (match-end 0)))
18646 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
18647 (goto-char (match-end 0))
18648 (goto-char (match-beginning 1))))
18649 (call-interactively (if (fboundp 'move-end-of-line)
18653 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18655 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
18656 (define-key org-mode-map "\C-e" 'org-end-of-line)
18657 (define-key org-mode-map [home] 'org-beginning-of-line)
18658 (define-key org-mode-map [end] 'org-end-of-line)
18660 (defun org-backward-sentence (&optional arg)
18661 "Go to beginning of sentence, or beginning of table field.
18662 This will call `backward-sentence' or `org-table-beginning-of-field',
18663 depending on context."
18666 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
18667 (t (call-interactively 'backward-sentence))))
18669 (defun org-forward-sentence (&optional arg)
18670 "Go to end of sentence, or end of table field.
18671 This will call `forward-sentence' or `org-table-end-of-field',
18672 depending on context."
18675 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
18676 (t (call-interactively 'forward-sentence))))
18678 (define-key org-mode-map "\M-a" 'org-backward-sentence)
18679 (define-key org-mode-map "\M-e" 'org-forward-sentence)
18681 (defun org-kill-line (&optional arg)
18682 "Kill line, to tags or end of line."
18685 ((or (not org-special-ctrl-k)
18687 (not (org-on-heading-p)))
18688 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
18689 org-ctrl-k-protect-subtree)
18690 (if (or (eq org-ctrl-k-protect-subtree 'error)
18691 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
18692 (error "C-k aborted - would kill hidden subtree")))
18693 (call-interactively 'kill-line))
18694 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
18695 (kill-region (point) (match-beginning 1))
18696 (org-set-tags nil t))
18697 (t (kill-region (point) (point-at-eol)))))
18699 (define-key org-mode-map "\C-k" 'org-kill-line)
18701 (defun org-yank (&optional arg)
18702 "Yank. If the kill is a subtree, treat it specially.
18703 This command will look at the current kill and check if is a single
18704 subtree, or a series of subtrees[1]. If it passes the test, and if the
18705 cursor is at the beginning of a line or after the stars of a currently
18706 empty headline, then the yank is handled specially. How exactly depends
18707 on the value of the following variables, both set by default.
18709 org-yank-folded-subtrees
18710 When set, the subtree(s) will be folded after insertion, but only
18711 if doing so would now swallow text after the yanked text.
18713 org-yank-adjusted-subtrees
18714 When set, the subtree will be promoted or demoted in order to
18715 fit into the local outline tree structure, which means that the level
18716 will be adjusted so that it becomes the smaller one of the two
18717 *visible* surrounding headings.
18719 Any prefix to this command will cause `yank' to be called directly with
18720 no special treatment. In particular, a simple `C-u' prefix will just
18721 plainly yank the text as it is.
18723 \[1] The test checks if the first non-white line is a heading
18724 and if there are no other headings with fewer stars."
18726 (org-yank-generic 'yank arg))
18728 (defun org-yank-generic (command arg)
18729 "Perform some yank-like command.
18731 This function implements the behavior described in the `org-yank'
18732 documentation. However, it has been generalized to work for any
18733 interactive command with similar behavior."
18735 ;; pretend to be command COMMAND
18736 (setq this-command command)
18739 (call-interactively command)
18741 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18742 (and (org-kill-is-subtree-p)
18744 (and (looking-at "[ \t]*$")
18747 (buffer-substring (point-at-bol) (point)))))))
18750 ((and subtreep org-yank-folded-subtrees)
18751 (let ((beg (point))
18753 (if (and subtreep org-yank-adjusted-subtrees)
18754 (org-paste-subtree nil nil 'for-yank)
18755 (call-interactively command))
18759 (when (and (bolp) subtreep
18760 (not (setq swallowp
18761 (org-yank-folding-would-swallow-text beg end))))
18762 (or (looking-at outline-regexp)
18763 (re-search-forward (concat "^" outline-regexp) end t))
18764 (while (and (< (point) end) (looking-at outline-regexp))
18766 (org-cycle-show-empty-lines 'folded)
18767 (condition-case nil
18768 (outline-forward-same-level 1)
18769 (error (goto-char end)))))
18772 "Inserted text not folded because that would swallow text"))
18775 (skip-chars-forward " \t\n\r")
18776 (beginning-of-line 1)
18777 (push-mark beg 'nomsg)))
18778 ((and subtreep org-yank-adjusted-subtrees)
18779 (let ((beg (point-at-bol)))
18780 (org-paste-subtree nil nil 'for-yank)
18781 (push-mark beg 'nomsg)))
18783 (call-interactively command))))))
18785 (defun org-yank-folding-would-swallow-text (beg end)
18786 "Would hide-subtree at BEG swallow any text after END?"
18790 (when (or (looking-at outline-regexp)
18791 (re-search-forward (concat "^" outline-regexp) end t))
18792 (setq level (org-outline-level)))
18794 (skip-chars-forward " \t\r\n\v\f")
18796 (and (bolp) (looking-at org-outline-regexp)
18797 (<= (org-outline-level) level)))
18798 nil ; Nothing would be swallowed
18799 t)))) ; something would swallow
18801 (define-key org-mode-map "\C-y" 'org-yank)
18803 (defun org-invisible-p ()
18804 "Check if point is at a character currently not visible."
18805 ;; Early versions of noutline don't have `outline-invisible-p'.
18806 (if (fboundp 'outline-invisible-p)
18807 (outline-invisible-p)
18808 (get-char-property (point) 'invisible)))
18810 (defun org-truely-invisible-p ()
18811 "Check if point is at a character currently not visible.
18812 This version does not only check the character property, but also
18814 ;; Early versions of noutline don't have `outline-invisible-p'.
18815 (if (org-bound-and-true-p visible-mode)
18817 (if (fboundp 'outline-invisible-p)
18818 (outline-invisible-p)
18819 (get-char-property (point) 'invisible))))
18821 (defun org-invisible-p2 ()
18822 "Check if point is at a character currently not visible."
18824 (if (and (eolp) (not (bobp))) (backward-char 1))
18825 ;; Early versions of noutline don't have `outline-invisible-p'.
18826 (if (fboundp 'outline-invisible-p)
18827 (outline-invisible-p)
18828 (get-char-property (point) 'invisible))))
18830 (defun org-back-to-heading (&optional invisible-ok)
18831 "Call `outline-back-to-heading', but provide a better error message."
18832 (condition-case nil
18833 (outline-back-to-heading invisible-ok)
18834 (error (error "Before first headline at position %d in buffer %s"
18835 (point) (current-buffer)))))
18837 (defun org-beginning-of-defun ()
18838 "Go to the beginning of the subtree, i.e. back to the heading."
18839 (org-back-to-heading))
18840 (defun org-end-of-defun ()
18841 "Go to the end of the subtree."
18842 (org-end-of-subtree nil t))
18844 (defun org-before-first-heading-p ()
18845 "Before first heading?"
18847 (null (re-search-backward "^\\*+ " nil t))))
18849 (defun org-on-heading-p (&optional ignored)
18850 (outline-on-heading-p t))
18851 (defun org-at-heading-p (&optional ignored)
18852 (outline-on-heading-p t))
18854 (defun org-point-at-end-of-empty-headline ()
18855 "If point is at the end of an empty headline, return t, else nil.
18856 If the heading only contains a TODO keyword, it is still still considered
18858 (and (looking-at "[ \t]*$")
18860 (beginning-of-line 1)
18861 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18863 (defun org-at-heading-or-item-p ()
18864 (or (org-on-heading-p) (org-at-item-p)))
18866 (defun org-on-target-p ()
18867 (or (org-in-regexp org-radio-target-regexp)
18868 (org-in-regexp org-target-regexp)))
18870 (defun org-up-heading-all (arg)
18871 "Move to the heading line of which the present line is a subheading.
18872 This function considers both visible and invisible heading lines.
18873 With argument, move up ARG levels."
18874 (if (fboundp 'outline-up-heading-all)
18875 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18876 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18878 (defun org-up-heading-safe ()
18879 "Move to the heading line of which the present line is a subheading.
18880 This version will not throw an error. It will return the level of the
18881 headline found, or nil if no higher level is found.
18883 Also, this function will be a lot faster than `outline-up-heading',
18884 because it relies on stars being the outline starters. This can really
18885 make a significant difference in outlines with very many siblings."
18886 (let (start-level re)
18887 (org-back-to-heading t)
18888 (setq start-level (funcall outline-level))
18889 (if (equal start-level 1)
18891 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18892 (if (re-search-backward re nil t)
18893 (funcall outline-level)))))
18895 (defun org-first-sibling-p ()
18896 "Is this heading the first child of its parents?"
18898 (let ((re (concat "^" outline-regexp))
18900 (unless (org-at-heading-p t)
18901 (error "Not at a heading"))
18902 (setq level (funcall outline-level))
18904 (if (not (re-search-backward re nil t))
18906 (setq l (funcall outline-level))
18909 (defun org-goto-sibling (&optional previous)
18910 "Goto the next sibling, even if it is invisible.
18911 When PREVIOUS is set, go to the previous sibling instead. Returns t
18912 when a sibling was found. When none is found, return nil and don't
18914 (let ((fun (if previous 're-search-backward 're-search-forward))
18916 (re (concat "^" outline-regexp))
18918 (when (condition-case nil (org-back-to-heading t) (error nil))
18919 (setq level (funcall outline-level))
18921 (or previous (forward-char 1))
18922 (while (funcall fun re nil t)
18923 (setq l (funcall outline-level))
18924 (when (< l level) (goto-char pos) (throw 'exit nil))
18925 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18929 (defun org-show-siblings ()
18930 "Show all siblings of the current headline."
18932 (while (org-goto-sibling) (org-flag-heading nil)))
18934 (while (org-goto-sibling 'previous)
18935 (org-flag-heading nil))))
18937 (defun org-show-hidden-entry ()
18938 "Show an entry where even the heading is hidden."
18942 (defun org-flag-heading (flag &optional entry)
18943 "Flag the current heading. FLAG non-nil means make invisible.
18944 When ENTRY is non-nil, show the entire entry."
18946 (org-back-to-heading t)
18947 ;; Check if we should show the entire entry
18952 (and (outline-next-heading)
18953 (org-flag-heading nil))))
18954 (outline-flag-region (max (point-min) (1- (point)))
18955 (save-excursion (outline-end-of-heading) (point))
18958 (defun org-get-next-sibling ()
18959 "Move to next heading of the same level, and return point.
18960 If there is no such heading, return nil.
18961 This is like outline-next-sibling, but invisible headings are ok."
18962 (let ((level (funcall outline-level)))
18963 (outline-next-heading)
18964 (while (and (not (eobp)) (> (funcall outline-level) level))
18965 (outline-next-heading))
18966 (if (or (eobp) (< (funcall outline-level) level))
18970 (defun org-get-last-sibling ()
18971 "Move to previous heading of the same level, and return point.
18972 If there is no such heading, return nil."
18973 (let ((opoint (point))
18974 (level (funcall outline-level)))
18975 (outline-previous-heading)
18976 (when (and (/= (point) opoint) (outline-on-heading-p t))
18977 (while (and (> (funcall outline-level) level)
18979 (outline-previous-heading))
18980 (if (< (funcall outline-level) level)
18984 (defun org-end-of-subtree (&optional invisible-OK to-heading)
18985 ;; This contains an exact copy of the original function, but it uses
18986 ;; `org-back-to-heading', to make it work also in invisible
18987 ;; trees. And is uses an invisible-OK argument.
18988 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
18989 ;; Furthermore, when used inside Org, finding the end of a large subtree
18990 ;; with many children and grandchildren etc, this can be much faster
18991 ;; than the outline version.
18992 (org-back-to-heading invisible-OK)
18994 (level (funcall outline-level)))
18995 (if (and (org-mode-p) (< level 1000))
18996 ;; A true heading (not a plain list item), in Org-mode
18997 ;; This means we can easily find the end by looking
18998 ;; only for the right number of stars. Using a regexp to do
18999 ;; this is so much faster than using a Lisp loop.
19000 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
19002 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
19003 ;; something else, do it the slow way
19004 (while (and (not (eobp))
19005 (or first (> (funcall outline-level) level)))
19007 (outline-next-heading)))
19009 (if (memq (preceding-char) '(?\n ?\^M))
19011 ;; Go to end of line before heading
19013 (if (memq (preceding-char) '(?\n ?\^M))
19014 ;; leave blank line before heading
19015 (forward-char -1))))))
19018 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
19019 "Use Org version in org-mode, for dramatic speed-up."
19020 (if (eq major-mode 'org-mode)
19022 (org-end-of-subtree nil t)
19023 (unless (eobp) (backward-char 1)))
19026 (defun org-forward-same-level (arg &optional invisible-ok)
19027 "Move forward to the arg'th subheading at same level as this one.
19028 Stop at the first and last subheadings of a superior heading."
19030 (org-back-to-heading invisible-ok)
19032 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19033 (re (format "^\\*\\{1,%d\\} " level))
19037 (while (and (re-search-forward re nil 'move)
19038 (setq l (- (match-end 0) (match-beginning 0) 1))
19041 (progn (backward-char 1) (org-invisible-p)))
19042 (if (< l level) (setq arg 1)))
19043 (setq arg (1- arg)))
19044 (beginning-of-line 1)))
19046 (defun org-backward-same-level (arg &optional invisible-ok)
19047 "Move backward to the arg'th subheading at same level as this one.
19048 Stop at the first and last subheadings of a superior heading."
19050 (org-back-to-heading)
19052 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19053 (re (format "^\\*\\{1,%d\\} " level))
19056 (while (and (re-search-backward re nil 'move)
19057 (setq l (- (match-end 0) (match-beginning 0) 1))
19061 (if (< l level) (setq arg 1)))
19062 (setq arg (1- arg)))))
19064 (defun org-show-subtree ()
19065 "Show everything after this heading at deeper levels."
19066 (outline-flag-region
19069 (org-end-of-subtree t t))
19072 (defun org-show-entry ()
19073 "Show the body directly following this heading.
19074 Show the heading too, if it is currently invisible."
19077 (condition-case nil
19079 (org-back-to-heading t)
19080 (outline-flag-region
19081 (max (point-min) (1- (point)))
19083 (if (re-search-forward
19084 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
19085 (match-beginning 1)
19088 (org-cycle-hide-drawers 'children))
19091 (defun org-make-options-regexp (kwds &optional extra)
19092 "Make a regular expression for keyword lines."
19096 (mapconcat 'regexp-quote kwds "\\|")
19097 (if extra (concat "\\|" extra))
19101 ;; Make isearch reveal the necessary context
19102 (defun org-isearch-end ()
19103 "Reveal context after isearch exits."
19104 (when isearch-success ; only if search was successful
19105 (if (featurep 'xemacs)
19106 ;; Under XEmacs, the hook is run in the correct place,
19107 ;; we directly show the context.
19108 (org-show-context 'isearch)
19109 ;; In Emacs the hook runs *before* restoring the overlays.
19110 ;; So we have to use a one-time post-command-hook to do this.
19111 ;; (Emacs 22 has a special variable, see function `org-mode')
19112 (unless (and (boundp 'isearch-mode-end-hook-quit)
19113 isearch-mode-end-hook-quit)
19114 ;; Only when the isearch was not quitted.
19115 (org-add-hook 'post-command-hook 'org-isearch-post-command
19116 'append 'local)))))
19118 (defun org-isearch-post-command ()
19119 "Remove self from hook, and show context."
19120 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
19121 (org-show-context 'isearch))
19124 ;;;; Integration with and fixes for other packages
19128 (defvar org-imenu-markers nil
19129 "All markers currently used by Imenu.")
19130 (make-variable-buffer-local 'org-imenu-markers)
19132 (defun org-imenu-new-marker (&optional pos)
19133 "Return a new marker for use by Imenu, and remember the marker."
19134 (let ((m (make-marker)))
19135 (move-marker m (or pos (point)))
19136 (push m org-imenu-markers)
19139 (defun org-imenu-get-tree ()
19140 "Produce the index for Imenu."
19141 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
19142 (setq org-imenu-markers nil)
19143 (let* ((n org-imenu-depth)
19144 (re (concat "^" outline-regexp))
19145 (subs (make-vector (1+ n) nil))
19151 (goto-char (point-max))
19152 (while (re-search-backward re nil t)
19153 (setq level (org-reduced-level (funcall outline-level)))
19155 (looking-at org-complex-heading-regexp)
19156 (setq head (org-link-display-format
19157 (org-match-string-no-properties 4))
19158 m (org-imenu-new-marker))
19159 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
19160 (if (>= level last-level)
19161 (push (cons head m) (aref subs level))
19162 (push (cons head (aref subs (1+ level))) (aref subs level))
19163 (loop for i from (1+ level) to n do (aset subs i nil)))
19164 (setq last-level level)))))
19167 (eval-after-load "imenu"
19169 (add-hook 'imenu-after-jump-hook
19171 (if (eq major-mode 'org-mode)
19172 (org-show-context 'org-goto))))))
19174 (defun org-link-display-format (link)
19175 "Replace a link with either the description, or the link target
19176 if no description is present"
19178 (if (string-match org-bracket-link-analytic-regexp link)
19179 (replace-match (if (match-end 5)
19180 (match-string 5 link)
19181 (concat (match-string 1 link)
19182 (match-string 3 link)))
19186 ;; Speedbar support
19188 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
19189 "Overlay marking the agenda restriction line in speedbar.")
19190 (overlay-put org-speedbar-restriction-lock-overlay
19191 'face 'org-agenda-restriction-lock)
19192 (overlay-put org-speedbar-restriction-lock-overlay
19193 'help-echo "Agendas are currently limited to this item.")
19194 (org-detach-overlay org-speedbar-restriction-lock-overlay)
19196 (defun org-speedbar-set-agenda-restriction ()
19197 "Restrict future agenda commands to the location at point in speedbar.
19198 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
19200 (require 'org-agenda)
19201 (let (p m tp np dir txt)
19203 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19205 (setq m (get-text-property p 'org-imenu-marker))
19206 (with-current-buffer (marker-buffer m)
19208 (org-agenda-set-restriction-lock 'subtree)))
19209 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19210 'speedbar-function 'speedbar-find-file))
19211 (setq tp (previous-single-property-change
19212 (1+ p) 'speedbar-function)
19213 np (next-single-property-change
19214 tp 'speedbar-function)
19215 dir (speedbar-line-directory)
19216 txt (buffer-substring-no-properties (or tp (point-min))
19217 (or np (point-max))))
19218 (with-current-buffer (find-file-noselect
19219 (let ((default-directory dir))
19220 (expand-file-name txt)))
19221 (unless (org-mode-p)
19222 (error "Cannot restrict to non-Org-mode file"))
19223 (org-agenda-set-restriction-lock 'file)))
19224 (t (error "Don't know how to restrict Org-mode's agenda")))
19225 (move-overlay org-speedbar-restriction-lock-overlay
19226 (point-at-bol) (point-at-eol))
19227 (setq current-prefix-arg nil)
19228 (org-agenda-maybe-redo)))
19230 (eval-after-load "speedbar"
19232 (speedbar-add-supported-extension ".org")
19233 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
19234 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
19235 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
19236 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
19237 (add-hook 'speedbar-visiting-tag-hook
19238 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
19240 ;;; Fixes and Hacks for problems with other packages
19242 ;; Make flyspell not check words in links, to not mess up our keymap
19243 (defun org-mode-flyspell-verify ()
19244 "Don't let flyspell put overlays at active buttons."
19245 (and (not (get-text-property (point) 'keymap))
19246 (not (get-text-property (point) 'org-no-flyspell))))
19248 (defun org-remove-flyspell-overlays-in (beg end)
19249 "Remove flyspell overlays in region."
19250 (and (org-bound-and-true-p flyspell-mode)
19251 (fboundp 'flyspell-delete-region-overlays)
19252 (flyspell-delete-region-overlays beg end))
19253 (add-text-properties beg end '(org-no-flyspell t)))
19255 ;; Make `bookmark-jump' shows the jump location if it was hidden.
19256 (eval-after-load "bookmark"
19257 '(if (boundp 'bookmark-after-jump-hook)
19258 ;; We can use the hook
19259 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
19260 ;; Hook not available, use advice
19261 (defadvice bookmark-jump (after org-make-visible activate)
19262 "Make the position visible."
19263 (org-bookmark-jump-unhide))))
19265 ;; Make sure saveplace shows the location if it was hidden
19266 (eval-after-load "saveplace"
19267 '(defadvice save-place-find-file-hook (after org-make-visible activate)
19268 "Make the position visible."
19269 (org-bookmark-jump-unhide)))
19271 ;; Make sure ecb shows the location if it was hidden
19272 (eval-after-load "ecb"
19273 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
19274 "Make hierarchy visible when jumping into location from ECB tree buffer."
19275 (if (eq major-mode 'org-mode)
19276 (org-show-context))))
19278 (defun org-bookmark-jump-unhide ()
19279 "Unhide the current position, to show the bookmark location."
19281 (or (org-invisible-p)
19282 (save-excursion (goto-char (max (point-min) (1- (point))))
19283 (org-invisible-p)))
19284 (org-show-context 'bookmark-jump)))
19286 ;; Make session.el ignore our circular variable
19287 (eval-after-load "session"
19288 '(add-to-list 'session-globals-exclude 'org-mark-ring))
19290 ;;;; Experimental code
19292 (defun org-closed-in-range ()
19293 "Sparse tree of items closed in a certain time range.
19294 Still experimental, may disappear in the future."
19296 ;; Get the time interval from the user.
19297 (let* ((time1 (org-float-time
19298 (org-read-date nil 'to-time nil "Starting date: ")))
19299 (time2 (org-float-time
19300 (org-read-date nil 'to-time nil "End date:")))
19301 ;; callback function
19302 (callback (lambda ()
19305 (apply 'encode-time
19306 (org-parse-time-string
19307 (match-string 1))))))
19308 ;; check if time in interval
19309 (and (>= time time1) (<= time time2))))))
19310 ;; make tree, check each match with the callback
19311 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
19317 (run-hooks 'org-load-hook)
19319 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
19321 ;;; org.el ends here