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
)
107 ;;;; Customization variables
111 (defconst org-version
"6.35trans"
112 "The version number of the file org.el.")
114 (defun org-version (&optional here
)
115 "Show the org-mode version in the echo area.
116 With prefix arg HERE, insert it at point."
118 (let* ((origin default-directory
)
119 (version org-version
)
121 (dir (concat (file-name-directory (locate-library "org")) "../" )))
122 (when (and (file-exists-p (expand-file-name ".git" dir
))
123 (executable-find "git"))
127 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
128 (with-current-buffer "*Shell Command Output*"
129 (goto-char (point-min))
130 (setq git-version
(buffer-substring (point) (point-at-eol))))
131 (subst-char-in-string ?- ?. git-version t
)
132 (when (string-match "\\S-"
133 (shell-command-to-string
134 "git diff-index --name-only HEAD --"))
135 (setq git-version
(concat git-version
".dirty")))
136 (setq version
(concat version
" (" git-version
")"))))
138 (setq version
(format "Org-mode version %s" version
))
139 (if here
(insert version
))
142 ;;; Compatibility constants
144 ;;; The custom variables
147 "Outline-based notes management and organizer."
152 (defcustom org-mode-hook nil
153 "Mode hook for Org-mode, run after the mode was turned on."
157 (defcustom org-load-hook nil
158 "Hook that is run after org.el has been loaded."
162 (defvar org-modules
) ; defined below
163 (defvar org-modules-loaded nil
164 "Have the modules been loaded already?")
166 (defun org-load-modules-maybe (&optional force
)
167 "Load all extensions listed in `org-modules'."
168 (when (or force
(not org-modules-loaded
))
170 (condition-case nil
(require ext
)
171 (error (message "Problems while trying to load feature `%s'" ext
))))
173 (setq org-modules-loaded t
)))
175 (defun org-set-modules (var value
)
176 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
178 (when (featurep 'org
)
179 (org-load-modules-maybe 'force
)))
181 (when (org-bound-and-true-p org-modules
)
182 (let ((a (member 'org-infojs org-modules
)))
183 (and a
(setcar a
'org-jsinfo
))))
185 (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
)
186 "Modules that should always be loaded together with org.el.
187 If a description starts with <C>, the file is not part of Emacs
188 and loading it will require that you have downloaded and properly installed
189 the org-mode distribution.
191 You can also use this system to load external packages (i.e. neither Org
192 core modules, nor modules from the CONTRIB directory). Just add symbols
193 to the end of the list. If the package is called org-xyz.el, then you need
194 to add the symbol `xyz', and the package must have a call to
198 :set
'org-set-modules
201 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
202 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
203 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
204 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
205 (const :tag
" docview: Links to doc-view buffers" org-docview
)
206 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
207 (const :tag
" id: Global IDs for identifying entries" org-id
)
208 (const :tag
" info: Links to Info nodes" org-info
)
209 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
210 (const :tag
" habit: Track your consistency with habits" org-habit
)
211 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
212 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
213 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
214 (const :tag
" mew Links to Mew folders/messages" org-mew
)
215 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
216 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
217 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
218 (const :tag
" vm: Links to VM folders/messages" org-vm
)
219 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
220 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
221 (const :tag
" mouse: Additional mouse support" org-mouse
)
223 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
224 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
225 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
226 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
227 (const :tag
"C collector: Collect properties into tables" org-collector
)
228 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
229 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
230 (const :tag
"C eval: Include command output as text" org-eval
)
231 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
232 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
233 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
234 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
235 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
237 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
239 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
240 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
241 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
242 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
243 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
244 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
245 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
246 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
247 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
248 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
249 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
250 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
251 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
252 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
253 (const :tag
"C track: Keep up with Org-mode development" org-track
)
254 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
256 (defcustom org-support-shift-select nil
257 "Non-nil means make shift-cursor commands select text when possible.
259 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
260 selecting a region, or enlarge thusly regions started in this way.
261 In Org-mode, in special contexts, these same keys are used for other
262 purposes, important enough to compete with shift selection. Org tries
263 to balance these needs by supporting `shift-select-mode' outside these
264 special contexts, under control of this variable.
266 The default of this variable is nil, to avoid confusing behavior. Shifted
267 cursor keys will then execute Org commands in the following contexts:
268 - on a headline, changing TODO state (left/right) and priority (up/down)
269 - on a time stamp, changing the time
270 - in a plain list item, changing the bullet type
271 - in a property definition line, switching between allowed values
272 - in the BEGIN line of a clock table (changing the time block).
273 Outside these contexts, the commands will throw an error.
275 When this variable is t and the cursor is not in a special context,
276 Org-mode will support shift-selection for making and enlarging regions.
277 To make this more effective, the bullet cycling will no longer happen
278 anywhere in an item line, but only if the cursor is exactly on the bullet.
280 If you set this variable to the symbol `always', then the keys
281 will not be special in headlines, property lines, and item lines, to make
282 shift selection work there as well. If this is what you want, you can
283 use the following alternative commands: `C-c C-t' and `C-c ,' to
284 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
285 TODO sets, `C-c -' to cycle item bullet types, and properties can be
286 edited by hand or in column view.
288 However, when the cursor is on a timestamp, shift-cursor commands
289 will still edit the time stamp - this is just too good to give up.
291 XEmacs user should have this variable set to nil, because shift-select-mode
295 (const :tag
"Never" nil
)
296 (const :tag
"When outside special context" t
)
297 (const :tag
"Everywhere except timestamps" always
)))
299 (defgroup org-startup nil
300 "Options concerning startup of Org-mode."
304 (defcustom org-startup-folded t
305 "Non-nil means entering Org-mode will switch to OVERVIEW.
306 This can also be configured on a per-file basis by adding one of
307 the following lines anywhere in the buffer:
309 #+STARTUP: fold (or `overview', this is equivalent)
310 #+STARTUP: nofold (or `showall', this is equivalent)
312 #+STARTUP: showeverything"
315 (const :tag
"nofold: show all" nil
)
316 (const :tag
"fold: overview" t
)
317 (const :tag
"content: all headlines" content
)
318 (const :tag
"show everything, even drawers" showeverything
)))
320 (defcustom org-startup-truncated t
321 "Non-nil means entering Org-mode will set `truncate-lines'.
322 This is useful since some lines containing links can be very long and
323 uninteresting. Also tables look terrible when wrapped."
327 (defcustom org-startup-indented nil
328 "Non-nil means turn on `org-indent-mode' on startup.
329 This can also be configured on a per-file basis by adding one of
330 the following lines anywhere in the buffer:
334 :group
'org-structure
336 (const :tag
"Not" nil
)
337 (const :tag
"Globally (slow on startup in large files)" t
)))
339 (defcustom org-startup-with-beamer-mode nil
340 "Non-nil means turn on `org-beamer-mode' on startup.
341 This can also be configured on a per-file basis by adding one of
342 the following lines anywhere in the buffer:
348 (defcustom org-startup-align-all-tables nil
349 "Non-nil means align all tables when visiting a file.
350 This is useful when the column width in tables is forced with <N> cookies
351 in table fields. Such tables will look correct only after the first re-align.
352 This can also be configured on a per-file basis by adding one of
353 the following lines anywhere in the buffer:
359 (defcustom org-insert-mode-line-in-empty-file nil
360 "Non-nil means insert the first line setting Org-mode in empty files.
361 When the function `org-mode' is called interactively in an empty file, this
362 normally means that the file name does not automatically trigger Org-mode.
363 To ensure that the file will always be in Org-mode in the future, a
364 line enforcing Org-mode will be inserted into the buffer, if this option
369 (defcustom org-replace-disputed-keys nil
370 "Non-nil means use alternative key bindings for some keys.
371 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
372 These keys are also used by other packages like shift-selection-mode'
373 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
374 If you want to use Org-mode together with one of these other modes,
375 or more generally if you would like to move some Org-mode commands to
376 other keys, set this variable and configure the keys with the variable
379 This option is only relevant at load-time of Org-mode, and must be set
380 *before* org.el is loaded. Changing it requires a restart of Emacs to
385 (defcustom org-use-extra-keys nil
386 "Non-nil means use extra key sequence definitions for certain
387 commands. This happens automatically if you run XEmacs or if
388 window-system is nil. This variable lets you do the same
389 manually. You must set it before loading org.
391 Example: on Carbon Emacs 22 running graphically, with an external
392 keyboard on a Powerbook, the default way of setting M-left might
393 not work for either Alt or ESC. Setting this variable will make
398 (if (fboundp 'defvaralias
)
399 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
401 (defcustom org-disputed-keys
402 '(([(shift up
)] .
[(meta p
)])
403 ([(shift down
)] .
[(meta n
)])
404 ([(shift left
)] .
[(meta -
)])
405 ([(shift right
)] .
[(meta +)])
406 ([(control shift right
)] .
[(meta shift
+)])
407 ([(control shift left
)] .
[(meta shift -
)]))
408 "Keys for which Org-mode and other modes compete.
409 This is an alist, cars are the default keys, second element specifies
410 the alternative to use when `org-replace-disputed-keys' is t.
412 Keys can be specified in any syntax supported by `define-key'.
413 The value of this option takes effect only at Org-mode's startup,
414 therefore you'll have to restart Emacs to apply it after changing."
419 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
420 Or return the original if not disputed."
421 (if org-replace-disputed-keys
422 (let* ((nkey (key-description key
))
423 (x (org-find-if (lambda (x)
424 (equal (key-description (car x
)) nkey
))
429 (defun org-find-if (predicate seq
)
432 (if (funcall predicate
(car seq
))
433 (throw 'exit
(car seq
))
436 (defun org-defkey (keymap key def
)
437 "Define a key, possibly translated, as returned by `org-key'."
438 (define-key keymap
(org-key key
) def
))
440 (defcustom org-ellipsis nil
441 "The ellipsis to use in the Org-mode outline.
442 When nil, just use the standard three dots. When a string, use that instead,
443 When a face, use the standard 3 dots, but with the specified face.
444 The change affects only Org-mode (which will then use its own display table).
445 Changing this requires executing `M-x org-mode' in a buffer to become
448 :type
'(choice (const :tag
"Default" nil
)
449 (face :tag
"Face" :value org-warning
)
450 (string :tag
"String" :value
"...#")))
452 (defvar org-display-table nil
453 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
455 (defgroup org-keywords nil
456 "Keywords in Org-mode."
460 (defcustom org-deadline-string
"DEADLINE:"
461 "String to mark deadline entries.
462 A deadline is this string, followed by a time stamp. Should be a word,
463 terminated by a colon. You can insert a schedule keyword and
464 a timestamp with \\[org-deadline].
465 Changes become only effective after restarting Emacs."
469 (defcustom org-scheduled-string
"SCHEDULED:"
470 "String to mark scheduled TODO entries.
471 A schedule is this string, followed by a time stamp. Should be a word,
472 terminated by a colon. You can insert a schedule keyword and
473 a timestamp with \\[org-schedule].
474 Changes become only effective after restarting Emacs."
478 (defcustom org-closed-string
"CLOSED:"
479 "String used as the prefix for timestamps logging closing a TODO entry."
483 (defcustom org-clock-string
"CLOCK:"
484 "String used as prefix for timestamps clocking work hours on an item."
488 (defcustom org-comment-string
"COMMENT"
489 "Entries starting with this keyword will never be exported.
490 An entry can be toggled between COMMENT and normal with
491 \\[org-toggle-comment].
492 Changes become only effective after restarting Emacs."
496 (defcustom org-quote-string
"QUOTE"
497 "Entries starting with this keyword will be exported in fixed-width font.
498 Quoting applies only to the text in the entry following the headline, and does
499 not extend beyond the next headline, even if that is lower level.
500 An entry can be toggled between QUOTE and normal with
501 \\[org-toggle-fixed-width-section]."
505 (defconst org-repeat-re
506 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
507 "Regular expression for specifying repeated events.
508 After a match, group 1 contains the repeat expression.")
510 (defgroup org-structure nil
511 "Options concerning the general structure of Org-mode files."
515 (defgroup org-reveal-location nil
516 "Options about how to make context of a location visible."
517 :tag
"Org Reveal Location"
518 :group
'org-structure
)
520 (defconst org-context-choice
522 (const :tag
"Always" t
)
523 (const :tag
"Never" nil
)
524 (repeat :greedy t
:tag
"Individual contexts"
526 (choice :tag
"Context"
533 (const bookmark-jump
)
537 "Contexts for the reveal options.")
539 (defcustom org-show-hierarchy-above
'((default . t
))
540 "Non-nil means show full hierarchy when revealing a location.
541 Org-mode often shows locations in an org-mode file which might have
542 been invisible before. When this is set, the hierarchy of headings
543 above the exposed location is shown.
544 Turning this off for example for sparse trees makes them very compact.
545 Instead of t, this can also be an alist specifying this option for different
546 contexts. Valid contexts are
547 agenda when exposing an entry from the agenda
548 org-goto when using the command `org-goto' on key C-c C-j
549 occur-tree when using the command `org-occur' on key C-c /
550 tags-tree when constructing a sparse tree based on tags matches
551 link-search when exposing search matches associated with a link
552 mark-goto when exposing the jump goal of a mark
553 bookmark-jump when exposing a bookmark location
554 isearch when exiting from an incremental search
555 default default for all contexts not set explicitly"
556 :group
'org-reveal-location
557 :type org-context-choice
)
559 (defcustom org-show-following-heading
'((default . nil
))
560 "Non-nil means show following heading when revealing a location.
561 Org-mode often shows locations in an org-mode file which might have
562 been invisible before. When this is set, the heading following the
564 Turning this off for example for sparse trees makes them very compact,
565 but makes it harder to edit the location of the match. In such a case,
566 use the command \\[org-reveal] to show more context.
567 Instead of t, this can also be an alist specifying this option for different
568 contexts. See `org-show-hierarchy-above' for valid contexts."
569 :group
'org-reveal-location
570 :type org-context-choice
)
572 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
573 "Non-nil means show all sibling heading when revealing a location.
574 Org-mode often shows locations in an org-mode file which might have
575 been invisible before. When this is set, the sibling of the current entry
576 heading are all made visible. If `org-show-hierarchy-above' is t,
577 the same happens on each level of the hierarchy above the current entry.
579 By default this is on for the isearch context, off for all other contexts.
580 Turning this off for example for sparse trees makes them very compact,
581 but makes it harder to edit the location of the match. In such a case,
582 use the command \\[org-reveal] to show more context.
583 Instead of t, this can also be an alist specifying this option for different
584 contexts. See `org-show-hierarchy-above' for valid contexts."
585 :group
'org-reveal-location
586 :type org-context-choice
)
588 (defcustom org-show-entry-below
'((default . nil
))
589 "Non-nil means show the entry below a headline when revealing a location.
590 Org-mode often shows locations in an org-mode file which might have
591 been invisible before. When this is set, the text below the headline that is
592 exposed is also shown.
594 By default this is off for all contexts.
595 Instead of t, this can also be an alist specifying this option for different
596 contexts. See `org-show-hierarchy-above' for valid contexts."
597 :group
'org-reveal-location
598 :type org-context-choice
)
600 (defcustom org-indirect-buffer-display
'other-window
601 "How should indirect tree buffers be displayed?
602 This applies to indirect buffers created with the commands
603 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
605 current-window Display in the current window
606 other-window Just display in another window.
607 dedicated-frame Create one new frame, and re-use it each time.
608 new-frame Make a new frame each time. Note that in this case
609 previously-made indirect buffers are kept, and you need to
610 kill these buffers yourself."
611 :group
'org-structure
612 :group
'org-agenda-windows
614 (const :tag
"In current window" current-window
)
615 (const :tag
"In current frame, other window" other-window
)
616 (const :tag
"Each time a new frame" new-frame
)
617 (const :tag
"One dedicated frame" dedicated-frame
)))
619 (defcustom org-use-speed-commands nil
620 "Non-nil means activate single letter commands at beginning of a headline.
621 This may also be a function to test for appropriate locations where speed
622 commands should be active."
623 :group
'org-structure
625 (const :tag
"Never" nil
)
626 (const :tag
"At beginning of headline stars" t
)
629 (defcustom org-speed-commands-user nil
630 "Alist of additional speed commands.
631 This list will be checked before `org-speed-commands-default'
632 when the variable `org-use-speed-commands' is non-nil
633 and when the cursor is at the beginning of a headline.
634 The car if each entry is a string with a single letter, which must
635 be assigned to `self-insert-command' in the global map.
636 The cdr is either a command to be called interactively, a function
637 to be called, or a form to be evaluated.
638 An entry that is just a list with a single string will be interpreted
639 as a descriptive headline that will be added when listing the speed
640 copmmands in the Help buffer using the `?' speed command."
641 :group
'org-structure
642 :type
'(repeat :value
("k" . ignore
)
643 (choice :value
("k" . ignore
)
644 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
645 (cons :tag
"Letter and Command"
646 (string :tag
"Command letter")
651 (defgroup org-cycle nil
652 "Options concerning visibility cycling in Org-mode."
654 :group
'org-structure
)
656 (defcustom org-cycle-skip-children-state-if-no-children t
657 "Non-nil means skip CHILDREN state in entries that don't have any."
661 (defcustom org-cycle-max-level nil
662 "Maximum level which should still be subject to visibility cycling.
663 Levels higher than this will, for cycling, be treated as text, not a headline.
664 When `org-odd-levels-only' is set, a value of N in this variable actually
665 means 2N-1 stars as the limiting headline.
666 When nil, cycle all levels.
667 Note that the limiting level of cycling is also influenced by
668 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
669 `org-inlinetask-min-level' is, cycling will be limited to levels one less
673 (const :tag
"No limit" nil
)
674 (integer :tag
"Maximum level")))
676 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
677 "Names of drawers. Drawers are not opened by cycling on the headline above.
678 Drawers only open with a TAB on the drawer line itself. A drawer looks like
683 The drawer \"PROPERTIES\" is special for capturing properties through
686 Drawers can be defined on the per-file basis with a line like:
688 #+DRAWERS: HIDDEN STATE PROPERTIES"
689 :group
'org-structure
691 :type
'(repeat (string :tag
"Drawer Name")))
693 (defcustom org-hide-block-startup nil
694 "Non-nil means entering Org-mode will fold all blocks.
695 This can also be set in on a per-file basis with
697 #+STARTUP: hideblocks
698 #+STARTUP: showblocks"
703 (defcustom org-cycle-global-at-bob nil
704 "Cycle globally if cursor is at beginning of buffer and not at a headline.
705 This makes it possible to do global cycling without having to use S-TAB or
706 C-u TAB. For this special case to work, the first line of the buffer
707 must not be a headline - it may be empty or some other text. When used in
708 this way, `org-cycle-hook' is disables temporarily, to make sure the
709 cursor stays at the beginning of the buffer.
710 When this option is nil, don't do anything special at the beginning
715 (defcustom org-cycle-level-after-item
/entry-creation t
716 "Non-nil means cycle entry level or item indentation in new empty entries.
718 When the cursor is at the end of an empty headline, i.e with only stars
719 and maybe a TODO keyword, TAB will then switch the entry to become a child,
720 and then all possible anchestor states, before returning to the original state.
721 This makes data entry extremely fast: M-RET to create a new headline,
722 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
724 When the cursor is at the end of an empty plain list item, one TAB will
725 make it a subitem, two or more tabs will back up to make this an item
726 higher up in the item hierarchy."
730 (defcustom org-cycle-emulate-tab t
731 "Where should `org-cycle' emulate TAB.
733 white Only in completely white lines
734 whitestart Only at the beginning of lines, before the first non-white char
735 t Everywhere except in headlines
736 exc-hl-bol Everywhere except at the start of a headline
737 If TAB is used in a place where it does not emulate TAB, the current subtree
738 visibility is cycled."
740 :type
'(choice (const :tag
"Never" nil
)
741 (const :tag
"Only in completely white lines" white
)
742 (const :tag
"Before first char in a line" whitestart
)
743 (const :tag
"Everywhere except in headlines" t
)
744 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
747 (defcustom org-cycle-separator-lines
2
748 "Number of empty lines needed to keep an empty line between collapsed trees.
749 If you leave an empty line between the end of a subtree and the following
750 headline, this empty line is hidden when the subtree is folded.
751 Org-mode will leave (exactly) one empty line visible if the number of
752 empty lines is equal or larger to the number given in this variable.
753 So the default 2 means at least 2 empty lines after the end of a subtree
754 are needed to produce free space between a collapsed subtree and the
757 If the number is negative, and the number of empty lines is at least -N,
758 all empty lines are shown.
760 Special case: when 0, never leave empty lines in collapsed view."
763 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
765 (defcustom org-pre-cycle-hook nil
766 "Hook that is run before visibility cycling is happening.
767 The function(s) in this hook must accept a single argument which indicates
768 the new state that will be set right after running this hook. The
769 argument is a symbol. Before a global state change, it can have the values
770 `overview', `content', or `all'. Before a local state change, it can have
771 the values `folded', `children', or `subtree'."
775 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
776 org-cycle-hide-drawers
777 org-cycle-show-empty-lines
778 org-optimize-window-after-visibility-change
)
779 "Hook that is run after `org-cycle' has changed the buffer visibility.
780 The function(s) in this hook must accept a single argument which indicates
781 the new state that was set by the most recent `org-cycle' command. The
782 argument is a symbol. After a global state change, it can have the values
783 `overview', `content', or `all'. After a local state change, it can have
784 the values `folded', `children', or `subtree'."
788 (defgroup org-edit-structure nil
789 "Options concerning structure editing in Org-mode."
790 :tag
"Org Edit Structure"
791 :group
'org-structure
)
793 (defcustom org-odd-levels-only nil
794 "Non-nil means skip even levels and only use odd levels for the outline.
795 This has the effect that two stars are being added/taken away in
796 promotion/demotion commands. It also influences how levels are
797 handled by the exporters.
798 Changing it requires restart of `font-lock-mode' to become effective
799 for fontification also in regions already fontified.
800 You may also set this on a per-file basis by adding one of the following
805 :group
'org-edit-structure
806 :group
'org-appearance
809 (defcustom org-adapt-indentation t
810 "Non-nil means adapt indentation to outline node level.
812 When this variable is set, Org assumes that you write outlines by
813 indenting text in each node to align with the headline (after the stars).
814 The following issues are influenced by this variable:
816 - When this is set and the *entire* text in an entry is indented, the
817 indentation is increased by one space in a demotion command, and
818 decreased by one in a promotion command. If any line in the entry
819 body starts with text at column 0, indentation is not changed at all.
821 - Property drawers and planning information is inserted indented when
822 this variable s set. When nil, they will not be indented.
824 - TAB indents a line relative to context. The lines below a headline
825 will be indented when this variable is set.
827 Note that this is all about true indentation, by adding and removing
828 space characters. See also `org-indent.el' which does level-dependent
829 indentation in a virtual way, i.e. at display time in Emacs."
830 :group
'org-edit-structure
833 (defcustom org-special-ctrl-a
/e nil
834 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
836 When t, `C-a' will bring back the cursor to the beginning of the
837 headline text, i.e. after the stars and after a possible TODO keyword.
838 In an item, this will be the position after the bullet.
839 When the cursor is already at that position, another `C-a' will bring
840 it to the beginning of the line.
842 `C-e' will jump to the end of the headline, ignoring the presence of tags
843 in the headline. A second `C-e' will then jump to the true end of the
844 line, after any tags. This also means that, when this variable is
845 non-nil, `C-e' also will never jump beyond the end of the heading of a
846 folded section, i.e. not after the ellipses.
848 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
849 going to the true line boundary first. Only a directly following, identical
850 keypress will bring the cursor to the special positions.
852 This may also be a cons cell where the behavior for `C-a' and `C-e' is
854 :group
'org-edit-structure
856 (const :tag
"off" nil
)
857 (const :tag
"on: after stars/bullet and before tags first" t
)
858 (const :tag
"reversed: true line boundary first" reversed
)
859 (cons :tag
"Set C-a and C-e separately"
860 (choice :tag
"Special C-a"
861 (const :tag
"off" nil
)
862 (const :tag
"on: after stars/bullet first" t
)
863 (const :tag
"reversed: before stars/bullet first" reversed
))
864 (choice :tag
"Special C-e"
865 (const :tag
"off" nil
)
866 (const :tag
"on: before tags first" t
)
867 (const :tag
"reversed: after tags first" reversed
)))))
868 (if (fboundp 'defvaralias
)
869 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
871 (defcustom org-special-ctrl-k nil
872 "Non-nil means `C-k' will behave specially in headlines.
873 When nil, `C-k' will call the default `kill-line' command.
874 When t, the following will happen while the cursor is in the headline:
876 - When the cursor is at the beginning of a headline, kill the entire
877 line and possible the folded subtree below the line.
878 - When in the middle of the headline text, kill the headline up to the tags.
879 - When after the headline text, kill the tags."
880 :group
'org-edit-structure
883 (defcustom org-yank-folded-subtrees t
884 "Non-nil means when yanking subtrees, fold them.
885 If the kill is a single subtree, or a sequence of subtrees, i.e. if
886 it starts with a heading and all other headings in it are either children
887 or siblings, then fold all the subtrees. However, do this only if no
888 text after the yank would be swallowed into a folded tree by this action."
889 :group
'org-edit-structure
892 (defcustom org-yank-adjusted-subtrees nil
893 "Non-nil means when yanking subtrees, adjust the level.
894 With this setting, `org-paste-subtree' is used to insert the subtree, see
895 this function for details."
896 :group
'org-edit-structure
899 (defcustom org-M-RET-may-split-line
'((default . t
))
900 "Non-nil means M-RET will split the line at the cursor position.
901 When nil, it will go to the end of the line before making a
903 You may also set this option in a different way for different
904 contexts. Valid contexts are:
906 headline when creating a new headline
907 item when creating a new item
908 table in a table field
909 default the value to be used for all contexts not explicitly
911 :group
'org-structure
914 (const :tag
"Always" t
)
915 (const :tag
"Never" nil
)
916 (repeat :greedy t
:tag
"Individual contexts"
918 (choice :tag
"Context"
926 (defcustom org-insert-heading-respect-content nil
927 "Non-nil means insert new headings after the current subtree.
928 When nil, the new heading is created directly after the current line.
929 The commands \\[org-insert-heading-respect-content] and
930 \\[org-insert-todo-heading-respect-content] turn this variable on
931 for the duration of the command."
932 :group
'org-structure
935 (defcustom org-blank-before-new-entry
'((heading . auto
)
936 (plain-list-item . auto
))
937 "Should `org-insert-heading' leave a blank line before new heading/item?
938 The value is an alist, with `heading' and `plain-list-item' as car,
939 and a boolean flag as cdr. For plain lists, if the variable
940 `org-empty-line-terminates-plain-lists' is set, the setting here
941 is ignored and no empty line is inserted, to keep the list in tact."
942 :group
'org-edit-structure
944 (cons (const heading
)
945 (choice (const :tag
"Never" nil
)
946 (const :tag
"Always" t
)
947 (const :tag
"Auto" auto
)))
948 (cons (const plain-list-item
)
949 (choice (const :tag
"Never" nil
)
950 (const :tag
"Always" t
)
951 (const :tag
"Auto" auto
)))))
953 (defcustom org-insert-heading-hook nil
954 "Hook being run after inserting a new heading."
955 :group
'org-edit-structure
958 (defcustom org-enable-fixed-width-editor t
959 "Non-nil means lines starting with \":\" are treated as fixed-width.
960 This currently only means they are never auto-wrapped.
961 When nil, such lines will be treated like ordinary lines.
962 See also the QUOTE keyword."
963 :group
'org-edit-structure
967 (defcustom org-goto-auto-isearch t
968 "Non-nil means typing characters in org-goto starts incremental search."
969 :group
'org-edit-structure
972 (defgroup org-sparse-trees nil
973 "Options concerning sparse trees in Org-mode."
974 :tag
"Org Sparse Trees"
975 :group
'org-structure
)
977 (defcustom org-highlight-sparse-tree-matches t
978 "Non-nil means highlight all matches that define a sparse tree.
979 The highlights will automatically disappear the next time the buffer is
980 changed by an edit command."
981 :group
'org-sparse-trees
984 (defcustom org-remove-highlights-with-change t
985 "Non-nil means any change to the buffer will remove temporary highlights.
986 Such highlights are created by `org-occur' and `org-clock-display'.
987 When nil, `C-c C-c needs to be used to get rid of the highlights.
988 The highlights created by `org-preview-latex-fragment' always need
989 `C-c C-c' to be removed."
990 :group
'org-sparse-trees
995 (defcustom org-occur-hook
'(org-first-headline-recenter)
996 "Hook that is run after `org-occur' has constructed a sparse tree.
997 This can be used to recenter the window to show as much of the structure
999 :group
'org-sparse-trees
1002 (defgroup org-imenu-and-speedbar nil
1003 "Options concerning imenu and speedbar in Org-mode."
1004 :tag
"Org Imenu and Speedbar"
1005 :group
'org-structure
)
1007 (defcustom org-imenu-depth
2
1008 "The maximum level for Imenu access to Org-mode headlines.
1009 This also applied for speedbar access."
1010 :group
'org-imenu-and-speedbar
1013 (defgroup org-table nil
1014 "Options concerning tables in Org-mode."
1018 (defcustom org-enable-table-editor
'optimized
1019 "Non-nil means lines starting with \"|\" are handled by the table editor.
1020 When nil, such lines will be treated like ordinary lines.
1022 When equal to the symbol `optimized', the table editor will be optimized to
1024 - Automatic overwrite mode in front of whitespace in table fields.
1025 This makes the structure of the table stay in tact as long as the edited
1026 field does not exceed the column width.
1027 - Minimize the number of realigns. Normally, the table is aligned each time
1028 TAB or RET are pressed to move to another field. With optimization this
1029 happens only if changes to a field might have changed the column width.
1030 Optimization requires replacing the functions `self-insert-command',
1031 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1032 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1033 very good at guessing when a re-align will be necessary, but you can always
1034 force one with \\[org-ctrl-c-ctrl-c].
1036 If you would like to use the optimized version in Org-mode, but the
1037 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1039 This variable can be used to turn on and off the table editor during a session,
1040 but in order to toggle optimization, a restart is required.
1042 See also the variable `org-table-auto-blank-field'."
1045 (const :tag
"off" nil
)
1047 (const :tag
"on, optimized" optimized
)))
1049 (defcustom org-self-insert-cluster-for-undo t
1050 "Non-nil means cluster self-insert commands for undo when possible.
1051 If this is set, then, like in the Emacs command loop, 20 consecutive
1052 characters will be undone together.
1053 This is configurable, because there is some impact on typing performance."
1057 (defcustom org-table-tab-recognizes-table.el t
1058 "Non-nil means TAB will automatically notice a table.el table.
1059 When it sees such a table, it moves point into it and - if necessary -
1060 calls `table-recognize-table'."
1061 :group
'org-table-editing
1064 (defgroup org-link nil
1065 "Options concerning links in Org-mode."
1069 (defvar org-link-abbrev-alist-local nil
1070 "Buffer-local version of `org-link-abbrev-alist', which see.
1071 The value of this is taken from the #+LINK lines.")
1072 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1074 (defcustom org-link-abbrev-alist nil
1075 "Alist of link abbreviations.
1076 The car of each element is a string, to be replaced at the start of a link.
1077 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1078 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1080 [[linkkey:tag][description]]
1082 The 'linkkey' must be a word word, starting with a letter, followed
1083 by letters, numbers, '-' or '_'.
1085 If REPLACE is a string, the tag will simply be appended to create the link.
1086 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1087 the placeholder \"%h\" will cause a url-encoded version of the tag to
1088 be inserted at that point (see the function `url-hexify-string').
1090 REPLACE may also be a function that will be called with the tag as the
1091 only argument to create the link, which should be returned as a string.
1093 See the manual for examples."
1097 (string :tag
"Protocol")
1099 (string :tag
"Format")
1102 (defcustom org-descriptive-links t
1103 "Non-nil means hide link part and only show description of bracket links.
1104 Bracket links are like [[link][description]]. This variable sets the initial
1105 state in new org-mode buffers. The setting can then be toggled on a
1106 per-buffer basis from the Org->Hyperlinks menu."
1110 (defcustom org-link-file-path-type
'adaptive
1111 "How the path name in file links should be stored.
1114 relative Relative to the current directory, i.e. the directory of the file
1115 into which the link is being inserted.
1116 absolute Absolute path, if possible with ~ for home directory.
1117 noabbrev Absolute path, no abbreviation of home directory.
1118 adaptive Use relative path for files in the current directory and sub-
1119 directories of it. For other files, use an absolute path."
1127 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1128 "Types of links that should be activated in Org-mode files.
1129 This is a list of symbols, each leading to the activation of a certain link
1130 type. In principle, it does not hurt to turn on most link types - there may
1131 be a small gain when turning off unused link types. The types are:
1133 bracket The recommended [[link][description]] or [[link]] links with hiding.
1134 angular Links in angular brackets that may contain whitespace like
1135 <bbdb:Carsten Dominik>.
1136 plain Plain links in normal text, no whitespace, like http://google.com.
1137 radio Text that is matched by a radio target, see manual for details.
1138 tag Tag settings in a headline (link to tag search).
1139 date Time stamps (link to calendar).
1140 footnote Footnote labels.
1142 Changing this variable requires a restart of Emacs to become effective."
1144 :type
'(set :greedy t
1145 (const :tag
"Double bracket links (new style)" bracket
)
1146 (const :tag
"Angular bracket links (old style)" angular
)
1147 (const :tag
"Plain text links" plain
)
1148 (const :tag
"Radio target matches" radio
)
1149 (const :tag
"Tags" tag
)
1150 (const :tag
"Timestamps" date
)
1151 (const :tag
"Footnotes" footnote
)))
1153 (defcustom org-make-link-description-function nil
1154 "Function to use to generate link descriptions from links. If
1155 nil the link location will be used. This function must take two
1156 parameters; the first is the link and the second the description
1157 org-insert-link has generated, and should return the description
1162 (defgroup org-link-store nil
1163 "Options concerning storing links in Org-mode."
1164 :tag
"Org Store Link"
1167 (defcustom org-email-link-description-format
"Email %c: %.30s"
1168 "Format of the description part of a link to an email or usenet message.
1169 The following %-escapes will be replaced by corresponding information:
1171 %F full \"From\" field
1172 %f name, taken from \"From\" field, address if no name
1173 %T full \"To\" field
1174 %t first name in \"To\" field, address if no name
1175 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1176 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1180 You may use normal field width specification between the % and the letter.
1181 This is for example useful to limit the length of the subject.
1183 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1184 :group
'org-link-store
1187 (defcustom org-from-is-user-regexp
1189 (when (and user-mail-address
(not (string= user-mail-address
"")))
1190 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1191 (when (and user-full-name
(not (string= user-full-name
"")))
1192 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1193 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1194 "Regexp matched against the \"From:\" header of an email or usenet message.
1195 It should match if the message is from the user him/herself."
1196 :group
'org-link-store
1199 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1200 "Non-nil means storing a link to an Org file will use entry IDs.
1202 Note that before this variable is even considered, org-id must be loaded,
1203 so please customize `org-modules' and turn it on.
1205 The variable can have the following values:
1207 t Create an ID if needed to make a link to the current entry.
1209 create-if-interactive
1210 If `org-store-link' is called directly (interactively, as a user
1211 command), do create an ID to support the link. But when doing the
1212 job for remember, only use the ID if it already exists. The
1213 purpose of this setting is to avoid proliferation of unwanted
1214 IDs, just because you happen to be in an Org file when you
1215 call `org-remember' that automatically and preemptively
1216 creates a link. If you do want to get an ID link in a remember
1217 template to an entry not having an ID, create it first by
1218 explicitly creating a link to it, using `C-c C-l' first.
1220 create-if-interactive-and-no-custom-id
1221 Like create-if-interactive, but do not create an ID if there is
1222 a CUSTOM_ID property defined in the entry. This is the default.
1225 Use existing ID, do not create one.
1227 nil Never use an ID to make a link, instead link using a text search for
1229 :group
'org-link-store
1231 (const :tag
"Create ID to make link" t
)
1232 (const :tag
"Create if storing link interactively"
1233 create-if-interactive
)
1234 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1235 create-if-interactive-and-no-custom-id
)
1236 (const :tag
"Only use existing" use-existing
)
1237 (const :tag
"Do not use ID to create link" nil
)))
1239 (defcustom org-context-in-file-links t
1240 "Non-nil means file links from `org-store-link' contain context.
1241 A search string will be added to the file name with :: as separator and
1242 used to find the context when the link is activated by the command
1243 `org-open-at-point'.
1244 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1245 negates this setting for the duration of the command."
1246 :group
'org-link-store
1249 (defcustom org-keep-stored-link-after-insertion nil
1250 "Non-nil means keep link in list for entire session.
1252 The command `org-store-link' adds a link pointing to the current
1253 location to an internal list. These links accumulate during a session.
1254 The command `org-insert-link' can be used to insert links into any
1255 Org-mode file (offering completion for all stored links). When this
1256 option is nil, every link which has been inserted once using \\[org-insert-link]
1257 will be removed from the list, to make completing the unused links
1259 :group
'org-link-store
1262 (defgroup org-link-follow nil
1263 "Options concerning following links in Org-mode."
1264 :tag
"Org Follow Link"
1267 (defcustom org-link-translation-function nil
1268 "Function to translate links with different syntax to Org syntax.
1269 This can be used to translate links created for example by the Planner
1270 or emacs-wiki packages to Org syntax.
1271 The function must accept two parameters, a TYPE containing the link
1272 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1273 which is everything after the link protocol. It should return a cons
1274 with possibly modified values of type and path.
1275 Org contains a function for this, so if you set this variable to
1276 `org-translate-link-from-planner', you should be able follow many
1277 links created by planner."
1278 :group
'org-link-follow
1281 (defcustom org-follow-link-hook nil
1282 "Hook that is run after a link has been followed."
1283 :group
'org-link-follow
1286 (defcustom org-tab-follows-link nil
1287 "Non-nil means on links TAB will follow the link.
1288 Needs to be set before org.el is loaded.
1289 This really should not be used, it does not make sense, and the
1290 implementation is bad."
1291 :group
'org-link-follow
1294 (defcustom org-return-follows-link nil
1295 "Non-nil means on links RET will follow the link.
1296 Needs to be set before org.el is loaded."
1297 :group
'org-link-follow
1300 (defcustom org-mouse-1-follows-link
1301 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1302 "Non-nil means mouse-1 on a link will follow the link.
1303 A longer mouse click will still set point. Does not work on XEmacs.
1304 Needs to be set before org.el is loaded."
1305 :group
'org-link-follow
1308 (defcustom org-mark-ring-length
4
1309 "Number of different positions to be recorded in the ring
1310 Changing this requires a restart of Emacs to work correctly."
1311 :group
'org-link-follow
1314 (defcustom org-link-frame-setup
1315 '((vm . vm-visit-folder-other-frame
)
1316 (gnus . gnus-other-frame
)
1317 (file . find-file-other-window
))
1318 "Setup the frame configuration for following links.
1319 When following a link with Emacs, it may often be useful to display
1320 this link in another window or frame. This variable can be used to
1321 set this up for the different types of links.
1324 `vm-visit-folder-other-frame'
1325 For Gnus, use any of
1328 `org-gnus-no-new-news'
1329 For FILE, use any of
1331 `find-file-other-window'
1332 `find-file-other-frame'
1333 For the calendar, use the variable `calendar-setup'.
1334 For BBDB, it is currently only possible to display the matches in
1336 :group
'org-link-follow
1340 (const vm-visit-folder
)
1341 (const vm-visit-folder-other-window
)
1342 (const vm-visit-folder-other-frame
)))
1346 (const gnus-other-frame
)
1347 (const org-gnus-no-new-news
)))
1351 (const find-file-other-window
)
1352 (const find-file-other-frame
)))))
1354 (defcustom org-display-internal-link-with-indirect-buffer nil
1355 "Non-nil means use indirect buffer to display infile links.
1356 Activating internal links (from one location in a file to another location
1357 in the same file) normally just jumps to the location. When the link is
1358 activated with a C-u prefix (or with mouse-3), the link is displayed in
1359 another window. When this option is set, the other window actually displays
1360 an indirect buffer clone of the current buffer, to avoid any visibility
1361 changes to the current buffer."
1362 :group
'org-link-follow
1365 (defcustom org-open-non-existing-files nil
1366 "Non-nil means `org-open-file' will open non-existing files.
1367 When nil, an error will be generated.
1368 This variable applies only to external applications because they
1369 might choke on non-existing files. If the link is to a file that
1370 will be opened in Emacs, the variable is ignored."
1371 :group
'org-link-follow
1374 (defcustom org-open-directory-means-index-dot-org nil
1375 "Non-nil means a link to a directory really means to index.org.
1376 When nil, following a directory link will run dired or open a finder/explorer
1377 window on that directory."
1378 :group
'org-link-follow
1381 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1382 "Function and arguments to call for following mailto links.
1383 This is a list with the first element being a lisp function, and the
1384 remaining elements being arguments to the function. In string arguments,
1385 %a will be replaced by the address, and %s will be replaced by the subject
1386 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1387 :group
'org-link-follow
1389 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1390 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1391 (const :tag
"message-mail" (message-mail "%a" "%s"))
1392 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1394 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1395 "Non-nil means ask for confirmation before executing shell links.
1396 Shell links can be dangerous: just think about a link
1398 [[shell:rm -rf ~/*][Google Search]]
1400 This link would show up in your Org-mode document as \"Google Search\",
1401 but really it would remove your entire home directory.
1402 Therefore we advise against setting this variable to nil.
1403 Just change it to `y-or-n-p' if you want to confirm with a
1404 single keystroke rather than having to type \"yes\"."
1405 :group
'org-link-follow
1407 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1408 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1409 (const :tag
"no confirmation (dangerous)" nil
)))
1411 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1412 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1413 Elisp links can be dangerous: just think about a link
1415 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1417 This link would show up in your Org-mode document as \"Google Search\",
1418 but really it would remove your entire home directory.
1419 Therefore we advise against setting this variable to nil.
1420 Just change it to `y-or-n-p' if you want to confirm with a
1421 single keystroke rather than having to type \"yes\"."
1422 :group
'org-link-follow
1424 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1425 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1426 (const :tag
"no confirmation (dangerous)" nil
)))
1428 (defconst org-file-apps-defaults-gnu
1432 "Default file applications on a UNIX or GNU/Linux system.
1433 See `org-file-apps'.")
1435 (defconst org-file-apps-defaults-macosx
1438 (system .
"open %s")
1440 ("eps.gz" .
"gv %s")
1442 ("fig" .
"xfig %s"))
1443 "Default file applications on a MacOS X system.
1444 The system \"open\" is known as a default, but we use X11 applications
1445 for some files for which the OS does not have a good default.
1446 See `org-file-apps'.")
1448 (defconst org-file-apps-defaults-windowsnt
1452 (list (if (featurep 'xemacs
)
1453 'mswindows-shell-execute
1457 (list (if (featurep 'xemacs
)
1458 'mswindows-shell-execute
1461 "Default file applications on a Windows NT system.
1462 The system \"open\" is used for most files.
1463 See `org-file-apps'.")
1465 (defcustom org-file-apps
1468 ("\\.mm\\'" . default
)
1469 ("\\.x?html?\\'" . default
)
1470 ("\\.pdf\\'" . default
)
1472 "External applications for opening `file:path' items in a document.
1473 Org-mode uses system defaults for different file types, but
1474 you can use this variable to set the application for a given file
1475 extension. The entries in this list are cons cells where the car identifies
1476 files and the cdr the corresponding command. Possible values for the
1478 \"regex\" Regular expression matched against the file name. For backward
1479 compatibility, this can also be a string with only alphanumeric
1480 characters, which is then interpreted as an extension.
1481 `directory' Matches a directory
1482 `remote' Matches a remote file, accessible through tramp or efs.
1483 Remote files most likely should be visited through Emacs
1484 because external applications cannot handle such paths.
1485 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1486 so all files Emacs knows how to handle. Using this with
1487 command `emacs' will open most files in Emacs. Beware that this
1488 will also open html files inside Emacs, unless you add
1489 (\"html\" . default) to the list as well.
1490 t Default for files not matched by any of the other options.
1491 `system' The system command to open files, like `open' on Windows
1492 and Mac OS X, and mailcap under GNU/Linux. This is the command
1493 that will be selected if you call `C-c C-o' with a double
1496 Possible values for the command are:
1497 `emacs' The file will be visited by the current Emacs process.
1498 `default' Use the default application for this file type, which is the
1499 association for t in the list, most likely in the system-specific
1501 This can be used to overrule an unwanted setting in the
1502 system-specific variable.
1503 `system' Use the system command for opening files, like \"open\".
1504 This command is specified by the entry whose car is `system'.
1505 Most likely, the system-specific version of this variable
1506 does define this command, but you can overrule/replace it
1508 string A command to be executed by a shell; %s will be replaced
1509 by the path to the file.
1510 sexp A Lisp form which will be evaluated. The file path will
1511 be available in the Lisp variable `file'.
1512 For more examples, see the system specific constants
1513 `org-file-apps-defaults-macosx'
1514 `org-file-apps-defaults-windowsnt'
1515 `org-file-apps-defaults-gnu'."
1516 :group
'org-link-follow
1518 (cons (choice :value
""
1519 (string :tag
"Extension")
1520 (const :tag
"System command to open files" system
)
1521 (const :tag
"Default for unrecognized files" t
)
1522 (const :tag
"Remote file" remote
)
1523 (const :tag
"Links to a directory" directory
)
1524 (const :tag
"Any files that have Emacs modes"
1527 (const :tag
"Visit with Emacs" emacs
)
1528 (const :tag
"Use default" default
)
1529 (const :tag
"Use the system command" system
)
1530 (string :tag
"Command")
1531 (sexp :tag
"Lisp form")))))
1535 (defgroup org-refile nil
1536 "Options concerning refiling entries in Org-mode."
1540 (defcustom org-directory
"~/org"
1541 "Directory with org files.
1542 This is just a default location to look for Org files. There is no need
1543 at all to put your files into this directory. It is only used in the
1544 following situations:
1546 1. When a remember template specifies a target file that is not an
1547 absolute path. The path will then be interpreted relative to
1549 2. When a remember note is filed away in an interactive way (when exiting the
1550 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1551 with `org-directory' as the default path."
1553 :group
'org-remember
1556 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1557 "Default target for storing notes.
1558 Used by the hooks for remember.el. This can be a string, or nil to mean
1559 the value of `remember-data-file'.
1560 You can set this on a per-template basis with the variable
1561 `org-remember-templates'."
1563 :group
'org-remember
1565 (const :tag
"Default from remember-data-file" nil
)
1568 (defcustom org-goto-interface
'outline
1569 "The default interface to be used for `org-goto'.
1571 outline The interface shows an outline of the relevant file
1572 and the correct heading is found by moving through
1573 the outline or by searching with incremental search.
1574 outline-path-completion Headlines in the current buffer are offered via
1575 completion. This is the interface also used by
1576 the refile command."
1579 (const :tag
"Outline" outline
)
1580 (const :tag
"Outline-path-completion" outline-path-completion
)))
1582 (defcustom org-goto-max-level
5
1583 "Maximum level to be considered when running org-goto with refile interface."
1587 (defcustom org-reverse-note-order nil
1588 "Non-nil means store new notes at the beginning of a file or entry.
1589 When nil, new notes will be filed to the end of a file or entry.
1590 This can also be a list with cons cells of regular expressions that
1591 are matched against file names, and values."
1592 :group
'org-remember
1595 (const :tag
"Reverse always" t
)
1596 (const :tag
"Reverse never" nil
)
1597 (repeat :tag
"By file name regexp"
1598 (cons regexp boolean
))))
1600 (defcustom org-log-refile nil
1601 "Information to record when a task is refiled.
1603 Possible values are:
1605 nil Don't add anything
1606 time Add a time stamp to the task
1607 note Prompt for a note and add it with template `org-log-note-headings'
1609 This option can also be set with on a per-file-basis with
1611 #+STARTUP: nologrefile
1612 #+STARTUP: logrefile
1613 #+STARTUP: lognoterefile
1615 You can have local logging settings for a subtree by setting the LOGGING
1616 property to one or more of these keywords.
1618 When bulk-refiling from the agenda, the value `note' is forbidden and
1619 will temporarily be changed to `time'."
1621 :group
'org-progress
1623 (const :tag
"No logging" nil
)
1624 (const :tag
"Record timestamp" time
)
1625 (const :tag
"Record timestamp with note." note
)))
1627 (defcustom org-refile-targets nil
1628 "Targets for refiling entries with \\[org-refile].
1629 This is list of cons cells. Each cell contains:
1630 - a specification of the files to be considered, either a list of files,
1631 or a symbol whose function or variable value will be used to retrieve
1632 a file name or a list of file names. If you use `org-agenda-files' for
1633 that, all agenda files will be scanned for targets. Nil means consider
1634 headings in the current buffer.
1635 - A specification of how to find candidate refile targets. This may be
1637 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1638 This tag has to be present in all target headlines, inheritance will
1640 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1642 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1643 headlines that are refiling targets.
1644 - a cons cell (:level . N). Any headline of level N is considered a target.
1645 Note that, when `org-odd-levels-only' is set, level corresponds to
1646 order in hierarchy, not to the number of stars.
1647 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1648 Note that, when `org-odd-levels-only' is set, level corresponds to
1649 order in hierarchy, not to the number of stars.
1651 You can set the variable `org-refile-target-verify-function' to a function
1652 to verify each headline found by the simple critery above.
1654 When this variable is nil, all top-level headlines in the current buffer
1655 are used, equivalent to the value `((nil . (:level . 1))'."
1659 (choice :value org-agenda-files
1660 (const :tag
"All agenda files" org-agenda-files
)
1661 (const :tag
"Current buffer" nil
)
1662 (function) (variable) (file))
1663 (choice :tag
"Identify target headline by"
1664 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1665 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1666 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1667 (cons :tag
"Level number" (const :value
:level
) (integer))
1668 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1670 (defcustom org-refile-target-verify-function nil
1671 "Function to verify if the headline at point should be a refile target.
1672 The function will be called without arguments, with point at the
1673 beginning of the headline. It should return t and leave point
1674 where it is if the headline is a valid target for refiling.
1676 If the target should not be selected, the function must return nil.
1677 In addition to this, it may move point to a place from where the search
1678 should be continued. For example, the function may decide that the entire
1679 subtree of the current entry should be excluded and move point to the end
1684 (defcustom org-refile-use-outline-path nil
1685 "Non-nil means provide refile targets as paths.
1686 So a level 3 headline will be available as level1/level2/level3.
1688 When the value is `file', also include the file name (without directory)
1689 into the path. In this case, you can also stop the completion after
1690 the file name, to get entries inserted as top level in the file.
1692 When `full-file-path', include the full file path."
1695 (const :tag
"Not" nil
)
1696 (const :tag
"Yes" t
)
1697 (const :tag
"Start with file name" file
)
1698 (const :tag
"Start with full file path" full-file-path
)))
1700 (defcustom org-outline-path-complete-in-steps t
1701 "Non-nil means complete the outline path in hierarchical steps.
1702 When Org-mode uses the refile interface to select an outline path
1703 \(see variable `org-refile-use-outline-path'), the completion of
1704 the path can be done is a single go, or if can be done in steps down
1705 the headline hierarchy. Going in steps is probably the best if you
1706 do not use a special completion package like `ido' or `icicles'.
1707 However, when using these packages, going in one step can be very
1708 fast, while still showing the whole path to the entry."
1712 (defcustom org-refile-allow-creating-parent-nodes nil
1713 "Non-nil means allow to create new nodes as refile targets.
1714 New nodes are then created by adding \"/new node name\" to the completion
1715 of an existing node. When the value of this variable is `confirm',
1716 new node creation must be confirmed by the user (recommended)
1717 When nil, the completion must match an existing entry.
1719 Note that, if the new heading is not seen by the criteria
1720 listed in `org-refile-targets', multiple instances of the same
1721 heading would be created by trying again to file under the new
1725 (const :tag
"Never" nil
)
1726 (const :tag
"Always" t
)
1727 (const :tag
"Prompt for confirmation" confirm
)))
1729 (defgroup org-todo nil
1730 "Options concerning TODO items in Org-mode."
1734 (defgroup org-progress nil
1735 "Options concerning Progress logging in Org-mode."
1739 (defvar org-todo-interpretation-widgets
1741 (:tag
"Sequence (cycling hits every state)" sequence
)
1742 (:tag
"Type (cycling directly to DONE)" type
))
1743 "The available interpretation symbols for customizing
1744 `org-todo-keywords'.
1745 Interested libraries should add to this list.")
1747 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1748 "List of TODO entry keyword sequences and their interpretation.
1749 \\<org-mode-map>This is a list of sequences.
1751 Each sequence starts with a symbol, either `sequence' or `type',
1752 indicating if the keywords should be interpreted as a sequence of
1753 action steps, or as different types of TODO items. The first
1754 keywords are states requiring action - these states will select a headline
1755 for inclusion into the global TODO list Org-mode produces. If one of
1756 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1757 signify that no further action is necessary. If \"|\" is not found,
1758 the last keyword is treated as the only DONE state of the sequence.
1760 The command \\[org-todo] cycles an entry through these states, and one
1761 additional state where no keyword is present. For details about this
1762 cycling, see the manual.
1764 TODO keywords and interpretation can also be set on a per-file basis with
1765 the special #+SEQ_TODO and #+TYP_TODO lines.
1767 Each keyword can optionally specify a character for fast state selection
1768 \(in combination with the variable `org-use-fast-todo-selection')
1769 and specifiers for state change logging, using the same syntax
1770 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1771 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1772 indicates to record a time stamp each time this state is selected.
1774 Each keyword may also specify if a timestamp or a note should be
1775 recorded when entering or leaving the state, by adding additional
1776 characters in the parenthesis after the keyword. This looks like this:
1777 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1778 record only the time of the state change. With X and Y being either
1779 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1780 Y when leaving the state if and only if the *target* state does not
1781 define X. You may omit any of the fast-selection key or X or /Y,
1782 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1784 For backward compatibility, this variable may also be just a list
1785 of keywords - in this case the interpretation (sequence or type) will be
1786 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1788 :group
'org-keywords
1790 (repeat :tag
"Old syntax, just keywords"
1791 (string :tag
"Keyword"))
1792 (repeat :tag
"New syntax"
1795 :tag
"Interpretation"
1796 ;;Quick and dirty way to see
1797 ;;`org-todo-interpretations'. This takes the
1798 ;;place of item arguments
1806 org-todo-interpretation-widgets
))
1809 (string :tag
"Keyword"))))))
1811 (defvar org-todo-keywords-1 nil
1812 "All TODO and DONE keywords active in a buffer.")
1813 (make-variable-buffer-local 'org-todo-keywords-1
)
1814 (defvar org-todo-keywords-for-agenda nil
)
1815 (defvar org-done-keywords-for-agenda nil
)
1816 (defvar org-drawers-for-agenda nil
)
1817 (defvar org-todo-keyword-alist-for-agenda nil
)
1818 (defvar org-tag-alist-for-agenda nil
)
1819 (defvar org-agenda-contributing-files nil
)
1820 (defvar org-not-done-keywords nil
)
1821 (make-variable-buffer-local 'org-not-done-keywords
)
1822 (defvar org-done-keywords nil
)
1823 (make-variable-buffer-local 'org-done-keywords
)
1824 (defvar org-todo-heads nil
)
1825 (make-variable-buffer-local 'org-todo-heads
)
1826 (defvar org-todo-sets nil
)
1827 (make-variable-buffer-local 'org-todo-sets
)
1828 (defvar org-todo-log-states nil
)
1829 (make-variable-buffer-local 'org-todo-log-states
)
1830 (defvar org-todo-kwd-alist nil
)
1831 (make-variable-buffer-local 'org-todo-kwd-alist
)
1832 (defvar org-todo-key-alist nil
)
1833 (make-variable-buffer-local 'org-todo-key-alist
)
1834 (defvar org-todo-key-trigger nil
)
1835 (make-variable-buffer-local 'org-todo-key-trigger
)
1837 (defcustom org-todo-interpretation
'sequence
1838 "Controls how TODO keywords are interpreted.
1839 This variable is in principle obsolete and is only used for
1840 backward compatibility, if the interpretation of todo keywords is
1841 not given already in `org-todo-keywords'. See that variable for
1844 :group
'org-keywords
1845 :type
'(choice (const sequence
)
1848 (defcustom org-use-fast-todo-selection t
1849 "Non-nil means use the fast todo selection scheme with C-c C-t.
1850 This variable describes if and under what circumstances the cycling
1851 mechanism for TODO keywords will be replaced by a single-key, direct
1854 When nil, fast selection is never used.
1856 When the symbol `prefix', it will be used when `org-todo' is called with
1857 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
1858 in an agenda buffer.
1860 When t, fast selection is used by default. In this case, the prefix
1861 argument forces cycling instead.
1863 In all cases, the special interface is only used if access keys have actually
1864 been assigned by the user, i.e. if keywords in the configuration are followed
1865 by a letter in parenthesis, like TODO(t)."
1868 (const :tag
"Never" nil
)
1869 (const :tag
"By default" t
)
1870 (const :tag
"Only with C-u C-c C-t" prefix
)))
1872 (defcustom org-provide-todo-statistics t
1873 "Non-nil means update todo statistics after insert and toggle.
1874 ALL-HEADLINES means update todo statistics by including headlines
1875 with no TODO keyword as well, counting them as not done.
1876 A list of TODO keywords means the same, but skip keywords that are
1879 When this is set, todo statistics is updated in the parent of the
1880 current entry each time a todo state is changed."
1883 (const :tag
"Yes, only for TODO entries" t
)
1884 (const :tag
"Yes, including all entries" 'all-headlines
)
1885 (repeat :tag
"Yes, for TODOs in this list"
1886 (string :tag
"TODO keyword"))
1887 (other :tag
"No TODO statistics" nil
)))
1889 (defcustom org-hierarchical-todo-statistics t
1890 "Non-nil means TODO statistics covers just direct children.
1891 When nil, all entries in the subtree are considered.
1892 This has only an effect if `org-provide-todo-statistics' is set.
1893 To set this to nil for only a single subtree, use a COOKIE_DATA
1894 property and include the word \"recursive\" into the value."
1898 (defcustom org-after-todo-state-change-hook nil
1899 "Hook which is run after the state of a TODO item was changed.
1900 The new state (a string with a TODO keyword, or nil) is available in the
1901 Lisp variable `state'."
1905 (defvar org-blocker-hook nil
1906 "Hook for functions that are allowed to block a state change.
1908 Each function gets as its single argument a property list, see
1909 `org-trigger-hook' for more information about this list.
1911 If any of the functions in this hook returns nil, the state change
1914 (defvar org-trigger-hook nil
1915 "Hook for functions that are triggered by a state change.
1917 Each function gets as its single argument a property list with at least
1918 the following elements:
1920 (:type type-of-change :position pos-at-entry-start
1921 :from old-state :to new-state)
1923 Depending on the type, more properties may be present.
1925 This mechanism is currently implemented for:
1929 :type todo-state-change
1930 :from previous state (keyword as a string), or nil, or a symbol
1931 'todo' or 'done', to indicate the general type of state.
1932 :to new state, like in :from")
1934 (defcustom org-enforce-todo-dependencies nil
1935 "Non-nil means undone TODO entries will block switching the parent to DONE.
1936 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1937 be blocked if any prior sibling is not yet done.
1938 Finally, if the parent is blocked because of ordered siblings of its own,
1939 the child will also be blocked.
1940 This variable needs to be set before org.el is loaded, and you need to
1941 restart Emacs after a change to make the change effective. The only way
1942 to change is while Emacs is running is through the customize interface."
1943 :set
(lambda (var val
)
1946 (add-hook 'org-blocker-hook
1947 'org-block-todo-from-children-or-siblings-or-parent
)
1948 (remove-hook 'org-blocker-hook
1949 'org-block-todo-from-children-or-siblings-or-parent
)))
1953 (defcustom org-enforce-todo-checkbox-dependencies nil
1954 "Non-nil means unchecked boxes will block switching the parent to DONE.
1955 When this is nil, checkboxes have no influence on switching TODO states.
1956 When non-nil, you first need to check off all check boxes before the TODO
1957 entry can be switched to DONE.
1958 This variable needs to be set before org.el is loaded, and you need to
1959 restart Emacs after a change to make the change effective. The only way
1960 to change is while Emacs is running is through the customize interface."
1961 :set
(lambda (var val
)
1964 (add-hook 'org-blocker-hook
1965 'org-block-todo-from-checkboxes
)
1966 (remove-hook 'org-blocker-hook
1967 'org-block-todo-from-checkboxes
)))
1971 (defcustom org-treat-insert-todo-heading-as-state-change nil
1972 "Non-nil means inserting a TODO heading is treated as state change.
1973 So when the command \\[org-insert-todo-heading] is used, state change
1974 logging will apply if appropriate. When nil, the new TODO item will
1975 be inserted directly, and no logging will take place."
1979 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
1980 "Non-nil means switching TODO states with S-cursor counts as state change.
1981 This is the default behavior. However, setting this to nil allows a
1982 convenient way to select a TODO state and bypass any logging associated
1987 (defcustom org-todo-state-tags-triggers nil
1988 "Tag changes that should be triggered by TODO state changes.
1989 This is a list. Each entry is
1991 (state-change (tag . flag) .......)
1993 State-change can be a string with a state, and empty string to indicate the
1994 state that has no TODO keyword, or it can be one of the symbols `todo'
1995 or `done', meaning any not-done or done state, respectively."
1999 (cons (choice :tag
"When changing to"
2000 (const :tag
"Not-done state" todo
)
2001 (const :tag
"Done state" done
)
2002 (string :tag
"State"))
2004 (cons :tag
"Tag action"
2006 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2008 (defcustom org-log-done nil
2009 "Information to record when a task moves to the DONE state.
2011 Possible values are:
2013 nil Don't add anything, just change the keyword
2014 time Add a time stamp to the task
2015 note Prompt for a note and add it with template `org-log-note-headings'
2017 This option can also be set with on a per-file-basis with
2019 #+STARTUP: nologdone
2021 #+STARTUP: lognotedone
2023 You can have local logging settings for a subtree by setting the LOGGING
2024 property to one or more of these keywords."
2026 :group
'org-progress
2028 (const :tag
"No logging" nil
)
2029 (const :tag
"Record CLOSED timestamp" time
)
2030 (const :tag
"Record CLOSED timestamp with note." note
)))
2032 ;; Normalize old uses of org-log-done.
2034 ((eq org-log-done t
) (setq org-log-done
'time
))
2035 ((and (listp org-log-done
) (memq 'done org-log-done
))
2036 (setq org-log-done
'note
)))
2038 (defcustom org-log-reschedule nil
2039 "Information to record when the scheduling date of a tasks is modified.
2041 Possible values are:
2043 nil Don't add anything, just change the date
2044 time Add a time stamp to the task
2045 note Prompt for a note and add it with template `org-log-note-headings'
2047 This option can also be set with on a per-file-basis with
2049 #+STARTUP: nologreschedule
2050 #+STARTUP: logreschedule
2051 #+STARTUP: lognotereschedule"
2053 :group
'org-progress
2055 (const :tag
"No logging" nil
)
2056 (const :tag
"Record timestamp" time
)
2057 (const :tag
"Record timestamp with note." note
)))
2059 (defcustom org-log-redeadline nil
2060 "Information to record when the deadline date of a tasks is modified.
2062 Possible values are:
2064 nil Don't add anything, just change the date
2065 time Add a time stamp to the task
2066 note Prompt for a note and add it with template `org-log-note-headings'
2068 This option can also be set with on a per-file-basis with
2070 #+STARTUP: nologredeadline
2071 #+STARTUP: logredeadline
2072 #+STARTUP: lognoteredeadline
2074 You can have local logging settings for a subtree by setting the LOGGING
2075 property to one or more of these keywords."
2077 :group
'org-progress
2079 (const :tag
"No logging" nil
)
2080 (const :tag
"Record timestamp" time
)
2081 (const :tag
"Record timestamp with note." note
)))
2083 (defcustom org-log-note-clock-out nil
2084 "Non-nil means record a note when clocking out of an item.
2085 This can also be configured on a per-file basis by adding one of
2086 the following lines anywhere in the buffer:
2088 #+STARTUP: lognoteclock-out
2089 #+STARTUP: nolognoteclock-out"
2091 :group
'org-progress
2094 (defcustom org-log-done-with-time t
2095 "Non-nil means the CLOSED time stamp will contain date and time.
2096 When nil, only the date will be recorded."
2097 :group
'org-progress
2100 (defcustom org-log-note-headings
2101 '((done .
"CLOSING NOTE %t")
2102 (state .
"State %-12s from %-12S %t")
2103 (note .
"Note taken on %t")
2104 (reschedule .
"Rescheduled from %S on %t")
2105 (delschedule .
"Not scheduled, was %S on %t")
2106 (redeadline .
"New deadline from %S on %t")
2107 (deldeadline .
"Removed deadline, was %S on %t")
2108 (refile .
"Refiled on %t")
2110 "Headings for notes added to entries.
2111 The value is an alist, with the car being a symbol indicating the note
2112 context, and the cdr is the heading to be used. The heading may also be the
2114 %t in the heading will be replaced by a time stamp.
2115 %s will be replaced by the new TODO state, in double quotes.
2116 %S will be replaced by the old TODO state, in double quotes.
2117 %u will be replaced by the user name.
2118 %U will be replaced by the full user name.
2120 In fact, it is not a good idea to change the `state' entry, because
2121 agenda log mode depends on the format of these entries."
2123 :group
'org-progress
2124 :type
'(list :greedy t
2125 (cons (const :tag
"Heading when closing an item" done
) string
)
2127 "Heading when changing todo state (todo sequence only)"
2129 (cons (const :tag
"Heading when just taking a note" note
) string
)
2130 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2131 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2132 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2133 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2134 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2135 (cons (const :tag
"Heading when refiling" refile
) string
)))
2137 (unless (assq 'note org-log-note-headings
)
2138 (push '(note .
"%t") org-log-note-headings
))
2140 (defcustom org-log-into-drawer nil
2141 "Non-nil means insert state change notes and time stamps into a drawer.
2142 When nil, state changes notes will be inserted after the headline and
2143 any scheduling and clock lines, but not inside a drawer.
2145 The value of this variable should be the name of the drawer to use.
2146 LOGBOOK is proposed at the default drawer for this purpose, you can
2147 also set this to a string to define the drawer of your choice.
2149 A value of t is also allowed, representing \"LOGBOOK\".
2151 If this variable is set, `org-log-state-notes-insert-after-drawers'
2154 You can set the property LOG_INTO_DRAWER to overrule this setting for
2157 :group
'org-progress
2159 (const :tag
"Not into a drawer" nil
)
2160 (const :tag
"LOGBOOK" t
)
2161 (string :tag
"Other")))
2163 (if (fboundp 'defvaralias
)
2164 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2166 (defun org-log-into-drawer ()
2167 "Return the value of `org-log-into-drawer', but let properties overrule.
2168 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2169 used instead of the default value."
2170 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2172 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2173 ((equal p
"t") "LOGBOOK")
2176 (defcustom org-log-state-notes-insert-after-drawers nil
2177 "Non-nil means insert state change notes after any drawers in entry.
2178 Only the drawers that *immediately* follow the headline and the
2179 deadline/scheduled line are skipped.
2180 When nil, insert notes right after the heading and perhaps the line
2181 with deadline/scheduling if present.
2183 This variable will have no effect if `org-log-into-drawer' is
2186 :group
'org-progress
2189 (defcustom org-log-states-order-reversed t
2190 "Non-nil means the latest state note will be directly after heading.
2191 When nil, the state change notes will be ordered according to time."
2193 :group
'org-progress
2196 (defcustom org-todo-repeat-to-state nil
2197 "The TODO state to which a repeater should return the repeating task.
2198 By default this is the first task in a TODO sequence, or the previous state
2199 in a TODO_TYP set. But you can specify another task here.
2200 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2202 :type
'(choice (const :tag
"Head of sequence" nil
)
2203 (string :tag
"Specific state")))
2205 (defcustom org-log-repeat
'time
2206 "Non-nil means record moving through the DONE state when triggering repeat.
2207 An auto-repeating task is immediately switched back to TODO when
2208 marked DONE. If you are not logging state changes (by adding \"@\"
2209 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2210 record a closing note, there will be no record of the task moving
2211 through DONE. This variable forces taking a note anyway.
2213 nil Don't force a record
2214 time Record a time stamp
2217 This option can also be set with on a per-file-basis with
2219 #+STARTUP: logrepeat
2220 #+STARTUP: lognoterepeat
2221 #+STARTUP: nologrepeat
2223 You can have local logging settings for a subtree by setting the LOGGING
2224 property to one or more of these keywords."
2226 :group
'org-progress
2228 (const :tag
"Don't force a record" nil
)
2229 (const :tag
"Force recording the DONE state" time
)
2230 (const :tag
"Force recording a note with the DONE state" note
)))
2233 (defgroup org-priorities nil
2234 "Priorities in Org-mode."
2235 :tag
"Org Priorities"
2238 (defcustom org-enable-priority-commands t
2239 "Non-nil means priority commands are active.
2240 When nil, these commands will be disabled, so that you never accidentally
2242 :group
'org-priorities
2245 (defcustom org-highest-priority ?A
2246 "The highest priority of TODO items. A character like ?A, ?B etc.
2247 Must have a smaller ASCII number than `org-lowest-priority'."
2248 :group
'org-priorities
2251 (defcustom org-lowest-priority ?C
2252 "The lowest priority of TODO items. A character like ?A, ?B etc.
2253 Must have a larger ASCII number than `org-highest-priority'."
2254 :group
'org-priorities
2257 (defcustom org-default-priority ?B
2258 "The default priority of TODO items.
2259 This is the priority an item get if no explicit priority is given."
2260 :group
'org-priorities
2263 (defcustom org-priority-start-cycle-with-default t
2264 "Non-nil means start with default priority when starting to cycle.
2265 When this is nil, the first step in the cycle will be (depending on the
2266 command used) one higher or lower that the default priority."
2267 :group
'org-priorities
2270 (defgroup org-time nil
2271 "Options concerning time stamps and deadlines in Org-mode."
2275 (defcustom org-insert-labeled-timestamps-at-point nil
2276 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2277 When nil, these labeled time stamps are forces into the second line of an
2278 entry, just after the headline. When scheduling from the global TODO list,
2279 the time stamp will always be forced into the second line."
2283 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2284 "Formats for `format-time-string' which are used for time stamps.
2285 It is not recommended to change this constant.")
2287 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2288 "Number of minutes to round time stamps to.
2289 These are two values, the first applies when first creating a time stamp.
2290 The second applies when changing it with the commands `S-up' and `S-down'.
2291 When changing the time stamp, this means that it will change in steps
2292 of N minutes, as given by the second value.
2294 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2295 numbers should be factors of 60, so for example 5, 10, 15.
2297 When this is larger than 1, you can still force an exact time-stamp by using
2298 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2299 and by using a prefix arg to `S-up/down' to specify the exact number
2300 of minutes to shift."
2302 :get
'(lambda (var) ; Make sure all entries have 5 elements
2303 (if (integerp (default-value var
))
2304 (list (default-value var
) 5)
2305 (default-value var
)))
2307 (integer :tag
"when inserting times")
2308 (integer :tag
"when modifying times")))
2310 ;; Normalize old customizations of this variable.
2311 (when (integerp org-time-stamp-rounding-minutes
)
2312 (setq org-time-stamp-rounding-minutes
2313 (list org-time-stamp-rounding-minutes
2314 org-time-stamp-rounding-minutes
)))
2316 (defcustom org-display-custom-times nil
2317 "Non-nil means overlay custom formats over all time stamps.
2318 The formats are defined through the variable `org-time-stamp-custom-formats'.
2319 To turn this on on a per-file basis, insert anywhere in the file:
2320 #+STARTUP: customtime"
2324 (make-variable-buffer-local 'org-display-custom-times
)
2326 (defcustom org-time-stamp-custom-formats
2327 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2328 "Custom formats for time stamps. See `format-time-string' for the syntax.
2329 These are overlayed over the default ISO format if the variable
2330 `org-display-custom-times' is set. Time like %H:%M should be at the
2331 end of the second format. The custom formats are also honored by export
2332 commands, if custom time display is turned on at the time of export."
2336 (defun org-time-stamp-format (&optional long inactive
)
2337 "Get the right format for a time string."
2338 (let ((f (if long
(cdr org-time-stamp-formats
)
2339 (car org-time-stamp-formats
))))
2341 (concat "[" (substring f
1 -
1) "]")
2344 (defcustom org-time-clocksum-format
"%d:%02d"
2345 "The format string used when creating CLOCKSUM lines, or when
2346 org-mode generates a time duration."
2350 (defcustom org-time-clocksum-use-fractional nil
2351 "If non-nil, \\[org-clock-display] uses fractional times.
2352 org-mode generates a time duration."
2356 (defcustom org-time-clocksum-fractional-format
"%.2f"
2357 "The format string used when creating CLOCKSUM lines, or when
2358 org-mode generates a time duration."
2362 (defcustom org-deadline-warning-days
14
2363 "No. of days before expiration during which a deadline becomes active.
2364 This variable governs the display in sparse trees and in the agenda.
2365 When 0 or negative, it means use this number (the absolute value of it)
2366 even if a deadline has a different individual lead time specified.
2368 Custom commands can set this variable in the options section."
2370 :group
'org-agenda-daily
/weekly
2373 (defcustom org-read-date-prefer-future t
2374 "Non-nil means assume future for incomplete date input from user.
2375 This affects the following situations:
2376 1. The user gives a month but not a year.
2377 For example, if it is april and you enter \"feb 2\", this will be read
2378 as feb 2, *next* year. \"May 5\", however, will be this year.
2379 2. The user gives a day, but no month.
2380 For example, if today is the 15th, and you enter \"3\", Org-mode will
2381 read this as the third of *next* month. However, if you enter \"17\",
2382 it will be considered as *this* month.
2384 If you set this variable to the symbol `time', then also the following
2387 3. If the user gives a time, but no day. If the time is before now,
2388 to will be interpreted as tomorrow.
2390 Currently none of this works for ISO week specifications.
2392 When this option is nil, the current day, month and year will always be
2396 (const :tag
"Never" nil
)
2397 (const :tag
"Check month and day" t
)
2398 (const :tag
"Check month, day, and time" time
)))
2400 (defcustom org-read-date-display-live t
2401 "Non-nil means display current interpretation of date prompt live.
2402 This display will be in an overlay, in the minibuffer."
2406 (defcustom org-read-date-popup-calendar t
2407 "Non-nil means pop up a calendar when prompting for a date.
2408 In the calendar, the date can be selected with mouse-1. However, the
2409 minibuffer will also be active, and you can simply enter the date as well.
2410 When nil, only the minibuffer will be available."
2413 (if (fboundp 'defvaralias
)
2414 (defvaralias 'org-popup-calendar-for-date-prompt
2415 'org-read-date-popup-calendar
))
2417 (defcustom org-read-date-minibuffer-setup-hook nil
2418 "Hook to be used to set up keys for the date/time interface.
2419 Add key definitions to `minibuffer-local-map', which will be a temporary
2424 (defcustom org-extend-today-until
0
2425 "The hour when your day really ends. Must be an integer.
2426 This has influence for the following applications:
2427 - When switching the agenda to \"today\". It it is still earlier than
2428 the time given here, the day recognized as TODAY is actually yesterday.
2429 - When a date is read from the user and it is still before the time given
2430 here, the current date and time will be assumed to be yesterday, 23:59.
2431 Also, timestamps inserted in remember templates follow this rule.
2433 IMPORTANT: This is a feature whose implementation is and likely will
2434 remain incomplete. Really, it is only here because past midnight seems to
2435 be the favorite working time of John Wiegley :-)"
2439 (defcustom org-edit-timestamp-down-means-later nil
2440 "Non-nil means S-down will increase the time in a time stamp.
2441 When nil, S-up will increase."
2445 (defcustom org-calendar-follow-timestamp-change t
2446 "Non-nil means make the calendar window follow timestamp changes.
2447 When a timestamp is modified and the calendar window is visible, it will be
2448 moved to the new date."
2452 (defgroup org-tags nil
2453 "Options concerning tags in Org-mode."
2457 (defcustom org-tag-alist nil
2458 "List of tags allowed in Org-mode files.
2459 When this list is nil, Org-mode will base TAG input on what is already in the
2461 The value of this variable is an alist, the car of each entry must be a
2462 keyword as a string, the cdr may be a character that is used to select
2463 that tag through the fast-tag-selection interface.
2464 See the manual for details."
2468 (cons (string :tag
"Tag name")
2469 (character :tag
"Access char"))
2470 (list :tag
"Start radio group"
2472 (option (string :tag
"Group description")))
2473 (list :tag
"End radio group"
2475 (option (string :tag
"Group description")))
2476 (const :tag
"New line" (:newline
)))))
2478 (defcustom org-tag-persistent-alist nil
2479 "List of tags that will always appear in all Org-mode files.
2480 This is in addition to any in buffer settings or customizations
2482 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2483 The value of this variable is an alist, the car of each entry must be a
2484 keyword as a string, the cdr may be a character that is used to select
2485 that tag through the fast-tag-selection interface.
2486 See the manual for details.
2487 To disable these tags on a per-file basis, insert anywhere in the file:
2492 (cons (string :tag
"Tag name")
2493 (character :tag
"Access char"))
2494 (const :tag
"Start radio group" (:startgroup
))
2495 (const :tag
"End radio group" (:endgroup
))
2496 (const :tag
"New line" (:newline
)))))
2498 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2499 "If non-nil, always offer completion for all tags of all agenda files.
2500 Instead of customizing this variable directly, you might want to
2501 set it locally for remember buffers, because there no list of
2502 tags in that file can be created dynamically (there are none).
2504 (add-hook 'org-remember-mode-hook
2506 (set (make-local-variable
2507 'org-complete-tags-always-offer-all-agenda-tags)
2512 (defvar org-file-tags nil
2513 "List of tags that can be inherited by all entries in the file.
2514 The tags will be inherited if the variable `org-use-tag-inheritance'
2515 says they should be.
2516 This variable is populated from #+FILETAGS lines.")
2518 (defcustom org-use-fast-tag-selection
'auto
2519 "Non-nil means use fast tag selection scheme.
2520 This is a special interface to select and deselect tags with single keys.
2521 When nil, fast selection is never used.
2522 When the symbol `auto', fast selection is used if and only if selection
2523 characters for tags have been configured, either through the variable
2524 `org-tag-alist' or through a #+TAGS line in the buffer.
2525 When t, fast selection is always used and selection keys are assigned
2526 automatically if necessary."
2529 (const :tag
"Always" t
)
2530 (const :tag
"Never" nil
)
2531 (const :tag
"When selection characters are configured" 'auto
)))
2533 (defcustom org-fast-tag-selection-single-key nil
2534 "Non-nil means fast tag selection exits after first change.
2535 When nil, you have to press RET to exit it.
2536 During fast tag selection, you can toggle this flag with `C-c'.
2537 This variable can also have the value `expert'. In this case, the window
2538 displaying the tags menu is not even shown, until you press C-c again."
2541 (const :tag
"No" nil
)
2542 (const :tag
"Yes" t
)
2543 (const :tag
"Expert" expert
)))
2545 (defvar org-fast-tag-selection-include-todo nil
2546 "Non-nil means fast tags selection interface will also offer TODO states.
2547 This is an undocumented feature, you should not rely on it.")
2549 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2550 "The column to which tags should be indented in a headline.
2551 If this number is positive, it specifies the column. If it is negative,
2552 it means that the tags should be flushright to that column. For example,
2553 -80 works well for a normal 80 character screen."
2557 (defcustom org-auto-align-tags t
2558 "Non-nil means realign tags after pro/demotion of TODO state change.
2559 These operations change the length of a headline and therefore shift
2560 the tags around. With this options turned on, after each such operation
2561 the tags are again aligned to `org-tags-column'."
2565 (defcustom org-use-tag-inheritance t
2566 "Non-nil means tags in levels apply also for sublevels.
2567 When nil, only the tags directly given in a specific line apply there.
2568 This may also be a list of tags that should be inherited, or a regexp that
2569 matches tags that should be inherited. Additional control is possible
2570 with the variable `org-tags-exclude-from-inheritance' which gives an
2571 explicit list of tags to be excluded from inheritance., even if the value of
2572 `org-use-tag-inheritance' would select it for inheritance.
2574 If this option is t, a match early-on in a tree can lead to a large
2575 number of matches in the subtree when constructing the agenda or creating
2576 a sparse tree. If you only want to see the first match in a tree during
2577 a search, check out the variable `org-tags-match-list-sublevels'."
2580 (const :tag
"Not" nil
)
2581 (const :tag
"Always" t
)
2582 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2583 (regexp :tag
"Tags matched by regexp")))
2585 (defcustom org-tags-exclude-from-inheritance nil
2586 "List of tags that should never be inherited.
2587 This is a way to exclude a few tags from inheritance. For way to do
2588 the opposite, to actively allow inheritance for selected tags,
2589 see the variable `org-use-tag-inheritance'."
2591 :type
'(repeat (string :tag
"Tag")))
2593 (defun org-tag-inherit-p (tag)
2594 "Check if TAG is one that should be inherited."
2596 ((member tag org-tags-exclude-from-inheritance
) nil
)
2597 ((eq org-use-tag-inheritance t
) t
)
2598 ((not org-use-tag-inheritance
) nil
)
2599 ((stringp org-use-tag-inheritance
)
2600 (string-match org-use-tag-inheritance tag
))
2601 ((listp org-use-tag-inheritance
)
2602 (member tag org-use-tag-inheritance
))
2603 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2605 (defcustom org-tags-match-list-sublevels t
2606 "Non-nil means list also sublevels of headlines matching a search.
2607 This variable applies to tags/property searches, and also to stuck
2608 projects because this search is based on a tags match as well.
2610 When set to the symbol `indented', sublevels are indented with
2613 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2614 the sublevels of a headline matching a tag search often also match
2615 the same search. Listing all of them can create very long lists.
2616 Setting this variable to nil causes subtrees of a match to be skipped.
2618 This variable is semi-obsolete and probably should always be true. It
2619 is better to limit inheritance to certain tags using the variables
2620 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2623 (const :tag
"No, don't list them" nil
)
2624 (const :tag
"Yes, do list them" t
)
2625 (const :tag
"List them, indented with leading dots" indented
)))
2627 (defcustom org-tags-sort-function nil
2628 "When set, tags are sorted using this function as a comparator"
2631 (const :tag
"No sorting" nil
)
2632 (const :tag
"Alphabetical" string
<)
2633 (const :tag
"Reverse alphabetical" string
>)
2634 (function :tag
"Custom function" nil
)))
2636 (defvar org-tags-history nil
2637 "History of minibuffer reads for tags.")
2638 (defvar org-last-tags-completion-table nil
2639 "The last used completion table for tags.")
2640 (defvar org-after-tags-change-hook nil
2641 "Hook that is run after the tags in a line have changed.")
2643 (defgroup org-properties nil
2644 "Options concerning properties in Org-mode."
2645 :tag
"Org Properties"
2648 (defcustom org-property-format
"%-10s %s"
2649 "How property key/value pairs should be formatted by `indent-line'.
2650 When `indent-line' hits a property definition, it will format the line
2651 according to this format, mainly to make sure that the values are
2652 lined-up with respect to each other."
2653 :group
'org-properties
2656 (defcustom org-use-property-inheritance nil
2657 "Non-nil means properties apply also for sublevels.
2659 This setting is chiefly used during property searches. Turning it on can
2660 cause significant overhead when doing a search, which is why it is not
2663 When nil, only the properties directly given in the current entry count.
2664 When t, every property is inherited. The value may also be a list of
2665 properties that should have inheritance, or a regular expression matching
2666 properties that should be inherited.
2668 However, note that some special properties use inheritance under special
2669 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2670 and the properties ending in \"_ALL\" when they are used as descriptor
2671 for valid values of a property.
2673 Note for programmers:
2674 When querying an entry with `org-entry-get', you can control if inheritance
2675 should be used. By default, `org-entry-get' looks only at the local
2676 properties. You can request inheritance by setting the inherit argument
2677 to t (to force inheritance) or to `selective' (to respect the setting
2679 :group
'org-properties
2681 (const :tag
"Not" nil
)
2682 (const :tag
"Always" t
)
2683 (repeat :tag
"Specific properties" (string :tag
"Property"))
2684 (regexp :tag
"Properties matched by regexp")))
2686 (defun org-property-inherit-p (property)
2687 "Check if PROPERTY is one that should be inherited."
2689 ((eq org-use-property-inheritance t
) t
)
2690 ((not org-use-property-inheritance
) nil
)
2691 ((stringp org-use-property-inheritance
)
2692 (string-match org-use-property-inheritance property
))
2693 ((listp org-use-property-inheritance
)
2694 (member property org-use-property-inheritance
))
2695 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2697 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2698 "The default column format, if no other format has been defined.
2699 This variable can be set on the per-file basis by inserting a line
2701 #+COLUMNS: %25ITEM ....."
2702 :group
'org-properties
2705 (defcustom org-columns-ellipses
".."
2706 "The ellipses to be used when a field in column view is truncated.
2707 When this is the empty string, as many characters as possible are shown,
2708 but then there will be no visual indication that the field has been truncated.
2709 When this is a string of length N, the last N characters of a truncated
2710 field are replaced by this string. If the column is narrower than the
2711 ellipses string, only part of the ellipses string will be shown."
2712 :group
'org-properties
2715 (defcustom org-columns-modify-value-for-display-function nil
2716 "Function that modifies values for display in column view.
2717 For example, it can be used to cut out a certain part from a time stamp.
2718 The function must take 2 arguments:
2720 column-title The title of the column (*not* the property name)
2721 value The value that should be modified.
2723 The function should return the value that should be displayed,
2724 or nil if the normal value should be used."
2725 :group
'org-properties
2728 (defcustom org-effort-property
"Effort"
2729 "The property that is being used to keep track of effort estimates.
2730 Effort estimates given in this property need to have the format H:MM."
2731 :group
'org-properties
2732 :group
'org-progress
2733 :type
'(string :tag
"Property"))
2735 (defconst org-global-properties-fixed
2736 '(("VISIBILITY_ALL" .
"folded children content all")
2737 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2738 "List of property/value pairs that can be inherited by any entry.
2740 These are fixed values, for the preset properties. The user variable
2741 that can be used to add to this list is `org-global-properties'.
2743 The entries in this list are cons cells where the car is a property
2744 name and cdr is a string with the value. If the value represents
2745 multiple items like an \"_ALL\" property, separate the items by
2748 (defcustom org-global-properties nil
2749 "List of property/value pairs that can be inherited by any entry.
2751 This list will be combined with the constant `org-global-properties-fixed'.
2753 The entries in this list are cons cells where the car is a property
2754 name and cdr is a string with the value.
2756 You can set buffer-local values for the same purpose in the variable
2757 `org-file-properties' this by adding lines like
2759 #+PROPERTY: NAME VALUE"
2760 :group
'org-properties
2762 (cons (string :tag
"Property")
2763 (string :tag
"Value"))))
2765 (defvar org-file-properties nil
2766 "List of property/value pairs that can be inherited by any entry.
2767 Valid for the current buffer.
2768 This variable is populated from #+PROPERTY lines.")
2769 (make-variable-buffer-local 'org-file-properties
)
2771 (defgroup org-agenda nil
2772 "Options concerning agenda views in Org-mode."
2776 (defvar org-category nil
2777 "Variable used by org files to set a category for agenda display.
2778 Such files should use a file variable to set it, for example
2780 # -*- mode: org; org-category: \"ELisp\"
2782 or contain a special line
2786 If the file does not specify a category, then file's base name
2788 (make-variable-buffer-local 'org-category
)
2789 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2791 (defcustom org-agenda-files nil
2792 "The files to be used for agenda display.
2793 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2794 \\[org-remove-file]. You can also use customize to edit the list.
2796 If an entry is a directory, all files in that directory that are matched by
2797 `org-agenda-file-regexp' will be part of the file list.
2799 If the value of the variable is not a list but a single file name, then
2800 the list of agenda files is actually stored and maintained in that file, one
2801 agenda file per line. In this file paths can be given relative to
2802 `org-directory'. Tilde expansion and environment variable substitution
2806 (repeat :tag
"List of files and directories" file
)
2807 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2809 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2810 "Regular expression to match files for `org-agenda-files'.
2811 If any element in the list in that variable contains a directory instead
2812 of a normal file, all files in that directory that are matched by this
2813 regular expression will be included."
2817 (defcustom org-agenda-text-search-extra-files nil
2818 "List of extra files to be searched by text search commands.
2819 These files will be search in addition to the agenda files by the
2820 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2821 Note that these files will only be searched for text search commands,
2822 not for the other agenda views like todo lists, tag searches or the weekly
2823 agenda. This variable is intended to list notes and possibly archive files
2824 that should also be searched by these two commands.
2825 In fact, if the first element in the list is the symbol `agenda-archives',
2826 than all archive files of all agenda files will be added to the search
2829 :type
'(set :greedy t
2830 (const :tag
"Agenda Archives" agenda-archives
)
2831 (repeat :inline t
(file))))
2833 (if (fboundp 'defvaralias
)
2834 (defvaralias 'org-agenda-multi-occur-extra-files
2835 'org-agenda-text-search-extra-files
))
2837 (defcustom org-agenda-skip-unavailable-files nil
2838 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
2839 A nil value means to remove them, after a query, from the list."
2843 (defcustom org-calendar-to-agenda-key
[?c
]
2844 "The key to be installed in `calendar-mode-map' for switching to the agenda.
2845 The command `org-calendar-goto-agenda' will be bound to this key. The
2846 default is the character `c' because then `c' can be used to switch back and
2847 forth between agenda and calendar."
2851 (defcustom org-calendar-agenda-action-key
[?k
]
2852 "The key to be installed in `calendar-mode-map' for agenda-action.
2853 The command `org-agenda-action' will be bound to this key. The
2854 default is the character `k' because we use the same key in the agenda."
2858 (defcustom org-calendar-insert-diary-entry-key
[?i
]
2859 "The key to be installed in `calendar-mode-map' for adding diary entries.
2860 This option is irrelevant until `org-agenda-diary-file' has been configured
2861 to point to an Org-mode file. When that is the case, the command
2862 `org-agenda-diary-entry' will be bound to the key given here, by default
2863 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
2864 if you want to continue doing this, you need to change this to a different
2869 (defcustom org-agenda-diary-file
'diary-file
2870 "File to which to add new entries with the `i' key in agenda and calendar.
2871 When this is the symbol `diary-file', the functionality in the Emacs
2872 calendar will be used to add entries to the `diary-file'. But when this
2873 points to a file, `org-agenda-diary-entry' will be used instead."
2876 (const :tag
"The standard Emacs diary file" diary-file
)
2877 (file :tag
"Special Org file diary entries")))
2879 (eval-after-load "calendar"
2881 (org-defkey calendar-mode-map org-calendar-to-agenda-key
2882 'org-calendar-goto-agenda
)
2883 (org-defkey calendar-mode-map org-calendar-agenda-action-key
2885 (add-hook 'calendar-mode-hook
2887 (unless (eq org-agenda-diary-file
'diary-file
)
2888 (define-key calendar-mode-map
2889 org-calendar-insert-diary-entry-key
2890 'org-agenda-diary-entry
))))))
2892 (defgroup org-latex nil
2893 "Options for embedding LaTeX code into Org-mode."
2897 (defcustom org-format-latex-options
2898 '(:foreground default
:background default
:scale
1.0
2899 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
2900 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
2901 "Options for creating images from LaTeX fragments.
2902 This is a property list with the following properties:
2903 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
2904 `default' means use the foreground of the default face.
2905 :background the background color, or \"Transparent\".
2906 `default' means use the background of the default face.
2907 :scale a scaling factor for the size of the images.
2908 :html-foreground, :html-background, :html-scale
2909 the same numbers for HTML export.
2910 :matchers a list indicating which matchers should be used to
2911 find LaTeX fragments. Valid members of this list are:
2912 \"begin\" find environments
2913 \"$1\" find single characters surrounded by $.$
2914 \"$\" find math expressions surrounded by $...$
2915 \"$$\" find math expressions surrounded by $$....$$
2916 \"\\(\" find math expressions surrounded by \\(...\\)
2917 \"\\ [\" find math expressions surrounded by \\ [...\\]"
2921 (defcustom org-format-latex-signal-error t
2922 "Non-nil means signal an error when image creation of LaTeX snippets fails.
2923 When nil, just push out a message."
2927 (defcustom org-format-latex-header
"\\documentclass{article}
2928 \\usepackage[usenames]{color}
2929 \\usepackage{amsmath}
2930 \\usepackage[mathscr]{eucal}
2931 \\pagestyle{empty} % do not remove
2934 % The settings below are copied from fullpage.sty
2935 \\setlength{\\textwidth}{\\paperwidth}
2936 \\addtolength{\\textwidth}{-3cm}
2937 \\setlength{\\oddsidemargin}{1.5cm}
2938 \\addtolength{\\oddsidemargin}{-2.54cm}
2939 \\setlength{\\evensidemargin}{\\oddsidemargin}
2940 \\setlength{\\textheight}{\\paperheight}
2941 \\addtolength{\\textheight}{-\\headheight}
2942 \\addtolength{\\textheight}{-\\headsep}
2943 \\addtolength{\\textheight}{-\\footskip}
2944 \\addtolength{\\textheight}{-3cm}
2945 \\setlength{\\topmargin}{1.5cm}
2946 \\addtolength{\\topmargin}{-2.54cm}"
2947 "The document header used for processing LaTeX fragments.
2948 It is imperative that this header make sure that no page number
2949 appears on the page. The package defined in the variables
2950 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
2951 will either replace the placeholder \"[PACKAGES]\" in this header, or they
2956 (defvar org-format-latex-header-extra nil
)
2958 ;; The following variables are defined here because is it also used
2959 ;; when formatting latex fragments. Originally it was part of the
2960 ;; LaTeX exporter, which is why the name includes "export".
2961 (defcustom org-export-latex-default-packages-alist
2962 '(("AUTO" "inputenc")
2979 "Alist of default packages to be inserted in the header.
2980 Change this only if one of the packages here causes an incompatibility
2981 with another package you are using.
2982 The packages in this list are needed by one part or another of Org-mode
2983 to function properly.
2985 - inputenc, fontenc, t1enc: for basic font and character selection
2986 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
2987 for interpreting the entities in `org-entities'. You can skip some of these
2988 packages if you don't use any of the symbols in it.
2989 - graphicx: for including images
2990 - float, wrapfig: for figure placement
2991 - longtable: for long tables
2992 - hyperref: for cross references
2994 Therefore you should not modify this variable unless you know what you
2995 are doing. The one reason to change it anyway is that you might be loading
2996 some other package that conflicts with one of the default packages.
2997 Each cell is of the format \( \"options\" \"package\" \)."
2998 :group
'org-export-latex
3001 (string :tag
"A line of LaTeX")
3002 (list :tag
"options/package pair"
3003 (string :tag
"options")
3004 (string :tag
"package")))))
3006 (defcustom org-export-latex-packages-alist nil
3007 "Alist of packages to be inserted in every LaTeX the header.
3008 These will be inserted after `org-export-latex-default-packages-alist'.
3009 Each cell is of the format \( \"options\" \"package\" \).
3010 Make sure that you only lis packages here which:
3011 - you want in every file
3012 - do not conflict with the default packages in
3013 `org-export-latex-default-packages-alist'
3014 - do not conflict with the setup in `org-format-latex-header'."
3015 :group
'org-export-latex
3018 (string :tag
"A line of LaTeX")
3019 (list :tag
"options/package pair"
3020 (string :tag
"options")
3021 (string :tag
"package")))))
3023 (defgroup org-appearance nil
3024 "Settings for Org-mode appearance."
3025 :tag
"Org Appearance"
3028 (defcustom org-level-color-stars-only nil
3029 "Non-nil means fontify only the stars in each headline.
3030 When nil, the entire headline is fontified.
3031 Changing it requires restart of `font-lock-mode' to become effective
3032 also in regions already fontified."
3033 :group
'org-appearance
3036 (defcustom org-hide-leading-stars nil
3037 "Non-nil means hide the first N-1 stars in a headline.
3038 This works by using the face `org-hide' for these stars. This
3039 face is white for a light background, and black for a dark
3040 background. You may have to customize the face `org-hide' to
3042 Changing it requires restart of `font-lock-mode' to become effective
3043 also in regions already fontified.
3044 You may also set this on a per-file basis by adding one of the following
3045 lines to the buffer:
3047 #+STARTUP: hidestars
3048 #+STARTUP: showstars"
3049 :group
'org-appearance
3052 (defcustom org-hidden-keywords nil
3053 "List of keywords that should be hidden when typed in the org buffer.
3054 For example, add #+TITLE to this list in order to make the
3055 document title appear in the buffer without the initial #+TITLE:
3057 :group
'org-appearance
3058 :type
'(set (const :tag
"#+AUTHOR" author
)
3059 (const :tag
"#+DATE" date
)
3060 (const :tag
"#+EMAIL" email
)
3061 (const :tag
"#+TITLE" title
)))
3063 (defcustom org-fontify-done-headline nil
3064 "Non-nil means change the face of a headline if it is marked DONE.
3065 Normally, only the TODO/DONE keyword indicates the state of a headline.
3066 When this is non-nil, the headline after the keyword is set to the
3067 `org-headline-done' as an additional indication."
3068 :group
'org-appearance
3071 (defcustom org-fontify-emphasized-text t
3072 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3073 Changing this variable requires a restart of Emacs to take effect."
3074 :group
'org-appearance
3077 (defcustom org-fontify-whole-heading-line nil
3078 "Non-nil means fontify the whole line for headings.
3079 This is useful when setting a background color for the
3081 :group
'org-appearance
3084 (defcustom org-highlight-latex-fragments-and-specials nil
3085 "Non-nil means fontify what is treated specially by the exporters."
3086 :group
'org-appearance
3089 (defcustom org-hide-emphasis-markers nil
3090 "Non-nil mean font-lock should hide the emphasis marker characters."
3091 :group
'org-appearance
3094 (defvar org-emph-re nil
3095 "Regular expression for matching emphasis.")
3096 (defvar org-verbatim-re nil
3097 "Regular expression for matching verbatim text.")
3098 (defvar org-emphasis-regexp-components
) ; defined just below
3099 (defvar org-emphasis-alist
) ; defined just below
3100 (defun org-set-emph-re (var val
)
3101 "Set variable and compute the emphasis regular expression."
3103 (when (and (boundp 'org-emphasis-alist
)
3104 (boundp 'org-emphasis-regexp-components
)
3105 org-emphasis-alist org-emphasis-regexp-components
)
3106 (let* ((e org-emphasis-regexp-components
)
3112 (body1 (concat body
"*?"))
3113 (markers (mapconcat 'car org-emphasis-alist
""))
3114 (vmarkers (mapconcat
3115 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3116 org-emphasis-alist
"")))
3117 ;; make sure special characters appear at the right position in the class
3118 (if (string-match "\\^" markers
)
3119 (setq markers
(concat (replace-match "" t t markers
) "^")))
3120 (if (string-match "-" markers
)
3121 (setq markers
(concat (replace-match "" t t markers
) "-")))
3122 (if (string-match "\\^" vmarkers
)
3123 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3124 (if (string-match "-" vmarkers
)
3125 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3127 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3128 (int-to-string nl
) "\\}")))
3131 (concat "\\([" pre
"]\\|^\\)"
3133 "\\([" markers
"]\\)"
3141 "\\([" post
"]\\|$\\)"))
3142 (setq org-verbatim-re
3143 (concat "\\([" pre
"]\\|^\\)"
3145 "\\([" vmarkers
"]\\)"
3153 "\\([" post
"]\\|$\\)")))))
3155 (defcustom org-emphasis-regexp-components
3156 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3157 "Components used to build the regular expression for emphasis.
3158 This is a list with 6 entries. Terminology: In an emphasis string
3159 like \" *strong word* \", we call the initial space PREMATCH, the final
3160 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3161 and \"trong wor\" is the body. The different components in this variable
3162 specify what is allowed/forbidden in each part:
3164 pre Chars allowed as prematch. Beginning of line will be allowed too.
3165 post Chars allowed as postmatch. End of line will be allowed too.
3166 border The chars *forbidden* as border characters.
3167 body-regexp A regexp like \".\" to match a body character. Don't use
3168 non-shy groups here, and don't allow newline here.
3169 newline The maximum number of newlines allowed in an emphasis exp.
3171 Use customize to modify this, or restart Emacs after changing it."
3172 :group
'org-appearance
3173 :set
'org-set-emph-re
3175 (sexp :tag
"Allowed chars in pre ")
3176 (sexp :tag
"Allowed chars in post ")
3177 (sexp :tag
"Forbidden chars in border ")
3178 (sexp :tag
"Regexp for body ")
3179 (integer :tag
"number of newlines allowed")
3180 (option (boolean :tag
"Please ignore this button"))))
3182 (defcustom org-emphasis-alist
3183 `(("*" bold
"<b>" "</b>")
3184 ("/" italic
"<i>" "</i>")
3185 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3186 ("=" org-code
"<code>" "</code>" verbatim
)
3187 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3188 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3191 "Special syntax for emphasized text.
3192 Text starting and ending with a special character will be emphasized, for
3193 example *bold*, _underlined_ and /italic/. This variable sets the marker
3194 characters, the face to be used by font-lock for highlighting in Org-mode
3195 Emacs buffers, and the HTML tags to be used for this.
3196 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3197 Use customize to modify this, or restart Emacs after changing it."
3198 :group
'org-appearance
3199 :set
'org-set-emph-re
3202 (string :tag
"Marker character")
3204 (face :tag
"Font-lock-face")
3205 (plist :tag
"Face property list"))
3206 (string :tag
"HTML start tag")
3207 (string :tag
"HTML end tag")
3208 (option (const verbatim
)))))
3210 (defvar org-protecting-blocks
3211 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3212 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3213 This is needed for font-lock setup.")
3215 ;;; Miscellaneous options
3217 (defgroup org-completion nil
3218 "Completion in Org-mode."
3219 :tag
"Org Completion"
3222 (defcustom org-completion-use-ido nil
3223 "Non-nil means use ido completion wherever possible.
3224 Note that `ido-mode' must be active for this variable to be relevant.
3225 If you decide to turn this variable on, you might well want to turn off
3226 `org-outline-path-complete-in-steps'.
3227 See also `org-completion-use-iswitchb'."
3228 :group
'org-completion
3231 (defcustom org-completion-use-iswitchb nil
3232 "Non-nil means use iswitchb completion wherever possible.
3233 Note that `iswitchb-mode' must be active for this variable to be relevant.
3234 If you decide to turn this variable on, you might well want to turn off
3235 `org-outline-path-complete-in-steps'.
3236 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3237 :group
'org-completion
3240 (defcustom org-completion-fallback-command
'hippie-expand
3241 "The expansion command called by \\[org-complete] in normal context.
3242 Normal means no org-mode-specific context."
3243 :group
'org-completion
3246 ;;; Functions and variables from their packages
3247 ;; Declared here to avoid compiler warnings
3250 (defvar outline-mode-menu-heading
)
3251 (defvar outline-mode-menu-show
)
3252 (defvar outline-mode-menu-hide
)
3253 (defvar zmacs-regions
) ; XEmacs regions
3256 (defvar mark-active
)
3259 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3260 (declare-function calendar-forward-day
"cal-move" (arg))
3261 (declare-function calendar-goto-date
"cal-move" (date))
3262 (declare-function calendar-goto-today
"cal-move" ())
3263 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3264 (defvar calc-embedded-close-formula
)
3265 (defvar calc-embedded-open-formula
)
3266 (declare-function cdlatex-tab
"ext:cdlatex" ())
3267 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3268 (defvar font-lock-unfontify-region-function
)
3269 (declare-function iswitchb-read-buffer
"iswitchb"
3270 (prompt &optional default require-match start matches-set
))
3271 (defvar iswitchb-temp-buflist
)
3272 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3273 (defvar org-agenda-tags-todo-honor-ignore-options
)
3274 (declare-function org-agenda-skip
"org-agenda" ())
3276 org-format-agenda-item
"org-agenda"
3277 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3278 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3279 (declare-function org-agenda-change-all-lines
"org-agenda"
3280 (newhead hdmarker
&optional fixface just-this
))
3281 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3282 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3283 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3285 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3286 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3287 "org-agenda" (&optional end
))
3288 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3289 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3290 (declare-function parse-time-string
"parse-time" (string))
3291 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3292 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3293 (defvar remember-data-file
)
3294 (defvar texmathp-why
)
3295 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3296 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3298 (defvar w3m-current-url
)
3299 (defvar w3m-current-title
)
3301 (defvar org-latex-regexps
)
3303 ;;; Autoload and prepare some org modules
3305 ;; Some table stuff that needs to be defined here, because it is used
3306 ;; by the functions setting up org-mode or checking for table context.
3308 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3309 "Detects an org-type or table-type table.")
3310 (defconst org-table-line-regexp
"^[ \t]*|"
3311 "Detects an org-type table line.")
3312 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3313 "Detects an org-type table line.")
3314 (defconst org-table-hline-regexp
"^[ \t]*|-"
3315 "Detects an org-type table hline.")
3316 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3317 "Detects a table-type table hline.")
3318 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3319 "Searching from within a table (any type) this finds the first line
3320 outside the table.")
3322 ;; Autoload the functions in org-table.el that are needed by functions here.
3325 (org-autoload "org-table"
3326 '(org-table-align org-table-begin org-table-blank-field
3327 org-table-convert org-table-convert-region org-table-copy-down
3328 org-table-copy-region org-table-create
3329 org-table-create-or-convert-from-region
3330 org-table-create-with-table.el org-table-current-dline
3331 org-table-cut-region org-table-delete-column org-table-edit-field
3332 org-table-edit-formulas org-table-end org-table-eval-formula
3333 org-table-export org-table-field-info
3334 org-table-get-stored-formulas org-table-goto-column
3335 org-table-hline-and-move org-table-import org-table-insert-column
3336 org-table-insert-hline org-table-insert-row org-table-iterate
3337 org-table-justify-field-maybe org-table-kill-row
3338 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3339 org-table-move-column org-table-move-column-left
3340 org-table-move-column-right org-table-move-row
3341 org-table-move-row-down org-table-move-row-up
3342 org-table-next-field org-table-next-row org-table-paste-rectangle
3343 org-table-previous-field org-table-recalculate
3344 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3345 org-table-toggle-coordinate-overlays
3346 org-table-toggle-formula-debugger org-table-wrap-region
3347 orgtbl-mode turn-on-orgtbl org-table-to-lisp
)))
3349 (defun org-at-table-p (&optional table-type
)
3350 "Return t if the cursor is inside an org-type table.
3351 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3352 (if org-enable-table-editor
3354 (beginning-of-line 1)
3355 (looking-at (if table-type org-table-any-line-regexp
3356 org-table-line-regexp
)))
3358 (defsubst org-table-p
() (org-at-table-p))
3360 (defun org-at-table.el-p
()
3361 "Return t if and only if we are at a table.el table."
3362 (and (org-at-table-p 'any
)
3364 (goto-char (org-table-begin 'any
))
3365 (looking-at org-table1-hline-regexp
))))
3366 (defun org-table-recognize-table.el
()
3367 "If there is a table.el table nearby, recognize it and move into it."
3368 (if org-table-tab-recognizes-table.el
3369 (if (org-at-table.el-p
)
3371 (beginning-of-line 1)
3372 (if (looking-at org-table-dataline-regexp
)
3374 (if (looking-at org-table1-hline-regexp
)
3376 (beginning-of-line 2)
3377 (if (looking-at org-table-any-border-regexp
)
3378 (beginning-of-line -
1)))))
3379 (if (re-search-forward "|" (org-table-end t
) t
)
3382 (if (table--at-cell-p (point))
3384 (message "recognizing table.el table...")
3385 (table-recognize-table)
3386 (message "recognizing table.el table...done")))
3387 (error "This should not happen..."))
3392 (defun org-at-table-hline-p ()
3393 "Return t if the cursor is inside a hline in a table."
3394 (if org-enable-table-editor
3396 (beginning-of-line 1)
3397 (looking-at org-table-hline-regexp
))
3400 (defvar org-table-clean-did-remove-column nil
)
3402 (defun org-table-map-tables (function)
3403 "Apply FUNCTION to the start of all tables in the buffer."
3407 (goto-char (point-min))
3408 (while (re-search-forward org-table-any-line-regexp nil t
)
3409 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
3410 (beginning-of-line 1)
3411 (when (looking-at org-table-line-regexp
)
3412 (save-excursion (funcall function
))
3413 (or (looking-at org-table-line-regexp
)
3415 (re-search-forward org-table-any-border-regexp nil
1))))
3416 (message "Mapping tables: done"))
3418 ;; Declare and autoload functions from org-exp.el & Co
3420 (declare-function org-default-export-plist
"org-exp")
3421 (declare-function org-infile-export-plist
"org-exp")
3422 (declare-function org-get-current-options
"org-exp")
3424 (org-autoload "org-exp"
3425 '(org-export org-export-visible
3426 org-insert-export-options-template
3427 org-table-clean-before-export
))
3428 (org-autoload "org-ascii"
3429 '(org-export-as-ascii org-export-ascii-preprocess
3430 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3431 org-export-region-as-ascii
))
3432 (org-autoload "org-latex"
3433 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3434 org-replace-region-by-latex org-export-region-as-latex
3435 org-export-as-latex org-export-as-pdf
3436 org-export-as-pdf-and-open
))
3437 (org-autoload "org-html"
3438 '(org-export-as-html-and-open
3439 org-export-as-html-batch org-export-as-html-to-buffer
3440 org-replace-region-by-html org-export-region-as-html
3441 org-export-as-html
))
3442 (org-autoload "org-docbook"
3443 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3444 org-replace-region-by-docbook org-export-region-as-docbook
3445 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3446 org-export-as-docbook
))
3447 (org-autoload "org-icalendar"
3448 '(org-export-icalendar-this-file
3449 org-export-icalendar-all-agenda-files
3450 org-export-icalendar-combine-agenda-files
))
3451 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3452 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3454 ;; Declare and autoload functions from org-agenda.el
3457 (org-autoload "org-agenda"
3458 '(org-agenda org-agenda-list org-search-view
3459 org-todo-list org-tags-view org-agenda-list-stuck-projects
3460 org-diary org-agenda-to-appt
3461 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3463 ;; Autoload org-remember
3466 (org-autoload "org-remember"
3467 '(org-remember-insinuate org-remember-annotation
3468 org-remember-apply-template org-remember org-remember-handler
)))
3470 ;; Autoload org-clock.el
3473 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3475 (declare-function org-clock-update-mode-line
"org-clock" ())
3476 (declare-function org-resolve-clocks
"org-clock"
3477 (&optional also-non-dangling-p prompt last-valid
))
3478 (defvar org-clock-start-time
)
3479 (defvar org-clock-marker
(make-marker)
3480 "Marker recording the last clock-in.")
3481 (defvar org-clock-hd-marker
(make-marker)
3482 "Marker recording the last clock-in, but the headline position.")
3483 (defvar org-clock-heading
""
3484 "The heading of the current clock entry.")
3485 (defun org-clock-is-active ()
3486 "Return non-nil if clock is currently running.
3487 The return value is actually the clock marker."
3488 (marker-buffer org-clock-marker
))
3493 '(org-clock-in org-clock-out org-clock-cancel
3494 org-clock-goto org-clock-sum org-clock-display
3495 org-clock-remove-overlays org-clock-report
3496 org-clocktable-shift org-dblock-write
:clocktable
3497 org-get-clocktable org-resolve-clocks
)))
3499 (defun org-clock-update-time-maybe ()
3500 "If this is a CLOCK line, update it and return t.
3501 Otherwise, return nil."
3504 (beginning-of-line 1)
3505 (skip-chars-forward " \t")
3506 (when (looking-at org-clock-string
)
3507 (let ((re (concat "[ \t]*" org-clock-string
3508 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3509 "\\([ \t]*=>.*\\)?\\)?"))
3512 ((not (looking-at re
))
3514 ((not (match-end 2))
3515 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3516 (> org-clock-marker
(point))
3517 (<= org-clock-marker
(point-at-eol)))
3518 ;; The clock is running here
3519 (setq org-clock-start-time
3521 (org-parse-time-string (match-string 1))))
3522 (org-clock-update-mode-line)))
3524 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3526 (setq ts
(match-string 1)
3527 te
(match-string 3))
3528 (setq s
(- (org-float-time
3529 (apply 'encode-time
(org-parse-time-string te
)))
3531 (apply 'encode-time
(org-parse-time-string ts
))))
3534 h
(floor (/ s
3600))
3538 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3541 (defun org-check-running-clock ()
3542 "Check if the current buffer contains the running clock.
3543 If yes, offer to stop it and to save the buffer with the changes."
3544 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3545 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3548 (when (y-or-n-p "Save changed buffer?")
3551 (defun org-clocktable-try-shift (dir n
)
3552 "Check if this line starts a clock table, if yes, shift the time block."
3553 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3554 (org-clocktable-shift dir n
)))
3556 ;; Autoload org-timer.el
3561 '(org-timer-start org-timer org-timer-item
3562 org-timer-change-times-in-region
3564 org-timer-reset-timers
3565 org-timer-show-remaining-time
)))
3567 ;; Autoload org-feed.el
3572 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3575 ;; Autoload org-indent.el
3577 ;; Define the variable already here, to make sure we have it.
3578 (defvar org-indent-mode nil
3579 "Non-nil if Org-Indent mode is enabled.
3580 Use the command `org-indent-mode' to change this variable.")
3585 '(org-indent-mode)))
3587 ;; Autoload org-mobile.el
3592 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3594 ;; Autoload archiving code
3595 ;; The stuff that is needed for cycling and tags has to be defined here.
3597 (defgroup org-archive nil
3598 "Options concerning archiving in Org-mode."
3600 :group
'org-structure
)
3602 (defcustom org-archive-location
"%s_archive::"
3603 "The location where subtrees should be archived.
3605 The value of this variable is a string, consisting of two parts,
3606 separated by a double-colon. The first part is a filename and
3607 the second part is a headline.
3609 When the filename is omitted, archiving happens in the same file.
3610 %s in the filename will be replaced by the current file
3611 name (without the directory part). Archiving to a different file
3612 is useful to keep archived entries from contributing to the
3615 The archived entries will be filed as subtrees of the specified
3616 headline. When the headline is omitted, the subtrees are simply
3617 filed away at the end of the file, as top-level entries. Also in
3618 the heading you can use %s to represent the file name, this can be
3619 useful when using the same archive for a number of different files.
3621 Here are a few examples:
3623 If the current file is Projects.org, archive in file
3624 Projects.org_archive, as top-level trees. This is the default.
3626 \"::* Archived Tasks\"
3627 Archive in the current file, under the top-level headline
3628 \"* Archived Tasks\".
3630 \"~/org/archive.org::\"
3631 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3633 \"~/org/archive.org::From %s\"
3634 Archive in file ~/org/archive.org (absolute path), under headlines
3635 \"From FILENAME\" where file name is the current file name.
3637 \"basement::** Finished Tasks\"
3638 Archive in file ./basement (relative path), as level 3 trees
3639 below the level 2 heading \"** Finished Tasks\".
3641 You may set this option on a per-file basis by adding to the buffer a
3644 #+ARCHIVE: basement::** Finished Tasks
3646 You may also define it locally for a subtree by setting an ARCHIVE property
3647 in the entry. If such a property is found in an entry, or anywhere up
3648 the hierarchy, it will be used."
3652 (defcustom org-archive-tag
"ARCHIVE"
3653 "The tag that marks a subtree as archived.
3654 An archived subtree does not open during visibility cycling, and does
3655 not contribute to the agenda listings.
3656 After changing this, font-lock must be restarted in the relevant buffers to
3657 get the proper fontification."
3659 :group
'org-keywords
3662 (defcustom org-agenda-skip-archived-trees t
3663 "Non-nil means the agenda will skip any items located in archived trees.
3664 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3665 variable is no longer recommended, you should leave it at the value t.
3666 Instead, use the key `v' to cycle the archives-mode in the agenda."
3668 :group
'org-agenda-skip
3671 (defcustom org-columns-skip-archived-trees t
3672 "Non-nil means ignore archived trees when creating column view."
3674 :group
'org-properties
3677 (defcustom org-cycle-open-archived-trees nil
3678 "Non-nil means `org-cycle' will open archived trees.
3679 An archived tree is a tree marked with the tag ARCHIVE.
3680 When nil, archived trees will stay folded. You can still open them with
3681 normal outline commands like `show-all', but not with the cycling commands."
3686 (defcustom org-sparse-tree-open-archived-trees nil
3687 "Non-nil means sparse tree construction shows matches in archived trees.
3688 When nil, matches in these trees are highlighted, but the trees are kept in
3691 :group
'org-sparse-trees
3694 (defun org-cycle-hide-archived-subtrees (state)
3695 "Re-hide all archived subtrees after a visibility state change."
3696 (when (and (not org-cycle-open-archived-trees
)
3697 (not (memq state
'(overview folded
))))
3699 (let* ((globalp (memq state
'(contents all
)))
3700 (beg (if globalp
(point-min) (point)))
3701 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3702 (org-hide-archived-subtrees beg end
)
3704 (if (looking-at (concat ".*:" org-archive-tag
":"))
3705 (message "%s" (substitute-command-keys
3706 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3708 (defun org-force-cycle-archived ()
3709 "Cycle subtree even if it is archived."
3711 (setq this-command
'org-cycle
)
3712 (let ((org-cycle-open-archived-trees t
))
3713 (call-interactively 'org-cycle
)))
3715 (defun org-hide-archived-subtrees (beg end
)
3716 "Re-hide all archived subtrees after a visibility state change."
3718 (let* ((re (concat ":" org-archive-tag
":")))
3720 (while (re-search-forward re end t
)
3721 (when (org-on-heading-p)
3722 (org-flag-subtree t
)
3723 (org-end-of-subtree t
))))))
3725 (defun org-flag-subtree (flag)
3727 (org-back-to-heading t
)
3728 (outline-end-of-heading)
3729 (outline-flag-region (point)
3730 (progn (org-end-of-subtree t
) (point))
3733 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3736 (org-autoload "org-archive"
3737 '(org-add-archive-files org-archive-subtree
3738 org-archive-to-archive-sibling org-toggle-archive-tag
3739 org-archive-subtree-default
3740 org-archive-subtree-default-with-confirmation
)))
3742 ;; Autoload Column View Code
3744 (declare-function org-columns-number-to-string
"org-colview")
3745 (declare-function org-columns-get-format-and-top-level
"org-colview")
3746 (declare-function org-columns-compute
"org-colview")
3748 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3749 '(org-columns-number-to-string org-columns-get-format-and-top-level
3750 org-columns-compute org-agenda-columns org-columns-remove-overlays
3751 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3755 (declare-function org-id-store-link
"org-id")
3756 (declare-function org-id-locations-load
"org-id")
3757 (declare-function org-id-locations-save
"org-id")
3758 (defvar org-id-track-globally
)
3759 (org-autoload "org-id"
3760 '(org-id-get-create org-id-new org-id-copy org-id-get
3761 org-id-get-with-outline-path-completion
3762 org-id-get-with-outline-drilling
3763 org-id-goto org-id-find org-id-store-link
))
3765 ;; Autoload Plotting Code
3767 (org-autoload "org-plot"
3768 '(org-plot/gnuplot
))
3770 ;;; Variables for pre-computed regular expressions, all buffer local
3772 (defvar org-drawer-regexp nil
3773 "Matches first line of a hidden block.")
3774 (make-variable-buffer-local 'org-drawer-regexp
)
3775 (defvar org-todo-regexp nil
3776 "Matches any of the TODO state keywords.")
3777 (make-variable-buffer-local 'org-todo-regexp
)
3778 (defvar org-not-done-regexp nil
3779 "Matches any of the TODO state keywords except the last one.")
3780 (make-variable-buffer-local 'org-not-done-regexp
)
3781 (defvar org-not-done-heading-regexp nil
3782 "Matches a TODO headline that is not done.")
3783 (make-variable-buffer-local 'org-not-done-regexp
)
3784 (defvar org-todo-line-regexp nil
3785 "Matches a headline and puts TODO state into group 2 if present.")
3786 (make-variable-buffer-local 'org-todo-line-regexp
)
3787 (defvar org-complex-heading-regexp nil
3788 "Matches a headline and puts everything into groups:
3790 group 2: The todo keyword, maybe
3791 group 3: Priority cookie
3792 group 4: True headline
3794 (make-variable-buffer-local 'org-complex-heading-regexp
)
3795 (defvar org-complex-heading-regexp-format nil
)
3796 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
3797 (defvar org-todo-line-tags-regexp nil
3798 "Matches a headline and puts TODO state into group 2 if present.
3799 Also put tags into group 4 if tags are present.")
3800 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
3801 (defvar org-nl-done-regexp nil
3802 "Matches newline followed by a headline with the DONE keyword.")
3803 (make-variable-buffer-local 'org-nl-done-regexp
)
3804 (defvar org-looking-at-done-regexp nil
3805 "Matches the DONE keyword a point.")
3806 (make-variable-buffer-local 'org-looking-at-done-regexp
)
3807 (defvar org-ds-keyword-length
12
3808 "Maximum length of the Deadline and SCHEDULED keywords.")
3809 (make-variable-buffer-local 'org-ds-keyword-length
)
3810 (defvar org-deadline-regexp nil
3811 "Matches the DEADLINE keyword.")
3812 (make-variable-buffer-local 'org-deadline-regexp
)
3813 (defvar org-deadline-time-regexp nil
3814 "Matches the DEADLINE keyword together with a time stamp.")
3815 (make-variable-buffer-local 'org-deadline-time-regexp
)
3816 (defvar org-deadline-line-regexp nil
3817 "Matches the DEADLINE keyword and the rest of the line.")
3818 (make-variable-buffer-local 'org-deadline-line-regexp
)
3819 (defvar org-scheduled-regexp nil
3820 "Matches the SCHEDULED keyword.")
3821 (make-variable-buffer-local 'org-scheduled-regexp
)
3822 (defvar org-scheduled-time-regexp nil
3823 "Matches the SCHEDULED keyword together with a time stamp.")
3824 (make-variable-buffer-local 'org-scheduled-time-regexp
)
3825 (defvar org-closed-time-regexp nil
3826 "Matches the CLOSED keyword together with a time stamp.")
3827 (make-variable-buffer-local 'org-closed-time-regexp
)
3829 (defvar org-keyword-time-regexp nil
3830 "Matches any of the 4 keywords, together with the time stamp.")
3831 (make-variable-buffer-local 'org-keyword-time-regexp
)
3832 (defvar org-keyword-time-not-clock-regexp nil
3833 "Matches any of the 3 keywords, together with the time stamp.")
3834 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
3835 (defvar org-maybe-keyword-time-regexp nil
3836 "Matches a timestamp, possibly preceeded by a keyword.")
3837 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
3838 (defvar org-planning-or-clock-line-re nil
3839 "Matches a line with planning or clock info.")
3840 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
3841 (defvar org-all-time-keywords nil
3842 "List of time keywords.")
3843 (make-variable-buffer-local 'org-all-time-keywords
)
3845 (defconst org-plain-time-of-day-regexp
3848 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3851 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3853 "Regular expression to match a plain time or time range.
3854 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3855 groups carry important information:
3857 1 the first time, range or not
3858 8 the second time, if it is a range.")
3860 (defconst org-plain-time-extension-regexp
3863 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3864 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3865 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3866 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3867 groups carry important information:
3870 9 minutes of duration")
3872 (defconst org-stamp-time-of-day-regexp
3874 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3875 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3877 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3878 "Regular expression to match a timestamp time or time range.
3879 After a match, the following groups carry important information:
3881 1 date plus weekday, for back referencing to make sure both times are on the same day
3882 2 the first time, range or not
3883 4 the second time, if it is a range.")
3885 (defconst org-startup-options
3886 '(("fold" org-startup-folded t
)
3887 ("overview" org-startup-folded t
)
3888 ("nofold" org-startup-folded nil
)
3889 ("showall" org-startup-folded nil
)
3890 ("showeverything" org-startup-folded showeverything
)
3891 ("content" org-startup-folded content
)
3892 ("indent" org-startup-indented t
)
3893 ("noindent" org-startup-indented nil
)
3894 ("hidestars" org-hide-leading-stars t
)
3895 ("showstars" org-hide-leading-stars nil
)
3896 ("odd" org-odd-levels-only t
)
3897 ("oddeven" org-odd-levels-only nil
)
3898 ("align" org-startup-align-all-tables t
)
3899 ("noalign" org-startup-align-all-tables nil
)
3900 ("customtime" org-display-custom-times t
)
3901 ("logdone" org-log-done time
)
3902 ("lognotedone" org-log-done note
)
3903 ("nologdone" org-log-done nil
)
3904 ("lognoteclock-out" org-log-note-clock-out t
)
3905 ("nolognoteclock-out" org-log-note-clock-out nil
)
3906 ("logrepeat" org-log-repeat state
)
3907 ("lognoterepeat" org-log-repeat note
)
3908 ("nologrepeat" org-log-repeat nil
)
3909 ("logreschedule" org-log-reschedule time
)
3910 ("lognotereschedule" org-log-reschedule note
)
3911 ("nologreschedule" org-log-reschedule nil
)
3912 ("logredeadline" org-log-redeadline time
)
3913 ("lognoteredeadline" org-log-redeadline note
)
3914 ("nologredeadline" org-log-redeadline nil
)
3915 ("logrefile" org-log-refile time
)
3916 ("lognoterefile" org-log-refile note
)
3917 ("nologrefile" org-log-refile nil
)
3918 ("fninline" org-footnote-define-inline t
)
3919 ("nofninline" org-footnote-define-inline nil
)
3920 ("fnlocal" org-footnote-section nil
)
3921 ("fnauto" org-footnote-auto-label t
)
3922 ("fnprompt" org-footnote-auto-label nil
)
3923 ("fnconfirm" org-footnote-auto-label confirm
)
3924 ("fnplain" org-footnote-auto-label plain
)
3925 ("fnadjust" org-footnote-auto-adjust t
)
3926 ("nofnadjust" org-footnote-auto-adjust nil
)
3927 ("constcgs" constants-unit-system cgs
)
3928 ("constSI" constants-unit-system SI
)
3929 ("noptag" org-tag-persistent-alist nil
)
3930 ("hideblocks" org-hide-block-startup t
)
3931 ("nohideblocks" org-hide-block-startup nil
)
3932 ("beamer" org-startup-with-beamer-mode t
))
3933 "Variable associated with STARTUP options for org-mode.
3934 Each element is a list of three items: The startup options as written
3935 in the #+STARTUP line, the corresponding variable, and the value to
3936 set this variable to if the option is found. An optional forth element PUSH
3937 means to push this value onto the list in the variable.")
3939 (defun org-set-regexps-and-options ()
3940 "Precompute regular expressions for current buffer."
3942 (org-set-local 'org-todo-kwd-alist nil
)
3943 (org-set-local 'org-todo-key-alist nil
)
3944 (org-set-local 'org-todo-key-trigger nil
)
3945 (org-set-local 'org-todo-keywords-1 nil
)
3946 (org-set-local 'org-done-keywords nil
)
3947 (org-set-local 'org-todo-heads nil
)
3948 (org-set-local 'org-todo-sets nil
)
3949 (org-set-local 'org-todo-log-states nil
)
3950 (org-set-local 'org-file-properties nil
)
3951 (org-set-local 'org-file-tags nil
)
3952 (let ((re (org-make-options-regexp
3953 '("CATEGORY" "TODO" "COLUMNS"
3954 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
3955 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS")
3956 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
3958 kwds kws0 kwsa key log value cat arch tags const links hw dws
3959 tail sep kws1 prio props ftags drawers beamer-p
3960 ext-setup-or-nil setup-contents
(start 0))
3964 (goto-char (point-min))
3965 (while (or (and ext-setup-or-nil
3966 (string-match re ext-setup-or-nil start
)
3967 (setq start
(match-end 0)))
3968 (and (setq ext-setup-or-nil nil start
0)
3969 (re-search-forward re nil t
)))
3970 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
3971 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
3973 ((equal key
"CATEGORY")
3974 (if (string-match "[ \t]+$" value
)
3975 (setq value
(replace-match "" t t value
)))
3977 ((member key
'("SEQ_TODO" "TODO"))
3978 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
3979 ((equal key
"TYP_TODO")
3980 (push (cons 'type
(org-split-string value splitre
)) kwds
))
3981 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
3982 ;; general TODO-like setup
3983 (push (cons (intern (downcase (match-string 1 key
)))
3984 (org-split-string value splitre
)) kwds
))
3986 (setq tags
(append tags
(if tags
'("\\n") nil
)
3987 (org-split-string value splitre
))))
3988 ((equal key
"COLUMNS")
3989 (org-set-local 'org-columns-default-format value
))
3991 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
3992 (push (cons (match-string 1 value
)
3993 (org-trim (match-string 2 value
)))
3995 ((equal key
"PRIORITIES")
3996 (setq prio
(org-split-string value
" +")))
3997 ((equal key
"PROPERTY")
3998 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
3999 (push (cons (match-string 1 value
) (match-string 2 value
))
4001 ((equal key
"FILETAGS")
4002 (when (string-match "\\S-" value
)
4007 (mapcar (lambda (x) (org-split-string x
":"))
4008 (org-split-string value
)))))))
4009 ((equal key
"DRAWERS")
4010 (setq drawers
(org-split-string value splitre
)))
4011 ((equal key
"CONSTANTS")
4012 (setq const
(append const
(org-split-string value splitre
))))
4013 ((equal key
"STARTUP")
4014 (let ((opts (org-split-string value splitre
))
4016 (while (setq l
(pop opts
))
4017 (when (setq l
(assoc l org-startup-options
))
4018 (setq var
(nth 1 l
) val
(nth 2 l
))
4020 (set (make-local-variable var
) val
)
4021 (if (not (listp (symbol-value var
)))
4022 (set (make-local-variable var
) nil
))
4023 (set (make-local-variable var
) (symbol-value var
))
4024 (add-to-list var val
))))))
4025 ((equal key
"ARCHIVE")
4026 (string-match " *$" value
)
4027 (setq arch
(replace-match "" t t value
))
4028 (remove-text-properties 0 (length arch
)
4029 '(face t fontified t
) arch
))
4030 ((equal key
"LATEX_CLASS")
4031 (setq beamer-p
(equal value
"beamer")))
4032 ((equal key
"SETUPFILE")
4033 (setq setup-contents
(org-file-contents
4035 (org-remove-double-quotes value
))
4037 (if (not ext-setup-or-nil
)
4038 (setq ext-setup-or-nil setup-contents start
0)
4039 (setq ext-setup-or-nil
4040 (concat (substring ext-setup-or-nil
0 start
)
4041 "\n" setup-contents
"\n"
4042 (substring ext-setup-or-nil start
)))))
4045 (org-set-local 'org-category
(intern cat
))
4046 (push (cons "CATEGORY" cat
) props
))
4048 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4049 (setq prio
(mapcar 'string-to-char prio
))
4050 (org-set-local 'org-highest-priority
(nth 0 prio
))
4051 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4052 (org-set-local 'org-default-priority
(nth 2 prio
)))
4053 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4054 (and ftags
(org-set-local 'org-file-tags
4055 (mapcar 'org-add-prop-inherited ftags
)))
4056 (and drawers
(org-set-local 'org-drawers drawers
))
4057 (and arch
(org-set-local 'org-archive-location arch
))
4058 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4059 ;; Process the TODO keywords
4061 ;; Use the global values as if they had been given locally.
4062 (setq kwds
(default-value 'org-todo-keywords
))
4063 (if (stringp (car kwds
))
4064 (setq kwds
(list (cons org-todo-interpretation
4065 (default-value 'org-todo-keywords
)))))
4066 (setq kwds
(reverse kwds
)))
4067 (setq kwds
(nreverse kwds
))
4069 (while (setq kws
(pop kwds
))
4071 (run-hook-with-args-until-success
4072 'org-todo-setup-filter-hook kws
)
4074 (setq inter
(pop kws
) sep
(member "|" kws
)
4075 kws0
(delete "|" (copy-sequence kws
))
4080 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4082 (setq kw
(match-string 1 x
)
4083 key
(and (match-end 2) (match-string 2 x
))
4084 log
(org-extract-log-state-settings x
))
4085 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4086 (and log
(push log org-todo-log-states
))
4088 (error "Invalid TODO keyword %s" x
)))
4090 kwsa
(if kwsa
(append '((:startgroup
))
4094 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4095 tail
(list inter hw
(car dws
) (org-last dws
))))
4096 (add-to-list 'org-todo-heads hw
'append
)
4097 (push kws1 org-todo-sets
)
4098 (setq org-done-keywords
(append org-done-keywords dws nil
))
4099 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4100 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4101 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4102 (setq org-todo-sets
(nreverse org-todo-sets
)
4103 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4104 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4105 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4106 ;; Process the constants
4109 (while (setq e
(pop const
))
4110 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4111 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4112 (setq org-table-formula-constants-local cst
)))
4114 ;; Process the tags.
4117 (while (setq e
(pop tags
))
4119 ((equal e
"{") (push '(:startgroup
) tgs
))
4120 ((equal e
"}") (push '(:endgroup
) tgs
))
4121 ((equal e
"\\n") (push '(:newline
) tgs
))
4122 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4123 (push (cons (match-string 1 e
)
4124 (string-to-char (match-string 2 e
)))
4126 (t (push (list e
) tgs
))))
4127 (org-set-local 'org-tag-alist nil
)
4128 (while (setq e
(pop tgs
))
4129 (or (and (stringp (car e
))
4130 (assoc (car e
) org-tag-alist
))
4131 (push e org-tag-alist
)))))
4133 ;; Compute the regular expressions and other local variables
4134 (if (not org-done-keywords
)
4135 (setq org-done-keywords
(and org-todo-keywords-1
4136 (list (org-last org-todo-keywords-1
)))))
4137 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4138 (length org-scheduled-string
)
4139 (length org-clock-string
)
4140 (length org-closed-string
)))
4142 (concat "^[ \t]*:\\("
4143 (mapconcat 'regexp-quote org-drawers
"\\|")
4145 org-not-done-keywords
4146 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4148 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4152 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4154 org-not-done-heading-regexp
4155 (concat "^\\(\\*+\\)[ \t]+\\("
4156 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4158 org-todo-line-regexp
4159 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4160 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4161 "\\)\\>\\)?[ \t]*\\(.*\\)")
4162 org-complex-heading-regexp
4163 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4164 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4165 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4166 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4167 org-complex-heading-regexp-format
4168 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4169 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4170 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(%s\\)"
4171 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4173 (concat "\n\\*+[ \t]+"
4174 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4176 org-todo-line-tags-regexp
4177 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4178 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4180 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4181 org-looking-at-done-regexp
4183 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4185 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4186 org-deadline-time-regexp
4187 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4188 org-deadline-line-regexp
4189 (concat "\\<\\(" org-deadline-string
"\\).*")
4190 org-scheduled-regexp
4191 (concat "\\<" org-scheduled-string
)
4192 org-scheduled-time-regexp
4193 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4194 org-closed-time-regexp
4195 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4196 org-keyword-time-regexp
4197 (concat "\\<\\(" org-scheduled-string
4198 "\\|" org-deadline-string
4199 "\\|" org-closed-string
4200 "\\|" org-clock-string
"\\)"
4201 " *[[<]\\([^]>]+\\)[]>]")
4202 org-keyword-time-not-clock-regexp
4203 (concat "\\<\\(" org-scheduled-string
4204 "\\|" org-deadline-string
4205 "\\|" org-closed-string
4207 " *[[<]\\([^]>]+\\)[]>]")
4208 org-maybe-keyword-time-regexp
4209 (concat "\\(\\<\\(" org-scheduled-string
4210 "\\|" org-deadline-string
4211 "\\|" org-closed-string
4212 "\\|" org-clock-string
"\\)\\)?"
4213 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4214 org-planning-or-clock-line-re
4215 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4216 "\\|" org-deadline-string
4217 "\\|" org-closed-string
"\\|" org-clock-string
4219 org-all-time-keywords
4220 (mapcar (lambda (w) (substring w
0 -
1))
4221 (list org-scheduled-string org-deadline-string
4222 org-clock-string org-closed-string
))
4224 (org-compute-latex-and-specials-regexp)
4225 (org-set-font-lock-defaults))))
4227 (defun org-file-contents (file &optional noerror
)
4228 "Return the contents of FILE, as a string."
4230 (not (file-readable-p file
)))
4233 (message "Cannot read file %s" file
)
4236 (error "Cannot read file %s" file
))
4238 (insert-file-contents file
)
4241 (defun org-extract-log-state-settings (x)
4242 "Extract the log state setting from a TODO keyword string.
4243 This will extract info from a string like \"WAIT(w@/!)\"."
4244 (let (kw key log1 log2
)
4245 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4246 (setq kw
(match-string 1 x
)
4247 key
(and (match-end 2) (match-string 2 x
))
4248 log1
(and (match-end 3) (match-string 3 x
))
4249 log2
(and (match-end 4) (match-string 4 x
)))
4252 (and log1
(if (equal log1
"!") 'time
'note
))
4253 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4255 (defun org-remove-keyword-keys (list)
4256 "Remove a pair of parenthesis at the end of each string in LIST."
4258 (if (string-match "(.*)$" x
)
4259 (substring x
0 (match-beginning 0))
4263 (defun org-assign-fast-keys (alist)
4264 "Assign fast keys to a keyword-key alist.
4265 Respect keys that are already there."
4266 (let (new e
(alt ?
0))
4267 (while (setq e
(pop alist
))
4268 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4269 (cdr e
)) ;; Key already assigned.
4271 (let ((clist (string-to-list (downcase (car e
))))
4272 (used (append new alist
)))
4273 (when (= (car clist
) ?
@)
4275 (while (and clist
(rassoc (car clist
) used
))
4278 (while (rassoc alt used
)
4280 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4283 ;;; Some variables used in various places
4285 (defvar org-window-configuration nil
4286 "Used in various places to store a window configuration.")
4287 (defvar org-selected-window nil
4288 "Used in various places to store a window configuration.")
4289 (defvar org-finish-function nil
4290 "Function to be called when `C-c C-c' is used.
4291 This is for getting out of special buffers like remember.")
4294 ;; FIXME: Occasionally check by commenting these, to make sure
4295 ;; no other functions uses these, forgetting to let-bind them.
4300 ;; Defined somewhere in this file, but used before definition.
4301 (defvar org-entities
) ;; defined in org-entities.el
4302 (defvar org-struct-menu
)
4303 (defvar org-org-menu
)
4304 (defvar org-tbl-menu
)
4306 ;;;; Define the Org-mode
4308 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4309 (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."))
4312 ;; We use a before-change function to check if a table might need
4314 (defvar org-table-may-need-update t
4315 "Indicates that a table might need an update.
4316 This variable is set by `org-before-change-function'.
4317 `org-table-align' sets it back to nil.")
4318 (defun org-before-change-function (beg end
)
4319 "Every change indicates that a table might need an update."
4320 (setq org-table-may-need-update t
))
4321 (defvar org-mode-map
)
4322 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4323 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4324 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4325 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4326 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4327 (defvar org-table-buffer-is-an nil
)
4328 (defconst org-outline-regexp
"\\*+ ")
4331 (define-derived-mode org-mode outline-mode
"Org"
4332 "Outline-based notes management and organizer, alias
4333 \"Carsten's outline-mode for keeping track of everything.\"
4335 Org-mode develops organizational tasks around a NOTES file which
4336 contains information about projects as plain text. Org-mode is
4337 implemented on top of outline-mode, which is ideal to keep the content
4338 of large files well structured. It supports ToDo items, deadlines and
4339 time stamps, which magically appear in the diary listing of the Emacs
4340 calendar. Tables are easily created with a built-in table editor.
4341 Plain text URL-like links connect to websites, emails (VM), Usenet
4342 messages (Gnus), BBDB entries, and any files related to the project.
4343 For printing and sharing of notes, an Org-mode file (or a part of it)
4344 can be exported as a structured ASCII or HTML file.
4346 The following commands are available:
4350 ;; Get rid of Outline menus, they are not needed
4351 ;; Need to do this here because define-derived-mode sets up
4352 ;; the keymap so late. Still, it is a waste to call this each time
4353 ;; we switch another buffer into org-mode.
4354 (if (featurep 'xemacs
)
4355 (when (boundp 'outline-mode-menu-heading
)
4356 ;; Assume this is Greg's port, it used easymenu
4357 (easy-menu-remove outline-mode-menu-heading
)
4358 (easy-menu-remove outline-mode-menu-show
)
4359 (easy-menu-remove outline-mode-menu-hide
))
4360 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4361 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4362 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4364 (org-load-modules-maybe)
4365 (easy-menu-add org-org-menu
)
4366 (easy-menu-add org-tbl-menu
)
4367 (org-install-agenda-files-menu)
4368 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4369 (add-to-invisibility-spec '(org-cwidth))
4370 (add-to-invisibility-spec '(org-hide-block . t
))
4371 (when (featurep 'xemacs
)
4372 (org-set-local 'line-move-ignore-invisible t
))
4373 (org-set-local 'outline-regexp org-outline-regexp
)
4374 (org-set-local 'outline-level
'org-outline-level
)
4375 (when (and org-ellipsis
4376 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4377 (fboundp 'make-glyph-code
))
4378 (unless org-display-table
4379 (setq org-display-table
(make-display-table)))
4380 (set-display-table-slot
4383 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4385 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4386 (setq buffer-display-table org-display-table
))
4387 (org-set-regexps-and-options)
4388 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4389 ;; tag faces set outside customize.... force initialization.
4390 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4392 (org-set-local 'calc-embedded-open-mode
"# ")
4393 (modify-syntax-entry ?
# "<")
4394 (modify-syntax-entry ?
@ "w")
4395 (if org-startup-truncated
(setq truncate-lines t
))
4396 (org-set-local 'font-lock-unfontify-region-function
4397 'org-unfontify-region
)
4398 ;; Activate before-change-function
4399 (org-set-local 'org-table-may-need-update t
)
4400 (org-add-hook 'before-change-functions
'org-before-change-function nil
4402 ;; Check for running clock before killing a buffer
4403 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4404 ;; Paragraphs and auto-filling
4405 (org-set-autofill-regexps)
4406 (setq indent-line-function
'org-indent-line-function
)
4407 (org-update-radio-target-regexp)
4408 ;; Make sure dependence stuff works reliably, even for users who set it
4410 (if org-enforce-todo-dependencies
4411 (add-hook 'org-blocker-hook
4412 'org-block-todo-from-children-or-siblings-or-parent
)
4413 (remove-hook 'org-blocker-hook
4414 'org-block-todo-from-children-or-siblings-or-parent
))
4415 (if org-enforce-todo-checkbox-dependencies
4416 (add-hook 'org-blocker-hook
4417 'org-block-todo-from-checkboxes
)
4418 (remove-hook 'org-blocker-hook
4419 'org-block-todo-from-checkboxes
))
4421 ;; Comment characters
4422 ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
4423 (org-set-local 'comment-padding
" ")
4425 ;; Align options lines
4427 'align-mode-rules-list
4428 '((org-in-buffer-settings
4429 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4430 (modes .
'(org-mode)))))
4433 (org-set-local 'imenu-create-index-function
4434 'org-imenu-get-tree
)
4436 ;; Make isearch reveal context
4437 (if (or (featurep 'xemacs
)
4438 (not (boundp 'outline-isearch-open-invisible-function
)))
4439 ;; Emacs 21 and XEmacs make use of the hook
4440 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4441 ;; Emacs 22 deals with this through a special variable
4442 (org-set-local 'outline-isearch-open-invisible-function
4443 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4445 ;; Turn on org-beamer-mode?
4446 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4448 ;; If empty file that did not turn on org-mode automatically, make it to.
4449 (if (and org-insert-mode-line-in-empty-file
4451 (= (point-min) (point-max)))
4452 (insert "# -*- mode: org -*-\n\n"))
4453 (unless org-inhibit-startup
4454 (when org-startup-align-all-tables
4455 (let ((bmp (buffer-modified-p)))
4456 (org-table-map-tables 'org-table-align
)
4457 (set-buffer-modified-p bmp
)))
4458 (when org-startup-indented
4459 (require 'org-indent
)
4460 (org-indent-mode 1))
4461 (unless org-inhibit-startup-visibility-stuff
4462 (org-set-startup-visibility))))
4464 (when (fboundp 'abbrev-table-put
)
4465 (abbrev-table-put org-mode-abbrev-table
4466 :parents
(list text-mode-abbrev-table
)))
4468 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4470 (defun org-current-time ()
4471 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4472 (if (> (car org-time-stamp-rounding-minutes
) 1)
4473 (let ((r (car org-time-stamp-rounding-minutes
))
4474 (time (decode-time)))
4476 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4480 ;;;; Font-Lock stuff, including the activators
4482 (defvar org-mouse-map
(make-sparse-keymap))
4483 (org-defkey org-mouse-map
4484 (if (featurep 'xemacs
) [button2] [mouse-2]) 'org-open-at-mouse)
4485 (org-defkey org-mouse-map
4486 (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
4487 (when org-mouse-1-follows-link
4488 (org-defkey org-mouse-map [follow-link] 'mouse-face))
4489 (when org-tab-follows-link
4490 (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
4491 (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
4493 (require 'font-lock)
4495 (defconst org-non-link-chars "]\t\n\r<>")
4496 (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
4498 (defvar org-link-types-re nil
4499 "Matches a link that has a url-like prefix like \"http:\"")
4500 (defvar org-link-re-with-space nil
4501 "Matches a link with spaces, optional angular brackets around it.")
4502 (defvar org-link-re-with-space2 nil
4503 "Matches a link with spaces, optional angular brackets around it.")
4504 (defvar org-link-re-with-space3 nil
4505 "Matches a link with spaces, only for internal part in bracket links.")
4506 (defvar org-angle-link-re nil
4507 "Matches link with angular brackets, spaces are allowed.")
4508 (defvar org-plain-link-re nil
4509 "Matches plain link, without spaces.")
4510 (defvar org-bracket-link-regexp nil
4511 "Matches a link in double brackets.")
4512 (defvar org-bracket-link-analytic-regexp nil
4513 "Regular expression used to analyze links.
4514 Here is what the match groups contain after a match:
4520 (defvar org-bracket-link-analytic-regexp++ nil
4521 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4522 (defvar org-any-link-re nil
4523 "Regular expression matching any link.")
4525 (defun org-make-link-regexps ()
4526 "Update the link regular expressions.
4527 This should be called after the variable `org-link-types' has changed."
4528 (setq org-link-types-re
4530 "\\`\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):")
4531 org-link-re-with-space
4533 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4534 "\\([^" org-non-link-chars " ]"
4535 "[^" org-non-link-chars "]*"
4536 "[^" org-non-link-chars " ]\\)>?")
4537 org-link-re-with-space2
4539 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4540 "\\([^" org-non-link-chars " ]"
4542 "[^" org-non-link-chars " ]\\)>?")
4543 org-link-re-with-space3
4545 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4546 "\\([^" org-non-link-chars " ]"
4550 "<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4551 "\\([^" org-non-link-chars " ]"
4552 "[^" org-non-link-chars "]*"
4556 "\\<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
4557 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4558 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4559 org-bracket-link-regexp
4560 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4561 org-bracket-link-analytic-regexp
4564 "\\(\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):\\)?"
4567 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4569 org-bracket-link-analytic-regexp++
4572 "\\(\\(" (mapconcat 'regexp-quote (cons "coderef" org-link-types) "\\|") "\\):\\)?"
4575 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4578 (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
4579 org-angle-link-re "\\)\\|\\("
4580 org-plain-link-re "\\)")))
4582 (org-make-link-regexps)
4584 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4585 "Regular expression for fast time stamp matching.")
4586 (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4587 "Regular expression for fast time stamp matching.")
4588 (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4589 "Regular expression matching time strings for analysis.
4590 This one does not require the space after the date, so it can be used
4591 on a string that terminates immediately after the date.")
4592 (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4593 "Regular expression matching time strings for analysis.")
4594 (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
4595 "Regular expression matching time stamps, with groups.")
4596 (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
4597 "Regular expression matching time stamps (also [..]), with groups.")
4598 (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
4599 "Regular expression matching a time stamp range.")
4600 (defconst org-tr-regexp-both
4601 (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
4602 "Regular expression matching a time stamp range.")
4603 (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
4604 org-ts-regexp "\\)?")
4605 "Regular expression matching a time stamp or time stamp range.")
4606 (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
4607 org-ts-regexp-both "\\)?")
4608 "Regular expression matching a time stamp or time stamp range.
4609 The time stamps may be either active or inactive.")
4611 (defvar org-emph-face nil)
4613 (defun org-do-emphasis-faces (limit)
4614 "Run through the buffer and add overlays to links."
4616 (while (and (not rtn) (re-search-forward org-emph-re limit t))
4617 (if (not (= (char-after (match-beginning 3))
4618 (char-after (match-beginning 4))))
4621 (setq a (assoc (match-string 3) org-emphasis-alist))
4622 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4626 (org-remove-flyspell-overlays-in
4627 (match-beginning 0) (match-end 0)))
4628 (add-text-properties (match-beginning 2) (match-end 2)
4629 '(font-lock-multiline t))
4630 (when org-hide-emphasis-markers
4631 (add-text-properties (match-end 4) (match-beginning 5)
4632 '(invisible org-link))
4633 (add-text-properties (match-beginning 3) (match-end 3)
4634 '(invisible org-link)))))
4638 (defun org-emphasize (&optional char)
4639 "Insert or change an emphasis, i.e. a font like bold or italic.
4640 If there is an active region, change that region to a new emphasis.
4641 If there is no region, just insert the marker characters and position
4642 the cursor between them.
4643 CHAR should be either the marker character, or the first character of the
4644 HTML tag associated with that emphasis. If CHAR is a space, the means
4645 to remove the emphasis of the selected region.
4646 If char is not given (for example in an interactive call) it
4647 will be prompted for."
4649 (let ((eal org-emphasis-alist) e det
4650 (erc org-emphasis-regexp-components)
4652 (string "") beg end move tag c s)
4653 (if (org-region-active-p)
4654 (setq beg (region-beginning) end (region-end)
4655 string (buffer-substring beg end))
4658 (while (setq e (pop eal))
4659 (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
4661 (push (cons c (string-to-char (car e))) det)
4662 (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
4663 (substring tag 1)))))
4664 (setq det (nreverse det))
4666 (message "%s" (concat "Emphasis marker or tag:" prompt))
4667 (setq char (read-char-exclusive)))
4668 (setq char (or (cdr (assoc char det)) char))
4669 (if (equal char ?\ )
4670 (setq s "" move nil)
4671 (unless (assoc (char-to-string char) org-emphasis-alist)
4672 (error "No such emphasis marker: \"%c\"" char))
4673 (setq s (char-to-string char)))
4674 (while (and (> (length string) 1)
4675 (equal (substring string 0 1) (substring string -1))
4676 (assoc (substring string 0 1) org-emphasis-alist))
4677 (setq string (substring string 1 -1)))
4678 (setq string (concat s string s))
4679 (if beg (delete-region beg end))
4681 (string-match (concat "[" (nth 0 erc) "\n]")
4682 (char-to-string (char-before (point)))))
4685 (string-match (concat "[" (nth 1 erc) "\n]")
4686 (char-to-string (char-after (point)))))
4687 (insert " ") (backward-char 1))
4689 (and move (backward-char 1))))
4691 (defconst org-nonsticky-props
4692 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
4694 (defsubst org-rear-nonsticky-at (pos)
4695 (add-text-properties (1- pos) pos (list 'rear-nonsticky org-nonsticky-props)))
4697 (defun org-activate-plain-links (limit)
4698 "Run through the buffer and add overlays to links."
4701 (if (re-search-forward org-plain-link-re limit t)
4703 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4704 (setq f (get-text-property (match-beginning 0) 'face))
4705 (if (or (eq f 'org-tag)
4706 (and (listp f) (memq 'org-tag f)))
4708 (add-text-properties (match-beginning 0) (match-end 0)
4709 (list 'mouse-face 'highlight
4711 'keymap org-mouse-map))
4712 (org-rear-nonsticky-at (match-end 0)))
4715 (defun org-activate-code (limit)
4716 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
4718 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4719 (remove-text-properties (match-beginning 0) (match-end 0)
4720 '(display t invisible t intangible t))
4723 (defun org-fontify-meta-lines-and-blocks (limit)
4724 "Fontify #+ lines and blocks, in the correct ways."
4725 (let ((case-fold-search t))
4726 (if (re-search-forward
4727 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
4729 (let ((beg (match-beginning 0))
4730 (beg1 (line-beginning-position 2))
4731 (dc1 (downcase (match-string 2)))
4732 (dc3 (downcase (match-string 3)))
4733 end end1 quoting block-type)
4735 ((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
4736 ;; a single line of backend-specific content
4737 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4738 (remove-text-properties (match-beginning 0) (match-end 0)
4739 '(display t invisible t intangible t))
4740 (add-text-properties (match-beginning 1) (match-end 3)
4741 '(font-lock-fontified t face org-meta-line))
4742 (add-text-properties (match-beginning 6) (match-end 6)
4743 '(font-lock-fontified t face org-block))
4745 ((and (match-end 4) (equal dc3 "begin"))
4747 (setq block-type (downcase (match-string 5))
4748 quoting (member block-type org-protecting-blocks))
4749 (when (re-search-forward
4750 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
4751 nil t) ;; on purpose, we look further than LIMIT
4752 (setq end (match-end 0) end1 (1- (match-beginning 0)))
4754 (remove-text-properties beg end
4755 '(display t invisible t intangible t)))
4756 (add-text-properties
4758 '(font-lock-fontified t font-lock-multiline t))
4759 (add-text-properties beg beg1 '(face org-meta-line))
4760 (add-text-properties end1 end '(face org-meta-line))
4763 (add-text-properties beg1 end1 '(face org-block)))
4764 ((not org-fontify-quote-and-verse-blocks))
4765 ((string= block-type "quote")
4766 (add-text-properties beg1 end1 '(face org-quote)))
4767 ((string= block-type "verse")
4768 (add-text-properties beg1 end1 '(face org-verse))))
4770 ((member dc1 '("title:" "author:" "email:" "date:"))
4771 (add-text-properties
4773 (if (member (intern (substring dc1 0 -1)) org-hidden-keywords)
4774 '(font-lock-fontified t invisible t)
4775 '(font-lock-fontified t face org-document-info-keyword)))
4776 (add-text-properties
4777 (match-beginning 6) (match-end 6)
4778 (if (string-equal dc1 "title:")
4779 '(font-lock-fontified t face org-document-title)
4780 '(font-lock-fontified t face org-document-info))))
4781 ((not (member (char-after beg) '(?\ ?\t)))
4782 ;; just any other in-buffer setting, but not indented
4783 (add-text-properties
4785 '(font-lock-fontified t face org-meta-line))
4787 ((or (member dc1 '("begin:" "end:" "caption:" "label:"
4788 "orgtbl:" "tblfm:" "tblname:"))
4789 (and (match-end 4) (equal dc3 "attr")))
4790 (add-text-properties
4792 '(font-lock-fontified t face org-meta-line))
4794 ((member dc3 '(" " ""))
4795 (add-text-properties
4797 '(font-lock-fontified t face font-lock-comment-face)))
4800 (defun org-activate-angle-links (limit)
4801 "Run through the buffer and add overlays to links."
4802 (if (re-search-forward org-angle-link-re limit t)
4804 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4805 (add-text-properties (match-beginning 0) (match-end 0)
4806 (list 'mouse-face 'highlight
4807 'keymap org-mouse-map))
4808 (org-rear-nonsticky-at (match-end 0))
4811 (defun org-activate-footnote-links (limit)
4812 "Run through the buffer and add overlays to links."
4813 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
4816 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4817 (add-text-properties (match-beginning 2) (match-end 2)
4818 (list 'mouse-face 'highlight
4819 'keymap org-mouse-map
4821 (if (= (point-at-bol) (match-beginning 2))
4822 "Footnote definition"
4823 "Footnote reference")
4825 (org-rear-nonsticky-at (match-end 2))
4828 (defun org-activate-bracket-links (limit)
4829 "Run through the buffer and add overlays to bracketed links."
4830 (if (re-search-forward org-bracket-link-regexp limit t)
4831 (let* ((help (concat "LINK: "
4832 (org-match-string-no-properties 1)))
4833 ;; FIXME: above we should remove the escapes.
4834 ;; but that requires another match, protecting match data,
4835 ;; a lot of overhead for font-lock.
4836 (ip (org-maybe-intangible
4837 (list 'invisible 'org-link
4838 'keymap org-mouse-map 'mouse-face 'highlight
4839 'font-lock-multiline t 'help-echo help)))
4840 (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
4841 'font-lock-multiline t 'help-echo help)))
4842 ;; We need to remove the invisible property here. Table narrowing
4843 ;; may have made some of this invisible.
4844 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4845 (remove-text-properties (match-beginning 0) (match-end 0)
4849 (add-text-properties (match-beginning 0) (match-beginning 3) ip)
4850 (org-rear-nonsticky-at (match-beginning 3))
4851 (add-text-properties (match-beginning 3) (match-end 3) vp)
4852 (org-rear-nonsticky-at (match-end 3))
4853 (add-text-properties (match-end 3) (match-end 0) ip)
4854 (org-rear-nonsticky-at (match-end 0)))
4855 (add-text-properties (match-beginning 0) (match-beginning 1) ip)
4856 (org-rear-nonsticky-at (match-beginning 1))
4857 (add-text-properties (match-beginning 1) (match-end 1) vp)
4858 (org-rear-nonsticky-at (match-end 1))
4859 (add-text-properties (match-end 1) (match-end 0) ip)
4860 (org-rear-nonsticky-at (match-end 0)))
4863 (defun org-activate-dates (limit)
4864 "Run through the buffer and add overlays to dates."
4865 (if (re-search-forward org-tsr-regexp-both limit t)
4867 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4868 (add-text-properties (match-beginning 0) (match-end 0)
4869 (list 'mouse-face 'highlight
4870 'keymap org-mouse-map))
4871 (org-rear-nonsticky-at (match-end 0))
4872 (when org-display-custom-times
4874 (org-display-custom-time (match-beginning 3) (match-end 3)))
4875 (org-display-custom-time (match-beginning 1) (match-end 1)))
4878 (defvar org-target-link-regexp nil
4879 "Regular expression matching radio targets in plain text.")
4880 (make-variable-buffer-local 'org-target-link-regexp)
4881 (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
4882 "Regular expression matching a link target.")
4883 (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
4884 "Regular expression matching a radio target.")
4885 (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
4886 "Regular expression matching any target.")
4888 (defun org-activate-target-links (limit)
4889 "Run through the buffer and add overlays to target matches."
4890 (when org-target-link-regexp
4891 (let ((case-fold-search t))
4892 (if (re-search-forward org-target-link-regexp limit t)
4894 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4895 (add-text-properties (match-beginning 0) (match-end 0)
4896 (list 'mouse-face 'highlight
4897 'keymap org-mouse-map
4898 'help-echo "Radio target link"
4899 'org-linked-text t))
4900 (org-rear-nonsticky-at (match-end 0))
4903 (defun org-update-radio-target-regexp ()
4904 "Find all radio targets in this file and update the regular expression."
4906 (when (memq 'radio org-activate-links)
4907 (setq org-target-link-regexp
4908 (org-make-target-link-regexp (org-all-targets 'radio)))
4909 (org-restart-font-lock)))
4911 (defun org-hide-wide-columns (limit)
4913 (setq s (text-property-any (point) (or limit (point-max))
4916 (setq e (next-single-property-change s 'org-cwidth))
4917 (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
4921 (defvar org-latex-and-specials-regexp nil
4922 "Regular expression for highlighting export special stuff.")
4923 (defvar org-match-substring-regexp)
4924 (defvar org-match-substring-with-braces-regexp)
4926 ;; This should be with the exporter code, but we also use if for font-locking
4927 (defconst org-export-html-special-string-regexps
4928 '(("\\\\-" . "­")
4929 ("---\\([^-]\\)" . "—\\1")
4930 ("--\\([^-]\\)" . "–\\1")
4931 ("\\.\\.\\." . "…"))
4932 "Regular expressions for special string conversion.")
4935 (defun org-compute-latex-and-specials-regexp ()
4936 "Compute regular expression for stuff treated specially by exporters."
4937 (if (not org-highlight-latex-fragments-and-specials)
4938 (org-set-local 'org-latex-and-specials-regexp nil)
4941 ((matchers (plist-get org-format-latex-options :matchers))
4942 (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
4943 org-latex-regexps)))
4944 (org-export-allow-BIND nil)
4945 (options (org-combine-plists (org-default-export-plist)
4946 (org-infile-export-plist)))
4947 (org-export-with-sub-superscripts (plist-get options :sub-superscript))
4948 (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
4949 (org-export-with-TeX-macros (plist-get options :TeX-macros))
4950 (org-export-html-expand (plist-get options :expand-quoted-html))
4951 (org-export-with-special-strings (plist-get options :special-strings))
4954 ((equal org-export-with-sub-superscripts '{})
4955 (list org-match-substring-with-braces-regexp))
4956 (org-export-with-sub-superscripts
4957 (list org-match-substring-regexp))
4960 (if org-export-with-LaTeX-fragments
4961 (mapcar (lambda (x) (nth 1 x)) latexs)))
4963 (if org-export-with-TeX-macros
4964 (list (concat "\\\\"
4966 (append (mapcar 'car (append org-entities-user
4968 (if (boundp 'org-latex-entities)
4970 (or (car-safe x) x))
4975 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
4976 (re-special (if org-export-with-special-strings
4977 (mapcar (lambda (x) (car x))
4978 org-export-html-special-string-regexps)))
4982 (if org-export-html-expand "@<[^>\n]+>")
4985 'org-latex-and-specials-regexp
4986 (mapconcat 'identity (append re-latex re-sub re-macros re-special
4989 (defun org-do-latex-and-special-faces (limit)
4990 "Run through the buffer and add overlays to links."
4991 (when org-latex-and-specials-regexp
4993 (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
4995 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
4997 '(org-code org-verbatim underline)))
5000 d (cond ((member (char-after (1+ (match-beginning 0)))
5003 (font-lock-prepend-text-property
5004 (+ d (match-beginning 0)) (match-end 0)
5005 'face 'org-latex-and-export-specials)
5006 (add-text-properties (+ d (match-beginning 0)) (match-end 0)
5007 '(font-lock-multiline t)))))
5010 (defun org-restart-font-lock ()
5011 "Restart font-lock-mode, to force refontification."
5012 (when (and (boundp 'font-lock-mode) font-lock-mode)
5014 (font-lock-mode 1)))
5016 (defun org-all-targets (&optional radio)
5017 "Return a list of all targets in this file.
5018 With optional argument RADIO, only find radio targets."
5019 (let ((re (if radio org-radio-target-regexp org-target-regexp))
5022 (goto-char (point-min))
5023 (while (re-search-forward re nil t)
5024 (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
5027 (defun org-make-target-link-regexp (targets)
5028 "Make regular expression matching all strings in TARGETS.
5029 The regular expression finds the targets also if there is a line break
5036 (while (string-match " +" x)
5037 (setq x (replace-match "\\s-+" t t x)))
5043 (defun org-activate-tags (limit)
5044 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
5046 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5047 (add-text-properties (match-beginning 1) (match-end 1)
5048 (list 'mouse-face 'highlight
5049 'keymap org-mouse-map))
5050 (org-rear-nonsticky-at (match-end 1))
5053 (defun org-outline-level ()
5054 "Compute the outline level of the heading at point.
5055 This function assumes that the cursor is at the beginning of a line matched
5056 by outline-regexp. Otherwise it returns garbage.
5057 If this is called at a normal headline, the level is the number of stars.
5058 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5059 For plain list items, if they are matched by `outline-regexp', this returns
5060 1000 plus the line indentation."
5062 (looking-at outline-regexp)
5063 (if (match-beginning 1)
5064 (+ (org-get-string-indentation (match-string 1)) 1000)
5065 (1- (- (match-end 0) (match-beginning 0))))))
5067 (defvar org-font-lock-keywords nil)
5069 (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5070 "Regular expression matching a property line.")
5072 (defvar org-font-lock-hook nil
5073 "Functions to be called for special font lock stuff.")
5075 (defun org-font-lock-hook (limit)
5076 (run-hook-with-args 'org-font-lock-hook limit))
5078 (defun org-set-font-lock-defaults ()
5079 (let* ((em org-fontify-emphasized-text)
5080 (lk org-activate-links)
5081 (org-font-lock-extra-keywords
5084 '(org-font-lock-hook)
5086 `(,(if org-fontify-whole-heading-line
5087 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5088 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5089 (1 (org-get-level-face 1))
5090 (2 (org-get-level-face 2))
5091 (3 (org-get-level-face 3)))
5093 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5096 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
5097 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
5098 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
5099 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t))
5101 (list org-drawer-regexp '(0 'org-special-keyword t))
5102 (list "^[ \t]*:END:" '(0 'org-special-keyword t))
5104 (list org-property-re
5105 '(1 'org-special-keyword t)
5106 '(3 'org-property-value t))
5108 (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
5109 (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
5110 (if (memq 'plain lk) '(org-activate-plain-links))
5111 (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
5112 (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
5113 (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
5114 (if (memq 'footnote lk) '(org-activate-footnote-links
5115 (2 'org-footnote t)))
5116 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
5117 '(org-hide-wide-columns (0 nil append))
5119 (list (concat "^\\*+[ \t]+" org-todo-regexp "\\([ \t]\\|$\\)")
5120 '(1 (org-get-todo-face 1) t))
5122 (if org-fontify-done-headline
5123 (list (concat "^[*]+ +\\<\\("
5124 (mapconcat 'regexp-quote org-done-keywords "\\|")
5126 '(2 'org-headline-done t))
5129 '(org-font-lock-add-priority-faces)
5131 '(org-font-lock-add-tag-faces)
5133 (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
5134 (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
5135 (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
5136 (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
5139 (if (featurep 'xemacs)
5140 '(org-do-emphasis-faces (0 nil append))
5141 '(org-do-emphasis-faces)))
5143 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5144 2 'org-checkbox prepend)
5145 (if org-provide-checkbox-statistics
5146 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5147 (0 (org-get-checkbox-statistics-face) t)))
5148 ;; Description list items
5149 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5151 ;; ARCHIVEd headings
5152 (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
5153 '(1 'org-archived prepend))
5155 '(org-do-latex-and-special-faces)
5157 '(org-activate-code (1 'org-code t))
5159 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5160 "\\|" org-quote-string "\\)\\>")
5161 '(1 'org-special-keyword t))
5162 '("^#.*" (0 'font-lock-comment-face t))
5163 ;; Blocks and meta lines
5164 '(org-fontify-meta-lines-and-blocks)
5166 (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
5167 ;; Now set the full font-lock-keywords
5168 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
5169 (org-set-local 'font-lock-defaults
5170 '(org-font-lock-keywords t nil nil backward-paragraph))
5171 (kill-local-variable 'font-lock-keywords) nil))
5173 (defun org-fontify-like-in-org-mode (s &optional odd-levels)
5174 "Fontify string S like in Org-mode"
5177 (let ((org-odd-levels-only odd-levels))
5179 (font-lock-fontify-buffer)
5185 (defun org-get-level-face (n)
5186 "Get the right face for match N in font-lock matching of headlines."
5187 (setq org-l (- (match-end 2) (match-beginning 1) 1))
5188 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
5189 (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
5191 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
5193 (t (if org-level-color-stars-only nil org-f))))
5195 (defun org-get-todo-face (kwd)
5196 "Get the right face for a TODO keyword KWD.
5197 If KWD is a number, get the corresponding match group."
5198 (if (numberp kwd) (setq kwd (match-string kwd)))
5199 (or (org-face-from-face-or-color
5200 'todo 'org-todo (cdr (assoc kwd org-todo-keyword-faces)))
5201 (and (member kwd org-done-keywords) 'org-done)
5204 (defun org-face-from-face-or-color (context inherit face-or-color)
5205 "Create a face list that inherits INHERIT, but sets the foreground color.
5206 When FACE-OR-COLOR is not a string, just return it."
5207 (if (stringp face-or-color)
5208 (list :inherit inherit
5209 (cdr (assoc context org-faces-easy-properties))
5213 (defun org-font-lock-add-tag-faces (limit)
5214 "Add the special tag faces."
5215 (when (and org-tag-faces org-tags-special-faces-re)
5216 (while (re-search-forward org-tags-special-faces-re limit t)
5217 (add-text-properties (match-beginning 1) (match-end 1)
5218 (list 'face (org-get-tag-face 1)
5219 'font-lock-fontified t))
5220 (backward-char 1))))
5222 (defun org-font-lock-add-priority-faces (limit)
5223 "Add the special priority faces."
5224 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t)
5225 (add-text-properties
5226 (match-beginning 0) (match-end 0)
5227 (list 'face (or (org-face-from-face-or-color
5228 'priority 'org-special-keyword
5229 (cdr (assoc (char-after (match-beginning 1))
5230 org-priority-faces)))
5231 'org-special-keyword)
5232 'font-lock-fontified t))))
5234 (defun org-get-tag-face (kwd)
5235 "Get the right face for a TODO keyword KWD.
5236 If KWD is a number, get the corresponding match group."
5237 (if (numberp kwd) (setq kwd (match-string kwd)))
5238 (or (org-face-from-face-or-color
5239 'tag 'org-tag (cdr (assoc kwd org-tag-faces)))
5242 (defun org-unfontify-region (beg end &optional maybe_loudly)
5243 "Remove fontification and activation overlays from links."
5244 (font-lock-default-unfontify-region beg end)
5245 (let* ((buffer-undo-list t)
5246 (inhibit-read-only t) (inhibit-point-motion-hooks t)
5247 (inhibit-modification-hooks t)
5248 deactivate-mark buffer-file-name buffer-file-truename)
5249 (remove-text-properties
5252 ;; also remove line-prefix and wrap-prefix properties
5253 '(mouse-face t keymap t org-linked-text t
5254 invisible t intangible t
5255 line-prefix t wrap-prefix t
5257 '(mouse-face t keymap t org-linked-text t
5258 invisible t intangible t
5259 org-no-flyspell t)))))
5261 ;;;; Visibility cycling, including org-goto and indirect buffer
5265 (defvar org-cycle-global-status nil)
5266 (make-variable-buffer-local 'org-cycle-global-status)
5267 (defvar org-cycle-subtree-status nil)
5268 (make-variable-buffer-local 'org-cycle-subtree-status)
5272 (defvar org-inlinetask-min-level)
5274 (defun org-cycle (&optional arg)
5275 "TAB-action and visibility cycling for Org-mode.
5277 This is the command invoked in Org-mode by the TAB key. Its main purpose
5278 is outline visibility cycling, but it also invokes other actions
5279 in special contexts.
5281 - When this function is called with a prefix argument, rotate the entire
5282 buffer through 3 states (global cycling)
5283 1. OVERVIEW: Show only top-level headlines.
5284 2. CONTENTS: Show all headlines of all levels, but no body text.
5285 3. SHOW ALL: Show everything.
5286 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5287 determined by the variable `org-startup-folded', and by any VISIBILITY
5288 properties in the buffer.
5289 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5290 including any drawers.
5292 - When inside a table, re-align the table and move to the next field.
5294 - When point is at the beginning of a headline, rotate the subtree started
5295 by this line through 3 different states (local cycling)
5296 1. FOLDED: Only the main headline is shown.
5297 2. CHILDREN: The main headline and the direct children are shown.
5298 From this state, you can move to one of the children
5299 and zoom in further.
5300 3. SUBTREE: Show the entire subtree, including body text.
5301 If there is no subtree, switch directly from CHILDREN to FOLDED.
5303 - When point is at the beginning of an empty headline and the variable
5304 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5305 of the headline by demoting and promoting it to likely levels. This
5306 speeds up creation document structure by presing TAB once or several
5307 times right after creating a new headline.
5309 - When there is a numeric prefix, go up to a heading with level ARG, do
5310 a `show-subtree' and return to the previous cursor position. If ARG
5311 is negative, go up that many levels.
5313 - When point is not at the beginning of a headline, execute the global
5314 binding for TAB, which is re-indenting the line. See the option
5315 `org-cycle-emulate-tab' for details.
5317 - Special case: if point is at the beginning of the buffer and there is
5318 no headline in line 1, this function will act as if called with prefix arg.
5319 But only if also the variable `org-cycle-global-at-bob' is t."
5321 (org-load-modules-maybe)
5322 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook)
5323 (and org-cycle-level-after-item/entry-creation
5324 (or (org-cycle-level)
5325 (org-cycle-item-indentation))))
5327 (or org-cycle-max-level
5328 (and (boundp 'org-inlinetask-min-level)
5329 org-inlinetask-min-level
5330 (1- org-inlinetask-min-level))))
5331 (nstars (and limit-level
5332 (if org-odd-levels-only
5333 (and limit-level (1- (* limit-level 2)))
5337 ((not (org-mode-p)) outline-regexp)
5338 ((or (eq org-cycle-include-plain-lists 'integrate)
5339 (and org-cycle-include-plain-lists (org-at-item-p)))
5341 (if nstars (format "\\{1,%d\\}" nstars) "+")
5342 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5343 (t (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))))
5344 (bob-special (and org-cycle-global-at-bob (bobp)
5345 (not (looking-at outline-regexp))))
5348 (delq 'org-optimize-window-after-visibility-change
5349 (copy-sequence org-cycle-hook))
5353 (if (or bob-special (equal arg '(4)))
5354 ;; special case: use global cycling
5360 (org-set-startup-visibility)
5361 (message "Startup visibility, plus VISIBILITY properties"))
5365 (message "Entire buffer visible, including drawers"))
5367 ((org-at-table-p 'any)
5368 ;; Enter the table or move to the next field in the table
5369 (if (org-at-table.el-p)
5370 (message "Use C-c ' to edit table.el tables")
5371 (if arg (org-table-edit-field t)
5372 (org-table-justify-field-maybe)
5373 (call-interactively 'org-table-next-field))))
5375 ((run-hook-with-args-until-success
5376 'org-tab-after-check-for-table-hook))
5378 ((eq arg t) ;; Global cycling
5379 (org-cycle-internal-global))
5381 ((and org-drawers org-drawer-regexp
5383 (beginning-of-line 1)
5384 (looking-at org-drawer-regexp)))
5385 ;; Toggle block visibility
5387 (not (get-char-property (match-end 0) 'invisible))))
5390 ;; Show-subtree, ARG levels up from here.
5392 (org-back-to-heading)
5393 (outline-up-heading (if (< arg 0) (- arg)
5394 (- (funcall outline-level) arg)))
5395 (org-show-subtree)))
5397 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
5398 (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
5400 (org-cycle-internal-local))
5402 ;; TAB emulation and template completion
5403 (buffer-read-only (org-back-to-heading))
5405 ((run-hook-with-args-until-success
5406 'org-tab-after-check-for-cycling-hook))
5408 ((org-try-structure-completion))
5410 ((org-try-cdlatex-tab))
5412 ((run-hook-with-args-until-success
5413 'org-tab-before-tab-emulation-hook))
5415 ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
5417 (not (looking-at outline-regexp))))
5418 (call-interactively (global-key-binding "\t")))
5420 ((if (and (memq org-cycle-emulate-tab '(white whitestart))
5421 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5422 (or (and (eq org-cycle-emulate-tab 'white)
5423 (= (match-end 0) (point-at-eol)))
5424 (and (eq org-cycle-emulate-tab 'whitestart)
5425 (>= (match-end 0) pos))))
5427 (eq org-cycle-emulate-tab t))
5428 (call-interactively (global-key-binding "\t")))
5431 (org-back-to-heading)
5434 (defun org-cycle-internal-global ()
5435 "Do the global cycling action."
5437 ((and (eq last-command this-command)
5438 (eq org-cycle-global-status 'overview))
5439 ;; We just created the overview - now do table of contents
5440 ;; This can be slow in very large buffers, so indicate action
5441 (run-hook-with-args 'org-pre-cycle-hook 'contents)
5442 (message "CONTENTS...")
5444 (message "CONTENTS...done")
5445 (setq org-cycle-global-status 'contents)
5446 (run-hook-with-args 'org-cycle-hook 'contents))
5448 ((and (eq last-command this-command)
5449 (eq org-cycle-global-status 'contents))
5450 ;; We just showed the table of contents - now show everything
5451 (run-hook-with-args 'org-pre-cycle-hook 'all)
5453 (message "SHOW ALL")
5454 (setq org-cycle-global-status 'all)
5455 (run-hook-with-args 'org-cycle-hook 'all))
5458 ;; Default action: go to overview
5459 (run-hook-with-args 'org-pre-cycle-hook 'overview)
5461 (message "OVERVIEW")
5462 (setq org-cycle-global-status 'overview)
5463 (run-hook-with-args 'org-cycle-hook 'overview))))
5465 (defun org-cycle-internal-local ()
5466 "Do the local cycling action."
5467 (org-back-to-heading)
5468 (let ((goal-column 0) eoh eol eos level has-children children-skipped)
5469 ;; First, some boundaries
5471 (org-back-to-heading)
5472 (setq level (funcall outline-level))
5474 (beginning-of-line 2)
5475 (if (or (featurep 'xemacs) (<= emacs-major-version 21))
5476 ; XEmacs does not have `next-single-char-property-change'
5477 ; I'm not sure about Emacs 21.
5478 (while (and (not (eobp)) ;; this is like `next-line'
5479 (get-char-property (1- (point)) 'invisible))
5480 (beginning-of-line 2))
5481 (while (and (not (eobp)) ;; this is like `next-line'
5482 (get-char-property (1- (point)) 'invisible))
5483 (goto-char (next-single-char-property-change (point) 'invisible))
5484 ;;;??? (or (bolp) (beginning-of-line 2))))
5485 (and (eolp) (beginning-of-line 2))))
5487 (outline-end-of-heading) (setq eoh (point))
5489 (outline-next-heading)
5490 (setq has-children (and (org-at-heading-p t)
5491 (> (funcall outline-level) level))))
5492 (org-end-of-subtree t)
5494 (skip-chars-forward " \t\n")
5495 (beginning-of-line 1) ; in case this is an item
5497 (setq eos (if (eobp) (point) (1- (point)))))
5498 ;; Find out what to do next and set `this-command'
5501 ;; Nothing is hidden behind this heading
5502 (run-hook-with-args 'org-pre-cycle-hook 'empty)
5503 (message "EMPTY ENTRY")
5504 (setq org-cycle-subtree-status nil)
5507 (outline-next-heading)
5508 (if (org-invisible-p) (org-flag-heading nil))))
5509 ((and (or (>= eol eos)
5510 (not (string-match "\\S-" (buffer-substring eol eos))))
5512 (not (setq children-skipped
5513 org-cycle-skip-children-state-if-no-children))))
5514 ;; Entire subtree is hidden in one line: children view
5515 (run-hook-with-args 'org-pre-cycle-hook 'children)
5518 (message "CHILDREN")
5521 (outline-next-heading)
5522 (if (org-invisible-p) (org-flag-heading nil)))
5523 (setq org-cycle-subtree-status 'children)
5524 (run-hook-with-args 'org-cycle-hook 'children))
5525 ((or children-skipped
5526 (and (eq last-command this-command)
5527 (eq org-cycle-subtree-status 'children)))
5528 ;; We just showed the children, or no children are there,
5529 ;; now show everything.
5530 (run-hook-with-args 'org-pre-cycle-hook 'subtree)
5532 (message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
5533 (setq org-cycle-subtree-status 'subtree)
5534 (run-hook-with-args 'org-cycle-hook 'subtree))
5536 ;; Default action: hide the subtree.
5537 (run-hook-with-args 'org-pre-cycle-hook 'folded)
5540 (setq org-cycle-subtree-status 'folded)
5541 (run-hook-with-args 'org-cycle-hook 'folded)))))
5544 (defun org-global-cycle (&optional arg)
5545 "Cycle the global visibility. For details see `org-cycle'.
5546 With C-u prefix arg, switch to startup visibility.
5547 With a numeric prefix, show all headlines up to that level."
5549 (let ((org-cycle-include-plain-lists
5550 (if (org-mode-p) org-cycle-include-plain-lists nil)))
5554 (hide-sublevels arg)
5555 (setq org-cycle-global-status 'contents))
5557 (org-set-startup-visibility)
5558 (message "Startup visibility, plus VISIBILITY properties."))
5560 (org-cycle '(4))))))
5562 (defun org-set-startup-visibility ()
5563 "Set the visibility required by startup options and properties."
5565 ((eq org-startup-folded t)
5567 ((eq org-startup-folded 'content)
5568 (let ((this-command 'org-cycle) (last-command 'org-cycle))
5569 (org-cycle '(4)) (org-cycle '(4)))))
5570 (unless (eq org-startup-folded 'showeverything)
5571 (if org-hide-block-startup (org-hide-block-all))
5572 (org-set-visibility-according-to-property 'no-cleanup)
5573 (org-cycle-hide-archived-subtrees 'all)
5574 (org-cycle-hide-drawers 'all)
5575 (org-cycle-show-empty-lines 'all)))
5577 (defun org-set-visibility-according-to-property (&optional no-cleanup)
5578 "Switch subtree visibilities according to :VISIBILITY: property."
5580 (let (org-show-entry-below state)
5582 (goto-char (point-min))
5583 (while (re-search-forward
5584 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5586 (setq state (match-string 1))
5588 (org-back-to-heading t)
5592 ((equal state '("fold" "folded"))
5594 ((equal state "children")
5595 (org-show-hidden-entry)
5597 ((equal state "content")
5600 (org-narrow-to-subtree)
5602 ((member state '("all" "showall"))
5605 (org-cycle-hide-archived-subtrees 'all)
5606 (org-cycle-hide-drawers 'all)
5607 (org-cycle-show-empty-lines 'all)))))
5609 (defun org-overview ()
5610 "Switch to overview mode, showing only top-level headlines.
5611 Really, this shows all headlines with level equal or greater than the level
5612 of the first headline in the buffer. This is important, because if the
5613 first headline is not level one, then (hide-sublevels 1) gives confusing
5616 (let ((level (save-excursion
5617 (goto-char (point-min))
5618 (if (re-search-forward (concat "^" outline-regexp) nil t)
5620 (goto-char (match-beginning 0))
5621 (funcall outline-level))))))
5622 (and level (hide-sublevels level))))
5624 (defun org-content (&optional arg)
5625 "Show all headlines in the buffer, like a table of contents.
5626 With numerical argument N, show content up to level N."
5629 ;; Visit all headings and show their offspring
5630 (and (integerp arg) (org-overview))
5631 (goto-char (point-max))
5633 (while (and (progn (condition-case nil
5634 (outline-previous-visible-heading 1)
5635 (error (goto-char (point-min))))
5637 (looking-at outline-regexp))
5639 (show-children (1- arg))
5641 (if (bobp) (throw 'exit nil))))))
5644 (defun org-optimize-window-after-visibility-change (state)
5645 "Adjust the window after a change in outline visibility.
5646 This function is the default value of the hook `org-cycle-hook'."
5647 (when (get-buffer-window (current-buffer))
5649 ((eq state 'content) nil)
5650 ((eq state 'all) nil)
5651 ((eq state 'folded) nil)
5652 ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
5653 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
5655 (defun org-remove-empty-overlays-at (pos)
5656 "Remove outline overlays that do not contain non-white stuff."
5659 (and (eq 'outline (overlay-get o 'invisible))
5660 (not (string-match "\\S-" (buffer-substring (overlay-start o)
5662 (delete-overlay o)))
5663 (org-overlays-at pos)))
5665 (defun org-clean-visibility-after-subtree-move ()
5666 "Fix visibility issues after moving a subtree."
5667 ;; First, find a reasonable region to look at:
5668 ;; Start two siblings above, end three below
5669 (let* ((beg (save-excursion
5670 (and (org-get-last-sibling)
5671 (org-get-last-sibling))
5673 (end (save-excursion
5674 (and (org-get-next-sibling)
5675 (org-get-next-sibling)
5676 (org-get-next-sibling))
5677 (if (org-at-heading-p)
5680 (level (looking-at "\\*+"))
5681 (re (if level (concat "^" (regexp-quote (match-string 0)) " "))))
5684 (narrow-to-region beg end)
5686 ;; Properly fold already folded siblings
5687 (goto-char (point-min))
5688 (while (re-search-forward re nil t)
5689 (if (and (not (org-invisible-p))
5691 (goto-char (point-at-eol)) (org-invisible-p)))
5693 (org-cycle-show-empty-lines 'overview)
5694 (org-cycle-hide-drawers 'overview)))))
5696 (defun org-cycle-show-empty-lines (state)
5697 "Show empty lines above all visible headlines.
5698 The region to be covered depends on STATE when called through
5699 `org-cycle-hook'. Lisp program can use t for STATE to get the
5700 entire buffer covered. Note that an empty line is only shown if there
5701 are at least `org-cycle-separator-lines' empty lines before the headline."
5702 (when (not (= org-cycle-separator-lines 0))
5704 (let* ((n (abs org-cycle-separator-lines))
5706 ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
5707 ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
5708 (t (let ((ns (number-to-string (- n 2))))
5709 (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
5710 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
5713 ((memq state '(overview contents t))
5714 (setq beg (point-min) end (point-max)))
5715 ((memq state '(children folded))
5716 (setq beg (point) end (progn (org-end-of-subtree t t)
5717 (beginning-of-line 2)
5721 (while (re-search-forward re end t)
5722 (unless (get-char-property (match-end 1) 'invisible)
5723 (setq e (match-end 1))
5724 (if (< org-cycle-separator-lines 0)
5725 (setq b (save-excursion
5726 (goto-char (match-beginning 0))
5727 (org-back-over-empty-lines)
5729 (goto-char (max (point-min) (1- (point))))
5733 (setq b (match-beginning 1)))
5734 (outline-flag-region b e nil)))))))
5735 ;; Never hide empty lines at the end of the file.
5737 (goto-char (point-max))
5738 (outline-previous-heading)
5739 (outline-end-of-heading)
5740 (if (and (looking-at "[ \t\n]+")
5741 (= (match-end 0) (point-max)))
5742 (outline-flag-region (point) (match-end 0) nil))))
5744 (defun org-show-empty-lines-in-parent ()
5745 "Move to the parent and re-show empty lines before visible headlines."
5747 (let ((context (if (org-up-heading-safe) 'children 'overview)))
5748 (org-cycle-show-empty-lines context))))
5750 (defun org-files-list ()
5751 "Return `org-agenda-files' list, plus all open org-mode files.
5752 This is useful for operations that need to scan all of a user's
5753 open and agenda-wise Org files."
5754 (let ((files (mapcar 'expand-file-name (org-agenda-files))))
5755 (dolist (buf (buffer-list))
5756 (with-current-buffer buf
5757 (if (and (eq major-mode 'org-mode) (buffer-file-name))
5758 (let ((file (expand-file-name (buffer-file-name))))
5759 (unless (member file files)
5760 (push file files))))))
5763 (defsubst org-entry-beginning-position ()
5764 "Return the beginning position of the current entry."
5765 (save-excursion (outline-back-to-heading t) (point)))
5767 (defsubst org-entry-end-position ()
5768 "Return the end position of the current entry."
5769 (save-excursion (outline-next-heading) (point)))
5771 (defun org-cycle-hide-drawers (state)
5772 "Re-hide all drawers after a visibility state change."
5773 (when (and (org-mode-p)
5774 (not (memq state '(overview folded contents))))
5776 (let* ((globalp (memq state '(contents all)))
5777 (beg (if globalp (point-min) (point)))
5778 (end (if globalp (point-max)
5779 (if (eq state 'children)
5780 (save-excursion (outline-next-heading) (point))
5781 (org-end-of-subtree t)))))
5783 (while (re-search-forward org-drawer-regexp end t)
5784 (org-flag-drawer t))))))
5786 (defun org-flag-drawer (flag)
5788 (beginning-of-line 1)
5789 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
5790 (let ((b (match-end 0))
5791 (outline-regexp org-outline-regexp))
5792 (if (re-search-forward
5794 (save-excursion (outline-next-heading) (point)) t)
5795 (outline-flag-region b (point-at-eol) flag)
5796 (error ":END: line missing at position %s" b))))))
5798 (defun org-subtree-end-visible-p ()
5799 "Is the end of the current subtree visible?"
5800 (pos-visible-in-window-p
5801 (save-excursion (org-end-of-subtree t) (point))))
5803 (defun org-first-headline-recenter (&optional N)
5804 "Move cursor to the first headline and recenter the headline.
5805 Optional argument N means put the headline into the Nth line of the window."
5806 (goto-char (point-min))
5807 (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
5809 (recenter (prefix-numeric-value N))))
5811 ;;; Saving and restoring visibility
5813 (defun org-outline-overlay-data (&optional use-markers)
5814 "Return a list of the locations of all outline overlays.
5815 The are overlays with the `invisible' property value `outline'.
5816 The return valus is a list of cons cells, with start and stop
5817 positions for each overlay.
5818 If USE-MARKERS is set, return the positions as markers."
5825 (when (eq (overlay-get o 'invisible) 'outline)
5826 (setq beg (overlay-start o)
5827 end (overlay-end o))
5828 (and beg end (> end beg)
5830 (cons (move-marker (make-marker) beg)
5831 (move-marker (make-marker) end))
5833 (org-overlays-in (point-min) (point-max))))))))
5835 (defun org-set-outline-overlay-data (data)
5836 "Create visibility overlays for all positions in DATA.
5837 DATA should have been made by `org-outline-overlay-data'."
5844 (setq o (make-overlay (car c) (cdr c)))
5845 (overlay-put o 'invisible 'outline))
5848 (defmacro org-save-outline-visibility (use-markers &rest body)
5849 "Save and restore outline visibility around BODY.
5850 If USE-MARKERS is non-nil, use markers for the positions.
5851 This means that the buffer may change while running BODY,
5852 but it also means that the buffer should stay alive
5853 during the operation, because otherwise all these markers will
5855 `(let ((data (org-outline-overlay-data ,use-markers)))
5859 (org-set-outline-overlay-data data))
5862 (and (markerp (car c)) (move-marker (car c) nil))
5863 (and (markerp (cdr c)) (move-marker (cdr c) nil)))
5867 ;;; Folding of blocks
5869 (defconst org-block-regexp
5871 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
5872 "Regular expression for hiding blocks.")
5874 (defvar org-hide-block-overlays nil
5875 "Overlays hiding blocks.")
5876 (make-variable-buffer-local 'org-hide-block-overlays)
5878 (defun org-block-map (function &optional start end)
5879 "Call func at the head of all source blocks in the current
5880 buffer. Optional arguments START and END can be used to limit
5882 (let ((start (or start (point-min)))
5883 (end (or end (point-max))))
5886 (while (and (< (point) end) (re-search-forward org-block-regexp end t))
5889 (goto-char (match-beginning 0))
5890 (funcall function)))))))
5892 (defun org-hide-block-toggle-all ()
5893 "Toggle the visibility of all blocks in the current buffer."
5894 (org-block-map #'org-hide-block-toggle))
5896 (defun org-hide-block-all ()
5897 "Fold all blocks in the current buffer."
5899 (org-show-block-all)
5900 (org-block-map #'org-hide-block-toggle-maybe))
5902 (defun org-show-block-all ()
5903 "Unfold all blocks in the current buffer."
5904 (mapc 'delete-overlay org-hide-block-overlays)
5905 (setq org-hide-block-overlays nil))
5907 (defun org-hide-block-toggle-maybe ()
5908 "Toggle visibility of block at point."
5910 (let ((case-fold-search t))
5912 (beginning-of-line 1)
5913 (looking-at org-block-regexp))
5914 (progn (org-hide-block-toggle)
5915 t) ;; to signal that we took action
5916 nil))) ;; to signal that we did not
5918 (defun org-hide-block-toggle (&optional force)
5919 "Toggle the visibility of the current block."
5923 (if (re-search-forward org-block-regexp nil t)
5924 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
5925 (end (match-end 0)) ;; end of entire body
5927 (if (memq t (mapcar (lambda (overlay)
5928 (eq (overlay-get overlay 'invisible)
5930 (org-overlays-at start)))
5931 (if (or (not force) (eq force 'off))
5933 (when (member ov org-hide-block-overlays)
5934 (setq org-hide-block-overlays
5935 (delq ov org-hide-block-overlays)))
5936 (when (eq (overlay-get ov 'invisible)
5938 (delete-overlay ov)))
5939 (org-overlays-at start)))
5940 (setq ov (make-overlay start end))
5941 (overlay-put ov 'invisible 'org-hide-block)
5942 ;; make the block accessible to isearch
5944 ov 'isearch-open-invisible
5946 (when (member ov org-hide-block-overlays)
5947 (setq org-hide-block-overlays
5948 (delq ov org-hide-block-overlays)))
5949 (when (eq (overlay-get ov 'invisible)
5951 (delete-overlay ov))))
5952 (push ov org-hide-block-overlays)))
5953 (error "Not looking at a source block"))))
5955 ;; org-tab-after-check-for-cycling-hook
5956 (add-hook 'org-tab-first-hook 'org-hide-block-toggle-maybe)
5957 ;; Remove overlays when changing major mode
5958 (add-hook 'org-mode-hook
5959 (lambda () (org-add-hook 'change-major-mode-hook
5960 'org-show-block-all 'append 'local)))
5964 (defvar org-goto-window-configuration nil)
5965 (defvar org-goto-marker nil)
5966 (defvar org-goto-map
5967 (let ((map (make-sparse-keymap)))
5968 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
5969 (while (setq cmd (pop cmds))
5970 (substitute-key-definition cmd cmd map global-map)))
5971 (suppress-keymap map)
5972 (org-defkey map "\C-m" 'org-goto-ret)
5973 (org-defkey map [(return)] 'org-goto-ret)
5974 (org-defkey map [(left)] 'org-goto-left)
5975 (org-defkey map [(right)] 'org-goto-right)
5976 (org-defkey map [(control ?g)] 'org-goto-quit)
5977 (org-defkey map "\C-i" 'org-cycle)
5978 (org-defkey map [(tab)] 'org-cycle)
5979 (org-defkey map [(down)] 'outline-next-visible-heading)
5980 (org-defkey map [(up)] 'outline-previous-visible-heading)
5981 (if org-goto-auto-isearch
5982 (if (fboundp 'define-key-after)
5983 (define-key-after map [t] 'org-goto-local-auto-isearch)
5985 (org-defkey map "q" 'org-goto-quit)
5986 (org-defkey map "n" 'outline-next-visible-heading)
5987 (org-defkey map "p" 'outline-previous-visible-heading)
5988 (org-defkey map "f" 'outline-forward-same-level)
5989 (org-defkey map "b" 'outline-backward-same-level)
5990 (org-defkey map "u" 'outline-up-heading))
5991 (org-defkey map "/" 'org-occur)
5992 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
5993 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
5994 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
5995 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
5996 (org-defkey map "\C-c\C-u" 'outline-up-heading)
5999 (defconst org-goto-help
6000 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6001 RET=jump to location [Q]uit and return to previous location
6002 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6004 (defvar org-goto-start-pos) ; dynamically scoped parameter
6006 ;; FIXME: Docstring does not mention both interfaces
6007 (defun org-goto (&optional alternative-interface)
6008 "Look up a different location in the current file, keeping current visibility.
6010 When you want look-up or go to a different location in a document, the
6011 fastest way is often to fold the entire buffer and then dive into the tree.
6012 This method has the disadvantage, that the previous location will be folded,
6013 which may not be what you want.
6015 This command works around this by showing a copy of the current buffer
6016 in an indirect buffer, in overview mode. You can dive into the tree in
6017 that copy, use org-occur and incremental search to find a location.
6018 When pressing RET or `Q', the command returns to the original buffer in
6019 which the visibility is still unchanged. After RET is will also jump to
6020 the location selected in the indirect buffer and expose the
6021 the headline hierarchy above."
6023 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6024 (org-refile-use-outline-path t)
6025 (org-refile-target-verify-function nil)
6027 (if (not alternative-interface)
6029 (if (eq org-goto-interface 'outline)
6030 'outline-path-completion
6032 (org-goto-start-pos (point))
6034 (if (eq interface 'outline)
6035 (car (org-get-location (current-buffer) org-goto-help))
6036 (nth 3 (org-refile-get-location "Goto: ")))))
6039 (org-mark-ring-push org-goto-start-pos)
6040 (goto-char selected-point)
6041 (if (or (org-invisible-p) (org-invisible-p2))
6042 (org-show-context 'org-goto)))
6045 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6046 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6047 (defvar org-goto-local-auto-isearch-map) ; defined below
6049 (defun org-get-location (buf help)
6050 "Let the user select a location in the Org-mode buffer BUF.
6051 This function uses a recursive edit. It returns the selected position
6053 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6054 (isearch-hide-immediately nil)
6055 (isearch-search-fun-function
6056 (lambda () 'org-goto-local-search-headings))
6057 (org-goto-selected-point org-goto-exit-command)
6059 (special-display-buffer-names nil)
6060 (special-display-regexps nil)
6061 (special-display-function nil))
6063 (save-window-excursion
6064 (delete-other-windows)
6065 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6068 (make-indirect-buffer (current-buffer) "*org-goto*")
6069 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6070 (with-output-to-temp-buffer "*Help*"
6072 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6073 (setq buffer-read-only nil)
6074 (let ((org-startup-truncated t)
6075 (org-startup-folded nil)
6076 (org-startup-align-all-tables nil))
6079 (setq buffer-read-only t)
6080 (if (and (boundp 'org-goto-start-pos)
6081 (integer-or-marker-p org-goto-start-pos))
6082 (let ((org-show-hierarchy-above t)
6083 (org-show-siblings t)
6084 (org-show-following-heading t))
6085 (goto-char org-goto-start-pos)
6086 (and (org-invisible-p) (org-show-context)))
6087 (goto-char (point-min)))
6088 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6089 (message "Select location and press RET")
6090 (use-local-map org-goto-map)
6093 (kill-buffer "*org-goto*")
6094 (cons org-goto-selected-point org-goto-exit-command)))
6096 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6097 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6098 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6099 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6101 (defun org-goto-local-search-headings (string bound noerror)
6102 "Search and make sure that any matches are in headlines."
6104 (while (if isearch-forward
6105 (search-forward string bound noerror)
6106 (search-backward string bound noerror))
6107 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6108 (and (member :headline context)
6109 (not (member :tags context))))
6110 (throw 'return (point))))))
6112 (defun org-goto-local-auto-isearch ()
6115 (goto-char (point-min))
6116 (let ((keys (this-command-keys)))
6117 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6119 (isearch-process-search-char (string-to-char keys)))))
6121 (defun org-goto-ret (&optional arg)
6122 "Finish `org-goto' by going to the new location."
6124 (setq org-goto-selected-point (point)
6125 org-goto-exit-command 'return)
6128 (defun org-goto-left ()
6129 "Finish `org-goto' by going to the new location."
6131 (if (org-on-heading-p)
6133 (beginning-of-line 1)
6134 (setq org-goto-selected-point (point)
6135 org-goto-exit-command 'left)
6137 (error "Not on a heading")))
6139 (defun org-goto-right ()
6140 "Finish `org-goto' by going to the new location."
6142 (if (org-on-heading-p)
6144 (setq org-goto-selected-point (point)
6145 org-goto-exit-command 'right)
6147 (error "Not on a heading")))
6149 (defun org-goto-quit ()
6150 "Finish `org-goto' without cursor motion."
6152 (setq org-goto-selected-point nil)
6153 (setq org-goto-exit-command 'quit)
6156 ;;; Indirect buffer display of subtrees
6158 (defvar org-indirect-dedicated-frame nil
6159 "This is the frame being used for indirect tree display.")
6160 (defvar org-last-indirect-buffer nil)
6162 (defun org-tree-to-indirect-buffer (&optional arg)
6163 "Create indirect buffer and narrow it to current subtree.
6164 With numerical prefix ARG, go up to this level and then take that tree.
6165 If ARG is negative, go up that many levels.
6166 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6167 indirect buffer previously made with this command, to avoid proliferation of
6168 indirect buffers. However, when you call the command with a `C-u' prefix, or
6169 when `org-indirect-buffer-display' is `new-frame', the last buffer
6170 is kept so that you can work with several indirect buffers at the same time.
6171 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6172 requests that a new frame be made for the new buffer, so that the dedicated
6173 frame is not changed."
6175 (let ((cbuf (current-buffer))
6176 (cwin (selected-window))
6178 beg end level heading ibuf)
6180 (org-back-to-heading t)
6182 (setq level (org-outline-level))
6183 (if (< arg 0) (setq arg (+ level arg)))
6184 (while (> (setq level (org-outline-level)) arg)
6185 (outline-up-heading 1 t)))
6187 heading (org-get-heading))
6188 (org-end-of-subtree t t)
6189 (if (org-on-heading-p) (backward-char 1))
6191 (if (and (buffer-live-p org-last-indirect-buffer)
6192 (not (eq org-indirect-buffer-display 'new-frame))
6194 (kill-buffer org-last-indirect-buffer))
6195 (setq ibuf (org-get-indirect-buffer cbuf)
6196 org-last-indirect-buffer ibuf)
6198 ((or (eq org-indirect-buffer-display 'new-frame)
6199 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6200 (select-frame (make-frame))
6201 (delete-other-windows)
6202 (switch-to-buffer ibuf)
6203 (org-set-frame-title heading))
6204 ((eq org-indirect-buffer-display 'dedicated-frame)
6206 (select-frame (or (and org-indirect-dedicated-frame
6207 (frame-live-p org-indirect-dedicated-frame)
6208 org-indirect-dedicated-frame)
6209 (setq org-indirect-dedicated-frame (make-frame)))))
6210 (delete-other-windows)
6211 (switch-to-buffer ibuf)
6212 (org-set-frame-title (concat "Indirect: " heading)))
6213 ((eq org-indirect-buffer-display 'current-window)
6214 (switch-to-buffer ibuf))
6215 ((eq org-indirect-buffer-display 'other-window)
6216 (pop-to-buffer ibuf))
6217 (t (error "Invalid value")))
6218 (if (featurep 'xemacs)
6219 (save-excursion (org-mode) (turn-on-font-lock)))
6220 (narrow-to-region beg end)
6223 (and (window-live-p cwin) (select-window cwin))))
6225 (defun org-get-indirect-buffer (&optional buffer)
6226 (setq buffer (or buffer (current-buffer)))
6227 (let ((n 1) (base (buffer-name buffer)) bname)
6228 (while (buffer-live-p
6229 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6232 (make-indirect-buffer buffer bname 'clone)
6233 (error (make-indirect-buffer buffer bname)))))
6235 (defun org-set-frame-title (title)
6236 "Set the title of the current frame to the string TITLE."
6237 ;; FIXME: how to name a single frame in XEmacs???
6238 (unless (featurep 'xemacs)
6239 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6241 ;;;; Structure editing
6243 ;;; Inserting headlines
6245 (defun org-previous-line-empty-p ()
6248 (or (beginning-of-line 0) t)
6250 (looking-at "[ \t]*$")))))
6252 (defun org-insert-heading (&optional force-heading invisible-ok)
6253 "Insert a new heading or item with same depth at point.
6254 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6255 If point is at the beginning of a headline, insert a sibling before the
6256 current headline. If point is not at the beginning, do not split the line,
6257 but create the new headline after the current line.
6258 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6259 This is important for non-interactive uses of the command."
6261 (if (or (= (buffer-size) 0)
6262 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6263 (org-on-heading-p))))
6264 (not (org-in-item-p))))
6266 (when (or force-heading (not (org-insert-item)))
6267 (let* ((empty-line-p nil)
6268 (head (save-excursion
6271 (org-back-to-heading invisible-ok)
6272 (setq empty-line-p (org-previous-line-empty-p))
6275 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6276 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6277 pos hide-previous previous-pos)
6279 ((and (org-on-heading-p) (bolp)
6281 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6282 ;; insert before the current line
6283 (open-line (if blank 2 1)))
6285 (not org-insert-heading-respect-content)
6288 (backward-char 1) (not (org-invisible-p)))))
6289 ;; insert right here
6292 ;; somewhere in the line
6294 (setq previous-pos (point-at-bol))
6296 (setq hide-previous (org-invisible-p)))
6297 (and org-insert-heading-respect-content (org-show-subtree))
6299 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6302 (goto-char (point-at-bol))
6303 (and (looking-at org-complex-heading-regexp)
6304 (> p (match-beginning 4)))))))
6307 (org-insert-heading-respect-content
6308 (org-end-of-subtree nil t)
6309 (or (bolp) (newline))
6310 (or (org-previous-line-empty-p)
6311 (and blank (newline)))
6317 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6318 (setq tags (and (match-end 2) (match-string 2)))
6320 (delete-region (match-beginning 1) (match-end 1)))
6321 (setq pos (point-at-bol))
6322 (or split (end-of-line 1))
6323 (delete-horizontal-space)
6324 (if (string-match "\\`\\*+\\'"
6325 (buffer-substring (point-at-bol) (point)))
6327 (newline (if blank 2 1))
6333 (org-set-tags nil 'align))))
6335 (or split (end-of-line 1))
6336 (newline (if blank 2 1)))))))
6337 (insert head) (just-one-space)
6340 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6341 (when (and org-insert-heading-respect-content hide-previous)
6343 (goto-char previous-pos)
6345 (run-hooks 'org-insert-heading-hook)))))
6347 (defun org-get-heading (&optional no-tags)
6348 "Return the heading of the current entry, without the stars."
6350 (org-back-to-heading t)
6353 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6354 "\\*+[ \t]+\\([^\r\n]*\\)"))
6355 (match-string 1) "")))
6357 (defun org-heading-components ()
6358 "Return the components of the current heading.
6359 This is a list with the following elements:
6360 - the level as an integer
6361 - the reduced level, different if `org-odd-levels-only' is set.
6362 - the TODO keyword, or nil
6363 - the priority character, like ?A, or nil if no priority is given
6364 - the headline text itself, or the tags string if no headline text
6365 - the tags string, or nil."
6367 (org-back-to-heading t)
6368 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6369 (list (length (match-string 1))
6370 (org-reduced-level (length (match-string 1)))
6371 (org-match-string-no-properties 2)
6372 (and (match-end 3) (aref (match-string 3) 2))
6373 (org-match-string-no-properties 4)
6374 (org-match-string-no-properties 5)))))
6376 (defun org-get-entry ()
6377 "Get the entry text, after heading, entire subtree."
6379 (org-back-to-heading t)
6380 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6382 (defun org-insert-heading-after-current ()
6383 "Insert a new heading with same level as current, after current subtree."
6385 (org-back-to-heading)
6386 (org-insert-heading)
6387 (org-move-subtree-down)
6390 (defun org-insert-heading-respect-content ()
6392 (let ((org-insert-heading-respect-content t))
6393 (org-insert-heading t)))
6395 (defun org-insert-todo-heading-respect-content (&optional force-state)
6397 (let ((org-insert-heading-respect-content t))
6398 (org-insert-todo-heading force-state t)))
6400 (defun org-insert-todo-heading (arg &optional force-heading)
6401 "Insert a new heading with the same level and TODO state as current heading.
6402 If the heading has no TODO state, or if the state is DONE, use the first
6403 state (TODO by default). Also with prefix arg, force first state."
6405 (when (or force-heading (not (org-insert-item 'checkbox)))
6406 (org-insert-heading force-heading)
6408 (org-back-to-heading)
6409 (outline-previous-heading)
6410 (looking-at org-todo-line-regexp))
6414 (not (match-beginning 2))
6415 (member (match-string 2) org-done-keywords))
6416 (car org-todo-keywords-1)
6420 (run-hook-with-args-until-success
6421 'org-todo-get-default-hook new-mark-x nil)
6423 (beginning-of-line 1)
6424 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6425 (if org-treat-insert-todo-heading-as-state-change
6427 (insert new-mark " "))))
6428 (when org-provide-todo-statistics
6429 (org-update-parent-todo-statistics))))
6431 (defun org-insert-subheading (arg)
6432 "Insert a new subheading and demote it.
6433 Works for outline headings and for plain lists alike."
6435 (org-insert-heading arg)
6437 ((org-on-heading-p) (org-do-demote))
6438 ((org-at-item-p) (org-indent-item 1))))
6440 (defun org-insert-todo-subheading (arg)
6441 "Insert a new subheading with TODO keyword or checkbox and demote it.
6442 Works for outline headings and for plain lists alike."
6444 (org-insert-todo-heading arg)
6446 ((org-on-heading-p) (org-do-demote))
6447 ((org-at-item-p) (org-indent-item 1))))
6449 ;;; Promotion and Demotion
6451 (defvar org-after-demote-entry-hook nil
6452 "Hook run after an entry has been demoted.
6453 The cursor will be at the beginning of the entry.
6454 When a subtree is being demoted, the hook will be called for each node.")
6456 (defvar org-after-promote-entry-hook nil
6457 "Hook run after an entry has been promoted.
6458 The cursor will be at the beginning of the entry.
6459 When a subtree is being promoted, the hook will be called for each node.")
6461 (defun org-promote-subtree ()
6462 "Promote the entire subtree.
6463 See also `org-promote'."
6466 (org-map-tree 'org-promote))
6467 (org-fix-position-after-promote))
6469 (defun org-demote-subtree ()
6470 "Demote the entire subtree. See `org-demote'.
6471 See also `org-promote'."
6474 (org-map-tree 'org-demote))
6475 (org-fix-position-after-promote))
6478 (defun org-do-promote ()
6479 "Promote the current heading higher up the tree.
6480 If the region is active in `transient-mark-mode', promote all headings
6484 (if (org-region-active-p)
6485 (org-map-region 'org-promote (region-beginning) (region-end))
6487 (org-fix-position-after-promote))
6489 (defun org-do-demote ()
6490 "Demote the current heading lower down the tree.
6491 If the region is active in `transient-mark-mode', demote all headings
6495 (if (org-region-active-p)
6496 (org-map-region 'org-demote (region-beginning) (region-end))
6498 (org-fix-position-after-promote))
6500 (defun org-fix-position-after-promote ()
6501 "Make sure that after pro/demotion cursor position is right."
6502 (let ((pos (point)))
6503 (when (save-excursion
6504 (beginning-of-line 1)
6505 (looking-at org-todo-line-regexp)
6506 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6507 (cond ((eobp) (insert " "))
6508 ((eolp) (insert " "))
6509 ((equal (char-after) ?\ ) (forward-char 1))))))
6511 (defun org-current-level ()
6512 "Return the level of the current entry, or nil if before the first headline.
6513 The level is the number of stars at the beginning of the headline."
6517 (org-back-to-heading t)
6518 (funcall outline-level))
6521 (defun org-get-previous-line-level ()
6522 "Return the outline depth of the last headline before the current line.
6523 Returns 0 for the first headline in the buffer, and nil if before the
6525 (let ((current-level (org-current-level))
6526 (prev-level (when (> (line-number-at-pos) 1)
6528 (beginning-of-line 0)
6529 (org-current-level)))))
6530 (cond ((null current-level) nil) ; Before first headline
6531 ((null prev-level) 0) ; At first headline
6534 (defun org-reduced-level (l)
6535 "Compute the effective level of a heading.
6536 This takes into account the setting of `org-odd-levels-only'."
6537 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6539 (defun org-level-increment ()
6540 "Return the number of stars that will be added or removed at a
6541 time to headlines when structure editing, based on the value of
6542 `org-odd-levels-only'."
6543 (if org-odd-levels-only 2 1))
6545 (defun org-get-valid-level (level &optional change)
6546 "Rectify a level change under the influence of `org-odd-levels-only'
6547 LEVEL is a current level, CHANGE is by how much the level should be
6548 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6549 even level numbers will become the next higher odd number."
6550 (if org-odd-levels-only
6551 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6552 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6553 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6554 (max 1 (+ level (or change 0)))))
6556 (if (boundp 'define-obsolete-function-alias)
6557 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6558 (define-obsolete-function-alias 'org-get-legal-level
6559 'org-get-valid-level)
6560 (define-obsolete-function-alias 'org-get-legal-level
6561 'org-get-valid-level "23.1")))
6563 (defun org-promote ()
6564 "Promote the current heading higher up the tree.
6565 If the region is active in `transient-mark-mode', promote all headings
6567 (org-back-to-heading t)
6568 (let* ((level (save-match-data (funcall outline-level)))
6569 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6570 (diff (abs (- level (length up-head) -1))))
6571 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6572 (replace-match up-head nil t)
6573 ;; Fixup tag positioning
6574 (and org-auto-align-tags (org-set-tags nil t))
6575 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6576 (run-hooks 'org-after-promote-entry-hook)))
6578 (defun org-demote ()
6579 "Demote the current heading lower down the tree.
6580 If the region is active in `transient-mark-mode', demote all headings
6582 (org-back-to-heading t)
6583 (let* ((level (save-match-data (funcall outline-level)))
6584 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6585 (diff (abs (- level (length down-head) -1))))
6586 (replace-match down-head nil t)
6587 ;; Fixup tag positioning
6588 (and org-auto-align-tags (org-set-tags nil t))
6589 (if org-adapt-indentation (org-fixup-indentation diff))
6590 (run-hooks 'org-after-demote-entry-hook)))
6592 (defun org-cycle-level ()
6593 "Cycle the level of an empty headline through possible states.
6594 This goes first to child, then to parent, level, then up the hierarchy.
6595 After top level, it switches back to sibling level."
6597 (let ((org-adapt-indentation nil))
6598 (when (org-point-at-end-of-empty-headline)
6599 (setq this-command 'org-cycle-level) ; Only needed for caching
6600 (let ((cur-level (org-current-level))
6601 (prev-level (org-get-previous-line-level)))
6603 ;; If first headline in file, promote to top-level.
6605 (loop repeat (/ (- cur-level 1) (org-level-increment))
6606 do (org-do-promote)))
6607 ;; If same level as prev, demote one.
6608 ((= prev-level cur-level)
6610 ;; If parent is top-level, promote to top level if not already.
6612 (loop repeat (/ (- cur-level 1) (org-level-increment))
6613 do (org-do-promote)))
6614 ;; If top-level, return to prev-level.
6616 (loop repeat (/ (- prev-level 1) (org-level-increment))
6617 do (org-do-demote)))
6618 ;; If less than prev-level, promote one.
6619 ((< cur-level prev-level)
6621 ;; If deeper than prev-level, promote until higher than
6623 ((> cur-level prev-level)
6624 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6625 do (org-do-promote))))
6628 (defun org-map-tree (fun)
6629 "Call FUN for every heading underneath the current one."
6630 (org-back-to-heading)
6631 (let ((level (funcall outline-level)))
6635 (outline-next-heading)
6636 (> (funcall outline-level) level))
6640 (defun org-map-region (fun beg end)
6641 "Call FUN for every heading between BEG and END."
6642 (let ((org-ignore-region t))
6644 (setq end (copy-marker end))
6646 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6650 (outline-next-heading)
6655 (defun org-fixup-indentation (diff)
6656 "Change the indentation in the current entry by DIFF
6657 However, if any line in the current entry has no indentation, or if it
6658 would end up with no indentation after the change, nothing at all is done."
6660 (let ((end (save-excursion (outline-next-heading)
6662 (prohibit (if (> diff 0)
6664 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6666 (unless (save-excursion (end-of-line 1)
6667 (re-search-forward prohibit end t))
6668 (while (and (< (point) end)
6669 (re-search-forward "^[ \t]+" end t))
6670 (goto-char (match-end 0))
6671 (setq col (current-column))
6672 (if (< diff 0) (replace-match ""))
6673 (org-indent-to-column (+ diff col))))
6674 (move-marker end nil))))
6676 (defun org-convert-to-odd-levels ()
6677 "Convert an org-mode file with all levels allowed to one with odd levels.
6678 This will leave level 1 alone, convert level 2 to level 3, level 3 to
6681 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
6682 (let ((outline-regexp org-outline-regexp)
6683 (outline-level 'org-outline-level)
6684 (org-odd-levels-only nil) n)
6686 (goto-char (point-min))
6687 (while (re-search-forward "^\\*\\*+ " nil t)
6688 (setq n (- (length (match-string 0)) 2))
6689 (while (>= (setq n (1- n)) 0)
6691 (end-of-line 1))))))
6693 (defun org-convert-to-oddeven-levels ()
6694 "Convert an org-mode file with only odd levels to one with odd and even levels.
6695 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
6696 section with an even level, conversion would destroy the structure of the file. An error
6697 is signaled in this case."
6699 (goto-char (point-min))
6700 ;; First check if there are no even levels
6701 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
6702 (org-show-context t)
6703 (error "Not all levels are odd in this file. Conversion not possible"))
6704 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
6705 (let ((outline-regexp org-outline-regexp)
6706 (outline-level 'org-outline-level)
6707 (org-odd-levels-only nil) n)
6709 (goto-char (point-min))
6710 (while (re-search-forward "^\\*\\*+ " nil t)
6711 (setq n (/ (1- (length (match-string 0))) 2))
6712 (while (>= (setq n (1- n)) 0)
6714 (end-of-line 1))))))
6716 (defun org-tr-level (n)
6717 "Make N odd if required."
6718 (if org-odd-levels-only (1+ (/ n 2)) n))
6720 ;;; Vertical tree motion, cutting and pasting of subtrees
6722 (defun org-move-subtree-up (&optional arg)
6723 "Move the current subtree up past ARG headlines of the same level."
6725 (org-move-subtree-down (- (prefix-numeric-value arg))))
6727 (defun org-move-subtree-down (&optional arg)
6728 "Move the current subtree down past ARG headlines of the same level."
6730 (setq arg (prefix-numeric-value arg))
6731 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
6732 'org-get-last-sibling))
6733 (ins-point (make-marker))
6735 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
6737 (org-back-to-heading)
6740 (setq ne-beg (org-back-over-empty-lines))
6743 (save-excursion (outline-end-of-heading)
6744 (setq folded (org-invisible-p)))
6745 (outline-end-of-subtree))
6746 (outline-next-heading)
6747 (setq ne-end (org-back-over-empty-lines))
6750 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
6751 ;; include less whitespace
6754 (forward-line (- ne-beg ne-end))
6755 (setq beg (point))))
6756 ;; Find insertion point, with error handling
6758 (or (and (funcall movfunc) (looking-at outline-regexp))
6759 (progn (goto-char beg0)
6760 (error "Cannot move past superior level or buffer limit")))
6761 (setq cnt (1- cnt)))
6763 ;; Moving forward - still need to move over subtree
6764 (progn (org-end-of-subtree t t)
6766 (org-back-over-empty-lines)
6767 (or (bolp) (newline)))))
6768 (setq ne-ins (org-back-over-empty-lines))
6769 (move-marker ins-point (point))
6770 (setq txt (buffer-substring beg end))
6771 (org-save-markers-in-region beg end)
6772 (delete-region beg end)
6773 (org-remove-empty-overlays-at beg)
6774 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
6775 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
6776 (and (not (bolp)) (looking-at "\n") (forward-char 1))
6777 (let ((bbb (point)))
6778 (insert-before-markers txt)
6779 (org-reinstall-markers-in-region bbb)
6780 (move-marker ins-point bbb))
6781 (or (bolp) (insert "\n"))
6782 (setq ins-end (point))
6783 (goto-char ins-point)
6784 (org-skip-whitespace)
6785 (when (and (< arg 0)
6786 (org-first-sibling-p)
6788 ;; Move whitespace back to beginning
6791 (let ((kill-whole-line t))
6792 (kill-line (- ne-ins ne-beg)) (point)))
6793 (insert (make-string (- ne-ins ne-beg) ?\n)))
6794 (move-marker ins-point nil)
6799 (org-cycle-hide-drawers 'children))
6800 (org-clean-visibility-after-subtree-move)))
6802 (defvar org-subtree-clip ""
6803 "Clipboard for cut and paste of subtrees.
6804 This is actually only a copy of the kill, because we use the normal kill
6805 ring. We need it to check if the kill was created by `org-copy-subtree'.")
6807 (defvar org-subtree-clip-folded nil
6808 "Was the last copied subtree folded?
6809 This is used to fold the tree back after pasting.")
6811 (defun org-cut-subtree (&optional n)
6812 "Cut the current subtree into the clipboard.
6813 With prefix arg N, cut this many sequential subtrees.
6814 This is a short-hand for marking the subtree and then cutting it."
6816 (org-copy-subtree n 'cut))
6818 (defun org-copy-subtree (&optional n cut force-store-markers)
6819 "Cut the current subtree into the clipboard.
6820 With prefix arg N, cut this many sequential subtrees.
6821 This is a short-hand for marking the subtree and then copying it.
6822 If CUT is non-nil, actually cut the subtree.
6823 If FORCE-STORE-MARKERS is non-nil, store the relative locations
6824 of some markers in the region, even if CUT is non-nil. This is
6825 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
6827 (let (beg end folded (beg0 (point)))
6829 (org-back-to-heading nil) ; take what looks like a subtree
6830 (org-back-to-heading t)) ; take what is really there
6831 (org-back-over-empty-lines)
6833 (skip-chars-forward " \t\r\n")
6835 (save-excursion (outline-end-of-heading)
6836 (setq folded (org-invisible-p)))
6838 (org-forward-same-level (1- n) t)
6840 (org-end-of-subtree t t))
6841 (org-back-over-empty-lines)
6845 (setq org-subtree-clip-folded folded)
6846 (when (or cut force-store-markers)
6847 (org-save-markers-in-region beg end))
6848 (if cut (kill-region beg end) (copy-region-as-kill beg end))
6849 (setq org-subtree-clip (current-kill 0))
6850 (message "%s: Subtree(s) with %d characters"
6851 (if cut "Cut" "Copied")
6852 (length org-subtree-clip)))))
6854 (defun org-paste-subtree (&optional level tree for-yank)
6855 "Paste the clipboard as a subtree, with modification of headline level.
6856 The entire subtree is promoted or demoted in order to match a new headline
6859 If the cursor is at the beginning of a headline, the same level as
6860 that headline is used to paste the tree
6862 If not, the new level is derived from the *visible* headings
6863 before and after the insertion point, and taken to be the inferior headline
6864 level of the two. So if the previous visible heading is level 3 and the
6865 next is level 4 (or vice versa), level 4 will be used for insertion.
6866 This makes sure that the subtree remains an independent subtree and does
6867 not swallow low level entries.
6869 You can also force a different level, either by using a numeric prefix
6870 argument, or by inserting the heading marker by hand. For example, if the
6871 cursor is after \"*****\", then the tree will be shifted to level 5.
6873 If optional TREE is given, use this text instead of the kill ring.
6875 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
6876 move back over whitespace before inserting, and move point to the end of
6877 the inserted text when done."
6879 (setq tree (or tree (and kill-ring (current-kill 0))))
6880 (unless (org-kill-is-subtree-p tree)
6882 (substitute-command-keys
6883 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
6884 (let* ((visp (not (org-invisible-p)))
6886 (^re (concat "^\\(" outline-regexp "\\)"))
6887 (re (concat "\\(" outline-regexp "\\)"))
6888 (^re_ (concat "\\(\\*+\\)[ \t]*"))
6890 (old-level (if (string-match ^re txt)
6891 (- (match-end 0) (match-beginning 0) 1)
6893 (force-level (cond (level (prefix-numeric-value level))
6894 ((and (looking-at "[ \t]*$")
6896 ^re_ (buffer-substring
6897 (point-at-bol) (point))))
6898 (- (match-end 1) (match-beginning 1)))
6900 (looking-at org-outline-regexp))
6901 (- (match-end 0) (point) 1))
6903 (previous-level (save-excursion
6906 (outline-previous-visible-heading 1)
6908 (- (match-end 0) (match-beginning 0) 1)
6911 (next-level (save-excursion
6914 (or (looking-at outline-regexp)
6915 (outline-next-visible-heading 1))
6917 (- (match-end 0) (match-beginning 0) 1)
6920 (new-level (or force-level (max previous-level next-level)))
6921 (shift (if (or (= old-level -1)
6923 (= old-level new-level))
6925 (- new-level old-level)))
6926 (delta (if (> shift 0) -1 1))
6927 (func (if (> shift 0) 'org-demote 'org-promote))
6928 (org-odd-levels-only nil)
6930 ;; Remove the forced level indicator
6932 (delete-region (point-at-bol) (point)))
6934 (beginning-of-line 1)
6935 (unless for-yank (org-back-over-empty-lines))
6937 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
6938 (insert-before-markers txt)
6939 (unless (string-match "\n\\'" txt) (insert "\n"))
6940 (setq newend (point))
6941 (org-reinstall-markers-in-region beg)
6944 (skip-chars-forward " \t\n\r")
6946 (if (and (org-invisible-p) visp)
6947 (save-excursion (outline-show-heading)))
6948 ;; Shift if necessary
6951 (narrow-to-region beg end)
6952 (while (not (= shift 0))
6953 (org-map-region func (point-min) (point-max))
6954 (setq shift (+ delta shift)))
6955 (goto-char (point-min))
6956 (setq newend (point-max))))
6957 (when (or (interactive-p) for-yank)
6958 (message "Clipboard pasted as level %d subtree" new-level))
6959 (if (and (not for-yank) ; in this case, org-yank will decide about folding
6961 (eq org-subtree-clip (current-kill 0))
6962 org-subtree-clip-folded)
6963 ;; The tree was folded before it was killed/copied
6965 (and for-yank (goto-char newend))))
6967 (defun org-kill-is-subtree-p (&optional txt)
6968 "Check if the current kill is an outline subtree, or a set of trees.
6969 Returns nil if kill does not start with a headline, or if the first
6970 headline level is not the largest headline level in the tree.
6971 So this will actually accept several entries of equal levels as well,
6972 which is OK for `org-paste-subtree'.
6973 If optional TXT is given, check this string instead of the current kill."
6974 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
6975 (start-level (and kill
6976 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
6977 org-outline-regexp "\\)")
6979 (- (match-end 2) (match-beginning 2) 1)))
6980 (re (concat "^" org-outline-regexp))
6981 (start (1+ (or (match-beginning 2) -1))))
6982 (if (not start-level)
6984 nil) ;; does not even start with a heading
6986 (while (setq start (string-match re kill (1+ start)))
6987 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
6991 (defvar org-markers-to-move nil
6992 "Markers that should be moved with a cut-and-paste operation.
6993 Those markers are stored together with their positions relative to
6994 the start of the region.")
6996 (defun org-save-markers-in-region (beg end)
6997 "Check markers in region.
6998 If these markers are between BEG and END, record their position relative
6999 to BEG, so that after moving the block of text, we can put the markers back
7001 This function gets called just before an entry or tree gets cut from the
7002 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7003 called immediately, to move the markers with the entries."
7004 (setq org-markers-to-move nil)
7005 (when (featurep 'org-clock)
7006 (org-clock-save-markers-for-cut-and-paste beg end))
7007 (when (featurep 'org-agenda)
7008 (org-agenda-save-markers-for-cut-and-paste beg end)))
7010 (defun org-check-and-save-marker (marker beg end)
7011 "Check if MARKER is between BEG and END.
7012 If yes, remember the marker and the distance to BEG."
7013 (when (and (marker-buffer marker)
7014 (equal (marker-buffer marker) (current-buffer)))
7015 (if (and (>= marker beg) (< marker end))
7016 (push (cons marker (- marker beg)) org-markers-to-move))))
7018 (defun org-reinstall-markers-in-region (beg)
7019 "Move all remembered markers to their position relative to BEG."
7021 (move-marker (car x) (+ beg (cdr x))))
7022 org-markers-to-move)
7023 (setq org-markers-to-move nil))
7025 (defun org-narrow-to-subtree ()
7026 "Narrow buffer to the current subtree."
7031 (progn (org-back-to-heading t) (point))
7032 (progn (org-end-of-subtree t t)
7033 (if (org-on-heading-p) (backward-char 1))
7036 (defun org-clone-subtree-with-time-shift (n &optional shift)
7037 "Clone the task (subtree) at point N times.
7038 The clones will be inserted as siblings.
7040 In interactive use, the user will be prompted for the number of clones
7041 to be produced, and for a time SHIFT, which may be a repeater as used
7042 in time stamps, for example `+3d'.
7044 When a valid repeater is given and the entry contains any time stamps,
7045 the clones will become a sequence in time, with time stamps in the
7046 subtree shifted for each clone produced. If SHIFT is nil or the
7047 empty string, time stamps will be left alone.
7049 If the original subtree did contain time stamps with a repeater,
7050 the following will happen:
7051 - the repeater will be removed in each clone
7052 - an additional clone will be produced, with the current, unshifted
7053 date(s) in the entry.
7054 - the original entry will be placed *after* all the clones, with
7056 - the start days in the repeater in the original entry will be shifted
7057 to past the last clone.
7058 I this way you can spell out a number of instances of a repeating task,
7059 and still retain the repeater to cover future instances of the task."
7060 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7061 (let (beg end template task
7062 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7063 (if (not (and (integerp n) (> n 0)))
7064 (error "Invalid number of replications %s" n))
7065 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7066 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7068 (error "Invalid shift specification %s" shift))
7070 (setq shift-n (string-to-number (match-string 1 shift))
7071 shift-what (cdr (assoc (match-string 2 shift)
7072 '(("d" . day) ("w" . week)
7073 ("m" . month) ("y" . year))))))
7074 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7075 (setq nmin 1 nmax n)
7076 (org-back-to-heading t)
7078 (org-end-of-subtree t t)
7079 (or (bolp) (insert "\n"))
7081 (setq template (buffer-substring beg end))
7083 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7084 (delete-region beg end)
7086 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7088 (loop for n from nmin to nmax do
7090 (setq task template)
7094 (goto-char (point-min))
7095 (while (re-search-forward org-ts-regexp-both nil t)
7096 (org-timestamp-change (* n shift-n) shift-what))
7097 (unless (= n n-no-remove)
7098 (goto-char (point-min))
7099 (while (re-search-forward org-ts-regexp nil t)
7101 (goto-char (match-beginning 0))
7102 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7103 (delete-region (match-beginning 1) (match-end 1))))))
7104 (setq task (buffer-string))))
7110 (defun org-sort (with-case)
7111 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7112 Optional argument WITH-CASE means sort case-sensitively.
7113 With a double prefix argument, also remove duplicate entries."
7115 (if (org-at-table-p)
7116 (org-call-with-arg 'org-table-sort-lines with-case)
7117 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7119 (defun org-sort-remove-invisible (s)
7120 (remove-text-properties 0 (length s) org-rm-props s)
7121 (while (string-match org-bracket-link-regexp s)
7122 (setq s (replace-match (if (match-end 2)
7124 (match-string 1 s)) t t s)))
7127 (defvar org-priority-regexp) ; defined later in the file
7129 (defvar org-after-sorting-entries-or-items-hook nil
7130 "Hook that is run after a bunch of entries or items have been sorted.
7131 When children are sorted, the cursor is in the parent line when this
7132 hook gets called. When a region or a plain list is sorted, the cursor
7133 will be in the first entry of the sorted region/list.")
7135 (defun org-sort-entries-or-items
7136 (&optional with-case sorting-type getkey-func compare-func property)
7137 "Sort entries on a certain level of an outline tree, or plain list items.
7138 If there is an active region, the entries in the region are sorted.
7139 Else, if the cursor is before the first entry, sort the top-level items.
7140 Else, the children of the entry at point are sorted.
7141 If the cursor is at the first item in a plain list, the list items will be
7144 Sorting can be alphabetically, numerically, by date/time as given by
7145 a time stamp, by a property or by priority.
7147 The command prompts for the sorting type unless it has been given to the
7148 function through the SORTING-TYPE argument, which needs to a character,
7149 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7150 precise meaning of each character:
7152 n Numerically, by converting the beginning of the entry/item to a number.
7153 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7154 t By date/time, either the first active time stamp in the entry, or, if
7155 none exist, by the first inactive one.
7156 In items, only the first line will be checked.
7157 s By the scheduled date/time.
7158 d By deadline date/time.
7159 c By creation time, which is assumed to be the first inactive time stamp
7160 at the beginning of a line.
7161 p By priority according to the cookie.
7162 r By the value of a property.
7164 Capital letters will reverse the sort order.
7166 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7167 called with point at the beginning of the record. It must return either
7168 a string or a number that should serve as the sorting key for that record.
7170 Comparing entries ignores case by default. However, with an optional argument
7171 WITH-CASE, the sorting considers case as well."
7173 (let ((case-func (if with-case 'identity 'downcase))
7174 start beg end stars re re2
7175 txt what tmp plain-list-p)
7176 ;; Find beginning and end of region to sort
7178 ((org-region-active-p)
7179 ;; we will sort the region
7180 (setq end (region-end)
7182 (goto-char (region-beginning))
7183 (if (not (org-on-heading-p)) (outline-next-heading))
7184 (setq start (point)))
7186 ;; we will sort this plain list
7187 (org-beginning-of-item-list) (setq start (point))
7188 (org-end-of-item-list)
7189 (or (bolp) (insert "\n"))
7192 (setq plain-list-p t
7194 ((or (org-on-heading-p)
7195 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7196 ;; we will sort the children of the current headline
7197 (org-back-to-heading)
7199 end (progn (org-end-of-subtree t t)
7200 (or (bolp) (insert "\n"))
7201 (org-back-over-empty-lines)
7206 (outline-next-heading))
7208 ;; we will sort the top-level entries in this file
7209 (goto-char (point-min))
7210 (or (org-on-heading-p) (outline-next-heading))
7211 (setq start (point))
7212 (goto-char (point-max))
7213 (beginning-of-line 1)
7214 (when (looking-at ".*?\\S-")
7215 ;; File ends in a non-white line
7218 (setq end (point-max))
7219 (setq what "top-level")
7224 (if (>= beg end) (error "Nothing to sort"))
7226 (unless plain-list-p
7227 (looking-at "\\(\\*+\\)")
7228 (setq stars (match-string 1)
7229 re (concat "^" (regexp-quote stars) " +")
7230 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7231 txt (buffer-substring beg end))
7232 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7233 (if (and (not (equal stars "*")) (string-match re2 txt))
7234 (error "Region to sort contains a level above the first entry")))
7236 (unless sorting-type
7239 "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
7240 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7241 [t]ime [s]cheduled [d]eadline [c]reated
7242 A/N/T/S/D/C/P/O/F means reversed:")
7244 (setq sorting-type (read-char-exclusive))
7246 (and (= (downcase sorting-type) ?f)
7248 (org-icompleting-read "Sort using function: "
7249 obarray 'fboundp t nil nil))
7250 (setq getkey-func (intern getkey-func)))
7252 (and (= (downcase sorting-type) ?r)
7254 (org-icompleting-read "Property: "
7255 (mapcar 'list (org-buffer-property-keys t))
7258 (message "Sorting entries...")
7261 (narrow-to-region start end)
7263 (let ((dcst (downcase sorting-type))
7264 (case-fold-search nil)
7265 (now (current-time)))
7267 (/= dcst sorting-type)
7268 ;; This function moves to the beginning character of the "record" to
7272 (if (org-at-item-p) t (goto-char (point-max))))
7274 (if (re-search-forward re nil t)
7275 (goto-char (match-beginning 0))
7276 (goto-char (point-max)))))
7277 ;; This function moves to the last character of the "record" being
7284 (outline-forward-same-level 1)
7286 (goto-char (point-max)))))))
7288 ;; This function returns the value that gets sorted against.
7291 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7294 (string-to-number (buffer-substring (match-end 0)
7297 (buffer-substring (match-end 0) (point-at-eol)))
7299 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7300 (re-search-forward org-ts-regexp-both
7302 (org-time-string-to-seconds (match-string 0))
7303 (org-float-time now)))
7307 (setq tmp (funcall getkey-func))
7308 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7310 (error "Invalid key function `%s'" getkey-func)))
7311 (t (error "Invalid sorting type `%c'" sorting-type)))))
7315 (if (looking-at org-complex-heading-regexp)
7316 (string-to-number (match-string 4))
7319 (if (looking-at org-complex-heading-regexp)
7320 (funcall case-func (match-string 4))
7323 (let ((end (save-excursion (outline-next-heading) (point))))
7324 (if (or (re-search-forward org-ts-regexp end t)
7325 (re-search-forward org-ts-regexp-both end t))
7326 (org-time-string-to-seconds (match-string 0))
7327 (org-float-time now))))
7329 (let ((end (save-excursion (outline-next-heading) (point))))
7330 (if (re-search-forward
7331 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7333 (org-time-string-to-seconds (match-string 0))
7334 (org-float-time now))))
7336 (let ((end (save-excursion (outline-next-heading) (point))))
7337 (if (re-search-forward org-scheduled-time-regexp end t)
7338 (org-time-string-to-seconds (match-string 1))
7339 (org-float-time now))))
7341 (let ((end (save-excursion (outline-next-heading) (point))))
7342 (if (re-search-forward org-deadline-time-regexp end t)
7343 (org-time-string-to-seconds (match-string 1))
7344 (org-float-time now))))
7346 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7347 (string-to-char (match-string 2))
7348 org-default-priority))
7350 (or (org-entry-get nil property) ""))
7352 (if (looking-at org-complex-heading-regexp)
7353 (- 9999 (length (member (match-string 2)
7354 org-todo-keywords-1)))))
7358 (setq tmp (funcall getkey-func))
7359 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7361 (error "Invalid key function `%s'" getkey-func)))
7362 (t (error "Invalid sorting type `%c'" sorting-type)))))
7365 ((= dcst ?a) 'string<)
7366 ((= dcst ?f) compare-func)
7367 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7369 (run-hooks 'org-after-sorting-entries-or-items-hook)
7370 (message "Sorting entries...done")))
7372 (defun org-do-sort (table what &optional with-case sorting-type)
7373 "Sort TABLE of WHAT according to SORTING-TYPE.
7374 The user will be prompted for the SORTING-TYPE if the call to this
7375 function does not specify it. WHAT is only for the prompt, to indicate
7376 what is being sorted. The sorting key will be extracted from
7377 the car of the elements of the table.
7378 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7379 (unless sorting-type
7381 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
7383 (setq sorting-type (read-char-exclusive)))
7384 (let ((dcst (downcase sorting-type))
7385 extractfun comparefun)
7386 ;; Define the appropriate functions
7389 (setq extractfun 'string-to-number
7390 comparefun (if (= dcst sorting-type) '< '>)))
7392 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7393 (lambda(x) (downcase (org-sort-remove-invisible x))))
7394 comparefun (if (= dcst sorting-type)
7396 (lambda (a b) (and (not (string< a b))
7397 (not (string= a b)))))))
7401 (if (or (string-match org-ts-regexp x)
7402 (string-match org-ts-regexp-both x))
7404 (org-time-string-to-time (match-string 0 x)))
7406 comparefun (if (= dcst sorting-type) '< '>)))
7407 (t (error "Invalid sorting type `%c'" sorting-type)))
7409 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7411 (lambda (a b) (funcall comparefun (car a) (car b))))))
7414 ;;; The orgstruct minor mode
7416 ;; Define a minor mode which can be used in other modes in order to
7417 ;; integrate the org-mode structure editing commands.
7419 ;; This is really a hack, because the org-mode structure commands use
7420 ;; keys which normally belong to the major mode. Here is how it
7421 ;; works: The minor mode defines all the keys necessary to operate the
7422 ;; structure commands, but wraps the commands into a function which
7423 ;; tests if the cursor is currently at a headline or a plain list
7424 ;; item. If that is the case, the structure command is used,
7425 ;; temporarily setting many Org-mode variables like regular
7426 ;; expressions for filling etc. However, when any of those keys is
7427 ;; used at a different location, function uses `key-binding' to look
7428 ;; up if the key has an associated command in another currently active
7429 ;; keymap (minor modes, major mode, global), and executes that
7430 ;; command. There might be problems if any of the keys is otherwise
7431 ;; used as a prefix key.
7433 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7434 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7435 ;; addresses this by checking explicitly for both bindings.
7437 (defvar orgstruct-mode-map (make-sparse-keymap)
7438 "Keymap for the minor `orgstruct-mode'.")
7440 (defvar org-local-vars nil
7441 "List of local variables, for use by `orgstruct-mode'")
7444 (define-minor-mode orgstruct-mode
7445 "Toggle the minor more `orgstruct-mode'.
7446 This mode is for using Org-mode structure commands in other modes.
7447 The following key behave as if Org-mode was active, if the cursor
7448 is on a headline, or on a plain list item (both in the definition
7451 M-up Move entry/item up
7452 M-down Move entry/item down
7455 M-S-up Move entry/item up
7456 M-S-down Move entry/item down
7457 M-S-left Promote subtree
7458 M-S-right Demote subtree
7459 M-q Fill paragraph and items like in Org-mode
7461 C-c - Cycle list bullet
7462 TAB Cycle item visibility
7463 M-RET Insert new heading/item
7464 S-M-RET Insert new TODO heading / Checkbox item
7465 C-c C-c Set tags / toggle checkbox"
7466 nil " OrgStruct" nil
7467 (org-load-modules-maybe)
7468 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7471 (defun turn-on-orgstruct ()
7472 "Unconditionally turn on `orgstruct-mode'."
7475 (defun orgstruct++-mode (&optional arg)
7476 "Toggle `orgstruct-mode', the enhanced version of it.
7477 In addition to setting orgstruct-mode, this also exports all indentation
7478 and autofilling variables from org-mode into the buffer. It will also
7479 recognize item context in multiline items.
7480 Note that turning off orgstruct-mode will *not* remove the
7481 indentation/paragraph settings. This can only be done by refreshing the
7482 major mode, for example with \\[normal-mode]."
7484 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7492 "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7493 (symbol-name (car x)))
7494 (setq var (car x) val (nth 1 x))
7495 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7497 (org-set-local 'orgstruct-is-++ t))))
7499 (defvar orgstruct-is-++ nil
7500 "Is orgstruct-mode in ++ version in the current-buffer?")
7501 (make-variable-buffer-local 'orgstruct-is-++)
7504 (defun turn-on-orgstruct++ ()
7505 "Unconditionally turn on `orgstruct++-mode'."
7506 (orgstruct++-mode 1))
7508 (defun orgstruct-error ()
7509 "Error when there is no default binding for a structure key."
7511 (error "This key has no function outside structure elements"))
7513 (defun orgstruct-setup ()
7514 "Setup orgstruct keymaps."
7518 '([(meta up)] org-metaup)
7519 '([(meta down)] org-metadown)
7520 '([(meta left)] org-metaleft)
7521 '([(meta right)] org-metaright)
7522 '([(meta shift up)] org-shiftmetaup)
7523 '([(meta shift down)] org-shiftmetadown)
7524 '([(meta shift left)] org-shiftmetaleft)
7525 '([(meta shift right)] org-shiftmetaright)
7526 '([?\e (up)] org-metaup)
7527 '([?\e (down)] org-metadown)
7528 '([?\e (left)] org-metaleft)
7529 '([?\e (right)] org-metaright)
7530 '([?\e (shift up)] org-shiftmetaup)
7531 '([?\e (shift down)] org-shiftmetadown)
7532 '([?\e (shift left)] org-shiftmetaleft)
7533 '([?\e (shift right)] org-shiftmetaright)
7534 '([(shift up)] org-shiftup)
7535 '([(shift down)] org-shiftdown)
7536 '([(shift left)] org-shiftleft)
7537 '([(shift right)] org-shiftright)
7538 '("\C-c\C-c" org-ctrl-c-ctrl-c)
7539 '("\M-q" fill-paragraph)
7541 '("\C-c-" org-cycle-list-bullet)))
7543 (while (setq elt (pop bindings))
7544 (setq nfunc (1+ nfunc))
7545 (setq key (org-key (car elt))
7547 cmd (orgstruct-make-binding fun nfunc key))
7548 (org-defkey orgstruct-mode-map key cmd))
7550 ;; Special treatment needed for TAB and RET
7551 (org-defkey orgstruct-mode-map [(tab)]
7552 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
7553 (org-defkey orgstruct-mode-map "\C-i"
7554 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
7556 (org-defkey orgstruct-mode-map "\M-\C-m"
7557 (orgstruct-make-binding 'org-insert-heading 105
7558 "\M-\C-m" [(meta return)]))
7559 (org-defkey orgstruct-mode-map [(meta return)]
7560 (orgstruct-make-binding 'org-insert-heading 106
7561 [(meta return)] "\M-\C-m"))
7563 (org-defkey orgstruct-mode-map [(shift meta return)]
7564 (orgstruct-make-binding 'org-insert-todo-heading 107
7565 [(meta return)] "\M-\C-m"))
7567 (org-defkey orgstruct-mode-map "\e\C-m"
7568 (orgstruct-make-binding 'org-insert-heading 108
7569 "\e\C-m" [?\e (return)]))
7570 (org-defkey orgstruct-mode-map [?\e (return)]
7571 (orgstruct-make-binding 'org-insert-heading 109
7572 [?\e (return)] "\e\C-m"))
7573 (org-defkey orgstruct-mode-map [?\e (shift return)]
7574 (orgstruct-make-binding 'org-insert-todo-heading 110
7575 [?\e (return)] "\e\C-m"))
7577 (unless org-local-vars
7578 (setq org-local-vars (org-get-local-variables)))
7582 (defun orgstruct-make-binding (fun n &rest keys)
7583 "Create a function for binding in the structure minor mode.
7584 FUN is the command to call inside a table. N is used to create a unique
7585 command name. KEYS are keys that should be checked in for a command
7586 to execute outside of tables."
7589 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
7591 (concat "In Structure, run `" (symbol-name fun) "'.\n"
7592 "Outside of structure, run the binding of `"
7593 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
7597 `(org-context-p 'headline 'item
7598 (and orgstruct-is-++
7599 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7601 (list 'org-run-like-in-org-mode (list 'quote fun))
7602 (list 'let '(orgstruct-mode)
7603 (list 'call-interactively
7606 (list 'key-binding k))
7608 '('orgstruct-error))))))))
7610 (defun org-context-p (&rest contexts)
7611 "Check if local context is any of CONTEXTS.
7612 Possible values in the list of contexts are `table', `headline', and `item'."
7613 (let ((pos (point)))
7614 (goto-char (point-at-bol))
7615 (prog1 (or (and (memq 'table contexts)
7616 (looking-at "[ \t]*|"))
7617 (and (memq 'headline contexts)
7618 ;;????????? (looking-at "\\*+"))
7619 (looking-at outline-regexp))
7620 (and (memq 'item contexts)
7621 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
7622 (and (memq 'item-body contexts)
7626 (defun org-get-local-variables ()
7627 "Return a list of all local variables in an org-mode buffer."
7629 (with-current-buffer (get-buffer-create "*Org tmp*")
7632 (setq varlist (buffer-local-variables)))
7633 (kill-buffer "*Org tmp*")
7640 (list (car x) (list 'quote (cdr x)))))
7642 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
7643 (symbol-name (car x)))
7648 (defun org-run-like-in-org-mode (cmd)
7649 "Run a command, pretending that the current buffer is in Org-mode.
7650 This will temporarily bind local variables that are typically bound in
7651 Org-mode to the values they have in Org-mode, and then interactively
7653 (org-load-modules-maybe)
7654 (unless org-local-vars
7655 (setq org-local-vars (org-get-local-variables)))
7656 (eval (list 'let org-local-vars
7657 (list 'call-interactively (list 'quote cmd)))))
7661 (defun org-get-category (&optional pos)
7662 "Get the category applying to position POS."
7663 (get-text-property (or pos (point)) 'org-category))
7665 (defun org-refresh-category-properties ()
7666 "Refresh category text properties in the buffer."
7667 (let ((def-cat (cond
7668 ((null org-category)
7669 (if buffer-file-name
7670 (file-name-sans-extension
7671 (file-name-nondirectory buffer-file-name))
7673 ((symbolp org-category) (symbol-name org-category))
7675 beg end cat pos optionp)
7680 (goto-char (point-min))
7681 (put-text-property (point) (point-max) 'org-category def-cat)
7682 (while (re-search-forward
7683 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
7684 (setq pos (match-end 0)
7685 optionp (equal (char-after (match-beginning 0)) ?#)
7686 cat (org-trim (match-string 2)))
7688 (setq beg (point-at-bol) end (point-max))
7689 (org-back-to-heading t)
7690 (setq beg (point) end (org-end-of-subtree t t)))
7691 (put-text-property beg end 'org-category cat)
7692 (goto-char pos)))))))
7697 ;;; Link abbreviations
7699 (defun org-link-expand-abbrev (link)
7700 "Apply replacements as defined in `org-link-abbrev-alist."
7701 (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
7702 (let* ((key (match-string 1 link))
7703 (as (or (assoc key org-link-abbrev-alist-local)
7704 (assoc key org-link-abbrev-alist)))
7705 (tag (and (match-end 2) (match-string 3 link)))
7711 ((symbolp rpl) (funcall rpl tag))
7712 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
7713 ((string-match "%h" rpl)
7714 (replace-match (url-hexify-string (or tag "")) t t rpl))
7715 (t (concat rpl tag)))))
7718 ;;; Storing and inserting links
7720 (defvar org-insert-link-history nil
7721 "Minibuffer history for links inserted with `org-insert-link'.")
7723 (defvar org-stored-links nil
7724 "Contains the links stored with `org-store-link'.")
7726 (defvar org-store-link-plist nil
7727 "Plist with info about the most recently link created with `org-store-link'.")
7729 (defvar org-link-protocols nil
7730 "Link protocols added to Org-mode using `org-add-link-type'.")
7732 (defvar org-store-link-functions nil
7733 "List of functions that are called to create and store a link.
7734 Each function will be called in turn until one returns a non-nil
7735 value. Each function should check if it is responsible for creating
7736 this link (for example by looking at the major mode).
7737 If not, it must exit and return nil.
7738 If yes, it should return a non-nil value after a calling
7739 `org-store-link-props' with a list of properties and values.
7740 Special properties are:
7742 :type The link prefix. like \"http\". This must be given.
7743 :link The link, like \"http://www.astro.uva.nl/~dominik\".
7744 This is obligatory as well.
7745 :description Optional default description for the second pair
7746 of brackets in an Org-mode link. The user can still change
7747 this when inserting this link into an Org-mode buffer.
7749 In addition to these, any additional properties can be specified
7750 and then used in remember templates.")
7752 (defun org-add-link-type (type &optional follow export)
7753 "Add TYPE to the list of `org-link-types'.
7754 Re-compute all regular expressions depending on `org-link-types'
7756 FOLLOW and EXPORT are two functions.
7758 FOLLOW should take the link path as the single argument and do whatever
7759 is necessary to follow the link, for example find a file or display
7762 EXPORT should format the link path for export to one of the export formats.
7763 It should be a function accepting three arguments:
7765 path the path of the link, the text after the prefix (like \"http:\")
7766 desc the description of the link, if any, nil if there was no description
7767 format the export format, a symbol like `html' or `latex'.
7769 The function may use the FORMAT information to return different values
7770 depending on the format. The return value will be put literally into
7772 Org-mode has a built-in default for exporting links. If you are happy with
7773 this default, there is no need to define an export function for the link
7774 type. For a simple example of an export function, see `org-bbdb.el'."
7775 (add-to-list 'org-link-types type t)
7776 (org-make-link-regexps)
7777 (if (assoc type org-link-protocols)
7778 (setcdr (assoc type org-link-protocols) (list follow export))
7779 (push (list type follow export) org-link-protocols)))
7781 (defvar org-agenda-buffer-name)
7784 (defun org-store-link (arg)
7785 "\\<org-mode-map>Store an org-link to the current location.
7786 This link is added to `org-stored-links' and can later be inserted
7787 into an org-buffer with \\[org-insert-link].
7789 For some link types, a prefix arg is interpreted:
7790 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
7791 For file links, arg negates `org-context-in-file-links'."
7793 (org-load-modules-maybe)
7794 (setq org-store-link-plist nil) ; reset
7795 (let ((outline-regexp (org-get-limited-outline-regexp))
7796 link cpltxt desc description search txt custom-id)
7799 ((run-hook-with-args-until-success 'org-store-link-functions)
7800 (setq link (plist-get org-store-link-plist :link)
7801 desc (or (plist-get org-store-link-plist :description) link)))
7803 ((equal (buffer-name) "*Org Edit Src Example*")
7805 (while (or (not label)
7809 (goto-char (point-min))
7811 (regexp-quote (format org-coderef-label-format label))
7813 (when label (message "Label exists already") (sit-for 2))
7814 (setq label (read-string "Code line label: " label)))
7816 (setq link (format org-coderef-label-format label))
7817 (setq gc (- 79 (length link)))
7818 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
7820 (setq link (concat "(" label ")") desc nil)))
7822 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
7823 ;; We are in the agenda, link to referenced location
7824 (let ((m (or (get-text-property (point) 'org-hd-marker)
7825 (get-text-property (point) 'org-marker))))
7827 (org-with-point-at m
7828 (call-interactively 'org-store-link)))))
7830 ((eq major-mode 'calendar-mode)
7831 (let ((cd (calendar-cursor-to-date)))
7834 (car org-time-stamp-formats)
7836 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
7838 (org-store-link-props :type "calendar" :date cd)))
7840 ((eq major-mode 'w3-mode)
7841 (setq cpltxt (if (and (buffer-name)
7842 (not (string-match "Untitled" (buffer-name))))
7845 link (org-make-link (url-view-url t)))
7846 (org-store-link-props :type "w3" :url (url-view-url t)))
7848 ((eq major-mode 'w3m-mode)
7849 (setq cpltxt (or w3m-current-title w3m-current-url)
7850 link (org-make-link w3m-current-url))
7851 (org-store-link-props :type "w3m" :url (url-view-url t)))
7853 ((setq search (run-hook-with-args-until-success
7854 'org-create-file-search-functions))
7855 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
7857 (setq cpltxt (or description link)))
7859 ((eq major-mode 'image-mode)
7860 (setq cpltxt (concat "file:"
7861 (abbreviate-file-name buffer-file-name))
7862 link (org-make-link cpltxt))
7863 (org-store-link-props :type "image" :file buffer-file-name))
7865 ((eq major-mode 'dired-mode)
7866 ;; link to the file in the current line
7867 (let ((file (dired-get-filename nil t)))
7869 (abbreviate-file-name
7870 (expand-file-name (dired-get-filename nil t)))
7871 ;; otherwise, no file so use current directory.
7873 (setq cpltxt (concat "file:" file)
7874 link (org-make-link cpltxt))))
7876 ((and buffer-file-name (org-mode-p))
7877 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID")))
7879 ((org-in-regexp "<<\\(.*?\\)>>")
7882 (abbreviate-file-name buffer-file-name)
7883 "::" (match-string 1))
7884 link (org-make-link cpltxt)))
7885 ((and (featurep 'org-id)
7886 (or (eq org-link-to-org-use-id t)
7887 (and (eq org-link-to-org-use-id 'create-if-interactive)
7889 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
7892 (and org-link-to-org-use-id
7894 (org-entry-get nil "ID")
7896 ;; We can make a link using the ID.
7897 (setq link (condition-case nil
7898 (prog1 (org-id-store-link)
7899 (setq desc (plist-get org-store-link-plist
7902 ;; probably before first headline, link to file only
7904 (abbreviate-file-name buffer-file-name))))))
7906 ;; Just link to current headline
7907 (setq cpltxt (concat "file:"
7908 (abbreviate-file-name buffer-file-name)))
7909 ;; Add a context search string
7910 (when (org-xor org-context-in-file-links arg)
7912 ((org-on-heading-p) nil)
7913 ((org-region-active-p)
7914 (buffer-substring (region-beginning) (region-end)))
7916 (when (or (null txt) (string-match "\\S-" txt))
7920 (org-make-org-heading-search-string txt)
7922 desc (or (nth 4 (ignore-errors
7923 (org-heading-components))) "NONE"))))
7924 (if (string-match "::\\'" cpltxt)
7925 (setq cpltxt (substring cpltxt 0 -2)))
7926 (setq link (org-make-link cpltxt)))))
7928 ((buffer-file-name (buffer-base-buffer))
7929 ;; Just link to this file here.
7930 (setq cpltxt (concat "file:"
7931 (abbreviate-file-name
7932 (buffer-file-name (buffer-base-buffer)))))
7933 ;; Add a context string
7934 (when (org-xor org-context-in-file-links arg)
7935 (setq txt (if (org-region-active-p)
7936 (buffer-substring (region-beginning) (region-end))
7937 (buffer-substring (point-at-bol) (point-at-eol))))
7938 ;; Only use search option if there is some text.
7939 (when (string-match "\\S-" txt)
7941 (concat cpltxt "::" (org-make-org-heading-search-string txt))
7943 (setq link (org-make-link cpltxt)))
7946 (error "Cannot link to a buffer which is not visiting a file"))
7948 (t (setq link nil)))
7950 (if (consp link) (setq cpltxt (car link) link (cdr link)))
7951 (setq link (or link cpltxt)
7952 desc (or desc cpltxt))
7953 (if (equal desc "NONE") (setq desc nil))
7955 (if (and (or (interactive-p) executing-kbd-macro) link)
7957 (setq org-stored-links
7958 (cons (list link desc) org-stored-links))
7959 (message "Stored: %s" (or desc link))
7961 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
7963 (setq org-stored-links
7964 (cons (list link desc) org-stored-links))))
7965 (and link (org-make-link-string link desc)))))
7967 (defun org-store-link-props (&rest plist)
7968 "Store link properties, extract names and addresses."
7970 (when (setq x (plist-get plist :from))
7971 (setq adr (mail-extract-address-components x))
7972 (setq plist (plist-put plist :fromname (car adr)))
7973 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
7974 (when (setq x (plist-get plist :to))
7975 (setq adr (mail-extract-address-components x))
7976 (setq plist (plist-put plist :toname (car adr)))
7977 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
7978 (let ((from (plist-get plist :from))
7979 (to (plist-get plist :to)))
7980 (when (and from to org-from-is-user-regexp)
7982 (plist-put plist :fromto
7983 (if (string-match org-from-is-user-regexp from)
7985 (concat "from %f"))))))
7986 (setq org-store-link-plist plist))
7988 (defun org-add-link-props (&rest plist)
7989 "Add these properties to the link property list."
7992 (setq key (pop plist) value (pop plist))
7993 (setq org-store-link-plist
7994 (plist-put org-store-link-plist key value)))))
7996 (defun org-email-link-description (&optional fmt)
7997 "Return the description part of an email link.
7998 This takes information from `org-store-link-plist' and formats it
7999 according to FMT (default from `org-email-link-description-format')."
8000 (setq fmt (or fmt org-email-link-description-format))
8001 (let* ((p org-store-link-plist)
8002 (to (plist-get p :toaddress))
8003 (from (plist-get p :fromaddress))
8006 (cons "%c" (plist-get p :fromto))
8007 (cons "%F" (plist-get p :from))
8008 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
8009 (cons "%T" (plist-get p :to))
8010 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
8011 (cons "%s" (plist-get p :subject))
8012 (cons "%m" (plist-get p :message-id)))))
8013 (when (string-match "%c" fmt)
8014 ;; Check if the user wrote this message
8015 (if (and org-from-is-user-regexp from to
8016 (save-match-data (string-match org-from-is-user-regexp from)))
8017 (setq fmt (replace-match "to %t" t t fmt))
8018 (setq fmt (replace-match "from %f" t t fmt))))
8019 (org-replace-escapes fmt table)))
8021 (defun org-make-org-heading-search-string (&optional string heading)
8022 "Make search string for STRING or current headline."
8024 (let ((s (or string (org-get-heading))))
8025 (unless (and string (not heading))
8026 ;; We are using a headline, clean up garbage in there.
8027 (if (string-match org-todo-regexp s)
8028 (setq s (replace-match "" t t s)))
8029 (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s)
8030 (setq s (replace-match "" t t s)))
8031 (setq s (org-trim s))
8032 (if (string-match (concat "^\\(" org-quote-string "\\|"
8033 org-comment-string "\\)") s)
8034 (setq s (replace-match "" t t s)))
8035 (while (string-match org-ts-regexp s)
8036 (setq s (replace-match "" t t s))))
8037 (while (string-match "[^a-zA-Z_0-9 \t]+" s)
8038 (setq s (replace-match " " t t s)))
8039 (or string (setq s (concat "*" s))) ; Add * for headlines
8040 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8042 (defun org-make-link (&rest strings)
8043 "Concatenate STRINGS."
8044 (apply 'concat strings))
8046 (defun org-make-link-string (link &optional description)
8047 "Make a link with brackets, consisting of LINK and DESCRIPTION."
8048 (unless (string-match "\\S-" link)
8049 (error "Empty link"))
8050 (when (and description
8051 (stringp description)
8052 (not (string-match "\\S-" description)))
8053 (setq description nil))
8054 (when (stringp description)
8055 ;; Remove brackets from the description, they are fatal.
8056 (while (string-match "\\[" description)
8057 (setq description (replace-match "{" t t description)))
8058 (while (string-match "\\]" description)
8059 (setq description (replace-match "}" t t description))))
8060 (when (equal (org-link-escape link) description)
8061 ;; No description needed, it is identical
8062 (setq description nil))
8063 (when (and (not description)
8064 (not (equal link (org-link-escape link))))
8065 (setq description (org-extract-attributes link)))
8066 (concat "[[" (org-link-escape link) "]"
8067 (if description (concat "[" description "]") "")
8070 (defconst org-link-escape-chars
8074 (?\340 . "%E0") ; `a
8075 (?\342 . "%E2") ; ^a
8076 (?\347 . "%E7") ; ,c
8077 (?\350 . "%E8") ; `e
8078 (?\351 . "%E9") ; 'e
8079 (?\352 . "%EA") ; ^e
8080 (?\356 . "%EE") ; ^i
8081 (?\364 . "%F4") ; ^o
8082 (?\371 . "%F9") ; `u
8083 (?\373 . "%FB") ; ^u
8089 "Association list of escapes for some characters problematic in links.
8090 This is the list that is used for internal purposes.")
8092 (defvar org-url-encoding-use-url-hexify nil)
8094 (defconst org-link-escape-chars-browser
8095 '((?\ . "%20")) ; 32 for the SPC char
8096 "Association list of escapes for some characters problematic in links.
8097 This is the list that is used before handing over to the browser.")
8099 (defun org-link-escape (text &optional table)
8100 "Escape characters in TEXT that are problematic for links."
8101 (if (and org-url-encoding-use-url-hexify (not table))
8102 (url-hexify-string text)
8103 (setq table (or table org-link-escape-chars))
8105 (let ((re (mapconcat (lambda (x) (regexp-quote
8106 (char-to-string (car x))))
8108 (while (string-match re text)
8111 (cdr (assoc (string-to-char (match-string 0 text))
8116 (defun org-link-unescape (text &optional table)
8117 "Reverse the action of `org-link-escape'."
8118 (if (and org-url-encoding-use-url-hexify (not table))
8119 (url-unhex-string text)
8120 (setq table (or table org-link-escape-chars))
8122 (let ((case-fold-search t)
8123 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8125 (while (string-match re text)
8128 (char-to-string (car (rassoc (upcase (match-string 0 text))
8133 (defun org-xor (a b)
8137 (defun org-fixup-message-id-for-http (s)
8138 "Replace special characters in a message id, so it can be used in an http query."
8139 (while (string-match "<" s)
8140 (setq s (replace-match "%3C" t t s)))
8141 (while (string-match ">" s)
8142 (setq s (replace-match "%3E" t t s)))
8143 (while (string-match "@" s)
8144 (setq s (replace-match "%40" t t s)))
8148 (defun org-insert-link-global ()
8149 "Insert a link like Org-mode does.
8150 This command can be called in any mode to insert a link in Org-mode syntax."
8152 (org-load-modules-maybe)
8153 (org-run-like-in-org-mode 'org-insert-link))
8155 (defun org-insert-link (&optional complete-file link-location)
8156 "Insert a link. At the prompt, enter the link.
8158 Completion can be used to insert any of the link protocol prefixes like
8161 The history can be used to select a link previously stored with
8162 `org-store-link'. When the empty string is entered (i.e. if you just
8163 press RET at the prompt), the link defaults to the most recently
8164 stored link. As SPC triggers completion in the minibuffer, you need to
8165 use M-SPC or C-q SPC to force the insertion of a space character.
8167 You will also be prompted for a description, and if one is given, it will
8168 be displayed in the buffer instead of the link.
8170 If there is already a link at point, this command will allow you to edit link
8171 and description parts.
8173 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
8174 be selected using completion. The path to the file will be relative to the
8175 current directory if the file is in the current directory or a subdirectory.
8176 Otherwise, the link will be the absolute path as completed in the minibuffer
8177 \(i.e. normally ~/path/to/file). You can configure this behavior using the
8178 option `org-link-file-path-type'.
8180 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
8181 the current directory or below.
8183 With three \\[universal-argument] prefixes, negate the meaning of
8184 `org-keep-stored-link-after-insertion'.
8186 If `org-make-link-description-function' is non-nil, this function will be
8187 called with the link target, and the result will be the default
8190 If the LINK-LOCATION parameter is non-nil, this value will be
8191 used as the link location instead of reading one interactively."
8193 (let* ((wcf (current-window-configuration))
8194 (region (if (org-region-active-p)
8195 (buffer-substring (region-beginning) (region-end))))
8196 (remove (and region (list (region-beginning) (region-end))))
8198 tmphist ; byte-compile incorrectly complains about this
8199 (link link-location)
8200 entry file all-prefixes)
8202 (link-location) ; specified by arg, just use it.
8203 ((org-in-regexp org-bracket-link-regexp 1)
8204 ;; We do have a link at point, and we are going to edit it.
8205 (setq remove (list (match-beginning 0) (match-end 0)))
8206 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8207 (setq link (read-string "Link: "
8209 (org-match-string-no-properties 1)))))
8210 ((or (org-in-regexp org-angle-link-re)
8211 (org-in-regexp org-plain-link-re))
8212 ;; Convert to bracket link
8213 (setq remove (list (match-beginning 0) (match-end 0))
8214 link (read-string "Link: "
8215 (org-remove-angle-brackets (match-string 0)))))
8216 ((member complete-file '((4) (16)))
8217 ;; Completing read for file names.
8218 (setq link (org-file-complete-link complete-file)))
8220 ;; Read link, with completion for stored links.
8221 (with-output-to-temp-buffer "*Org Links*"
8222 (princ "Insert a link.
8223 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
8224 (when org-stored-links
8225 (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
8228 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8229 (reverse org-stored-links) "\n"))))
8230 (let ((cw (selected-window)))
8231 (select-window (get-buffer-window "*Org Links*" 'visible))
8232 (setq truncate-lines t)
8233 (unless (pos-visible-in-window-p (point-max))
8234 (org-fit-window-to-buffer))
8235 (and (window-live-p cw) (select-window cw)))
8236 ;; Fake a link history, containing the stored links.
8237 (setq tmphist (append (mapcar 'car org-stored-links)
8238 org-insert-link-history))
8239 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8240 (mapcar 'car org-link-abbrev-alist)
8245 (let ((org-completion-use-ido nil)
8246 (org-completion-use-iswitchb nil))
8247 (org-completing-read
8250 (mapcar (lambda (x) (list (concat x ":")))
8252 (mapcar 'car org-stored-links))
8255 (car (car org-stored-links)))))
8256 (if (not (string-match "\\S-" link))
8257 (error "No link selected"))
8258 (if (or (member link all-prefixes)
8259 (and (equal ":" (substring link -1))
8260 (member (substring link 0 -1) all-prefixes)
8261 (setq link (substring link 0 -1))))
8262 (setq link (org-link-try-special-completion link))))
8263 (set-window-configuration wcf)
8264 (kill-buffer "*Org Links*"))
8265 (setq entry (assoc link org-stored-links))
8266 (or entry (push link org-insert-link-history))
8267 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8268 (not org-keep-stored-link-after-insertion))
8269 (setq org-stored-links (delq (assoc link org-stored-links)
8271 (setq desc (or desc (nth 1 entry)))))
8273 (if (string-match org-plain-link-re link)
8274 ;; URL-like link, normalize the use of angular brackets.
8275 (setq link (org-make-link (org-remove-angle-brackets link))))
8277 ;; Check if we are linking to the current file with a search option
8278 ;; If yes, simplify the link by using only the search option.
8279 (when (and buffer-file-name
8280 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
8281 (let* ((path (match-string 1 link))
8282 (case-fold-search nil)
8283 (search (match-string 2 link)))
8285 (if (equal (file-truename buffer-file-name) (file-truename path))
8286 ;; We are linking to this same file, with a search option
8287 (setq link search)))))
8289 ;; Check if we can/should use a relative path. If yes, simplify the link
8290 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
8291 (let* ((type (match-string 1 link))
8292 (path (match-string 2 link))
8294 (case-fold-search nil))
8296 ((or (eq org-link-file-path-type 'absolute)
8297 (equal complete-file '(16)))
8298 (setq path (abbreviate-file-name (expand-file-name path))))
8299 ((eq org-link-file-path-type 'noabbrev)
8300 (setq path (expand-file-name path)))
8301 ((eq org-link-file-path-type 'relative)
8302 (setq path (file-relative-name path)))
8305 (if (string-match (concat "^" (regexp-quote
8306 (file-name-as-directory
8307 (expand-file-name "."))))
8308 (expand-file-name path))
8309 ;; We are linking a file with relative path name.
8310 (setq path (substring (expand-file-name path)
8312 (setq path (abbreviate-file-name (expand-file-name path)))))))
8313 (setq link (concat type path))
8314 (if (equal desc origpath)
8317 (if org-make-link-description-function
8318 (setq desc (funcall org-make-link-description-function link desc)))
8320 (setq desc (read-string "Description: " desc))
8321 (unless (string-match "\\S-" desc) (setq desc nil))
8322 (if remove (apply 'delete-region remove))
8323 (insert (org-make-link-string link desc))))
8325 (defun org-link-try-special-completion (type)
8326 "If there is completion support for link type TYPE, offer it."
8327 (let ((fun (intern (concat "org-" type "-complete-link"))))
8330 (read-string "Link (no completion support): " (concat type ":")))))
8332 (defun org-file-complete-link (&optional arg)
8333 "Create a file link using completion."
8335 (setq file (read-file-name "File: "))
8336 (let ((pwd (file-name-as-directory (expand-file-name ".")))
8337 (pwd1 (file-name-as-directory (abbreviate-file-name
8338 (expand-file-name ".")))))
8341 (setq link (org-make-link
8343 (abbreviate-file-name (expand-file-name file)))))
8344 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
8345 (setq link (org-make-link "file:" (match-string 1 file))))
8346 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
8347 (expand-file-name file))
8348 (setq link (org-make-link
8349 "file:" (match-string 1 (expand-file-name file)))))
8350 (t (setq link (org-make-link "file:" file)))))
8353 (defun org-completing-read (&rest args)
8354 "Completing-read with SPACE being a normal character."
8355 (let ((minibuffer-local-completion-map
8356 (copy-keymap minibuffer-local-completion-map)))
8357 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8358 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
8359 (apply 'org-icompleting-read args)))
8361 (defun org-completing-read-no-i (&rest args)
8362 (let (org-completion-use-ido org-completion-use-iswitchb)
8363 (apply 'org-completing-read args)))
8365 (defun org-iswitchb-completing-read (prompt choices &rest args)
8366 "Use iswitch as a completing-read replacement to choose from choices.
8367 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8369 (let* ((iswitchb-use-virtual-buffers nil)
8370 (iswitchb-make-buflist-hook
8372 (setq iswitchb-temp-buflist choices))))
8373 (iswitchb-read-buffer prompt)))
8375 (defun org-icompleting-read (&rest args)
8376 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
8377 (org-without-partial-completion
8378 (if (and org-completion-use-ido
8379 (fboundp 'ido-completing-read)
8380 (boundp 'ido-mode) ido-mode
8381 (listp (second args)))
8382 (let ((ido-enter-matching-directory nil))
8383 (apply 'ido-completing-read (concat (car args))
8384 (if (consp (car (nth 1 args)))
8385 (mapcar (lambda (x) (car x)) (nth 1 args))
8388 (if (and org-completion-use-iswitchb
8389 (boundp 'iswitchb-mode) iswitchb-mode
8390 (listp (second args)))
8391 (apply 'org-iswitchb-completing-read (concat (car args))
8392 (if (consp (car (nth 1 args)))
8393 (mapcar (lambda (x) (car x)) (nth 1 args))
8396 (apply 'completing-read args)))))
8398 (defun org-extract-attributes (s)
8399 "Extract the attributes cookie from a string and set as text property."
8400 (let (a attr (start 0) key value)
8402 (when (string-match "{{\\([^}]+\\)}}$" s)
8403 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8404 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
8405 (setq key (match-string 1 a) value (match-string 2 a)
8407 attr (plist-put attr (intern key) value))))
8408 (org-add-props s nil 'org-attr attr))
8411 (defun org-extract-attributes-from-string (tag)
8412 (let (key value attr)
8413 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
8414 (setq key (match-string 1 tag) value (match-string 2 tag)
8415 tag (replace-match "" t t tag)
8416 attr (plist-put attr (intern key) value)))
8419 (defun org-attributes-to-string (plist)
8420 "Format a property list into an HTML attribute list."
8421 (let ((s "") key value)
8423 (setq key (pop plist) value (pop plist))
8425 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8428 ;;; Opening/following a link
8430 (defvar org-link-search-failed nil)
8432 (defvar org-open-link-functions nil
8433 "Hook for functions finding a plain text link.
8434 These functions must take a single argument, the link content.
8435 They will be called for links that look like [[link text][description]]
8436 when LINK TEXT does not have a protocol like \"http:\" and does not look
8437 like a filename (e.g. \"./blue.png\").
8439 These functions will be called *before* Org attempts to resolve the
8440 link by doing text searches in the current buffer - so if you want a
8441 link \"[[target]]\" to still find \"<<target>>\", your function should
8442 handle this as a special case.
8444 When the function does handle the link, it must return a non-nil value.
8445 If it decides that it is not responsible for this link, it must return
8446 nil to indicate that that Org-mode can continue with other options
8447 like exact and fuzzy text search.")
8449 (defun org-next-link ()
8450 "Move forward to the next link.
8451 If the link is in hidden text, expose it."
8453 (when (and org-link-search-failed (eq this-command last-command))
8454 (goto-char (point-min))
8455 (message "Link search wrapped back to beginning of buffer"))
8456 (setq org-link-search-failed nil)
8457 (let* ((pos (point))
8459 (a (assoc :link ct)))
8460 (if a (goto-char (nth 2 a)))
8461 (if (re-search-forward org-any-link-re nil t)
8463 (goto-char (match-beginning 0))
8464 (if (org-invisible-p) (org-show-context)))
8466 (setq org-link-search-failed t)
8467 (error "No further link found"))))
8469 (defun org-previous-link ()
8470 "Move backward to the previous link.
8471 If the link is in hidden text, expose it."
8473 (when (and org-link-search-failed (eq this-command last-command))
8474 (goto-char (point-max))
8475 (message "Link search wrapped back to end of buffer"))
8476 (setq org-link-search-failed nil)
8477 (let* ((pos (point))
8479 (a (assoc :link ct)))
8480 (if a (goto-char (nth 1 a)))
8481 (if (re-search-backward org-any-link-re nil t)
8483 (goto-char (match-beginning 0))
8484 (if (org-invisible-p) (org-show-context)))
8486 (setq org-link-search-failed t)
8487 (error "No further link found"))))
8489 (defun org-translate-link (s)
8490 "Translate a link string if a translation function has been defined."
8491 (if (and org-link-translation-function
8492 (fboundp org-link-translation-function)
8493 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8495 (setq s (funcall org-link-translation-function
8496 (match-string 1) (match-string 2)))
8497 (concat (car s) ":" (cdr s)))
8500 (defun org-translate-link-from-planner (type path)
8501 "Translate a link from Emacs Planner syntax so that Org can follow it.
8502 This is still an experimental function, your mileage may vary."
8504 ((member type '("http" "https" "news" "ftp"))
8505 ;; standard Internet links are the same.
8507 ((and (equal type "irc") (string-match "^//" path))
8508 ;; Planner has two / at the beginning of an irc link, we have 1.
8509 ;; We should have zero, actually....
8510 (setq path (substring path 1)))
8511 ((and (equal type "lisp") (string-match "^/" path))
8512 ;; Planner has a slash, we do not.
8513 (setq type "elisp" path (substring path 1)))
8514 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8515 ;; A typical message link. Planner has the id after the final slash,
8516 ;; we separate it with a hash mark
8517 (setq path (concat (match-string 1 path) "#"
8518 (org-remove-angle-brackets (match-string 2 path)))))
8522 (defun org-find-file-at-mouse (ev)
8523 "Open file link or URL at mouse."
8525 (mouse-set-point ev)
8526 (org-open-at-point 'in-emacs))
8528 (defun org-open-at-mouse (ev)
8529 "Open file link or URL at mouse."
8531 (mouse-set-point ev)
8532 (if (eq major-mode 'org-agenda-mode)
8533 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8534 (org-open-at-point))
8536 (defvar org-window-config-before-follow-link nil
8537 "The window configuration before following a link.
8538 This is saved in case the need arises to restore it.")
8540 (defvar org-open-link-marker (make-marker)
8541 "Marker pointing to the location where `org-open-at-point; was called.")
8544 (defun org-open-at-point-global ()
8545 "Follow a link like Org-mode does.
8546 This command can be called in any mode to follow a link that has
8549 (org-run-like-in-org-mode 'org-open-at-point))
8552 (defun org-open-link-from-string (s &optional arg reference-buffer)
8553 "Open a link in the string S, as if it was in Org-mode."
8554 (interactive "sLink: \nP")
8555 (let ((reference-buffer (or reference-buffer (current-buffer))))
8557 (let ((org-inhibit-startup t))
8560 (goto-char (point-min))
8561 (when reference-buffer
8562 (setq org-link-abbrev-alist-local
8563 (with-current-buffer reference-buffer
8564 org-link-abbrev-alist-local)))
8565 (org-open-at-point arg reference-buffer)))))
8567 (defun org-open-at-point (&optional in-emacs reference-buffer)
8568 "Open link at or after point.
8569 If there is no link at point, this function will search forward up to
8570 the end of the current line.
8571 Normally, files will be opened by an appropriate application. If the
8572 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8573 With a double prefix argument, try to open outside of Emacs, in the
8574 application the system uses for this file type."
8576 (org-load-modules-maybe)
8577 (move-marker org-open-link-marker (point))
8578 (setq org-window-config-before-follow-link (current-window-configuration))
8579 (org-remove-occur-highlights nil nil t)
8581 ((and (org-on-heading-p)
8583 (concat org-plain-link-re "\\|"
8584 org-bracket-link-regexp "\\|"
8585 org-angle-link-re "\\|"
8586 "[ \t]:[^ \t\n]+:[ \t]*$")))
8587 (not (get-text-property (point) 'org-linked-text)))
8588 (or (org-offer-links-in-entry in-emacs)
8589 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8590 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8591 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8592 (org-footnote-action))
8594 (let (type path link line search (pos (point)))
8597 (skip-chars-forward "^]\n\r")
8598 (when (org-in-regexp org-bracket-link-regexp 1)
8599 (setq link (org-extract-attributes
8600 (org-link-unescape (org-match-string-no-properties 1))))
8601 (while (string-match " *\n *" link)
8602 (setq link (replace-match " " t t link)))
8603 (setq link (org-link-expand-abbrev link))
8605 ((or (file-name-absolute-p link)
8606 (string-match "^\\.\\.?/" link))
8607 (setq type "file" path link))
8608 ((string-match org-link-re-with-space3 link)
8609 (setq type (match-string 1 link) path (match-string 2 link)))
8610 (t (setq type "thisfile" path link)))
8613 (when (get-text-property (point) 'org-linked-text)
8614 (setq type "thisfile"
8615 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8616 (1+ (point)) (point))
8617 path (buffer-substring
8618 (previous-single-property-change pos 'org-linked-text)
8619 (next-single-property-change pos 'org-linked-text)))
8623 (when (or (org-in-regexp org-angle-link-re)
8624 (org-in-regexp org-plain-link-re))
8625 (setq type (match-string 1) path (match-string 2))
8628 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8630 path (match-string 1))
8631 (while (string-match ":" path)
8632 (setq path (replace-match "+" t t path)))
8634 (when (org-in-regexp "<\\([^><\n]+\\)>")
8635 (setq type "tree-match"
8636 path (match-string 1))
8639 (error "No link found"))
8641 ;; switch back to reference buffer
8642 ;; needed when if called in a temporary buffer through
8643 ;; org-open-link-from-string
8644 (with-current-buffer (or reference-buffer (current-buffer))
8646 ;; Remove any trailing spaces in path
8647 (if (string-match " +\\'" path)
8648 (setq path (replace-match "" t t path)))
8649 (if (and org-link-translation-function
8650 (fboundp org-link-translation-function))
8651 ;; Check if we need to translate the link
8652 (let ((tmp (funcall org-link-translation-function type path)))
8653 (setq type (car tmp) path (cdr tmp))))
8657 ((assoc type org-link-protocols)
8658 (funcall (nth 1 (assoc type org-link-protocols)) path))
8660 ((equal type "mailto")
8661 (let ((cmd (car org-link-mailto-program))
8662 (args (cdr org-link-mailto-program)) args1
8663 (address path) (subject "") a)
8664 (if (string-match "\\(.*\\)::\\(.*\\)" path)
8665 (setq address (match-string 1 path)
8666 subject (org-link-escape (match-string 2 path))))
8669 ((not (stringp (car args))) (push (pop args) args1))
8670 (t (setq a (pop args))
8671 (if (string-match "%a" a)
8672 (setq a (replace-match address t t a)))
8673 (if (string-match "%s" a)
8674 (setq a (replace-match subject t t a)))
8676 (apply cmd (nreverse args1))))
8678 ((member type '("http" "https" "ftp" "news"))
8679 (browse-url (concat type ":" (org-link-escape
8680 path org-link-escape-chars-browser))))
8682 ((member type '("message"))
8683 (browse-url (concat type ":" path)))
8685 ((string= type "tags")
8686 (org-tags-view in-emacs path))
8688 ((string= type "tree-match")
8689 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
8691 ((string= type "file")
8692 (if (string-match "::\\([0-9]+\\)\\'" path)
8693 (setq line (string-to-number (match-string 1 path))
8694 path (substring path 0 (match-beginning 0)))
8695 (if (string-match "::\\(.+\\)\\'" path)
8696 (setq search (match-string 1 path)
8697 path (substring path 0 (match-beginning 0)))))
8698 (if (string-match "[*?{]" (file-name-nondirectory path))
8700 (org-open-file path in-emacs line search)))
8702 ((string= type "news")
8704 (org-gnus-follow-link path))
8706 ((string= type "shell")
8708 (if (or (not org-confirm-shell-link-function)
8709 (funcall org-confirm-shell-link-function
8710 (format "Execute \"%s\" in shell? "
8711 (org-add-props cmd nil
8712 'face 'org-warning))))
8714 (message "Executing %s" cmd)
8715 (shell-command cmd))
8718 ((string= type "elisp")
8720 (if (or (not org-confirm-elisp-link-function)
8721 (funcall org-confirm-elisp-link-function
8722 (format "Execute \"%s\" as elisp? "
8723 (org-add-props cmd nil
8724 'face 'org-warning))))
8725 (message "%s => %s" cmd
8726 (if (equal (string-to-char cmd) ?\()
8728 (call-interactively (read cmd))))
8731 ((and (string= type "thisfile")
8732 (run-hook-with-args-until-success
8733 'org-open-link-functions path)))
8735 ((string= type "thisfile")
8737 (switch-to-buffer-other-window
8738 (org-get-buffer-for-internal-link (current-buffer)))
8739 (org-mark-ring-push))
8740 (let ((cmd `(org-link-search
8742 ,(cond ((equal in-emacs '(4)) 'occur)
8743 ((equal in-emacs '(16)) 'org-occur)
8746 (condition-case nil (eval cmd)
8747 (error (progn (widen) (eval cmd))))))
8750 (browse-url-at-point)))))))
8751 (move-marker org-open-link-marker nil)
8752 (run-hook-with-args 'org-follow-link-hook))
8754 (defun org-offer-links-in-entry (&optional nth zero)
8755 "Offer links in the current entry and follow the selected link.
8756 If there is only one link, follow it immediately as well.
8757 If NTH is an integer, immediately pick the NTH link found.
8758 If ZERO is a string, check also this string for a link, and if
8759 there is one, offer it as link number zero."
8760 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
8761 "\\(" org-angle-link-re "\\)\\|"
8762 "\\(" org-plain-link-re "\\)"))
8764 (in-emacs (if (integerp nth) nil nth))
8765 have-zero end links link c)
8766 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
8767 (push (match-string 0 zero) links)
8768 (setq cnt (1- cnt) have-zero t))
8770 (org-back-to-heading t)
8771 (setq end (save-excursion (outline-next-heading) (point)))
8772 (while (re-search-forward re end t)
8773 (push (match-string 0) links))
8774 (setq links (org-uniquify (reverse links))))
8778 (message "No links"))
8779 ((equal (length links) 1)
8780 (setq link (list (car links))))
8781 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
8782 (setq link (nth (if have-zero nth (1- nth)) links)))
8783 (t ; we have to select a link
8785 (save-window-excursion
8786 (delete-other-windows)
8787 (with-output-to-temp-buffer "*Select Link*"
8789 (if (not (string-match org-bracket-link-regexp l))
8790 (princ (format "[%c] %s\n" (incf cnt)
8791 (org-remove-angle-brackets l)))
8793 (princ (format "[%c] %s (%s)\n" (incf cnt)
8794 (match-string 3 l) (match-string 1 l)))
8795 (princ (format "[%c] %s\n" (incf cnt)
8796 (match-string 1 l))))))
8798 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
8799 (message "Select link to open, RET to open all:")
8800 (setq c (read-char-exclusive))
8801 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
8802 (when (equal c ?q) (error "Abort"))
8806 (if have-zero (setq nth (1+ nth)))
8807 (unless (and (integerp nth) (>= (length links) nth))
8808 (error "Invalid link selection"))
8809 (setq link (list (nth (1- nth) links))))))
8811 (let ((buf (current-buffer)))
8813 (org-open-link-from-string l in-emacs buf))
8817 ;; Add special file links that specify the way of opening
8819 (org-add-link-type "file+sys" 'org-open-file-with-system)
8820 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
8821 (defun org-open-file-with-system (path)
8822 "Open file at PATH using the system way of opeing it."
8823 (org-open-file path 'system))
8824 (defun org-open-file-with-emacs (path)
8825 "Open file at PATH in emacs."
8826 (org-open-file path 'emacs))
8827 (defun org-remove-file-link-modifiers ()
8828 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
8829 (goto-char (point-min))
8830 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
8832 (replace-match "file:" t t))))
8833 (eval-after-load "org-exp"
8834 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
8835 'org-remove-file-link-modifiers))
8839 (defun org-get-effort (&optional pom)
8840 "Get the effort estimate for the current entry."
8841 (org-entry-get pom org-effort-property))
8845 (defvar org-create-file-search-functions nil
8846 "List of functions to construct the right search string for a file link.
8847 These functions are called in turn with point at the location to
8848 which the link should point.
8850 A function in the hook should first test if it would like to
8851 handle this file type, for example by checking the major-mode or
8852 the file extension. If it decides not to handle this file, it
8853 should just return nil to give other functions a chance. If it
8854 does handle the file, it must return the search string to be used
8855 when following the link. The search string will be part of the
8856 file link, given after a double colon, and `org-open-at-point'
8857 will automatically search for it. If special measures must be
8858 taken to make the search successful, another function should be
8859 added to the companion hook `org-execute-file-search-functions',
8862 A function in this hook may also use `setq' to set the variable
8863 `description' to provide a suggestion for the descriptive text to
8864 be used for this link when it gets inserted into an Org-mode
8865 buffer with \\[org-insert-link].")
8867 (defvar org-execute-file-search-functions nil
8868 "List of functions to execute a file search triggered by a link.
8870 Functions added to this hook must accept a single argument, the
8871 search string that was part of the file link, the part after the
8872 double colon. The function must first check if it would like to
8873 handle this search, for example by checking the major-mode or the
8874 file extension. If it decides not to handle this search, it
8875 should just return nil to give other functions a chance. If it
8876 does handle the search, it must return a non-nil value to keep
8877 other functions from trying.
8879 Each function can access the current prefix argument through the
8880 variable `current-prefix-argument'. Note that a single prefix is
8881 used to force opening a link in Emacs, so it may be good to only
8882 use a numeric or double prefix to guide the search function.
8884 In case this is needed, a function in this hook can also restore
8885 the window configuration before `org-open-at-point' was called using:
8887 (set-window-configuration org-window-config-before-follow-link)")
8889 (defun org-link-search (s &optional type avoid-pos)
8890 "Search for a link search option.
8891 If S is surrounded by forward slashes, it is interpreted as a
8892 regular expression. In org-mode files, this will create an `org-occur'
8893 sparse tree. In ordinary files, `occur' will be used to list matches.
8894 If the current buffer is in `dired-mode', grep will be used to search
8895 in all files. If AVOID-POS is given, ignore matches near that position."
8896 (let ((case-fold-search t)
8897 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
8898 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
8899 (append '(("") (" ") ("\t") ("\n"))
8903 (pre nil) (post nil)
8904 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
8906 ;; First check if there are any special
8907 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
8908 ;; Now try the builtin stuff
8909 ((and (equal (string-to-char s0) ?#)
8912 (goto-char (point-min))
8915 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
8916 (setq type 'dedicated
8917 pos (match-beginning 0))))
8918 ;; There is an exact target for this
8920 (org-back-to-heading t)))
8922 (goto-char (point-min))
8925 (concat "<<" (regexp-quote s0) ">>") nil t)
8926 (setq type 'dedicated
8927 pos (match-beginning 0))))
8928 ;; There is an exact target for this
8930 ((and (string-match "^(\\(.*\\))$" s0)
8932 (goto-char (point-min))
8935 (concat "[^[]" (regexp-quote
8936 (format org-coderef-label-format
8937 (match-string 1 s0))))
8939 (setq type 'dedicated
8940 pos (1+ (match-beginning 0))))))
8941 ;; There is a coderef target for this
8943 ((string-match "^/\\(.*\\)/$" s)
8944 ;; A regular expression
8947 (org-occur (match-string 1 s)))
8948 ;;((eq major-mode 'dired-mode)
8949 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
8950 (t (org-do-occur (match-string 1 s)))))
8952 ;; A normal search strings
8953 (when (equal (string-to-char s) ?*)
8954 ;; Anchor on headlines, post may include tags.
8955 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
8956 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
8958 (remove-text-properties
8960 '(face nil mouse-face nil keymap nil fontified nil) s)
8961 ;; Make a series of regular expressions to find a match
8962 (setq words (org-split-string s "[ \n\r\t]+")
8964 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
8965 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
8967 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
8968 re2a (concat "[ \t\r\n]" re2a_)
8969 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
8970 re4 (concat "[^a-zA-Z_]" re4_)
8972 re1 (concat pre re2 post)
8973 re3 (concat pre (if pre re4_ re4) post)
8974 re5 (concat pre ".*" re4)
8975 re2 (concat pre re2)
8976 re2a (concat pre (if pre re2a_ re2a))
8977 re4 (concat pre (if pre re4_ re4))
8978 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
8979 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
8983 ((eq type 'org-occur) (org-occur reall))
8984 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
8985 (t (goto-char (point-min))
8987 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
8988 (org-search-not-self 1 re1 nil t)
8989 (org-search-not-self 1 re2 nil t)
8990 (org-search-not-self 1 re2a nil t)
8991 (org-search-not-self 1 re3 nil t)
8992 (org-search-not-self 1 re4 nil t)
8993 (org-search-not-self 1 re5 nil t)
8995 (goto-char (match-beginning 1))
8997 (error "No match")))))
8999 ;; Normal string-search
9000 (goto-char (point-min))
9001 (if (search-forward s nil t)
9002 (goto-char (match-beginning 0))
9003 (error "No match"))))
9004 (and (org-mode-p) (org-show-context 'link-search))
9007 (defun org-search-not-self (group &rest args)
9008 "Execute `re-search-forward', but only accept matches that do not
9009 enclose the position of `org-open-link-marker'."
9010 (let ((m org-open-link-marker))
9012 (while (apply 're-search-forward args)
9013 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9014 (goto-char (match-end group))
9015 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9016 (> (match-beginning 0) (marker-position m))
9017 (< (match-end 0) (marker-position m)))
9019 (or (not (org-in-regexp
9020 org-bracket-link-analytic-regexp 1))
9021 (not (match-end 4)) ; no description
9022 (and (<= (match-beginning 4) (point))
9023 (>= (match-end 4) (point))))))
9024 (throw 'exit (point))))))))
9026 (defun org-get-buffer-for-internal-link (buffer)
9027 "Return a buffer to be used for displaying the link target of internal links."
9029 ((not org-display-internal-link-with-indirect-buffer)
9031 ((string-match "(Clone)$" (buffer-name buffer))
9032 (message "Buffer is already a clone, not making another one")
9033 ;; we also do not modify visibility in this case
9035 (t ; make a new indirect buffer for displaying the link
9036 (let* ((bn (buffer-name buffer))
9037 (ibn (concat bn "(Clone)"))
9038 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9039 (with-current-buffer ib (org-overview))
9042 (defun org-do-occur (regexp &optional cleanup)
9043 "Call the Emacs command `occur'.
9044 If CLEANUP is non-nil, remove the printout of the regular expression
9045 in the *Occur* buffer. This is useful if the regex is long and not useful
9049 (let ((cwin (selected-window)) win beg end)
9050 (when (setq win (get-buffer-window "*Occur*"))
9051 (select-window win))
9052 (goto-char (point-min))
9053 (when (re-search-forward "match[a-z]+" nil t)
9054 (setq beg (match-end 0))
9055 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9056 (setq end (1- (match-beginning 0)))))
9057 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9058 (goto-char (point-min))
9059 (select-window cwin))))
9061 ;;; The mark ring for links jumps
9063 (defvar org-mark-ring nil
9064 "Mark ring for positions before jumps in Org-mode.")
9065 (defvar org-mark-ring-last-goto nil
9066 "Last position in the mark ring used to go back.")
9067 ;; Fill and close the ring
9068 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9069 (loop for i from 1 to org-mark-ring-length do
9070 (push (make-marker) org-mark-ring))
9071 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9074 (defun org-mark-ring-push (&optional pos buffer)
9075 "Put the current position or POS into the mark ring and rotate it."
9077 (setq pos (or pos (point)))
9078 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9079 (move-marker (car org-mark-ring)
9081 (or buffer (current-buffer)))
9083 (substitute-command-keys
9084 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9086 (defun org-mark-ring-goto (&optional n)
9087 "Jump to the previous position in the mark ring.
9088 With prefix arg N, jump back that many stored positions. When
9089 called several times in succession, walk through the entire ring.
9090 Org-mode commands jumping to a different position in the current file,
9091 or to another Org-mode file, automatically push the old position
9095 (if (eq last-command this-command)
9096 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9097 (setq p org-mark-ring))
9098 (setq org-mark-ring-last-goto p)
9100 (switch-to-buffer (marker-buffer m))
9102 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9104 (defun org-remove-angle-brackets (s)
9105 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9106 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9108 (defun org-add-angle-brackets (s)
9109 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9110 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9112 (defun org-remove-double-quotes (s)
9113 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9114 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9117 ;;; Following specific links
9119 (defun org-follow-timestamp-link ()
9121 ((org-at-date-range-p t)
9122 (let ((org-agenda-start-on-weekday)
9123 (t1 (match-string 1))
9124 (t2 (match-string 2)))
9125 (setq t1 (time-to-days (org-time-string-to-time t1))
9126 t2 (time-to-days (org-time-string-to-time t2)))
9127 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9128 ((org-at-timestamp-p t)
9129 (org-agenda-list nil (time-to-days (org-time-string-to-time
9130 (substring (match-string 1) 0 10)))
9132 (t (error "This should not happen"))))
9135 ;;; Following file links
9136 (defvar org-wait nil)
9137 (defun org-open-file (path &optional in-emacs line search)
9138 "Open the file at PATH.
9139 First, this expands any special file name abbreviations. Then the
9140 configuration variable `org-file-apps' is checked if it contains an
9141 entry for this file type, and if yes, the corresponding command is launched.
9143 If no application is found, Emacs simply visits the file.
9145 With optional prefix argument IN-EMACS, Emacs will visit the file.
9146 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9147 and to use an external application to visit the file.
9149 Optional LINE specifies a line to go to, optional SEARCH a string
9150 to search for. If LINE or SEARCH is given, the file will be
9151 opened in Emacs, unless an entry from org-file-apps that makes
9152 use of groups in a regexp matches.
9153 If the file does not exist, an error is thrown."
9154 (let* ((file (if (equal path "")
9156 (substitute-in-file-name (expand-file-name path))))
9157 (file-apps (append org-file-apps (org-default-apps)))
9158 (apps (org-remove-if
9159 'org-file-apps-entry-match-against-dlink-p file-apps))
9160 (apps-dlink (org-remove-if-not
9161 'org-file-apps-entry-match-against-dlink-p file-apps))
9162 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9163 (dirp (if remp nil (file-directory-p file)))
9164 (file (if (and dirp org-open-directory-means-index-dot-org)
9165 (concat (file-name-as-directory file) "index.org")
9167 (a-m-a-p (assq 'auto-mode apps))
9168 (dfile (downcase file))
9169 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9170 (link (cond ((and (eq line nil)
9174 (concat file "::" (number-to-string line)))
9176 (concat file "::" search))))
9177 (dlink (downcase link))
9178 (old-buffer (current-buffer))
9180 (old-mode major-mode)
9181 ext cmd link-match-data)
9182 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9183 (setq ext (match-string 1 dfile))
9184 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9185 (setq ext (match-string 1 dfile))))
9187 ((member in-emacs '((16) system))
9188 (setq cmd (cdr (assoc 'system apps))))
9189 (in-emacs (setq cmd 'emacs))
9191 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9192 (and dirp (cdr (assoc 'directory apps)))
9193 ; first, try matching against apps-dlink
9194 ; if we get a match here, store the match data for later
9195 (let ((match (assoc-default dlink apps-dlink
9198 (progn (setq link-match-data (match-data))
9200 (progn (setq in-emacs (or in-emacs line search))
9201 nil))) ; if we have no match in apps-dlink,
9202 ; always open the file in emacs if line or search
9203 ; is given (for backwards compatibility)
9204 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9206 (cdr (assoc ext apps))
9207 (cdr (assoc t apps))))))
9208 (when (eq cmd 'system)
9209 (setq cmd (cdr (assoc 'system apps))))
9210 (when (eq cmd 'default)
9211 (setq cmd (cdr (assoc t apps))))
9212 (when (eq cmd 'mailcap)
9214 (mailcap-parse-mailcaps)
9215 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9216 (command (mailcap-mime-info mime-type)))
9217 (if (stringp command)
9219 (setq cmd 'emacs))))
9220 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9221 (not (file-exists-p file))
9222 (not org-open-non-existing-files))
9223 (error "No such file: %s" file))
9225 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9226 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9227 (while (string-match "['\"]%s['\"]" cmd)
9228 (setq cmd (replace-match "%s" t t cmd)))
9229 (while (string-match "%s" cmd)
9230 (setq cmd (replace-match
9232 (shell-quote-argument
9233 (convert-standard-filename file)))
9236 ;; Replace "%1", "%2" etc. in command with group matches from regex
9238 (let ((match-index 1)
9239 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9240 (set-match-data link-match-data)
9241 (while (<= match-index number-of-groups)
9242 (let ((regex (concat "%" (number-to-string match-index)))
9243 (replace-with (match-string match-index dlink)))
9244 (while (string-match regex cmd)
9245 (setq cmd (replace-match replace-with t t cmd))))
9246 (setq match-index (+ match-index 1)))))
9248 (save-window-excursion
9249 (start-process-shell-command cmd nil cmd)
9250 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9254 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9256 (if line (org-goto-line line)
9257 (if search (org-link-search search))))
9259 (let ((file (convert-standard-filename file)))
9261 (set-match-data link-match-data)
9263 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9264 (and (org-mode-p) (eq old-mode 'org-mode)
9265 (or (not (equal old-buffer (current-buffer)))
9266 (not (equal old-pos (point))))
9267 (org-mark-ring-push old-pos old-buffer))))
9269 (defun org-file-apps-entry-match-against-dlink-p (entry)
9270 "This function returns non-nil if `entry' uses a regular
9271 expression which should be matched against the whole link by
9274 It assumes that is the case when the entry uses a regular
9275 expression which has at least one grouping construct and the
9276 action is either a lisp form or a command string containing
9277 '%1', i.e. using at least one subexpression match as a
9279 (let ((selector (car entry))
9280 (action (cdr entry)))
9281 (if (stringp selector)
9282 (and (> (regexp-opt-depth selector) 0)
9283 (or (and (stringp action)
9284 (string-match "%[0-9]" action))
9288 (defun org-default-apps ()
9289 "Return the default applications for this operating system."
9291 ((eq system-type 'darwin)
9292 org-file-apps-defaults-macosx)
9293 ((eq system-type 'windows-nt)
9294 org-file-apps-defaults-windowsnt)
9295 (t org-file-apps-defaults-gnu)))
9297 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9298 "Convert extensions to regular expressions in the cars of LIST.
9299 Also, weed out any non-string entries, because the return value is used
9300 only for regexp matching.
9301 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9302 point to the symbol `emacs', indicating that the file should
9303 be opened in Emacs."
9307 (if (not (stringp (car x)))
9309 (if (string-match "\\W" (car x))
9311 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9314 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9316 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9317 (defun org-file-remote-p (file)
9318 "Test whether FILE specifies a location on a remote system.
9319 Return non-nil if the location is indeed remote.
9321 For example, the filename \"/user@host:/foo\" specifies a location
9322 on the system \"/user@host:\"."
9323 (cond ((fboundp 'file-remote-p)
9324 (file-remote-p file))
9325 ((fboundp 'tramp-handle-file-remote-p)
9326 (tramp-handle-file-remote-p file))
9327 ((and (boundp 'ange-ftp-name-format)
9328 (string-match (car ange-ftp-name-format) file))
9335 (defun org-get-org-file ()
9336 "Read a filename, with default directory `org-directory'."
9337 (let ((default (or org-default-notes-file remember-data-file)))
9338 (read-file-name (format "File name [%s]: " default)
9339 (file-name-as-directory org-directory)
9342 (defun org-notes-order-reversed-p ()
9343 "Check if the current file should receive notes in reversed order."
9345 ((not org-reverse-note-order) nil)
9346 ((eq t org-reverse-note-order) t)
9347 ((not (listp org-reverse-note-order)) nil)
9349 (let ((all org-reverse-note-order)
9351 (while (setq entry (pop all))
9352 (if (string-match (car entry) buffer-file-name)
9353 (throw 'exit (cdr entry))))
9356 (defvar org-refile-target-table nil
9357 "The list of refile targets, created by `org-refile'.")
9359 (defvar org-agenda-new-buffers nil
9360 "Buffers created to visit agenda files.")
9362 (defun org-get-refile-targets (&optional default-buffer)
9363 "Produce a table with refile targets."
9364 (let ((case-fold-search nil)
9365 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9366 (entries (or org-refile-targets '((nil . (:level . 1)))))
9367 targets txt re files f desc descre fast-path-p level pos0)
9368 (message "Getting targets...")
9369 (with-current-buffer (or default-buffer (current-buffer))
9370 (while (setq entry (pop entries))
9371 (setq files (car entry) desc (cdr entry))
9372 (setq fast-path-p nil)
9374 ((null files) (setq files (list (current-buffer))))
9375 ((eq files 'org-agenda-files)
9376 (setq files (org-agenda-files 'unrestricted)))
9377 ((and (symbolp files) (fboundp files))
9378 (setq files (funcall files)))
9379 ((and (symbolp files) (boundp files))
9380 (setq files (symbol-value files))))
9381 (if (stringp files) (setq files (list files)))
9383 ((eq (car desc) :tag)
9384 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9385 ((eq (car desc) :todo)
9386 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9387 ((eq (car desc) :regexp)
9388 (setq descre (cdr desc)))
9389 ((eq (car desc) :level)
9390 (setq descre (concat "^\\*\\{" (number-to-string
9391 (if org-odd-levels-only
9392 (1- (* 2 (cdr desc)))
9395 ((eq (car desc) :maxlevel)
9396 (setq fast-path-p t)
9397 (setq descre (concat "^\\*\\{1," (number-to-string
9398 (if org-odd-levels-only
9399 (1- (* 2 (cdr desc)))
9402 (t (error "Bad refiling target description %s" desc)))
9403 (while (setq f (pop files))
9404 (with-current-buffer
9405 (if (bufferp f) f (org-get-agenda-file-buffer f))
9406 (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
9407 (setq f (and f (expand-file-name f)))
9408 (if (eq org-refile-use-outline-path 'file)
9409 (push (list (file-name-nondirectory f) f nil nil) targets))
9413 (goto-char (point-min))
9414 (while (re-search-forward descre nil t)
9415 (goto-char (setq pos0 (point-at-bol)))
9417 (when org-refile-target-verify-function
9419 (or (funcall org-refile-target-verify-function)
9421 (when (looking-at org-complex-heading-regexp)
9422 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
9423 txt (org-link-display-format (match-string 4))
9424 re (concat "^" (regexp-quote
9425 (buffer-substring (match-beginning 1)
9427 (if (match-end 5) (setq re (concat re "[ \t]+"
9429 (match-string 5)))))
9430 (setq re (concat re "[ \t]*$"))
9431 (when org-refile-use-outline-path
9432 (setq txt (mapconcat 'org-protect-slash
9434 (if (eq org-refile-use-outline-path 'file)
9435 (list (file-name-nondirectory
9436 (buffer-file-name (buffer-base-buffer))))
9437 (if (eq org-refile-use-outline-path 'full-file-path)
9438 (list (buffer-file-name (buffer-base-buffer)))))
9439 (org-get-outline-path fast-path-p level txt)
9442 (push (list txt f re (point)) targets)))
9443 (when (= (point) pos0)
9444 ;; verification function has not moved point
9445 (goto-char (point-at-eol))))))))))
9446 (message "Getting targets...done")
9447 (nreverse targets)))
9449 (defun org-protect-slash (s)
9450 (while (string-match "/" s)
9451 (setq s (replace-match "\\" t t s)))
9454 (defvar org-olpa (make-vector 20 nil))
9456 (defun org-get-outline-path (&optional fastp level heading)
9457 "Return the outline path to the current entry, as a list.
9458 The parameters FASTP, LEVEL, and HEADING are for use be a scanner
9459 routine which makes outline path derivations for an entire file,
9460 avoiding backtracing."
9464 (error "Outline path failure, more than 19 levels."))
9465 (loop for i from level upto 19 do
9466 (aset org-olpa i nil))
9468 (delq nil (append org-olpa nil))
9469 (aset org-olpa level heading)))
9470 (let (rtn case-fold-search)
9474 (while (org-up-heading-safe)
9475 (when (looking-at org-complex-heading-regexp)
9476 (push (org-match-string-no-properties 4) rtn)))
9479 (defun org-format-outline-path (path &optional width prefix)
9480 "Format the outlie path PATH for display.
9481 Width is the maximum number of characters that is available.
9482 Prefix is a prefix to be included in the returned string,
9483 such as the file name."
9484 (setq width (or width 79))
9485 (if prefix (setq width (- width (length prefix))))
9488 (let* ((nsteps (length path))
9489 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9490 (maxwidth (if (<= total-width width)
9491 10000 ;; everything fits
9492 ;; we need to shorten the level headings
9493 (/ (- width nsteps) nsteps)))
9494 (org-odd-levels-only nil)
9496 (total (1+ (length prefix))))
9497 (setq maxwidth (max maxwidth 10))
9502 (if (and (= n nsteps) (< maxwidth 10000))
9503 (setq maxwidth (- total-width total)))
9504 (if (< (length h) maxwidth)
9505 (progn (setq total (+ total (length h) 1)) h)
9506 (setq h (substring h 0 (- maxwidth 2))
9507 total (+ total maxwidth 1))
9508 (if (string-match "[ \t]+\\'" h)
9509 (setq h (substring h 0 (match-beginning 0))))
9510 (setq h (concat h "..")))
9511 (org-add-props h nil 'face
9512 (nth (% (1- n) org-n-level-faces)
9517 (defun org-display-outline-path (&optional file current)
9518 "Display the current outline path in the echo area."
9520 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9521 (case-fold-search nil)
9522 (path (and (org-mode-p) (org-get-outline-path))))
9523 (if current (setq path (append path
9525 (org-back-to-heading t)
9526 (if (looking-at org-complex-heading-regexp)
9527 (list (match-string 4)))))))
9529 (org-format-outline-path
9532 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9534 (defvar org-refile-history nil
9535 "History for refiling operations.")
9537 (defvar org-after-refile-insert-hook nil
9538 "Hook run after `org-refile' has inserted its stuff at the new location.
9539 Note that this is still *before* the stuff will be removed from
9540 the *old* location.")
9542 (defun org-refile (&optional goto default-buffer rfloc)
9543 "Move the entry at point to another heading.
9544 The list of target headings is compiled using the information in
9545 `org-refile-targets', which see. This list is created before each use
9546 and will therefore always be up-to-date.
9548 At the target location, the entry is filed as a subitem of the target heading.
9549 Depending on `org-reverse-note-order', the new subitem will either be the
9550 first or the last subitem.
9552 If there is an active region, all entries in that region will be moved.
9553 However, the region must fulfil the requirement that the first heading
9554 is the first one sets the top-level of the moved text - at most siblings
9555 below it are allowed.
9557 With prefix arg GOTO, the command will only visit the target location,
9558 not actually move anything.
9559 With a double prefix `C-u C-u', go to the location where the last refiling
9560 operation has put the subtree.
9561 With a prefix argument of `2', refile to the running clock.
9563 RFLOC can be a refile location obtained in a different way.
9565 See also `org-refile-use-outline-path' and `org-completion-use-ido'"
9567 (let* ((cbuf (current-buffer))
9568 (regionp (org-region-active-p))
9569 (region-start (and regionp (region-beginning)))
9570 (region-end (and regionp (region-end)))
9571 (region-length (and regionp (- region-end region-start)))
9572 (filename (buffer-file-name (buffer-base-buffer cbuf)))
9573 pos it nbuf file re level reversed)
9574 (setq last-command nil)
9576 (goto-char region-start)
9577 (or (bolp) (goto-char (point-at-bol)))
9578 (setq region-start (point))
9579 (unless (org-kill-is-subtree-p
9580 (buffer-substring region-start region-end))
9581 (error "The region is not a (sequence of) subtree(s)")))
9582 (if (equal goto '(16))
9583 (org-refile-goto-last-stored)
9586 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
9588 (setq it (list (or org-clock-heading "running clock")
9590 (marker-buffer org-clock-hd-marker))
9592 (marker-position org-clock-hd-marker)))
9596 (org-refile-get-location
9597 (if goto "Goto: " "Refile to: ") default-buffer
9598 org-refile-allow-creating-parent-nodes)))))
9599 (setq file (nth 1 it)
9604 (equal (buffer-file-name) file)
9606 (and (>= pos region-start)
9607 (<= pos region-end))
9608 (and (>= pos (point))
9609 (< pos (save-excursion
9610 (org-end-of-subtree t t))))))
9611 (error "Cannot refile to position inside the tree or region"))
9613 (setq nbuf (or (find-buffer-visiting file)
9614 (find-file-noselect file)))
9617 (switch-to-buffer nbuf)
9619 (org-show-context 'org-goto))
9622 (org-kill-new (buffer-substring region-start region-end))
9623 (org-save-markers-in-region region-start region-end))
9624 (org-copy-subtree 1 nil t))
9625 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
9626 (find-file-noselect file)))
9627 (setq reversed (org-notes-order-reversed-p))
9634 (looking-at outline-regexp)
9635 (setq level (org-get-valid-level (funcall outline-level) 1))
9638 (or (outline-next-heading) (point-max))
9639 (or (save-excursion (org-get-next-sibling))
9640 (org-end-of-subtree t t)
9644 (goto-char (point-max))
9645 (goto-char (point-min))
9646 (or (outline-next-heading) (goto-char (point-max)))))
9647 (if (not (bolp)) (newline))
9648 (org-paste-subtree level)
9649 (when org-log-refile
9650 (org-add-log-setup 'refile nil nil 'findpos
9652 (unless (eq org-log-refile 'note)
9653 (save-excursion (org-add-log-note))))
9654 (and org-auto-align-tags (org-set-tags nil t))
9655 (bookmark-set "org-refile-last-stored")
9656 (if (fboundp 'deactivate-mark) (deactivate-mark))
9657 (run-hooks 'org-after-refile-insert-hook))))
9659 (delete-region (point) (+ (point) region-length))
9661 (when (featurep 'org-inlinetask)
9662 (org-inlinetask-remove-END-maybe))
9663 (setq org-markers-to-move nil)
9664 (message "Refiled to \"%s\"" (car it))))))
9667 (defun org-refile-goto-last-stored ()
9668 "Go to the location where the last refile was stored."
9670 (bookmark-jump "org-refile-last-stored")
9671 (message "This is the location of the last refile"))
9673 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
9674 "Prompt the user for a refile location, using PROMPT."
9675 (let ((org-refile-targets org-refile-targets)
9676 (org-refile-use-outline-path org-refile-use-outline-path))
9677 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
9678 (unless org-refile-target-table
9679 (error "No refile targets"))
9680 (let* ((cbuf (current-buffer))
9681 (partial-completion-mode nil)
9682 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
9683 (cfunc (if (and org-refile-use-outline-path
9684 org-outline-path-complete-in-steps)
9685 'org-olpath-completing-read
9686 'org-icompleting-read))
9687 (extra (if org-refile-use-outline-path "/" ""))
9688 (filename (and cfn (expand-file-name cfn)))
9691 (if (and (not (member org-refile-use-outline-path
9692 '(file full-file-path)))
9693 (not (equal filename (nth 1 x))))
9694 (cons (concat (car x) extra " ("
9695 (file-name-nondirectory (nth 1 x)) ")")
9697 (cons (concat (car x) extra) (cdr x))))
9698 org-refile-target-table))
9699 (completion-ignore-case t)
9700 pa answ parent-target child parent old-hist)
9701 (setq old-hist org-refile-history)
9702 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
9703 nil 'org-refile-history))
9704 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
9707 (when (or (not org-refile-history)
9708 (not (eq old-hist org-refile-history))
9709 (not (equal (car pa) (car org-refile-history))))
9710 (setq org-refile-history
9711 (cons (car pa) (if (assoc (car org-refile-history) tbl)
9713 (cdr org-refile-history))))
9714 (if (equal (car org-refile-history) (nth 1 org-refile-history))
9715 (pop org-refile-history)))
9717 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
9719 (setq parent (match-string 1 answ)
9720 child (match-string 2 answ))
9721 (setq parent-target (or (assoc parent tbl)
9722 (assoc (concat parent "/") tbl)))
9723 (when (and parent-target
9724 (or (eq new-nodes t)
9725 (and (eq new-nodes 'confirm)
9726 (y-or-n-p (format "Create new node \"%s\"? "
9728 (org-refile-new-child parent-target child)))
9729 (error "Invalid target location")))))
9731 (defun org-refile-new-child (parent-target child)
9732 "Use refile target PARENT-TARGET to add new CHILD below it."
9733 (unless parent-target
9734 (error "Cannot find parent for new node"))
9735 (let ((file (nth 1 parent-target))
9736 (pos (nth 3 parent-target))
9738 (with-current-buffer (or (find-buffer-visiting file)
9739 (find-file-noselect file))
9745 (goto-char (point-max))
9746 (if (not (bolp)) (newline)))
9747 (when (looking-at outline-regexp)
9748 (setq level (funcall outline-level))
9749 (org-end-of-subtree t t))
9750 (org-back-over-empty-lines)
9751 (insert "\n" (make-string
9752 (if pos (org-get-valid-level level 1) 1) ?*)
9754 (beginning-of-line 0)
9755 (list (concat (car parent-target) "/" child) file "" (point)))))))
9757 (defun org-olpath-completing-read (prompt collection &rest args)
9758 "Read an outline path like a file name."
9759 (let ((thetable collection)
9760 (org-completion-use-ido nil) ; does not work with ido.
9761 (org-completion-use-iswitchb nil)) ; or iswitchb
9763 'org-icompleting-read prompt
9764 (lambda (string predicate &optional flag)
9765 (let (rtn r f (l (length string)))
9769 (try-completion string thetable))
9772 (setq rtn (all-completions string thetable predicate))
9775 (setq r (substring x l))
9776 (if (string-match " ([^)]*)$" x)
9777 (setq f (match-string 0 x))
9779 (if (string-match "/" r)
9780 (concat string (substring r 0 (match-end 0)) f)
9785 (assoc string thetable)))
9791 (defun org-find-dblock (name)
9792 "Find the first dynamic block with name NAME in the buffer.
9793 If not found, stay at current position and return nil."
9796 (goto-char (point-min))
9797 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
9799 (match-beginning 0))))
9800 (if pos (goto-char pos))
9803 (defconst org-dblock-start-re
9804 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
9805 "Matches the start line of a dynamic block, with parameters.")
9807 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
9808 "Matches the end of a dynamic block.")
9810 (defun org-create-dblock (plist)
9811 "Create a dynamic block section, with parameters taken from PLIST.
9812 PLIST must contain a :name entry which is used as name of the block."
9813 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
9816 (let ((col (current-column))
9817 (name (plist-get plist :name)))
9818 (insert "#+BEGIN: " name)
9820 (if (eq (car plist) :name)
9821 (setq plist (cddr plist))
9822 (insert " " (prin1-to-string (pop plist)))))
9823 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
9824 (beginning-of-line -2)))
9826 (defun org-prepare-dblock ()
9827 "Prepare dynamic block for refresh.
9828 This empties the block, puts the cursor at the insert position and returns
9829 the property list including an extra property :name with the block name."
9830 (unless (looking-at org-dblock-start-re)
9831 (error "Not at a dynamic block"))
9832 (let* ((begdel (1+ (match-end 0)))
9833 (name (org-no-properties (match-string 1)))
9834 (params (append (list :name name)
9835 (read (concat "(" (match-string 3) ")")))))
9837 (beginning-of-line 1)
9838 (skip-chars-forward " \t")
9839 (setq params (plist-put params :indentation-column (current-column))))
9840 (unless (re-search-forward org-dblock-end-re nil t)
9841 (error "Dynamic block not terminated"))
9844 (list :content (buffer-substring
9845 begdel (match-beginning 0)))))
9846 (delete-region begdel (match-beginning 0))
9851 (defun org-map-dblocks (&optional command)
9852 "Apply COMMAND to all dynamic blocks in the current buffer.
9853 If COMMAND is not given, use `org-update-dblock'."
9854 (let ((cmd (or command 'org-update-dblock)))
9856 (goto-char (point-min))
9857 (while (re-search-forward org-dblock-start-re nil t)
9858 (goto-char (match-beginning 0))
9862 (error (message "Error during update of dynamic block"))))
9863 (unless (re-search-forward org-dblock-end-re nil t)
9864 (error "Dynamic block not terminated"))))))
9866 (defun org-dblock-update (&optional arg)
9867 "User command for updating dynamic blocks.
9868 Update the dynamic block at point. With prefix ARG, update all dynamic
9869 blocks in the buffer."
9872 (org-update-all-dblocks)
9873 (or (looking-at org-dblock-start-re)
9874 (org-beginning-of-dblock))
9875 (org-update-dblock)))
9877 (defun org-update-dblock ()
9878 "Update the dynamic block at point
9879 This means to empty the block, parse for parameters and then call
9880 the correct writing function."
9881 (save-window-excursion
9882 (let* ((pos (point))
9883 (line (org-current-line))
9884 (params (org-prepare-dblock))
9885 (name (plist-get params :name))
9886 (indent (plist-get params :indentation-column))
9887 (cmd (intern (concat "org-dblock-write:" name))))
9888 (message "Updating dynamic block `%s' at line %d..." name line)
9889 (funcall cmd params)
9890 (message "Updating dynamic block `%s' at line %d...done" name line)
9892 (when (and indent (> indent 0))
9893 (setq indent (make-string indent ?\ ))
9895 (org-beginning-of-dblock)
9897 (while (not (looking-at org-dblock-end-re))
9899 (beginning-of-line 2))
9900 (when (looking-at org-dblock-end-re)
9901 (and (looking-at "[ \t]+")
9903 (insert indent)))))))
9905 (defun org-beginning-of-dblock ()
9906 "Find the beginning of the dynamic block at point.
9907 Error if there is no such block at point."
9911 (if (and (re-search-backward org-dblock-start-re nil t)
9912 (setq beg (match-beginning 0))
9913 (re-search-forward org-dblock-end-re nil t)
9914 (> (match-end 0) pos))
9917 (error "Not in a dynamic block"))))
9919 (defun org-update-all-dblocks ()
9920 "Update all dynamic blocks in the buffer.
9921 This function can be used in a hook."
9923 (org-map-dblocks 'org-update-dblock)))
9928 (defconst org-additional-option-like-keywords
9929 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
9930 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
9931 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
9932 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
9934 "ORGTBL" "TBLFM:" "TBLNAME:"
9935 "BEGIN_EXAMPLE" "END_EXAMPLE"
9936 "BEGIN_QUOTE" "END_QUOTE"
9937 "BEGIN_VERSE" "END_VERSE"
9938 "BEGIN_CENTER" "END_CENTER"
9939 "BEGIN_SRC" "END_SRC"
9940 "CATEGORY" "COLUMNS"
9946 (defcustom org-structure-template-alist
9948 ("s" "#+begin_src ?\n\n#+end_src"
9949 "<src lang=\"?\">\n\n</src>")
9950 ("e" "#+begin_example\n?\n#+end_example"
9951 "<example>\n?\n</example>")
9952 ("q" "#+begin_quote\n?\n#+end_quote"
9953 "<quote>\n?\n</quote>")
9954 ("v" "#+begin_verse\n?\n#+end_verse"
9955 "<verse>\n?\n/verse>")
9956 ("c" "#+begin_center\n?\n#+end_center"
9957 "<center>\n?\n/center>")
9958 ("l" "#+begin_latex\n?\n#+end_latex"
9959 "<literal style=\"latex\">\n?\n</literal>")
9961 "<literal style=\"latex\">?</literal>")
9962 ("h" "#+begin_html\n?\n#+end_html"
9963 "<literal style=\"html\">\n?\n</literal>")
9965 "<literal style=\"html\">?</literal>")
9966 ("a" "#+begin_ascii\n?\n#+end_ascii")
9968 ("i" "#+include %file ?"
9969 "<include file=%file markup=\"?\">")
9971 "Structure completion elements.
9972 This is a list of abbreviation keys and values. The value gets inserted
9973 if you type `<' followed by the key and then press the completion key,
9974 usually `M-TAB'. %file will be replaced by a file name after prompting
9975 for the file using completion.
9976 There are two templates for each key, the first uses the original Org syntax,
9977 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
9978 the default when the /org-mtags.el/ module has been loaded. See also the
9979 variable `org-mtags-prefer-muse-templates'.
9980 This is an experimental feature, it is undecided if it is going to stay in."
9981 :group 'org-completion
9984 (string :tag "Template")
9985 (string :tag "Muse Template")))
9987 (defun org-try-structure-completion ()
9988 "Try to complete a structure template before point.
9989 This looks for strings like \"<e\" on an otherwise empty line and
9991 (let ((l (buffer-substring (point-at-bol) (point)))
9993 (when (and (looking-at "[ \t]*$")
9994 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
9995 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
9996 (org-complete-expand-structure-template (+ -1 (point-at-bol)
9997 (match-beginning 1)) a)
10000 (defun org-complete-expand-structure-template (start cell)
10001 "Expand a structure template."
10002 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10003 (rpl (nth (if musep 2 1) cell))
10005 (delete-region start (point))
10006 (when (string-match "\\`#\\+" rpl)
10009 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10010 (setq ind (buffer-substring (point-at-bol) (point))))
10012 (setq start (point))
10013 (if (string-match "%file" rpl)
10014 (setq rpl (replace-match
10018 (abbreviate-file-name (read-file-name "Include file: ")))
10021 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10022 (concat "\n" ind)))
10024 (if (re-search-backward "\\?" start t) (delete-char 1))))
10027 (defun org-complete (&optional arg)
10028 "Perform completion on word at point.
10029 At the beginning of a headline, this completes TODO keywords as given in
10030 `org-todo-keywords'.
10031 If the current word is preceded by a backslash, completes the TeX symbols
10032 that are supported for HTML support.
10033 If the current word is preceded by \"#+\", completes special words for
10034 setting file options.
10035 In the line after \"#+STARTUP:, complete valid keywords.\"
10036 At all other locations, this simply calls the value of
10037 `org-completion-fallback-command'."
10039 (org-without-partial-completion
10043 (beg1 (save-excursion
10044 (skip-chars-backward (org-re "[:alnum:]_@"))
10046 (beg (save-excursion
10047 (skip-chars-backward "a-zA-Z0-9_:$")
10049 (confirm (lambda (x) (stringp (car x))))
10050 (searchhead (equal (char-before beg) ?*))
10052 (when (and (member (char-before beg1) '(?. ?<))
10053 (setq a (assoc (buffer-substring beg1 (point))
10054 org-structure-template-alist)))
10055 (org-complete-expand-structure-template (1- beg1) a)
10057 (tag (and (equal (char-before beg1) ?:)
10058 (equal (char-after (point-at-bol)) ?*)))
10059 (prop (and (equal (char-before beg1) ?:)
10060 (not (equal (char-after (point-at-bol)) ?*))))
10061 (texp (equal (char-before beg) ?\\))
10062 (link (equal (char-before beg) ?\[))
10063 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10066 (startup (string-match "^#\\+STARTUP:.*"
10067 (buffer-substring (point-at-bol) (point))))
10068 (completion-ignore-case opt)
10080 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10081 (cons (match-string 2 x)
10082 (match-string 1 x))))
10083 (org-split-string (org-get-current-options) "\n")))
10084 (mapcar 'list org-additional-option-like-keywords)))
10086 (setq type :startup)
10087 org-startup-options)
10088 (link (append org-link-abbrev-alist-local
10089 org-link-abbrev-alist))
10092 (append org-entities-user org-entities))
10093 ((string-match "\\`\\*+[ \t]+\\'"
10094 (buffer-substring (point-at-bol) beg))
10096 (mapcar 'list org-todo-keywords-1))
10098 (setq type :searchhead)
10100 (goto-char (point-min))
10101 (while (re-search-forward org-todo-line-regexp nil t)
10103 (org-make-org-heading-search-string
10104 (match-string 3) t))
10107 (tag (setq type :tag beg beg1)
10108 (or org-tag-alist (org-get-buffer-tags)))
10109 (prop (setq type :prop beg beg1)
10110 (mapcar 'list (org-buffer-property-keys nil t t)))
10112 (call-interactively org-completion-fallback-command)
10113 (throw 'exit nil)))))
10114 (pattern (buffer-substring-no-properties beg end))
10115 (completion (try-completion pattern table confirm)))
10116 (cond ((eq completion t)
10117 (if (not (assoc (upcase pattern) table))
10118 (message "Already complete")
10119 (if (and (equal type :opt)
10120 (not (member (car (assoc (upcase pattern) table))
10121 org-additional-option-like-keywords)))
10122 (insert (substring (cdr (assoc (upcase pattern) table))
10124 (if (memq type '(:tag :prop)) (insert ":")))))
10126 (message "Can't find completion for \"%s\"" pattern)
10128 ((not (string= pattern completion))
10129 (delete-region beg end)
10130 (if (string-match " +$" completion)
10131 (setq completion (replace-match "" t t completion)))
10132 (insert completion)
10133 (if (get-buffer-window "*Completions*")
10134 (delete-window (get-buffer-window "*Completions*")))
10135 (if (assoc completion table)
10136 (if (eq type :todo) (insert " ")
10137 (if (memq type '(:tag :prop)) (insert ":"))))
10138 (if (and (equal type :opt) (assoc completion table))
10139 (message "%s" (substitute-command-keys
10140 "Press \\[org-complete] again to insert example settings"))))
10142 (message "Making completion list...")
10143 (let ((list (sort (all-completions pattern table confirm)
10145 (with-output-to-temp-buffer "*Completions*"
10146 (condition-case nil
10147 ;; Protection needed for XEmacs and emacs 21
10148 (display-completion-list list pattern)
10149 (error (display-completion-list list)))))
10150 (message "Making completion list...%s" "done")))))))
10152 ;;;; TODO, DEADLINE, Comments
10154 (defun org-toggle-comment ()
10155 "Change the COMMENT state of an entry."
10158 (org-back-to-heading)
10159 (let (case-fold-search)
10160 (if (looking-at (concat outline-regexp
10161 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10162 (replace-match "" t t nil 1)
10163 (if (looking-at outline-regexp)
10165 (goto-char (match-end 0))
10166 (insert org-comment-string " ")))))))
10168 (defvar org-last-todo-state-is-todo nil
10169 "This is non-nil when the last TODO state change led to a TODO state.
10170 If the last change removed the TODO tag or switched to DONE, then
10173 (defvar org-setting-tags nil) ; dynamically skipped
10175 (defun org-parse-local-options (string var)
10176 "Parse STRING for startup setting relevant for variable VAR."
10177 (let ((rtn (symbol-value var))
10180 (if (or (not string) (not (string-match "\\S-" string)))
10182 (setq opts (delq nil (mapcar (lambda (x)
10183 (setq e (assoc x org-startup-options))
10184 (if (eq (nth 1 e) var) e nil))
10185 (org-split-string string "[ \t]+"))))
10189 (while (setq e (pop opts))
10190 (if (not (nth 3 e))
10191 (setq rtn (nth 2 e))
10192 (if (not (listp rtn)) (setq rtn nil))
10193 (push (nth 2 e) rtn)))
10196 (defvar org-todo-setup-filter-hook nil
10197 "Hook for functions that pre-filter todo specs.
10199 Each function takes a todo spec and returns either `nil' or the spec
10200 transformed into canonical form." )
10202 (defvar org-todo-get-default-hook nil
10203 "Hook for functions that get a default item for todo.
10205 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10206 `nil' or a string to be used for the todo mark." )
10208 (defvar org-agenda-headline-snapshot-before-repeat)
10210 (defun org-todo (&optional arg)
10211 "Change the TODO state of an item.
10212 The state of an item is given by a keyword at the start of the heading,
10214 *** TODO Write paper
10217 The different keywords are specified in the variable `org-todo-keywords'.
10218 By default the available states are \"TODO\" and \"DONE\".
10219 So for this example: when the item starts with TODO, it is changed to DONE.
10220 When it starts with DONE, the DONE is removed. And when neither TODO nor
10221 DONE are present, add TODO at the beginning of the heading.
10223 With C-u prefix arg, use completion to determine the new state.
10224 With numeric prefix arg, switch to that state.
10225 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10226 With a triple C-u prefix, circumvent any state blocking.
10228 For calling through lisp, arg is also interpreted in the following way:
10229 'none -> empty state
10230 \"\"(empty string) -> switch to empty state
10231 'done -> switch to DONE
10232 'nextset -> switch to the next set of keywords
10233 'previousset -> switch to the previous set of keywords
10234 \"WAITING\" -> switch to the specified keyword, but only if it
10235 really is a member of `org-todo-keywords'."
10237 (if (equal arg '(16)) (setq arg 'nextset))
10238 (let ((org-blocker-hook org-blocker-hook)
10239 (case-fold-search nil))
10240 (when (equal arg '(64))
10241 (setq arg nil org-blocker-hook nil))
10242 (when (and org-blocker-hook
10243 (or org-inhibit-blocking
10244 (org-entry-get nil "NOBLOCKING")))
10245 (setq org-blocker-hook nil))
10248 (org-back-to-heading t)
10249 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10250 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10252 (let* ((match-data (match-data))
10253 (startpos (point-at-bol))
10254 (logging (save-match-data (org-entry-get nil "LOGGING" t)))
10255 (org-log-done org-log-done)
10256 (org-log-repeat org-log-repeat)
10257 (org-todo-log-states org-todo-log-states)
10258 (this (match-string 1))
10259 (hl-pos (match-beginning 0))
10260 (head (org-get-todo-sequence-head this))
10261 (ass (assoc head org-todo-kwd-alist))
10262 (interpret (nth 1 ass))
10263 (done-word (nth 3 ass))
10264 (final-done-word (nth 4 ass))
10265 (last-state (or this ""))
10266 (completion-ignore-case t)
10267 (member (member this org-todo-keywords-1))
10268 (tail (cdr member))
10270 ((and org-todo-key-trigger
10271 (or (and (equal arg '(4))
10272 (eq org-use-fast-todo-selection 'prefix))
10273 (and (not arg) org-use-fast-todo-selection
10274 (not (eq org-use-fast-todo-selection
10276 ;; Use fast selection
10277 (org-fast-todo-selection))
10278 ((and (equal arg '(4))
10279 (or (not org-use-fast-todo-selection)
10280 (not org-todo-key-trigger)))
10281 ;; Read a state with completion
10282 (org-icompleting-read
10283 "State: " (mapcar (lambda(x) (list x))
10284 org-todo-keywords-1)
10288 (if tail (car tail) nil)
10289 (car org-todo-keywords-1)))
10291 (if (equal member org-todo-keywords-1)
10294 (nth (- (length org-todo-keywords-1)
10296 org-todo-keywords-1)
10297 (org-last org-todo-keywords-1))))
10298 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10299 (setq arg nil))) ; hack to fall back to cycling
10301 ;; user or caller requests a specific state
10303 ((equal arg "") nil)
10304 ((eq arg 'none) nil)
10305 ((eq arg 'done) (or done-word (car org-done-keywords)))
10307 (or (car (cdr (member head org-todo-heads)))
10308 (car org-todo-heads)))
10309 ((eq arg 'previousset)
10310 (let ((org-todo-heads (reverse org-todo-heads)))
10311 (or (car (cdr (member head org-todo-heads)))
10312 (car org-todo-heads))))
10313 ((car (member arg org-todo-keywords-1)))
10315 (error "State `%s' not valid in this file" arg))
10316 ((nth (1- (prefix-numeric-value arg))
10317 org-todo-keywords-1))))
10318 ((null member) (or head (car org-todo-keywords-1)))
10319 ((equal this final-done-word) nil) ;; -> make empty
10320 ((null tail) nil) ;; -> first entry
10321 ((memq interpret '(type priority))
10322 (if (eq this-command last-command)
10324 (if (> (length tail) 0)
10325 (or done-word (car org-done-keywords))
10330 (run-hook-with-args-until-success
10331 'org-todo-get-default-hook state last-state)
10333 (next (if state (concat " " state " ") " "))
10334 (change-plist (list :type 'todo-state-change :from this :to state
10335 :position startpos))
10337 (when org-blocker-hook
10338 (setq org-last-todo-state-is-todo
10339 (not (member this org-done-keywords)))
10340 (unless (save-excursion
10342 (run-hook-with-args-until-failure
10343 'org-blocker-hook change-plist)))
10344 (if (interactive-p)
10345 (error "TODO state change from %s to %s blocked" this state)
10347 (message "TODO state change from %s to %s blocked" this state)
10348 (throw 'exit nil))))
10349 (store-match-data match-data)
10350 (replace-match next t t)
10351 (unless (pos-visible-in-window-p hl-pos)
10352 (message "TODO state changed to %s" (org-trim next)))
10354 (setq head (org-get-todo-sequence-head state)
10355 ass (assoc head org-todo-kwd-alist)
10356 interpret (nth 1 ass)
10357 done-word (nth 3 ass)
10358 final-done-word (nth 4 ass)))
10359 (when (memq arg '(nextset previousset))
10360 (message "Keyword-Set %d/%d: %s"
10361 (- (length org-todo-sets) -1
10362 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10363 (length org-todo-sets)
10364 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10365 (setq org-last-todo-state-is-todo
10366 (not (member state org-done-keywords)))
10367 (setq now-done-p (and (member state org-done-keywords)
10368 (not (member this org-done-keywords))))
10369 (and logging (org-local-logging logging))
10370 (when (and (or org-todo-log-states org-log-done)
10371 (not (eq org-inhibit-logging t))
10372 (not (memq arg '(nextset previousset))))
10373 ;; we need to look at recording a time and note
10374 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10375 (nth 2 (assoc this org-todo-log-states))))
10376 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10377 (setq dolog 'time))
10379 (member state org-not-done-keywords)
10380 (not (member this org-not-done-keywords)))
10381 ;; This is now a todo state and was not one before
10382 ;; If there was a CLOSED time stamp, get rid of it.
10383 (org-add-planning-info nil nil 'closed))
10384 (when (and now-done-p org-log-done)
10385 ;; It is now done, and it was not done before
10386 (org-add-planning-info 'closed (org-current-time))
10387 (if (and (not dolog) (eq 'note org-log-done))
10388 (org-add-log-setup 'done state this 'findpos 'note)))
10389 (when (and state dolog)
10390 ;; This is a non-nil state, and we need to log it
10391 (org-add-log-setup 'state state this 'findpos dolog)))
10392 ;; Fixup tag positioning
10393 (org-todo-trigger-tag-changes state)
10394 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10395 (when org-provide-todo-statistics
10396 (org-update-parent-todo-statistics))
10397 (run-hooks 'org-after-todo-state-change-hook)
10398 (if (and arg (not (member state org-done-keywords)))
10399 (setq head (org-get-todo-sequence-head state)))
10400 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10401 ;; Do we need to trigger a repeat?
10403 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10404 ;; This is for the agenda, take a snapshot of the headline.
10406 (setq org-agenda-headline-snapshot-before-repeat
10407 (org-get-heading))))
10408 (org-auto-repeat-maybe state))
10409 ;; Fixup cursor location if close to the keyword
10410 (if (and (outline-on-heading-p)
10412 (save-excursion (beginning-of-line 1)
10413 (looking-at org-todo-line-regexp))
10414 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10416 (goto-char (or (match-end 2) (match-end 1)))
10417 (and (looking-at " ") (just-one-space))))
10418 (when org-trigger-hook
10420 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10422 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10423 "Block turning an entry into a TODO, using the hierarchy.
10424 This checks whether the current task should be blocked from state
10425 changes. Such blocking occurs when:
10427 1. The task has children which are not all in a completed state.
10429 2. A task has a parent with the property :ORDERED:, and there
10430 are siblings prior to the current task with incomplete
10433 3. The parent of the task is blocked because it has siblings that should
10434 be done first, or is child of a block grandparent TODO entry."
10436 (if (not org-enforce-todo-dependencies)
10437 t ; if locally turned off don't block
10439 ;; If this is not a todo state change, or if this entry is already DONE,
10441 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10442 (member (plist-get change-plist :from)
10443 (cons 'done org-done-keywords))
10444 (member (plist-get change-plist :to)
10445 (cons 'todo org-not-done-keywords))
10446 (not (plist-get change-plist :to)))
10447 (throw 'dont-block t))
10448 ;; If this task has children, and any are undone, it's blocked
10450 (org-back-to-heading t)
10451 (let ((this-level (funcall outline-level)))
10452 (outline-next-heading)
10453 (let ((child-level (funcall outline-level)))
10454 (while (and (not (eobp))
10455 (> child-level this-level))
10456 ;; this todo has children, check whether they are all
10458 (if (and (not (org-entry-is-done-p))
10459 (org-entry-is-todo-p))
10460 (throw 'dont-block nil))
10461 (outline-next-heading)
10462 (setq child-level (funcall outline-level))))))
10463 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10464 ;; any previous siblings are undone, it's blocked
10466 (org-back-to-heading t)
10467 (let* ((pos (point))
10468 (parent-pos (and (org-up-heading-safe) (point))))
10469 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10470 (when (and (org-entry-get (point) "ORDERED")
10472 (re-search-forward org-not-done-heading-regexp pos t))
10473 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10474 ;; Search further up the hierarchy, to see if an anchestor is blocked
10476 (goto-char parent-pos)
10477 (if (not (looking-at org-not-done-heading-regexp))
10478 (throw 'dont-block t)) ; do not block, parent is not a TODO
10480 (setq parent-pos (and (org-up-heading-safe) (point)))
10481 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10482 (when (and (org-entry-get (point) "ORDERED")
10484 (re-search-forward org-not-done-heading-regexp pos t))
10485 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10487 (defcustom org-track-ordered-property-with-tag nil
10488 "Should the ORDERED property also be shown as a tag?
10489 The ORDERED property decides if an entry should require subtasks to be
10490 completed in sequence. Since a property is not very visible, setting
10491 this option means that toggling the ORDERED property with the command
10492 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10493 not relevant for the behavior, but it makes things more visible.
10495 Note that toggling the tag with tags commands will not change the property
10496 and therefore not influence behavior!
10498 This can be t, meaning the tag ORDERED should be used, It can also be a
10499 string to select a different tag for this task."
10502 (const :tag "No tracking" nil)
10503 (const :tag "Track with ORDERED tag" t)
10504 (string :tag "Use other tag")))
10506 (defun org-toggle-ordered-property ()
10507 "Toggle the ORDERED property of the current entry.
10508 For better visibility, you can track the value of this property with a tag.
10509 See variable `org-track-ordered-property-with-tag'."
10511 (let* ((t1 org-track-ordered-property-with-tag)
10512 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10514 (org-back-to-heading)
10515 (if (org-entry-get nil "ORDERED")
10517 (org-delete-property "ORDERED")
10518 (and tag (org-toggle-tag tag 'off))
10519 (message "Subtasks can be completed in arbitrary order"))
10520 (org-entry-put nil "ORDERED" "t")
10521 (and tag (org-toggle-tag tag 'on))
10522 (message "Subtasks must be completed in sequence")))))
10524 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10525 (defun org-block-todo-from-checkboxes (change-plist)
10526 "Block turning an entry into a TODO, using checkboxes.
10527 This checks whether the current task should be blocked from state
10528 changes because there are unchecked boxes in this entry."
10529 (if (not org-enforce-todo-checkbox-dependencies)
10530 t ; if locally turned off don't block
10532 ;; If this is not a todo state change, or if this entry is already DONE,
10534 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10535 (member (plist-get change-plist :from)
10536 (cons 'done org-done-keywords))
10537 (member (plist-get change-plist :to)
10538 (cons 'todo org-not-done-keywords))
10539 (not (plist-get change-plist :to)))
10540 (throw 'dont-block t))
10541 ;; If this task has checkboxes that are not checked, it's blocked
10543 (org-back-to-heading t)
10544 (let ((beg (point)) end)
10545 (outline-next-heading)
10548 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10551 (if (boundp 'org-blocked-by-checkboxes)
10552 (setq org-blocked-by-checkboxes t))
10553 (throw 'dont-block nil)))))
10554 t))) ; do not block
10556 (defun org-entry-blocked-p ()
10557 "Is the current entry blocked?"
10558 (if (org-entry-get nil "NOBLOCKING")
10559 nil ;; Never block this entry
10561 (run-hook-with-args-until-failure
10563 (list :type 'todo-state-change
10568 (defun org-update-statistics-cookies (all)
10569 "Update the statistics cookie, either from TODO or from checkboxes.
10570 This should be called with the cursor in a line with a statistics cookie."
10574 (org-update-checkbox-count 'all)
10575 (org-map-entries 'org-update-parent-todo-statistics))
10576 (if (not (org-on-heading-p))
10577 (org-update-checkbox-count)
10578 (let ((pos (move-marker (make-marker) (point)))
10580 (ignore-errors (org-back-to-heading t))
10581 (if (not (org-on-heading-p))
10582 (org-update-checkbox-count)
10583 (setq l1 (org-outline-level))
10584 (setq end (save-excursion
10585 (outline-next-heading)
10586 (if (org-on-heading-p) (setq l2 (org-outline-level)))
10588 (if (and (save-excursion
10590 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
10591 (not (save-excursion (re-search-forward
10592 ":COOKIE_DATA:.*\\<todo\\>" end t))))
10593 (org-update-checkbox-count)
10594 (if (and l2 (> l2 l1))
10597 (org-update-parent-todo-statistics))
10599 (beginning-of-line 1)
10600 (while (re-search-forward
10601 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
10603 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
10605 (move-marker pos nil)))))
10607 (defvar org-entry-property-inherited-from) ;; defined below
10608 (defun org-update-parent-todo-statistics ()
10609 "Update any statistics cookie in the parent of the current headline.
10610 When `org-hierarchical-todo-statistics' is nil, statistics will cover
10611 the entire subtree and this will travel up the hierarchy and update
10612 statistics everywhere."
10614 (let* ((lim 0) prop
10615 (recursive (or (not org-hierarchical-todo-statistics)
10618 (or (setq prop (org-entry-get
10619 nil "COOKIE_DATA" 'inherit)) ""))))
10620 (lim (or (and prop (marker-position
10621 org-entry-property-inherited-from))
10624 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
10625 level ltoggle l1 new ndel
10626 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
10629 (beginning-of-line 1)
10630 (if (org-at-heading-p)
10631 (setq ltoggle (funcall outline-level))
10632 (error "This should not happen"))
10633 (while (and (setq level (org-up-heading-safe))
10634 (or recursive first)
10636 (setq first nil cookie-present nil)
10645 (while (re-search-forward box-re (point-at-eol) t)
10646 (setq cnt-all 0 cnt-done 0 cookie-present t)
10647 (setq is-percent (match-end 2))
10649 (unless (outline-next-heading) (throw 'exit nil))
10650 (while (and (looking-at org-complex-heading-regexp)
10651 (> (setq l1 (length (match-string 1))) level))
10652 (setq kwd (and (or recursive (= l1 ltoggle))
10654 (if (or (eq org-provide-todo-statistics 'all-headlines)
10655 (and (listp org-provide-todo-statistics)
10656 (or (member kwd org-provide-todo-statistics)
10657 (member kwd org-done-keywords))))
10658 (setq cnt-all (1+ cnt-all))
10659 (if (eq org-provide-todo-statistics t)
10660 (and kwd (setq cnt-all (1+ cnt-all)))))
10661 (and (member kwd org-done-keywords)
10662 (setq cnt-done (1+ cnt-done)))
10663 (outline-next-heading)))
10666 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
10667 (format "[%d/%d]" cnt-done cnt-all))
10668 ndel (- (match-end 0) (match-beginning 0)))
10669 (goto-char (match-beginning 0))
10671 (delete-region (point) (+ (point) ndel)))
10672 (when cookie-present
10673 (run-hook-with-args 'org-after-todo-statistics-hook
10674 cnt-done (- cnt-all cnt-done))))))
10675 (run-hooks 'org-todo-statistics-hook)))
10677 (defvar org-after-todo-statistics-hook nil
10678 "Hook that is called after a TODO statistics cookie has been updated.
10679 Each function is called with two arguments: the number of not-done entries
10680 and the number of done entries.
10682 For example, the following function, when added to this hook, will switch
10683 an entry to DONE when all children are done, and back to TODO when new
10684 entries are set to a TODO status. Note that this hook is only called
10685 when there is a statistics cookie in the headline!
10687 (defun org-summary-todo (n-done n-not-done)
10688 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
10689 (let (org-log-done org-log-states) ; turn off logging
10690 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
10693 (defvar org-todo-statistics-hook nil
10694 "Hook that is run whenever Org thinks TODO statistics should be updated.
10695 This hook runs even if there is no statistics cookie present, in which case
10696 `org-after-todo-statistics-hook' would not run.")
10698 (defun org-todo-trigger-tag-changes (state)
10699 "Apply the changes defined in `org-todo-state-tags-triggers'."
10700 (let ((l org-todo-state-tags-triggers)
10702 (when (or (not state) (equal state ""))
10703 (setq changes (append changes (cdr (assoc "" l)))))
10704 (when (and (stringp state) (> (length state) 0))
10705 (setq changes (append changes (cdr (assoc state l)))))
10706 (when (member state org-not-done-keywords)
10707 (setq changes (append changes (cdr (assoc 'todo l)))))
10708 (when (member state org-done-keywords)
10709 (setq changes (append changes (cdr (assoc 'done l)))))
10710 (dolist (c changes)
10711 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
10713 (defun org-local-logging (value)
10714 "Get logging settings from a property VALUE."
10716 ;; directly set the variables, they are already local.
10717 (setq org-log-done nil
10719 org-todo-log-states nil)
10720 (setq words (org-split-string value))
10721 (while (setq w (pop words))
10723 ((setq a (assoc w org-startup-options))
10724 (and (member (nth 1 a) '(org-log-done org-log-repeat))
10725 (set (nth 1 a) (nth 2 a))))
10726 ((setq a (org-extract-log-state-settings w))
10727 (and (member (car a) org-todo-keywords-1)
10728 (push a org-todo-log-states)))))))
10730 (defun org-get-todo-sequence-head (kwd)
10731 "Return the head of the TODO sequence to which KWD belongs.
10732 If KWD is not set, check if there is a text property remembering the
10737 (or (get-text-property (point-at-bol) 'org-todo-head)
10739 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
10740 nil (point-at-eol)))
10741 (get-text-property p 'org-todo-head))))
10742 ((not (member kwd org-todo-keywords-1))
10743 (car org-todo-keywords-1))
10744 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
10746 (defun org-fast-todo-selection ()
10747 "Fast TODO keyword selection with single keys.
10748 Returns the new TODO keyword, or nil if no state change should occur."
10749 (let* ((fulltable org-todo-key-alist)
10750 (done-keywords org-done-keywords) ;; needed for the faces.
10751 (maxlen (apply 'max (mapcar
10753 (if (stringp (car x)) (string-width (car x)) 0))
10756 (fwidth (+ maxlen 3 1 3))
10757 (ncol (/ (- (window-width) 4) fwidth))
10761 (save-window-excursion
10763 (set-buffer (get-buffer-create " *Org todo*"))
10764 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
10766 (org-set-local 'org-done-keywords done-keywords)
10767 (setq tbl fulltable cnt 0)
10768 (while (setq e (pop tbl))
10770 ((equal e '(:startgroup))
10771 (push '() groups) (setq ingroup t)
10772 (when (not (= cnt 0))
10776 ((equal e '(:endgroup))
10777 (setq ingroup nil cnt 0)
10779 ((equal e '(:newline))
10780 (when (not (= cnt 0))
10784 (while (equal (car tbl) '(:newline))
10786 (setq tbl (cdr tbl)))))
10788 (setq tg (car e) c (cdr e))
10789 (if ingroup (push tg (car groups)))
10790 (setq tg (org-add-props tg nil 'face
10791 (org-get-todo-face tg)))
10792 (if (and (= cnt 0) (not ingroup)) (insert " "))
10793 (insert "[" c "] " tg (make-string
10794 (- fwidth 4 (length tg)) ?\ ))
10795 (when (= (setq cnt (1+ cnt)) ncol)
10797 (if ingroup (insert " "))
10800 (goto-char (point-min))
10801 (if (not expert) (org-fit-window-to-buffer))
10802 (message "[a-z..]:Set [SPC]:clear")
10803 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
10806 (and (= c ?q) (not (rassoc c fulltable))))
10807 (setq quit-flag t))
10809 ((setq e (rassoc c fulltable) tg (car e))
10811 (t (setq quit-flag t)))))))
10813 (defun org-entry-is-todo-p ()
10814 (member (org-get-todo-state) org-not-done-keywords))
10816 (defun org-entry-is-done-p ()
10817 (member (org-get-todo-state) org-done-keywords))
10819 (defun org-get-todo-state ()
10821 (org-back-to-heading t)
10822 (and (looking-at org-todo-line-regexp)
10824 (match-string 2))))
10826 (defun org-at-date-range-p (&optional inactive-ok)
10827 "Is the cursor inside a date range?"
10831 (let ((pos (point)))
10832 (skip-chars-backward "^[<\r\n")
10833 (skip-chars-backward "<[")
10834 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10835 (>= (match-end 0) pos)
10837 (skip-chars-backward "^<[\r\n")
10838 (skip-chars-backward "<[")
10839 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
10840 (>= (match-end 0) pos)
10844 (defun org-get-repeat (&optional tagline)
10845 "Check if there is a deadline/schedule with repeater in this entry."
10848 (org-back-to-heading t)
10849 (and (re-search-forward (if tagline
10850 (concat tagline "\\s-*" org-repeat-re)
10852 (org-entry-end-position) t)
10853 (match-string-no-properties 1)))))
10855 (defvar org-last-changed-timestamp)
10856 (defvar org-last-inserted-timestamp)
10857 (defvar org-log-post-message)
10858 (defvar org-log-note-purpose)
10859 (defvar org-log-note-how)
10860 (defvar org-log-note-extra)
10861 (defun org-auto-repeat-maybe (done-word)
10862 "Check if the current headline contains a repeated deadline/schedule.
10863 If yes, set TODO state back to what it was and change the base date
10864 of repeating deadline/scheduled time stamps to new date.
10865 This function is run automatically after each state change to a DONE state."
10866 ;; last-state is dynamically scoped into this function
10867 (let* ((repeat (org-get-repeat))
10868 (aa (assoc last-state org-todo-kwd-alist))
10869 (interpret (nth 1 aa))
10871 (whata '(("d" . day) ("m" . month) ("y" . year)))
10872 (msg "Entry repeats: ")
10874 (org-todo-log-states nil)
10875 (nshiftmax 10) (nshift 0)
10876 re type n what ts time to-state)
10878 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
10879 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
10880 org-todo-repeat-to-state))
10881 (unless (and to-state (member to-state org-todo-keywords-1))
10882 (setq to-state (if (eq interpret 'type) last-state head)))
10883 (org-todo to-state)
10884 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
10885 (org-entry-put nil "LAST_REPEAT" (format-time-string
10886 (org-time-stamp-format t t))))
10887 (when org-log-repeat
10888 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
10889 (memq 'org-add-log-note post-command-hook))
10890 ;; OK, we are already setup for some record
10891 (if (eq org-log-repeat 'note)
10892 ;; make sure we take a note, not only a time stamp
10893 (setq org-log-note-how 'note))
10894 ;; Set up for taking a record
10895 (org-add-log-setup 'state (or done-word (car org-done-keywords))
10897 'findpos org-log-repeat)))
10898 (org-back-to-heading t)
10899 (org-add-planning-info nil nil 'closed)
10900 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
10901 org-deadline-time-regexp "\\)\\|\\("
10902 org-ts-regexp "\\)"))
10903 (while (re-search-forward
10904 re (save-excursion (outline-next-heading) (point)) t)
10905 (setq type (if (match-end 1) org-scheduled-string
10906 (if (match-end 3) org-deadline-string "Plain:"))
10907 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
10908 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
10909 (setq n (string-to-number (match-string 2 ts))
10910 what (match-string 3 ts))
10911 (if (equal what "w") (setq n (* n 7) what "d"))
10912 ;; Preparation, see if we need to modify the start date for the change
10913 (when (match-end 1)
10914 (setq time (save-match-data (org-time-string-to-time ts)))
10916 ((equal (match-string 1 ts) ".")
10917 ;; Shift starting date to today
10918 (org-timestamp-change
10919 (- (time-to-days (current-time)) (time-to-days time))
10921 ((equal (match-string 1 ts) "+")
10922 (while (or (= nshift 0)
10923 (<= (time-to-days time) (time-to-days (current-time))))
10924 (when (= (incf nshift) nshiftmax)
10925 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
10927 (org-timestamp-change n (cdr (assoc what whata)))
10928 (org-at-timestamp-p t)
10929 (setq ts (match-string 1))
10930 (setq time (save-match-data (org-time-string-to-time ts))))
10931 (org-timestamp-change (- n) (cdr (assoc what whata)))
10932 ;; rematch, so that we have everything in place for the real shift
10933 (org-at-timestamp-p t)
10934 (setq ts (match-string 1))
10935 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
10936 (org-timestamp-change n (cdr (assoc what whata)))
10937 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
10938 (setq org-log-post-message msg)
10939 (message "%s" msg))))
10941 (defun org-show-todo-tree (arg)
10942 "Make a compact tree which shows all headlines marked with TODO.
10943 The tree will show the lines where the regexp matches, and all higher
10944 headlines above the match.
10945 With a \\[universal-argument] prefix, prompt for a regexp to match.
10946 With a numeric prefix N, construct a sparse tree for the Nth element
10947 of `org-todo-keywords-1'."
10949 (let ((case-fold-search nil)
10951 (cond ((null arg) org-not-done-regexp)
10953 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
10954 (mapcar 'list org-todo-keywords-1))))
10956 (mapconcat 'identity (org-split-string kwd "|") "\\|")
10958 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
10959 (regexp-quote (nth (1- (prefix-numeric-value arg))
10960 org-todo-keywords-1)))
10961 (t (error "Invalid prefix argument: %s" arg)))))
10962 (message "%d TODO entries found"
10963 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
10965 (defun org-deadline (&optional remove time)
10966 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
10967 With argument REMOVE, remove any deadline from the item.
10968 When TIME is set, it should be an internal time specification, and the
10969 scheduling will use the corresponding date."
10971 (let* ((old-date (org-entry-get nil "DEADLINE"))
10972 (repeater (and old-date
10973 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
10974 (match-string 1 old-date))))
10977 (when (and old-date org-log-redeadline)
10978 (org-add-log-setup 'deldeadline nil old-date 'findpos
10979 org-log-redeadline))
10980 (org-remove-timestamp-with-keyword org-deadline-string)
10981 (message "Item no longer has a deadline."))
10982 (org-add-planning-info 'deadline time 'closed)
10983 (when (and old-date org-log-redeadline
10984 (not (equal old-date
10985 (substring org-last-inserted-timestamp 1 -1))))
10986 (org-add-log-setup 'redeadline nil old-date 'findpos
10987 org-log-redeadline))
10990 (org-back-to-heading t)
10991 (when (re-search-forward (concat org-deadline-string " "
10992 org-last-inserted-timestamp)
10994 (outline-next-heading) (point)) t)
10995 (goto-char (1- (match-end 0)))
10996 (insert " " repeater)
10997 (setq org-last-inserted-timestamp
10998 (concat (substring org-last-inserted-timestamp 0 -1)
11000 (substring org-last-inserted-timestamp -1))))))
11001 (message "Deadline on %s" org-last-inserted-timestamp))))
11003 (defun org-schedule (&optional remove time)
11004 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11005 With argument REMOVE, remove any scheduling date from the item.
11006 When TIME is set, it should be an internal time specification, and the
11007 scheduling will use the corresponding date."
11009 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11010 (repeater (and old-date
11011 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11012 (match-string 1 old-date))))
11015 (when (and old-date org-log-reschedule)
11016 (org-add-log-setup 'delschedule nil old-date 'findpos
11017 org-log-reschedule))
11018 (org-remove-timestamp-with-keyword org-scheduled-string)
11019 (message "Item is no longer scheduled."))
11020 (org-add-planning-info 'scheduled time 'closed)
11021 (when (and old-date org-log-reschedule
11022 (not (equal old-date
11023 (substring org-last-inserted-timestamp 1 -1))))
11024 (org-add-log-setup 'reschedule nil old-date 'findpos
11025 org-log-reschedule))
11028 (org-back-to-heading t)
11029 (when (re-search-forward (concat org-scheduled-string " "
11030 org-last-inserted-timestamp)
11032 (outline-next-heading) (point)) t)
11033 (goto-char (1- (match-end 0)))
11034 (insert " " repeater)
11035 (setq org-last-inserted-timestamp
11036 (concat (substring org-last-inserted-timestamp 0 -1)
11038 (substring org-last-inserted-timestamp -1))))))
11039 (message "Scheduled to %s" org-last-inserted-timestamp))))
11041 (defun org-get-scheduled-time (pom &optional inherit)
11042 "Get the scheduled time as a time tuple, of a format suitable
11043 for calling org-schedule with, or if there is no scheduling,
11045 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11047 (apply 'encode-time (org-parse-time-string time)))))
11049 (defun org-get-deadline-time (pom &optional inherit)
11050 "Get the deadine as a time tuple, of a format suitable for
11051 calling org-deadline with, or if there is no scheduling, returns
11053 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11055 (apply 'encode-time (org-parse-time-string time)))))
11057 (defun org-remove-timestamp-with-keyword (keyword)
11058 "Remove all time stamps with KEYWORD in the current entry."
11059 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11062 (org-back-to-heading t)
11064 (outline-next-heading)
11065 (while (re-search-backward re beg t)
11067 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11068 (equal (char-before) ?\ ))
11069 (backward-delete-char 1)
11070 (if (string-match "^[ \t]*$" (buffer-substring
11071 (point-at-bol) (point-at-eol)))
11072 (delete-region (point-at-bol)
11073 (min (point-max) (1+ (point-at-eol))))))))))
11075 (defun org-add-planning-info (what &optional time &rest remove)
11076 "Insert new timestamp with keyword in the line directly after the headline.
11077 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11078 If non is given, the user is prompted for a date.
11079 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11082 (let (org-time-was-given org-end-time-was-given ts
11083 end default-time default-input)
11086 (when (and (not time) (memq what '(scheduled deadline)))
11087 ;; Try to get a default date/time from existing timestamp
11089 (org-back-to-heading t)
11090 (setq end (save-excursion (outline-next-heading) (point)))
11091 (when (re-search-forward (if (eq what 'scheduled)
11092 org-scheduled-time-regexp
11093 org-deadline-time-regexp)
11095 (setq ts (match-string 1)
11097 (apply 'encode-time (org-parse-time-string ts))
11098 default-input (and ts (org-get-compact-tod ts))))))
11100 ;; If necessary, get the time from the user
11101 (setq time (or time (org-read-date nil 'to-time nil nil
11102 default-time default-input))))
11104 (when (and org-insert-labeled-timestamps-at-point
11105 (member what '(scheduled deadline)))
11107 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11108 (org-insert-time-stamp time org-time-was-given
11109 nil nil nil (list org-end-time-was-given))
11113 (let (col list elt ts buffer-invisibility-spec)
11114 (org-back-to-heading t)
11115 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11116 (goto-char (match-end 1))
11117 (setq col (current-column))
11118 (goto-char (match-end 0))
11119 (if (eobp) (insert "\n") (forward-char 1))
11120 (when (and (not what)
11123 org-keyword-time-not-clock-regexp))))
11124 ;; Nothing to add, nothing to remove...... :-)
11126 (if (and (not (looking-at outline-regexp))
11127 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11129 (not (equal (match-string 1) org-clock-string)))
11130 (narrow-to-region (match-beginning 0) (match-end 0))
11131 (insert-before-markers "\n")
11133 (narrow-to-region (point) (point))
11134 (and org-adapt-indentation (org-indent-to-column col)))
11135 ;; Check if we have to remove something.
11136 (setq list (cons what remove))
11138 (setq elt (pop list))
11139 (goto-char (point-min))
11140 (when (or (and (eq elt 'scheduled)
11141 (re-search-forward org-scheduled-time-regexp nil t))
11142 (and (eq elt 'deadline)
11143 (re-search-forward org-deadline-time-regexp nil t))
11144 (and (eq elt 'closed)
11145 (re-search-forward org-closed-time-regexp nil t)))
11147 (if (looking-at "--+<[^>]+>") (replace-match ""))
11148 (skip-chars-backward " ")
11149 (if (looking-at " +") (replace-match ""))))
11150 (goto-char (point-max))
11151 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11154 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11155 (cond ((eq what 'scheduled) org-scheduled-string)
11156 ((eq what 'deadline) org-deadline-string)
11157 ((eq what 'closed) org-closed-string))
11159 (setq ts (org-insert-time-stamp
11161 (or org-time-was-given
11162 (and (eq what 'closed) org-log-done-with-time))
11164 nil nil (list org-end-time-was-given)))
11166 (goto-char (point-min))
11168 (if (and (looking-at "[ \t]+\n")
11169 (equal (char-before) ?\n))
11170 (delete-region (1- (point)) (point-at-eol)))
11173 (defvar org-log-note-marker (make-marker))
11174 (defvar org-log-note-purpose nil)
11175 (defvar org-log-note-state nil)
11176 (defvar org-log-note-previous-state nil)
11177 (defvar org-log-note-how nil)
11178 (defvar org-log-note-extra nil)
11179 (defvar org-log-note-window-configuration nil)
11180 (defvar org-log-note-return-to (make-marker))
11181 (defvar org-log-post-message nil
11182 "Message to be displayed after a log note has been stored.
11183 The auto-repeater uses this.")
11185 (defun org-add-note ()
11186 "Add a note to the current entry.
11187 This is done in the same way as adding a state change note."
11189 (org-add-log-setup 'note nil nil 'findpos nil))
11191 (defvar org-property-end-re)
11192 (defun org-add-log-setup (&optional purpose state prev-state
11193 findpos how &optional extra)
11194 "Set up the post command hook to take a note.
11195 If this is about to TODO state change, the new state is expected in STATE.
11196 When FINDPOS is non-nil, find the correct position for the note in
11197 the current entry. If not, assume that it can be inserted at point.
11198 HOW is an indicator what kind of note should be created.
11199 EXTRA is additional text that will be inserted into the notes buffer."
11200 (let* ((org-log-into-drawer (org-log-into-drawer))
11201 (drawer (cond ((stringp org-log-into-drawer)
11202 org-log-into-drawer)
11203 (org-log-into-drawer "LOGBOOK")
11208 (org-back-to-heading t)
11209 (narrow-to-region (point) (save-excursion
11210 (outline-next-heading) (point)))
11211 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11212 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11214 (goto-char (match-end 0))
11217 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11220 (goto-char (match-end 0))
11221 (or org-log-states-order-reversed
11222 (and (re-search-forward org-property-end-re nil t)
11223 (goto-char (1- (match-beginning 0))))))
11224 (insert "\n:" drawer ":\n:END:")
11225 (beginning-of-line 0)
11226 (org-indent-line-function)
11227 (beginning-of-line 2)
11228 (org-indent-line-function)
11230 ((and org-log-state-notes-insert-after-drawers
11232 (forward-line) (looking-at org-drawer-regexp)))
11234 (while (looking-at org-drawer-regexp)
11235 (goto-char (match-end 0))
11236 (re-search-forward org-property-end-re (point-max) t)
11238 (forward-line -1)))
11239 (unless org-log-states-order-reversed
11240 (and (= (char-after) ?\n) (forward-char 1))
11241 (org-skip-over-state-notes)
11242 (skip-chars-backward " \t\n\r")))
11243 (move-marker org-log-note-marker (point))
11244 (setq org-log-note-purpose purpose
11245 org-log-note-state state
11246 org-log-note-previous-state prev-state
11247 org-log-note-how how
11248 org-log-note-extra extra)
11249 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11251 (defun org-skip-over-state-notes ()
11252 "Skip past the list of State notes in an entry."
11253 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11254 (while (looking-at "[ \t]*- State")
11255 (condition-case nil
11257 (error (org-end-of-item)))))
11259 (defun org-add-log-note (&optional purpose)
11260 "Pop up a window for taking a note, and add this note later at point."
11261 (remove-hook 'post-command-hook 'org-add-log-note)
11262 (setq org-log-note-window-configuration (current-window-configuration))
11263 (delete-other-windows)
11264 (move-marker org-log-note-return-to (point))
11265 (switch-to-buffer (marker-buffer org-log-note-marker))
11266 (goto-char org-log-note-marker)
11267 (org-switch-to-buffer-other-window "*Org Note*")
11269 (if (memq org-log-note-how '(time state))
11270 (let (current-prefix-arg) (org-store-log-note))
11271 (let ((org-inhibit-startup t)) (org-mode))
11272 (insert (format "# Insert note for %s.
11273 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11275 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11276 ((eq org-log-note-purpose 'done) "closed todo item")
11277 ((eq org-log-note-purpose 'state)
11278 (format "state change from \"%s\" to \"%s\""
11279 (or org-log-note-previous-state "")
11280 (or org-log-note-state "")))
11281 ((eq org-log-note-purpose 'reschedule)
11283 ((eq org-log-note-purpose 'delschedule)
11284 "no longer scheduled")
11285 ((eq org-log-note-purpose 'redeadline)
11286 "changing deadline")
11287 ((eq org-log-note-purpose 'deldeadline)
11288 "removing deadline")
11289 ((eq org-log-note-purpose 'refile)
11291 ((eq org-log-note-purpose 'note)
11293 (t (error "This should not happen")))))
11294 (if org-log-note-extra (insert org-log-note-extra))
11295 (org-set-local 'org-finish-function 'org-store-log-note)))
11297 (defvar org-note-abort nil) ; dynamically scoped
11298 (defun org-store-log-note ()
11299 "Finish taking a log note, and insert it to where it belongs."
11300 (let ((txt (buffer-string))
11301 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11303 (kill-buffer (current-buffer))
11304 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11305 (setq txt (replace-match "" t t txt)))
11306 (if (string-match "\\s-+\\'" txt)
11307 (setq txt (replace-match "" t t txt)))
11308 (setq lines (org-split-string txt "\n"))
11309 (when (and note (string-match "\\S-" note))
11311 (org-replace-escapes
11313 (list (cons "%u" (user-login-name))
11314 (cons "%U" user-full-name)
11315 (cons "%t" (format-time-string
11316 (org-time-stamp-format 'long 'inactive)
11318 (cons "%s" (if org-log-note-state
11319 (concat "\"" org-log-note-state "\"")
11321 (cons "%S" (if org-log-note-previous-state
11322 (concat "\"" org-log-note-previous-state "\"")
11324 (if lines (setq note (concat note " \\\\")))
11326 (when (or current-prefix-arg org-note-abort)
11327 (when org-log-into-drawer
11328 (org-remove-empty-drawer-at
11329 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11330 org-log-note-marker))
11333 (with-current-buffer (marker-buffer org-log-note-marker)
11335 (goto-char org-log-note-marker)
11336 (move-marker org-log-note-marker nil)
11338 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11339 (insert "- " (pop lines))
11340 (org-indent-line-function)
11341 (beginning-of-line 1)
11342 (looking-at "[ \t]*")
11343 (setq ind (concat (match-string 0) " "))
11345 (while lines (insert "\n" ind (pop lines)))
11346 (message "Note stored")
11347 (org-back-to-heading t)
11348 (org-cycle-hide-drawers 'children)))))
11349 (set-window-configuration org-log-note-window-configuration)
11350 (with-current-buffer (marker-buffer org-log-note-return-to)
11351 (goto-char org-log-note-return-to))
11352 (move-marker org-log-note-return-to nil)
11353 (and org-log-post-message (message "%s" org-log-post-message)))
11355 (defun org-remove-empty-drawer-at (drawer pos)
11356 "Remove an empty drawer DRAWER at position POS.
11357 POS may also be a marker."
11358 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11364 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11365 (replace-match ""))))))
11367 (defun org-sparse-tree (&optional arg)
11368 "Create a sparse tree, prompt for the details.
11369 This command can create sparse trees. You first need to select the type
11370 of match used to create the tree:
11372 t Show entries with a specific TODO keyword.
11373 m Show entries selected by a tags/property match.
11374 p Enter a property name and its value (both with completion on existing
11375 names/values) and show entries with that property.
11376 / Show entries matching a regular expression (`r' can be used as well)
11377 d Show deadlines due within `org-deadline-warning-days'.
11378 b Show deadlines and scheduled items before a date.
11379 a Show deadlines and scheduled items after a date."
11381 (let (ans kwd value)
11382 (message "Sparse tree: [/]regexp [t]odo-kwd [m]atch [p]roperty [d]eadlines [b]efore-date [a]fter-date")
11383 (setq ans (read-char-exclusive))
11386 (call-interactively 'org-check-deadlines))
11388 (call-interactively 'org-check-before-date))
11390 (call-interactively 'org-check-after-date))
11392 (org-show-todo-tree '(4)))
11393 ((member ans '(?T ?m))
11394 (call-interactively 'org-match-sparse-tree))
11395 ((member ans '(?p ?P))
11396 (setq kwd (org-icompleting-read "Property: "
11397 (mapcar 'list (org-buffer-property-keys))))
11398 (setq value (org-icompleting-read "Value: "
11399 (mapcar 'list (org-property-values kwd))))
11400 (unless (string-match "\\`{.*}\\'" value)
11401 (setq value (concat "\"" value "\"")))
11402 (org-match-sparse-tree arg (concat kwd "=" value)))
11403 ((member ans '(?r ?R ?/))
11404 (call-interactively 'org-occur))
11405 (t (error "No such sparse tree command \"%c\"" ans)))))
11407 (defvar org-occur-highlights nil
11408 "List of overlays used for occur matches.")
11409 (make-variable-buffer-local 'org-occur-highlights)
11410 (defvar org-occur-parameters nil
11411 "Parameters of the active org-occur calls.
11412 This is a list, each call to org-occur pushes as cons cell,
11413 containing the regular expression and the callback, onto the list.
11414 The list can contain several entries if `org-occur' has been called
11415 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11416 will only contain one set of parameters. When the highlights are
11417 removed (for example with `C-c C-c', or with the next edit (depending
11418 on `org-remove-highlights-with-change'), this variable is emptied
11420 (make-variable-buffer-local 'org-occur-parameters)
11422 (defun org-occur (regexp &optional keep-previous callback)
11423 "Make a compact tree which shows all matches of REGEXP.
11424 The tree will show the lines where the regexp matches, and all higher
11425 headlines above the match. It will also show the heading after the match,
11426 to make sure editing the matching entry is easy.
11427 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11428 call to `org-occur' will be kept, to allow stacking of calls to this
11430 If CALLBACK is non-nil, it is a function which is called to confirm
11431 that the match should indeed be shown."
11432 (interactive "sRegexp: \nP")
11433 (when (equal regexp "")
11434 (error "Regexp cannot be empty"))
11435 (unless keep-previous
11436 (org-remove-occur-highlights nil nil t))
11437 (push (cons regexp callback) org-occur-parameters)
11440 (goto-char (point-min))
11441 (if (or (not keep-previous) ; do not want to keep
11442 (not org-occur-highlights)) ; no previous matches
11445 (while (re-search-forward regexp nil t)
11446 (when (or (not callback)
11447 (save-match-data (funcall callback)))
11448 (setq cnt (1+ cnt))
11449 (when org-highlight-sparse-tree-matches
11450 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11451 (org-show-context 'occur-tree))))
11452 (when org-remove-highlights-with-change
11453 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11455 (unless org-sparse-tree-open-archived-trees
11456 (org-hide-archived-subtrees (point-min) (point-max)))
11457 (run-hooks 'org-occur-hook)
11458 (if (interactive-p)
11459 (message "%d match(es) for regexp %s" cnt regexp))
11462 (defun org-show-context (&optional key)
11463 "Make sure point and context and visible.
11464 How much context is shown depends upon the variables
11465 `org-show-hierarchy-above', `org-show-following-heading'. and
11466 `org-show-siblings'."
11467 (let ((heading-p (org-on-heading-p t))
11468 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11469 (following-p (org-get-alist-option org-show-following-heading key))
11470 (entry-p (org-get-alist-option org-show-entry-below key))
11471 (siblings-p (org-get-alist-option org-show-siblings key)))
11473 ;; Show heading or entry text
11474 (if (and heading-p (not entry-p))
11475 (org-flag-heading nil) ; only show the heading
11476 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11477 (org-show-hidden-entry))) ; show entire entry
11479 ;; Show next sibling, or heading below text
11481 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11482 (org-flag-heading nil))))
11483 (when siblings-p (org-show-siblings))
11485 ;; show all higher headings, possibly with siblings
11487 (while (and (condition-case nil
11488 (progn (org-up-heading-all 1) t)
11491 (org-flag-heading nil)
11492 (when siblings-p (org-show-siblings))))))))
11494 (defvar org-reveal-start-hook nil
11495 "Hook run before revealing a location.")
11497 (defun org-reveal (&optional siblings)
11498 "Show current entry, hierarchy above it, and the following headline.
11499 This can be used to show a consistent set of context around locations
11500 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11501 not t for the search context.
11503 With optional argument SIBLINGS, on each level of the hierarchy all
11504 siblings are shown. This repairs the tree structure to what it would
11505 look like when opened with hierarchical calls to `org-cycle'.
11506 With double optional argument `C-u C-u', go to the parent and show the
11509 (run-hooks 'org-reveal-start-hook)
11510 (let ((org-show-hierarchy-above t)
11511 (org-show-following-heading t)
11512 (org-show-siblings (if siblings t org-show-siblings)))
11513 (org-show-context nil))
11514 (when (equal siblings '(16))
11516 (when (org-up-heading-safe)
11518 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11520 (defun org-highlight-new-match (beg end)
11521 "Highlight from BEG to END and mark the highlight is an occur headline."
11522 (let ((ov (make-overlay beg end)))
11523 (overlay-put ov 'face 'secondary-selection)
11524 (push ov org-occur-highlights)))
11526 (defun org-remove-occur-highlights (&optional beg end noremove)
11527 "Remove the occur highlights from the buffer.
11528 BEG and END are ignored. If NOREMOVE is nil, remove this function
11529 from the `before-change-functions' in the current buffer."
11531 (unless org-inhibit-highlight-removal
11532 (mapc 'delete-overlay org-occur-highlights)
11533 (setq org-occur-highlights nil)
11534 (setq org-occur-parameters nil)
11536 (remove-hook 'before-change-functions
11537 'org-remove-occur-highlights 'local))))
11541 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11542 "Regular expression matching the priority indicator.")
11544 (defvar org-remove-priority-next-time nil)
11546 (defun org-priority-up ()
11547 "Increase the priority of the current item."
11549 (org-priority 'up))
11551 (defun org-priority-down ()
11552 "Decrease the priority of the current item."
11554 (org-priority 'down))
11556 (defun org-priority (&optional action)
11557 "Change the priority of an item by ARG.
11558 ACTION can be `set', `up', `down', or a character."
11560 (unless org-enable-priority-commands
11561 (error "Priority commands are disabled"))
11562 (setq action (or action 'set))
11563 (let (current new news have remove)
11565 (org-back-to-heading t)
11566 (if (looking-at org-priority-regexp)
11567 (setq current (string-to-char (match-string 2))
11569 (setq current org-default-priority))
11571 ((eq action 'remove)
11572 (setq remove t new ?\ ))
11573 ((or (eq action 'set)
11574 (if (featurep 'xemacs) (characterp action) (integerp action)))
11575 (if (not (eq action 'set))
11577 (message "Priority %c-%c, SPC to remove: "
11578 org-highest-priority org-lowest-priority)
11579 (setq new (read-char-exclusive)))
11580 (if (and (= (upcase org-highest-priority) org-highest-priority)
11581 (= (upcase org-lowest-priority) org-lowest-priority))
11582 (setq new (upcase new)))
11583 (cond ((equal new ?\ ) (setq remove t))
11584 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
11585 (error "Priority must be between `%c' and `%c'"
11586 org-highest-priority org-lowest-priority))))
11588 (if (and (not have) (eq last-command this-command))
11589 (setq new org-lowest-priority)
11590 (setq new (if (and org-priority-start-cycle-with-default (not have))
11591 org-default-priority (1- current)))))
11593 (if (and (not have) (eq last-command this-command))
11594 (setq new org-highest-priority)
11595 (setq new (if (and org-priority-start-cycle-with-default (not have))
11596 org-default-priority (1+ current)))))
11597 (t (error "Invalid action")))
11598 (if (or (< (upcase new) org-highest-priority)
11599 (> (upcase new) org-lowest-priority))
11601 (setq news (format "%c" new))
11604 (replace-match "" t t nil 1)
11605 (replace-match news t t nil 2))
11607 (error "No priority cookie found in line")
11608 (let ((case-fold-search nil))
11609 (looking-at org-todo-line-regexp))
11612 (goto-char (match-end 2))
11613 (insert " [#" news "]"))
11614 (goto-char (match-beginning 3))
11615 (insert "[#" news "] "))))
11616 (org-preserve-lc (org-set-tags nil 'align)))
11618 (message "Priority removed")
11619 (message "Priority of current item set to %s" news))))
11621 (defun org-get-priority (s)
11622 "Find priority cookie and return priority."
11624 (if (not (string-match org-priority-regexp s))
11625 (* 1000 (- org-lowest-priority org-default-priority))
11626 (* 1000 (- org-lowest-priority
11627 (string-to-char (match-string 2 s)))))))
11631 (defvar org-agenda-archives-mode)
11632 (defvar org-map-continue-from nil
11633 "Position from where mapping should continue.
11634 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
11636 (defvar org-scanner-tags nil
11637 "The current tag list while the tags scanner is running.")
11638 (defvar org-trust-scanner-tags nil
11639 "Should `org-get-tags-at' use the tags fro the scanner.
11640 This is for internal dynamical scoping only.
11641 When this is non-nil, the function `org-get-tags-at' will return the value
11642 of `org-scanner-tags' instead of building the list by itself. This
11643 can lead to large speed-ups when the tags scanner is used in a file with
11644 many entries, and when the list of tags is retrieved, for example to
11645 obtain a list of properties. Building the tags list for each entry in such
11646 a file becomes an N^2 operation - but with this variable set, it scales
11649 (defun org-scan-tags (action matcher &optional todo-only)
11650 "Scan headline tags with inheritance and produce output ACTION.
11652 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
11653 or `agenda' to produce an entry list for an agenda view. It can also be
11654 a Lisp form or a function that should be called at each matched headline, in
11655 this case the return value is a list of all return values from these calls.
11657 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
11658 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
11659 only lines with a TODO keyword are included in the output."
11660 (require 'org-agenda)
11661 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
11662 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
11664 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
11665 (props (list 'face 'default
11666 'done-face 'org-agenda-done
11667 'undone-face 'default
11668 'mouse-face 'highlight
11669 'org-not-done-regexp org-not-done-regexp
11670 'org-todo-regexp org-todo-regexp
11672 (format "mouse-2 or RET jump to org file %s"
11673 (abbreviate-file-name
11674 (or (buffer-file-name (buffer-base-buffer))
11675 (buffer-name (buffer-base-buffer)))))))
11676 (case-fold-search nil)
11677 (org-map-continue-from nil)
11678 lspos tags tags-list
11679 (tags-alist (list (cons 0 org-file-tags)))
11680 (llast 0) rtn rtn1 level category i txt
11681 todo marker entry priority)
11682 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
11683 (setq action (list 'lambda nil action)))
11685 (goto-char (point-min))
11686 (when (eq action 'sparse-tree)
11688 (org-remove-occur-highlights))
11689 (while (re-search-forward re nil t)
11691 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
11692 tags (if (match-end 4) (org-match-string-no-properties 4)))
11693 (goto-char (setq lspos (match-beginning 0)))
11694 (setq level (org-reduced-level (funcall outline-level))
11695 category (org-get-category))
11696 (setq i llast llast level)
11697 ;; remove tag lists from same and sublevels
11698 (while (>= i level)
11699 (when (setq entry (assoc i tags-alist))
11700 (setq tags-alist (delete entry tags-alist)))
11702 ;; add the next tags
11704 (setq tags (org-split-string tags ":")
11706 (cons (cons level tags) tags-alist)))
11707 ;; compile tags for current headline
11709 (if org-use-tag-inheritance
11710 (apply 'append (mapcar 'cdr (reverse tags-alist)))
11712 org-scanner-tags tags-list)
11713 (when org-use-tag-inheritance
11714 (setcdr (car tags-alist)
11715 (mapcar (lambda (x)
11716 (setq x (copy-sequence x))
11717 (org-add-prop-inherited x))
11718 (cdar tags-alist))))
11719 (when (and tags org-use-tag-inheritance
11720 (or (not (eq t org-use-tag-inheritance))
11721 org-tags-exclude-from-inheritance))
11722 ;; selective inheritance, remove uninherited ones
11723 (setcdr (car tags-alist)
11724 (org-remove-uniherited-tags (cdar tags-alist))))
11725 (when (and (or (not todo-only)
11726 (and (member todo org-not-done-keywords)
11727 (or (not org-agenda-tags-todo-honor-ignore-options)
11728 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
11729 (let ((case-fold-search t)) (eval matcher))
11731 (not (member org-archive-tag tags-list))
11732 ;; we have an archive tag, should we use this anyway?
11733 (or (not org-agenda-skip-archived-trees)
11734 (and (eq action 'agenda) org-agenda-archives-mode))))
11735 (unless (eq action 'sparse-tree) (org-agenda-skip))
11737 ;; select this headline
11740 ((eq action 'sparse-tree)
11741 (and org-highlight-sparse-tree-matches
11742 (org-get-heading) (match-end 0)
11743 (org-highlight-new-match
11744 (match-beginning 0) (match-beginning 1)))
11745 (org-show-context 'tags-tree))
11746 ((eq action 'agenda)
11747 (setq txt (org-format-agenda-item
11750 (if (eq org-tags-match-list-sublevels 'indented)
11751 (make-string (1- level) ?.) "")
11756 priority (org-get-priority txt))
11758 (setq marker (org-agenda-new-marker))
11759 (org-add-props txt props
11760 'org-marker marker 'org-hd-marker marker 'org-category category
11762 'priority priority 'type "tagsmatch")
11764 ((functionp action)
11765 (setq org-map-continue-from nil)
11767 (setq rtn1 (funcall action))
11769 (t (error "Invalid action")))
11771 ;; if we are to skip sublevels, jump to end of subtree
11772 (unless org-tags-match-list-sublevels
11773 (org-end-of-subtree t)
11774 (backward-char 1))))
11775 ;; Get the correct position from where to continue
11776 (if org-map-continue-from
11777 (goto-char org-map-continue-from)
11778 (and (= (point) lspos) (end-of-line 1)))))
11779 (when (and (eq action 'sparse-tree)
11780 (not org-sparse-tree-open-archived-trees))
11781 (org-hide-archived-subtrees (point-min) (point-max)))
11784 (defun org-remove-uniherited-tags (tags)
11785 "Remove all tags that are not inherited from the list TAGS."
11787 ((eq org-use-tag-inheritance t)
11788 (if org-tags-exclude-from-inheritance
11789 (org-delete-all org-tags-exclude-from-inheritance tags)
11791 ((not org-use-tag-inheritance) nil)
11792 ((stringp org-use-tag-inheritance)
11795 (if (and (string-match org-use-tag-inheritance x)
11796 (not (member x org-tags-exclude-from-inheritance)))
11799 ((listp org-use-tag-inheritance)
11802 (if (member x org-use-tag-inheritance) x nil))
11805 (defvar todo-only) ;; dynamically scoped
11807 (defun org-match-sparse-tree (&optional todo-only match)
11808 "Create a sparse tree according to tags string MATCH.
11809 MATCH can contain positive and negative selection of tags, like
11810 \"+WORK+URGENT-WITHBOSS\".
11811 If optional argument TODO-ONLY is non-nil, only select lines that are
11814 (org-prepare-agenda-buffers (list (current-buffer)))
11815 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
11817 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
11819 (defvar org-cached-props nil)
11820 (defun org-cached-entry-get (pom property)
11821 (if (or (eq t org-use-property-inheritance)
11822 (and (stringp org-use-property-inheritance)
11823 (string-match org-use-property-inheritance property))
11824 (and (listp org-use-property-inheritance)
11825 (member property org-use-property-inheritance)))
11826 ;; Caching is not possible, check it directly
11827 (org-entry-get pom property 'inherit)
11828 ;; Get all properties, so that we can do complicated checks easily
11829 (cdr (assoc property (or org-cached-props
11830 (setq org-cached-props
11831 (org-entry-properties pom)))))))
11833 (defun org-global-tags-completion-table (&optional files)
11834 "Return the list of all tags in all agenda buffer/files."
11841 (set-buffer (find-file-noselect file))
11842 (append (org-get-buffer-tags)
11843 (mapcar (lambda (x) (if (stringp (car-safe x))
11844 (list (car-safe x)) nil))
11846 (if (and files (car files))
11848 (org-agenda-files))))))))
11850 (defun org-make-tags-matcher (match)
11851 "Create the TAGS//TODO matcher form for the selection string MATCH."
11852 ;; todo-only is scoped dynamically into this function, and the function
11853 ;; may change it if the matcher asks for it.
11855 ;; Get a new match request, with completion
11856 (let ((org-last-tags-completion-table
11857 (org-global-tags-completion-table)))
11858 (setq match (org-completing-read-no-i
11859 "Match: " 'org-tags-completion-function nil nil nil
11860 'org-tags-history))))
11862 ;; Parse the string and create a lisp form
11863 (let ((match0 match)
11864 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
11866 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
11867 orterms term orlist re-p str-p level-p level-op time-p
11868 prop-p pn pv po cat-p gv rest)
11869 (if (string-match "/+" match)
11870 ;; match contains also a todo-matching request
11872 (setq tagsmatch (substring match 0 (match-beginning 0))
11873 todomatch (substring match (match-end 0)))
11874 (if (string-match "^!" todomatch)
11875 (setq todo-only t todomatch (substring todomatch 1)))
11876 (if (string-match "^\\s-*$" todomatch)
11877 (setq todomatch nil)))
11878 ;; only matching tags
11879 (setq tagsmatch match todomatch nil))
11881 ;; Make the tags matcher
11882 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
11883 (setq tagsmatcher t)
11884 (setq orterms (org-split-string tagsmatch "|") orlist nil)
11885 (while (setq term (pop orterms))
11886 (while (and (equal (substring term -1) "\\") orterms)
11887 (setq term (concat term "|" (pop orterms)))) ; repair bad split
11888 (while (string-match re term)
11889 (setq rest (substring term (match-end 0))
11890 minus (and (match-end 1)
11891 (equal (match-string 1 term) "-"))
11892 tag (match-string 2 term)
11893 re-p (equal (string-to-char tag) ?{)
11894 level-p (match-end 4)
11895 prop-p (match-end 5)
11897 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
11899 (setq level-op (org-op-to-function (match-string 3 term)))
11900 `(,level-op level ,(string-to-number
11901 (match-string 4 term))))
11903 (setq pn (match-string 5 term)
11904 po (match-string 6 term)
11905 pv (match-string 7 term)
11906 cat-p (equal pn "CATEGORY")
11907 re-p (equal (string-to-char pv) ?{)
11908 str-p (equal (string-to-char pv) ?\")
11909 time-p (save-match-data
11910 (string-match "^\"[[<].*[]>]\"$" pv))
11911 pv (if (or re-p str-p) (substring pv 1 -1) pv))
11912 (if time-p (setq pv (org-matcher-time pv)))
11913 (setq po (org-op-to-function po (if time-p 'time str-p)))
11915 ((equal pn "CATEGORY")
11916 (setq gv '(get-text-property (point) 'org-category)))
11920 (setq gv `(org-cached-entry-get nil ,pn))))
11923 `(not (string-match ,pv (or ,gv "")))
11924 `(string-match ,pv (or ,gv "")))
11926 `(,po (or ,gv "") ,pv)
11927 `(,po (string-to-number (or ,gv ""))
11928 ,(string-to-number pv) ))))
11929 (t `(member ,tag tags-list)))
11930 mm (if minus (list 'not mm) mm)
11932 (push mm tagsmatcher))
11933 (push (if (> (length tagsmatcher) 1)
11934 (cons 'and tagsmatcher)
11937 (setq tagsmatcher nil))
11938 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
11940 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
11941 ;; Make the todo matcher
11942 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
11943 (setq todomatcher t)
11944 (setq orterms (org-split-string todomatch "|") orlist nil)
11945 (while (setq term (pop orterms))
11946 (while (string-match re term)
11947 (setq minus (and (match-end 1)
11948 (equal (match-string 1 term) "-"))
11949 kwd (match-string 2 term)
11950 re-p (equal (string-to-char kwd) ?{)
11951 term (substring term (match-end 0))
11953 `(string-match ,(substring kwd 1 -1) todo)
11954 (list 'equal 'todo kwd))
11955 mm (if minus (list 'not mm) mm))
11956 (push mm todomatcher))
11957 (push (if (> (length todomatcher) 1)
11958 (cons 'and todomatcher)
11961 (setq todomatcher nil))
11962 (setq todomatcher (if (> (length orlist) 1)
11963 (cons 'or orlist) (car orlist))))
11965 ;; Return the string and lisp forms of the matcher
11966 (setq matcher (if todomatcher
11967 (list 'and tagsmatcher todomatcher)
11969 (cons match0 matcher)))
11971 (defun org-op-to-function (op &optional stringp)
11972 "Turn an operator into the appropriate function."
11975 ((equal op "<" ) '(< string< org-time<))
11976 ((equal op ">" ) '(> org-string> org-time>))
11977 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
11978 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
11979 ((member op '("=" "==")) '(= string= org-time=))
11980 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
11981 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
11983 (defun org<> (a b) (not (= a b)))
11984 (defun org-string<= (a b) (or (string= a b) (string< a b)))
11985 (defun org-string>= (a b) (not (string< a b)))
11986 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
11987 (defun org-string<> (a b) (not (string= a b)))
11988 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
11989 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
11990 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
11991 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
11992 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
11993 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
11995 "Convert S to a floating point time.
11996 If S is already a number, just return it. If it is a string, parse
11997 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12001 (condition-case nil
12002 (float-time (apply 'encode-time (org-parse-time-string s)))
12006 (defun org-time-today ()
12007 "Time in seconds today at 0:00.
12008 Returns the float number of seconds since the beginning of the
12009 epoch to the beginning of today (00:00)."
12010 (float-time (apply 'encode-time
12011 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12013 (defun org-matcher-time (s)
12014 "Interpret a time comparison value."
12017 ((string= s "<now>") (float-time))
12018 ((string= s "<today>") (org-time-today))
12019 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12020 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12021 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12022 (+ (org-time-today)
12023 (* (string-to-number (match-string 1 s))
12024 (cdr (assoc (match-string 2 s)
12025 '(("d" . 86400.0) ("w" . 604800.0)
12026 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12029 (defun org-match-any-p (re list)
12030 "Does re match any element of list?"
12031 (setq list (mapcar (lambda (x) (string-match re x)) list))
12034 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12035 (defvar org-tags-overlay (make-overlay 1 1))
12036 (org-detach-overlay org-tags-overlay)
12038 (defun org-get-local-tags-at (&optional pos)
12039 "Get a list of tags defined in the current headline."
12040 (org-get-tags-at pos 'local))
12042 (defun org-get-local-tags ()
12043 "Get a list of tags defined in the current headline."
12044 (org-get-tags-at nil 'local))
12046 (defun org-get-tags-at (&optional pos local)
12047 "Get a list of all headline tags applicable at POS.
12048 POS defaults to point. If tags are inherited, the list contains
12049 the targets in the same sequence as the headlines appear, i.e.
12050 the tags of the current headline come last.
12051 When LOCAL is non-nil, only return tags from the current headline,
12052 ignore inherited ones."
12054 (if (and org-trust-scanner-tags
12055 (or (not pos) (equal pos (point)))
12058 (let (tags ltags lastpos parent)
12062 (goto-char (or pos (point)))
12065 (condition-case nil
12067 (org-back-to-heading t)
12068 (while (not (equal lastpos (point)))
12069 (setq lastpos (point))
12071 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12072 (setq ltags (org-split-string
12073 (org-match-string-no-properties 1) ":"))
12075 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12078 (org-remove-uniherited-tags ltags)
12081 (or org-use-tag-inheritance (throw 'done t))
12082 (if local (throw 'done t))
12083 (or (org-up-heading-safe) (error nil))
12086 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12088 (defun org-add-prop-inherited (s)
12089 (add-text-properties 0 (length s) '(inherited t) s)
12092 (defun org-toggle-tag (tag &optional onoff)
12093 "Toggle the tag TAG for the current line.
12094 If ONOFF is `on' or `off', don't toggle but set to this state."
12097 (org-back-to-heading t)
12098 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12101 (setq current (match-string 1))
12102 (replace-match ""))
12104 (setq current (nreverse (org-split-string current ":")))
12108 (or (member tag current) (push tag current)))
12110 (or (not (member tag current)) (setq current (delete tag current))))
12111 (t (if (member tag current)
12112 (setq current (delete tag current))
12114 (push tag current))))
12118 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12119 (org-set-tags nil t))
12120 (delete-horizontal-space))
12121 (run-hooks 'org-after-tags-change-hook))
12124 (defun org-align-tags-here (to-col)
12125 ;; Assumes that this is a headline
12126 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12127 (beginning-of-line 1)
12128 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12129 (< pos (match-beginning 2)))
12131 (setq tags-l (- (match-end 2) (match-beginning 2)))
12132 (goto-char (match-beginning 1))
12134 (delete-region (point) (1+ (match-beginning 2)))
12135 (setq ncol (max (1+ (current-column))
12139 (- (abs to-col) tags-l))))
12141 (insert (make-string (- ncol (current-column)) ?\ ))
12142 (setq ncol (current-column))
12143 (when indent-tabs-mode (tabify p (point-at-eol)))
12144 (org-move-to-column (min ncol col) t))
12147 (defun org-set-tags-command (&optional arg just-align)
12148 "Call the set-tags command for the current entry."
12150 (if (org-on-heading-p)
12151 (org-set-tags arg just-align)
12153 (org-back-to-heading t)
12154 (org-set-tags arg just-align))))
12156 (defun org-set-tags-to (data)
12157 "Set the tags of the current entry to DATA, replacing the current tags.
12158 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12159 If DATA is nil or the empty string, any tags will be removed."
12160 (interactive "sTags: ")
12164 ((equal data "") "")
12166 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12169 (concat ":" (mapconcat 'identity data ":") ":"))
12173 (org-back-to-heading t)
12174 (when (looking-at org-complex-heading-regexp)
12177 (goto-char (match-beginning 5))
12179 (delete-region (point) (point-at-eol))
12180 (org-set-tags nil 'align))
12181 (goto-char (point-at-eol))
12183 (org-set-tags nil 'align)))
12184 (beginning-of-line 1)
12185 (if (looking-at ".*?\\([ \t]+\\)$")
12186 (delete-region (match-beginning 1) (match-end 1))))))
12188 (defun org-align-all-tags ()
12189 "Align the tags i all headings."
12192 (or (ignore-errors (org-back-to-heading t))
12193 (outline-next-heading))
12194 (if (org-on-heading-p)
12196 (message "No headings"))))
12198 (defun org-set-tags (&optional arg just-align)
12199 "Set the tags for the current headline.
12200 With prefix ARG, realign all tags in headings in the current buffer."
12202 (let* ((re (concat "^" outline-regexp))
12203 (current (org-get-tags-string))
12204 (col (current-column))
12205 (org-setting-tags t)
12206 table current-tags inherited-tags ; computed below when needed
12210 (goto-char (point-min))
12211 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12212 (while (re-search-forward re nil t)
12213 (org-set-tags nil t)
12215 (message "All tags realigned to column %d" org-tags-column))
12217 (setq tags current)
12218 ;; Get a new set of tags from the user
12220 (setq table (append org-tag-persistent-alist
12221 (or org-tag-alist (org-get-buffer-tags))
12222 (and org-complete-tags-always-offer-all-agenda-tags
12223 (org-global-tags-completion-table (org-agenda-files))))
12224 org-last-tags-completion-table table
12225 current-tags (org-split-string current ":")
12226 inherited-tags (nreverse
12227 (nthcdr (length current-tags)
12228 (nreverse (org-get-tags-at))))
12230 (if (or (eq t org-use-fast-tag-selection)
12231 (and org-use-fast-tag-selection
12232 (delq nil (mapcar 'cdr table))))
12233 (org-fast-tag-selection
12234 current-tags inherited-tags table
12235 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12236 (let ((org-add-colon-after-tag-completion t))
12238 (org-without-partial-completion
12239 (org-icompleting-read "Tags: " 'org-tags-completion-function
12240 nil nil current 'org-tags-history)))))))
12241 (while (string-match "[-+&]+" tags)
12242 ;; No boolean logic, just a list
12243 (setq tags (replace-match ":" t t tags))))
12245 (if org-tags-sort-function
12246 (setq tags (mapconcat 'identity
12247 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12248 org-tags-sort-function) ":")))
12250 (if (string-match "\\`[\t ]*\\'" tags)
12252 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12253 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12255 ;; Insert new tags at the correct column
12256 (beginning-of-line 1)
12258 ((and (equal current "") (equal tags "")))
12259 ((re-search-forward
12260 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12262 (if (equal tags "")
12264 (goto-char (match-beginning 0))
12265 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12266 (1+ (point)) (point))
12267 c1 (max (1+ c0) (if (> org-tags-column 0)
12269 (- (- org-tags-column) (length tags))))
12270 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12271 (replace-match rpl t t)
12272 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12274 (t (error "Tags alignment failed")))
12275 (org-move-to-column col)
12277 (run-hooks 'org-after-tags-change-hook)))))
12279 (defun org-change-tag-in-region (beg end tag off)
12280 "Add or remove TAG for each entry in the region.
12281 This works in the agenda, and also in an org-mode buffer."
12283 (list (region-beginning) (region-end)
12284 (let ((org-last-tags-completion-table
12286 (org-get-buffer-tags)
12287 (org-global-tags-completion-table))))
12288 (org-icompleting-read
12289 "Tag: " 'org-tags-completion-function nil nil nil
12290 'org-tags-history))
12292 (message "[s]et or [r]emove? ")
12293 (equal (read-char-exclusive) ?r))))
12294 (if (fboundp 'deactivate-mark) (deactivate-mark))
12295 (let ((agendap (equal major-mode 'org-agenda-mode))
12296 l1 l2 m buf pos newhead (cnt 0))
12298 (setq l2 (1- (org-current-line)))
12300 (setq l1 (org-current-line))
12301 (loop for l from l1 to l2 do
12303 (setq m (get-text-property (point) 'org-hd-marker))
12304 (when (or (and (org-mode-p) (org-on-heading-p))
12306 (setq buf (if agendap (marker-buffer m) (current-buffer))
12307 pos (if agendap m (point)))
12308 (with-current-buffer buf
12312 (setq cnt (1+ cnt))
12313 (org-toggle-tag tag (if off 'off 'on))
12314 (setq newhead (org-get-heading)))))
12315 (and agendap (org-agenda-change-all-lines newhead m))))
12316 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12318 (defun org-tags-completion-function (string predicate &optional flag)
12319 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12320 (confirm (lambda (x) (stringp (car x)))))
12321 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12322 (setq s1 (match-string 1 string)
12323 s2 (match-string 2 string))
12324 (setq s1 "" s2 string))
12328 (setq rtn (try-completion s2 ctable confirm))
12331 (concat s1 s2 (substring rtn (length s2))
12332 (if (and org-add-colon-after-tag-completion
12333 (assoc rtn ctable))
12338 (all-completions s2 ctable confirm)
12342 (assoc s2 ctable)))
12345 (defun org-fast-tag-insert (kwd tags face &optional end)
12346 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12347 (insert (format "%-12s" (concat kwd ":"))
12348 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12351 (defun org-fast-tag-show-exit (flag)
12354 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12355 (replace-match ""))
12358 (org-move-to-column (- (window-width) 19) t)
12359 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12361 (defun org-set-current-tags-overlay (current prefix)
12362 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12363 (if (featurep 'xemacs)
12364 (org-overlay-display org-tags-overlay (concat prefix s)
12365 'secondary-selection)
12366 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12367 (org-overlay-display org-tags-overlay (concat prefix s)))))
12369 (defvar org-last-tag-selection-key nil)
12370 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12371 "Fast tag selection with single keys.
12372 CURRENT is the current list of tags in the headline, INHERITED is the
12373 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12374 possibly with grouping information. TODO-TABLE is a similar table with
12375 TODO keywords, should these have keys assigned to them.
12376 If the keys are nil, a-z are automatically assigned.
12377 Returns the new tags string, or nil to not change the current settings."
12378 (let* ((fulltable (append table todo-table))
12379 (maxlen (apply 'max (mapcar
12381 (if (stringp (car x)) (string-width (car x)) 0))
12383 (buf (current-buffer))
12384 (expert (eq org-fast-tag-selection-single-key 'expert))
12386 (fwidth (+ maxlen 3 1 3))
12387 (ncol (/ (- (window-width) 4) fwidth))
12390 tg cnt e c char c1 c2 ntable tbl rtn
12391 ov-start ov-end ov-prefix
12392 (exit-after-next org-fast-tag-selection-single-key)
12393 (done-keywords org-done-keywords)
12396 (beginning-of-line 1)
12398 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12399 (setq ov-start (match-beginning 1)
12400 ov-end (match-end 1)
12402 (setq ov-start (1- (point-at-eol))
12403 ov-end (1+ ov-start))
12404 (skip-chars-forward "^\n\r")
12407 (buffer-substring (1- (point)) (point))
12408 (if (> (current-column) org-tags-column)
12410 (make-string (- org-tags-column (current-column)) ?\ ))))))
12411 (move-overlay org-tags-overlay ov-start ov-end)
12412 (save-window-excursion
12414 (set-buffer (get-buffer-create " *Org tags*"))
12415 (delete-other-windows)
12416 (split-window-vertically)
12417 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12419 (org-set-local 'org-done-keywords done-keywords)
12420 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12421 (org-fast-tag-insert "Current" current c-face "\n\n")
12422 (org-fast-tag-show-exit exit-after-next)
12423 (org-set-current-tags-overlay current ov-prefix)
12424 (setq tbl fulltable char ?a cnt 0)
12425 (while (setq e (pop tbl))
12427 ((equal (car e) :startgroup)
12428 (push '() groups) (setq ingroup t)
12429 (when (not (= cnt 0))
12432 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12433 ((equal (car e) :endgroup)
12434 (setq ingroup nil cnt 0)
12435 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12436 ((equal e '(:newline))
12437 (when (not (= cnt 0))
12441 (while (equal (car tbl) '(:newline))
12443 (setq tbl (cdr tbl)))))
12445 (setq tg (copy-sequence (car e)) c2 nil)
12448 ;; automatically assign a character.
12449 (setq c1 (string-to-char
12450 (downcase (substring
12451 tg (if (= (string-to-char tg) ?@) 1 0)))))
12452 (if (or (rassoc c1 ntable) (rassoc c1 table))
12453 (while (or (rassoc char ntable) (rassoc char table))
12454 (setq char (1+ char)))
12456 (setq c (or c2 char)))
12457 (if ingroup (push tg (car groups)))
12458 (setq tg (org-add-props tg nil 'face
12460 ((not (assoc tg table))
12461 (org-get-todo-face tg))
12462 ((member tg current) c-face)
12463 ((member tg inherited) i-face)
12465 (if (and (= cnt 0) (not ingroup)) (insert " "))
12466 (insert "[" c "] " tg (make-string
12467 (- fwidth 4 (length tg)) ?\ ))
12468 (push (cons tg c) ntable)
12469 (when (= (setq cnt (1+ cnt)) ncol)
12471 (if ingroup (insert " "))
12473 (setq ntable (nreverse ntable))
12475 (goto-char (point-min))
12476 (if (not expert) (org-fit-window-to-buffer))
12480 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12481 (if (not groups) "no " "")
12482 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12483 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12484 (setq org-last-tag-selection-key c)
12486 ((= c ?\r) (throw 'exit t))
12488 (setq groups (not groups))
12489 (goto-char (point-min))
12490 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12493 (org-fast-tag-show-exit
12494 (setq exit-after-next (not exit-after-next)))
12496 (delete-other-windows)
12497 (split-window-vertically)
12498 (org-switch-to-buffer-other-window " *Org tags*")
12499 (org-fit-window-to-buffer)))
12501 (and (= c ?q) (not (rassoc c ntable))))
12502 (org-detach-overlay org-tags-overlay)
12503 (setq quit-flag t))
12506 (if exit-after-next (setq exit-after-next 'now)))
12508 (condition-case nil
12509 (setq tg (org-icompleting-read
12512 (with-current-buffer buf
12513 (org-get-buffer-tags)))))
12514 (quit (setq tg "")))
12515 (when (string-match "\\S-" tg)
12516 (add-to-list 'buffer-tags (list tg))
12517 (if (member tg current)
12518 (setq current (delete tg current))
12519 (push tg current)))
12520 (if exit-after-next (setq exit-after-next 'now)))
12521 ((setq e (rassoc c todo-table) tg (car e))
12522 (with-current-buffer buf
12523 (save-excursion (org-todo tg)))
12524 (if exit-after-next (setq exit-after-next 'now)))
12525 ((setq e (rassoc c ntable) tg (car e))
12526 (if (member tg current)
12527 (setq current (delete tg current))
12528 (loop for g in groups do
12531 (setq current (delete x current)))
12534 (if exit-after-next (setq exit-after-next 'now))))
12536 ;; Create a sorted list
12540 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12541 (if (eq exit-after-next 'now) (throw 'exit t))
12542 (goto-char (point-min))
12543 (beginning-of-line 2)
12544 (delete-region (point) (point-at-eol))
12545 (org-fast-tag-insert "Current" current c-face)
12546 (org-set-current-tags-overlay current ov-prefix)
12547 (while (re-search-forward
12548 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12549 (setq tg (match-string 1))
12550 (add-text-properties
12551 (match-beginning 1) (match-end 1)
12554 ((member tg current) c-face)
12555 ((member tg inherited) i-face)
12556 (t (get-text-property (match-beginning 1) 'face))))))
12557 (goto-char (point-min)))))
12558 (org-detach-overlay org-tags-overlay)
12560 (mapconcat 'identity current ":")
12563 (defun org-get-tags-string ()
12564 "Get the TAGS string in the current headline."
12565 (unless (org-on-heading-p t)
12566 (error "Not on a heading"))
12568 (beginning-of-line 1)
12569 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12570 (org-match-string-no-properties 1)
12573 (defun org-get-tags ()
12574 "Get the list of tags specified in the current headline."
12575 (org-split-string (org-get-tags-string) ":"))
12577 (defun org-get-buffer-tags ()
12578 "Get a table of all tags used in the buffer, for completion."
12581 (goto-char (point-min))
12582 (while (re-search-forward
12583 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
12584 (when (equal (char-after (point-at-bol 0)) ?*)
12585 (mapc (lambda (x) (add-to-list 'tags x))
12586 (org-split-string (org-match-string-no-properties 1) ":")))))
12587 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
12588 (mapcar 'list tags)))
12590 ;;;; The mapping API
12593 (defun org-map-entries (func &optional match scope &rest skip)
12594 "Call FUNC at each headline selected by MATCH in SCOPE.
12596 FUNC is a function or a lisp form. The function will be called without
12597 arguments, with the cursor positioned at the beginning of the headline.
12598 The return values of all calls to the function will be collected and
12599 returned as a list.
12601 The call to FUNC will be wrapped into a save-excursion form, so FUNC
12602 does not need to preserve point. After evaluation, the cursor will be
12603 moved to the end of the line (presumably of the headline of the
12604 processed entry) and search continues from there. Under some
12605 circumstances, this may not produce the wanted results. For example,
12606 if you have removed (e.g. archived) the current (sub)tree it could
12607 mean that the next entry will be skipped entirely. In such cases, you
12608 can specify the position from where search should continue by making
12609 FUNC set the variable `org-map-continue-from' to the desired buffer
12612 MATCH is a tags/property/todo match as it is used in the agenda tags view.
12613 Only headlines that are matched by this query will be considered during
12614 the iteration. When MATCH is nil or t, all headlines will be
12615 visited by the iteration.
12617 SCOPE determines the scope of this command. It can be any of:
12619 nil The current buffer, respecting the restriction if any
12620 tree The subtree started with the entry at point
12621 file The current buffer, without restriction
12623 The current buffer, and any archives associated with it
12624 agenda All agenda files
12625 agenda-with-archives
12626 All agenda files with any archive files associated with them
12628 If this is a list, all files in the list will be scanned
12630 The remaining args are treated as settings for the skipping facilities of
12631 the scanner. The following items can be given here:
12633 archive skip trees with the archive tag.
12634 comment skip trees with the COMMENT keyword
12635 function or Emacs Lisp form:
12636 will be used as value for `org-agenda-skip-function', so whenever
12637 the function returns t, FUNC will not be called for that
12638 entry and search will continue from the point where the
12639 function leaves it.
12641 If your function needs to retrieve the tags including inherited tags
12642 at the *current* entry, you can use the value of the variable
12643 `org-scanner-tags' which will be much faster than getting the value
12644 with `org-get-tags-at'. If your function gets properties with
12645 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
12646 to t around the call to `org-entry-properties' to get the same speedup.
12647 Note that if your function moves around to retrieve tags and properties at
12648 a *different* entry, you cannot use these techniques."
12649 (let* ((org-agenda-archives-mode nil) ; just to make sure
12650 (org-agenda-skip-archived-trees (memq 'archive skip))
12651 (org-agenda-skip-comment-trees (memq 'comment skip))
12652 (org-agenda-skip-function
12653 (car (org-delete-all '(comment archive) skip)))
12654 (org-tags-match-list-sublevels t)
12656 org-todo-keywords-for-agenda
12657 org-done-keywords-for-agenda
12658 org-todo-keyword-alist-for-agenda
12659 org-drawers-for-agenda
12660 org-tag-alist-for-agenda)
12663 ((eq match t) (setq matcher t))
12664 ((eq match nil) (setq matcher t))
12665 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
12669 (when (eq scope 'tree)
12670 (org-back-to-heading t)
12671 (org-narrow-to-subtree)
12676 (org-prepare-agenda-buffers
12677 (list (buffer-file-name (current-buffer))))
12678 (setq res (org-scan-tags func matcher)))
12679 ;; Get the right scope
12681 ((and scope (listp scope) (symbolp (car scope)))
12682 (setq scope (eval scope)))
12683 ((eq scope 'agenda)
12684 (setq scope (org-agenda-files t)))
12685 ((eq scope 'agenda-with-archives)
12686 (setq scope (org-agenda-files t))
12687 (setq scope (org-add-archive-files scope)))
12689 (setq scope (list (buffer-file-name))))
12690 ((eq scope 'file-with-archives)
12691 (setq scope (org-add-archive-files (list (buffer-file-name))))))
12692 (org-prepare-agenda-buffers scope)
12693 (while (setq file (pop scope))
12694 (with-current-buffer (org-find-base-buffer-visiting file)
12698 (goto-char (point-min))
12699 (setq res (append res (org-scan-tags func matcher))))))))))
12704 ;;; Setting and retrieving properties
12706 (defconst org-special-properties
12707 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
12708 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
12709 "The special properties valid in Org-mode.
12711 These are properties that are not defined in the property drawer,
12712 but in some other way.")
12714 (defconst org-default-properties
12715 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
12716 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
12717 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
12718 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
12719 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
12720 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
12721 "Some properties that are used by Org-mode for various purposes.
12722 Being in this list makes sure that they are offered for completion.")
12724 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
12725 "Regular expression matching the first line of a property drawer.")
12727 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
12728 "Regular expression matching the last line of a property drawer.")
12730 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
12731 "Regular expression matching the first line of a property drawer.")
12733 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
12734 "Regular expression matching the first line of a property drawer.")
12736 (defconst org-property-drawer-re
12737 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
12738 org-property-end-re "\\)\n?")
12739 "Matches an entire property drawer.")
12741 (defconst org-clock-drawer-re
12742 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
12743 org-property-end-re "\\)\n?")
12744 "Matches an entire clock drawer.")
12746 (defun org-property-action ()
12747 "Do an action on properties."
12750 (org-at-property-p)
12751 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
12752 (setq c (read-char-exclusive))
12755 (call-interactively 'org-set-property))
12757 (call-interactively 'org-delete-property))
12759 (call-interactively 'org-delete-property-globally))
12761 (call-interactively 'org-compute-property-at-point))
12762 (t (error "No such property action %c" c)))))
12764 (defun org-set-effort (&optional value)
12765 "Set the effort property of the current entry.
12766 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
12769 (if (equal value 0) (setq value 10))
12770 (let* ((completion-ignore-case t)
12771 (prop org-effort-property)
12772 (cur (org-entry-get nil prop))
12773 (allowed (org-property-get-allowed-values nil prop 'table))
12774 (existing (mapcar 'list (org-property-values prop)))
12777 ((stringp value) value)
12778 ((and allowed (integerp value))
12779 (or (car (nth (1- value) allowed))
12780 (car (org-last allowed))))
12782 (message "Select 1-9,0, [RET%s]: %s"
12783 (if cur (concat "=" cur) "")
12784 (mapconcat 'car allowed " "))
12785 (setq rpl (read-char-exclusive))
12786 (if (equal rpl ?\r)
12788 (setq rpl (- rpl ?0))
12789 (if (equal rpl 0) (setq rpl 10))
12790 (if (and (> rpl 0) (<= rpl (length allowed)))
12791 (car (nth (1- rpl) allowed))
12792 (org-completing-read "Effort: " allowed nil))))
12794 (let (org-completion-use-ido org-completion-use-iswitchb)
12795 (org-completing-read
12796 (concat "Effort " (if (and cur (string-match "\\S-" cur))
12797 (concat "[" cur "]") "")
12799 existing nil nil "" nil cur))))))
12800 (unless (equal (org-entry-get nil prop) val)
12801 (org-entry-put nil prop val))
12802 (message "%s is now %s" prop val)))
12804 (defun org-at-property-p ()
12805 "Is cursor inside a property drawer?"
12807 (beginning-of-line 1)
12808 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
12809 (let ((match (match-data)) ;; Keep match-data for use by calling
12810 (p (point)) ;; procedures.
12811 (range (unless (org-before-first-heading-p)
12812 (org-get-property-block))))
12813 (prog1 (and range (<= (car range) p) (< p (cdr range)))
12814 (set-match-data match))))))
12816 (defun org-get-property-block (&optional beg end force)
12817 "Return the (beg . end) range of the body of the property drawer.
12818 BEG and END can be beginning and end of subtree, if not given
12819 they will be found.
12820 If the drawer does not exist and FORCE is non-nil, create the drawer."
12823 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
12824 (end (or end (progn (outline-next-heading) (point)))))
12826 (if (re-search-forward org-property-start-re end t)
12827 (setq beg (1+ (match-end 0)))
12830 (org-insert-property-drawer)
12831 (setq end (progn (outline-next-heading) (point))))
12834 (if (re-search-forward org-property-start-re end t)
12835 (setq beg (1+ (match-end 0)))))
12836 (if (re-search-forward org-property-end-re end t)
12837 (setq end (match-beginning 0))
12838 (or force (throw 'exit nil))
12841 (org-indent-line-function)
12842 (insert ":END:\n"))
12845 (defun org-entry-properties (&optional pom which specific)
12846 "Get all properties of the entry at point-or-marker POM.
12847 This includes the TODO keyword, the tags, time strings for deadline,
12848 scheduled, and clocking, and any additional properties defined in the
12849 entry. The return value is an alist, keys may occur multiple times
12850 if the property key was used several times.
12851 POM may also be nil, in which case the current entry is used.
12852 If WHICH is nil or `all', get all properties. If WHICH is
12853 `special' or `standard', only get that subclass. If WHICH
12854 is a string only get exactly this property. Specific can be a string, the
12855 specific property we are interested in. Specifying it can speed
12856 things up because then unnecessary parsing is avoided."
12857 (setq which (or which 'all))
12858 (org-with-point-at pom
12859 (let ((clockstr (substring org-clock-string 0 -1))
12860 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
12861 (case-fold-search nil)
12862 beg end range props sum-props key value string clocksum)
12864 (when (condition-case nil
12865 (and (org-mode-p) (org-back-to-heading t))
12868 (setq sum-props (get-text-property (point) 'org-summaries))
12869 (setq clocksum (get-text-property (point) :org-clock-minutes))
12870 (outline-next-heading)
12872 (when (memq which '(all special))
12873 ;; Get the special properties, like TODO and tags
12875 (when (and (or (not specific) (string= specific "TODO"))
12876 (looking-at org-todo-line-regexp) (match-end 2))
12877 (push (cons "TODO" (org-match-string-no-properties 2)) props))
12878 (when (and (or (not specific) (string= specific "PRIORITY"))
12879 (looking-at org-priority-regexp))
12880 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
12881 (when (and (or (not specific) (string= specific "TAGS"))
12882 (setq value (org-get-tags-string))
12883 (string-match "\\S-" value))
12884 (push (cons "TAGS" value) props))
12885 (when (and (or (not specific) (string= specific "ALLTAGS"))
12886 (setq value (org-get-tags-at)))
12887 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
12890 (when (or (not specific) (string= specific "BLOCKED"))
12891 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
12892 (when (or (not specific)
12893 (member specific org-all-time-keywords)
12894 (member specific '("TIMESTAMP" "TIMESTAMP_IA")))
12895 (while (re-search-forward org-maybe-keyword-time-regexp end t)
12896 (setq key (if (match-end 1) (substring (org-match-string-no-properties 1) 0 -1))
12897 string (if (equal key clockstr)
12901 (match-beginning 3) (goto-char (point-at-eol)))))
12902 (substring (org-match-string-no-properties 3) 1 -1)))
12904 (if (= (char-after (match-beginning 3)) ?\[)
12905 (setq key "TIMESTAMP_IA")
12906 (setq key "TIMESTAMP")))
12907 (when (or (equal key clockstr) (not (assoc key props)))
12908 (push (cons key string) props))))
12912 (when (memq which '(all standard))
12913 ;; Get the standard properties, like :PROP: ...
12914 (setq range (org-get-property-block beg end))
12916 (goto-char (car range))
12917 (while (re-search-forward
12918 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
12920 (setq key (org-match-string-no-properties 1)
12921 value (org-trim (or (org-match-string-no-properties 2) "")))
12922 (unless (member key excluded)
12923 (push (cons key (or value "")) props)))))
12925 (push (cons "CLOCKSUM"
12926 (org-columns-number-to-string (/ (float clocksum) 60.)
12929 (unless (assoc "CATEGORY" props)
12930 (setq value (or (org-get-category)
12931 (progn (org-refresh-category-properties)
12932 (org-get-category))))
12933 (push (cons "CATEGORY" value) props))
12934 (append sum-props (nreverse props)))))))
12936 (defun org-entry-get (pom property &optional inherit)
12937 "Get value of PROPERTY for entry at point-or-marker POM.
12938 If INHERIT is non-nil and the entry does not have the property,
12939 then also check higher levels of the hierarchy.
12940 If INHERIT is the symbol `selective', use inheritance only if the setting
12941 in `org-use-property-inheritance' selects PROPERTY for inheritance.
12942 If the property is present but empty, the return value is the empty string.
12943 If the property is not present at all, nil is returned."
12944 (org-with-point-at pom
12945 (if (and inherit (if (eq inherit 'selective)
12946 (org-property-inherit-p property)
12948 (org-entry-get-with-inheritance property)
12949 (if (member property org-special-properties)
12950 ;; We need a special property. Use `org-entry-properties' to
12951 ;; retrieve it, but specify the wanted property
12952 (cdr (assoc property (org-entry-properties nil 'special property)))
12953 (let ((range (org-get-property-block)))
12955 (goto-char (car range))
12957 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
12959 ;; Found the property, return it.
12961 (org-match-string-no-properties 1)
12964 (defun org-property-or-variable-value (var &optional inherit)
12965 "Check if there is a property fixing the value of VAR.
12966 If yes, return this value. If not, return the current value of the variable."
12967 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
12968 (if (and prop (stringp prop) (string-match "\\S-" prop))
12970 (symbol-value var))))
12972 (defun org-entry-delete (pom property)
12973 "Delete the property PROPERTY from entry at point-or-marker POM."
12974 (org-with-point-at pom
12975 (if (member property org-special-properties)
12976 nil ; cannot delete these properties.
12977 (let ((range (org-get-property-block)))
12979 (goto-char (car range))
12981 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
12984 (delete-region (match-beginning 0) (1+ (point-at-eol)))
12988 ;; Multi-values properties are properties that contain multiple values
12989 ;; These values are assumed to be single words, separated by whitespace.
12990 (defun org-entry-add-to-multivalued-property (pom property value)
12991 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
12992 (let* ((old (org-entry-get pom property))
12993 (values (and old (org-split-string old "[ \t]"))))
12994 (setq value (org-entry-protect-space value))
12995 (unless (member value values)
12996 (setq values (cons value values))
12997 (org-entry-put pom property
12998 (mapconcat 'identity values " ")))))
13000 (defun org-entry-remove-from-multivalued-property (pom property value)
13001 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
13002 (let* ((old (org-entry-get pom property))
13003 (values (and old (org-split-string old "[ \t]"))))
13004 (setq value (org-entry-protect-space value))
13005 (when (member value values)
13006 (setq values (delete value values))
13007 (org-entry-put pom property
13008 (mapconcat 'identity values " ")))))
13010 (defun org-entry-member-in-multivalued-property (pom property value)
13011 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
13012 (let* ((old (org-entry-get pom property))
13013 (values (and old (org-split-string old "[ \t]"))))
13014 (setq value (org-entry-protect-space value))
13015 (member value values)))
13017 (defun org-entry-get-multivalued-property (pom property)
13018 "Return a list of values in a multivalued property."
13019 (let* ((value (org-entry-get pom property))
13020 (values (and value (org-split-string value "[ \t]"))))
13021 (mapcar 'org-entry-restore-space values)))
13023 (defun org-entry-put-multivalued-property (pom property &rest values)
13024 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13025 VALUES should be a list of strings. Spaces will be protected."
13026 (org-entry-put pom property
13027 (mapconcat 'org-entry-protect-space values " "))
13028 (let* ((value (org-entry-get pom property))
13029 (values (and value (org-split-string value "[ \t]"))))
13030 (mapcar 'org-entry-restore-space values)))
13032 (defun org-entry-protect-space (s)
13033 "Protect spaces and newline in string S."
13034 (while (string-match " " s)
13035 (setq s (replace-match "%20" t t s)))
13036 (while (string-match "\n" s)
13037 (setq s (replace-match "%0A" t t s)))
13040 (defun org-entry-restore-space (s)
13041 "Restore spaces and newline in string S."
13042 (while (string-match "%20" s)
13043 (setq s (replace-match " " t t s)))
13044 (while (string-match "%0A" s)
13045 (setq s (replace-match "\n" t t s)))
13048 (defvar org-entry-property-inherited-from (make-marker)
13049 "Marker pointing to the entry from where a property was inherited.
13050 Each call to `org-entry-get-with-inheritance' will set this marker to the
13051 location of the entry where the inheritance search matched. If there was
13052 no match, the marker will point nowhere.
13053 Note that also `org-entry-get' calls this function, if the INHERIT flag
13056 (defun org-entry-get-with-inheritance (property)
13057 "Get entry property, and search higher levels if not present."
13058 (move-marker org-entry-property-inherited-from nil)
13065 (when (setq tmp (org-entry-get nil property))
13066 (org-back-to-heading t)
13067 (move-marker org-entry-property-inherited-from (point))
13069 (or (org-up-heading-safe) (throw 'ex nil)))))
13071 (cdr (assoc property org-file-properties))
13072 (cdr (assoc property org-global-properties))
13073 (cdr (assoc property org-global-properties-fixed))))))
13075 (defvar org-property-changed-functions nil
13076 "Hook called when the value of a property has changed.
13077 Each hook function should accept two arguments, the name of the property
13078 and the new value.")
13080 (defun org-entry-put (pom property value)
13081 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13082 (org-with-point-at pom
13083 (org-back-to-heading t)
13084 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13087 ((equal property "TODO")
13088 (when (and (stringp value) (string-match "\\S-" value)
13089 (not (member value org-todo-keywords-1)))
13090 (error "\"%s\" is not a valid TODO state" value))
13091 (if (or (not value)
13092 (not (string-match "\\S-" value)))
13093 (setq value 'none))
13095 (org-set-tags nil 'align))
13096 ((equal property "PRIORITY")
13097 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13098 (string-to-char value) ?\ ))
13099 (org-set-tags nil 'align))
13100 ((equal property "SCHEDULED")
13101 (if (re-search-forward org-scheduled-time-regexp end t)
13103 ((eq value 'earlier) (org-timestamp-change -1 'day))
13104 ((eq value 'later) (org-timestamp-change 1 'day))
13105 (t (call-interactively 'org-schedule)))
13106 (call-interactively 'org-schedule)))
13107 ((equal property "DEADLINE")
13108 (if (re-search-forward org-deadline-time-regexp end t)
13110 ((eq value 'earlier) (org-timestamp-change -1 'day))
13111 ((eq value 'later) (org-timestamp-change 1 'day))
13112 (t (call-interactively 'org-deadline)))
13113 (call-interactively 'org-deadline)))
13114 ((member property org-special-properties)
13115 (error "The %s property can not yet be set with `org-entry-put'"
13117 (t ; a non-special property
13118 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13119 (setq range (org-get-property-block beg end 'force))
13120 (goto-char (car range))
13121 (if (re-search-forward
13122 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13124 (delete-region (match-beginning 1) (match-end 1))
13125 (goto-char (match-beginning 1)))
13126 (goto-char (cdr range))
13129 (org-indent-line-function)
13130 (insert ":" property ":"))
13131 (and value (insert " " value))
13132 (org-indent-line-function)))))
13133 (run-hook-with-args 'org-property-changed-functions property value)))
13135 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13136 "Get all property keys in the current buffer.
13137 With INCLUDE-SPECIALS, also list the special properties that reflect things
13138 like tags and TODO state.
13139 With INCLUDE-DEFAULTS, also include properties that has special meaning
13140 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13141 With INCLUDE-COLUMNS, also include property names given in COLUMN
13142 formats in the current buffer."
13143 (let (rtn range cfmt s p)
13147 (goto-char (point-min))
13148 (while (re-search-forward org-property-start-re nil t)
13149 (setq range (org-get-property-block))
13150 (goto-char (car range))
13151 (while (re-search-forward
13152 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13154 (add-to-list 'rtn (org-match-string-no-properties 1)))
13155 (outline-next-heading))))
13157 (when include-specials
13158 (setq rtn (append org-special-properties rtn)))
13160 (when include-defaults
13161 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13162 (add-to-list 'rtn org-effort-property))
13164 (when include-columns
13168 (goto-char (point-min))
13169 (while (re-search-forward
13170 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13172 (setq cfmt (match-string 2) s 0)
13173 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13175 (setq s (match-end 0)
13176 p (match-string 1 cfmt))
13177 (unless (or (equal p "ITEM")
13178 (member p org-special-properties))
13179 (add-to-list 'rtn (match-string 1 cfmt))))))))
13181 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13183 (defun org-property-values (key)
13184 "Return a list of all values of property KEY."
13188 (goto-char (point-min))
13189 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13191 (while (re-search-forward re nil t)
13192 (add-to-list 'values (org-trim (match-string 1))))
13193 (delete "" values)))))
13195 (defun org-insert-property-drawer ()
13196 "Insert a property drawer into the current entry."
13198 (org-back-to-heading t)
13199 (looking-at outline-regexp)
13200 (let ((indent (if org-adapt-indentation
13201 (- (match-end 0)(match-beginning 0))
13204 (re (concat "^[ \t]*" org-keyword-time-regexp))
13206 (outline-next-heading)
13209 (while (re-search-forward re end t))
13210 (setq hiddenp (org-invisible-p))
13212 (and (equal (char-after) ?\n) (forward-char 1))
13213 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13214 (if (member (match-string 1) '("CLOCK:" ":END:"))
13215 ;; just skip this line
13216 (beginning-of-line 2)
13217 ;; Drawer start, find the end
13218 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13219 (beginning-of-line 1)))
13220 (org-skip-over-state-notes)
13221 (skip-chars-backward " \t\n\r")
13222 (if (eq (char-before) ?*) (forward-char 1))
13223 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13224 (beginning-of-line 0)
13225 (org-indent-to-column indent)
13226 (beginning-of-line 2)
13227 (org-indent-to-column indent)
13228 (beginning-of-line 0)
13231 (org-back-to-heading t)
13233 (org-flag-drawer t))))
13235 (defun org-set-property (property value)
13236 "In the current entry, set PROPERTY to VALUE.
13237 When called interactively, this will prompt for a property name, offering
13238 completion on existing and default properties. And then it will prompt
13239 for a value, offering completion either on allowed values (via an inherited
13240 xxx_ALL property) or on existing values in other instances of this property
13241 in the current file."
13243 (let* ((completion-ignore-case t)
13244 (keys (org-buffer-property-keys nil t t))
13245 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13246 (prop (if (member prop0 keys)
13248 (or (cdr (assoc (downcase prop0)
13249 (mapcar (lambda (x) (cons (downcase x) x))
13252 (cur (org-entry-get nil prop))
13253 (prompt (concat prop " value"
13254 (if (and cur (string-match "\\S-" cur))
13255 (concat " [" cur "]") "") ": "))
13256 (allowed (org-property-get-allowed-values nil prop 'table))
13257 (existing (mapcar 'list (org-property-values prop)))
13259 (org-completing-read prompt allowed nil
13260 (not (get-text-property 0 'org-unrestricted
13262 (let (org-completion-use-ido org-completion-use-iswitchb)
13263 (org-completing-read prompt existing nil nil "" nil cur)))))
13264 (list prop (if (equal val "") cur val))))
13265 (unless (equal (org-entry-get nil property) value)
13266 (org-entry-put nil property value)))
13268 (defun org-delete-property (property)
13269 "In the current entry, delete PROPERTY."
13271 (let* ((completion-ignore-case t)
13272 (prop (org-icompleting-read "Property: " (org-entry-properties nil 'standard))))
13274 (message "Property %s %s" property
13275 (if (org-entry-delete nil property)
13277 "was not present in the entry")))
13279 (defun org-delete-property-globally (property)
13280 "Remove PROPERTY globally, from all entries."
13282 (let* ((completion-ignore-case t)
13283 (prop (org-icompleting-read
13284 "Globally remove property: "
13285 (mapcar 'list (org-buffer-property-keys)))))
13290 (goto-char (point-min))
13292 (while (re-search-forward
13293 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13295 (setq cnt (1+ cnt))
13296 (replace-match ""))
13297 (message "Property \"%s\" removed from %d entries" property cnt)))))
13299 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13301 (defun org-compute-property-at-point ()
13302 "Compute the property at point.
13303 This looks for an enclosing column format, extracts the operator and
13304 then applies it to the property in the column format's scope."
13306 (unless (org-at-property-p)
13307 (error "Not at a property"))
13308 (let ((prop (org-match-string-no-properties 2)))
13309 (org-columns-get-format-and-top-level)
13310 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13311 (error "No operator defined for property %s" prop))
13312 (org-columns-compute prop)))
13314 (defvar org-property-allowed-value-functions nil
13315 "Hook for functions supplying allowed values for a specific property.
13316 The functions must take a single argument, the name of the property, and
13317 return a flat list of allowed values. If \":ETC\" is one of
13318 the values, this means that these values are intended as defaults for
13319 completion, but that other values should be allowed too.
13320 The functions must return nil if they are not responsible for this
13323 (defun org-property-get-allowed-values (pom property &optional table)
13324 "Get allowed values for the property PROPERTY.
13325 When TABLE is non-nil, return an alist that can directly be used for
13329 ((equal property "TODO")
13330 (setq vals (org-with-point-at pom
13331 (append org-todo-keywords-1 '("")))))
13332 ((equal property "PRIORITY")
13333 (let ((n org-lowest-priority))
13334 (while (>= n org-highest-priority)
13335 (push (char-to-string n) vals)
13337 ((member property org-special-properties))
13338 ((setq vals (run-hook-with-args-until-success
13339 'org-property-allowed-value-functions property)))
13341 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13342 (when (and vals (string-match "\\S-" vals))
13343 (setq vals (car (read-from-string (concat "(" vals ")"))))
13344 (setq vals (mapcar (lambda (x)
13345 (cond ((stringp x) x)
13346 ((numberp x) (number-to-string x))
13347 ((symbolp x) (symbol-name x))
13350 (when (member ":ETC" vals)
13351 (setq vals (remove ":ETC" vals))
13352 (org-add-props (car vals) '(org-unrestricted t)))
13353 (if table (mapcar 'list vals) vals)))
13355 (defun org-property-previous-allowed-value (&optional previous)
13356 "Switch to the next allowed value for this property."
13358 (org-property-next-allowed-value t))
13360 (defun org-property-next-allowed-value (&optional previous)
13361 "Switch to the next allowed value for this property."
13363 (unless (org-at-property-p)
13364 (error "Not at a property"))
13365 (let* ((key (match-string 2))
13366 (value (match-string 3))
13367 (allowed (or (org-property-get-allowed-values (point) key)
13368 (and (member value '("[ ]" "[-]" "[X]"))
13372 (error "Allowed values for this property have not been defined"))
13373 (if previous (setq allowed (reverse allowed)))
13374 (if (member value allowed)
13375 (setq nval (car (cdr (member value allowed)))))
13376 (setq nval (or nval (car allowed)))
13377 (if (equal nval value)
13378 (error "Only one allowed value for this property"))
13379 (org-at-property-p)
13380 (replace-match (concat " :" key ": " nval) t t)
13381 (org-indent-line-function)
13382 (beginning-of-line 1)
13383 (skip-chars-forward " \t")
13384 (run-hook-with-args 'org-property-changed-functions key nval)))
13386 (defun org-find-entry-with-id (ident)
13387 "Locate the entry that contains the ID property with exact value IDENT.
13388 IDENT can be a string, a symbol or a number, this function will search for
13389 the string representation of it.
13390 Return the position where this entry starts, or nil if there is no such entry."
13391 (interactive "sID: ")
13393 ((stringp ident) ident)
13394 ((symbol-name ident) (symbol-name ident))
13395 ((numberp ident) (number-to-string ident))
13396 (t (error "IDENT %s must be a string, symbol or number" ident))))
13397 (case-fold-search nil))
13401 (goto-char (point-min))
13402 (when (re-search-forward
13403 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13405 (org-back-to-heading t)
13410 (defvar org-last-changed-timestamp nil)
13411 (defvar org-last-inserted-timestamp nil
13412 "The last time stamp inserted with `org-insert-time-stamp'.")
13413 (defvar org-time-was-given) ; dynamically scoped parameter
13414 (defvar org-end-time-was-given) ; dynamically scoped parameter
13415 (defvar org-ts-what) ; dynamically scoped parameter
13417 (defun org-time-stamp (arg &optional inactive)
13418 "Prompt for a date/time and insert a time stamp.
13419 If the user specifies a time like HH:MM, or if this command is called
13420 with a prefix argument, the time stamp will contain date and time.
13421 Otherwise, only the date will be included. All parts of a date not
13422 specified by the user will be filled in from the current date/time.
13423 So if you press just return without typing anything, the time stamp
13424 will represent the current date/time. If there is already a timestamp
13425 at the cursor, it will be modified."
13429 ;; Default time is either today, or, when entering a range,
13430 ;; the range start.
13431 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13433 (re-search-backward
13434 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13435 (- (point) 20) t)))
13436 (apply 'encode-time (org-parse-time-string (match-string 1)))
13438 (default-input (and ts (org-get-compact-tod ts)))
13439 org-time-was-given org-end-time-was-given time)
13441 ((and (org-at-timestamp-p t)
13442 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13443 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13445 (setq time (let ((this-command this-command))
13446 (org-read-date arg 'totime nil nil
13447 default-time default-input)))
13448 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13449 ((org-at-timestamp-p t)
13450 (setq time (let ((this-command this-command))
13451 (org-read-date arg 'totime nil nil default-time default-input)))
13452 (when (org-at-timestamp-p t) ; just to get the match data
13453 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13455 (setq org-last-changed-timestamp
13456 (org-insert-time-stamp
13457 time (or org-time-was-given arg)
13458 inactive nil nil (list org-end-time-was-given))))
13459 (message "Timestamp updated"))
13461 (setq time (let ((this-command this-command))
13462 (org-read-date arg 'totime nil nil default-time default-input)))
13463 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13464 nil nil (list org-end-time-was-given))))))
13466 ;; FIXME: can we use this for something else, like computing time differences?
13467 (defun org-get-compact-tod (s)
13468 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13469 (let* ((t1 (match-string 1 s))
13470 (h1 (string-to-number (match-string 2 s)))
13471 (m1 (string-to-number (match-string 3 s)))
13472 (t2 (and (match-end 4) (match-string 5 s)))
13473 (h2 (and t2 (string-to-number (match-string 6 s))))
13474 (m2 (and t2 (string-to-number (match-string 7 s))))
13478 (setq dh (- h2 h1) dm (- m2 m1))
13479 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13480 (concat t1 "+" (number-to-string dh)
13481 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13483 (defun org-time-stamp-inactive (&optional arg)
13484 "Insert an inactive time stamp.
13485 An inactive time stamp is enclosed in square brackets instead of angle
13486 brackets. It is inactive in the sense that it does not trigger agenda entries,
13487 does not link to the calendar and cannot be changed with the S-cursor keys.
13488 So these are more for recording a certain time/date."
13490 (org-time-stamp arg 'inactive))
13492 (defvar org-date-ovl (make-overlay 1 1))
13493 (overlay-put org-date-ovl 'face 'org-warning)
13494 (org-detach-overlay org-date-ovl)
13496 (defvar org-ans1) ; dynamically scoped parameter
13497 (defvar org-ans2) ; dynamically scoped parameter
13499 (defvar org-plain-time-of-day-regexp) ; defined below
13501 (defvar org-overriding-default-time nil) ; dynamically scoped
13502 (defvar org-read-date-overlay nil)
13503 (defvar org-dcst nil) ; dynamically scoped
13504 (defvar org-read-date-history nil)
13505 (defvar org-read-date-final-answer nil)
13507 (defun org-read-date (&optional with-time to-time from-string prompt
13508 default-time default-input)
13509 "Read a date, possibly a time, and make things smooth for the user.
13510 The prompt will suggest to enter an ISO date, but you can also enter anything
13511 which will at least partially be understood by `parse-time-string'.
13512 Unrecognized parts of the date will default to the current day, month, year,
13513 hour and minute. If this command is called to replace a timestamp at point,
13514 of to enter the second timestamp of a range, the default time is taken from the
13515 existing stamp. For example,
13516 3-2-5 --> 2003-02-05
13517 feb 15 --> currentyear-02-15
13518 sep 12 9 --> 2009-09-12
13519 12:45 --> today 12:45
13520 22 sept 0:34 --> currentyear-09-22 0:34
13521 12 --> currentyear-currentmonth-12
13522 Fri --> nearest Friday (today or later)
13525 Furthermore you can specify a relative date by giving, as the *first* thing
13526 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
13527 change in days weeks, months, years.
13528 With a single plus or minus, the date is relative to today. With a double
13529 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
13530 +4d --> four days from today
13531 +4 --> same as above
13532 +2w --> two weeks from today
13533 ++5 --> five days from default date
13535 The function understands only English month and weekday abbreviations,
13536 but this can be configured with the variables `parse-time-months' and
13537 `parse-time-weekdays'.
13539 While prompting, a calendar is popped up - you can also select the
13540 date with the mouse (button 1). The calendar shows a period of three
13541 months. To scroll it to other months, use the keys `>' and `<'.
13542 If you don't like the calendar, turn it off with
13543 \(setq org-read-date-popup-calendar nil)
13545 With optional argument TO-TIME, the date will immediately be converted
13546 to an internal time.
13547 With an optional argument WITH-TIME, the prompt will suggest to also
13548 insert a time. Note that when WITH-TIME is not set, you can still
13549 enter a time, and this function will inform the calling routine about
13550 this change. The calling routine may then choose to change the format
13551 used to insert the time stamp into the buffer to include the time.
13552 With optional argument FROM-STRING, read from this string instead from
13553 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
13554 the time/date that is used for everything that is not specified by the
13556 (require 'parse-time)
13557 (let* ((org-time-stamp-rounding-minutes
13558 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
13559 (org-dcst org-display-custom-times)
13560 (ct (org-current-time))
13561 (def (or org-overriding-default-time default-time ct))
13562 (defdecode (decode-time def))
13564 (when (< (nth 2 defdecode) org-extend-today-until)
13565 (setcar (nthcdr 2 defdecode) -1)
13566 (setcar (nthcdr 1 defdecode) 59)
13567 (setq def (apply 'encode-time defdecode)
13568 defdecode (decode-time def)))))
13569 (calendar-frame-setup nil)
13570 (calendar-move-hook nil)
13571 (calendar-view-diary-initially-flag nil)
13572 (calendar-view-holidays-initially-flag nil)
13573 (timestr (format-time-string
13574 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
13575 (prompt (concat (if prompt (concat prompt " ") "")
13576 (format "Date+time [%s]: " timestr)))
13577 ans (org-ans0 "") org-ans1 org-ans2 final)
13580 (from-string (setq ans from-string))
13581 (org-read-date-popup-calendar
13583 (save-window-excursion
13585 (calendar-forward-day (- (time-to-days def)
13586 (calendar-absolute-from-gregorian
13587 (calendar-current-date))))
13588 (org-eval-in-calendar nil t)
13589 (let* ((old-map (current-local-map))
13590 (map (copy-keymap calendar-mode-map))
13591 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
13592 (org-defkey map (kbd "RET") 'org-calendar-select)
13593 (org-defkey map (if (featurep 'xemacs) [button1] [mouse-1])
13594 'org-calendar-select-mouse)
13595 (org-defkey map (if (featurep 'xemacs) [button2] [mouse-2
])
13596 'org-calendar-select-mouse
)
13597 (org-defkey minibuffer-local-map
[(meta shift left
)]
13598 (lambda () (interactive)
13599 (org-eval-in-calendar '(calendar-backward-month 1))))
13600 (org-defkey minibuffer-local-map
[(meta shift right
)]
13601 (lambda () (interactive)
13602 (org-eval-in-calendar '(calendar-forward-month 1))))
13603 (org-defkey minibuffer-local-map
[(meta shift up
)]
13604 (lambda () (interactive)
13605 (org-eval-in-calendar '(calendar-backward-year 1))))
13606 (org-defkey minibuffer-local-map
[(meta shift down
)]
13607 (lambda () (interactive)
13608 (org-eval-in-calendar '(calendar-forward-year 1))))
13609 (org-defkey minibuffer-local-map
[?\e
(shift left
)]
13610 (lambda () (interactive)
13611 (org-eval-in-calendar '(calendar-backward-month 1))))
13612 (org-defkey minibuffer-local-map
[?\e
(shift right
)]
13613 (lambda () (interactive)
13614 (org-eval-in-calendar '(calendar-forward-month 1))))
13615 (org-defkey minibuffer-local-map
[?\e
(shift up
)]
13616 (lambda () (interactive)
13617 (org-eval-in-calendar '(calendar-backward-year 1))))
13618 (org-defkey minibuffer-local-map
[?\e
(shift down
)]
13619 (lambda () (interactive)
13620 (org-eval-in-calendar '(calendar-forward-year 1))))
13621 (org-defkey minibuffer-local-map
[(shift up
)]
13622 (lambda () (interactive)
13623 (org-eval-in-calendar '(calendar-backward-week 1))))
13624 (org-defkey minibuffer-local-map
[(shift down
)]
13625 (lambda () (interactive)
13626 (org-eval-in-calendar '(calendar-forward-week 1))))
13627 (org-defkey minibuffer-local-map
[(shift left
)]
13628 (lambda () (interactive)
13629 (org-eval-in-calendar '(calendar-backward-day 1))))
13630 (org-defkey minibuffer-local-map
[(shift right
)]
13631 (lambda () (interactive)
13632 (org-eval-in-calendar '(calendar-forward-day 1))))
13633 (org-defkey minibuffer-local-map
">"
13634 (lambda () (interactive)
13635 (org-eval-in-calendar '(scroll-calendar-left 1))))
13636 (org-defkey minibuffer-local-map
"<"
13637 (lambda () (interactive)
13638 (org-eval-in-calendar '(scroll-calendar-right 1))))
13639 (run-hooks 'org-read-date-minibuffer-setup-hook
)
13642 (use-local-map map
)
13643 (add-hook 'post-command-hook
'org-read-date-display
)
13644 (setq org-ans0
(read-string prompt default-input
13645 'org-read-date-history nil
))
13646 ;; org-ans0: from prompt
13647 ;; org-ans1: from mouse click
13648 ;; org-ans2: from calendar motion
13649 (setq ans
(concat org-ans0
" " (or org-ans1 org-ans2
))))
13650 (remove-hook 'post-command-hook
'org-read-date-display
)
13651 (use-local-map old-map
)
13652 (when org-read-date-overlay
13653 (delete-overlay org-read-date-overlay
)
13654 (setq org-read-date-overlay nil
)))))))
13656 (t ; Naked prompt only
13658 (setq ans
(read-string prompt default-input
13659 'org-read-date-history timestr
))
13660 (when org-read-date-overlay
13661 (delete-overlay org-read-date-overlay
)
13662 (setq org-read-date-overlay nil
)))))
13664 (setq final
(org-read-date-analyze ans def defdecode
))
13665 (setq org-read-date-final-answer ans
)
13668 (apply 'encode-time final
)
13669 (if (and (boundp 'org-time-was-given
) org-time-was-given
)
13670 (format "%04d-%02d-%02d %02d:%02d"
13671 (nth 5 final
) (nth 4 final
) (nth 3 final
)
13672 (nth 2 final
) (nth 1 final
))
13673 (format "%04d-%02d-%02d" (nth 5 final
) (nth 4 final
) (nth 3 final
))))))
13678 (defvar org-read-date-analyze-futurep nil
)
13679 (defun org-read-date-display ()
13680 "Display the current date prompt interpretation in the minibuffer."
13681 (when org-read-date-display-live
13682 (when org-read-date-overlay
13683 (delete-overlay org-read-date-overlay
))
13686 (while (not (equal (buffer-substring
13687 (max (point-min) (- (point) 4)) (point))
13691 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
13692 " " (or org-ans1 org-ans2
)))
13693 (org-end-time-was-given nil
)
13694 (f (org-read-date-analyze ans def defdecode
))
13696 org-time-stamp-custom-formats
13697 org-time-stamp-formats
))
13698 (fmt (if (or with-time
13699 (and (boundp 'org-time-was-given
) org-time-was-given
))
13702 (txt (concat "=> " (format-time-string fmt
(apply 'encode-time f
)))))
13703 (when (and org-end-time-was-given
13704 (string-match org-plain-time-of-day-regexp txt
))
13705 (setq txt
(concat (substring txt
0 (match-end 0)) "-"
13706 org-end-time-was-given
13707 (substring txt
(match-end 0)))))
13708 (when org-read-date-analyze-futurep
13709 (setq txt
(concat txt
" (=>F)")))
13710 (setq org-read-date-overlay
13711 (make-overlay (1- (point-at-eol)) (point-at-eol)))
13712 (org-overlay-display org-read-date-overlay txt
'secondary-selection
))))
13714 (defun org-read-date-analyze (ans def defdecode
)
13715 "Analyse the combined answer of the date prompt."
13716 ;; FIXME: cleanup and comment
13717 (let ((nowdecode (decode-time (current-time)))
13718 delta deltan deltaw deltadef year month day
13719 hour minute second wday pm h2 m2 tl wday1
13720 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year
)
13721 (setq org-read-date-analyze-futurep nil
)
13722 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans
)
13725 (when (setq delta
(org-read-date-get-relative ans
(current-time) def
))
13726 (setq ans
(replace-match "" t t ans
)
13728 deltaw
(nth 1 delta
)
13729 deltadef
(nth 2 delta
)))
13731 ;; Check if there is an iso week date in there
13732 ;; If yes, store the info and postpone interpreting it until the rest
13733 ;; of the parsing is done
13734 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans
)
13735 (setq iso-year
(if (match-end 1)
13736 (org-small-year-to-year
13737 (string-to-number (match-string 1 ans
))))
13738 iso-weekday
(if (match-end 3)
13739 (string-to-number (match-string 3 ans
)))
13740 iso-week
(string-to-number (match-string 2 ans
)))
13741 (setq ans
(replace-match "" t t ans
)))
13743 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
13744 (when (string-match
13745 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans
)
13746 (setq year
(if (match-end 2)
13747 (string-to-number (match-string 2 ans
))
13748 (progn (setq kill-year t
)
13749 (string-to-number (format-time-string "%Y"))))
13750 month
(string-to-number (match-string 3 ans
))
13751 day
(string-to-number (match-string 4 ans
)))
13752 (if (< year
100) (setq year
(+ 2000 year
)))
13753 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
13755 ;; Help matching american dates, like 5/30 or 5/30/7
13756 (when (string-match
13757 "^ *\\([0-3]?[0-9]\\)/\\([0-1]?[0-9]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans
)
13758 (setq year
(if (match-end 4)
13759 (string-to-number (match-string 4 ans
))
13760 (progn (setq kill-year t
)
13761 (string-to-number (format-time-string "%Y"))))
13762 month
(string-to-number (match-string 1 ans
))
13763 day
(string-to-number (match-string 2 ans
)))
13764 (if (< year
100) (setq year
(+ 2000 year
)))
13765 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
13767 ;; Help matching am/pm times, because `parse-time-string' does not do that.
13768 ;; If there is a time with am/pm, and *no* time without it, we convert
13769 ;; so that matching will be successful.
13770 (loop for i from
1 to
2 do
; twice, for end time as well
13771 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans
))
13772 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans
))
13773 (setq hour
(string-to-number (match-string 1 ans
))
13774 minute
(if (match-end 3)
13775 (string-to-number (match-string 3 ans
))
13778 (string-to-char (downcase (match-string 4 ans
)))))
13779 (if (and (= hour
12) (not pm
))
13781 (if (and pm
(< hour
12)) (setq hour
(+ 12 hour
))))
13782 (setq ans
(replace-match (format "%02d:%02d" hour minute
)
13785 ;; Check if a time range is given as a duration
13786 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans
)
13787 (setq hour
(string-to-number (match-string 1 ans
))
13788 h2
(+ hour
(string-to-number (match-string 3 ans
)))
13789 minute
(string-to-number (match-string 2 ans
))
13790 m2
(+ minute
(if (match-end 5) (string-to-number
13791 (match-string 5 ans
))0)))
13792 (if (>= m2
60) (setq h2
(1+ h2
) m2
(- m2
60)))
13793 (setq ans
(replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2
)
13796 ;; Check if there is a time range
13797 (when (boundp 'org-end-time-was-given
)
13798 (setq org-time-was-given nil
)
13799 (when (and (string-match org-plain-time-of-day-regexp ans
)
13801 (setq org-end-time-was-given
(match-string 8 ans
))
13802 (setq ans
(concat (substring ans
0 (match-beginning 7))
13803 (substring ans
(match-end 7))))))
13805 (setq tl
(parse-time-string ans
)
13806 day
(or (nth 3 tl
) (nth 3 defdecode
))
13807 month
(or (nth 4 tl
)
13808 (if (and org-read-date-prefer-future
13809 (nth 3 tl
) (< (nth 3 tl
) (nth 3 nowdecode
)))
13810 (prog1 (1+ (nth 4 nowdecode
)) (setq futurep t
))
13811 (nth 4 defdecode
)))
13812 year
(or (and (not kill-year
) (nth 5 tl
))
13813 (if (and org-read-date-prefer-future
13814 (nth 4 tl
) (< (nth 4 tl
) (nth 4 nowdecode
)))
13815 (prog1 (1+ (nth 5 nowdecode
)) (setq futurep t
))
13816 (nth 5 defdecode
)))
13817 hour
(or (nth 2 tl
) (nth 2 defdecode
))
13818 minute
(or (nth 1 tl
) (nth 1 defdecode
))
13819 second
(or (nth 0 tl
) 0)
13822 (when (and (eq org-read-date-prefer-future
'time
)
13823 (not (nth 3 tl
)) (not (nth 4 tl
)) (not (nth 5 tl
))
13824 (equal day
(nth 3 nowdecode
))
13825 (equal month
(nth 4 nowdecode
))
13826 (equal year
(nth 5 nowdecode
))
13828 (or (< (nth 2 tl
) (nth 2 nowdecode
))
13829 (and (= (nth 2 tl
) (nth 2 nowdecode
))
13831 (< (nth 1 tl
) (nth 1 nowdecode
)))))
13835 ;; Special date definitions below
13838 ;; There was an iso week
13841 (setq year
(or iso-year year
)
13842 day
(or iso-weekday wday
1)
13843 wday nil
; to make sure that the trigger below does not match
13844 iso-date
(calendar-gregorian-from-absolute
13845 (calendar-absolute-from-iso
13846 (list iso-week day year
))))
13847 ; FIXME: Should we also push ISO weeks into the future?
13848 ; (when (and org-read-date-prefer-future
13850 ; (< (calendar-absolute-from-gregorian iso-date)
13851 ; (time-to-days (current-time))))
13852 ; (setq year (1+ year)
13853 ; iso-date (calendar-gregorian-from-absolute
13854 ; (calendar-absolute-from-iso
13855 ; (list iso-week day year)))))
13856 (setq month
(car iso-date
)
13857 year
(nth 2 iso-date
)
13858 day
(nth 1 iso-date
)))
13862 (let ((now (decode-time (current-time))))
13863 (setq day
(nth 3 now
) month
(nth 4 now
) year
(nth 5 now
))))
13864 (cond ((member deltaw
'("d" "")) (setq day
(+ day deltan
)))
13865 ((equal deltaw
"w") (setq day
(+ day
(* 7 deltan
))))
13866 ((equal deltaw
"m") (setq month
(+ month deltan
)))
13867 ((equal deltaw
"y") (setq year
(+ year deltan
)))))
13868 ((and wday
(not (nth 3 tl
)))
13870 ;; Weekday was given, but no day, so pick that day in the week
13871 ;; on or after the derived date.
13872 (setq wday1
(nth 6 (decode-time (encode-time 0 0 0 day month year
))))
13873 (unless (equal wday wday1
)
13874 (setq day
(+ day
(%
(- wday wday1 -
7) 7))))))
13875 (if (and (boundp 'org-time-was-given
)
13877 (setq org-time-was-given t
))
13878 (if (< year
100) (setq year
(+ 2000 year
)))
13879 (if (< year
1970) (setq year
(nth 5 defdecode
))) ; not representable
13880 (setq org-read-date-analyze-futurep futurep
)
13881 (list second minute hour day month year
)))
13883 (defvar parse-time-weekdays
)
13885 (defun org-read-date-get-relative (s today default
)
13886 "Check string S for special relative date string.
13887 TODAY and DEFAULT are internal times, for today and for a default.
13888 Return shift list (N what def-flag)
13889 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
13890 N is the number of WHATs to shift.
13891 DEF-FLAG is t when a double ++ or -- indicates shift relative to
13892 the DEFAULT date rather than TODAY."
13896 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
13898 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays
"\\|") "\\)\\)?"
13899 "\\([ \t]\\|$\\)") s
)
13900 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
13901 (let* ((dir (if (> (match-end 1) (match-beginning 1))
13902 (string-to-char (substring (match-string 1 s
) -
1))
13904 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
13905 (n (if (match-end 2) (string-to-number (match-string 2 s
)) 1))
13906 (what (if (match-end 3) (match-string 3 s
) "d"))
13907 (wday1 (cdr (assoc (downcase what
) parse-time-weekdays
)))
13908 (date (if rel default today
))
13909 (wday (nth 6 (decode-time date
)))
13913 (setq delta
(mod (+ 7 (- wday1 wday
)) 7))
13914 (if (= dir ?-
) (setq delta
(- delta
7)))
13915 (if (> n
1) (setq delta
(+ delta
(* (1- n
) (if (= dir ?-
) -
7 7)))))
13916 (list delta
"d" rel
))
13917 (list (* n
(if (= dir ?-
) -
1 1)) what rel
)))))
13919 (defun org-order-calendar-date-args (arg1 arg2 arg3
)
13920 "Turn a user-specified date into the internal representation.
13921 The internal representation needed by the calendar is (month day year).
13922 This is a wrapper to handle the brain-dead convention in calendar that
13923 user function argument order change dependent on argument order."
13924 (if (boundp 'calendar-date-style
)
13926 ((eq calendar-date-style
'american
)
13927 (list arg1 arg2 arg3
))
13928 ((eq calendar-date-style
'european
)
13929 (list arg2 arg1 arg3
))
13930 ((eq calendar-date-style
'iso
)
13931 (list arg2 arg3 arg1
)))
13932 (if (org-bound-and-true-p european-calendar-style
)
13933 (list arg2 arg1 arg3
)
13934 (list arg1 arg2 arg3
))))
13936 (defun org-eval-in-calendar (form &optional keepdate
)
13937 "Eval FORM in the calendar window and return to current window.
13938 Also, store the cursor date in variable org-ans2."
13939 (let ((sf (selected-frame))
13940 (sw (selected-window)))
13941 (select-window (get-buffer-window "*Calendar*" t
))
13943 (when (and (not keepdate
) (calendar-cursor-to-date))
13944 (let* ((date (calendar-cursor-to-date))
13945 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13946 (setq org-ans2
(format-time-string "%Y-%m-%d" time
))))
13947 (move-overlay org-date-ovl
(1- (point)) (1+ (point)) (current-buffer))
13949 (org-select-frame-set-input-focus sf
)))
13951 (defun org-calendar-select ()
13952 "Return to `org-read-date' with the date currently selected.
13953 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
13955 (when (calendar-cursor-to-date)
13956 (let* ((date (calendar-cursor-to-date))
13957 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
13958 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
13959 (if (active-minibuffer-window) (exit-minibuffer))))
13961 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra
)
13962 "Insert a date stamp for the date given by the internal TIME.
13963 WITH-HM means use the stamp format that includes the time of the day.
13964 INACTIVE means use square brackets instead of angular ones, so that the
13965 stamp will not contribute to the agenda.
13966 PRE and POST are optional strings to be inserted before and after the
13968 The command returns the inserted time stamp."
13969 (let ((fmt (funcall (if with-hm
'cdr
'car
) org-time-stamp-formats
))
13971 (if inactive
(setq fmt
(concat "[" (substring fmt
1 -
1) "]")))
13972 (insert-before-markers (or pre
""))
13973 (insert-before-markers (setq stamp
(format-time-string fmt time
)))
13974 (when (listp extra
)
13975 (setq extra
(car extra
))
13976 (if (and (stringp extra
)
13977 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra
))
13978 (setq extra
(format "-%02d:%02d"
13979 (string-to-number (match-string 1 extra
))
13980 (string-to-number (match-string 2 extra
))))
13984 (insert-before-markers extra
)
13986 (insert-before-markers (or post
""))
13987 (setq org-last-inserted-timestamp stamp
)))
13989 (defun org-toggle-time-stamp-overlays ()
13990 "Toggle the use of custom time stamp formats."
13992 (setq org-display-custom-times
(not org-display-custom-times
))
13993 (unless org-display-custom-times
13994 (let ((p (point-min)) (bmp (buffer-modified-p)))
13995 (while (setq p
(next-single-property-change p
'display
))
13996 (if (and (get-text-property p
'display
)
13997 (eq (get-text-property p
'face
) 'org-date
))
13998 (remove-text-properties
13999 p
(setq p
(next-single-property-change p
'display
))
14001 (set-buffer-modified-p bmp
)))
14002 (if (featurep 'xemacs
)
14003 (remove-text-properties (point-min) (point-max) '(end-glyph t
)))
14004 (org-restart-font-lock)
14005 (setq org-table-may-need-update t
)
14006 (if org-display-custom-times
14007 (message "Time stamps are overlayed with custom format")
14008 (message "Time stamp overlays removed")))
14010 (defun org-display-custom-time (beg end
)
14011 "Overlay modified time stamp format over timestamp between BEG and END."
14012 (let* ((ts (buffer-substring beg end
))
14013 t1 w1 with-hm tf time str w2
(off 0))
14015 (setq t1
(org-parse-time-string ts t
))
14016 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts
)
14017 (setq off
(- (match-end 0) (match-beginning 0)))))
14018 (setq end
(- end off
))
14019 (setq w1
(- end beg
)
14020 with-hm
(and (nth 1 t1
) (nth 2 t1
))
14021 tf
(funcall (if with-hm
'cdr
'car
) org-time-stamp-custom-formats
)
14022 time
(org-fix-decoded-time t1
)
14024 (format-time-string
14025 (substring tf
1 -
1) (apply 'encode-time time
))
14026 nil
'mouse-face
'highlight
)
14028 (if (not (= w2 w1
))
14029 (add-text-properties (1+ beg
) (+ 2 beg
)
14030 (list 'org-dwidth t
'org-dwidth-n
(- w1 w2
))))
14031 (if (featurep 'xemacs
)
14033 (put-text-property beg end
'invisible t
)
14034 (put-text-property beg end
'end-glyph
(make-glyph str
)))
14035 (put-text-property beg end
'display str
))))
14037 (defun org-translate-time (string)
14038 "Translate all timestamps in STRING to custom format.
14039 But do this only if the variable `org-display-custom-times' is set."
14040 (when org-display-custom-times
14043 (re org-ts-regexp-both
)
14044 t1 with-hm inactive tf time str beg end
)
14045 (while (setq start
(string-match re string start
))
14046 (setq beg
(match-beginning 0)
14048 t1
(save-match-data
14049 (org-parse-time-string (substring string beg end
) t
))
14050 with-hm
(and (nth 1 t1
) (nth 2 t1
))
14051 inactive
(equal (substring string beg
(1+ beg
)) "[")
14052 tf
(funcall (if with-hm
'cdr
'car
)
14053 org-time-stamp-custom-formats
)
14054 time
(org-fix-decoded-time t1
)
14055 str
(format-time-string
14057 (if inactive
"[" "<") (substring tf
1 -
1)
14058 (if inactive
"]" ">"))
14059 (apply 'encode-time time
))
14060 string
(replace-match str t t string
)
14061 start
(+ start
(length str
)))))))
14064 (defun org-fix-decoded-time (time)
14065 "Set 0 instead of nil for the first 6 elements of time.
14066 Don't touch the rest."
14068 (mapcar (lambda (x) (if (< (setq n
(1+ n
)) 7) (or x
0) x
)) time
)))
14070 (defun org-days-to-time (timestamp-string)
14071 "Difference between TIMESTAMP-STRING and now in days."
14072 (- (time-to-days (org-time-string-to-time timestamp-string
))
14073 (time-to-days (current-time))))
14075 (defun org-deadline-close (timestamp-string &optional ndays
)
14076 "Is the time in TIMESTAMP-STRING close to the current date?"
14077 (setq ndays
(or ndays
(org-get-wdays timestamp-string
)))
14078 (and (< (org-days-to-time timestamp-string
) ndays
)
14079 (not (org-entry-is-done-p))))
14081 (defun org-get-wdays (ts)
14082 "Get the deadline lead time appropriate for timestring TS."
14084 ((<= org-deadline-warning-days
0)
14085 ;; 0 or negative, enforce this value no matter what
14086 (- org-deadline-warning-days
))
14087 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts
)
14088 ;; lead time is specified.
14089 (floor (* (string-to-number (match-string 1 ts
))
14090 (cdr (assoc (match-string 2 ts
)
14091 '(("d" .
1) ("w" .
7)
14092 ("m" .
30.4) ("y" .
365.25)))))))
14093 ;; go for the default.
14094 (t org-deadline-warning-days
)))
14096 (defun org-calendar-select-mouse (ev)
14097 "Return to `org-read-date' with the date currently selected.
14098 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14100 (mouse-set-point ev
)
14101 (when (calendar-cursor-to-date)
14102 (let* ((date (calendar-cursor-to-date))
14103 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
14104 (setq org-ans1
(format-time-string "%Y-%m-%d" time
)))
14105 (if (active-minibuffer-window) (exit-minibuffer))))
14107 (defun org-check-deadlines (ndays)
14108 "Check if there are any deadlines due or past due.
14109 A deadline is considered due if it happens within `org-deadline-warning-days'
14110 days from today's date. If the deadline appears in an entry marked DONE,
14111 it is not shown. The prefix arg NDAYS can be used to test that many
14112 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14114 (let* ((org-warn-days
14116 ((equal ndays
'(4)) 100000)
14117 (ndays (prefix-numeric-value ndays
))
14118 (t (abs org-deadline-warning-days
))))
14119 (case-fold-search nil
)
14120 (regexp (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>"))
14122 (lambda () (org-deadline-close (match-string 1) org-warn-days
))))
14124 (message "%d deadlines past-due or due within %d days"
14125 (org-occur regexp nil callback
)
14128 (defun org-check-before-date (date)
14129 "Check if there are deadlines or scheduled entries before DATE."
14130 (interactive (list (org-read-date)))
14131 (let ((case-fold-search nil
)
14132 (regexp (concat "\\<\\(" org-deadline-string
14133 "\\|" org-scheduled-string
14134 "\\) *<\\([^>]+\\)>"))
14136 (lambda () (time-less-p
14137 (org-time-string-to-time (match-string 2))
14138 (org-time-string-to-time date
)))))
14139 (message "%d entries before %s"
14140 (org-occur regexp nil callback
) date
)))
14142 (defun org-check-after-date (date)
14143 "Check if there are deadlines or scheduled entries after DATE."
14144 (interactive (list (org-read-date)))
14145 (let ((case-fold-search nil
)
14146 (regexp (concat "\\<\\(" org-deadline-string
14147 "\\|" org-scheduled-string
14148 "\\) *<\\([^>]+\\)>"))
14152 (org-time-string-to-time (match-string 2))
14153 (org-time-string-to-time date
))))))
14154 (message "%d entries after %s"
14155 (org-occur regexp nil callback
) date
)))
14157 (defun org-evaluate-time-range (&optional to-buffer
)
14158 "Evaluate a time range by computing the difference between start and end.
14159 Normally the result is just printed in the echo area, but with prefix arg
14160 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14161 If the time range is actually in a table, the result is inserted into the
14163 For time difference computation, a year is assumed to be exactly 365
14164 days in order to avoid rounding problems."
14167 (org-clock-update-time-maybe)
14169 (unless (org-at-date-range-p t
)
14170 (goto-char (point-at-bol))
14171 (re-search-forward org-tr-regexp-both
(point-at-eol) t
))
14172 (if (not (org-at-date-range-p t
))
14173 (error "Not at a time-stamp range, and none found in current line")))
14174 (let* ((ts1 (match-string 1))
14175 (ts2 (match-string 2))
14176 (havetime (or (> (length ts1
) 15) (> (length ts2
) 15)))
14177 (match-end (match-end 0))
14178 (time1 (org-time-string-to-time ts1
))
14179 (time2 (org-time-string-to-time ts2
))
14180 (t1 (org-float-time time1
))
14181 (t2 (org-float-time time2
))
14182 (diff (abs (- t2 t1
)))
14183 (negative (< (- t2 t1
) 0))
14184 ;; (ys (floor (* 365 24 60 60)))
14187 (fy "%dy %dd %02d:%02d")
14189 (fd "%dd %02d:%02d")
14194 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14196 d
(floor (/ diff ds
)) diff
(mod diff ds
)
14197 h
(floor (/ diff hs
)) diff
(mod diff hs
)
14198 m
(floor (/ diff
60)))
14199 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14201 d
(floor (+ (/ diff ds
) 0.5))
14203 (if (not to-buffer
)
14204 (message "%s" (org-make-tdiff-string y d h m
))
14205 (if (org-at-table-p)
14207 (goto-char match-end
)
14209 (and (looking-at " *|") (goto-char (match-end 0))))
14210 (goto-char match-end
))
14212 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14213 (replace-match ""))
14214 (if negative
(insert " -"))
14215 (if (> y
0) (insert " " (format (if havetime fy fy1
) y d h m
))
14216 (if (> d
0) (insert " " (format (if havetime fd fd1
) d h m
))
14217 (insert " " (format fh h m
))))
14218 (if align
(org-table-align))
14219 (message "Time difference inserted")))))
14221 (defun org-make-tdiff-string (y d h m
)
14224 (if (> y
0) (setq fmt
(concat fmt
"%d year" (if (> y
1) "s" "") " ")
14226 (if (> d
0) (setq fmt
(concat fmt
"%d day" (if (> d
1) "s" "") " ")
14228 (if (> h
0) (setq fmt
(concat fmt
"%d hour" (if (> h
1) "s" "") " ")
14230 (if (> m
0) (setq fmt
(concat fmt
"%d minute" (if (> m
1) "s" "") " ")
14232 (apply 'format fmt
(nreverse l
))))
14234 (defun org-time-string-to-time (s)
14235 (apply 'encode-time
(org-parse-time-string s
)))
14236 (defun org-time-string-to-seconds (s)
14237 (org-float-time (org-time-string-to-time s
)))
14239 (defun org-time-string-to-absolute (s &optional daynr prefer show-all
)
14240 "Convert a time stamp to an absolute day number.
14241 If there is a specifyer for a cyclic time stamp, get the closest date to
14243 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14244 the variable date is bound by the calendar when this is called."
14246 ((and daynr
(string-match "\\`%%\\((.*)\\)" s
))
14247 (if (org-diary-sexp-entry (match-string 1 s
) "" date
)
14250 ((and daynr
(string-match "\\+[0-9]+[dwmy]" s
))
14251 (org-closest-date s
(if (and (boundp 'daynr
) (integerp daynr
)) daynr
14252 (time-to-days (current-time))) (match-string 0 s
)
14254 (t (time-to-days (apply 'encode-time
(org-parse-time-string s
))))))
14256 (defun org-days-to-iso-week (days)
14257 "Return the iso week number."
14259 (car (calendar-iso-from-absolute days
)))
14261 (defun org-small-year-to-year (year)
14262 "Convert 2-digit years into 4-digit years.
14263 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14264 The year 2000 cannot be abbreviated. Any year larger than 99
14265 is returned unchanged."
14267 (setq year
(+ 2000 year
))
14269 (setq year
(+ 1900 year
))))
14272 (defun org-time-from-absolute (d)
14273 "Return the time corresponding to date D.
14274 D may be an absolute day number, or a calendar-type list (month day year)."
14275 (if (numberp d
) (setq d
(calendar-gregorian-from-absolute d
)))
14276 (encode-time 0 0 0 (nth 1 d
) (car d
) (nth 2 d
)))
14278 (defun org-calendar-holiday ()
14279 "List of holidays, for Diary display in Org-mode."
14280 (require 'holidays
)
14282 (if (fboundp 'calendar-check-holidays
)
14283 'calendar-check-holidays
'check-calendar-holidays
) date
)))
14284 (if hl
(mapconcat 'identity hl
"; "))))
14286 (defun org-diary-sexp-entry (sexp entry date
)
14287 "Process a SEXP diary ENTRY for DATE."
14288 (require 'diary-lib
)
14289 (let ((result (if calendar-debug-sexp
14290 (let ((stack-trace-on-error t
))
14291 (eval (car (read-from-string sexp
))))
14292 (condition-case nil
14293 (eval (car (read-from-string sexp
)))
14296 (message "Bad sexp at line %d in %s: %s"
14298 (buffer-file-name) sexp
)
14300 (cond ((stringp result
) result
)
14301 ((and (consp result
)
14302 (stringp (cdr result
))) (cdr result
))
14306 (defun org-diary-to-ical-string (frombuf)
14307 "Get iCalendar entries from diary entries in buffer FROMBUF.
14308 This uses the icalendar.el library."
14309 (let* ((tmpdir (if (featurep 'xemacs
)
14311 temporary-file-directory
))
14312 (tmpfile (make-temp-name
14313 (expand-file-name "orgics" tmpdir
)))
14315 (with-current-buffer frombuf
14316 (icalendar-export-region (point-min) (point-max) tmpfile
)
14317 (setq buf
(find-buffer-visiting tmpfile
))
14319 (goto-char (point-min))
14320 (if (re-search-forward "^BEGIN:VEVENT" nil t
)
14321 (setq b
(match-beginning 0)))
14322 (goto-char (point-max))
14323 (if (re-search-backward "^END:VEVENT" nil t
)
14324 (setq e
(match-end 0)))
14325 (setq rtn
(if (and b e
) (concat (buffer-substring b e
) "\n") "")))
14327 (delete-file tmpfile
)
14330 (defun org-closest-date (start current change prefer show-all
)
14331 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14332 When PREFER is `past' return a date that is either CURRENT or past.
14333 When PREFER is `future', return a date that is either CURRENT or future.
14334 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14335 ;; Make the proper lists from the dates
14337 (let ((a1 '(("d" . day
) ("w" . week
) ("m" . month
) ("y" . year
)))
14338 dn dw sday cday n1 n2 n0
14339 d m y y1 y2 date1 date2 nmonths nm ny m2
)
14341 (setq start
(org-date-to-gregorian start
)
14342 current
(org-date-to-gregorian
14345 (time-to-days (current-time))))
14346 sday
(calendar-absolute-from-gregorian start
)
14347 cday
(calendar-absolute-from-gregorian current
))
14349 (if (<= cday sday
) (throw 'exit sday
))
14351 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change
)
14352 (setq dn
(string-to-number (match-string 1 change
))
14353 dw
(cdr (assoc (match-string 2 change
) a1
)))
14354 (error "Invalid change specifyer: %s" change
))
14355 (if (eq dw
'week
) (setq dw
'day dn
(* 7 dn
)))
14358 (setq n1
(+ sday
(* dn
(floor (/ (- cday sday
) dn
))))
14361 (setq d
(nth 1 start
) m
(car start
) y1
(nth 2 start
) y2
(nth 2 current
))
14362 (setq y1
(+ (* (floor (/ (- y2 y1
) dn
)) dn
) y1
))
14363 (setq date1
(list m d y1
)
14364 n1
(calendar-absolute-from-gregorian date1
)
14365 date2
(list m d
(+ y1
(* (if (< n1 cday
) 1 -
1) dn
)))
14366 n2
(calendar-absolute-from-gregorian date2
)))
14368 ;; approx number of month between the two dates
14369 (setq nmonths
(floor (/ (- cday sday
) 30.436875)))
14370 ;; How often does dn fit in there?
14371 (setq d
(nth 1 start
) m
(car start
) y
(nth 2 start
)
14372 nm
(* dn
(max 0 (1- (floor (/ nmonths dn
)))))
14374 ny
(floor (/ m
12))
14377 (while (> m
12) (setq m
(- m
12) y
(1+ y
)))
14378 (setq n1
(calendar-absolute-from-gregorian (list m d y
)))
14379 (setq m2
(+ m dn
) y2 y
)
14380 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
14381 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
)))
14382 (while (<= n2 cday
)
14383 (setq n1 n2 m m2 y y2
)
14384 (setq m2
(+ m dn
) y2 y
)
14385 (if (> m2
12) (setq y2
(1+ y2
) m2
(- m2
12)))
14386 (setq n2
(calendar-absolute-from-gregorian (list m2 d y2
))))))
14387 ;; Make sure n1 is the earlier date
14388 (setq n0 n1 n1
(min n1 n2
) n2
(max n0 n2
))
14391 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
14392 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
14393 (t (if (> (abs (- cday n1
)) (abs (- cday n2
))) n2 n1
)))
14395 ((eq prefer
'past
) (if (= cday n2
) n2 n1
))
14396 ((eq prefer
'future
) (if (= cday n1
) n1 n2
))
14397 (t (if (= cday n1
) n1 n2
)))))))
14399 (defun org-date-to-gregorian (date)
14400 "Turn any specification of DATE into a gregorian date for the calendar."
14401 (cond ((integerp date
) (calendar-gregorian-from-absolute date
))
14402 ((and (listp date
) (= (length date
) 3)) date
)
14404 (setq date
(org-parse-time-string date
))
14405 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))
14407 (list (nth 4 date
) (nth 3 date
) (nth 5 date
)))))
14409 (defun org-parse-time-string (s &optional nodefault
)
14410 "Parse the standard Org-mode time string.
14411 This should be a lot faster than the normal `parse-time-string'.
14412 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14413 hour and minute fields will be nil if not given."
14414 (if (string-match org-ts-regexp0 s
)
14416 (if (or (match-beginning 8) (not nodefault
))
14417 (string-to-number (or (match-string 8 s
) "0")))
14418 (if (or (match-beginning 7) (not nodefault
))
14419 (string-to-number (or (match-string 7 s
) "0")))
14420 (string-to-number (match-string 4 s
))
14421 (string-to-number (match-string 3 s
))
14422 (string-to-number (match-string 2 s
))
14424 (error "Not a standard Org-mode time string: %s" s
)))
14426 (defun org-timestamp-up (&optional arg
)
14427 "Increase the date item at the cursor by one.
14428 If the cursor is on the year, change the year. If it is on the month or
14429 the day, change that.
14430 With prefix ARG, change by that many units."
14432 (org-timestamp-change (prefix-numeric-value arg
)))
14434 (defun org-timestamp-down (&optional arg
)
14435 "Decrease the date item at the cursor by one.
14436 If the cursor is on the year, change the year. If it is on the month or
14437 the day, change that.
14438 With prefix ARG, change by that many units."
14440 (org-timestamp-change (- (prefix-numeric-value arg
))))
14442 (defun org-timestamp-up-day (&optional arg
)
14443 "Increase the date in the time stamp by one day.
14444 With prefix ARG, change that many days."
14446 (if (and (not (org-at-timestamp-p t
))
14447 (org-on-heading-p))
14449 (org-timestamp-change (prefix-numeric-value arg
) 'day
)))
14451 (defun org-timestamp-down-day (&optional arg
)
14452 "Decrease the date in the time stamp by one day.
14453 With prefix ARG, change that many days."
14455 (if (and (not (org-at-timestamp-p t
))
14456 (org-on-heading-p))
14458 (org-timestamp-change (- (prefix-numeric-value arg
)) 'day
)))
14460 (defun org-at-timestamp-p (&optional inactive-ok
)
14461 "Determine if the cursor is in or at a timestamp."
14463 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2
))
14465 (ans (or (looking-at tsr
)
14467 (skip-chars-backward "^[<\n\r\t")
14468 (if (> (point) (point-min)) (backward-char 1))
14469 (and (looking-at tsr
)
14470 (> (- (match-end 0) pos
) -
1))))))
14472 (boundp 'org-ts-what
)
14475 ((= pos
(match-beginning 0)) 'bracket
)
14476 ((= pos
(1- (match-end 0))) 'bracket
)
14477 ((org-pos-in-match-range pos
2) 'year
)
14478 ((org-pos-in-match-range pos
3) 'month
)
14479 ((org-pos-in-match-range pos
7) 'hour
)
14480 ((org-pos-in-match-range pos
8) 'minute
)
14481 ((or (org-pos-in-match-range pos
4)
14482 (org-pos-in-match-range pos
5)) 'day
)
14483 ((and (> pos
(or (match-end 8) (match-end 5)))
14484 (< pos
(match-end 0)))
14485 (- pos
(or (match-end 8) (match-end 5))))
14489 (defun org-toggle-timestamp-type ()
14490 "Toggle the type (<active> or [inactive]) of a time stamp."
14492 (when (org-at-timestamp-p t
)
14493 (let ((beg (match-beginning 0)) (end (match-end 0))
14494 (map '((?\
[ .
"<") (?\
] .
">") (?
< .
"[") (?
> .
"]"))))
14497 (while (re-search-forward "[][<>]" end t
)
14498 (replace-match (cdr (assoc (char-after (match-beginning 0)) map
))
14500 (message "Timestamp is now %sactive"
14501 (if (equal (char-after beg
) ?
<) "" "in")))))
14503 (defun org-timestamp-change (n &optional what
)
14504 "Change the date in the time stamp at point.
14505 The date will be changed by N times WHAT. WHAT can be `day', `month',
14506 `year', `minute', `second'. If WHAT is not given, the cursor position
14507 in the timestamp determines what will be changed."
14508 (let ((pos (point))
14510 (dm (max (nth 1 org-time-stamp-rounding-minutes
) 1))
14514 (if (not (org-at-timestamp-p t
))
14515 (error "Not at a timestamp"))
14516 (if (and (not what
) (eq org-ts-what
'bracket
))
14517 (org-toggle-timestamp-type)
14518 (if (and (not what
) (not (eq org-ts-what
'day
))
14519 org-display-custom-times
14520 (get-text-property (point) 'display
)
14521 (not (get-text-property (1- (point)) 'display
)))
14522 (setq org-ts-what
'day
))
14523 (setq org-ts-what
(or what org-ts-what
)
14524 inactive
(= (char-after (match-beginning 0)) ?\
[)
14525 ts
(match-string 0))
14528 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
14530 (setq extra
(match-string 1 ts
)))
14531 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts
)
14533 (setq time0
(org-parse-time-string ts
))
14534 (when (and (eq org-ts-what
'minute
)
14535 (eq current-prefix-arg nil
))
14536 (setq n
(* dm
(cond ((> n
0) 1) ((< n
0) -
1) (t 0))))
14537 (when (not (= 0 (setq rem
(%
(nth 1 time0
) dm
))))
14538 (setcar (cdr time0
) (+ (nth 1 time0
)
14539 (if (> n
0) (- rem
) (- dm rem
))))))
14541 (encode-time (or (car time0
) 0)
14542 (+ (if (eq org-ts-what
'minute
) n
0) (nth 1 time0
))
14543 (+ (if (eq org-ts-what
'hour
) n
0) (nth 2 time0
))
14544 (+ (if (eq org-ts-what
'day
) n
0) (nth 3 time0
))
14545 (+ (if (eq org-ts-what
'month
) n
0) (nth 4 time0
))
14546 (+ (if (eq org-ts-what
'year
) n
0) (nth 5 time0
))
14548 (when (and (member org-ts-what
'(hour minute
))
14550 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra
))
14551 (setq extra
(org-modify-ts-extra
14553 (if (eq org-ts-what
'hour
) 2 5)
14555 (when (integerp org-ts-what
)
14556 (setq extra
(org-modify-ts-extra extra org-ts-what n dm
)))
14557 (if (eq what
'calendar
)
14558 (let ((cal-date (org-get-date-from-calendar)))
14559 (setcar (nthcdr 4 time0
) (nth 0 cal-date
)) ; month
14560 (setcar (nthcdr 3 time0
) (nth 1 cal-date
)) ; day
14561 (setcar (nthcdr 5 time0
) (nth 2 cal-date
)) ; year
14562 (setcar time0
(or (car time0
) 0))
14563 (setcar (nthcdr 1 time0
) (or (nth 1 time0
) 0))
14564 (setcar (nthcdr 2 time0
) (or (nth 2 time0
) 0))
14565 (setq time
(apply 'encode-time time0
))))
14566 (setq org-last-changed-timestamp
14567 (org-insert-time-stamp time with-hm inactive nil nil extra
))
14568 (org-clock-update-time-maybe)
14570 ;; Try to recenter the calendar window, if any
14571 (if (and org-calendar-follow-timestamp-change
14572 (get-buffer-window "*Calendar*" t
)
14573 (memq org-ts-what
'(day month year
)))
14574 (org-recenter-calendar (time-to-days time
))))))
14576 (defun org-modify-ts-extra (s pos n dm
)
14577 "Change the different parts of the lead-time and repeat fields in timestamp."
14578 (let ((idx '(("d" .
0) ("w" .
1) ("m" .
2) ("y" .
3) ("d" . -
1) ("y" .
4)))
14580 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s
)
14582 ((or (org-pos-in-match-range pos
2)
14583 (org-pos-in-match-range pos
3))
14584 (setq m
(string-to-number (match-string 3 s
))
14585 h
(string-to-number (match-string 2 s
)))
14586 (if (org-pos-in-match-range pos
2)
14588 (setq n
(* dm
(org-no-warnings (signum n
))))
14589 (when (not (= 0 (setq rem
(% m dm
))))
14590 (setq m
(+ m
(if (> n
0) (- rem
) (- dm rem
)))))
14592 (if (< m
0) (setq m
(+ m
60) h
(1- h
)))
14593 (if (> m
59) (setq m
(- m
60) h
(1+ h
)))
14594 (setq h
(min 24 (max 0 h
)))
14595 (setq ng
1 new
(format "-%02d:%02d" h m
)))
14596 ((org-pos-in-match-range pos
6)
14597 (setq ng
6 new
(car (rassoc (+ n
(cdr (assoc (match-string 6 s
) idx
))) idx
))))
14598 ((org-pos-in-match-range pos
5)
14599 (setq ng
5 new
(format "%d" (max 1 (+ n
(string-to-number (match-string 5 s
)))))))
14601 ((org-pos-in-match-range pos
9)
14602 (setq ng
9 new
(car (rassoc (+ n
(cdr (assoc (match-string 9 s
) idx
))) idx
))))
14603 ((org-pos-in-match-range pos
8)
14604 (setq ng
8 new
(format "%d" (max 0 (+ n
(string-to-number (match-string 8 s
))))))))
14608 (substring s
0 (match-beginning ng
))
14610 (substring s
(match-end ng
))))))
14613 (defun org-recenter-calendar (date)
14614 "If the calendar is visible, recenter it to DATE."
14615 (let* ((win (selected-window))
14616 (cwin (get-buffer-window "*Calendar*" t
))
14617 (calendar-move-hook nil
))
14619 (select-window cwin
)
14620 (calendar-goto-date (if (listp date
) date
14621 (calendar-gregorian-from-absolute date
)))
14622 (select-window win
))))
14624 (defun org-goto-calendar (&optional arg
)
14625 "Go to the Emacs calendar at the current date.
14626 If there is a time stamp in the current line, go to that date.
14627 A prefix ARG can be used to force the current date."
14629 (let ((tsr org-ts-regexp
) diff
14630 (calendar-move-hook nil
)
14631 (calendar-view-holidays-initially-flag nil
)
14632 (calendar-view-diary-initially-flag nil
))
14633 (if (or (org-at-timestamp-p)
14635 (beginning-of-line 1)
14636 (looking-at (concat ".*" tsr
))))
14637 (let ((d1 (time-to-days (current-time)))
14639 (org-time-string-to-time (match-string 1)))))
14640 (setq diff
(- d2 d1
))))
14642 (calendar-goto-today)
14643 (if (and diff
(not arg
)) (calendar-forward-day diff
))))
14645 (defun org-get-date-from-calendar ()
14646 "Return a list (month day year) of date at point in calendar."
14647 (with-current-buffer "*Calendar*"
14649 (calendar-cursor-to-date))))
14651 (defun org-date-from-calendar ()
14652 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
14653 If there is already a time stamp at the cursor position, update it."
14655 (if (org-at-timestamp-p t
)
14656 (org-timestamp-change 0 'calendar
)
14657 (let ((cal-date (org-get-date-from-calendar)))
14658 (org-insert-time-stamp
14659 (encode-time 0 0 0 (nth 1 cal-date
) (car cal-date
) (nth 2 cal-date
))))))
14661 (defun org-minutes-to-hh:mm-string
(m)
14662 "Compute H:MM from a number of minutes."
14663 (let ((h (/ m
60)))
14664 (setq m
(- m
(* 60 h
)))
14665 (format org-time-clocksum-format h m
)))
14667 (defun org-hh:mm-string-to-minutes
(s)
14668 "Convert a string H:MM to a number of minutes.
14669 If the string is just a number, interpret it as minutes.
14670 In fact, the first hh:mm or number in the string will be taken,
14671 there can be extra stuff in the string.
14672 If no number is found, the return value is 0."
14674 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s
)
14675 (+ (* (string-to-number (match-string 1 s
)) 60)
14676 (string-to-number (match-string 2 s
))))
14677 ((string-match "\\([0-9]+\\)" s
)
14678 (string-to-number (match-string 1 s
)))
14683 (defun org-save-all-org-buffers ()
14684 "Save all Org-mode buffers without user confirmation."
14686 (message "Saving all Org-mode buffers...")
14687 (save-some-buffers t
'org-mode-p
)
14688 (when (featurep 'org-id
) (org-id-locations-save))
14689 (message "Saving all Org-mode buffers... done"))
14691 (defun org-revert-all-org-buffers ()
14692 "Revert all Org-mode buffers.
14693 Prompt for confirmation when there are unsaved changes.
14694 Be sure you know what you are doing before letting this function
14695 overwrite your changes.
14697 This function is useful in a setup where one tracks org files
14698 with a version control system, to revert on one machine after pulling
14699 changes from another. I believe the procedure must be like this:
14701 1. M-x org-save-all-org-buffers
14702 2. Pull changes from the other machine, resolve conflicts
14703 3. M-x org-revert-all-org-buffers"
14705 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
14708 (save-window-excursion
14711 (when (and (with-current-buffer b
(org-mode-p))
14712 (with-current-buffer b buffer-file-name
))
14713 (switch-to-buffer b
)
14714 (revert-buffer t
'no-confirm
)))
14716 (when (and (featurep 'org-id
) org-id-track-globally
)
14717 (org-id-locations-load)))))
14722 (defun org-iswitchb (&optional arg
)
14723 "Use `org-icompleting-read' to prompt for an Org buffer to switch to.
14724 With a prefix argument, restrict available to files.
14725 With two prefix arguments, restrict available buffers to agenda files."
14727 (let ((blist (cond ((equal arg
'(4)) (org-buffer-list 'files
))
14728 ((equal arg
'(16)) (org-buffer-list 'agenda
))
14729 (t (org-buffer-list)))))
14731 (org-icompleting-read "Org buffer: "
14732 (mapcar 'list
(mapcar 'buffer-name blist
))
14736 (defalias 'org-ido-switchb
'org-iswitchb
)
14738 (defun org-buffer-list (&optional predicate exclude-tmp
)
14739 "Return a list of Org buffers.
14740 PREDICATE can be `export', `files' or `agenda'.
14742 export restrict the list to Export buffers.
14743 files restrict the list to buffers visiting Org files.
14744 agenda restrict the list to buffers visiting agenda files.
14746 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
14748 (agenda-files (and (eq predicate
'agenda
)
14749 (mapcar 'file-truename
(org-agenda-files t
))))
14752 ((eq predicate
'files
)
14753 (lambda (b) (with-current-buffer b
(eq major-mode
'org-mode
))))
14754 ((eq predicate
'export
)
14755 (lambda (b) (string-match "\*Org .*Export" (buffer-name b
))))
14756 ((eq predicate
'agenda
)
14758 (with-current-buffer b
14759 (and (eq major-mode
'org-mode
)
14760 (setq bfn
(buffer-file-name b
))
14761 (member (file-truename bfn
) agenda-files
)))))
14762 (t (lambda (b) (with-current-buffer b
14763 (or (eq major-mode
'org-mode
)
14764 (string-match "\*Org .*Export"
14765 (buffer-name b
)))))))))
14769 (if (and (funcall filter b
)
14770 (or (not exclude-tmp
)
14771 (not (string-match "tmp" (buffer-name b
)))))
14776 (defun org-agenda-files (&optional unrestricted archives
)
14777 "Get the list of agenda files.
14778 Optional UNRESTRICTED means return the full list even if a restriction
14779 is currently in place.
14780 When ARCHIVES is t, include all archive files that are really being
14781 used by the agenda files. If ARCHIVE is `ifmode', do this only if
14782 `org-agenda-archives-mode' is t."
14785 ((and (not unrestricted
) (get 'org-agenda-files
'org-restrict
)))
14786 ((stringp org-agenda-files
) (org-read-agenda-file-list))
14787 ((listp org-agenda-files
) org-agenda-files
)
14788 (t (error "Invalid value of `org-agenda-files'")))))
14789 (setq files
(apply 'append
14790 (mapcar (lambda (f)
14791 (if (file-directory-p f
)
14793 f t org-agenda-file-regexp
)
14796 (when org-agenda-skip-unavailable-files
14797 (setq files
(delq nil
14800 (and (file-readable-p file
) file
)))
14802 (when (or (eq archives t
)
14803 (and (eq archives
'ifmode
) (eq org-agenda-archives-mode t
)))
14804 (setq files
(org-add-archive-files files
)))
14807 (defun org-edit-agenda-file-list ()
14808 "Edit the list of agenda files.
14809 Depending on setup, this either uses customize to edit the variable
14810 `org-agenda-files', or it visits the file that is holding the list. In the
14811 latter case, the buffer is set up in a way that saving it automatically kills
14812 the buffer and restores the previous window configuration."
14814 (if (stringp org-agenda-files
)
14815 (let ((cw (current-window-configuration)))
14816 (find-file org-agenda-files
)
14817 (org-set-local 'org-window-configuration cw
)
14818 (org-add-hook 'after-save-hook
14820 (set-window-configuration
14821 (prog1 org-window-configuration
14822 (kill-buffer (current-buffer))))
14823 (org-install-agenda-files-menu)
14824 (message "New agenda file list installed"))
14826 (message "%s" (substitute-command-keys
14827 "Edit list and finish with \\[save-buffer]")))
14828 (customize-variable 'org-agenda-files
)))
14830 (defun org-store-new-agenda-file-list (list)
14831 "Set new value for the agenda file list and save it correctly."
14832 (if (stringp org-agenda-files
)
14833 (let ((fe (org-read-agenda-file-list t
)) b u
)
14834 (while (setq b
(find-buffer-visiting org-agenda-files
))
14836 (with-temp-file org-agenda-files
14839 (lambda (f) ;; Keep un-expanded entries.
14840 (if (setq u
(assoc f fe
))
14845 (let ((org-mode-hook nil
) (org-inhibit-startup t
)
14846 (org-insert-mode-line-in-empty-file nil
))
14847 (setq org-agenda-files list
)
14848 (customize-save-variable 'org-agenda-files org-agenda-files
))))
14850 (defun org-read-agenda-file-list (&optional pair-with-expansion
)
14851 "Read the list of agenda files from a file.
14852 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
14853 filenames, used by `org-store-new-agenda-file-list' to write back
14854 un-expanded file names."
14855 (when (file-directory-p org-agenda-files
)
14856 (error "`org-agenda-files' cannot be a single directory"))
14857 (when (stringp org-agenda-files
)
14859 (insert-file-contents org-agenda-files
)
14862 (let ((e (expand-file-name (substitute-in-file-name f
)
14864 (if pair-with-expansion
14867 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
14870 (defun org-cycle-agenda-files ()
14871 "Cycle through the files in `org-agenda-files'.
14872 If the current buffer visits an agenda file, find the next one in the list.
14873 If the current buffer does not, find the first agenda file."
14875 (let* ((fs (org-agenda-files t
))
14876 (files (append fs
(list (car fs
))))
14877 (tcf (if buffer-file-name
(file-truename buffer-file-name
)))
14879 (unless files
(error "No agenda files"))
14881 (while (setq file
(pop files
))
14882 (if (equal (file-truename file
) tcf
)
14884 (find-file (car files
))
14886 (find-file (car fs
)))
14887 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
14889 (defun org-agenda-file-to-front (&optional to-end
)
14890 "Move/add the current file to the top of the agenda file list.
14891 If the file is not present in the list, it is added to the front. If it is
14892 present, it is moved there. With optional argument TO-END, add/move to the
14895 (let ((org-agenda-skip-unavailable-files nil
)
14896 (file-alist (mapcar (lambda (x)
14897 (cons (file-truename x
) x
))
14898 (org-agenda-files t
)))
14899 (ctf (file-truename buffer-file-name
))
14901 (setq x
(assoc ctf file-alist
) had x
)
14903 (if (not x
) (setq x
(cons ctf
(abbreviate-file-name buffer-file-name
))))
14905 (setq file-alist
(append (delq x file-alist
) (list x
)))
14906 (setq file-alist
(cons x
(delq x file-alist
))))
14907 (org-store-new-agenda-file-list (mapcar 'cdr file-alist
))
14908 (org-install-agenda-files-menu)
14909 (message "File %s to %s of agenda file list"
14910 (if had
"moved" "added") (if to-end
"end" "front"))))
14912 (defun org-remove-file (&optional file
)
14913 "Remove current file from the list of files in variable `org-agenda-files'.
14914 These are the files which are being checked for agenda entries.
14915 Optional argument FILE means use this file instead of the current."
14917 (let* ((org-agenda-skip-unavailable-files nil
)
14918 (file (or file buffer-file-name
))
14919 (true-file (file-truename file
))
14920 (afile (abbreviate-file-name file
))
14921 (files (delq nil
(mapcar
14923 (if (equal true-file
14926 (org-agenda-files t
)))))
14927 (if (not (= (length files
) (length (org-agenda-files t
))))
14929 (org-store-new-agenda-file-list files
)
14930 (org-install-agenda-files-menu)
14931 (message "Removed file: %s" afile
))
14932 (message "File was not in list: %s (not removed)" afile
))))
14934 (defun org-file-menu-entry (file)
14935 (vector file
(list 'find-file file
) t
))
14937 (defun org-check-agenda-file (file)
14938 "Make sure FILE exists. If not, ask user what to do."
14939 (when (not (file-exists-p file
))
14940 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
14941 (abbreviate-file-name file
))
14942 (let ((r (downcase (read-char-exclusive))))
14945 (org-remove-file file
)
14946 (throw 'nextfile t
))
14947 (t (error "Abort"))))))
14949 (defun org-get-agenda-file-buffer (file)
14950 "Get a buffer visiting FILE. If the buffer needs to be created, add
14951 it to the list of buffers which might be released later."
14952 (let ((buf (org-find-base-buffer-visiting file
)))
14954 buf
; just return it
14955 ;; Make a new buffer and remember it
14956 (setq buf
(find-file-noselect file
))
14957 (if buf
(push buf org-agenda-new-buffers
))
14960 (defun org-release-buffers (blist)
14961 "Release all buffers in list, asking the user for confirmation when needed.
14962 When a buffer is unmodified, it is just killed. When modified, it is saved
14963 \(if the user agrees) and then killed."
14965 (while (setq buf
(pop blist
))
14966 (setq file
(buffer-file-name buf
))
14967 (when (and (buffer-modified-p buf
)
14969 (y-or-n-p (format "Save file %s? " file
)))
14970 (with-current-buffer buf
(save-buffer)))
14971 (kill-buffer buf
))))
14973 (defun org-prepare-agenda-buffers (files)
14974 "Create buffers for all agenda files, protect archived trees and comments."
14976 (let ((pa '(:org-archived t
))
14977 (pc '(:org-comment t
))
14978 (pall '(:org-archived t
:org-comment t
))
14979 (inhibit-read-only t
)
14980 (rea (concat ":" org-archive-tag
":"))
14984 (while (setq file
(pop files
))
14988 (org-check-agenda-file file
)
14989 (set-buffer (org-get-agenda-file-buffer file
)))
14991 (setq bmp
(buffer-modified-p))
14992 (org-refresh-category-properties)
14993 (setq org-todo-keywords-for-agenda
14994 (append org-todo-keywords-for-agenda org-todo-keywords-1
))
14995 (setq org-done-keywords-for-agenda
14996 (append org-done-keywords-for-agenda org-done-keywords
))
14997 (setq org-todo-keyword-alist-for-agenda
14998 (append org-todo-keyword-alist-for-agenda org-todo-key-alist
))
14999 (setq org-drawers-for-agenda
15000 (append org-drawers-for-agenda org-drawers
))
15001 (setq org-tag-alist-for-agenda
15002 (append org-tag-alist-for-agenda org-tag-alist
))
15005 (remove-text-properties (point-min) (point-max) pall
)
15006 (when org-agenda-skip-archived-trees
15007 (goto-char (point-min))
15008 (while (re-search-forward rea nil t
)
15009 (if (org-on-heading-p t
)
15010 (add-text-properties (point-at-bol) (org-end-of-subtree t
) pa
))))
15011 (goto-char (point-min))
15012 (setq re
(concat "^\\*+ +" org-comment-string
"\\>"))
15013 (while (re-search-forward re nil t
)
15014 (add-text-properties
15015 (match-beginning 0) (org-end-of-subtree t
) pc
)))
15016 (set-buffer-modified-p bmp
)))))
15017 (setq org-todo-keywords-for-agenda
15018 (org-uniquify org-todo-keywords-for-agenda
))
15019 (setq org-todo-keyword-alist-for-agenda
15020 (org-uniquify org-todo-keyword-alist-for-agenda
)
15021 org-tag-alist-for-agenda
(org-uniquify org-tag-alist-for-agenda
))))
15023 ;;;; Embedded LaTeX
15025 (defvar org-cdlatex-mode-map
(make-sparse-keymap)
15026 "Keymap for the minor `org-cdlatex-mode'.")
15028 (org-defkey org-cdlatex-mode-map
"_" 'org-cdlatex-underscore-caret
)
15029 (org-defkey org-cdlatex-mode-map
"^" 'org-cdlatex-underscore-caret
)
15030 (org-defkey org-cdlatex-mode-map
"`" 'cdlatex-math-symbol
)
15031 (org-defkey org-cdlatex-mode-map
"'" 'org-cdlatex-math-modify
)
15032 (org-defkey org-cdlatex-mode-map
"\C-c{" 'cdlatex-environment
)
15034 (defvar org-cdlatex-texmathp-advice-is-done nil
15035 "Flag remembering if we have applied the advice to texmathp already.")
15037 (define-minor-mode org-cdlatex-mode
15038 "Toggle the minor `org-cdlatex-mode'.
15039 This mode supports entering LaTeX environment and math in LaTeX fragments
15041 \\{org-cdlatex-mode-map}"
15043 (when org-cdlatex-mode
(require 'cdlatex
))
15044 (unless org-cdlatex-texmathp-advice-is-done
15045 (setq org-cdlatex-texmathp-advice-is-done t
)
15046 (defadvice texmathp
(around org-math-always-on activate
)
15047 "Always return t in org-mode buffers.
15048 This is because we want to insert math symbols without dollars even outside
15049 the LaTeX math segments. If Orgmode thinks that point is actually inside
15050 an embedded LaTeX fragment, let texmathp do its job.
15051 \\[org-cdlatex-mode-map]"
15055 ((not (org-mode-p)) ad-do-it
)
15056 ((eq this-command
'cdlatex-math-symbol
)
15057 (setq ad-return-value t
15058 texmathp-why
'("cdlatex-math-symbol in org-mode" .
0)))
15060 (let ((p (org-inside-LaTeX-fragment-p)))
15061 (if (and p
(member (car p
) (plist-get org-format-latex-options
:matchers
)))
15062 (setq ad-return-value t
15063 texmathp-why
'("Org-mode embedded math" .
0))
15064 (if p ad-do-it
)))))))))
15066 (defun turn-on-org-cdlatex ()
15067 "Unconditionally turn on `org-cdlatex-mode'."
15068 (org-cdlatex-mode 1))
15070 (defun org-inside-LaTeX-fragment-p ()
15071 "Test if point is inside a LaTeX fragment.
15072 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15073 sequence appearing also before point.
15074 Even though the matchers for math are configurable, this function assumes
15075 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15076 delimiters are skipped when they have been removed by customization.
15077 The return value is nil, or a cons cell with the delimiter and
15078 and the position of this delimiter.
15080 This function does a reasonably good job, but can locally be fooled by
15081 for example currency specifications. For example it will assume being in
15082 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15083 fragments that are properly closed, but during editing, we have to live
15084 with the uncertainty caused by missing closing delimiters. This function
15085 looks only before point, not after."
15087 (let ((pos (point))
15088 (dodollar (member "$" (plist-get org-format-latex-options
:matchers
)))
15090 (re-search-backward (concat "^\\(" paragraph-start
"\\)") nil t
)
15092 dd-on str
(start 0) m re
)
15095 (setq str
(concat (buffer-substring lim
(point)) "\000 X$.")
15096 re
(nth 1 (assoc "$" org-latex-regexps
)))
15097 (while (string-match re str start
)
15099 ((= (match-end 0) (length str
))
15100 (throw 'exit
(cons "$" (+ lim
(match-beginning 0) 1))))
15101 ((= (match-end 0) (- (length str
) 5))
15103 (t (setq start
(match-end 0))))))
15104 (when (setq m
(re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t
))
15106 (and (match-beginning 1) (throw 'exit
(cons (match-string 1) m
)))
15107 (and (match-beginning 2) (throw 'exit nil
))
15109 (while (re-search-backward "\\$\\$" lim t
)
15110 (setq dd-on
(not dd-on
)))
15112 (if dd-on
(cons "$$" m
))))))
15114 (defun org-inside-latex-macro-p ()
15115 "Is point inside a LaTeX macro or its arguments?"
15118 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15122 (message "%s" (org-inside-latex-macro-p)))
15124 (defun org-try-cdlatex-tab ()
15125 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15126 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15127 - inside a LaTeX fragment, or
15128 - after the first word in a line, where an abbreviation expansion could
15129 insert a LaTeX environment."
15130 (when org-cdlatex-mode
15133 (skip-chars-backward "a-zA-Z0-9*")
15134 (skip-chars-backward " \t")
15137 ((org-inside-LaTeX-fragment-p)
15141 (defun org-cdlatex-underscore-caret (&optional arg
)
15142 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15143 Revert to the normal definition outside of these fragments."
15145 (if (org-inside-LaTeX-fragment-p)
15146 (call-interactively 'cdlatex-sub-superscript
)
15147 (let (org-cdlatex-mode)
15148 (call-interactively (key-binding (vector last-input-event
))))))
15150 (defun org-cdlatex-math-modify (&optional arg
)
15151 "Execute `cdlatex-math-modify' in LaTeX fragments.
15152 Revert to the normal definition outside of these fragments."
15154 (if (org-inside-LaTeX-fragment-p)
15155 (call-interactively 'cdlatex-math-modify
)
15156 (let (org-cdlatex-mode)
15157 (call-interactively (key-binding (vector last-input-event
))))))
15159 (defvar org-latex-fragment-image-overlays nil
15160 "List of overlays carrying the images of latex fragments.")
15161 (make-variable-buffer-local 'org-latex-fragment-image-overlays
)
15163 (defun org-remove-latex-fragment-image-overlays ()
15164 "Remove all overlays with LaTeX fragment images in current buffer."
15165 (mapc 'delete-overlay org-latex-fragment-image-overlays
)
15166 (setq org-latex-fragment-image-overlays nil
))
15168 (defun org-preview-latex-fragment (&optional subtree
)
15169 "Preview the LaTeX fragment at point, or all locally or globally.
15170 If the cursor is in a LaTeX fragment, create the image and overlay
15171 it over the source code. If there is no fragment at point, display
15172 all fragments in the current text, from one headline to the next. With
15173 prefix SUBTREE, display all fragments in the current subtree. With a
15174 double prefix `C-u C-u', or when the cursor is before the first headline,
15175 display all fragments in the buffer.
15176 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15178 (org-remove-latex-fragment-image-overlays)
15181 (let (beg end at msg
)
15183 ((or (equal subtree
'(16))
15184 (not (save-excursion
15185 (re-search-backward (concat "^" outline-regexp
) nil t
))))
15186 (setq beg
(point-min) end
(point-max)
15187 msg
"Creating images for buffer...%s"))
15188 ((equal subtree
'(4))
15189 (org-back-to-heading)
15190 (setq beg
(point) end
(org-end-of-subtree t
)
15191 msg
"Creating images for subtree...%s"))
15193 (if (setq at
(org-inside-LaTeX-fragment-p))
15194 (goto-char (max (point-min) (- (cdr at
) 2)))
15195 (org-back-to-heading))
15196 (setq beg
(point) end
(progn (outline-next-heading) (point))
15197 msg
(if at
"Creating image...%s"
15198 "Creating images for entry...%s"))))
15200 (narrow-to-region beg end
)
15203 (concat "ltxpng/" (file-name-sans-extension
15204 (file-name-nondirectory
15205 buffer-file-name
)))
15206 default-directory
'overlays msg at
'forbuffer
)
15207 (message msg
"done. Use `C-c C-c' to remove images.")))))
15209 (defvar org-latex-regexps
15210 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t
)
15211 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15212 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15213 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
15214 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil
)
15215 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil
)
15216 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil
)
15217 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil
))
15218 "Regular expressions for matching embedded LaTeX.")
15220 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer
)
15221 "Replace LaTeX fragments with links to an image, and produce images.
15222 Some of the options can be changed using the variable
15223 `org-format-latex-options'."
15224 (if (and overlays
(fboundp 'clear-image-cache
)) (clear-image-cache))
15225 (let* ((prefixnodir (file-name-nondirectory prefix
))
15226 (absprefix (expand-file-name prefix dir
))
15227 (todir (file-name-directory absprefix
))
15228 (opt org-format-latex-options
)
15229 (matchers (plist-get opt
:matchers
))
15230 (re-list org-latex-regexps
)
15231 (org-format-latex-header-extra
15232 (plist-get (org-infile-export-plist) :latex-header-extra
))
15233 (cnt 0) txt hash link beg end re e checkdir
15234 executables-checked
15235 m n block linkfile movefile ov
)
15236 ;; Check the different regular expressions
15237 (while (setq e
(pop re-list
))
15238 (setq m
(car e
) re
(nth 1 e
) n
(nth 2 e
)
15239 block
(if (nth 3 e
) "\n\n" ""))
15240 (when (member m matchers
)
15241 (goto-char (point-min))
15242 (while (re-search-forward re nil t
)
15243 (when (and (or (not at
) (equal (cdr at
) (match-beginning n
)))
15244 (not (get-text-property (match-beginning n
)
15247 (not (eq (get-char-property (match-beginning n
)
15249 'org-latex-overlay
))))
15250 (setq txt
(match-string n
)
15251 beg
(match-beginning n
) end
(match-end n
)
15253 (let (print-length print-level
) ; make sure full list is printed
15254 (setq hash
(sha1 (prin1-to-string
15255 (list org-format-latex-header
15256 org-format-latex-header-extra
15257 org-export-latex-default-packages-alist
15258 org-export-latex-packages-alist
15259 org-format-latex-options
15261 linkfile
(format "%s_%s.png" prefix hash
)
15262 movefile
(format "%s_%s.png" absprefix hash
)))
15263 (setq link
(concat block
"[[file:" linkfile
"]]" block
))
15264 (if msg
(message msg cnt
))
15266 (unless checkdir
; make sure the directory exists
15268 (or (file-directory-p todir
) (make-directory todir
)))
15270 (unless executables-checked
15271 (org-check-external-command
15272 "latex" "needed to convert LaTeX fragments to images")
15273 (org-check-external-command
15274 "dvipng" "needed to convert LaTeX fragments to images")
15275 (setq executables-checked t
))
15277 (unless (file-exists-p movefile
)
15278 (org-create-formula-image
15279 txt movefile opt forbuffer
))
15283 (if (eq (overlay-get o
'org-overlay-type
)
15284 'org-latex-overlay
)
15285 (delete-overlay o
)))
15286 (org-overlays-in beg end
))
15287 (setq ov
(make-overlay beg end
))
15288 (overlay-put ov
'org-overlay-type
'org-latex-overlay
)
15289 (if (featurep 'xemacs
)
15291 (overlay-put ov
'invisible t
)
15294 (make-glyph (vector 'png
:file movefile
))))
15297 (list 'image
:type
'png
:file movefile
:ascent
'center
)))
15298 (push ov org-latex-fragment-image-overlays
)
15300 (delete-region beg end
)
15301 (insert (org-add-props link
15302 (list 'org-latex-src
15303 (replace-regexp-in-string "\"" "" txt
)))))))))))
15305 ;; This function borrows from Ganesh Swami's latex2png.el
15306 (defun org-create-formula-image (string tofile options buffer
)
15307 "This calls dvipng."
15308 (require 'org-latex
)
15309 (let* ((tmpdir (if (featurep 'xemacs
)
15311 temporary-file-directory
))
15312 (texfilebase (make-temp-name
15313 (expand-file-name "orgtex" tmpdir
)))
15314 (texfile (concat texfilebase
".tex"))
15315 (dvifile (concat texfilebase
".dvi"))
15316 (pngfile (concat texfilebase
".png"))
15317 (fnh (if (featurep 'xemacs
)
15318 (font-height (get-face-font 'default
))
15319 (face-attribute 'default
:height nil
)))
15320 (scale (or (plist-get options
(if buffer
:scale
:html-scale
)) 1.0))
15321 (dpi (number-to-string (* scale
(floor (* 0.9 (if buffer fnh
140.
))))))
15322 (fg (or (plist-get options
(if buffer
:foreground
:html-foreground
))
15324 (bg (or (plist-get options
(if buffer
:background
:html-background
))
15326 (if (eq fg
'default
) (setq fg
(org-dvipng-color :foreground
)))
15327 (if (eq bg
'default
) (setq bg
(org-dvipng-color :background
)))
15328 (with-temp-file texfile
15329 (insert (org-splice-latex-header
15330 org-format-latex-header
15331 org-export-latex-default-packages-alist
15332 org-export-latex-packages-alist
15333 org-format-latex-header-extra
))
15334 (insert "\n\\begin{document}\n" string
"\n\\end{document}\n")
15335 (require 'org-latex
)
15336 (org-export-latex-fix-inputenc))
15337 (let ((dir default-directory
))
15338 (condition-case nil
15341 (call-process "latex" nil nil nil texfile
))
15344 (if (not (file-exists-p dvifile
))
15345 (progn (message "Failed to create dvi file from %s" texfile
) nil
)
15346 (condition-case nil
15347 (call-process "dvipng" nil nil nil
15350 ;;"-x" scale "-y" scale
15355 (if (not (file-exists-p pngfile
))
15356 (if org-format-latex-signal-error
15357 (error "Failed to create png file from %s" texfile
)
15358 (message "Failed to create png file from %s" texfile
)
15360 ;; Use the requested file name and clean up
15361 (copy-file pngfile tofile
'replace
)
15362 (loop for e in
'(".dvi" ".tex" ".aux" ".log" ".png") do
15363 (delete-file (concat texfilebase e
)))
15366 (defun org-splice-latex-header (tpl def-pkg pkg
&optional extra
)
15367 "Fill a LaTeX header template TPL.
15368 In the template, the following place holders will be recognized:
15370 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15371 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15372 [PACKAGES] \\usepackage statements for PKG
15373 [NO-PACKAGES] do not include PKG
15374 [EXTRA] the string EXTRA
15375 [NO-EXTRA] do not include EXTRA
15377 For backward compatibility, if both the positive and the negative place
15378 holder is missing, the positive one (without the \"NO-\") will be
15379 assumed to be present at the end of the template.
15380 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15381 EXTRA is a string."
15382 (let (rpl (end ""))
15383 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl
)
15384 (setq rpl
(if (or (match-end 1) (not def-pkg
))
15385 "" (org-latex-packages-to-string def-pkg t
))
15386 tpl
(replace-match rpl t t tpl
))
15387 (if def-pkg
(setq end
(org-latex-packages-to-string def-pkg
))))
15389 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl
)
15390 (setq rpl
(if (or (match-end 1) (not pkg
))
15391 "" (org-latex-packages-to-string pkg t
))
15392 tpl
(replace-match rpl t t tpl
))
15393 (if pkg
(setq end
(concat end
"\n" (org-latex-packages-to-string pkg
)))))
15395 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl
)
15396 (setq rpl
(if (or (match-end 1) (not extra
))
15397 "" (concat extra
"\n"))
15398 tpl
(replace-match rpl t t tpl
))
15399 (if (and extra
(string-match "\\S-" extra
))
15400 (setq end
(concat end
"\n" extra
))))
15402 (if (string-match "\\S-" end
)
15403 (concat tpl
"\n" end
)
15406 (defun org-latex-packages-to-string (pkg &optional newline
)
15407 "Turn an alist of packages into a string with the \\usepackage macros."
15408 (setq pkg
(mapconcat (lambda(p)
15411 ((equal "" (car p
))
15412 (format "\\usepackage{%s}" (cadr p
)))
15414 (format "\\usepackage[%s]{%s}"
15415 (car p
) (cadr p
)))))
15418 (if newline
(concat pkg
"\n") pkg
))
15420 (defun org-dvipng-color (attr)
15421 "Return an rgb color specification for dvipng."
15422 (apply 'format
"rgb %s %s %s"
15423 (mapcar 'org-normalize-color
15424 (color-values (face-attribute 'default attr nil
)))))
15426 (defun org-normalize-color (value)
15427 "Return string to be used as color value for an RGB component."
15428 (format "%g" (/ value
65535.0)))
15432 ;; Make `C-c C-x' a prefix key
15433 (org-defkey org-mode-map
"\C-c\C-x" (make-sparse-keymap))
15435 ;; TAB key with modifiers
15436 (org-defkey org-mode-map
"\C-i" 'org-cycle
)
15437 (org-defkey org-mode-map
[(tab)] 'org-cycle
)
15438 (org-defkey org-mode-map
[(control tab
)] 'org-force-cycle-archived
)
15439 (org-defkey org-mode-map
[(meta tab
)] 'org-complete
)
15440 (org-defkey org-mode-map
"\M-\t" 'org-complete
)
15441 (org-defkey org-mode-map
"\M-\C-i" 'org-complete
)
15442 ;; The following line is necessary under Suse GNU/Linux
15443 (unless (featurep 'xemacs
)
15444 (org-defkey org-mode-map
[S-iso-lefttab
] 'org-shifttab
))
15445 (org-defkey org-mode-map
[(shift tab
)] 'org-shifttab
)
15446 (define-key org-mode-map
[backtab] 'org-shifttab)
15448 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
15449 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
15450 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
15452 ;; Cursor keys with modifiers
15453 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
15454 (org-defkey org-mode-map [(meta right)] 'org-metaright)
15455 (org-defkey org-mode-map [(meta up)] 'org-metaup)
15456 (org-defkey org-mode-map [(meta down)] 'org-metadown)
15458 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
15459 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
15460 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
15461 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
15463 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
15464 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
15465 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
15466 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
15468 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
15469 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
15471 ;;; Extra keys for tty access.
15472 ;; We only set them when really needed because otherwise the
15473 ;; menus don't show the simple keys
15475 (when (or org-use-extra-keys
15476 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
15477 (not window-system))
15478 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
15479 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
15480 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
15481 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
15482 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
15483 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
15484 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
15485 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
15486 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
15487 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
15488 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
15489 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
15490 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
15491 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
15492 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
15493 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
15494 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
15495 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
15496 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
15497 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
15498 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
15499 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
15500 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
15501 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
15502 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
15503 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
15504 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
15505 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
15507 ;; All the other keys
15509 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
15510 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
15511 (if (boundp 'narrow-map)
15512 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
15513 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
15514 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
15515 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
15516 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
15517 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
15518 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
15519 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
15520 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
15521 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
15522 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
15523 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
15524 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
15525 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
15526 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
15527 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
15528 (org-defkey org-mode-map "\C-c\C-v" 'org-show-todo-tree)
15529 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
15530 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
15531 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
15532 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
15533 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
15534 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
15535 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
15536 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
15537 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
15538 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
15539 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
15540 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
15541 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
15542 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
15543 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
15544 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
15545 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
15546 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
15547 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
15548 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
15549 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
15550 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
15551 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
15552 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
15553 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
15554 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
15555 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
15556 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
15557 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
15558 (org-defkey org-mode-map "\C-c^" 'org-sort)
15559 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
15560 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
15561 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
15562 (org-defkey org-mode-map "\C-m" 'org-return)
15563 (org-defkey org-mode-map "\C-j" 'org-return-indent)
15564 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
15565 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
15566 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
15567 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
15568 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
15569 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
15570 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
15571 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
15572 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
15573 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
15574 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
15575 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
15576 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
15577 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
15578 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
15579 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
15580 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
15581 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
15582 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
15583 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
15585 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
15586 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
15587 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
15588 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
15590 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
15591 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
15592 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
15593 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
15594 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
15595 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
15596 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
15597 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
15598 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
15599 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
15600 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
15601 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
15602 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
15603 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
15604 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
15606 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
15607 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
15608 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
15609 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
15611 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
15613 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
15615 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
15616 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
15618 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
15621 (when (featurep 'xemacs)
15622 (org-defkey org-mode-map 'button3 'popup-mode-menu))
15625 (defconst org-speed-commands-default
15627 ("Outline Navigation")
15628 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
15629 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
15630 ("f" . (org-speed-move-safe 'org-forward-same-level))
15631 ("b" . (org-speed-move-safe 'org-backward-same-level))
15632 ("u" . (org-speed-move-safe 'outline-up-heading))
15634 ("g" . (org-refile t))
15635 ("Outline Visibility")
15637 ("C" . org-shifttab)
15638 (" " . org-display-outline-path)
15639 ("Outline Structure Editing")
15640 ("U" . org-shiftmetaup)
15641 ("D" . org-shiftmetadown)
15642 ("r" . org-metaright)
15643 ("l" . org-metaleft)
15644 ("R" . org-shiftmetaright)
15645 ("L" . org-shiftmetaleft)
15646 ("i" . (progn (forward-char 1) (call-interactively
15647 'org-insert-heading-respect-content)))
15650 ("a" . org-archive-subtree-default-with-confirmation)
15651 ("." . outline-mark-subtree)
15653 ("I" . org-clock-in)
15654 ("O" . org-clock-out)
15655 ("Meta Data Editing")
15657 ("0" . (org-priority ?\ ))
15658 ("1" . (org-priority ?A))
15659 ("2" . (org-priority ?B))
15660 ("3" . (org-priority ?C))
15661 (";" . org-set-tags-command)
15662 ("e" . org-set-effort)
15663 ("Agenda Views etc")
15665 ("/" . org-sparse-tree)
15667 ("o" . org-open-at-point)
15668 ("?" . org-speed-command-help)
15670 "The default speed commands.")
15672 (defun org-print-speed-command (e)
15673 (if (> (length (car e)) 1)
15678 (princ (make-string (length (car e)) ?-))
15682 (if (symbolp (cdr e))
15683 (princ (symbol-name (cdr e)))
15687 (defun org-speed-command-help ()
15688 "Show the available speed commands."
15690 (if (not org-use-speed-commands)
15691 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
15692 (with-output-to-temp-buffer "*Help*"
15693 (princ "User-defined Speed commands\n===========================\n")
15694 (mapc 'org-print-speed-command org-speed-commands-user)
15696 (princ "Built-in Speed commands\n=======================\n")
15697 (mapc 'org-print-speed-command org-speed-commands-default))
15698 (with-current-buffer "*Help*"
15699 (setq truncate-lines t))))
15701 (defun org-speed-move-safe (cmd)
15702 "Execute CMD, but make sure that the cursor always ends up in a headline.
15703 If not, return to the original position and throw an error."
15705 (let ((pos (point)))
15706 (call-interactively cmd)
15707 (unless (and (bolp) (org-on-heading-p))
15709 (error "Boundary reached while executing %s" cmd))))
15711 (defvar org-self-insert-command-undo-counter 0)
15713 (defvar org-table-auto-blank-field) ; defined in org-table.el
15714 (defvar org-speed-command nil)
15715 (defun org-self-insert-command (N)
15716 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
15717 If the cursor is in a table looking at whitespace, the whitespace is
15718 overwritten, and the table is not marked as requiring realignment."
15721 ((and org-use-speed-commands
15722 (or (and (bolp) (looking-at outline-regexp))
15723 (and (functionp org-use-speed-commands)
15724 (funcall org-use-speed-commands)))
15727 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
15728 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
15730 ((commandp org-speed-command)
15731 (setq this-command org-speed-command)
15732 (call-interactively org-speed-command))
15733 ((functionp org-speed-command)
15734 (funcall org-speed-command))
15735 ((and org-speed-command (listp org-speed-command))
15736 (eval org-speed-command))
15737 (t (let (org-use-speed-commands)
15738 (call-interactively 'org-self-insert-command)))))
15742 ;; check if we blank the field, and if that triggers align
15743 (and (featurep 'org-table) org-table-auto-blank-field
15744 (member last-command
15745 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
15746 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
15747 ;; got extra space, this field does not determine column width
15748 (let (org-table-may-need-update) (org-table-blank-field))
15749 ;; no extra space, this field may determine column width
15750 (org-table-blank-field)))
15753 (looking-at "[^|\n]* |"))
15754 (let (org-table-may-need-update)
15755 (goto-char (1- (match-end 0)))
15756 (delete-backward-char 1)
15757 (goto-char (match-beginning 0))
15758 (self-insert-command N)))
15760 (setq org-table-may-need-update t)
15761 (self-insert-command N)
15762 (org-fix-tags-on-the-fly)
15763 (if org-self-insert-cluster-for-undo
15764 (if (not (eq last-command 'org-self-insert-command))
15765 (setq org-self-insert-command-undo-counter 1)
15766 (if (>= org-self-insert-command-undo-counter 20)
15767 (setq org-self-insert-command-undo-counter 1)
15768 (and (> org-self-insert-command-undo-counter 0)
15770 (not (cadr buffer-undo-list)) ; remove nil entry
15771 (setcdr buffer-undo-list (cddr buffer-undo-list)))
15772 (setq org-self-insert-command-undo-counter
15773 (1+ org-self-insert-command-undo-counter))))))))
15775 (defun org-fix-tags-on-the-fly ()
15776 (when (and (equal (char-after (point-at-bol)) ?*)
15777 (org-on-heading-p))
15778 (org-align-tags-here org-tags-column)))
15780 (defun org-delete-backward-char (N)
15781 "Like `delete-backward-char', insert whitespace at field end in tables.
15782 When deleting backwards, in tables this function will insert whitespace in
15783 front of the next \"|\" separator, to keep the table aligned. The table will
15784 still be marked for re-alignment if the field did fill the entire column,
15785 because, in this case the deletion might narrow the column."
15787 (if (and (org-table-p)
15789 (string-match "|" (buffer-substring (point-at-bol) (point)))
15790 (looking-at ".*?|"))
15791 (let ((pos (point))
15792 (noalign (looking-at "[^|\n\r]* |"))
15793 (c org-table-may-need-update))
15794 (backward-delete-char N)
15795 (skip-chars-forward "^|")
15797 (goto-char (1- pos))
15798 ;; noalign: if there were two spaces at the end, this field
15799 ;; does not determine the width of the column.
15800 (if noalign (setq org-table-may-need-update c)))
15801 (backward-delete-char N)
15802 (org-fix-tags-on-the-fly)))
15804 (defun org-delete-char (N)
15805 "Like `delete-char', but insert whitespace at field end in tables.
15806 When deleting characters, in tables this function will insert whitespace in
15807 front of the next \"|\" separator, to keep the table aligned. The table will
15808 still be marked for re-alignment if the field did fill the entire column,
15809 because, in this case the deletion might narrow the column."
15811 (if (and (org-table-p)
15813 (not (= (char-after) ?|))
15815 (if (looking-at ".*?|")
15816 (let ((pos (point))
15817 (noalign (looking-at "[^|\n\r]* |"))
15818 (c org-table-may-need-update))
15819 (replace-match (concat
15820 (substring (match-string 0) 1 -1)
15823 ;; noalign: if there were two spaces at the end, this field
15824 ;; does not determine the width of the column.
15825 (if noalign (setq org-table-may-need-update c)))
15828 (org-fix-tags-on-the-fly)))
15830 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
15831 (put 'org-self-insert-command 'delete-selection t)
15832 (put 'orgtbl-self-insert-command 'delete-selection t)
15833 (put 'org-delete-char 'delete-selection 'supersede)
15834 (put 'org-delete-backward-char 'delete-selection 'supersede)
15835 (put 'org-yank 'delete-selection 'yank)
15837 ;; Make `flyspell-mode' delay after some commands
15838 (put 'org-self-insert-command 'flyspell-delayed t)
15839 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
15840 (put 'org-delete-char 'flyspell-delayed t)
15841 (put 'org-delete-backward-char 'flyspell-delayed t)
15843 ;; Make pabbrev-mode expand after org-mode commands
15844 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
15845 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
15847 ;; How to do this: Measure non-white length of current string
15848 ;; If equal to column width, we should realign.
15850 (defun org-remap (map &rest commands)
15851 "In MAP, remap the functions given in COMMANDS.
15852 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
15855 (setq old (pop commands) new (pop commands))
15856 (if (fboundp 'command-remapping)
15857 (org-defkey map (vector 'remap old) new)
15858 (substitute-key-definition old new map global-map)))))
15860 (when (eq org-enable-table-editor 'optimized)
15861 ;; If the user wants maximum table support, we need to hijack
15862 ;; some standard editing functions
15863 (org-remap org-mode-map
15864 'self-insert-command 'org-self-insert-command
15865 'delete-char 'org-delete-char
15866 'delete-backward-char 'org-delete-backward-char)
15867 (org-defkey org-mode-map "|" 'org-force-self-insert))
15869 (defvar org-ctrl-c-ctrl-c-hook nil
15870 "Hook for functions attaching themselves to `C-c C-c'.
15871 This can be used to add additional functionality to the C-c C-c key which
15872 executes context-dependent commands.
15873 Each function will be called with no arguments. The function must check
15874 if the context is appropriate for it to act. If yes, it should do its
15875 thing and then return a non-nil value. If the context is wrong,
15876 just do nothing and return nil.")
15878 (defvar org-tab-first-hook nil
15879 "Hook for functions to attach themselves to TAB.
15880 See `org-ctrl-c-ctrl-c-hook' for more information.
15881 This hook runs as the first action when TAB is pressed, even before
15882 `org-cycle' messes around with the `outline-regexp' to cater for
15883 inline tasks and plain list item folding.
15884 If any function in this hook returns t, not other actions like table
15885 field motion visibility cycling will be done.")
15887 (defvar org-tab-after-check-for-table-hook nil
15888 "Hook for functions to attach themselves to TAB.
15889 See `org-ctrl-c-ctrl-c-hook' for more information.
15890 This hook runs after it has been established that the cursor is not in a
15891 table, but before checking if the cursor is in a headline or if global cycling
15893 If any function in this hook returns t, not other actions like visibility
15894 cycling will be done.")
15896 (defvar org-tab-after-check-for-cycling-hook nil
15897 "Hook for functions to attach themselves to TAB.
15898 See `org-ctrl-c-ctrl-c-hook' for more information.
15899 This hook runs after it has been established that not table field motion and
15900 not visibility should be done because of current context. This is probably
15901 the place where a package like yasnippets can hook in.")
15903 (defvar org-tab-before-tab-emulation-hook nil
15904 "Hook for functions to attach themselves to TAB.
15905 See `org-ctrl-c-ctrl-c-hook' for more information.
15906 This hook runs after every other options for TAB have been exhausted, but
15907 before indentation and \t insertion takes place.")
15909 (defvar org-metaleft-hook nil
15910 "Hook for functions attaching themselves to `M-left'.
15911 See `org-ctrl-c-ctrl-c-hook' for more information.")
15912 (defvar org-metaright-hook nil
15913 "Hook for functions attaching themselves to `M-right'.
15914 See `org-ctrl-c-ctrl-c-hook' for more information.")
15915 (defvar org-metaup-hook nil
15916 "Hook for functions attaching themselves to `M-up'.
15917 See `org-ctrl-c-ctrl-c-hook' for more information.")
15918 (defvar org-metadown-hook nil
15919 "Hook for functions attaching themselves to `M-down'.
15920 See `org-ctrl-c-ctrl-c-hook' for more information.")
15921 (defvar org-shiftmetaleft-hook nil
15922 "Hook for functions attaching themselves to `M-S-left'.
15923 See `org-ctrl-c-ctrl-c-hook' for more information.")
15924 (defvar org-shiftmetaright-hook nil
15925 "Hook for functions attaching themselves to `M-S-right'.
15926 See `org-ctrl-c-ctrl-c-hook' for more information.")
15927 (defvar org-shiftmetaup-hook nil
15928 "Hook for functions attaching themselves to `M-S-up'.
15929 See `org-ctrl-c-ctrl-c-hook' for more information.")
15930 (defvar org-shiftmetadown-hook nil
15931 "Hook for functions attaching themselves to `M-S-down'.
15932 See `org-ctrl-c-ctrl-c-hook' for more information.")
15933 (defvar org-metareturn-hook nil
15934 "Hook for functions attaching themselves to `M-RET'.
15935 See `org-ctrl-c-ctrl-c-hook' for more information.")
15937 (defun org-modifier-cursor-error ()
15938 "Throw an error, a modified cursor command was applied in wrong context."
15939 (error "This command is active in special context like tables, headlines or items"))
15941 (defun org-shiftselect-error ()
15942 "Throw an error because Shift-Cursor command was applied in wrong context."
15943 (if (and (boundp 'shift-select-mode) shift-select-mode)
15944 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
15945 (error "This command works only in special context like headlines or timestamps")))
15947 (defun org-call-for-shift-select (cmd)
15948 (let ((this-command-keys-shift-translated t))
15949 (call-interactively cmd)))
15951 (defun org-shifttab (&optional arg)
15952 "Global visibility cycling or move to previous table field.
15953 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
15955 See the individual commands for more information."
15958 ((org-at-table-p) (call-interactively 'org-table-previous-field))
15960 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
15961 (message "Content view to level: %d" arg)
15962 (org-content (prefix-numeric-value arg2))
15963 (setq org-cycle-global-status 'overview)))
15964 (t (call-interactively 'org-global-cycle))))
15966 (defun org-shiftmetaleft ()
15967 "Promote subtree or delete table column.
15968 Calls `org-promote-subtree', `org-outdent-item',
15969 or `org-table-delete-column', depending on context.
15970 See the individual commands for more information."
15973 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
15974 ((org-at-table-p) (call-interactively 'org-table-delete-column))
15975 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
15976 ((org-at-item-p) (call-interactively 'org-outdent-item))
15977 (t (org-modifier-cursor-error))))
15979 (defun org-shiftmetaright ()
15980 "Demote subtree or insert table column.
15981 Calls `org-demote-subtree', `org-indent-item',
15982 or `org-table-insert-column', depending on context.
15983 See the individual commands for more information."
15986 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
15987 ((org-at-table-p) (call-interactively 'org-table-insert-column))
15988 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
15989 ((org-at-item-p) (call-interactively 'org-indent-item))
15990 (t (org-modifier-cursor-error))))
15992 (defun org-shiftmetaup (&optional arg)
15993 "Move subtree up or kill table row.
15994 Calls `org-move-subtree-up' or `org-table-kill-row' or
15995 `org-move-item-up' depending on context. See the individual commands
15996 for more information."
15999 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16000 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16001 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16002 ((org-at-item-p) (call-interactively 'org-move-item-up))
16003 (t (org-modifier-cursor-error))))
16005 (defun org-shiftmetadown (&optional arg)
16006 "Move subtree down or insert table row.
16007 Calls `org-move-subtree-down' or `org-table-insert-row' or
16008 `org-move-item-down', depending on context. See the individual
16009 commands for more information."
16012 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16013 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16014 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16015 ((org-at-item-p) (call-interactively 'org-move-item-down))
16016 (t (org-modifier-cursor-error))))
16018 (defun org-metaleft (&optional arg)
16019 "Promote heading or move table column to left.
16020 Calls `org-do-promote' or `org-table-move-column', depending on context.
16021 With no specific context, calls the Emacs default `backward-word'.
16022 See the individual commands for more information."
16025 ((run-hook-with-args-until-success 'org-metaleft-hook))
16026 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16027 ((or (org-on-heading-p)
16028 (and (org-region-active-p)
16030 (goto-char (region-beginning))
16031 (org-on-heading-p))))
16032 (call-interactively 'org-do-promote))
16033 ((or (org-at-item-p)
16034 (and (org-region-active-p)
16036 (goto-char (region-beginning))
16038 (call-interactively 'org-outdent-item))
16039 (t (call-interactively 'backward-word))))
16041 (defun org-metaright (&optional arg)
16042 "Demote subtree or move table column to right.
16043 Calls `org-do-demote' or `org-table-move-column', depending on context.
16044 With no specific context, calls the Emacs default `forward-word'.
16045 See the individual commands for more information."
16048 ((run-hook-with-args-until-success 'org-metaright-hook))
16049 ((org-at-table-p) (call-interactively 'org-table-move-column))
16050 ((or (org-on-heading-p)
16051 (and (org-region-active-p)
16053 (goto-char (region-beginning))
16054 (org-on-heading-p))))
16055 (call-interactively 'org-do-demote))
16056 ((or (org-at-item-p)
16057 (and (org-region-active-p)
16059 (goto-char (region-beginning))
16061 (call-interactively 'org-indent-item))
16062 (t (call-interactively 'forward-word))))
16064 (defun org-metaup (&optional arg)
16065 "Move subtree up or move table row up.
16066 Calls `org-move-subtree-up' or `org-table-move-row' or
16067 `org-move-item-up', depending on context. See the individual commands
16068 for more information."
16071 ((run-hook-with-args-until-success 'org-metaup-hook))
16072 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16073 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16074 ((org-at-item-p) (call-interactively 'org-move-item-up))
16075 (t (transpose-lines 1) (beginning-of-line -1))))
16077 (defun org-metadown (&optional arg)
16078 "Move subtree down or move table row down.
16079 Calls `org-move-subtree-down' or `org-table-move-row' or
16080 `org-move-item-down', depending on context. See the individual
16081 commands for more information."
16084 ((run-hook-with-args-until-success 'org-metadown-hook))
16085 ((org-at-table-p) (call-interactively 'org-table-move-row))
16086 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16087 ((org-at-item-p) (call-interactively 'org-move-item-down))
16088 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16090 (defun org-shiftup (&optional arg)
16091 "Increase item in timestamp or increase priority of current headline.
16092 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16093 depending on context. See the individual commands for more information."
16096 ((and org-support-shift-select (org-region-active-p))
16097 (org-call-for-shift-select 'previous-line))
16098 ((org-at-timestamp-p t)
16099 (call-interactively (if org-edit-timestamp-down-means-later
16100 'org-timestamp-down 'org-timestamp-up)))
16101 ((and (not (eq org-support-shift-select 'always))
16102 org-enable-priority-commands
16103 (org-on-heading-p))
16104 (call-interactively 'org-priority-up))
16105 ((and (not org-support-shift-select) (org-at-item-p))
16106 (call-interactively 'org-previous-item))
16107 ((org-clocktable-try-shift 'up arg))
16108 (org-support-shift-select
16109 (org-call-for-shift-select 'previous-line))
16110 (t (org-shiftselect-error))))
16112 (defun org-shiftdown (&optional arg)
16113 "Decrease item in timestamp or decrease priority of current headline.
16114 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16115 depending on context. See the individual commands for more information."
16118 ((and org-support-shift-select (org-region-active-p))
16119 (org-call-for-shift-select 'next-line))
16120 ((org-at-timestamp-p t)
16121 (call-interactively (if org-edit-timestamp-down-means-later
16122 'org-timestamp-up 'org-timestamp-down)))
16123 ((and (not (eq org-support-shift-select 'always))
16124 org-enable-priority-commands
16125 (org-on-heading-p))
16126 (call-interactively 'org-priority-down))
16127 ((and (not org-support-shift-select) (org-at-item-p))
16128 (call-interactively 'org-next-item))
16129 ((org-clocktable-try-shift 'down arg))
16130 (org-support-shift-select
16131 (org-call-for-shift-select 'next-line))
16132 (t (org-shiftselect-error))))
16134 (defun org-shiftright (&optional arg)
16135 "Cycle the thing at point or in the current line, depending on context.
16136 Depending on context, this does one of the following:
16138 - switch a timestamp at point one day into the future
16139 - on a headline, switch to the next TODO keyword.
16140 - on an item, switch entire list to the next bullet type
16141 - on a property line, switch to the next allowed value
16142 - on a clocktable definition line, move time block into the future"
16145 ((and org-support-shift-select (org-region-active-p))
16146 (org-call-for-shift-select 'forward-char))
16147 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16148 ((and (not (eq org-support-shift-select 'always))
16149 (org-on-heading-p))
16150 (let ((org-inhibit-logging
16151 (not org-treat-S-cursor-todo-selection-as-state-change))
16152 (org-inhibit-blocking
16153 (not org-treat-S-cursor-todo-selection-as-state-change)))
16154 (org-call-with-arg 'org-todo 'right)))
16155 ((or (and org-support-shift-select
16156 (not (eq org-support-shift-select 'always))
16157 (org-at-item-bullet-p))
16158 (and (not org-support-shift-select) (org-at-item-p)))
16159 (org-call-with-arg 'org-cycle-list-bullet nil))
16160 ((and (not (eq org-support-shift-select 'always))
16161 (org-at-property-p))
16162 (call-interactively 'org-property-next-allowed-value))
16163 ((org-clocktable-try-shift 'right arg))
16164 (org-support-shift-select
16165 (org-call-for-shift-select 'forward-char))
16166 (t (org-shiftselect-error))))
16168 (defun org-shiftleft (&optional arg)
16169 "Cycle the thing at point or in the current line, depending on context.
16170 Depending on context, this does one of the following:
16172 - switch a timestamp at point one day into the past
16173 - on a headline, switch to the previous TODO keyword.
16174 - on an item, switch entire list to the previous bullet type
16175 - on a property line, switch to the previous allowed value
16176 - on a clocktable definition line, move time block into the past"
16179 ((and org-support-shift-select (org-region-active-p))
16180 (org-call-for-shift-select 'backward-char))
16181 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16182 ((and (not (eq org-support-shift-select 'always))
16183 (org-on-heading-p))
16184 (let ((org-inhibit-logging
16185 (not org-treat-S-cursor-todo-selection-as-state-change))
16186 (org-inhibit-blocking
16187 (not org-treat-S-cursor-todo-selection-as-state-change)))
16188 (org-call-with-arg 'org-todo 'left)))
16189 ((or (and org-support-shift-select
16190 (not (eq org-support-shift-select 'always))
16191 (org-at-item-bullet-p))
16192 (and (not org-support-shift-select) (org-at-item-p)))
16193 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16194 ((and (not (eq org-support-shift-select 'always))
16195 (org-at-property-p))
16196 (call-interactively 'org-property-previous-allowed-value))
16197 ((org-clocktable-try-shift 'left arg))
16198 (org-support-shift-select
16199 (org-call-for-shift-select 'backward-char))
16200 (t (org-shiftselect-error))))
16202 (defun org-shiftcontrolright ()
16203 "Switch to next TODO set."
16206 ((and org-support-shift-select (org-region-active-p))
16207 (org-call-for-shift-select 'forward-word))
16208 ((and (not (eq org-support-shift-select 'always))
16209 (org-on-heading-p))
16210 (org-call-with-arg 'org-todo 'nextset))
16211 (org-support-shift-select
16212 (org-call-for-shift-select 'forward-word))
16213 (t (org-shiftselect-error))))
16215 (defun org-shiftcontrolleft ()
16216 "Switch to previous TODO set."
16219 ((and org-support-shift-select (org-region-active-p))
16220 (org-call-for-shift-select 'backward-word))
16221 ((and (not (eq org-support-shift-select 'always))
16222 (org-on-heading-p))
16223 (org-call-with-arg 'org-todo 'previousset))
16224 (org-support-shift-select
16225 (org-call-for-shift-select 'backward-word))
16226 (t (org-shiftselect-error))))
16228 (defun org-ctrl-c-ret ()
16229 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16232 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16233 (t (call-interactively 'org-insert-heading))))
16235 (defun org-copy-special ()
16236 "Copy region in table or copy current subtree.
16237 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16238 See the individual commands for more information."
16240 (call-interactively
16241 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16243 (defun org-cut-special ()
16244 "Cut region in table or cut current subtree.
16245 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16246 See the individual commands for more information."
16248 (call-interactively
16249 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16251 (defun org-paste-special (arg)
16252 "Paste rectangular region into table, or past subtree relative to level.
16253 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16254 See the individual commands for more information."
16256 (if (org-at-table-p)
16257 (org-table-paste-rectangle)
16258 (org-paste-subtree arg)))
16260 (defun org-edit-special ()
16261 "Call a special editor for the stuff at point.
16262 When at a table, call the formula editor with `org-table-edit-formulas'.
16263 When at the first line of an src example, call `org-edit-src-code'.
16264 When in an #+include line, visit the include file. Otherwise call
16265 `ffap' to visit the file at point."
16268 ((org-at-table.el-p)
16269 (org-edit-src-code))
16271 (call-interactively 'org-table-edit-formulas))
16273 (beginning-of-line 1)
16274 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16275 (find-file (org-trim (match-string 1))))
16276 ((org-edit-src-code))
16277 ((org-edit-fixed-width-region))
16278 (t (call-interactively 'ffap))))
16281 (defun org-ctrl-c-ctrl-c (&optional arg)
16282 "Set tags in headline, or update according to changed information at point.
16284 This command does many different things, depending on context:
16286 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
16287 this is what we do.
16289 - If the cursor is on a statistics cookie, update it.
16291 - If the cursor is in a headline, prompt for tags and insert them
16292 into the current line, aligned to `org-tags-column'. When called
16293 with prefix arg, realign all tags in the current buffer.
16295 - If the cursor is in one of the special #+KEYWORD lines, this
16296 triggers scanning the buffer for these lines and updating the
16299 - If the cursor is inside a table, realign the table. This command
16300 works even if the automatic table editor has been turned off.
16302 - If the cursor is on a #+TBLFM line, re-apply the formulas to
16305 - If the cursor is at a footnote reference or definition, jump to
16306 the corresponding definition or references, respectively.
16308 - If the cursor is a the beginning of a dynamic block, update it.
16310 - If the current buffer is a remember buffer, close note and file
16311 it. A prefix argument of 1 files to the default location
16312 without further interaction. A prefix argument of 2 files to
16313 the currently clocking task.
16315 - If the cursor is on a <<<target>>>, update radio targets and corresponding
16316 links in this buffer.
16318 - If the cursor is on a numbered item in a plain list, renumber the
16321 - If the cursor is on a checkbox, toggle it."
16323 (let ((org-enable-table-editor t))
16325 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
16326 org-occur-highlights
16327 org-latex-fragment-image-overlays)
16328 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
16329 (org-remove-occur-highlights)
16330 (org-remove-latex-fragment-image-overlays)
16331 (message "Temporary highlights/overlays removed from current buffer"))
16332 ((and (local-variable-p 'org-finish-function (current-buffer))
16333 (fboundp org-finish-function))
16334 (funcall org-finish-function))
16335 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
16336 ((or (looking-at org-property-start-re)
16337 (org-at-property-p))
16338 (call-interactively 'org-property-action))
16339 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
16340 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
16341 (or (org-on-heading-p) (org-at-item-p)))
16342 (call-interactively 'org-update-statistics-cookies))
16343 ((org-on-heading-p) (call-interactively 'org-set-tags))
16344 ((org-at-table.el-p)
16345 (message "Use C-c ' to edit table.el tables"))
16347 (org-table-maybe-eval-formula)
16349 (call-interactively 'org-table-recalculate)
16350 (org-table-maybe-recalculate-line))
16351 (call-interactively 'org-table-align))
16352 ((or (org-footnote-at-reference-p)
16353 (org-footnote-at-definition-p))
16354 (call-interactively 'org-footnote-action))
16355 ((org-at-item-checkbox-p)
16356 (call-interactively 'org-toggle-checkbox))
16359 (call-interactively 'org-toggle-checkbox)
16360 (call-interactively 'org-maybe-renumber-ordered-list)))
16361 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
16363 (beginning-of-line 1)
16364 (save-excursion (org-update-dblock)))
16366 (beginning-of-line 1)
16367 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
16369 ((equal (match-string 1) "TBLFM")
16370 ;; Recalculate the table before this line
16372 (beginning-of-line 1)
16373 (skip-chars-backward " \r\n\t")
16374 (if (org-at-table-p)
16375 (org-call-with-arg 'org-table-recalculate (or arg t)))))
16377 (let ((org-inhibit-startup-visibility-stuff t)
16378 (org-startup-align-all-tables nil))
16379 (org-save-outline-visibility 'use-markers (org-mode-restart)))
16380 (message "Local setup has been refreshed"))))
16381 ((org-clock-update-time-maybe))
16382 (t (error "C-c C-c can do nothing useful at this location")))))
16384 (defun org-mode-restart ()
16385 "Restart Org-mode, to scan again for special lines.
16386 Also updates the keyword regular expressions."
16389 (message "Org-mode restarted"))
16391 (defun org-kill-note-or-show-branches ()
16392 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
16394 (if (not org-finish-function)
16395 (call-interactively 'show-branches)
16396 (let ((org-note-abort t))
16397 (funcall org-finish-function))))
16399 (defun org-return (&optional indent)
16400 "Goto next table row or insert a newline.
16401 Calls `org-table-next-row' or `newline', depending on context.
16402 See the individual commands for more information."
16405 ((bobp) (if indent (newline-and-indent) (newline)))
16407 (org-table-justify-field-maybe)
16408 (call-interactively 'org-table-next-row))
16409 ((and org-return-follows-link
16410 (eq (get-text-property (point) 'face) 'org-link))
16411 (call-interactively 'org-open-at-point))
16412 ((and (org-at-heading-p)
16414 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
16418 (t (if indent (newline-and-indent) (newline)))))
16420 (defun org-return-indent ()
16421 "Goto next table row or insert a newline and indent.
16422 Calls `org-table-next-row' or `newline-and-indent', depending on
16423 context. See the individual commands for more information."
16427 (defun org-ctrl-c-star ()
16428 "Compute table, or change heading status of lines.
16429 Calls `org-table-recalculate' or `org-toggle-heading',
16430 depending on context."
16434 (call-interactively 'org-table-recalculate))
16436 ;; Convert all lines in region to list items
16437 (call-interactively 'org-toggle-heading))))
16439 (defun org-ctrl-c-minus ()
16440 "Insert separator line in table or modify bullet status of line.
16441 Also turns a plain line or a region of lines into list items.
16442 Calls `org-table-insert-hline', `org-toggle-item', or
16443 `org-cycle-list-bullet', depending on context."
16447 (call-interactively 'org-table-insert-hline))
16448 ((org-region-active-p)
16449 (call-interactively 'org-toggle-item))
16451 (call-interactively 'org-cycle-list-bullet))
16453 (call-interactively 'org-toggle-item))))
16455 (defun org-toggle-item ()
16456 "Convert headings or normal lines to items, items to normal lines.
16457 If there is no active region, only the current line is considered.
16459 If the first line in the region is a headline, convert all headlines to items.
16461 If the first line in the region is an item, convert all items to normal lines.
16463 If the first line is normal text, add an item bullet to each line."
16465 (let (l2 l beg end)
16466 (if (org-region-active-p)
16467 (setq beg (region-beginning) end (region-end))
16468 (setq beg (point-at-bol)
16469 end (min (1+ (point-at-eol)) (point-max))))
16472 (setq l2 (org-current-line))
16474 (beginning-of-line 1)
16475 (setq l (1- (org-current-line)))
16476 (if (org-at-item-p)
16477 ;; We already have items, de-itemize
16478 (while (< (setq l (1+ l)) l2)
16479 (when (org-at-item-p)
16480 (goto-char (match-beginning 2))
16481 (delete-region (match-beginning 2) (match-end 2))
16482 (and (looking-at "[ \t]+") (replace-match "")))
16483 (beginning-of-line 2))
16484 (if (org-on-heading-p)
16485 ;; Headings, convert to items
16486 (while (< (setq l (1+ l)) l2)
16487 (if (looking-at org-outline-regexp)
16488 (replace-match "- " t t))
16489 (beginning-of-line 2))
16490 ;; normal lines, turn them into items
16491 (while (< (setq l (1+ l)) l2)
16492 (unless (org-at-item-p)
16493 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16494 (replace-match "\\1- \\2")))
16495 (beginning-of-line 2)))))))
16497 (defun org-toggle-heading (&optional nstars)
16498 "Convert headings to normal text, or items or text to headings.
16499 If there is no active region, only the current line is considered.
16501 If the first line is a heading, remove the stars from all headlines
16504 If the first line is a plain list item, turn all plain list items
16507 If the first line is a normal line, turn each and every line in the
16508 region into a heading.
16510 When converting a line into a heading, the number of stars is chosen
16511 such that the lines become children of the current entry. However,
16512 when a prefix argument is given, its value determines the number of
16515 (let (l2 l itemp beg end)
16516 (if (org-region-active-p)
16517 (setq beg (region-beginning) end (region-end))
16518 (setq beg (point-at-bol)
16519 end (min (1+ (point-at-eol)) (point-max))))
16522 (setq l2 (org-current-line))
16524 (beginning-of-line 1)
16525 (setq l (1- (org-current-line)))
16526 (if (org-on-heading-p)
16527 ;; We already have headlines, de-star them
16528 (while (< (setq l (1+ l)) l2)
16529 (when (org-on-heading-p t)
16530 (and (looking-at outline-regexp) (replace-match "")))
16531 (beginning-of-line 2))
16532 (setq itemp (org-at-item-p))
16535 (make-string (prefix-numeric-value current-prefix-arg)
16538 (if (re-search-backward org-complex-heading-regexp nil t)
16539 (match-string 1) ""))))
16540 (add-stars (cond (nstars "")
16541 ((equal stars "") "*")
16542 (org-odd-levels-only "**")
16544 (rpl (concat stars add-stars " ")))
16545 (while (< (setq l (1+ l)) l2)
16547 (and (org-at-item-p) (replace-match rpl t t))
16548 (unless (org-on-heading-p)
16549 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
16550 (replace-match (concat rpl (match-string 2))))))
16551 (beginning-of-line 2)))))))
16553 (defun org-meta-return (&optional arg)
16554 "Insert a new heading or wrap a region in a table.
16555 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
16556 See the individual commands for more information."
16559 ((run-hook-with-args-until-success 'org-metareturn-hook))
16561 (call-interactively 'org-table-wrap-region))
16562 (t (call-interactively 'org-insert-heading))))
16566 ;; Define the Org-mode menus
16567 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
16569 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
16570 ["Next Field" org-cycle (org-at-table-p)]
16571 ["Previous Field" org-shifttab (org-at-table-p)]
16572 ["Next Row" org-return (org-at-table-p)]
16574 ["Blank Field" org-table-blank-field (org-at-table-p)]
16575 ["Edit Field" org-table-edit-field (org-at-table-p)]
16576 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
16579 ["Move Column Left" org-metaleft (org-at-table-p)]
16580 ["Move Column Right" org-metaright (org-at-table-p)]
16581 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
16582 ["Insert Column" org-shiftmetaright (org-at-table-p)])
16584 ["Move Row Up" org-metaup (org-at-table-p)]
16585 ["Move Row Down" org-metadown (org-at-table-p)]
16586 ["Delete Row" org-shiftmetaup (org-at-table-p)]
16587 ["Insert Row" org-shiftmetadown (org-at-table-p)]
16588 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
16590 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
16592 ["Copy Rectangle" org-copy-special (org-at-table-p)]
16593 ["Cut Rectangle" org-cut-special (org-at-table-p)]
16594 ["Paste Rectangle" org-paste-special (org-at-table-p)]
16595 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
16598 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
16599 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
16600 ["Edit Formulas" org-edit-special (org-at-table-p)]
16602 ["Recalculate line" org-table-recalculate (org-at-table-p)]
16603 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
16604 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
16606 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
16608 ["Sum Column/Rectangle" org-table-sum
16609 (or (org-at-table-p) (org-region-active-p))]
16610 ["Which Column?" org-table-current-column (org-at-table-p)])
16612 org-table-toggle-formula-debugger
16613 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
16614 ["Show Col/Row Numbers"
16615 org-table-toggle-coordinate-overlays
16617 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
16619 ["Create" org-table-create (and (not (org-at-table-p))
16620 org-enable-table-editor)]
16621 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
16622 ["Import from File" org-table-import (not (org-at-table-p))]
16623 ["Export to File" org-table-export (org-at-table-p)]
16625 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
16627 (easy-menu-define org-org-menu org-mode-map "Org menu"
16630 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
16631 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
16632 ["Sparse Tree..." org-sparse-tree t]
16633 ["Reveal Context" org-reveal t]
16634 ["Show All" show-all t]
16636 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
16638 ["New Heading" org-insert-heading t]
16639 ("Navigate Headings"
16640 ["Up" outline-up-heading t]
16641 ["Next" outline-next-visible-heading t]
16642 ["Previous" outline-previous-visible-heading t]
16643 ["Next Same Level" outline-forward-same-level t]
16644 ["Previous Same Level" outline-backward-same-level t]
16646 ["Jump" org-goto t])
16648 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
16649 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
16651 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
16652 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
16653 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
16655 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
16657 ["Promote Heading" org-metaleft (not (org-at-table-p))]
16658 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
16659 ["Demote Heading" org-metaright (not (org-at-table-p))]
16660 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
16662 ["Sort Region/Children" org-sort (not (org-at-table-p))]
16664 ["Convert to odd levels" org-convert-to-odd-levels t]
16665 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
16667 ["Emphasis..." org-emphasize t]
16668 ["Edit Source Example" org-edit-special t]
16670 ["Footnote new/jump" org-footnote-action t]
16671 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
16673 ["Archive (default method)" org-archive-subtree-default t]
16675 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
16676 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
16677 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
16681 ["Store Link (Global)" org-store-link t]
16682 ["Find existing link to here" org-occur-link-in-agenda-files t]
16683 ["Insert Link" org-insert-link t]
16684 ["Follow Link" org-open-at-point t]
16686 ["Next link" org-next-link t]
16687 ["Previous link" org-previous-link t]
16689 ["Descriptive Links"
16690 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
16692 :selected (member '(org-link) buffer-invisibility-spec)]
16695 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
16697 :selected (not (member '(org-link) buffer-invisibility-spec))])
16700 ["TODO/DONE/-" org-todo t]
16702 ["Next keyword" org-shiftright (org-on-heading-p)]
16703 ["Previous keyword" org-shiftleft (org-on-heading-p)]
16704 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
16705 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
16706 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
16707 ["Show TODO Tree" org-show-todo-tree t]
16708 ["Global TODO list" org-todo-list t]
16710 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
16711 :selected org-enforce-todo-dependencies :style toggle :active t]
16712 "Settings for tree at point"
16713 ["Do Children sequentially" org-toggle-ordered-property :style radio
16714 :selected (ignore-errors (org-entry-get nil "ORDERED"))
16715 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16716 ["Do Children parallel" org-toggle-ordered-property :style radio
16717 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
16718 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
16720 ["Set Priority" org-priority t]
16721 ["Priority Up" org-shiftup t]
16722 ["Priority Down" org-shiftdown t]
16724 ["Get news from all feeds" org-feed-update-all t]
16725 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
16726 ["Customize feeds" (customize-variable 'org-feed-alist) t])
16727 ("TAGS and Properties"
16728 ["Set Tags" org-set-tags-command t]
16729 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
16731 ["Set property" org-set-property t]
16732 ["Column view of properties" org-columns t]
16733 ["Insert Column View DBlock" org-insert-columns-dblock t])
16734 ("Dates and Scheduling"
16735 ["Timestamp" org-time-stamp t]
16736 ["Timestamp (inactive)" org-time-stamp-inactive t]
16738 ["1 Day Later" org-shiftright t]
16739 ["1 Day Earlier" org-shiftleft t]
16740 ["1 ... Later" org-shiftup t]
16741 ["1 ... Earlier" org-shiftdown t])
16742 ["Compute Time Range" org-evaluate-time-range t]
16743 ["Schedule Item" org-schedule t]
16744 ["Deadline" org-deadline t]
16746 ["Custom time format" org-toggle-time-stamp-overlays
16747 :style radio :selected org-display-custom-times]
16749 ["Goto Calendar" org-goto-calendar t]
16750 ["Date from Calendar" org-date-from-calendar t]
16752 ["Start/Restart Timer" org-timer-start t]
16753 ["Pause/Continue Timer" org-timer-pause-or-continue t]
16754 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
16755 ["Insert Timer String" org-timer t]
16756 ["Insert Timer Item" org-timer-item t])
16758 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
16759 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
16760 ["Clock out" org-clock-out t]
16761 ["Clock cancel" org-clock-cancel t]
16763 ["Mark as default task" org-clock-mark-default-task t]
16764 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
16765 ["Goto running clock" org-clock-goto t]
16767 ["Display times" org-clock-display t]
16768 ["Create clock table" org-clock-report t]
16770 ["Record DONE time"
16771 (progn (setq org-log-done (not org-log-done))
16772 (message "Switching to %s will %s record a timestamp"
16773 (car org-done-keywords)
16774 (if org-log-done "automatically" "not")))
16775 :style toggle :selected org-log-done])
16777 ["Agenda Command..." org-agenda t]
16778 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
16779 ("File List for Agenda")
16780 ("Special views current file"
16781 ["TODO Tree" org-show-todo-tree t]
16782 ["Check Deadlines" org-check-deadlines t]
16783 ["Timeline" org-timeline t]
16784 ["Tags/Property tree" org-match-sparse-tree t])
16786 ["Export/Publish..." org-export t]
16788 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
16789 :selected org-cdlatex-mode]
16790 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
16791 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
16792 ["Modify math symbol" org-cdlatex-math-modify
16793 (org-inside-LaTeX-fragment-p)]
16794 ["Insert citation" org-reftex-citation t]
16796 ["Export LaTeX fragments as images"
16797 (if (featurep 'org-exp)
16798 (setq org-export-with-LaTeX-fragments
16799 (not org-export-with-LaTeX-fragments))
16800 (require 'org-exp))
16801 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
16802 org-export-with-LaTeX-fragments)]
16804 ["Template for BEAMER" org-beamer-settings-template t])
16807 ["Push Files and Views" org-mobile-push t]
16808 ["Get Captured and Flagged" org-mobile-pull t]
16809 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
16811 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
16814 ["Show Version" org-version t]
16815 ["Info Documentation" org-info t])
16817 ["Browse Org Group" org-customize t]
16819 ["Expand This Menu" org-create-customize-menu
16820 (fboundp 'customize-menu-create)])
16821 ["Send bug report" org-submit-bug-report t]
16824 ["Refresh setup current buffer" org-mode-restart t]
16825 ["Reload Org (after update)" org-reload t]
16826 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
16829 (defun org-info (&optional node)
16830 "Read documentation for Org-mode in the info system.
16831 With optional NODE, go directly to that node."
16833 (info (format "(org)%s" (or node ""))))
16836 (defun org-submit-bug-report ()
16837 "Submit a bug report on Org-mode via mail.
16839 Don't hesitate to report any problems or inaccurate documentation.
16841 If you don't have setup sending mail from (X)Emacs, please copy the
16842 output buffer into your mail program, as it gives us important
16843 information about your Org-mode version and configuration."
16845 (require 'reporter)
16846 (org-load-modules-maybe)
16847 (org-require-autoloaded-modules)
16848 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
16849 (reporter-submit-bug-report
16850 "emacs-orgmode@gnu.org"
16853 (save-window-excursion
16854 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
16855 (delete-other-windows)
16857 (insert "You are about to submit a bug report to the Org-mode mailing list.
16859 We would like to add your full Org-mode and Outline configuration to the
16860 bug report. This greatly simplifies the work of the maintainer and
16861 other experts on the mailing list.
16863 HOWEVER, some variables you have customized may contain private
16864 information. The names of customers, colleagues, or friends, might
16865 appear in the form of file names, tags, todo states, or search strings.
16866 If you answer yes to the prompt, you might want to check and remove
16867 such private information before sending the email.")
16868 (add-text-properties (point-min) (point-max) '(face org-warning))
16869 (when (yes-or-no-p "Include your Org-mode configuration ")
16873 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
16874 (or (and (symbol-value v)
16875 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
16877 (get v 'custom-type) (get v 'standard-value)
16878 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
16880 (kill-buffer (get-buffer "*Warn about privacy*"))
16883 "Remember to cover the basics, that is, what you expected to happen and
16884 what in fact did happen. You don't know how to make a good report? See
16886 http://orgmode.org/manual/Feedback.html#Feedback
16888 Your bug report will be posted to the Org-mode mailing list.
16889 ------------------------------------------------------------------------")
16891 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
16892 (replace-match "\\1Bug: \\3 [\\2]")))))
16895 (defun org-install-agenda-files-menu ()
16896 (let ((bl (buffer-list)))
16899 (set-buffer (pop bl))
16900 (if (org-mode-p) (setq bl nil)))
16903 '("Org") "File List for Agenda"
16906 ["Edit File List" (org-edit-agenda-file-list) t]
16907 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
16908 ["Remove Current File from List" org-remove-file t]
16909 ["Cycle through agenda files" org-cycle-agenda-files t]
16910 ["Occur in all agenda files" org-occur-in-agenda-files t]
16912 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
16917 (defun org-require-autoloaded-modules ()
16920 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
16921 org-docbook org-exp org-html org-icalendar
16923 org-publish org-remember org-table
16924 org-timer org-xoxo)))
16927 (defun org-reload (&optional uncompiled)
16928 "Reload all org lisp files.
16929 With prefix arg UNCOMPILED, load the uncompiled versions."
16931 (require 'find-func)
16932 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
16933 (dir-org (file-name-directory (org-find-library-name "org")))
16934 (dir-org-contrib (ignore-errors
16935 (file-name-directory
16936 (org-find-library-name "org-contribdir"))))
16938 (append (directory-files dir-org t file-re)
16939 (and dir-org-contrib
16940 (directory-files dir-org-contrib t file-re))))
16941 (remove-re (concat (if (featurep 'xemacs)
16942 "org-colview" "org-colview-xemacs")
16944 (setq files (mapcar 'file-name-sans-extension files))
16945 (setq files (mapcar
16946 (lambda (x) (if (string-match remove-re x) nil x))
16948 (setq files (delq nil files))
16951 (when (featurep (intern (file-name-nondirectory f)))
16952 (if (and (not uncompiled)
16953 (file-exists-p (concat f ".elc")))
16954 (load (concat f ".elc") nil nil t)
16955 (load (concat f ".el") nil nil t))))
16960 (defun org-customize ()
16961 "Call the customize function with org as argument."
16963 (org-load-modules-maybe)
16964 (org-require-autoloaded-modules)
16965 (customize-browse 'org))
16967 (defun org-create-customize-menu ()
16968 "Create a full customization menu for Org-mode, insert it into the menu."
16970 (org-load-modules-maybe)
16971 (org-require-autoloaded-modules)
16972 (if (fboundp 'customize-menu-create)
16975 '("Org") "Customize"
16976 `(["Browse Org group" org-customize t]
16978 ,(customize-menu-create 'org)
16979 ["Set" Custom-set t]
16980 ["Save" Custom-save t]
16981 ["Reset to Current" Custom-reset-current t]
16982 ["Reset to Saved" Custom-reset-saved t]
16983 ["Reset to Standard Settings" Custom-reset-standard t]))
16984 (message "\"Org\"-menu now contains full customization menu"))
16985 (error "Cannot expand menu (outdated version of cus-edit.el)")))
16987 ;;;; Miscellaneous stuff
16989 ;;; Generally useful functions
16991 (defun org-get-at-bol (property)
16992 "Get text property PROPERTY at beginning of line."
16993 (get-text-property (point-at-bol) property))
16995 (defun org-find-text-property-in-string (prop s)
16996 "Return the first non-nil value of property PROP in string S."
16997 (or (get-text-property 0 prop s)
16998 (get-text-property (or (next-single-property-change 0 prop s) 0)
17001 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17002 "Display the given MESSAGE as a warning."
17003 (if (fboundp 'display-warning)
17004 (display-warning 'org message
17005 (if (featurep 'xemacs)
17008 (let ((buf (get-buffer-create "*Org warnings*")))
17009 (with-current-buffer buf
17010 (goto-char (point-max))
17011 (insert "Warning (Org): " message)
17014 (display-buffer buf)
17017 (defun org-in-commented-line ()
17018 "Is point in a line starting with `#'?"
17019 (equal (char-after (point-at-bol)) ?#))
17021 (defun org-in-verbatim-emphasis ()
17023 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17025 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17026 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17027 (if (and marker (marker-buffer marker)
17028 (buffer-live-p (marker-buffer marker)))
17030 (switch-to-buffer (marker-buffer marker))
17031 (if (or (> marker (point-max)) (< marker (point-min)))
17034 (org-show-context 'org-goto))
17036 (bookmark-jump bookmark)
17037 (error "Cannot find location"))))
17039 (defun org-quote-csv-field (s)
17040 "Quote field for inclusion in CSV material."
17041 (if (string-match "[\",]" s)
17042 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17045 (defun org-plist-delete (plist property)
17046 "Delete PROPERTY from PLIST.
17047 This is in contrast to merely setting it to 0."
17050 (if (not (eq property (car plist)))
17051 (setq p (plist-put p (car plist) (nth 1 plist))))
17052 (setq plist (cddr plist)))
17055 (defun org-force-self-insert (N)
17056 "Needed to enforce self-insert under remapping."
17058 (self-insert-command N))
17060 (defun org-string-width (s)
17061 "Compute width of string, ignoring invisible characters.
17062 This ignores character with invisibility property `org-link', and also
17063 characters with property `org-cwidth', because these will become invisible
17064 upon the next fontification round."
17066 (when (or (eq t buffer-invisibility-spec)
17067 (assq 'org-link buffer-invisibility-spec))
17068 (while (setq b (text-property-any 0 (length s)
17069 'invisible 'org-link s))
17070 (setq s (concat (substring s 0 b)
17071 (substring s (or (next-single-property-change
17072 b 'invisible s) (length s)))))))
17073 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17074 (setq s (concat (substring s 0 b)
17075 (substring s (or (next-single-property-change
17076 b 'org-cwidth s) (length s))))))
17077 (setq l (string-width s) b -1)
17078 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17079 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17082 (defun org-get-indentation (&optional line)
17083 "Get the indentation of the current line, interpreting tabs.
17084 When LINE is given, assume it represents a line and compute its indentation."
17086 (if (string-match "^ *" (org-remove-tabs line))
17089 (beginning-of-line 1)
17090 (skip-chars-forward " \t")
17091 (current-column))))
17093 (defun org-remove-tabs (s &optional width)
17094 "Replace tabulators in S with spaces.
17095 Assumes that s is a single line, starting in column 0."
17096 (setq width (or width tab-width))
17097 (while (string-match "\t" s)
17098 (setq s (replace-match
17100 (- (* width (/ (+ (match-beginning 0) width) width))
17101 (match-beginning 0)) ?\ )
17105 (defun org-fix-indentation (line ind)
17106 "Fix indentation in LINE.
17107 IND is a cons cell with target and minimum indentation.
17108 If the current indentation in LINE is smaller than the minimum,
17109 leave it alone. If it is larger than ind, set it to the target."
17110 (let* ((l (org-remove-tabs line))
17111 (i (org-get-indentation l))
17112 (i1 (car ind)) (i2 (cdr ind)))
17113 (if (>= i i2) (setq l (substring line i2)))
17115 (concat (make-string i1 ?\ ) l)
17118 (defun org-remove-indentation (code &optional n)
17119 "Remove the maximum common indentation from the lines in CODE.
17120 N may optionally be the number of spaces to remove."
17123 (org-do-remove-indentation n)
17126 (defun org-do-remove-indentation (&optional n)
17127 "Remove the maximum common indentation from the buffer."
17128 (untabify (point-min) (point-max))
17129 (let ((min 10000) re)
17132 (goto-char (point-min))
17133 (while (re-search-forward "^ *[^ \n]" nil t)
17134 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17135 (unless (or (= min 0) (= min 10000))
17136 (setq re (format "^ \\{%d\\}" min))
17137 (goto-char (point-min))
17138 (while (re-search-forward re nil t)
17143 (defun org-fill-template (template alist)
17144 "Find each %key of ALIST in TEMPLATE and replace it."
17145 (let ((case-fold-search nil)
17147 (setq alist (sort (copy-sequence alist)
17148 (lambda (a b) (< (length (car a)) (length (car b))))))
17149 (while (setq entry (pop alist))
17151 (replace-regexp-in-string
17152 (concat "%" (regexp-quote (car entry)))
17153 (cdr entry) template t t)))
17156 (defun org-base-buffer (buffer)
17157 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17160 (or (buffer-base-buffer buffer)
17163 (defun org-trim (s)
17164 "Remove whitespace at beginning and end of string."
17165 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17166 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17169 (defun org-wrap (string &optional width lines)
17170 "Wrap string to either a number of lines, or a width in characters.
17171 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17172 that costs. If there is a word longer than WIDTH, the text is actually
17173 wrapped to the length of that word.
17174 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17175 many lines, whatever width that takes.
17176 The return value is a list of lines, without newlines at the end."
17177 (let* ((words (org-split-string string "[ \t\n]+"))
17178 (maxword (apply 'max (mapcar 'org-string-width words)))
17181 (org-do-wrap words (max maxword width)))
17184 (setq ll (org-do-wrap words maxword))
17185 (if (<= (length ll) lines)
17188 (while (> (length ll) lines)
17190 (setq ll (org-do-wrap words w)))
17192 (t (error "Cannot wrap this")))))
17194 (defun org-do-wrap (words width)
17195 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17198 (setq line (pop words))
17199 (while (and words (< (+ (length line) (length (car words))) width))
17200 (setq line (concat line " " (pop words))))
17201 (setq lines (push line lines)))
17204 (defun org-split-string (string &optional separators)
17205 "Splits STRING into substrings at SEPARATORS.
17206 No empty strings are returned if there are matches at the beginning
17207 and end of string."
17208 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17212 (while (and (string-match rexp string
17214 (= start (match-beginning 0))
17215 (< start (length string)))
17217 (< (match-beginning 0) (length string)))
17219 (or (eq (match-beginning 0) 0)
17220 (and (eq (match-beginning 0) (match-end 0))
17221 (eq (match-beginning 0) start))
17223 (cons (substring string start (match-beginning 0))
17225 (setq start (match-end 0)))
17226 (or (eq start (length string))
17228 (cons (substring string start)
17232 (defun org-quote-vert (s)
17233 "Replace \"|\" with \"\\vert\"."
17234 (while (string-match "|" s)
17235 (setq s (replace-match "\\vert" t t s)))
17238 (defun org-uuidgen-p (s)
17239 "Is S an ID created by UUIDGEN?"
17240 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17242 (defun org-context ()
17243 "Return a list of contexts of the current cursor position.
17244 If several contexts apply, all are returned.
17245 Each context entry is a list with a symbol naming the context, and
17246 two positions indicating start and end of the context. Possible
17249 :headline anywhere in a headline
17250 :headline-stars on the leading stars in a headline
17251 :todo-keyword on a TODO keyword (including DONE) in a headline
17252 :tags on the TAGS in a headline
17253 :priority on the priority cookie in a headline
17254 :item on the first line of a plain list item
17255 :item-bullet on the bullet/number of a plain list item
17256 :checkbox on the checkbox in a plain list item
17257 :table in an org-mode table
17258 :table-special on a special filed in a table
17259 :table-table in a table.el table
17260 :link on a hyperlink
17261 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
17262 :target on a <<target>>
17263 :radio-target on a <<<radio-target>>>
17264 :latex-fragment on a LaTeX fragment
17265 :latex-preview on a LaTeX fragment with overlayed preview image
17267 This function expects the position to be visible because it uses font-lock
17268 faces as a help to recognize the following contexts: :table-special, :link,
17270 (let* ((f (get-text-property (point) 'face))
17271 (faces (if (listp f) f (list f)))
17272 (p (point)) clist o)
17273 ;; First the large context
17275 ((org-on-heading-p t)
17276 (push (list :headline (point-at-bol) (point-at-eol)) clist)
17278 (beginning-of-line 1)
17279 (looking-at org-todo-line-tags-regexp))
17280 (push (org-point-in-group p 1 :headline-stars) clist)
17281 (push (org-point-in-group p 2 :todo-keyword) clist)
17282 (push (org-point-in-group p 4 :tags) clist))
17284 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
17285 (if (looking-at "\\[#[A-Z0-9]\\]")
17286 (push (org-point-in-group p 0 :priority) clist)))
17289 (push (org-point-in-group p 2 :item-bullet) clist)
17290 (push (list :item (point-at-bol)
17291 (save-excursion (org-end-of-item) (point)))
17293 (and (org-at-item-checkbox-p)
17294 (push (org-point-in-group p 0 :checkbox) clist)))
17297 (push (list :table (org-table-begin) (org-table-end)) clist)
17298 (if (memq 'org-formula faces)
17299 (push (list :table-special
17300 (previous-single-property-change p 'face)
17301 (next-single-property-change p 'face)) clist)))
17302 ((org-at-table-p 'any)
17303 (push (list :table-table) clist)))
17306 ;; Now the small context
17308 ((org-at-timestamp-p)
17309 (push (org-point-in-group p 0 :timestamp) clist))
17310 ((memq 'org-link faces)
17312 (previous-single-property-change p 'face)
17313 (next-single-property-change p 'face)) clist))
17314 ((memq 'org-special-keyword faces)
17315 (push (list :keyword
17316 (previous-single-property-change p 'face)
17317 (next-single-property-change p 'face)) clist))
17319 (push (org-point-in-group p 0 :target) clist)
17320 (goto-char (1- (match-beginning 0)))
17321 (if (looking-at org-radio-target-regexp)
17322 (push (org-point-in-group p 0 :radio-target) clist))
17324 ((setq o (car (delq nil
17327 (if (memq x org-latex-fragment-image-overlays) x))
17328 (org-overlays-at (point))))))
17329 (push (list :latex-fragment
17330 (overlay-start o) (overlay-end o)) clist)
17331 (push (list :latex-preview
17332 (overlay-start o) (overlay-end o)) clist))
17333 ((org-inside-LaTeX-fragment-p)
17334 ;; FIXME: positions wrong.
17335 (push (list :latex-fragment (point) (point)) clist)))
17337 (setq clist (nreverse (delq nil clist)))
17340 ;; FIXME: Compare with at-regexp-p Do we need both?
17341 (defun org-in-regexp (re &optional nlines visually)
17342 "Check if point is inside a match of regexp.
17343 Normally only the current line is checked, but you can include NLINES extra
17344 lines both before and after point into the search.
17345 If VISUALLY is set, require that the cursor is not after the match but
17346 really on, so that the block visually is on the match."
17348 (let ((pos (point))
17349 (eol (point-at-eol (+ 1 (or nlines 0))))
17350 (inc (if visually 1 0)))
17352 (beginning-of-line (- 1 (or nlines 0)))
17353 (while (re-search-forward re eol t)
17354 (if (and (<= (match-beginning 0) pos)
17355 (>= (+ inc (match-end 0)) pos))
17356 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
17358 (defun org-at-regexp-p (regexp)
17359 "Is point inside a match of REGEXP in the current line?"
17362 (let ((pos (point)) (end (point-at-eol)))
17363 (beginning-of-line 1)
17364 (while (re-search-forward regexp end t)
17365 (if (and (<= (match-beginning 0) pos)
17366 (>= (match-end 0) pos))
17370 (defun org-in-regexps-block-p (start-re end-re)
17371 "Returns t if the current point is between matches of START-RE and END-RE.
17372 This will also return to if point is on one of the two matches."
17376 (and (or (org-at-regexp-p start-re)
17377 (re-search-backward start-re nil t))
17378 (re-search-forward end-re nil t)
17381 (defun org-occur-in-agenda-files (regexp &optional nlines)
17382 "Call `multi-occur' with buffers for all agenda files."
17383 (interactive "sOrg-files matching: \np")
17384 (let* ((files (org-agenda-files))
17385 (tnames (mapcar 'file-truename files))
17386 (extra org-agenda-text-search-extra-files)
17388 (when (eq (car extra) 'agenda-archives)
17389 (setq extra (cdr extra))
17390 (setq files (org-add-archive-files files)))
17391 (while (setq f (pop extra))
17392 (unless (member (file-truename f) tnames)
17393 (add-to-list 'files f 'append)
17394 (add-to-list 'tnames (file-truename f) 'append)))
17396 (mapcar (lambda (x)
17397 (with-current-buffer
17398 (or (get-file-buffer x) (find-file-noselect x))
17404 (if (boundp 'occur-mode-find-occurrence-hook)
17406 (add-hook 'occur-mode-find-occurrence-hook
17411 (defadvice occur-mode-goto-occurrence
17412 (after org-occur-reveal activate)
17413 (and (org-mode-p) (org-reveal)))
17414 (defadvice occur-mode-goto-occurrence-other-window
17415 (after org-occur-reveal activate)
17416 (and (org-mode-p) (org-reveal)))
17417 (defadvice occur-mode-display-occurrence
17418 (after org-occur-reveal activate)
17420 (let ((pos (occur-mode-find-occurrence)))
17421 (with-current-buffer (marker-buffer pos)
17426 (defun org-occur-link-in-agenda-files ()
17427 "Create a link and search for it in the agendas.
17428 The link is not stored in `org-stored-links', it is just created
17429 for the search purpose."
17431 (let ((link (condition-case nil
17432 (org-store-link nil)
17433 (error "Unable to create a link to here"))))
17434 (org-occur-in-agenda-files (regexp-quote link))))
17436 (defun org-uniquify (list)
17437 "Remove duplicate elements from LIST."
17439 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
17442 (defun org-delete-all (elts list)
17443 "Remove all elements in ELTS from LIST."
17445 (setq list (delete (pop elts) list)))
17448 (defun org-remove-if (predicate seq)
17449 "Remove everything from SEQ that fulfills PREDICATE."
17453 (if (not (funcall predicate e)) (push e res)))
17456 (defun org-remove-if-not (predicate seq)
17457 "Remove everything from SEQ that does not fulfill PREDICATE."
17461 (if (funcall predicate e) (push e res)))
17464 (defun org-back-over-empty-lines ()
17465 "Move backwards over whitespace, to the beginning of the first empty line.
17466 Returns the number of empty lines passed."
17467 (let ((pos (point)))
17468 (skip-chars-backward " \t\n\r")
17469 (beginning-of-line 2)
17470 (goto-char (min (point) pos))
17471 (count-lines (point) pos)))
17473 (defun org-skip-whitespace ()
17474 (skip-chars-forward " \t\n\r"))
17476 (defun org-point-in-group (point group &optional context)
17477 "Check if POINT is in match-group GROUP.
17478 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
17479 match. If the match group does ot exist or point is not inside it,
17481 (and (match-beginning group)
17482 (>= point (match-beginning group))
17483 (<= point (match-end group))
17485 (list context (match-beginning group) (match-end group))
17488 (defun org-switch-to-buffer-other-window (&rest args)
17489 "Switch to buffer in a second window on the current frame.
17490 In particular, do not allow pop-up frames."
17491 (let (pop-up-frames special-display-buffer-names special-display-regexps
17492 special-display-function)
17493 (apply 'switch-to-buffer-other-window args)))
17495 (defun org-combine-plists (&rest plists)
17496 "Create a single property list from all plists in PLISTS.
17497 The process starts by copying the first list, and then setting properties
17498 from the other lists. Settings in the last list are the most significant
17499 ones and overrule settings in the other lists."
17500 (let ((rtn (copy-sequence (pop plists)))
17503 (setq ls (pop plists))
17505 (setq p (pop ls) v (pop ls))
17506 (setq rtn (plist-put rtn p v))))
17509 (defun org-move-line-down (arg)
17510 "Move the current line down. With prefix argument, move it past ARG lines."
17512 (let ((col (current-column))
17514 (beginning-of-line 1) (setq beg (point))
17515 (beginning-of-line 2) (setq end (point))
17516 (beginning-of-line (+ 1 arg))
17517 (setq pos (move-marker (make-marker) (point)))
17518 (insert (delete-and-extract-region beg end))
17520 (org-move-to-column col)))
17522 (defun org-move-line-up (arg)
17523 "Move the current line up. With prefix argument, move it past ARG lines."
17525 (let ((col (current-column))
17527 (beginning-of-line 1) (setq beg (point))
17528 (beginning-of-line 2) (setq end (point))
17529 (beginning-of-line (- arg))
17530 (setq pos (move-marker (make-marker) (point)))
17531 (insert (delete-and-extract-region beg end))
17533 (org-move-to-column col)))
17535 (defun org-replace-escapes (string table)
17536 "Replace %-escapes in STRING with values in TABLE.
17537 TABLE is an association list with keys like \"%a\" and string values.
17538 The sequences in STRING may contain normal field width and padding information,
17539 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
17540 so values can contain further %-escapes if they are define later in TABLE."
17541 (let ((case-fold-search nil)
17543 (while (setq e (pop table))
17544 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
17545 (while (string-match re string)
17546 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
17548 (setq string (replace-match rpl t t string))))
17552 (defun org-sublist (list start end)
17553 "Return a section of LIST, from START to END.
17554 Counting starts at 1."
17555 (let (rtn (c start))
17556 (setq list (nthcdr (1- start) list))
17557 (while (and list (<= c end))
17558 (push (pop list) rtn)
17562 (defun org-find-base-buffer-visiting (file)
17563 "Like `find-buffer-visiting' but always return the base buffer and
17564 not an indirect buffer."
17565 (let ((buf (or (get-file-buffer file)
17566 (find-buffer-visiting file))))
17568 (or (buffer-base-buffer buf) buf)
17571 (defun org-image-file-name-regexp (&optional extensions)
17572 "Return regexp matching the file names of images.
17573 If EXTENSIONS is given, only match these."
17574 (if (and (not extensions) (fboundp 'image-file-name-regexp))
17575 (image-file-name-regexp)
17576 (let ((image-file-name-extensions
17578 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
17579 "xbm" "xpm" "pbm" "pgm" "ppm"))))
17581 (regexp-opt (nconc (mapcar 'upcase
17582 image-file-name-extensions)
17583 image-file-name-extensions)
17587 (defun org-file-image-p (file &optional extensions)
17588 "Return non-nil if FILE is an image."
17590 (string-match (org-image-file-name-regexp extensions) file)))
17592 (defun org-get-cursor-date ()
17593 "Return the date at cursor in as a time.
17594 This works in the calendar and in the agenda, anywhere else it just
17595 returns the current time."
17596 (let (date day defd)
17598 ((eq major-mode 'calendar-mode)
17599 (setq date (calendar-cursor-to-date)
17600 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
17601 ((eq major-mode 'org-agenda-mode)
17602 (setq day (get-text-property (point) 'day))
17604 (setq date (calendar-gregorian-from-absolute day)
17605 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
17607 (or defd (current-time))))
17609 (defvar org-agenda-action-marker (make-marker)
17610 "Marker pointing to the entry for the next agenda action.")
17612 (defun org-mark-entry-for-agenda-action ()
17613 "Mark the current entry as target of an agenda action.
17614 Agenda actions are actions executed from the agenda with the key `k',
17615 which make use of the date at the cursor."
17617 (move-marker org-agenda-action-marker
17618 (save-excursion (org-back-to-heading t) (point))
17621 "Entry marked for action; press `k' at desired date in agenda or calendar"))
17623 ;;; Paragraph filling stuff.
17624 ;; We want this to be just right, so use the full arsenal.
17626 (defun org-indent-line-function ()
17627 "Indent line like previous, but further if previous was headline or item."
17629 (let* ((pos (point))
17630 (itemp (org-at-item-p))
17631 (case-fold-search t)
17632 (org-drawer-regexp (or org-drawer-regexp "\000"))
17633 column bpos bcol tpos tcol bullet btype bullet-type)
17634 ;; Find the previous relevant line
17635 (beginning-of-line 1)
17637 ((looking-at "#") (setq column 0))
17638 ((looking-at "\\*+ ") (setq column 0))
17639 ((and (looking-at "[ \t]*:END:")
17640 (save-excursion (re-search-backward org-drawer-regexp nil t)))
17642 (goto-char (1- (match-beginning 1)))
17643 (setq column (current-column))))
17644 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
17646 (re-search-backward
17647 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
17648 (setq column (org-get-indentation (match-string 0))))
17650 (beginning-of-line 0)
17651 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
17652 (not (looking-at "[ \t]*:END:"))
17653 (not (looking-at org-drawer-regexp)))
17654 (beginning-of-line 0))
17656 ((looking-at "\\*+[ \t]+")
17657 (if (not org-adapt-indentation)
17659 (goto-char (match-end 0))
17660 (setq column (current-column))))
17661 ((looking-at org-drawer-regexp)
17662 (goto-char (1- (match-beginning 1)))
17663 (setq column (current-column)))
17664 ((looking-at "\\([ \t]*\\):END:")
17665 (goto-char (match-end 1))
17666 (setq column (current-column)))
17668 (org-beginning-of-item)
17669 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
17670 (setq bpos (match-beginning 1) tpos (match-end 0)
17671 bcol (progn (goto-char bpos) (current-column))
17672 tcol (progn (goto-char tpos) (current-column))
17673 bullet (match-string 1)
17674 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
17675 (if (> tcol (+ bcol org-description-max-indent))
17676 (setq tcol (+ bcol 5)))
17680 (beginning-of-line 1)
17681 (if (looking-at "\\S-")
17683 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
17684 (setq bullet (match-string 1)
17685 btype (if (string-match "[0-9]" bullet) "n" bullet))
17686 (setq column (if (equal btype bullet-type) bcol tcol)))
17687 (setq column (org-get-indentation)))))
17688 (t (setq column (org-get-indentation))))))
17690 (if (<= (current-column) (current-indentation))
17691 (org-indent-line-to column)
17692 (save-excursion (org-indent-line-to column)))
17693 (setq column (current-column))
17694 (beginning-of-line 1)
17696 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
17697 (replace-match (concat (match-string 1)
17698 (format org-property-format
17699 (match-string 2) (match-string 3)))
17701 (org-move-to-column column)))
17703 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
17704 "Variable to store copy of `adaptive-fill-regexp'.
17705 Since `adaptive-fill-regexp' is set to never match, we need to
17706 store a backup of its value before entering `org-mode' so that
17707 the functionality can be provided as a fall-back.")
17709 (defun org-set-autofill-regexps ()
17711 ;; In the paragraph separator we include headlines, because filling
17712 ;; text in a line directly attached to a headline would otherwise
17713 ;; fill the headline as well.
17714 (org-set-local 'comment-start-skip "^#+[ \t]*")
17715 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
17716 ;; The paragraph starter includes hand-formatted lists.
17724 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
17727 "\\\\\\(begin\\|end\\|[][]\\)"))
17728 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
17729 ;; But only if the user has not turned off tables or fixed-width regions
17731 'auto-fill-inhibit-regexp
17732 (concat "\\*+ \\|#\\+"
17733 "\\|[ \t]*" org-keyword-time-regexp
17734 (if (or org-enable-table-editor org-enable-fixed-width-editor)
17737 (if org-enable-table-editor "|" "")
17738 (if org-enable-fixed-width-editor ":" "")
17740 ;; We use our own fill-paragraph function, to make sure that tables
17741 ;; and fixed-width regions are not wrapped. That function will pass
17742 ;; through to `fill-paragraph' when appropriate.
17743 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
17744 ;; Adaptive filling: To get full control, first make sure that
17745 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
17746 (unless (local-variable-p 'adaptive-fill-regexp)
17747 (org-set-local 'org-adaptive-fill-regexp-backup
17748 adaptive-fill-regexp))
17749 (org-set-local 'adaptive-fill-regexp "\000")
17750 (org-set-local 'adaptive-fill-function
17751 'org-adaptive-fill-function)
17753 'align-mode-rules-list
17754 '((org-in-buffer-settings
17755 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
17756 (modes . '(org-mode))))))
17758 (defun org-fill-paragraph (&optional justify)
17759 "Re-align a table, pass through to fill-paragraph if no table."
17760 (let ((table-p (org-at-table-p))
17761 (table.el-p (org-at-table.el-p)))
17762 (cond ((and (equal (char-after (point-at-bol)) ?*)
17763 (save-excursion (goto-char (point-at-bol))
17764 (looking-at outline-regexp)))
17765 t) ; skip headlines
17766 (table.el-p t) ; skip table.el tables
17767 (table-p (org-table-align) t) ; align org-mode tables
17768 (t nil)))) ; call paragraph-fill
17770 ;; For reference, this is the default value of adaptive-fill-regexp
17771 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
17773 (defun org-adaptive-fill-function ()
17774 "Return a fill prefix for org-mode files.
17775 In particular, this makes sure hanging paragraphs for hand-formatted lists
17779 ((looking-at "#[ \t]+")
17780 (match-string-no-properties 0))
17781 ;; Description list
17782 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
17784 (if (> (match-end 1) (+ (match-beginning 1)
17785 org-description-max-indent))
17786 (goto-char (+ (match-beginning 1) 5))
17787 (goto-char (match-end 0)))
17788 (make-string (current-column) ?\ )))
17789 ;; Ordered or unordered list
17790 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
17792 (goto-char (match-end 0))
17793 (make-string (current-column) ?\ )))
17795 ((looking-at org-adaptive-fill-regexp-backup)
17796 (match-string-no-properties 0))))
17800 (defun org-toggle-fixed-width-section (arg)
17801 "Toggle the fixed-width export.
17802 If there is no active region, the QUOTE keyword at the current headline is
17803 inserted or removed. When present, it causes the text between this headline
17804 and the next to be exported as fixed-width text, and unmodified.
17805 If there is an active region, this command adds or removes a colon as the
17806 first character of this line. If the first character of a line is a colon,
17807 this line is also exported in fixed-width font."
17810 (regionp (org-region-active-p))
17811 (beg (if regionp (region-beginning) (point)))
17812 (end (if regionp (region-end)))
17813 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
17814 (case-fold-search nil)
17815 (re "[ \t]*\\(: \\)")
17820 (setq cc (current-column))
17821 (beginning-of-line 1)
17822 (setq off (looking-at re))
17823 (while (> nlines 0)
17824 (setq nlines (1- nlines))
17825 (beginning-of-line 1)
17828 (org-move-to-column cc t)
17831 ((and off (looking-at re))
17832 (replace-match "" t t nil 1))
17833 ((not off) (org-move-to-column cc t) (insert ": ")))
17836 (org-back-to-heading)
17837 (if (looking-at (concat outline-regexp
17838 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
17839 (replace-match "" t t nil 1)
17840 (if (looking-at outline-regexp)
17842 (goto-char (match-end 0))
17843 (insert org-quote-string " "))))))))
17845 (defun org-reftex-citation ()
17846 "Use reftex-citation to insert a citation into the buffer.
17847 This looks for a line like
17849 #+BIBLIOGRAPHY: foo plain option:-d
17851 and derives from it that foo.bib is the bibliography file relevant
17852 for this document. It then installs the necessary environment for RefTeX
17853 to work in this buffer and calls `reftex-citation' to insert a citation
17856 Export of such citations to both LaTeX and HTML is handled by the contributed
17857 package org-exp-bibtex by Taru Karttunen."
17859 (let ((reftex-docstruct-symbol 'rds)
17860 (reftex-cite-format "\\cite{%l}")
17865 (let ((case-fold-search t)
17866 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
17867 (if (not (save-excursion
17868 (or (re-search-forward re nil t)
17869 (re-search-backward re nil t))))
17870 (error "No bibliography defined in file")
17871 (setq bib (concat (match-string 1) ".bib")
17872 rds (list (list 'bib bib)))))))
17873 (call-interactively 'reftex-citation)))
17875 ;;;; Functions extending outline functionality
17877 (defun org-beginning-of-line (&optional arg)
17878 "Go to the beginning of the current line. If that is invisible, continue
17879 to a visible line beginning. This makes the function of C-a more intuitive.
17880 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17881 first attempt, and only move to after the tags when the cursor is already
17882 beyond the end of the headline."
17884 (let ((pos (point))
17885 (special (if (consp org-special-ctrl-a/e)
17886 (car org-special-ctrl-a/e)
17887 org-special-ctrl-a/e))
17889 (if (org-bound-and-true-p line-move-visual)
17890 (beginning-of-visual-line 1)
17891 (beginning-of-line 1))
17892 (if (and arg (fboundp 'move-beginning-of-line))
17893 (call-interactively 'move-beginning-of-line)
17897 (if (org-invisible-p)
17898 (while (and (not (bobp)) (org-invisible-p))
17900 (beginning-of-line 1))
17901 (forward-char 1))))
17904 ((and (looking-at org-complex-heading-regexp)
17905 (= (char-after (match-end 1)) ?\ ))
17906 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
17910 (cond ((> pos refpos) refpos)
17911 ((= pos (point)) refpos)
17913 (cond ((> pos (point)) (point))
17914 ((not (eq last-command this-command)) (point))
17919 (cond ((> pos (match-end 4)) (match-end 4))
17920 ((= pos (point)) (match-end 4))
17922 (cond ((> pos (point)) (point))
17923 ((not (eq last-command this-command)) (point))
17924 (t (match-end 4))))))))
17926 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17928 (defun org-end-of-line (&optional arg)
17929 "Go to the end of the line.
17930 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
17931 first attempt, and only move to after the tags when the cursor is already
17932 beyond the end of the headline."
17934 (let ((special (if (consp org-special-ctrl-a/e)
17935 (cdr org-special-ctrl-a/e)
17936 org-special-ctrl-a/e)))
17937 (if (or (not special)
17938 (not (org-on-heading-p))
17940 (call-interactively
17941 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
17942 ((fboundp 'move-end-of-line) 'move-end-of-line)
17944 (let ((pos (point)))
17945 (beginning-of-line 1)
17946 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
17948 (if (or (< pos (match-beginning 1))
17949 (= pos (match-end 0)))
17950 (goto-char (match-beginning 1))
17951 (goto-char (match-end 0)))
17952 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
17953 (goto-char (match-end 0))
17954 (goto-char (match-beginning 1))))
17955 (call-interactively (if (fboundp 'move-end-of-line)
17959 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
17961 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
17962 (define-key org-mode-map "\C-e" 'org-end-of-line)
17963 (define-key org-mode-map [home] 'org-beginning-of-line)
17964 (define-key org-mode-map [end] 'org-end-of-line)
17966 (defun org-backward-sentence (&optional arg)
17967 "Go to beginning of sentence, or beginning of table field.
17968 This will call `backward-sentence' or `org-table-beginning-of-field',
17969 depending on context."
17972 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
17973 (t (call-interactively 'backward-sentence))))
17975 (defun org-forward-sentence (&optional arg)
17976 "Go to end of sentence, or end of table field.
17977 This will call `forward-sentence' or `org-table-end-of-field',
17978 depending on context."
17981 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
17982 (t (call-interactively 'forward-sentence))))
17984 (define-key org-mode-map "\M-a" 'org-backward-sentence)
17985 (define-key org-mode-map "\M-e" 'org-forward-sentence)
17987 (defun org-kill-line (&optional arg)
17988 "Kill line, to tags or end of line."
17991 ((or (not org-special-ctrl-k)
17993 (not (org-on-heading-p)))
17994 (call-interactively 'kill-line))
17995 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
17996 (kill-region (point) (match-beginning 1))
17997 (org-set-tags nil t))
17998 (t (kill-region (point) (point-at-eol)))))
18000 (define-key org-mode-map "\C-k" 'org-kill-line)
18002 (defun org-yank (&optional arg)
18003 "Yank. If the kill is a subtree, treat it specially.
18004 This command will look at the current kill and check if is a single
18005 subtree, or a series of subtrees[1]. If it passes the test, and if the
18006 cursor is at the beginning of a line or after the stars of a currently
18007 empty headline, then the yank is handled specially. How exactly depends
18008 on the value of the following variables, both set by default.
18010 org-yank-folded-subtrees
18011 When set, the subtree(s) will be folded after insertion, but only
18012 if doing so would now swallow text after the yanked text.
18014 org-yank-adjusted-subtrees
18015 When set, the subtree will be promoted or demoted in order to
18016 fit into the local outline tree structure, which means that the level
18017 will be adjusted so that it becomes the smaller one of the two
18018 *visible* surrounding headings.
18020 Any prefix to this command will cause `yank' to be called directly with
18021 no special treatment. In particular, a simple `C-u' prefix will just
18022 plainly yank the text as it is.
18024 \[1] The test checks if the first non-white line is a heading
18025 and if there are no other headings with fewer stars."
18027 (org-yank-generic 'yank arg))
18029 (defun org-yank-generic (command arg)
18030 "Perform some yank-like command.
18032 This function implements the behavior described in the `org-yank'
18033 documentation. However, it has been generalized to work for any
18034 interactive command with similar behavior."
18036 ;; pretend to be command COMMAND
18037 (setq this-command command)
18040 (call-interactively command)
18042 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18043 (and (org-kill-is-subtree-p)
18045 (and (looking-at "[ \t]*$")
18048 (buffer-substring (point-at-bol) (point)))))))
18051 ((and subtreep org-yank-folded-subtrees)
18052 (let ((beg (point))
18054 (if (and subtreep org-yank-adjusted-subtrees)
18055 (org-paste-subtree nil nil 'for-yank)
18056 (call-interactively command))
18060 (when (and (bolp) subtreep
18061 (not (setq swallowp
18062 (org-yank-folding-would-swallow-text beg end))))
18063 (or (looking-at outline-regexp)
18064 (re-search-forward (concat "^" outline-regexp) end t))
18065 (while (and (< (point) end) (looking-at outline-regexp))
18067 (org-cycle-show-empty-lines 'folded)
18068 (condition-case nil
18069 (outline-forward-same-level 1)
18070 (error (goto-char end)))))
18073 "Inserted text not folded because that would swallow text"))
18076 (skip-chars-forward " \t\n\r")
18077 (beginning-of-line 1)
18078 (push-mark beg 'nomsg)))
18079 ((and subtreep org-yank-adjusted-subtrees)
18080 (let ((beg (point-at-bol)))
18081 (org-paste-subtree nil nil 'for-yank)
18082 (push-mark beg 'nomsg)))
18084 (call-interactively command))))))
18086 (defun org-yank-folding-would-swallow-text (beg end)
18087 "Would hide-subtree at BEG swallow any text after END?"
18091 (when (or (looking-at outline-regexp)
18092 (re-search-forward (concat "^" outline-regexp) end t))
18093 (setq level (org-outline-level)))
18095 (skip-chars-forward " \t\r\n\v\f")
18097 (and (bolp) (looking-at org-outline-regexp)
18098 (<= (org-outline-level) level)))
18099 nil ; Nothing would be swallowed
18100 t)))) ; something would swallow
18102 (define-key org-mode-map "\C-y" 'org-yank)
18104 (defun org-invisible-p ()
18105 "Check if point is at a character currently not visible."
18106 ;; Early versions of noutline don't have `outline-invisible-p'.
18107 (if (fboundp 'outline-invisible-p)
18108 (outline-invisible-p)
18109 (get-char-property (point) 'invisible)))
18111 (defun org-invisible-p2 ()
18112 "Check if point is at a character currently not visible."
18114 (if (and (eolp) (not (bobp))) (backward-char 1))
18115 ;; Early versions of noutline don't have `outline-invisible-p'.
18116 (if (fboundp 'outline-invisible-p)
18117 (outline-invisible-p)
18118 (get-char-property (point) 'invisible))))
18120 (defun org-back-to-heading (&optional invisible-ok)
18121 "Call `outline-back-to-heading', but provide a better error message."
18122 (condition-case nil
18123 (outline-back-to-heading invisible-ok)
18124 (error (error "Before first headline at position %d in buffer %s"
18125 (point) (current-buffer)))))
18127 (defun org-before-first-heading-p ()
18128 "Before first heading?"
18130 (null (re-search-backward "^\\*+ " nil t))))
18132 (defun org-on-heading-p (&optional ignored)
18133 (outline-on-heading-p t))
18134 (defun org-at-heading-p (&optional ignored)
18135 (outline-on-heading-p t))
18137 (defun org-point-at-end-of-empty-headline ()
18138 "If point is at the end of an empty headline, return t, else nil.
18139 If the heading only contains a TODO keyword, it is still still considered
18141 (and (looking-at "[ \t]*$")
18143 (beginning-of-line 1)
18144 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18146 (defun org-at-heading-or-item-p ()
18147 (or (org-on-heading-p) (org-at-item-p)))
18149 (defun org-on-target-p ()
18150 (or (org-in-regexp org-radio-target-regexp)
18151 (org-in-regexp org-target-regexp)))
18153 (defun org-up-heading-all (arg)
18154 "Move to the heading line of which the present line is a subheading.
18155 This function considers both visible and invisible heading lines.
18156 With argument, move up ARG levels."
18157 (if (fboundp 'outline-up-heading-all)
18158 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18159 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18161 (defun org-up-heading-safe ()
18162 "Move to the heading line of which the present line is a subheading.
18163 This version will not throw an error. It will return the level of the
18164 headline found, or nil if no higher level is found.
18166 Also, this function will be a lot faster than `outline-up-heading',
18167 because it relies on stars being the outline starters. This can really
18168 make a significant difference in outlines with very many siblings."
18169 (let (start-level re)
18170 (org-back-to-heading t)
18171 (setq start-level (funcall outline-level))
18172 (if (equal start-level 1)
18174 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18175 (if (re-search-backward re nil t)
18176 (funcall outline-level)))))
18178 (defun org-first-sibling-p ()
18179 "Is this heading the first child of its parents?"
18181 (let ((re (concat "^" outline-regexp))
18183 (unless (org-at-heading-p t)
18184 (error "Not at a heading"))
18185 (setq level (funcall outline-level))
18187 (if (not (re-search-backward re nil t))
18189 (setq l (funcall outline-level))
18192 (defun org-goto-sibling (&optional previous)
18193 "Goto the next sibling, even if it is invisible.
18194 When PREVIOUS is set, go to the previous sibling instead. Returns t
18195 when a sibling was found. When none is found, return nil and don't
18197 (let ((fun (if previous 're-search-backward 're-search-forward))
18199 (re (concat "^" outline-regexp))
18201 (when (condition-case nil (org-back-to-heading t) (error nil))
18202 (setq level (funcall outline-level))
18204 (or previous (forward-char 1))
18205 (while (funcall fun re nil t)
18206 (setq l (funcall outline-level))
18207 (when (< l level) (goto-char pos) (throw 'exit nil))
18208 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18212 (defun org-show-siblings ()
18213 "Show all siblings of the current headline."
18215 (while (org-goto-sibling) (org-flag-heading nil)))
18217 (while (org-goto-sibling 'previous)
18218 (org-flag-heading nil))))
18220 (defun org-show-hidden-entry ()
18221 "Show an entry where even the heading is hidden."
18225 (defun org-flag-heading (flag &optional entry)
18226 "Flag the current heading. FLAG non-nil means make invisible.
18227 When ENTRY is non-nil, show the entire entry."
18229 (org-back-to-heading t)
18230 ;; Check if we should show the entire entry
18235 (and (outline-next-heading)
18236 (org-flag-heading nil))))
18237 (outline-flag-region (max (point-min) (1- (point)))
18238 (save-excursion (outline-end-of-heading) (point))
18241 (defun org-get-next-sibling ()
18242 "Move to next heading of the same level, and return point.
18243 If there is no such heading, return nil.
18244 This is like outline-next-sibling, but invisible headings are ok."
18245 (let ((level (funcall outline-level)))
18246 (outline-next-heading)
18247 (while (and (not (eobp)) (> (funcall outline-level) level))
18248 (outline-next-heading))
18249 (if (or (eobp) (< (funcall outline-level) level))
18253 (defun org-get-last-sibling ()
18254 "Move to previous heading of the same level, and return point.
18255 If there is no such heading, return nil."
18256 (let ((opoint (point))
18257 (level (funcall outline-level)))
18258 (outline-previous-heading)
18259 (when (and (/= (point) opoint) (outline-on-heading-p t))
18260 (while (and (> (funcall outline-level) level)
18262 (outline-previous-heading))
18263 (if (< (funcall outline-level) level)
18267 (defun org-end-of-subtree (&optional invisible-OK to-heading)
18268 ;; This contains an exact copy of the original function, but it uses
18269 ;; `org-back-to-heading', to make it work also in invisible
18270 ;; trees. And is uses an invisible-OK argument.
18271 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
18272 ;; Furthermore, when used inside Org, finding the end of a large subtree
18273 ;; with many children and grandchildren etc, this can be much faster
18274 ;; than the outline version.
18275 (org-back-to-heading invisible-OK)
18277 (level (funcall outline-level)))
18278 (if (and (org-mode-p) (< level 1000))
18279 ;; A true heading (not a plain list item), in Org-mode
18280 ;; This means we can easily find the end by looking
18281 ;; only for the right number of stars. Using a regexp to do
18282 ;; this is so much faster than using a Lisp loop.
18283 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
18285 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
18286 ;; something else, do it the slow way
18287 (while (and (not (eobp))
18288 (or first (> (funcall outline-level) level)))
18290 (outline-next-heading)))
18292 (if (memq (preceding-char) '(?\n ?\^M))
18294 ;; Go to end of line before heading
18296 (if (memq (preceding-char) '(?\n ?\^M))
18297 ;; leave blank line before heading
18298 (forward-char -1))))))
18301 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
18302 "Use Org version in org-mode, for dramatic speed-up."
18303 (if (eq major-mode 'org-mode)
18305 (org-end-of-subtree nil t)
18306 (unless (eobp) (backward-char 1)))
18309 (defun org-forward-same-level (arg &optional invisible-ok)
18310 "Move forward to the arg'th subheading at same level as this one.
18311 Stop at the first and last subheadings of a superior heading."
18313 (org-back-to-heading invisible-ok)
18315 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18316 (re (format "^\\*\\{1,%d\\} " level))
18320 (while (and (re-search-forward re nil 'move)
18321 (setq l (- (match-end 0) (match-beginning 0) 1))
18324 (progn (backward-char 1) (org-invisible-p)))
18325 (if (< l level) (setq arg 1)))
18326 (setq arg (1- arg)))
18327 (beginning-of-line 1)))
18329 (defun org-backward-same-level (arg &optional invisible-ok)
18330 "Move backward to the arg'th subheading at same level as this one.
18331 Stop at the first and last subheadings of a superior heading."
18333 (org-back-to-heading)
18335 (let* ((level (- (match-end 0) (match-beginning 0) 1))
18336 (re (format "^\\*\\{1,%d\\} " level))
18339 (while (and (re-search-backward re nil 'move)
18340 (setq l (- (match-end 0) (match-beginning 0) 1))
18344 (if (< l level) (setq arg 1)))
18345 (setq arg (1- arg)))))
18347 (defun org-show-subtree ()
18348 "Show everything after this heading at deeper levels."
18349 (outline-flag-region
18352 (org-end-of-subtree t t))
18355 (defun org-show-entry ()
18356 "Show the body directly following this heading.
18357 Show the heading too, if it is currently invisible."
18360 (condition-case nil
18362 (org-back-to-heading t)
18363 (outline-flag-region
18364 (max (point-min) (1- (point)))
18366 (if (re-search-forward
18367 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
18368 (match-beginning 1)
18371 (org-cycle-hide-drawers 'children))
18374 (defun org-make-options-regexp (kwds &optional extra)
18375 "Make a regular expression for keyword lines."
18379 (mapconcat 'regexp-quote kwds "\\|")
18380 (if extra (concat "\\|" extra))
18384 ;; Make isearch reveal the necessary context
18385 (defun org-isearch-end ()
18386 "Reveal context after isearch exits."
18387 (when isearch-success ; only if search was successful
18388 (if (featurep 'xemacs)
18389 ;; Under XEmacs, the hook is run in the correct place,
18390 ;; we directly show the context.
18391 (org-show-context 'isearch)
18392 ;; In Emacs the hook runs *before* restoring the overlays.
18393 ;; So we have to use a one-time post-command-hook to do this.
18394 ;; (Emacs 22 has a special variable, see function `org-mode')
18395 (unless (and (boundp 'isearch-mode-end-hook-quit)
18396 isearch-mode-end-hook-quit)
18397 ;; Only when the isearch was not quitted.
18398 (org-add-hook 'post-command-hook 'org-isearch-post-command
18399 'append 'local)))))
18401 (defun org-isearch-post-command ()
18402 "Remove self from hook, and show context."
18403 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
18404 (org-show-context 'isearch))
18407 ;;;; Integration with and fixes for other packages
18411 (defvar org-imenu-markers nil
18412 "All markers currently used by Imenu.")
18413 (make-variable-buffer-local 'org-imenu-markers)
18415 (defun org-imenu-new-marker (&optional pos)
18416 "Return a new marker for use by Imenu, and remember the marker."
18417 (let ((m (make-marker)))
18418 (move-marker m (or pos (point)))
18419 (push m org-imenu-markers)
18422 (defun org-imenu-get-tree ()
18423 "Produce the index for Imenu."
18424 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
18425 (setq org-imenu-markers nil)
18426 (let* ((n org-imenu-depth)
18427 (re (concat "^" outline-regexp))
18428 (subs (make-vector (1+ n) nil))
18434 (goto-char (point-max))
18435 (while (re-search-backward re nil t)
18436 (setq level (org-reduced-level (funcall outline-level)))
18438 (looking-at org-complex-heading-regexp)
18439 (setq head (org-link-display-format
18440 (org-match-string-no-properties 4))
18441 m (org-imenu-new-marker))
18442 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
18443 (if (>= level last-level)
18444 (push (cons head m) (aref subs level))
18445 (push (cons head (aref subs (1+ level))) (aref subs level))
18446 (loop for i from (1+ level) to n do (aset subs i nil)))
18447 (setq last-level level)))))
18450 (eval-after-load "imenu"
18452 (add-hook 'imenu-after-jump-hook
18454 (if (eq major-mode 'org-mode)
18455 (org-show-context 'org-goto))))))
18457 (defun org-link-display-format (link)
18458 "Replace a link with either the description, or the link target
18459 if no description is present"
18461 (if (string-match org-bracket-link-analytic-regexp link)
18462 (replace-match (if (match-end 5)
18463 (match-string 5 link)
18464 (concat (match-string 1 link)
18465 (match-string 3 link)))
18469 ;; Speedbar support
18471 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
18472 "Overlay marking the agenda restriction line in speedbar.")
18473 (overlay-put org-speedbar-restriction-lock-overlay
18474 'face 'org-agenda-restriction-lock)
18475 (overlay-put org-speedbar-restriction-lock-overlay
18476 'help-echo "Agendas are currently limited to this item.")
18477 (org-detach-overlay org-speedbar-restriction-lock-overlay)
18479 (defun org-speedbar-set-agenda-restriction ()
18480 "Restrict future agenda commands to the location at point in speedbar.
18481 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
18483 (require 'org-agenda)
18484 (let (p m tp np dir txt)
18486 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18488 (setq m (get-text-property p 'org-imenu-marker))
18489 (with-current-buffer (marker-buffer m)
18491 (org-agenda-set-restriction-lock 'subtree)))
18492 ((setq p (text-property-any (point-at-bol) (point-at-eol)
18493 'speedbar-function 'speedbar-find-file))
18494 (setq tp (previous-single-property-change
18495 (1+ p) 'speedbar-function)
18496 np (next-single-property-change
18497 tp 'speedbar-function)
18498 dir (speedbar-line-directory)
18499 txt (buffer-substring-no-properties (or tp (point-min))
18500 (or np (point-max))))
18501 (with-current-buffer (find-file-noselect
18502 (let ((default-directory dir))
18503 (expand-file-name txt)))
18504 (unless (org-mode-p)
18505 (error "Cannot restrict to non-Org-mode file"))
18506 (org-agenda-set-restriction-lock 'file)))
18507 (t (error "Don't know how to restrict Org-mode's agenda")))
18508 (move-overlay org-speedbar-restriction-lock-overlay
18509 (point-at-bol) (point-at-eol))
18510 (setq current-prefix-arg nil)
18511 (org-agenda-maybe-redo)))
18513 (eval-after-load "speedbar"
18515 (speedbar-add-supported-extension ".org")
18516 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
18517 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
18518 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
18519 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
18520 (add-hook 'speedbar-visiting-tag-hook
18521 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
18524 ;;; Fixes and Hacks for problems with other packages
18526 ;; Make flyspell not check words in links, to not mess up our keymap
18527 (defun org-mode-flyspell-verify ()
18528 "Don't let flyspell put overlays at active buttons."
18529 (and (not (get-text-property (point) 'keymap))
18530 (not (get-text-property (point) 'org-no-flyspell))))
18532 (defun org-remove-flyspell-overlays-in (beg end)
18533 "Remove flyspell overlays in region."
18534 (and (org-bound-and-true-p flyspell-mode)
18535 (fboundp 'flyspell-delete-region-overlays)
18536 (flyspell-delete-region-overlays beg end))
18537 (add-text-properties beg end '(org-no-flyspell t)))
18539 ;; Make `bookmark-jump' shows the jump location if it was hidden.
18540 (eval-after-load "bookmark"
18541 '(if (boundp 'bookmark-after-jump-hook)
18542 ;; We can use the hook
18543 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
18544 ;; Hook not available, use advice
18545 (defadvice bookmark-jump (after org-make-visible activate)
18546 "Make the position visible."
18547 (org-bookmark-jump-unhide))))
18549 ;; Make sure saveplace shows the location if it was hidden
18550 (eval-after-load "saveplace"
18551 '(defadvice save-place-find-file-hook (after org-make-visible activate)
18552 "Make the position visible."
18553 (org-bookmark-jump-unhide)))
18555 ;; Make sure ecb shows the location if it was hidden
18556 (eval-after-load "ecb"
18557 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
18558 "Make hierarchy visible when jumping into location from ECB tree buffer."
18559 (if (eq major-mode 'org-mode)
18560 (org-show-context))))
18562 (defun org-bookmark-jump-unhide ()
18563 "Unhide the current position, to show the bookmark location."
18565 (or (org-invisible-p)
18566 (save-excursion (goto-char (max (point-min) (1- (point))))
18567 (org-invisible-p)))
18568 (org-show-context 'bookmark-jump)))
18570 ;; Make session.el ignore our circular variable
18571 (eval-after-load "session"
18572 '(add-to-list 'session-globals-exclude 'org-mark-ring))
18574 ;;;; Experimental code
18576 (defun org-closed-in-range ()
18577 "Sparse tree of items closed in a certain time range.
18578 Still experimental, may disappear in the future."
18580 ;; Get the time interval from the user.
18581 (let* ((time1 (org-float-time
18582 (org-read-date nil 'to-time nil "Starting date: ")))
18583 (time2 (org-float-time
18584 (org-read-date nil 'to-time nil "End date:")))
18585 ;; callback function
18586 (callback (lambda ()
18589 (apply 'encode-time
18590 (org-parse-time-string
18591 (match-string 1))))))
18592 ;; check if time in interval
18593 (and (>= time time1) (<= time time2))))))
18594 ;; make tree, check each match with the callback
18595 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
18601 (run-hooks 'org-load-hook)
18603 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
18605 ;;; org.el ends here