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 (when (fboundp 'defvaralias
)
80 (unless (boundp 'calendar-view-holidays-initially-flag
)
81 (defvaralias 'calendar-view-holidays-initially-flag
82 'view-calendar-holidays-initially
))
83 (unless (boundp 'calendar-view-diary-initially-flag
)
84 (defvaralias 'calendar-view-diary-initially-flag
85 'view-diary-entries-initially
))
86 (unless (boundp 'diary-fancy-buffer
)
87 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
)))
89 ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
90 ;; the file noutline.el being loaded.
91 (if (featurep 'xemacs
) (condition-case nil
(require 'noutline
)))
92 ;; We require noutline, which might be provided in outline.el
93 (require 'outline
) (require 'noutline
)
94 ;; Other stuff we need.
96 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
101 (require 'org-entities
)
102 (require 'org-compat
)
106 (require 'org-footnote
)
117 ;; load languages based on value of `org-babel-load-languages'
118 (defvar org-babel-load-languages
)
120 (defun org-babel-do-load-languages (sym value
)
121 "Load the languages defined in `org-babel-load-languages'."
122 (set-default sym value
)
124 (let ((active (cdr pair
)) (lang (symbol-name (car pair
))))
127 (require (intern (concat "ob-" lang
))))
129 (funcall 'fmakunbound
130 (intern (concat "org-babel-execute:" lang
)))
131 (funcall 'fmakunbound
132 (intern (concat "org-babel-expand-body:" lang
)))))))
133 org-babel-load-languages
))
135 (defcustom org-babel-load-languages
'((emacs-lisp . t
))
136 "Languages which can be evaluated in Org-mode buffers. This
137 list can be used to load support for any of the languages below,
138 note that each language will depend on a different set of system
139 executables and/or Emacs modes. When a language is \"loaded\",
140 then code blocks in that language can be evaluated with
141 `org-babel-execute-src-block' bound by default to C-c C-c (note
142 the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can be set to
143 remove code block evaluation from the C-c C-c keybinding. By
144 default only Emacs Lisp (which has no requirements) is loaded."
146 :set
'org-babel-do-load-languages
147 :type
'(alist :tag
"Babel Languages"
152 (const :tag
"Asymptote" asymptote
)
153 (const :tag
"Clojure" clojure
)
154 (const :tag
"CSS" css
)
155 (const :tag
"Ditaa" ditaa
)
156 (const :tag
"Dot" dot
)
157 (const :tag
"Emacs Lisp" emacs-lisp
)
158 (const :tag
"Gnuplot" gnuplot
)
159 (const :tag
"Haskell" haskell
)
160 (const :tag
"Latex" latex
)
161 (const :tag
"Matlab" matlab
)
162 (const :tag
"Mscgen" mscgen
)
163 (const :tag
"Ocaml" ocaml
)
164 (const :tag
"Octave" octave
)
165 (const :tag
"Perl" perl
)
166 (const :tag
"Python" python
)
167 (const :tag
"Ruby" ruby
)
168 (const :tag
"Sass" sass
)
169 (const :tag
"Screen" screen
)
170 (const :tag
"Shell Script" sh
)
171 (const :tag
"Sql" sql
)
172 (const :tag
"Sqlite" sqlite
))
173 :value-type
(boolean :tag
"Activate" :value t
)))
175 ;;;; Customization variables
176 (defcustom org-clone-delete-id nil
177 "Remove ID property of clones of a subtree.
178 When non-nil, clones of a subtree don't inherit the ID property.
179 Otherwise they inherit the ID property with a new unique
186 (defconst org-version
"6.36trans"
187 "The version number of the file org.el.")
189 (defun org-version (&optional here
)
190 "Show the org-mode version in the echo area.
191 With prefix arg HERE, insert it at point."
193 (let* ((origin default-directory
)
194 (version org-version
)
196 (dir (concat (file-name-directory (locate-library "org")) "../" )))
197 (when (and (file-exists-p (expand-file-name ".git" dir
))
198 (executable-find "git"))
202 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
203 (with-current-buffer "*Shell Command Output*"
204 (goto-char (point-min))
205 (setq git-version
(buffer-substring (point) (point-at-eol))))
206 (subst-char-in-string ?- ?. git-version t
)
207 (when (string-match "\\S-"
208 (shell-command-to-string
209 "git diff-index --name-only HEAD --"))
210 (setq git-version
(concat git-version
".dirty")))
211 (setq version
(concat version
" (" git-version
")"))))
213 (setq version
(format "Org-mode version %s" version
))
214 (if here
(insert version
))
217 ;;; Compatibility constants
219 ;;; The custom variables
222 "Outline-based notes management and organizer."
227 (defcustom org-mode-hook nil
228 "Mode hook for Org-mode, run after the mode was turned on."
232 (defcustom org-load-hook nil
233 "Hook that is run after org.el has been loaded."
237 (defvar org-modules
) ; defined below
238 (defvar org-modules-loaded nil
239 "Have the modules been loaded already?")
241 (defun org-load-modules-maybe (&optional force
)
242 "Load all extensions listed in `org-modules'."
243 (when (or force
(not org-modules-loaded
))
245 (condition-case nil
(require ext
)
246 (error (message "Problems while trying to load feature `%s'" ext
))))
248 (setq org-modules-loaded t
)))
250 (defun org-set-modules (var value
)
251 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
253 (when (featurep 'org
)
254 (org-load-modules-maybe 'force
)))
256 (when (org-bound-and-true-p org-modules
)
257 (let ((a (member 'org-infojs org-modules
)))
258 (and a
(setcar a
'org-jsinfo
))))
260 (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
)
261 "Modules that should always be loaded together with org.el.
262 If a description starts with <C>, the file is not part of Emacs
263 and loading it will require that you have downloaded and properly installed
264 the org-mode distribution.
266 You can also use this system to load external packages (i.e. neither Org
267 core modules, nor modules from the CONTRIB directory). Just add symbols
268 to the end of the list. If the package is called org-xyz.el, then you need
269 to add the symbol `xyz', and the package must have a call to
273 :set
'org-set-modules
276 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
277 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
278 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
279 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
280 (const :tag
" docview: Links to doc-view buffers" org-docview
)
281 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
282 (const :tag
" id: Global IDs for identifying entries" org-id
)
283 (const :tag
" info: Links to Info nodes" org-info
)
284 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
285 (const :tag
" habit: Track your consistency with habits" org-habit
)
286 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
287 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
288 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
289 (const :tag
" mew Links to Mew folders/messages" org-mew
)
290 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
291 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
292 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
293 (const :tag
" vm: Links to VM folders/messages" org-vm
)
294 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
295 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
296 (const :tag
" mouse: Additional mouse support" org-mouse
)
298 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
299 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
300 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
301 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
302 (const :tag
"C collector: Collect properties into tables" org-collector
)
303 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
304 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
305 (const :tag
"C eval: Include command output as text" org-eval
)
306 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
307 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
308 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
309 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
310 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
312 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
314 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
315 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
316 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
317 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
318 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
319 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
320 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
321 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
322 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
323 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
324 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
325 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
326 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
327 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
328 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
329 (const :tag
"C track: Keep up with Org-mode development" org-track
)
330 (const :tag
"C TaskJuggler: Export tasks to a TaskJuggler project" org-taskjuggler
)
331 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
333 (defcustom org-support-shift-select nil
334 "Non-nil means make shift-cursor commands select text when possible.
336 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
337 selecting a region, or enlarge thusly regions started in this way.
338 In Org-mode, in special contexts, these same keys are used for other
339 purposes, important enough to compete with shift selection. Org tries
340 to balance these needs by supporting `shift-select-mode' outside these
341 special contexts, under control of this variable.
343 The default of this variable is nil, to avoid confusing behavior. Shifted
344 cursor keys will then execute Org commands in the following contexts:
345 - on a headline, changing TODO state (left/right) and priority (up/down)
346 - on a time stamp, changing the time
347 - in a plain list item, changing the bullet type
348 - in a property definition line, switching between allowed values
349 - in the BEGIN line of a clock table (changing the time block).
350 Outside these contexts, the commands will throw an error.
352 When this variable is t and the cursor is not in a special context,
353 Org-mode will support shift-selection for making and enlarging regions.
354 To make this more effective, the bullet cycling will no longer happen
355 anywhere in an item line, but only if the cursor is exactly on the bullet.
357 If you set this variable to the symbol `always', then the keys
358 will not be special in headlines, property lines, and item lines, to make
359 shift selection work there as well. If this is what you want, you can
360 use the following alternative commands: `C-c C-t' and `C-c ,' to
361 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
362 TODO sets, `C-c -' to cycle item bullet types, and properties can be
363 edited by hand or in column view.
365 However, when the cursor is on a timestamp, shift-cursor commands
366 will still edit the time stamp - this is just too good to give up.
368 XEmacs user should have this variable set to nil, because shift-select-mode
372 (const :tag
"Never" nil
)
373 (const :tag
"When outside special context" t
)
374 (const :tag
"Everywhere except timestamps" always
)))
376 (defgroup org-startup nil
377 "Options concerning startup of Org-mode."
381 (defcustom org-startup-folded t
382 "Non-nil means entering Org-mode will switch to OVERVIEW.
383 This can also be configured on a per-file basis by adding one of
384 the following lines anywhere in the buffer:
386 #+STARTUP: fold (or `overview', this is equivalent)
387 #+STARTUP: nofold (or `showall', this is equivalent)
389 #+STARTUP: showeverything"
392 (const :tag
"nofold: show all" nil
)
393 (const :tag
"fold: overview" t
)
394 (const :tag
"content: all headlines" content
)
395 (const :tag
"show everything, even drawers" showeverything
)))
397 (defcustom org-startup-truncated t
398 "Non-nil means entering Org-mode will set `truncate-lines'.
399 This is useful since some lines containing links can be very long and
400 uninteresting. Also tables look terrible when wrapped."
404 (defcustom org-startup-indented nil
405 "Non-nil means turn on `org-indent-mode' on startup.
406 This can also be configured on a per-file basis by adding one of
407 the following lines anywhere in the buffer:
411 :group
'org-structure
413 (const :tag
"Not" nil
)
414 (const :tag
"Globally (slow on startup in large files)" t
)))
416 (defcustom org-use-sub-superscripts t
417 "Non-nil means interpret \"_\" and \"^\" for export.
418 When this option is turned on, you can use TeX-like syntax for sub- and
419 superscripts. Several characters after \"_\" or \"^\" will be
420 considered as a single item - so grouping with {} is normally not
421 needed. For example, the following things will be parsed as single
422 sub- or superscripts.
424 10^24 or 10^tau several digits will be considered 1 item.
425 10^-12 or 10^-tau a leading sign with digits or a word
426 x^2-y^3 will be read as x^2 - y^3, because items are
427 terminated by almost any nonword/nondigit char.
428 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
430 Still, ambiguity is possible - so when in doubt use {} to enclose the
431 sub/superscript. If you set this variable to the symbol `{}',
432 the braces are *required* in order to trigger interpretations as
433 sub/superscript. This can be helpful in documents that need \"_\"
434 frequently in plain text.
436 Not all export backends support this, but HTML does.
438 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
440 :group
'org-export-translation
442 (const :tag
"Always interpret" t
)
443 (const :tag
"Only with braces" {})
444 (const :tag
"Never interpret" nil
)))
446 (if (fboundp 'defvaralias
)
447 (defvaralias 'org-export-with-sub-superscripts
'org-use-sub-superscripts
))
450 (defcustom org-startup-with-beamer-mode nil
451 "Non-nil means turn on `org-beamer-mode' on startup.
452 This can also be configured on a per-file basis by adding one of
453 the following lines anywhere in the buffer:
459 (defcustom org-startup-align-all-tables nil
460 "Non-nil means align all tables when visiting a file.
461 This is useful when the column width in tables is forced with <N> cookies
462 in table fields. Such tables will look correct only after the first re-align.
463 This can also be configured on a per-file basis by adding one of
464 the following lines anywhere in the buffer:
470 (defcustom org-insert-mode-line-in-empty-file nil
471 "Non-nil means insert the first line setting Org-mode in empty files.
472 When the function `org-mode' is called interactively in an empty file, this
473 normally means that the file name does not automatically trigger Org-mode.
474 To ensure that the file will always be in Org-mode in the future, a
475 line enforcing Org-mode will be inserted into the buffer, if this option
480 (defcustom org-replace-disputed-keys nil
481 "Non-nil means use alternative key bindings for some keys.
482 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
483 These keys are also used by other packages like shift-selection-mode'
484 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
485 If you want to use Org-mode together with one of these other modes,
486 or more generally if you would like to move some Org-mode commands to
487 other keys, set this variable and configure the keys with the variable
490 This option is only relevant at load-time of Org-mode, and must be set
491 *before* org.el is loaded. Changing it requires a restart of Emacs to
496 (defcustom org-use-extra-keys nil
497 "Non-nil means use extra key sequence definitions for certain
498 commands. This happens automatically if you run XEmacs or if
499 window-system is nil. This variable lets you do the same
500 manually. You must set it before loading org.
502 Example: on Carbon Emacs 22 running graphically, with an external
503 keyboard on a Powerbook, the default way of setting M-left might
504 not work for either Alt or ESC. Setting this variable will make
509 (if (fboundp 'defvaralias
)
510 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
512 (defcustom org-disputed-keys
513 '(([(shift up
)] .
[(meta p
)])
514 ([(shift down
)] .
[(meta n
)])
515 ([(shift left
)] .
[(meta -
)])
516 ([(shift right
)] .
[(meta +)])
517 ([(control shift right
)] .
[(meta shift
+)])
518 ([(control shift left
)] .
[(meta shift -
)]))
519 "Keys for which Org-mode and other modes compete.
520 This is an alist, cars are the default keys, second element specifies
521 the alternative to use when `org-replace-disputed-keys' is t.
523 Keys can be specified in any syntax supported by `define-key'.
524 The value of this option takes effect only at Org-mode's startup,
525 therefore you'll have to restart Emacs to apply it after changing."
530 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
531 Or return the original if not disputed.
532 Also apply the trnaslations defined in `org-xemacs-key-equivalents'."
533 (when org-replace-disputed-keys
534 (let* ((nkey (key-description key
))
535 (x (org-find-if (lambda (x)
536 (equal (key-description (car x
)) nkey
))
538 (setq key
(if x
(cdr x
) key
))))
539 (when (featurep 'xemacs
)
540 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
543 (defun org-find-if (predicate seq
)
546 (if (funcall predicate
(car seq
))
547 (throw 'exit
(car seq
))
550 (defun org-defkey (keymap key def
)
551 "Define a key, possibly translated, as returned by `org-key'."
552 (define-key keymap
(org-key key
) def
))
554 (defcustom org-ellipsis nil
555 "The ellipsis to use in the Org-mode outline.
556 When nil, just use the standard three dots. When a string, use that instead,
557 When a face, use the standard 3 dots, but with the specified face.
558 The change affects only Org-mode (which will then use its own display table).
559 Changing this requires executing `M-x org-mode' in a buffer to become
562 :type
'(choice (const :tag
"Default" nil
)
563 (face :tag
"Face" :value org-warning
)
564 (string :tag
"String" :value
"...#")))
566 (defvar org-display-table nil
567 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
569 (defgroup org-keywords nil
570 "Keywords in Org-mode."
574 (defcustom org-deadline-string
"DEADLINE:"
575 "String to mark deadline entries.
576 A deadline is this string, followed by a time stamp. Should be a word,
577 terminated by a colon. You can insert a schedule keyword and
578 a timestamp with \\[org-deadline].
579 Changes become only effective after restarting Emacs."
583 (defcustom org-scheduled-string
"SCHEDULED:"
584 "String to mark scheduled TODO entries.
585 A schedule is this string, followed by a time stamp. Should be a word,
586 terminated by a colon. You can insert a schedule keyword and
587 a timestamp with \\[org-schedule].
588 Changes become only effective after restarting Emacs."
592 (defcustom org-closed-string
"CLOSED:"
593 "String used as the prefix for timestamps logging closing a TODO entry."
597 (defcustom org-clock-string
"CLOCK:"
598 "String used as prefix for timestamps clocking work hours on an item."
602 (defcustom org-comment-string
"COMMENT"
603 "Entries starting with this keyword will never be exported.
604 An entry can be toggled between COMMENT and normal with
605 \\[org-toggle-comment].
606 Changes become only effective after restarting Emacs."
610 (defcustom org-quote-string
"QUOTE"
611 "Entries starting with this keyword will be exported in fixed-width font.
612 Quoting applies only to the text in the entry following the headline, and does
613 not extend beyond the next headline, even if that is lower level.
614 An entry can be toggled between QUOTE and normal with
615 \\[org-toggle-fixed-width-section]."
619 (defconst org-repeat-re
620 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
621 "Regular expression for specifying repeated events.
622 After a match, group 1 contains the repeat expression.")
624 (defgroup org-structure nil
625 "Options concerning the general structure of Org-mode files."
629 (defgroup org-reveal-location nil
630 "Options about how to make context of a location visible."
631 :tag
"Org Reveal Location"
632 :group
'org-structure
)
634 (defconst org-context-choice
636 (const :tag
"Always" t
)
637 (const :tag
"Never" nil
)
638 (repeat :greedy t
:tag
"Individual contexts"
640 (choice :tag
"Context"
647 (const bookmark-jump
)
651 "Contexts for the reveal options.")
653 (defcustom org-show-hierarchy-above
'((default . t
))
654 "Non-nil means show full hierarchy when revealing a location.
655 Org-mode often shows locations in an org-mode file which might have
656 been invisible before. When this is set, the hierarchy of headings
657 above the exposed location is shown.
658 Turning this off for example for sparse trees makes them very compact.
659 Instead of t, this can also be an alist specifying this option for different
660 contexts. Valid contexts are
661 agenda when exposing an entry from the agenda
662 org-goto when using the command `org-goto' on key C-c C-j
663 occur-tree when using the command `org-occur' on key C-c /
664 tags-tree when constructing a sparse tree based on tags matches
665 link-search when exposing search matches associated with a link
666 mark-goto when exposing the jump goal of a mark
667 bookmark-jump when exposing a bookmark location
668 isearch when exiting from an incremental search
669 default default for all contexts not set explicitly"
670 :group
'org-reveal-location
671 :type org-context-choice
)
673 (defcustom org-show-following-heading
'((default . nil
))
674 "Non-nil means show following heading when revealing a location.
675 Org-mode often shows locations in an org-mode file which might have
676 been invisible before. When this is set, the heading following the
678 Turning this off for example for sparse trees makes them very compact,
679 but makes it harder to edit the location of the match. In such a case,
680 use the command \\[org-reveal] to show more context.
681 Instead of t, this can also be an alist specifying this option for different
682 contexts. See `org-show-hierarchy-above' for valid contexts."
683 :group
'org-reveal-location
684 :type org-context-choice
)
686 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
687 "Non-nil means show all sibling heading when revealing a location.
688 Org-mode often shows locations in an org-mode file which might have
689 been invisible before. When this is set, the sibling of the current entry
690 heading are all made visible. If `org-show-hierarchy-above' is t,
691 the same happens on each level of the hierarchy above the current entry.
693 By default this is on for the isearch context, off for all other contexts.
694 Turning this off for example for sparse trees makes them very compact,
695 but makes it harder to edit the location of the match. In such a case,
696 use the command \\[org-reveal] to show more context.
697 Instead of t, this can also be an alist specifying this option for different
698 contexts. See `org-show-hierarchy-above' for valid contexts."
699 :group
'org-reveal-location
700 :type org-context-choice
)
702 (defcustom org-show-entry-below
'((default . nil
))
703 "Non-nil means show the entry below a headline when revealing a location.
704 Org-mode often shows locations in an org-mode file which might have
705 been invisible before. When this is set, the text below the headline that is
706 exposed is also shown.
708 By default this is off for all contexts.
709 Instead of t, this can also be an alist specifying this option for different
710 contexts. See `org-show-hierarchy-above' for valid contexts."
711 :group
'org-reveal-location
712 :type org-context-choice
)
714 (defcustom org-indirect-buffer-display
'other-window
715 "How should indirect tree buffers be displayed?
716 This applies to indirect buffers created with the commands
717 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
719 current-window Display in the current window
720 other-window Just display in another window.
721 dedicated-frame Create one new frame, and re-use it each time.
722 new-frame Make a new frame each time. Note that in this case
723 previously-made indirect buffers are kept, and you need to
724 kill these buffers yourself."
725 :group
'org-structure
726 :group
'org-agenda-windows
728 (const :tag
"In current window" current-window
)
729 (const :tag
"In current frame, other window" other-window
)
730 (const :tag
"Each time a new frame" new-frame
)
731 (const :tag
"One dedicated frame" dedicated-frame
)))
733 (defcustom org-use-speed-commands nil
734 "Non-nil means activate single letter commands at beginning of a headline.
735 This may also be a function to test for appropriate locations where speed
736 commands should be active."
737 :group
'org-structure
739 (const :tag
"Never" nil
)
740 (const :tag
"At beginning of headline stars" t
)
743 (defcustom org-speed-commands-user nil
744 "Alist of additional speed commands.
745 This list will be checked before `org-speed-commands-default'
746 when the variable `org-use-speed-commands' is non-nil
747 and when the cursor is at the beginning of a headline.
748 The car if each entry is a string with a single letter, which must
749 be assigned to `self-insert-command' in the global map.
750 The cdr is either a command to be called interactively, a function
751 to be called, or a form to be evaluated.
752 An entry that is just a list with a single string will be interpreted
753 as a descriptive headline that will be added when listing the speed
754 copmmands in the Help buffer using the `?' speed command."
755 :group
'org-structure
756 :type
'(repeat :value
("k" . ignore
)
757 (choice :value
("k" . ignore
)
758 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
759 (cons :tag
"Letter and Command"
760 (string :tag
"Command letter")
765 (defgroup org-cycle nil
766 "Options concerning visibility cycling in Org-mode."
768 :group
'org-structure
)
770 (defcustom org-cycle-skip-children-state-if-no-children t
771 "Non-nil means skip CHILDREN state in entries that don't have any."
775 (defcustom org-cycle-max-level nil
776 "Maximum level which should still be subject to visibility cycling.
777 Levels higher than this will, for cycling, be treated as text, not a headline.
778 When `org-odd-levels-only' is set, a value of N in this variable actually
779 means 2N-1 stars as the limiting headline.
780 When nil, cycle all levels.
781 Note that the limiting level of cycling is also influenced by
782 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
783 `org-inlinetask-min-level' is, cycling will be limited to levels one less
787 (const :tag
"No limit" nil
)
788 (integer :tag
"Maximum level")))
790 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
791 "Names of drawers. Drawers are not opened by cycling on the headline above.
792 Drawers only open with a TAB on the drawer line itself. A drawer looks like
797 The drawer \"PROPERTIES\" is special for capturing properties through
800 Drawers can be defined on the per-file basis with a line like:
802 #+DRAWERS: HIDDEN STATE PROPERTIES"
803 :group
'org-structure
805 :type
'(repeat (string :tag
"Drawer Name")))
807 (defcustom org-hide-block-startup nil
808 "Non-nil means entering Org-mode will fold all blocks.
809 This can also be set in on a per-file basis with
811 #+STARTUP: hideblocks
812 #+STARTUP: showblocks"
817 (defcustom org-cycle-global-at-bob nil
818 "Cycle globally if cursor is at beginning of buffer and not at a headline.
819 This makes it possible to do global cycling without having to use S-TAB or
820 C-u TAB. For this special case to work, the first line of the buffer
821 must not be a headline - it may be empty or some other text. When used in
822 this way, `org-cycle-hook' is disables temporarily, to make sure the
823 cursor stays at the beginning of the buffer.
824 When this option is nil, don't do anything special at the beginning
829 (defcustom org-cycle-level-after-item
/entry-creation t
830 "Non-nil means cycle entry level or item indentation in new empty entries.
832 When the cursor is at the end of an empty headline, i.e with only stars
833 and maybe a TODO keyword, TAB will then switch the entry to become a child,
834 and then all possible anchestor states, before returning to the original state.
835 This makes data entry extremely fast: M-RET to create a new headline,
836 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
838 When the cursor is at the end of an empty plain list item, one TAB will
839 make it a subitem, two or more tabs will back up to make this an item
840 higher up in the item hierarchy."
844 (defcustom org-cycle-emulate-tab t
845 "Where should `org-cycle' emulate TAB.
847 white Only in completely white lines
848 whitestart Only at the beginning of lines, before the first non-white char
849 t Everywhere except in headlines
850 exc-hl-bol Everywhere except at the start of a headline
851 If TAB is used in a place where it does not emulate TAB, the current subtree
852 visibility is cycled."
854 :type
'(choice (const :tag
"Never" nil
)
855 (const :tag
"Only in completely white lines" white
)
856 (const :tag
"Before first char in a line" whitestart
)
857 (const :tag
"Everywhere except in headlines" t
)
858 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
861 (defcustom org-cycle-separator-lines
2
862 "Number of empty lines needed to keep an empty line between collapsed trees.
863 If you leave an empty line between the end of a subtree and the following
864 headline, this empty line is hidden when the subtree is folded.
865 Org-mode will leave (exactly) one empty line visible if the number of
866 empty lines is equal or larger to the number given in this variable.
867 So the default 2 means at least 2 empty lines after the end of a subtree
868 are needed to produce free space between a collapsed subtree and the
871 If the number is negative, and the number of empty lines is at least -N,
872 all empty lines are shown.
874 Special case: when 0, never leave empty lines in collapsed view."
877 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
879 (defcustom org-pre-cycle-hook nil
880 "Hook that is run before visibility cycling is happening.
881 The function(s) in this hook must accept a single argument which indicates
882 the new state that will be set right after running this hook. The
883 argument is a symbol. Before a global state change, it can have the values
884 `overview', `content', or `all'. Before a local state change, it can have
885 the values `folded', `children', or `subtree'."
889 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
890 org-cycle-hide-drawers
891 org-cycle-show-empty-lines
892 org-optimize-window-after-visibility-change
)
893 "Hook that is run after `org-cycle' has changed the buffer visibility.
894 The function(s) in this hook must accept a single argument which indicates
895 the new state that was set by the most recent `org-cycle' command. The
896 argument is a symbol. After a global state change, it can have the values
897 `overview', `content', or `all'. After a local state change, it can have
898 the values `folded', `children', or `subtree'."
902 (defgroup org-edit-structure nil
903 "Options concerning structure editing in Org-mode."
904 :tag
"Org Edit Structure"
905 :group
'org-structure
)
907 (defcustom org-odd-levels-only nil
908 "Non-nil means skip even levels and only use odd levels for the outline.
909 This has the effect that two stars are being added/taken away in
910 promotion/demotion commands. It also influences how levels are
911 handled by the exporters.
912 Changing it requires restart of `font-lock-mode' to become effective
913 for fontification also in regions already fontified.
914 You may also set this on a per-file basis by adding one of the following
919 :group
'org-edit-structure
920 :group
'org-appearance
923 (defcustom org-adapt-indentation t
924 "Non-nil means adapt indentation to outline node level.
926 When this variable is set, Org assumes that you write outlines by
927 indenting text in each node to align with the headline (after the stars).
928 The following issues are influenced by this variable:
930 - When this is set and the *entire* text in an entry is indented, the
931 indentation is increased by one space in a demotion command, and
932 decreased by one in a promotion command. If any line in the entry
933 body starts with text at column 0, indentation is not changed at all.
935 - Property drawers and planning information is inserted indented when
936 this variable s set. When nil, they will not be indented.
938 - TAB indents a line relative to context. The lines below a headline
939 will be indented when this variable is set.
941 Note that this is all about true indentation, by adding and removing
942 space characters. See also `org-indent.el' which does level-dependent
943 indentation in a virtual way, i.e. at display time in Emacs."
944 :group
'org-edit-structure
947 (defcustom org-special-ctrl-a
/e nil
948 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
950 When t, `C-a' will bring back the cursor to the beginning of the
951 headline text, i.e. after the stars and after a possible TODO keyword.
952 In an item, this will be the position after the bullet.
953 When the cursor is already at that position, another `C-a' will bring
954 it to the beginning of the line.
956 `C-e' will jump to the end of the headline, ignoring the presence of tags
957 in the headline. A second `C-e' will then jump to the true end of the
958 line, after any tags. This also means that, when this variable is
959 non-nil, `C-e' also will never jump beyond the end of the heading of a
960 folded section, i.e. not after the ellipses.
962 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
963 going to the true line boundary first. Only a directly following, identical
964 keypress will bring the cursor to the special positions.
966 This may also be a cons cell where the behavior for `C-a' and `C-e' is
968 :group
'org-edit-structure
970 (const :tag
"off" nil
)
971 (const :tag
"on: after stars/bullet and before tags first" t
)
972 (const :tag
"reversed: true line boundary first" reversed
)
973 (cons :tag
"Set C-a and C-e separately"
974 (choice :tag
"Special C-a"
975 (const :tag
"off" nil
)
976 (const :tag
"on: after stars/bullet first" t
)
977 (const :tag
"reversed: before stars/bullet first" reversed
))
978 (choice :tag
"Special C-e"
979 (const :tag
"off" nil
)
980 (const :tag
"on: before tags first" t
)
981 (const :tag
"reversed: after tags first" reversed
)))))
982 (if (fboundp 'defvaralias
)
983 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
985 (defcustom org-special-ctrl-k nil
986 "Non-nil means `C-k' will behave specially in headlines.
987 When nil, `C-k' will call the default `kill-line' command.
988 When t, the following will happen while the cursor is in the headline:
990 - When the cursor is at the beginning of a headline, kill the entire
991 line and possible the folded subtree below the line.
992 - When in the middle of the headline text, kill the headline up to the tags.
993 - When after the headline text, kill the tags."
994 :group
'org-edit-structure
997 (defcustom org-ctrl-k-protect-subtree nil
998 "Non-nil means, do not delete a hidden subtree with C-k.
999 When set to the symbol `error', simply throw an error when C-k is
1000 used to kill (part-of) a headline that has hidden text behind it.
1001 Any other non-nil value will result in a query to the user, if it is
1002 OK to kill that hidden subtree. When nil, kill without remorse."
1003 :group
'org-edit-structure
1005 (const :tag
"Do not protect hidden subtrees" nil
)
1006 (const :tag
"Protect hidden subtrees with a security query" t
)
1007 (const :tag
"Never kill a hidden subtree with C-k" error
)))
1009 (defcustom org-yank-folded-subtrees t
1010 "Non-nil means when yanking subtrees, fold them.
1011 If the kill is a single subtree, or a sequence of subtrees, i.e. if
1012 it starts with a heading and all other headings in it are either children
1013 or siblings, then fold all the subtrees. However, do this only if no
1014 text after the yank would be swallowed into a folded tree by this action."
1015 :group
'org-edit-structure
1018 (defcustom org-yank-adjusted-subtrees nil
1019 "Non-nil means when yanking subtrees, adjust the level.
1020 With this setting, `org-paste-subtree' is used to insert the subtree, see
1021 this function for details."
1022 :group
'org-edit-structure
1025 (defcustom org-M-RET-may-split-line
'((default . t
))
1026 "Non-nil means M-RET will split the line at the cursor position.
1027 When nil, it will go to the end of the line before making a
1029 You may also set this option in a different way for different
1030 contexts. Valid contexts are:
1032 headline when creating a new headline
1033 item when creating a new item
1034 table in a table field
1035 default the value to be used for all contexts not explicitly
1037 :group
'org-structure
1040 (const :tag
"Always" t
)
1041 (const :tag
"Never" nil
)
1042 (repeat :greedy t
:tag
"Individual contexts"
1044 (choice :tag
"Context"
1052 (defcustom org-insert-heading-respect-content nil
1053 "Non-nil means insert new headings after the current subtree.
1054 When nil, the new heading is created directly after the current line.
1055 The commands \\[org-insert-heading-respect-content] and
1056 \\[org-insert-todo-heading-respect-content] turn this variable on
1057 for the duration of the command."
1058 :group
'org-structure
1061 (defcustom org-blank-before-new-entry
'((heading . auto
)
1062 (plain-list-item . auto
))
1063 "Should `org-insert-heading' leave a blank line before new heading/item?
1064 The value is an alist, with `heading' and `plain-list-item' as car,
1065 and a boolean flag as cdr. For plain lists, if the variable
1066 `org-empty-line-terminates-plain-lists' is set, the setting here
1067 is ignored and no empty line is inserted, to keep the list in tact."
1068 :group
'org-edit-structure
1070 (cons (const heading
)
1071 (choice (const :tag
"Never" nil
)
1072 (const :tag
"Always" t
)
1073 (const :tag
"Auto" auto
)))
1074 (cons (const plain-list-item
)
1075 (choice (const :tag
"Never" nil
)
1076 (const :tag
"Always" t
)
1077 (const :tag
"Auto" auto
)))))
1079 (defcustom org-insert-heading-hook nil
1080 "Hook being run after inserting a new heading."
1081 :group
'org-edit-structure
1084 (defcustom org-enable-fixed-width-editor t
1085 "Non-nil means lines starting with \":\" are treated as fixed-width.
1086 This currently only means they are never auto-wrapped.
1087 When nil, such lines will be treated like ordinary lines.
1088 See also the QUOTE keyword."
1089 :group
'org-edit-structure
1093 (defcustom org-goto-auto-isearch t
1094 "Non-nil means typing characters in org-goto starts incremental search."
1095 :group
'org-edit-structure
1098 (defgroup org-sparse-trees nil
1099 "Options concerning sparse trees in Org-mode."
1100 :tag
"Org Sparse Trees"
1101 :group
'org-structure
)
1103 (defcustom org-highlight-sparse-tree-matches t
1104 "Non-nil means highlight all matches that define a sparse tree.
1105 The highlights will automatically disappear the next time the buffer is
1106 changed by an edit command."
1107 :group
'org-sparse-trees
1110 (defcustom org-remove-highlights-with-change t
1111 "Non-nil means any change to the buffer will remove temporary highlights.
1112 Such highlights are created by `org-occur' and `org-clock-display'.
1113 When nil, `C-c C-c needs to be used to get rid of the highlights.
1114 The highlights created by `org-preview-latex-fragment' always need
1115 `C-c C-c' to be removed."
1116 :group
'org-sparse-trees
1121 (defcustom org-occur-hook
'(org-first-headline-recenter)
1122 "Hook that is run after `org-occur' has constructed a sparse tree.
1123 This can be used to recenter the window to show as much of the structure
1125 :group
'org-sparse-trees
1128 (defgroup org-imenu-and-speedbar nil
1129 "Options concerning imenu and speedbar in Org-mode."
1130 :tag
"Org Imenu and Speedbar"
1131 :group
'org-structure
)
1133 (defcustom org-imenu-depth
2
1134 "The maximum level for Imenu access to Org-mode headlines.
1135 This also applied for speedbar access."
1136 :group
'org-imenu-and-speedbar
1139 (defgroup org-table nil
1140 "Options concerning tables in Org-mode."
1144 (defcustom org-enable-table-editor
'optimized
1145 "Non-nil means lines starting with \"|\" are handled by the table editor.
1146 When nil, such lines will be treated like ordinary lines.
1148 When equal to the symbol `optimized', the table editor will be optimized to
1150 - Automatic overwrite mode in front of whitespace in table fields.
1151 This makes the structure of the table stay in tact as long as the edited
1152 field does not exceed the column width.
1153 - Minimize the number of realigns. Normally, the table is aligned each time
1154 TAB or RET are pressed to move to another field. With optimization this
1155 happens only if changes to a field might have changed the column width.
1156 Optimization requires replacing the functions `self-insert-command',
1157 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1158 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1159 very good at guessing when a re-align will be necessary, but you can always
1160 force one with \\[org-ctrl-c-ctrl-c].
1162 If you would like to use the optimized version in Org-mode, but the
1163 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1165 This variable can be used to turn on and off the table editor during a session,
1166 but in order to toggle optimization, a restart is required.
1168 See also the variable `org-table-auto-blank-field'."
1171 (const :tag
"off" nil
)
1173 (const :tag
"on, optimized" optimized
)))
1175 (defcustom org-self-insert-cluster-for-undo t
1176 "Non-nil means cluster self-insert commands for undo when possible.
1177 If this is set, then, like in the Emacs command loop, 20 consecutive
1178 characters will be undone together.
1179 This is configurable, because there is some impact on typing performance."
1183 (defcustom org-table-tab-recognizes-table.el t
1184 "Non-nil means TAB will automatically notice a table.el table.
1185 When it sees such a table, it moves point into it and - if necessary -
1186 calls `table-recognize-table'."
1187 :group
'org-table-editing
1190 (defgroup org-link nil
1191 "Options concerning links in Org-mode."
1195 (defvar org-link-abbrev-alist-local nil
1196 "Buffer-local version of `org-link-abbrev-alist', which see.
1197 The value of this is taken from the #+LINK lines.")
1198 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1200 (defcustom org-link-abbrev-alist nil
1201 "Alist of link abbreviations.
1202 The car of each element is a string, to be replaced at the start of a link.
1203 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1204 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1206 [[linkkey:tag][description]]
1208 The 'linkkey' must be a word word, starting with a letter, followed
1209 by letters, numbers, '-' or '_'.
1211 If REPLACE is a string, the tag will simply be appended to create the link.
1212 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1213 the placeholder \"%h\" will cause a url-encoded version of the tag to
1214 be inserted at that point (see the function `url-hexify-string').
1216 REPLACE may also be a function that will be called with the tag as the
1217 only argument to create the link, which should be returned as a string.
1219 See the manual for examples."
1223 (string :tag
"Protocol")
1225 (string :tag
"Format")
1228 (defcustom org-descriptive-links t
1229 "Non-nil means hide link part and only show description of bracket links.
1230 Bracket links are like [[link][description]]. This variable sets the initial
1231 state in new org-mode buffers. The setting can then be toggled on a
1232 per-buffer basis from the Org->Hyperlinks menu."
1236 (defcustom org-link-file-path-type
'adaptive
1237 "How the path name in file links should be stored.
1240 relative Relative to the current directory, i.e. the directory of the file
1241 into which the link is being inserted.
1242 absolute Absolute path, if possible with ~ for home directory.
1243 noabbrev Absolute path, no abbreviation of home directory.
1244 adaptive Use relative path for files in the current directory and sub-
1245 directories of it. For other files, use an absolute path."
1253 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1254 "Types of links that should be activated in Org-mode files.
1255 This is a list of symbols, each leading to the activation of a certain link
1256 type. In principle, it does not hurt to turn on most link types - there may
1257 be a small gain when turning off unused link types. The types are:
1259 bracket The recommended [[link][description]] or [[link]] links with hiding.
1260 angular Links in angular brackets that may contain whitespace like
1261 <bbdb:Carsten Dominik>.
1262 plain Plain links in normal text, no whitespace, like http://google.com.
1263 radio Text that is matched by a radio target, see manual for details.
1264 tag Tag settings in a headline (link to tag search).
1265 date Time stamps (link to calendar).
1266 footnote Footnote labels.
1268 Changing this variable requires a restart of Emacs to become effective."
1270 :type
'(set :greedy t
1271 (const :tag
"Double bracket links (new style)" bracket
)
1272 (const :tag
"Angular bracket links (old style)" angular
)
1273 (const :tag
"Plain text links" plain
)
1274 (const :tag
"Radio target matches" radio
)
1275 (const :tag
"Tags" tag
)
1276 (const :tag
"Timestamps" date
)
1277 (const :tag
"Footnotes" footnote
)))
1279 (defcustom org-make-link-description-function nil
1280 "Function to use to generate link descriptions from links. If
1281 nil the link location will be used. This function must take two
1282 parameters; the first is the link and the second the description
1283 org-insert-link has generated, and should return the description
1288 (defgroup org-link-store nil
1289 "Options concerning storing links in Org-mode."
1290 :tag
"Org Store Link"
1293 (defcustom org-email-link-description-format
"Email %c: %.30s"
1294 "Format of the description part of a link to an email or usenet message.
1295 The following %-escapes will be replaced by corresponding information:
1297 %F full \"From\" field
1298 %f name, taken from \"From\" field, address if no name
1299 %T full \"To\" field
1300 %t first name in \"To\" field, address if no name
1301 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1302 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1306 You may use normal field width specification between the % and the letter.
1307 This is for example useful to limit the length of the subject.
1309 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1310 :group
'org-link-store
1313 (defcustom org-from-is-user-regexp
1315 (when (and user-mail-address
(not (string= user-mail-address
"")))
1316 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1317 (when (and user-full-name
(not (string= user-full-name
"")))
1318 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1319 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1320 "Regexp matched against the \"From:\" header of an email or usenet message.
1321 It should match if the message is from the user him/herself."
1322 :group
'org-link-store
1325 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1326 "Non-nil means storing a link to an Org file will use entry IDs.
1328 Note that before this variable is even considered, org-id must be loaded,
1329 so please customize `org-modules' and turn it on.
1331 The variable can have the following values:
1333 t Create an ID if needed to make a link to the current entry.
1335 create-if-interactive
1336 If `org-store-link' is called directly (interactively, as a user
1337 command), do create an ID to support the link. But when doing the
1338 job for remember, only use the ID if it already exists. The
1339 purpose of this setting is to avoid proliferation of unwanted
1340 IDs, just because you happen to be in an Org file when you
1341 call `org-remember' that automatically and preemptively
1342 creates a link. If you do want to get an ID link in a remember
1343 template to an entry not having an ID, create it first by
1344 explicitly creating a link to it, using `C-c C-l' first.
1346 create-if-interactive-and-no-custom-id
1347 Like create-if-interactive, but do not create an ID if there is
1348 a CUSTOM_ID property defined in the entry. This is the default.
1351 Use existing ID, do not create one.
1353 nil Never use an ID to make a link, instead link using a text search for
1355 :group
'org-link-store
1357 (const :tag
"Create ID to make link" t
)
1358 (const :tag
"Create if storing link interactively"
1359 create-if-interactive
)
1360 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1361 create-if-interactive-and-no-custom-id
)
1362 (const :tag
"Only use existing" use-existing
)
1363 (const :tag
"Do not use ID to create link" nil
)))
1365 (defcustom org-context-in-file-links t
1366 "Non-nil means file links from `org-store-link' contain context.
1367 A search string will be added to the file name with :: as separator and
1368 used to find the context when the link is activated by the command
1369 `org-open-at-point'.
1370 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1371 negates this setting for the duration of the command."
1372 :group
'org-link-store
1375 (defcustom org-keep-stored-link-after-insertion nil
1376 "Non-nil means keep link in list for entire session.
1378 The command `org-store-link' adds a link pointing to the current
1379 location to an internal list. These links accumulate during a session.
1380 The command `org-insert-link' can be used to insert links into any
1381 Org-mode file (offering completion for all stored links). When this
1382 option is nil, every link which has been inserted once using \\[org-insert-link]
1383 will be removed from the list, to make completing the unused links
1385 :group
'org-link-store
1388 (defgroup org-link-follow nil
1389 "Options concerning following links in Org-mode."
1390 :tag
"Org Follow Link"
1393 (defcustom org-link-translation-function nil
1394 "Function to translate links with different syntax to Org syntax.
1395 This can be used to translate links created for example by the Planner
1396 or emacs-wiki packages to Org syntax.
1397 The function must accept two parameters, a TYPE containing the link
1398 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1399 which is everything after the link protocol. It should return a cons
1400 with possibly modified values of type and path.
1401 Org contains a function for this, so if you set this variable to
1402 `org-translate-link-from-planner', you should be able follow many
1403 links created by planner."
1404 :group
'org-link-follow
1407 (defcustom org-follow-link-hook nil
1408 "Hook that is run after a link has been followed."
1409 :group
'org-link-follow
1412 (defcustom org-tab-follows-link nil
1413 "Non-nil means on links TAB will follow the link.
1414 Needs to be set before org.el is loaded.
1415 This really should not be used, it does not make sense, and the
1416 implementation is bad."
1417 :group
'org-link-follow
1420 (defcustom org-return-follows-link nil
1421 "Non-nil means on links RET will follow the link."
1422 :group
'org-link-follow
1425 (defcustom org-mouse-1-follows-link
1426 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1427 "Non-nil means mouse-1 on a link will follow the link.
1428 A longer mouse click will still set point. Does not work on XEmacs.
1429 Needs to be set before org.el is loaded."
1430 :group
'org-link-follow
1433 (defcustom org-mark-ring-length
4
1434 "Number of different positions to be recorded in the ring
1435 Changing this requires a restart of Emacs to work correctly."
1436 :group
'org-link-follow
1439 (defcustom org-link-frame-setup
1440 '((vm . vm-visit-folder-other-frame
)
1441 (gnus . org-gnus-no-new-news
)
1442 (file . find-file-other-window
)
1443 (wl . wl-other-frame
))
1444 "Setup the frame configuration for following links.
1445 When following a link with Emacs, it may often be useful to display
1446 this link in another window or frame. This variable can be used to
1447 set this up for the different types of links.
1450 `vm-visit-folder-other-frame'
1451 For Gnus, use any of
1454 `org-gnus-no-new-news'
1455 For FILE, use any of
1457 `find-file-other-window'
1458 `find-file-other-frame'
1459 For Wanderlust use any of
1462 For the calendar, use the variable `calendar-setup'.
1463 For BBDB, it is currently only possible to display the matches in
1465 :group
'org-link-follow
1469 (const vm-visit-folder
)
1470 (const vm-visit-folder-other-window
)
1471 (const vm-visit-folder-other-frame
)))
1475 (const gnus-other-frame
)
1476 (const org-gnus-no-new-news
)))
1480 (const find-file-other-window
)
1481 (const find-file-other-frame
)))
1485 (const wl-other-frame
)))))
1487 (defcustom org-display-internal-link-with-indirect-buffer nil
1488 "Non-nil means use indirect buffer to display infile links.
1489 Activating internal links (from one location in a file to another location
1490 in the same file) normally just jumps to the location. When the link is
1491 activated with a C-u prefix (or with mouse-3), the link is displayed in
1492 another window. When this option is set, the other window actually displays
1493 an indirect buffer clone of the current buffer, to avoid any visibility
1494 changes to the current buffer."
1495 :group
'org-link-follow
1498 (defcustom org-open-non-existing-files nil
1499 "Non-nil means `org-open-file' will open non-existing files.
1500 When nil, an error will be generated.
1501 This variable applies only to external applications because they
1502 might choke on non-existing files. If the link is to a file that
1503 will be opened in Emacs, the variable is ignored."
1504 :group
'org-link-follow
1507 (defcustom org-open-directory-means-index-dot-org nil
1508 "Non-nil means a link to a directory really means to index.org.
1509 When nil, following a directory link will run dired or open a finder/explorer
1510 window on that directory."
1511 :group
'org-link-follow
1514 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1515 "Function and arguments to call for following mailto links.
1516 This is a list with the first element being a lisp function, and the
1517 remaining elements being arguments to the function. In string arguments,
1518 %a will be replaced by the address, and %s will be replaced by the subject
1519 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1520 :group
'org-link-follow
1522 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1523 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1524 (const :tag
"message-mail" (message-mail "%a" "%s"))
1525 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1527 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1528 "Non-nil means ask for confirmation before executing shell links.
1529 Shell links can be dangerous: just think about a link
1531 [[shell:rm -rf ~/*][Google Search]]
1533 This link would show up in your Org-mode document as \"Google Search\",
1534 but really it would remove your entire home directory.
1535 Therefore we advise against setting this variable to nil.
1536 Just change it to `y-or-n-p' if you want to confirm with a
1537 single keystroke rather than having to type \"yes\"."
1538 :group
'org-link-follow
1540 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1541 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1542 (const :tag
"no confirmation (dangerous)" nil
)))
1543 (put 'org-confirm-shell-link-function
1544 'safe-local-variable
1545 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1547 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1548 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1549 Elisp links can be dangerous: just think about a link
1551 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1553 This link would show up in your Org-mode document as \"Google Search\",
1554 but really it would remove your entire home directory.
1555 Therefore we advise against setting this variable to nil.
1556 Just change it to `y-or-n-p' if you want to confirm with a
1557 single keystroke rather than having to type \"yes\"."
1558 :group
'org-link-follow
1560 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1561 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1562 (const :tag
"no confirmation (dangerous)" nil
)))
1563 (put 'org-confirm-shell-link-function
1564 'safe-local-variable
1565 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1567 (defconst org-file-apps-defaults-gnu
1571 "Default file applications on a UNIX or GNU/Linux system.
1572 See `org-file-apps'.")
1574 (defconst org-file-apps-defaults-macosx
1577 (system .
"open %s")
1579 ("eps.gz" .
"gv %s")
1581 ("fig" .
"xfig %s"))
1582 "Default file applications on a MacOS X system.
1583 The system \"open\" is known as a default, but we use X11 applications
1584 for some files for which the OS does not have a good default.
1585 See `org-file-apps'.")
1587 (defconst org-file-apps-defaults-windowsnt
1591 (list (if (featurep 'xemacs
)
1592 'mswindows-shell-execute
1596 (list (if (featurep 'xemacs
)
1597 'mswindows-shell-execute
1600 "Default file applications on a Windows NT system.
1601 The system \"open\" is used for most files.
1602 See `org-file-apps'.")
1604 (defcustom org-file-apps
1607 ("\\.mm\\'" . default
)
1608 ("\\.x?html?\\'" . default
)
1609 ("\\.pdf\\'" . default
)
1611 "External applications for opening `file:path' items in a document.
1612 Org-mode uses system defaults for different file types, but
1613 you can use this variable to set the application for a given file
1614 extension. The entries in this list are cons cells where the car identifies
1615 files and the cdr the corresponding command. Possible values for the
1617 \"string\" A string as a file identifier can be interpreted in different
1618 ways, depending on its contents:
1620 - Alphanumeric characters only:
1621 Match links with this file extension.
1622 Example: (\"pdf\" . \"evince %s\")
1623 to open PDFs with evince.
1625 - Regular expression: Match links where the
1626 filename matches the regexp. If you want to
1627 use groups here, use shy groups.
1629 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1630 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1631 to open *.html and *.xhtml with firefox.
1633 - Regular expression which contains (non-shy) groups:
1634 Match links where the whole link, including \"::\", and
1635 anything after that, matches the regexp.
1636 In a custom command string, %1, %2, etc. are replaced with
1637 the parts of the link that were matched by the groups.
1638 For backwards compatibility, if a command string is given
1639 that does not use any of the group matches, this case is
1640 handled identically to the second one (i.e. match against
1643 In a custom lisp form, you can access the group matches with
1644 (match-string n link).
1646 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1647 to open [[file:document.pdf::5]] with evince at page 5.
1649 `directory' Matches a directory
1650 `remote' Matches a remote file, accessible through tramp or efs.
1651 Remote files most likely should be visited through Emacs
1652 because external applications cannot handle such paths.
1653 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1654 so all files Emacs knows how to handle. Using this with
1655 command `emacs' will open most files in Emacs. Beware that this
1656 will also open html files inside Emacs, unless you add
1657 (\"html\" . default) to the list as well.
1658 t Default for files not matched by any of the other options.
1659 `system' The system command to open files, like `open' on Windows
1660 and Mac OS X, and mailcap under GNU/Linux. This is the command
1661 that will be selected if you call `C-c C-o' with a double
1664 Possible values for the command are:
1665 `emacs' The file will be visited by the current Emacs process.
1666 `default' Use the default application for this file type, which is the
1667 association for t in the list, most likely in the system-specific
1669 This can be used to overrule an unwanted setting in the
1670 system-specific variable.
1671 `system' Use the system command for opening files, like \"open\".
1672 This command is specified by the entry whose car is `system'.
1673 Most likely, the system-specific version of this variable
1674 does define this command, but you can overrule/replace it
1676 string A command to be executed by a shell; %s will be replaced
1677 by the path to the file.
1678 sexp A Lisp form which will be evaluated. The file path will
1679 be available in the Lisp variable `file'.
1680 For more examples, see the system specific constants
1681 `org-file-apps-defaults-macosx'
1682 `org-file-apps-defaults-windowsnt'
1683 `org-file-apps-defaults-gnu'."
1684 :group
'org-link-follow
1686 (cons (choice :value
""
1687 (string :tag
"Extension")
1688 (const :tag
"System command to open files" system
)
1689 (const :tag
"Default for unrecognized files" t
)
1690 (const :tag
"Remote file" remote
)
1691 (const :tag
"Links to a directory" directory
)
1692 (const :tag
"Any files that have Emacs modes"
1695 (const :tag
"Visit with Emacs" emacs
)
1696 (const :tag
"Use default" default
)
1697 (const :tag
"Use the system command" system
)
1698 (string :tag
"Command")
1699 (sexp :tag
"Lisp form")))))
1703 (defgroup org-refile nil
1704 "Options concerning refiling entries in Org-mode."
1708 (defcustom org-directory
"~/org"
1709 "Directory with org files.
1710 This is just a default location to look for Org files. There is no need
1711 at all to put your files into this directory. It is only used in the
1712 following situations:
1714 1. When a remember template specifies a target file that is not an
1715 absolute path. The path will then be interpreted relative to
1717 2. When a remember note is filed away in an interactive way (when exiting the
1718 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1719 with `org-directory' as the default path."
1721 :group
'org-remember
1724 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1725 "Default target for storing notes.
1726 Used as a fall back file for org-remember.el and org-capture.el, for
1727 templates that do not specify a target file."
1729 :group
'org-remember
1731 (const :tag
"Default from remember-data-file" nil
)
1734 (defcustom org-goto-interface
'outline
1735 "The default interface to be used for `org-goto'.
1737 outline The interface shows an outline of the relevant file
1738 and the correct heading is found by moving through
1739 the outline or by searching with incremental search.
1740 outline-path-completion Headlines in the current buffer are offered via
1741 completion. This is the interface also used by
1742 the refile command."
1745 (const :tag
"Outline" outline
)
1746 (const :tag
"Outline-path-completion" outline-path-completion
)))
1748 (defcustom org-goto-max-level
5
1749 "Maximum level to be considered when running org-goto with refile interface."
1753 (defcustom org-reverse-note-order nil
1754 "Non-nil means store new notes at the beginning of a file or entry.
1755 When nil, new notes will be filed to the end of a file or entry.
1756 This can also be a list with cons cells of regular expressions that
1757 are matched against file names, and values."
1758 :group
'org-remember
1761 (const :tag
"Reverse always" t
)
1762 (const :tag
"Reverse never" nil
)
1763 (repeat :tag
"By file name regexp"
1764 (cons regexp boolean
))))
1766 (defcustom org-log-refile nil
1767 "Information to record when a task is refiled.
1769 Possible values are:
1771 nil Don't add anything
1772 time Add a time stamp to the task
1773 note Prompt for a note and add it with template `org-log-note-headings'
1775 This option can also be set with on a per-file-basis with
1777 #+STARTUP: nologrefile
1778 #+STARTUP: logrefile
1779 #+STARTUP: lognoterefile
1781 You can have local logging settings for a subtree by setting the LOGGING
1782 property to one or more of these keywords.
1784 When bulk-refiling from the agenda, the value `note' is forbidden and
1785 will temporarily be changed to `time'."
1787 :group
'org-progress
1789 (const :tag
"No logging" nil
)
1790 (const :tag
"Record timestamp" time
)
1791 (const :tag
"Record timestamp with note." note
)))
1793 (defcustom org-refile-targets nil
1794 "Targets for refiling entries with \\[org-refile].
1795 This is list of cons cells. Each cell contains:
1796 - a specification of the files to be considered, either a list of files,
1797 or a symbol whose function or variable value will be used to retrieve
1798 a file name or a list of file names. If you use `org-agenda-files' for
1799 that, all agenda files will be scanned for targets. Nil means consider
1800 headings in the current buffer.
1801 - A specification of how to find candidate refile targets. This may be
1803 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1804 This tag has to be present in all target headlines, inheritance will
1806 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1808 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1809 headlines that are refiling targets.
1810 - a cons cell (:level . N). Any headline of level N is considered a target.
1811 Note that, when `org-odd-levels-only' is set, level corresponds to
1812 order in hierarchy, not to the number of stars.
1813 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1814 Note that, when `org-odd-levels-only' is set, level corresponds to
1815 order in hierarchy, not to the number of stars.
1817 You can set the variable `org-refile-target-verify-function' to a function
1818 to verify each headline found by the simple critery above.
1820 When this variable is nil, all top-level headlines in the current buffer
1821 are used, equivalent to the value `((nil . (:level . 1))'."
1825 (choice :value org-agenda-files
1826 (const :tag
"All agenda files" org-agenda-files
)
1827 (const :tag
"Current buffer" nil
)
1828 (function) (variable) (file))
1829 (choice :tag
"Identify target headline by"
1830 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1831 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1832 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1833 (cons :tag
"Level number" (const :value
:level
) (integer))
1834 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1836 (defcustom org-refile-target-verify-function nil
1837 "Function to verify if the headline at point should be a refile target.
1838 The function will be called without arguments, with point at the
1839 beginning of the headline. It should return t and leave point
1840 where it is if the headline is a valid target for refiling.
1842 If the target should not be selected, the function must return nil.
1843 In addition to this, it may move point to a place from where the search
1844 should be continued. For example, the function may decide that the entire
1845 subtree of the current entry should be excluded and move point to the end
1850 (defcustom org-refile-use-cache nil
1851 "Non-nil means cache refile targets to speed up the process.
1852 The cache for a particular file will be updated automatically when
1853 the buffer has been killed, or when any of the marker used for flagging
1854 refile targets no longer points at a live buffer.
1855 If you have added new entries to a buffer that might themselves be targets,
1856 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
1857 find that easier, `C-u C-u C-u C-c C-w'."
1861 (defcustom org-refile-use-outline-path nil
1862 "Non-nil means provide refile targets as paths.
1863 So a level 3 headline will be available as level1/level2/level3.
1865 When the value is `file', also include the file name (without directory)
1866 into the path. In this case, you can also stop the completion after
1867 the file name, to get entries inserted as top level in the file.
1869 When `full-file-path', include the full file path."
1872 (const :tag
"Not" nil
)
1873 (const :tag
"Yes" t
)
1874 (const :tag
"Start with file name" file
)
1875 (const :tag
"Start with full file path" full-file-path
)))
1877 (defcustom org-outline-path-complete-in-steps t
1878 "Non-nil means complete the outline path in hierarchical steps.
1879 When Org-mode uses the refile interface to select an outline path
1880 \(see variable `org-refile-use-outline-path'), the completion of
1881 the path can be done is a single go, or if can be done in steps down
1882 the headline hierarchy. Going in steps is probably the best if you
1883 do not use a special completion package like `ido' or `icicles'.
1884 However, when using these packages, going in one step can be very
1885 fast, while still showing the whole path to the entry."
1889 (defcustom org-refile-allow-creating-parent-nodes nil
1890 "Non-nil means allow to create new nodes as refile targets.
1891 New nodes are then created by adding \"/new node name\" to the completion
1892 of an existing node. When the value of this variable is `confirm',
1893 new node creation must be confirmed by the user (recommended)
1894 When nil, the completion must match an existing entry.
1896 Note that, if the new heading is not seen by the criteria
1897 listed in `org-refile-targets', multiple instances of the same
1898 heading would be created by trying again to file under the new
1902 (const :tag
"Never" nil
)
1903 (const :tag
"Always" t
)
1904 (const :tag
"Prompt for confirmation" confirm
)))
1906 (defgroup org-todo nil
1907 "Options concerning TODO items in Org-mode."
1911 (defgroup org-progress nil
1912 "Options concerning Progress logging in Org-mode."
1916 (defvar org-todo-interpretation-widgets
1918 (:tag
"Sequence (cycling hits every state)" sequence
)
1919 (:tag
"Type (cycling directly to DONE)" type
))
1920 "The available interpretation symbols for customizing
1921 `org-todo-keywords'.
1922 Interested libraries should add to this list.")
1924 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
1925 "List of TODO entry keyword sequences and their interpretation.
1926 \\<org-mode-map>This is a list of sequences.
1928 Each sequence starts with a symbol, either `sequence' or `type',
1929 indicating if the keywords should be interpreted as a sequence of
1930 action steps, or as different types of TODO items. The first
1931 keywords are states requiring action - these states will select a headline
1932 for inclusion into the global TODO list Org-mode produces. If one of
1933 the \"keywords\" is the vertical bat \"|\" the remaining keywords
1934 signify that no further action is necessary. If \"|\" is not found,
1935 the last keyword is treated as the only DONE state of the sequence.
1937 The command \\[org-todo] cycles an entry through these states, and one
1938 additional state where no keyword is present. For details about this
1939 cycling, see the manual.
1941 TODO keywords and interpretation can also be set on a per-file basis with
1942 the special #+SEQ_TODO and #+TYP_TODO lines.
1944 Each keyword can optionally specify a character for fast state selection
1945 \(in combination with the variable `org-use-fast-todo-selection')
1946 and specifiers for state change logging, using the same syntax
1947 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
1948 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
1949 indicates to record a time stamp each time this state is selected.
1951 Each keyword may also specify if a timestamp or a note should be
1952 recorded when entering or leaving the state, by adding additional
1953 characters in the parenthesis after the keyword. This looks like this:
1954 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
1955 record only the time of the state change. With X and Y being either
1956 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
1957 Y when leaving the state if and only if the *target* state does not
1958 define X. You may omit any of the fast-selection key or X or /Y,
1959 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
1961 For backward compatibility, this variable may also be just a list
1962 of keywords - in this case the interpretation (sequence or type) will be
1963 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
1965 :group
'org-keywords
1967 (repeat :tag
"Old syntax, just keywords"
1968 (string :tag
"Keyword"))
1969 (repeat :tag
"New syntax"
1972 :tag
"Interpretation"
1973 ;;Quick and dirty way to see
1974 ;;`org-todo-interpretations'. This takes the
1975 ;;place of item arguments
1983 org-todo-interpretation-widgets
))
1986 (string :tag
"Keyword"))))))
1988 (defvar org-todo-keywords-1 nil
1989 "All TODO and DONE keywords active in a buffer.")
1990 (make-variable-buffer-local 'org-todo-keywords-1
)
1991 (defvar org-todo-keywords-for-agenda nil
)
1992 (defvar org-done-keywords-for-agenda nil
)
1993 (defvar org-drawers-for-agenda nil
)
1994 (defvar org-todo-keyword-alist-for-agenda nil
)
1995 (defvar org-tag-alist-for-agenda nil
)
1996 (defvar org-agenda-contributing-files nil
)
1997 (defvar org-not-done-keywords nil
)
1998 (make-variable-buffer-local 'org-not-done-keywords
)
1999 (defvar org-done-keywords nil
)
2000 (make-variable-buffer-local 'org-done-keywords
)
2001 (defvar org-todo-heads nil
)
2002 (make-variable-buffer-local 'org-todo-heads
)
2003 (defvar org-todo-sets nil
)
2004 (make-variable-buffer-local 'org-todo-sets
)
2005 (defvar org-todo-log-states nil
)
2006 (make-variable-buffer-local 'org-todo-log-states
)
2007 (defvar org-todo-kwd-alist nil
)
2008 (make-variable-buffer-local 'org-todo-kwd-alist
)
2009 (defvar org-todo-key-alist nil
)
2010 (make-variable-buffer-local 'org-todo-key-alist
)
2011 (defvar org-todo-key-trigger nil
)
2012 (make-variable-buffer-local 'org-todo-key-trigger
)
2014 (defcustom org-todo-interpretation
'sequence
2015 "Controls how TODO keywords are interpreted.
2016 This variable is in principle obsolete and is only used for
2017 backward compatibility, if the interpretation of todo keywords is
2018 not given already in `org-todo-keywords'. See that variable for
2021 :group
'org-keywords
2022 :type
'(choice (const sequence
)
2025 (defcustom org-use-fast-todo-selection t
2026 "Non-nil means use the fast todo selection scheme with C-c C-t.
2027 This variable describes if and under what circumstances the cycling
2028 mechanism for TODO keywords will be replaced by a single-key, direct
2031 When nil, fast selection is never used.
2033 When the symbol `prefix', it will be used when `org-todo' is called with
2034 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
2035 in an agenda buffer.
2037 When t, fast selection is used by default. In this case, the prefix
2038 argument forces cycling instead.
2040 In all cases, the special interface is only used if access keys have actually
2041 been assigned by the user, i.e. if keywords in the configuration are followed
2042 by a letter in parenthesis, like TODO(t)."
2045 (const :tag
"Never" nil
)
2046 (const :tag
"By default" t
)
2047 (const :tag
"Only with C-u C-c C-t" prefix
)))
2049 (defcustom org-provide-todo-statistics t
2050 "Non-nil means update todo statistics after insert and toggle.
2051 ALL-HEADLINES means update todo statistics by including headlines
2052 with no TODO keyword as well, counting them as not done.
2053 A list of TODO keywords means the same, but skip keywords that are
2056 When this is set, todo statistics is updated in the parent of the
2057 current entry each time a todo state is changed."
2060 (const :tag
"Yes, only for TODO entries" t
)
2061 (const :tag
"Yes, including all entries" 'all-headlines
)
2062 (repeat :tag
"Yes, for TODOs in this list"
2063 (string :tag
"TODO keyword"))
2064 (other :tag
"No TODO statistics" nil
)))
2066 (defcustom org-hierarchical-todo-statistics t
2067 "Non-nil means TODO statistics covers just direct children.
2068 When nil, all entries in the subtree are considered.
2069 This has only an effect if `org-provide-todo-statistics' is set.
2070 To set this to nil for only a single subtree, use a COOKIE_DATA
2071 property and include the word \"recursive\" into the value."
2075 (defcustom org-after-todo-state-change-hook nil
2076 "Hook which is run after the state of a TODO item was changed.
2077 The new state (a string with a TODO keyword, or nil) is available in the
2078 Lisp variable `state'."
2082 (defvar org-blocker-hook nil
2083 "Hook for functions that are allowed to block a state change.
2085 Each function gets as its single argument a property list, see
2086 `org-trigger-hook' for more information about this list.
2088 If any of the functions in this hook returns nil, the state change
2091 (defvar org-trigger-hook nil
2092 "Hook for functions that are triggered by a state change.
2094 Each function gets as its single argument a property list with at least
2095 the following elements:
2097 (:type type-of-change :position pos-at-entry-start
2098 :from old-state :to new-state)
2100 Depending on the type, more properties may be present.
2102 This mechanism is currently implemented for:
2106 :type todo-state-change
2107 :from previous state (keyword as a string), or nil, or a symbol
2108 'todo' or 'done', to indicate the general type of state.
2109 :to new state, like in :from")
2111 (defcustom org-enforce-todo-dependencies nil
2112 "Non-nil means undone TODO entries will block switching the parent to DONE.
2113 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2114 be blocked if any prior sibling is not yet done.
2115 Finally, if the parent is blocked because of ordered siblings of its own,
2116 the child will also be blocked.
2117 This variable needs to be set before org.el is loaded, and you need to
2118 restart Emacs after a change to make the change effective. The only way
2119 to change is while Emacs is running is through the customize interface."
2120 :set
(lambda (var val
)
2123 (add-hook 'org-blocker-hook
2124 'org-block-todo-from-children-or-siblings-or-parent
)
2125 (remove-hook 'org-blocker-hook
2126 'org-block-todo-from-children-or-siblings-or-parent
)))
2130 (defcustom org-enforce-todo-checkbox-dependencies nil
2131 "Non-nil means unchecked boxes will block switching the parent to DONE.
2132 When this is nil, checkboxes have no influence on switching TODO states.
2133 When non-nil, you first need to check off all check boxes before the TODO
2134 entry can be switched to DONE.
2135 This variable needs to be set before org.el is loaded, and you need to
2136 restart Emacs after a change to make the change effective. The only way
2137 to change is while Emacs is running is through the customize interface."
2138 :set
(lambda (var val
)
2141 (add-hook 'org-blocker-hook
2142 'org-block-todo-from-checkboxes
)
2143 (remove-hook 'org-blocker-hook
2144 'org-block-todo-from-checkboxes
)))
2148 (defcustom org-treat-insert-todo-heading-as-state-change nil
2149 "Non-nil means inserting a TODO heading is treated as state change.
2150 So when the command \\[org-insert-todo-heading] is used, state change
2151 logging will apply if appropriate. When nil, the new TODO item will
2152 be inserted directly, and no logging will take place."
2156 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2157 "Non-nil means switching TODO states with S-cursor counts as state change.
2158 This is the default behavior. However, setting this to nil allows a
2159 convenient way to select a TODO state and bypass any logging associated
2164 (defcustom org-todo-state-tags-triggers nil
2165 "Tag changes that should be triggered by TODO state changes.
2166 This is a list. Each entry is
2168 (state-change (tag . flag) .......)
2170 State-change can be a string with a state, and empty string to indicate the
2171 state that has no TODO keyword, or it can be one of the symbols `todo'
2172 or `done', meaning any not-done or done state, respectively."
2176 (cons (choice :tag
"When changing to"
2177 (const :tag
"Not-done state" todo
)
2178 (const :tag
"Done state" done
)
2179 (string :tag
"State"))
2181 (cons :tag
"Tag action"
2183 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2185 (defcustom org-log-done nil
2186 "Information to record when a task moves to the DONE state.
2188 Possible values are:
2190 nil Don't add anything, just change the keyword
2191 time Add a time stamp to the task
2192 note Prompt for a note and add it with template `org-log-note-headings'
2194 This option can also be set with on a per-file-basis with
2196 #+STARTUP: nologdone
2198 #+STARTUP: lognotedone
2200 You can have local logging settings for a subtree by setting the LOGGING
2201 property to one or more of these keywords."
2203 :group
'org-progress
2205 (const :tag
"No logging" nil
)
2206 (const :tag
"Record CLOSED timestamp" time
)
2207 (const :tag
"Record CLOSED timestamp with note." note
)))
2209 ;; Normalize old uses of org-log-done.
2211 ((eq org-log-done t
) (setq org-log-done
'time
))
2212 ((and (listp org-log-done
) (memq 'done org-log-done
))
2213 (setq org-log-done
'note
)))
2215 (defcustom org-log-reschedule nil
2216 "Information to record when the scheduling date of a tasks is modified.
2218 Possible values are:
2220 nil Don't add anything, just change the date
2221 time Add a time stamp to the task
2222 note Prompt for a note and add it with template `org-log-note-headings'
2224 This option can also be set with on a per-file-basis with
2226 #+STARTUP: nologreschedule
2227 #+STARTUP: logreschedule
2228 #+STARTUP: lognotereschedule"
2230 :group
'org-progress
2232 (const :tag
"No logging" nil
)
2233 (const :tag
"Record timestamp" time
)
2234 (const :tag
"Record timestamp with note." note
)))
2236 (defcustom org-log-redeadline nil
2237 "Information to record when the deadline date of a tasks is modified.
2239 Possible values are:
2241 nil Don't add anything, just change the date
2242 time Add a time stamp to the task
2243 note Prompt for a note and add it with template `org-log-note-headings'
2245 This option can also be set with on a per-file-basis with
2247 #+STARTUP: nologredeadline
2248 #+STARTUP: logredeadline
2249 #+STARTUP: lognoteredeadline
2251 You can have local logging settings for a subtree by setting the LOGGING
2252 property to one or more of these keywords."
2254 :group
'org-progress
2256 (const :tag
"No logging" nil
)
2257 (const :tag
"Record timestamp" time
)
2258 (const :tag
"Record timestamp with note." note
)))
2260 (defcustom org-log-note-clock-out nil
2261 "Non-nil means record a note when clocking out of an item.
2262 This can also be configured on a per-file basis by adding one of
2263 the following lines anywhere in the buffer:
2265 #+STARTUP: lognoteclock-out
2266 #+STARTUP: nolognoteclock-out"
2268 :group
'org-progress
2271 (defcustom org-log-done-with-time t
2272 "Non-nil means the CLOSED time stamp will contain date and time.
2273 When nil, only the date will be recorded."
2274 :group
'org-progress
2277 (defcustom org-log-note-headings
2278 '((done .
"CLOSING NOTE %t")
2279 (state .
"State %-12s from %-12S %t")
2280 (note .
"Note taken on %t")
2281 (reschedule .
"Rescheduled from %S on %t")
2282 (delschedule .
"Not scheduled, was %S on %t")
2283 (redeadline .
"New deadline from %S on %t")
2284 (deldeadline .
"Removed deadline, was %S on %t")
2285 (refile .
"Refiled on %t")
2287 "Headings for notes added to entries.
2288 The value is an alist, with the car being a symbol indicating the note
2289 context, and the cdr is the heading to be used. The heading may also be the
2291 %t in the heading will be replaced by a time stamp.
2292 %T will be an acive time stamp instead the default inacive one
2293 %s will be replaced by the new TODO state, in double quotes.
2294 %S will be replaced by the old TODO state, in double quotes.
2295 %u will be replaced by the user name.
2296 %U will be replaced by the full user name.
2298 In fact, it is not a good idea to change the `state' entry, because
2299 agenda log mode depends on the format of these entries."
2301 :group
'org-progress
2302 :type
'(list :greedy t
2303 (cons (const :tag
"Heading when closing an item" done
) string
)
2305 "Heading when changing todo state (todo sequence only)"
2307 (cons (const :tag
"Heading when just taking a note" note
) string
)
2308 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2309 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2310 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2311 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2312 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2313 (cons (const :tag
"Heading when refiling" refile
) string
)))
2315 (unless (assq 'note org-log-note-headings
)
2316 (push '(note .
"%t") org-log-note-headings
))
2318 (defcustom org-log-into-drawer nil
2319 "Non-nil means insert state change notes and time stamps into a drawer.
2320 When nil, state changes notes will be inserted after the headline and
2321 any scheduling and clock lines, but not inside a drawer.
2323 The value of this variable should be the name of the drawer to use.
2324 LOGBOOK is proposed at the default drawer for this purpose, you can
2325 also set this to a string to define the drawer of your choice.
2327 A value of t is also allowed, representing \"LOGBOOK\".
2329 If this variable is set, `org-log-state-notes-insert-after-drawers'
2332 You can set the property LOG_INTO_DRAWER to overrule this setting for
2335 :group
'org-progress
2337 (const :tag
"Not into a drawer" nil
)
2338 (const :tag
"LOGBOOK" t
)
2339 (string :tag
"Other")))
2341 (if (fboundp 'defvaralias
)
2342 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2344 (defun org-log-into-drawer ()
2345 "Return the value of `org-log-into-drawer', but let properties overrule.
2346 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2347 used instead of the default value."
2348 (let ((p (ignore-errors (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
))))
2350 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2351 ((equal p
"t") "LOGBOOK")
2354 (defcustom org-log-state-notes-insert-after-drawers nil
2355 "Non-nil means insert state change notes after any drawers in entry.
2356 Only the drawers that *immediately* follow the headline and the
2357 deadline/scheduled line are skipped.
2358 When nil, insert notes right after the heading and perhaps the line
2359 with deadline/scheduling if present.
2361 This variable will have no effect if `org-log-into-drawer' is
2364 :group
'org-progress
2367 (defcustom org-log-states-order-reversed t
2368 "Non-nil means the latest state note will be directly after heading.
2369 When nil, the state change notes will be ordered according to time."
2371 :group
'org-progress
2374 (defcustom org-todo-repeat-to-state nil
2375 "The TODO state to which a repeater should return the repeating task.
2376 By default this is the first task in a TODO sequence, or the previous state
2377 in a TODO_TYP set. But you can specify another task here.
2378 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2380 :type
'(choice (const :tag
"Head of sequence" nil
)
2381 (string :tag
"Specific state")))
2383 (defcustom org-log-repeat
'time
2384 "Non-nil means record moving through the DONE state when triggering repeat.
2385 An auto-repeating task is immediately switched back to TODO when
2386 marked DONE. If you are not logging state changes (by adding \"@\"
2387 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2388 record a closing note, there will be no record of the task moving
2389 through DONE. This variable forces taking a note anyway.
2391 nil Don't force a record
2392 time Record a time stamp
2395 This option can also be set with on a per-file-basis with
2397 #+STARTUP: logrepeat
2398 #+STARTUP: lognoterepeat
2399 #+STARTUP: nologrepeat
2401 You can have local logging settings for a subtree by setting the LOGGING
2402 property to one or more of these keywords."
2404 :group
'org-progress
2406 (const :tag
"Don't force a record" nil
)
2407 (const :tag
"Force recording the DONE state" time
)
2408 (const :tag
"Force recording a note with the DONE state" note
)))
2411 (defgroup org-priorities nil
2412 "Priorities in Org-mode."
2413 :tag
"Org Priorities"
2416 (defcustom org-enable-priority-commands t
2417 "Non-nil means priority commands are active.
2418 When nil, these commands will be disabled, so that you never accidentally
2420 :group
'org-priorities
2423 (defcustom org-highest-priority ?A
2424 "The highest priority of TODO items. A character like ?A, ?B etc.
2425 Must have a smaller ASCII number than `org-lowest-priority'."
2426 :group
'org-priorities
2429 (defcustom org-lowest-priority ?C
2430 "The lowest priority of TODO items. A character like ?A, ?B etc.
2431 Must have a larger ASCII number than `org-highest-priority'."
2432 :group
'org-priorities
2435 (defcustom org-default-priority ?B
2436 "The default priority of TODO items.
2437 This is the priority an item get if no explicit priority is given."
2438 :group
'org-priorities
2441 (defcustom org-priority-start-cycle-with-default t
2442 "Non-nil means start with default priority when starting to cycle.
2443 When this is nil, the first step in the cycle will be (depending on the
2444 command used) one higher or lower that the default priority."
2445 :group
'org-priorities
2448 (defgroup org-time nil
2449 "Options concerning time stamps and deadlines in Org-mode."
2453 (defcustom org-insert-labeled-timestamps-at-point nil
2454 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2455 When nil, these labeled time stamps are forces into the second line of an
2456 entry, just after the headline. When scheduling from the global TODO list,
2457 the time stamp will always be forced into the second line."
2461 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2462 "Formats for `format-time-string' which are used for time stamps.
2463 It is not recommended to change this constant.")
2465 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2466 "Number of minutes to round time stamps to.
2467 These are two values, the first applies when first creating a time stamp.
2468 The second applies when changing it with the commands `S-up' and `S-down'.
2469 When changing the time stamp, this means that it will change in steps
2470 of N minutes, as given by the second value.
2472 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2473 numbers should be factors of 60, so for example 5, 10, 15.
2475 When this is larger than 1, you can still force an exact time-stamp by using
2476 a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
2477 and by using a prefix arg to `S-up/down' to specify the exact number
2478 of minutes to shift."
2480 :get
'(lambda (var) ; Make sure both elements are there
2481 (if (integerp (default-value var
))
2482 (list (default-value var
) 5)
2483 (default-value var
)))
2485 (integer :tag
"when inserting times")
2486 (integer :tag
"when modifying times")))
2488 ;; Normalize old customizations of this variable.
2489 (when (integerp org-time-stamp-rounding-minutes
)
2490 (setq org-time-stamp-rounding-minutes
2491 (list org-time-stamp-rounding-minutes
2492 org-time-stamp-rounding-minutes
)))
2494 (defcustom org-display-custom-times nil
2495 "Non-nil means overlay custom formats over all time stamps.
2496 The formats are defined through the variable `org-time-stamp-custom-formats'.
2497 To turn this on on a per-file basis, insert anywhere in the file:
2498 #+STARTUP: customtime"
2502 (make-variable-buffer-local 'org-display-custom-times
)
2504 (defcustom org-time-stamp-custom-formats
2505 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2506 "Custom formats for time stamps. See `format-time-string' for the syntax.
2507 These are overlayed over the default ISO format if the variable
2508 `org-display-custom-times' is set. Time like %H:%M should be at the
2509 end of the second format. The custom formats are also honored by export
2510 commands, if custom time display is turned on at the time of export."
2514 (defun org-time-stamp-format (&optional long inactive
)
2515 "Get the right format for a time string."
2516 (let ((f (if long
(cdr org-time-stamp-formats
)
2517 (car org-time-stamp-formats
))))
2519 (concat "[" (substring f
1 -
1) "]")
2522 (defcustom org-time-clocksum-format
"%d:%02d"
2523 "The format string used when creating CLOCKSUM lines, or when
2524 org-mode generates a time duration."
2528 (defcustom org-time-clocksum-use-fractional nil
2529 "If non-nil, \\[org-clock-display] uses fractional times.
2530 org-mode generates a time duration."
2534 (defcustom org-time-clocksum-fractional-format
"%.2f"
2535 "The format string used when creating CLOCKSUM lines, or when
2536 org-mode generates a time duration."
2540 (defcustom org-deadline-warning-days
14
2541 "No. of days before expiration during which a deadline becomes active.
2542 This variable governs the display in sparse trees and in the agenda.
2543 When 0 or negative, it means use this number (the absolute value of it)
2544 even if a deadline has a different individual lead time specified.
2546 Custom commands can set this variable in the options section."
2548 :group
'org-agenda-daily
/weekly
2551 (defcustom org-read-date-prefer-future t
2552 "Non-nil means assume future for incomplete date input from user.
2553 This affects the following situations:
2554 1. The user gives a month but not a year.
2555 For example, if it is april and you enter \"feb 2\", this will be read
2556 as feb 2, *next* year. \"May 5\", however, will be this year.
2557 2. The user gives a day, but no month.
2558 For example, if today is the 15th, and you enter \"3\", Org-mode will
2559 read this as the third of *next* month. However, if you enter \"17\",
2560 it will be considered as *this* month.
2562 If you set this variable to the symbol `time', then also the following
2565 3. If the user gives a time, but no day. If the time is before now,
2566 to will be interpreted as tomorrow.
2568 Currently none of this works for ISO week specifications.
2570 When this option is nil, the current day, month and year will always be
2574 (const :tag
"Never" nil
)
2575 (const :tag
"Check month and day" t
)
2576 (const :tag
"Check month, day, and time" time
)))
2578 (defcustom org-read-date-display-live t
2579 "Non-nil means display current interpretation of date prompt live.
2580 This display will be in an overlay, in the minibuffer."
2584 (defcustom org-read-date-popup-calendar t
2585 "Non-nil means pop up a calendar when prompting for a date.
2586 In the calendar, the date can be selected with mouse-1. However, the
2587 minibuffer will also be active, and you can simply enter the date as well.
2588 When nil, only the minibuffer will be available."
2591 (if (fboundp 'defvaralias
)
2592 (defvaralias 'org-popup-calendar-for-date-prompt
2593 'org-read-date-popup-calendar
))
2595 (defcustom org-read-date-minibuffer-setup-hook nil
2596 "Hook to be used to set up keys for the date/time interface.
2597 Add key definitions to `minibuffer-local-map', which will be a temporary
2602 (defcustom org-extend-today-until
0
2603 "The hour when your day really ends. Must be an integer.
2604 This has influence for the following applications:
2605 - When switching the agenda to \"today\". It it is still earlier than
2606 the time given here, the day recognized as TODAY is actually yesterday.
2607 - When a date is read from the user and it is still before the time given
2608 here, the current date and time will be assumed to be yesterday, 23:59.
2609 Also, timestamps inserted in remember templates follow this rule.
2611 IMPORTANT: This is a feature whose implementation is and likely will
2612 remain incomplete. Really, it is only here because past midnight seems to
2613 be the favorite working time of John Wiegley :-)"
2617 (defcustom org-edit-timestamp-down-means-later nil
2618 "Non-nil means S-down will increase the time in a time stamp.
2619 When nil, S-up will increase."
2623 (defcustom org-calendar-follow-timestamp-change t
2624 "Non-nil means make the calendar window follow timestamp changes.
2625 When a timestamp is modified and the calendar window is visible, it will be
2626 moved to the new date."
2630 (defgroup org-tags nil
2631 "Options concerning tags in Org-mode."
2635 (defcustom org-tag-alist nil
2636 "List of tags allowed in Org-mode files.
2637 When this list is nil, Org-mode will base TAG input on what is already in the
2639 The value of this variable is an alist, the car of each entry must be a
2640 keyword as a string, the cdr may be a character that is used to select
2641 that tag through the fast-tag-selection interface.
2642 See the manual for details."
2646 (cons (string :tag
"Tag name")
2647 (character :tag
"Access char"))
2648 (list :tag
"Start radio group"
2650 (option (string :tag
"Group description")))
2651 (list :tag
"End radio group"
2653 (option (string :tag
"Group description")))
2654 (const :tag
"New line" (:newline
)))))
2656 (defcustom org-tag-persistent-alist nil
2657 "List of tags that will always appear in all Org-mode files.
2658 This is in addition to any in buffer settings or customizations
2660 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2661 The value of this variable is an alist, the car of each entry must be a
2662 keyword as a string, the cdr may be a character that is used to select
2663 that tag through the fast-tag-selection interface.
2664 See the manual for details.
2665 To disable these tags on a per-file basis, insert anywhere in the file:
2670 (cons (string :tag
"Tag name")
2671 (character :tag
"Access char"))
2672 (const :tag
"Start radio group" (:startgroup
))
2673 (const :tag
"End radio group" (:endgroup
))
2674 (const :tag
"New line" (:newline
)))))
2676 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2677 "If non-nil, always offer completion for all tags of all agenda files.
2678 Instead of customizing this variable directly, you might want to
2679 set it locally for remember buffers, because there no list of
2680 tags in that file can be created dynamically (there are none).
2682 (add-hook 'org-remember-mode-hook
2684 (set (make-local-variable
2685 'org-complete-tags-always-offer-all-agenda-tags)
2690 (defvar org-file-tags nil
2691 "List of tags that can be inherited by all entries in the file.
2692 The tags will be inherited if the variable `org-use-tag-inheritance'
2693 says they should be.
2694 This variable is populated from #+FILETAGS lines.")
2696 (defcustom org-use-fast-tag-selection
'auto
2697 "Non-nil means use fast tag selection scheme.
2698 This is a special interface to select and deselect tags with single keys.
2699 When nil, fast selection is never used.
2700 When the symbol `auto', fast selection is used if and only if selection
2701 characters for tags have been configured, either through the variable
2702 `org-tag-alist' or through a #+TAGS line in the buffer.
2703 When t, fast selection is always used and selection keys are assigned
2704 automatically if necessary."
2707 (const :tag
"Always" t
)
2708 (const :tag
"Never" nil
)
2709 (const :tag
"When selection characters are configured" 'auto
)))
2711 (defcustom org-fast-tag-selection-single-key nil
2712 "Non-nil means fast tag selection exits after first change.
2713 When nil, you have to press RET to exit it.
2714 During fast tag selection, you can toggle this flag with `C-c'.
2715 This variable can also have the value `expert'. In this case, the window
2716 displaying the tags menu is not even shown, until you press C-c again."
2719 (const :tag
"No" nil
)
2720 (const :tag
"Yes" t
)
2721 (const :tag
"Expert" expert
)))
2723 (defvar org-fast-tag-selection-include-todo nil
2724 "Non-nil means fast tags selection interface will also offer TODO states.
2725 This is an undocumented feature, you should not rely on it.")
2727 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2728 "The column to which tags should be indented in a headline.
2729 If this number is positive, it specifies the column. If it is negative,
2730 it means that the tags should be flushright to that column. For example,
2731 -80 works well for a normal 80 character screen."
2735 (defcustom org-auto-align-tags t
2736 "Non-nil means realign tags after pro/demotion of TODO state change.
2737 These operations change the length of a headline and therefore shift
2738 the tags around. With this options turned on, after each such operation
2739 the tags are again aligned to `org-tags-column'."
2743 (defcustom org-use-tag-inheritance t
2744 "Non-nil means tags in levels apply also for sublevels.
2745 When nil, only the tags directly given in a specific line apply there.
2746 This may also be a list of tags that should be inherited, or a regexp that
2747 matches tags that should be inherited. Additional control is possible
2748 with the variable `org-tags-exclude-from-inheritance' which gives an
2749 explicit list of tags to be excluded from inheritance., even if the value of
2750 `org-use-tag-inheritance' would select it for inheritance.
2752 If this option is t, a match early-on in a tree can lead to a large
2753 number of matches in the subtree when constructing the agenda or creating
2754 a sparse tree. If you only want to see the first match in a tree during
2755 a search, check out the variable `org-tags-match-list-sublevels'."
2758 (const :tag
"Not" nil
)
2759 (const :tag
"Always" t
)
2760 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2761 (regexp :tag
"Tags matched by regexp")))
2763 (defcustom org-tags-exclude-from-inheritance nil
2764 "List of tags that should never be inherited.
2765 This is a way to exclude a few tags from inheritance. For way to do
2766 the opposite, to actively allow inheritance for selected tags,
2767 see the variable `org-use-tag-inheritance'."
2769 :type
'(repeat (string :tag
"Tag")))
2771 (defun org-tag-inherit-p (tag)
2772 "Check if TAG is one that should be inherited."
2774 ((member tag org-tags-exclude-from-inheritance
) nil
)
2775 ((eq org-use-tag-inheritance t
) t
)
2776 ((not org-use-tag-inheritance
) nil
)
2777 ((stringp org-use-tag-inheritance
)
2778 (string-match org-use-tag-inheritance tag
))
2779 ((listp org-use-tag-inheritance
)
2780 (member tag org-use-tag-inheritance
))
2781 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
2783 (defcustom org-tags-match-list-sublevels t
2784 "Non-nil means list also sublevels of headlines matching a search.
2785 This variable applies to tags/property searches, and also to stuck
2786 projects because this search is based on a tags match as well.
2788 When set to the symbol `indented', sublevels are indented with
2791 Because of tag inheritance (see variable `org-use-tag-inheritance'),
2792 the sublevels of a headline matching a tag search often also match
2793 the same search. Listing all of them can create very long lists.
2794 Setting this variable to nil causes subtrees of a match to be skipped.
2796 This variable is semi-obsolete and probably should always be true. It
2797 is better to limit inheritance to certain tags using the variables
2798 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
2801 (const :tag
"No, don't list them" nil
)
2802 (const :tag
"Yes, do list them" t
)
2803 (const :tag
"List them, indented with leading dots" indented
)))
2805 (defcustom org-tags-sort-function nil
2806 "When set, tags are sorted using this function as a comparator"
2809 (const :tag
"No sorting" nil
)
2810 (const :tag
"Alphabetical" string
<)
2811 (const :tag
"Reverse alphabetical" string
>)
2812 (function :tag
"Custom function" nil
)))
2814 (defvar org-tags-history nil
2815 "History of minibuffer reads for tags.")
2816 (defvar org-last-tags-completion-table nil
2817 "The last used completion table for tags.")
2818 (defvar org-after-tags-change-hook nil
2819 "Hook that is run after the tags in a line have changed.")
2821 (defgroup org-properties nil
2822 "Options concerning properties in Org-mode."
2823 :tag
"Org Properties"
2826 (defcustom org-property-format
"%-10s %s"
2827 "How property key/value pairs should be formatted by `indent-line'.
2828 When `indent-line' hits a property definition, it will format the line
2829 according to this format, mainly to make sure that the values are
2830 lined-up with respect to each other."
2831 :group
'org-properties
2834 (defcustom org-use-property-inheritance nil
2835 "Non-nil means properties apply also for sublevels.
2837 This setting is chiefly used during property searches. Turning it on can
2838 cause significant overhead when doing a search, which is why it is not
2841 When nil, only the properties directly given in the current entry count.
2842 When t, every property is inherited. The value may also be a list of
2843 properties that should have inheritance, or a regular expression matching
2844 properties that should be inherited.
2846 However, note that some special properties use inheritance under special
2847 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
2848 and the properties ending in \"_ALL\" when they are used as descriptor
2849 for valid values of a property.
2851 Note for programmers:
2852 When querying an entry with `org-entry-get', you can control if inheritance
2853 should be used. By default, `org-entry-get' looks only at the local
2854 properties. You can request inheritance by setting the inherit argument
2855 to t (to force inheritance) or to `selective' (to respect the setting
2857 :group
'org-properties
2859 (const :tag
"Not" nil
)
2860 (const :tag
"Always" t
)
2861 (repeat :tag
"Specific properties" (string :tag
"Property"))
2862 (regexp :tag
"Properties matched by regexp")))
2864 (defun org-property-inherit-p (property)
2865 "Check if PROPERTY is one that should be inherited."
2867 ((eq org-use-property-inheritance t
) t
)
2868 ((not org-use-property-inheritance
) nil
)
2869 ((stringp org-use-property-inheritance
)
2870 (string-match org-use-property-inheritance property
))
2871 ((listp org-use-property-inheritance
)
2872 (member property org-use-property-inheritance
))
2873 (t (error "Invalid setting of `org-use-property-inheritance'"))))
2875 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
2876 "The default column format, if no other format has been defined.
2877 This variable can be set on the per-file basis by inserting a line
2879 #+COLUMNS: %25ITEM ....."
2880 :group
'org-properties
2883 (defcustom org-columns-ellipses
".."
2884 "The ellipses to be used when a field in column view is truncated.
2885 When this is the empty string, as many characters as possible are shown,
2886 but then there will be no visual indication that the field has been truncated.
2887 When this is a string of length N, the last N characters of a truncated
2888 field are replaced by this string. If the column is narrower than the
2889 ellipses string, only part of the ellipses string will be shown."
2890 :group
'org-properties
2893 (defcustom org-columns-modify-value-for-display-function nil
2894 "Function that modifies values for display in column view.
2895 For example, it can be used to cut out a certain part from a time stamp.
2896 The function must take 2 arguments:
2898 column-title The title of the column (*not* the property name)
2899 value The value that should be modified.
2901 The function should return the value that should be displayed,
2902 or nil if the normal value should be used."
2903 :group
'org-properties
2906 (defcustom org-effort-property
"Effort"
2907 "The property that is being used to keep track of effort estimates.
2908 Effort estimates given in this property need to have the format H:MM."
2909 :group
'org-properties
2910 :group
'org-progress
2911 :type
'(string :tag
"Property"))
2913 (defconst org-global-properties-fixed
2914 '(("VISIBILITY_ALL" .
"folded children content all")
2915 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
2916 "List of property/value pairs that can be inherited by any entry.
2918 These are fixed values, for the preset properties. The user variable
2919 that can be used to add to this list is `org-global-properties'.
2921 The entries in this list are cons cells where the car is a property
2922 name and cdr is a string with the value. If the value represents
2923 multiple items like an \"_ALL\" property, separate the items by
2926 (defcustom org-global-properties nil
2927 "List of property/value pairs that can be inherited by any entry.
2929 This list will be combined with the constant `org-global-properties-fixed'.
2931 The entries in this list are cons cells where the car is a property
2932 name and cdr is a string with the value.
2934 You can set buffer-local values for the same purpose in the variable
2935 `org-file-properties' this by adding lines like
2937 #+PROPERTY: NAME VALUE"
2938 :group
'org-properties
2940 (cons (string :tag
"Property")
2941 (string :tag
"Value"))))
2943 (defvar org-file-properties nil
2944 "List of property/value pairs that can be inherited by any entry.
2945 Valid for the current buffer.
2946 This variable is populated from #+PROPERTY lines.")
2947 (make-variable-buffer-local 'org-file-properties
)
2949 (defgroup org-agenda nil
2950 "Options concerning agenda views in Org-mode."
2954 (defvar org-category nil
2955 "Variable used by org files to set a category for agenda display.
2956 Such files should use a file variable to set it, for example
2958 # -*- mode: org; org-category: \"ELisp\"
2960 or contain a special line
2964 If the file does not specify a category, then file's base name
2966 (make-variable-buffer-local 'org-category
)
2967 (put 'org-category
'safe-local-variable
'(lambda (x) (or (symbolp x
) (stringp x
))))
2969 (defcustom org-agenda-files nil
2970 "The files to be used for agenda display.
2971 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
2972 \\[org-remove-file]. You can also use customize to edit the list.
2974 If an entry is a directory, all files in that directory that are matched by
2975 `org-agenda-file-regexp' will be part of the file list.
2977 If the value of the variable is not a list but a single file name, then
2978 the list of agenda files is actually stored and maintained in that file, one
2979 agenda file per line. In this file paths can be given relative to
2980 `org-directory'. Tilde expansion and environment variable substitution
2984 (repeat :tag
"List of files and directories" file
)
2985 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
2987 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
2988 "Regular expression to match files for `org-agenda-files'.
2989 If any element in the list in that variable contains a directory instead
2990 of a normal file, all files in that directory that are matched by this
2991 regular expression will be included."
2995 (defcustom org-agenda-text-search-extra-files nil
2996 "List of extra files to be searched by text search commands.
2997 These files will be search in addition to the agenda files by the
2998 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
2999 Note that these files will only be searched for text search commands,
3000 not for the other agenda views like todo lists, tag searches or the weekly
3001 agenda. This variable is intended to list notes and possibly archive files
3002 that should also be searched by these two commands.
3003 In fact, if the first element in the list is the symbol `agenda-archives',
3004 than all archive files of all agenda files will be added to the search
3007 :type
'(set :greedy t
3008 (const :tag
"Agenda Archives" agenda-archives
)
3009 (repeat :inline t
(file))))
3011 (if (fboundp 'defvaralias
)
3012 (defvaralias 'org-agenda-multi-occur-extra-files
3013 'org-agenda-text-search-extra-files
))
3015 (defcustom org-agenda-skip-unavailable-files nil
3016 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
3017 A nil value means to remove them, after a query, from the list."
3021 (defcustom org-calendar-to-agenda-key
[?c
]
3022 "The key to be installed in `calendar-mode-map' for switching to the agenda.
3023 The command `org-calendar-goto-agenda' will be bound to this key. The
3024 default is the character `c' because then `c' can be used to switch back and
3025 forth between agenda and calendar."
3029 (defcustom org-calendar-agenda-action-key
[?k
]
3030 "The key to be installed in `calendar-mode-map' for agenda-action.
3031 The command `org-agenda-action' will be bound to this key. The
3032 default is the character `k' because we use the same key in the agenda."
3036 (defcustom org-calendar-insert-diary-entry-key
[?i
]
3037 "The key to be installed in `calendar-mode-map' for adding diary entries.
3038 This option is irrelevant until `org-agenda-diary-file' has been configured
3039 to point to an Org-mode file. When that is the case, the command
3040 `org-agenda-diary-entry' will be bound to the key given here, by default
3041 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
3042 if you want to continue doing this, you need to change this to a different
3047 (defcustom org-agenda-diary-file
'diary-file
3048 "File to which to add new entries with the `i' key in agenda and calendar.
3049 When this is the symbol `diary-file', the functionality in the Emacs
3050 calendar will be used to add entries to the `diary-file'. But when this
3051 points to a file, `org-agenda-diary-entry' will be used instead."
3054 (const :tag
"The standard Emacs diary file" diary-file
)
3055 (file :tag
"Special Org file diary entries")))
3057 (eval-after-load "calendar"
3059 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3060 'org-calendar-goto-agenda
)
3061 (org-defkey calendar-mode-map org-calendar-agenda-action-key
3063 (add-hook 'calendar-mode-hook
3065 (unless (eq org-agenda-diary-file
'diary-file
)
3066 (define-key calendar-mode-map
3067 org-calendar-insert-diary-entry-key
3068 'org-agenda-diary-entry
))))))
3070 (defgroup org-latex nil
3071 "Options for embedding LaTeX code into Org-mode."
3075 (defcustom org-format-latex-options
3076 '(:foreground default
:background default
:scale
1.0
3077 :html-foreground
"Black" :html-background
"Transparent" :html-scale
1.0
3078 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3079 "Options for creating images from LaTeX fragments.
3080 This is a property list with the following properties:
3081 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3082 `default' means use the foreground of the default face.
3083 :background the background color, or \"Transparent\".
3084 `default' means use the background of the default face.
3085 :scale a scaling factor for the size of the images.
3086 :html-foreground, :html-background, :html-scale
3087 the same numbers for HTML export.
3088 :matchers a list indicating which matchers should be used to
3089 find LaTeX fragments. Valid members of this list are:
3090 \"begin\" find environments
3091 \"$1\" find single characters surrounded by $.$
3092 \"$\" find math expressions surrounded by $...$
3093 \"$$\" find math expressions surrounded by $$....$$
3094 \"\\(\" find math expressions surrounded by \\(...\\)
3095 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3099 (defcustom org-format-latex-signal-error t
3100 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3101 When nil, just push out a message."
3105 (defcustom org-format-latex-header
"\\documentclass{article}
3106 \\usepackage[usenames]{color}
3107 \\usepackage{amsmath}
3108 \\usepackage[mathscr]{eucal}
3109 \\pagestyle{empty} % do not remove
3112 % The settings below are copied from fullpage.sty
3113 \\setlength{\\textwidth}{\\paperwidth}
3114 \\addtolength{\\textwidth}{-3cm}
3115 \\setlength{\\oddsidemargin}{1.5cm}
3116 \\addtolength{\\oddsidemargin}{-2.54cm}
3117 \\setlength{\\evensidemargin}{\\oddsidemargin}
3118 \\setlength{\\textheight}{\\paperheight}
3119 \\addtolength{\\textheight}{-\\headheight}
3120 \\addtolength{\\textheight}{-\\headsep}
3121 \\addtolength{\\textheight}{-\\footskip}
3122 \\addtolength{\\textheight}{-3cm}
3123 \\setlength{\\topmargin}{1.5cm}
3124 \\addtolength{\\topmargin}{-2.54cm}"
3125 "The document header used for processing LaTeX fragments.
3126 It is imperative that this header make sure that no page number
3127 appears on the page. The package defined in the variables
3128 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
3129 will either replace the placeholder \"[PACKAGES]\" in this header, or they
3134 (defvar org-format-latex-header-extra nil
)
3136 (defun org-set-packages-alist (var val
)
3137 "Set the packages alist and make sure it has 3 elements per entry."
3138 (set var
(mapcar (lambda (x)
3139 (if (and (consp x
) (= (length x
) 2))
3140 (list (car x
) (nth 1 x
) t
)
3144 (defun org-get-packages-alist (var)
3146 "Get the packages alist and make sure it has 3 elements per entry."
3148 (if (and (consp x
) (= (length x
) 2))
3149 (list (car x
) (nth 1 x
) t
)
3151 (default-value var
)))
3153 ;; The following variables are defined here because is it also used
3154 ;; when formatting latex fragments. Originally it was part of the
3155 ;; LaTeX exporter, which is why the name includes "export".
3156 (defcustom org-export-latex-default-packages-alist
3157 '(("AUTO" "inputenc" t
)
3161 ("" "longtable" nil
)
3174 "Alist of default packages to be inserted in the header.
3175 Change this only if one of the packages here causes an incompatibility
3176 with another package you are using.
3177 The packages in this list are needed by one part or another of Org-mode
3178 to function properly.
3180 - inputenc, fontenc, t1enc: for basic font and character selection
3181 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3182 for interpreting the entities in `org-entities'. You can skip some of these
3183 packages if you don't use any of the symbols in it.
3184 - graphicx: for including images
3185 - float, wrapfig: for figure placement
3186 - longtable: for long tables
3187 - hyperref: for cross references
3189 Therefore you should not modify this variable unless you know what you
3190 are doing. The one reason to change it anyway is that you might be loading
3191 some other package that conflicts with one of the default packages.
3192 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3193 If SNIPPET-FLAG is t, the package also needs to be included when
3194 compiling LaTeX snippets into images for inclusion into HTML."
3195 :group
'org-export-latex
3196 :set
'org-set-packages-alist
3197 :get
'org-get-packages-alist
3200 (list :tag
"options/package pair"
3201 (string :tag
"options")
3202 (string :tag
"package")
3203 (boolean :tag
"Snippet"))
3204 (string :tag
"A line of LaTeX"))))
3206 (defcustom org-export-latex-packages-alist nil
3207 "Alist of packages to be inserted in every LaTeX header.
3208 These will be inserted after `org-export-latex-default-packages-alist'.
3209 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3210 SNIPPET-FLAG, when t, indicates that this package is also needed when
3211 turning LaTeX snippets into images for inclusion into HTML.
3212 Make sure that you only list packages here which:
3213 - you want in every file
3214 - do not conflict with the default packages in
3215 `org-export-latex-default-packages-alist'
3216 - do not conflict with the setup in `org-format-latex-header'."
3217 :group
'org-export-latex
3218 :set
'org-set-packages-alist
3219 :get
'org-get-packages-alist
3222 (list :tag
"options/package pair"
3223 (string :tag
"options")
3224 (string :tag
"package")
3225 (boolean :tag
"Snippet"))
3226 (string :tag
"A line of LaTeX"))))
3229 (defgroup org-appearance nil
3230 "Settings for Org-mode appearance."
3231 :tag
"Org Appearance"
3234 (defcustom org-level-color-stars-only nil
3235 "Non-nil means fontify only the stars in each headline.
3236 When nil, the entire headline is fontified.
3237 Changing it requires restart of `font-lock-mode' to become effective
3238 also in regions already fontified."
3239 :group
'org-appearance
3242 (defcustom org-hide-leading-stars nil
3243 "Non-nil means hide the first N-1 stars in a headline.
3244 This works by using the face `org-hide' for these stars. This
3245 face is white for a light background, and black for a dark
3246 background. You may have to customize the face `org-hide' to
3248 Changing it requires restart of `font-lock-mode' to become effective
3249 also in regions already fontified.
3250 You may also set this on a per-file basis by adding one of the following
3251 lines to the buffer:
3253 #+STARTUP: hidestars
3254 #+STARTUP: showstars"
3255 :group
'org-appearance
3258 (defcustom org-hidden-keywords nil
3259 "List of keywords that should be hidden when typed in the org buffer.
3260 For example, add #+TITLE to this list in order to make the
3261 document title appear in the buffer without the initial #+TITLE:
3263 :group
'org-appearance
3264 :type
'(set (const :tag
"#+AUTHOR" author
)
3265 (const :tag
"#+DATE" date
)
3266 (const :tag
"#+EMAIL" email
)
3267 (const :tag
"#+TITLE" title
)))
3269 (defcustom org-fontify-done-headline nil
3270 "Non-nil means change the face of a headline if it is marked DONE.
3271 Normally, only the TODO/DONE keyword indicates the state of a headline.
3272 When this is non-nil, the headline after the keyword is set to the
3273 `org-headline-done' as an additional indication."
3274 :group
'org-appearance
3277 (defcustom org-fontify-emphasized-text t
3278 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3279 Changing this variable requires a restart of Emacs to take effect."
3280 :group
'org-appearance
3283 (defcustom org-fontify-whole-heading-line nil
3284 "Non-nil means fontify the whole line for headings.
3285 This is useful when setting a background color for the
3287 :group
'org-appearance
3290 (defcustom org-highlight-latex-fragments-and-specials nil
3291 "Non-nil means fontify what is treated specially by the exporters."
3292 :group
'org-appearance
3295 (defcustom org-hide-emphasis-markers nil
3296 "Non-nil mean font-lock should hide the emphasis marker characters."
3297 :group
'org-appearance
3300 (defcustom org-pretty-entities nil
3301 "Non-nil means show entities as UTF8 characters.
3302 When nil, the \\name form remains in the buffer."
3303 :group
'org-appearance
3306 (defcustom org-pretty-entities-include-sub-superscripts t
3307 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3308 :group
'org-appearance
3311 (defvar org-emph-re nil
3312 "Regular expression for matching emphasis.
3313 After a match, the match groups contain these elements:
3314 1 The character before the proper match, or empty at beginning of line
3315 2 The proper match, including the leading and trailing markers
3316 3 The leading marker like * or /, indicating the type of highlighting
3317 4 The text between the emphasis markers, not including the markers
3318 5 The character after the match, empty at the end of a line")
3319 (defvar org-verbatim-re nil
3320 "Regular expression for matching verbatim text.")
3321 (defvar org-emphasis-regexp-components
) ; defined just below
3322 (defvar org-emphasis-alist
) ; defined just below
3323 (defun org-set-emph-re (var val
)
3324 "Set variable and compute the emphasis regular expression."
3326 (when (and (boundp 'org-emphasis-alist
)
3327 (boundp 'org-emphasis-regexp-components
)
3328 org-emphasis-alist org-emphasis-regexp-components
)
3329 (let* ((e org-emphasis-regexp-components
)
3335 (body1 (concat body
"*?"))
3336 (markers (mapconcat 'car org-emphasis-alist
""))
3337 (vmarkers (mapconcat
3338 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3339 org-emphasis-alist
"")))
3340 ;; make sure special characters appear at the right position in the class
3341 (if (string-match "\\^" markers
)
3342 (setq markers
(concat (replace-match "" t t markers
) "^")))
3343 (if (string-match "-" markers
)
3344 (setq markers
(concat (replace-match "" t t markers
) "-")))
3345 (if (string-match "\\^" vmarkers
)
3346 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3347 (if (string-match "-" vmarkers
)
3348 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3350 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3351 (int-to-string nl
) "\\}")))
3354 (concat "\\([" pre
"]\\|^\\)"
3356 "\\([" markers
"]\\)"
3364 "\\([" post
"]\\|$\\)"))
3365 (setq org-verbatim-re
3366 (concat "\\([" pre
"]\\|^\\)"
3368 "\\([" vmarkers
"]\\)"
3376 "\\([" post
"]\\|$\\)")))))
3378 (defcustom org-emphasis-regexp-components
3379 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3380 "Components used to build the regular expression for emphasis.
3381 This is a list with 6 entries. Terminology: In an emphasis string
3382 like \" *strong word* \", we call the initial space PREMATCH, the final
3383 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3384 and \"trong wor\" is the body. The different components in this variable
3385 specify what is allowed/forbidden in each part:
3387 pre Chars allowed as prematch. Beginning of line will be allowed too.
3388 post Chars allowed as postmatch. End of line will be allowed too.
3389 border The chars *forbidden* as border characters.
3390 body-regexp A regexp like \".\" to match a body character. Don't use
3391 non-shy groups here, and don't allow newline here.
3392 newline The maximum number of newlines allowed in an emphasis exp.
3394 Use customize to modify this, or restart Emacs after changing it."
3395 :group
'org-appearance
3396 :set
'org-set-emph-re
3398 (sexp :tag
"Allowed chars in pre ")
3399 (sexp :tag
"Allowed chars in post ")
3400 (sexp :tag
"Forbidden chars in border ")
3401 (sexp :tag
"Regexp for body ")
3402 (integer :tag
"number of newlines allowed")
3403 (option (boolean :tag
"Please ignore this button"))))
3405 (defcustom org-emphasis-alist
3406 `(("*" bold
"<b>" "</b>")
3407 ("/" italic
"<i>" "</i>")
3408 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3409 ("=" org-code
"<code>" "</code>" verbatim
)
3410 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3411 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3414 "Special syntax for emphasized text.
3415 Text starting and ending with a special character will be emphasized, for
3416 example *bold*, _underlined_ and /italic/. This variable sets the marker
3417 characters, the face to be used by font-lock for highlighting in Org-mode
3418 Emacs buffers, and the HTML tags to be used for this.
3419 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3420 For DocBook export, see the variable `org-export-docbook-emphasis-alist'.
3421 Use customize to modify this, or restart Emacs after changing it."
3422 :group
'org-appearance
3423 :set
'org-set-emph-re
3426 (string :tag
"Marker character")
3428 (face :tag
"Font-lock-face")
3429 (plist :tag
"Face property list"))
3430 (string :tag
"HTML start tag")
3431 (string :tag
"HTML end tag")
3432 (option (const verbatim
)))))
3434 (defvar org-protecting-blocks
3435 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3436 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3437 This is needed for font-lock setup.")
3439 ;;; Miscellaneous options
3441 (defgroup org-completion nil
3442 "Completion in Org-mode."
3443 :tag
"Org Completion"
3446 (defcustom org-completion-use-ido nil
3447 "Non-nil means use ido completion wherever possible.
3448 Note that `ido-mode' must be active for this variable to be relevant.
3449 If you decide to turn this variable on, you might well want to turn off
3450 `org-outline-path-complete-in-steps'.
3451 See also `org-completion-use-iswitchb'."
3452 :group
'org-completion
3455 (defcustom org-completion-use-iswitchb nil
3456 "Non-nil means use iswitchb completion wherever possible.
3457 Note that `iswitchb-mode' must be active for this variable to be relevant.
3458 If you decide to turn this variable on, you might well want to turn off
3459 `org-outline-path-complete-in-steps'.
3460 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3461 :group
'org-completion
3464 (defcustom org-completion-fallback-command
'hippie-expand
3465 "The expansion command called by \\[org-complete] in normal context.
3466 Normal means no org-mode-specific context."
3467 :group
'org-completion
3470 ;;; Functions and variables from their packages
3471 ;; Declared here to avoid compiler warnings
3474 (defvar outline-mode-menu-heading
)
3475 (defvar outline-mode-menu-show
)
3476 (defvar outline-mode-menu-hide
)
3477 (defvar zmacs-regions
) ; XEmacs regions
3480 (defvar mark-active
)
3483 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3484 (declare-function calendar-forward-day
"cal-move" (arg))
3485 (declare-function calendar-goto-date
"cal-move" (date))
3486 (declare-function calendar-goto-today
"cal-move" ())
3487 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3488 (defvar calc-embedded-close-formula
)
3489 (defvar calc-embedded-open-formula
)
3490 (declare-function cdlatex-tab
"ext:cdlatex" ())
3491 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3492 (defvar font-lock-unfontify-region-function
)
3493 (declare-function iswitchb-read-buffer
"iswitchb"
3494 (prompt &optional default require-match start matches-set
))
3495 (defvar iswitchb-temp-buflist
)
3496 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3497 (defvar org-agenda-tags-todo-honor-ignore-options
)
3498 (declare-function org-agenda-skip
"org-agenda" ())
3500 org-format-agenda-item
"org-agenda"
3501 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3502 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3503 (declare-function org-agenda-change-all-lines
"org-agenda"
3504 (newhead hdmarker
&optional fixface just-this
))
3505 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3506 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3507 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3509 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3510 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3511 "org-agenda" (&optional end
))
3512 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3513 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3514 (declare-function parse-time-string
"parse-time" (string))
3515 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3516 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3517 (defvar remember-data-file
)
3518 (defvar texmathp-why
)
3519 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3520 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3522 (defvar w3m-current-url
)
3523 (defvar w3m-current-title
)
3525 (defvar org-latex-regexps
)
3527 ;;; Autoload and prepare some org modules
3529 ;; Some table stuff that needs to be defined here, because it is used
3530 ;; by the functions setting up org-mode or checking for table context.
3532 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3533 "Detects an org-type or table-type table.")
3534 (defconst org-table-line-regexp
"^[ \t]*|"
3535 "Detects an org-type table line.")
3536 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3537 "Detects an org-type table line.")
3538 (defconst org-table-hline-regexp
"^[ \t]*|-"
3539 "Detects an org-type table hline.")
3540 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3541 "Detects a table-type table hline.")
3542 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3543 "Searching from within a table (any type) this finds the first line
3544 outside the table.")
3546 ;; Autoload the functions in org-table.el that are needed by functions here.
3549 (org-autoload "org-table"
3550 '(org-table-align org-table-begin org-table-blank-field
3551 org-table-convert org-table-convert-region org-table-copy-down
3552 org-table-copy-region org-table-create
3553 org-table-create-or-convert-from-region
3554 org-table-create-with-table.el org-table-current-dline
3555 org-table-cut-region org-table-delete-column org-table-edit-field
3556 org-table-edit-formulas org-table-end org-table-eval-formula
3557 org-table-export org-table-field-info
3558 org-table-get-stored-formulas org-table-goto-column
3559 org-table-hline-and-move org-table-import org-table-insert-column
3560 org-table-insert-hline org-table-insert-row org-table-iterate
3561 org-table-justify-field-maybe org-table-kill-row
3562 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3563 org-table-move-column org-table-move-column-left
3564 org-table-move-column-right org-table-move-row
3565 org-table-move-row-down org-table-move-row-up
3566 org-table-next-field org-table-next-row org-table-paste-rectangle
3567 org-table-previous-field org-table-recalculate
3568 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3569 org-table-toggle-coordinate-overlays
3570 org-table-toggle-formula-debugger org-table-wrap-region
3571 orgtbl-mode turn-on-orgtbl org-table-to-lisp
3572 orgtbl-to-generic orgtbl-to-tsv orgtbl-to-csv orgtbl-to-latex
3573 orgtbl-to-orgtbl orgtbl-to-html orgtbl-to-texinfo
)))
3575 (defun org-at-table-p (&optional table-type
)
3576 "Return t if the cursor is inside an org-type table.
3577 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3578 (if org-enable-table-editor
3580 (beginning-of-line 1)
3581 (looking-at (if table-type org-table-any-line-regexp
3582 org-table-line-regexp
)))
3584 (defsubst org-table-p
() (org-at-table-p))
3586 (defun org-at-table.el-p
()
3587 "Return t if and only if we are at a table.el table."
3588 (and (org-at-table-p 'any
)
3590 (goto-char (org-table-begin 'any
))
3591 (looking-at org-table1-hline-regexp
))))
3592 (defun org-table-recognize-table.el
()
3593 "If there is a table.el table nearby, recognize it and move into it."
3594 (if org-table-tab-recognizes-table.el
3595 (if (org-at-table.el-p
)
3597 (beginning-of-line 1)
3598 (if (looking-at org-table-dataline-regexp
)
3600 (if (looking-at org-table1-hline-regexp
)
3602 (beginning-of-line 2)
3603 (if (looking-at org-table-any-border-regexp
)
3604 (beginning-of-line -
1)))))
3605 (if (re-search-forward "|" (org-table-end t
) t
)
3608 (if (table--at-cell-p (point))
3610 (message "recognizing table.el table...")
3611 (table-recognize-table)
3612 (message "recognizing table.el table...done")))
3613 (error "This should not happen..."))
3618 (defun org-at-table-hline-p ()
3619 "Return t if the cursor is inside a hline in a table."
3620 (if org-enable-table-editor
3622 (beginning-of-line 1)
3623 (looking-at org-table-hline-regexp
))
3626 (defvar org-table-clean-did-remove-column nil
)
3628 (defun org-table-map-tables (function &optional quietly
)
3629 "Apply FUNCTION to the start of all tables in the buffer."
3633 (goto-char (point-min))
3634 (while (re-search-forward org-table-any-line-regexp nil t
)
3636 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3637 (beginning-of-line 1)
3638 (when (looking-at org-table-line-regexp
)
3639 (save-excursion (funcall function
))
3640 (or (looking-at org-table-line-regexp
)
3642 (re-search-forward org-table-any-border-regexp nil
1))))
3643 (unless quietly
(message "Mapping tables: done")))
3645 ;; Declare and autoload functions from org-exp.el & Co
3647 (declare-function org-default-export-plist
"org-exp")
3648 (declare-function org-infile-export-plist
"org-exp")
3649 (declare-function org-get-current-options
"org-exp")
3651 (org-autoload "org-exp"
3652 '(org-export org-export-visible
3653 org-insert-export-options-template
3654 org-table-clean-before-export
))
3655 (org-autoload "org-ascii"
3656 '(org-export-as-ascii org-export-ascii-preprocess
3657 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3658 org-export-region-as-ascii
))
3659 (org-autoload "org-latex"
3660 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3661 org-replace-region-by-latex org-export-region-as-latex
3662 org-export-as-latex org-export-as-pdf
3663 org-export-as-pdf-and-open
))
3664 (org-autoload "org-html"
3665 '(org-export-as-html-and-open
3666 org-export-as-html-batch org-export-as-html-to-buffer
3667 org-replace-region-by-html org-export-region-as-html
3668 org-export-as-html
))
3669 (org-autoload "org-docbook"
3670 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3671 org-replace-region-by-docbook org-export-region-as-docbook
3672 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3673 org-export-as-docbook
))
3674 (org-autoload "org-icalendar"
3675 '(org-export-icalendar-this-file
3676 org-export-icalendar-all-agenda-files
3677 org-export-icalendar-combine-agenda-files
))
3678 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3679 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3681 ;; Declare and autoload functions from org-agenda.el
3684 (org-autoload "org-agenda"
3685 '(org-agenda org-agenda-list org-search-view
3686 org-todo-list org-tags-view org-agenda-list-stuck-projects
3687 org-diary org-agenda-to-appt
3688 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
3690 ;; Autoload org-remember
3693 (org-autoload "org-remember"
3694 '(org-remember-insinuate org-remember-annotation
3695 org-remember-apply-template org-remember org-remember-handler
)))
3698 (org-autoload "org-capture"
3699 '(org-capture org-capture-insert-template-here
3700 org-capture-import-remember-templates
)))
3702 ;; Autoload org-clock.el
3705 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
3707 (declare-function org-clock-update-mode-line
"org-clock" ())
3708 (declare-function org-resolve-clocks
"org-clock"
3709 (&optional also-non-dangling-p prompt last-valid
))
3710 (defvar org-clock-start-time
)
3711 (defvar org-clock-marker
(make-marker)
3712 "Marker recording the last clock-in.")
3713 (defvar org-clock-hd-marker
(make-marker)
3714 "Marker recording the last clock-in, but the headline position.")
3715 (defvar org-clock-heading
""
3716 "The heading of the current clock entry.")
3717 (defun org-clock-is-active ()
3718 "Return non-nil if clock is currently running.
3719 The return value is actually the clock marker."
3720 (marker-buffer org-clock-marker
))
3725 '(org-clock-in org-clock-out org-clock-cancel
3726 org-clock-goto org-clock-sum org-clock-display
3727 org-clock-remove-overlays org-clock-report
3728 org-clocktable-shift org-dblock-write
:clocktable
3729 org-get-clocktable org-resolve-clocks
)))
3731 (defun org-clock-update-time-maybe ()
3732 "If this is a CLOCK line, update it and return t.
3733 Otherwise, return nil."
3736 (beginning-of-line 1)
3737 (skip-chars-forward " \t")
3738 (when (looking-at org-clock-string
)
3739 (let ((re (concat "[ \t]*" org-clock-string
3740 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
3741 "\\([ \t]*=>.*\\)?\\)?"))
3744 ((not (looking-at re
))
3746 ((not (match-end 2))
3747 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3748 (> org-clock-marker
(point))
3749 (<= org-clock-marker
(point-at-eol)))
3750 ;; The clock is running here
3751 (setq org-clock-start-time
3753 (org-parse-time-string (match-string 1))))
3754 (org-clock-update-mode-line)))
3756 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
3758 (setq ts
(match-string 1)
3759 te
(match-string 3))
3760 (setq s
(- (org-float-time
3761 (apply 'encode-time
(org-parse-time-string te
)))
3763 (apply 'encode-time
(org-parse-time-string ts
))))
3766 h
(floor (/ s
3600))
3770 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
3773 (defun org-check-running-clock ()
3774 "Check if the current buffer contains the running clock.
3775 If yes, offer to stop it and to save the buffer with the changes."
3776 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
3777 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
3780 (when (y-or-n-p "Save changed buffer?")
3783 (defun org-clocktable-try-shift (dir n
)
3784 "Check if this line starts a clock table, if yes, shift the time block."
3785 (when (org-match-line "#\\+BEGIN: clocktable\\>")
3786 (org-clocktable-shift dir n
)))
3788 ;; Autoload org-timer.el
3793 '(org-timer-start org-timer org-timer-item
3794 org-timer-change-times-in-region
3796 org-timer-reset-timers
3797 org-timer-show-remaining-time
)))
3799 ;; Autoload org-feed.el
3804 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
3807 ;; Autoload org-indent.el
3809 ;; Define the variable already here, to make sure we have it.
3810 (defvar org-indent-mode nil
3811 "Non-nil if Org-Indent mode is enabled.
3812 Use the command `org-indent-mode' to change this variable.")
3817 '(org-indent-mode)))
3819 ;; Autoload org-mobile.el
3824 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
3826 ;; Autoload archiving code
3827 ;; The stuff that is needed for cycling and tags has to be defined here.
3829 (defgroup org-archive nil
3830 "Options concerning archiving in Org-mode."
3832 :group
'org-structure
)
3834 (defcustom org-archive-location
"%s_archive::"
3835 "The location where subtrees should be archived.
3837 The value of this variable is a string, consisting of two parts,
3838 separated by a double-colon. The first part is a filename and
3839 the second part is a headline.
3841 When the filename is omitted, archiving happens in the same file.
3842 %s in the filename will be replaced by the current file
3843 name (without the directory part). Archiving to a different file
3844 is useful to keep archived entries from contributing to the
3847 The archived entries will be filed as subtrees of the specified
3848 headline. When the headline is omitted, the subtrees are simply
3849 filed away at the end of the file, as top-level entries. Also in
3850 the heading you can use %s to represent the file name, this can be
3851 useful when using the same archive for a number of different files.
3853 Here are a few examples:
3855 If the current file is Projects.org, archive in file
3856 Projects.org_archive, as top-level trees. This is the default.
3858 \"::* Archived Tasks\"
3859 Archive in the current file, under the top-level headline
3860 \"* Archived Tasks\".
3862 \"~/org/archive.org::\"
3863 Archive in file ~/org/archive.org (absolute path), as top-level trees.
3865 \"~/org/archive.org::From %s\"
3866 Archive in file ~/org/archive.org (absolute path), under headlines
3867 \"From FILENAME\" where file name is the current file name.
3869 \"basement::** Finished Tasks\"
3870 Archive in file ./basement (relative path), as level 3 trees
3871 below the level 2 heading \"** Finished Tasks\".
3873 You may set this option on a per-file basis by adding to the buffer a
3876 #+ARCHIVE: basement::** Finished Tasks
3878 You may also define it locally for a subtree by setting an ARCHIVE property
3879 in the entry. If such a property is found in an entry, or anywhere up
3880 the hierarchy, it will be used."
3884 (defcustom org-archive-tag
"ARCHIVE"
3885 "The tag that marks a subtree as archived.
3886 An archived subtree does not open during visibility cycling, and does
3887 not contribute to the agenda listings.
3888 After changing this, font-lock must be restarted in the relevant buffers to
3889 get the proper fontification."
3891 :group
'org-keywords
3894 (defcustom org-agenda-skip-archived-trees t
3895 "Non-nil means the agenda will skip any items located in archived trees.
3896 An archived tree is a tree marked with the tag ARCHIVE. The use of this
3897 variable is no longer recommended, you should leave it at the value t.
3898 Instead, use the key `v' to cycle the archives-mode in the agenda."
3900 :group
'org-agenda-skip
3903 (defcustom org-columns-skip-archived-trees t
3904 "Non-nil means ignore archived trees when creating column view."
3906 :group
'org-properties
3909 (defcustom org-cycle-open-archived-trees nil
3910 "Non-nil means `org-cycle' will open archived trees.
3911 An archived tree is a tree marked with the tag ARCHIVE.
3912 When nil, archived trees will stay folded. You can still open them with
3913 normal outline commands like `show-all', but not with the cycling commands."
3918 (defcustom org-sparse-tree-open-archived-trees nil
3919 "Non-nil means sparse tree construction shows matches in archived trees.
3920 When nil, matches in these trees are highlighted, but the trees are kept in
3923 :group
'org-sparse-trees
3926 (defun org-cycle-hide-archived-subtrees (state)
3927 "Re-hide all archived subtrees after a visibility state change."
3928 (when (and (not org-cycle-open-archived-trees
)
3929 (not (memq state
'(overview folded
))))
3931 (let* ((globalp (memq state
'(contents all
)))
3932 (beg (if globalp
(point-min) (point)))
3933 (end (if globalp
(point-max) (org-end-of-subtree t
))))
3934 (org-hide-archived-subtrees beg end
)
3936 (if (looking-at (concat ".*:" org-archive-tag
":"))
3937 (message "%s" (substitute-command-keys
3938 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
3940 (defun org-force-cycle-archived ()
3941 "Cycle subtree even if it is archived."
3943 (setq this-command
'org-cycle
)
3944 (let ((org-cycle-open-archived-trees t
))
3945 (call-interactively 'org-cycle
)))
3947 (defun org-hide-archived-subtrees (beg end
)
3948 "Re-hide all archived subtrees after a visibility state change."
3950 (let* ((re (concat ":" org-archive-tag
":")))
3952 (while (re-search-forward re end t
)
3953 (when (org-on-heading-p)
3954 (org-flag-subtree t
)
3955 (org-end-of-subtree t
))))))
3957 (defun org-flag-subtree (flag)
3959 (org-back-to-heading t
)
3960 (outline-end-of-heading)
3961 (outline-flag-region (point)
3962 (progn (org-end-of-subtree t
) (point))
3965 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
3968 (org-autoload "org-archive"
3969 '(org-add-archive-files org-archive-subtree
3970 org-archive-to-archive-sibling org-toggle-archive-tag
3971 org-archive-subtree-default
3972 org-archive-subtree-default-with-confirmation
)))
3974 ;; Autoload Column View Code
3976 (declare-function org-columns-number-to-string
"org-colview")
3977 (declare-function org-columns-get-format-and-top-level
"org-colview")
3978 (declare-function org-columns-compute
"org-colview")
3980 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
3981 '(org-columns-number-to-string org-columns-get-format-and-top-level
3982 org-columns-compute org-agenda-columns org-columns-remove-overlays
3983 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
3987 (declare-function org-id-store-link
"org-id")
3988 (declare-function org-id-locations-load
"org-id")
3989 (declare-function org-id-locations-save
"org-id")
3990 (defvar org-id-track-globally
)
3991 (org-autoload "org-id"
3992 '(org-id-get-create org-id-new org-id-copy org-id-get
3993 org-id-get-with-outline-path-completion
3994 org-id-get-with-outline-drilling
3995 org-id-goto org-id-find org-id-store-link
))
3997 ;; Autoload Plotting Code
3999 (org-autoload "org-plot"
4000 '(org-plot/gnuplot
))
4002 ;;; Variables for pre-computed regular expressions, all buffer local
4004 (defvar org-drawer-regexp nil
4005 "Matches first line of a hidden block.")
4006 (make-variable-buffer-local 'org-drawer-regexp
)
4007 (defvar org-todo-regexp nil
4008 "Matches any of the TODO state keywords.")
4009 (make-variable-buffer-local 'org-todo-regexp
)
4010 (defvar org-not-done-regexp nil
4011 "Matches any of the TODO state keywords except the last one.")
4012 (make-variable-buffer-local 'org-not-done-regexp
)
4013 (defvar org-not-done-heading-regexp nil
4014 "Matches a TODO headline that is not done.")
4015 (make-variable-buffer-local 'org-not-done-regexp
)
4016 (defvar org-todo-line-regexp nil
4017 "Matches a headline and puts TODO state into group 2 if present.")
4018 (make-variable-buffer-local 'org-todo-line-regexp
)
4019 (defvar org-complex-heading-regexp nil
4020 "Matches a headline and puts everything into groups:
4022 group 2: The todo keyword, maybe
4023 group 3: Priority cookie
4024 group 4: True headline
4026 (make-variable-buffer-local 'org-complex-heading-regexp
)
4027 (defvar org-complex-heading-regexp-format nil
)
4028 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
4029 (defvar org-todo-line-tags-regexp nil
4030 "Matches a headline and puts TODO state into group 2 if present.
4031 Also put tags into group 4 if tags are present.")
4032 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
4033 (defvar org-nl-done-regexp nil
4034 "Matches newline followed by a headline with the DONE keyword.")
4035 (make-variable-buffer-local 'org-nl-done-regexp
)
4036 (defvar org-looking-at-done-regexp nil
4037 "Matches the DONE keyword a point.")
4038 (make-variable-buffer-local 'org-looking-at-done-regexp
)
4039 (defvar org-ds-keyword-length
12
4040 "Maximum length of the Deadline and SCHEDULED keywords.")
4041 (make-variable-buffer-local 'org-ds-keyword-length
)
4042 (defvar org-deadline-regexp nil
4043 "Matches the DEADLINE keyword.")
4044 (make-variable-buffer-local 'org-deadline-regexp
)
4045 (defvar org-deadline-time-regexp nil
4046 "Matches the DEADLINE keyword together with a time stamp.")
4047 (make-variable-buffer-local 'org-deadline-time-regexp
)
4048 (defvar org-deadline-line-regexp nil
4049 "Matches the DEADLINE keyword and the rest of the line.")
4050 (make-variable-buffer-local 'org-deadline-line-regexp
)
4051 (defvar org-scheduled-regexp nil
4052 "Matches the SCHEDULED keyword.")
4053 (make-variable-buffer-local 'org-scheduled-regexp
)
4054 (defvar org-scheduled-time-regexp nil
4055 "Matches the SCHEDULED keyword together with a time stamp.")
4056 (make-variable-buffer-local 'org-scheduled-time-regexp
)
4057 (defvar org-closed-time-regexp nil
4058 "Matches the CLOSED keyword together with a time stamp.")
4059 (make-variable-buffer-local 'org-closed-time-regexp
)
4061 (defvar org-keyword-time-regexp nil
4062 "Matches any of the 4 keywords, together with the time stamp.")
4063 (make-variable-buffer-local 'org-keyword-time-regexp
)
4064 (defvar org-keyword-time-not-clock-regexp nil
4065 "Matches any of the 3 keywords, together with the time stamp.")
4066 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4067 (defvar org-maybe-keyword-time-regexp nil
4068 "Matches a timestamp, possibly preceeded by a keyword.")
4069 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4070 (defvar org-planning-or-clock-line-re nil
4071 "Matches a line with planning or clock info.")
4072 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
4073 (defvar org-all-time-keywords nil
4074 "List of time keywords.")
4075 (make-variable-buffer-local 'org-all-time-keywords
)
4077 (defconst org-plain-time-of-day-regexp
4080 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4083 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4085 "Regular expression to match a plain time or time range.
4086 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4087 groups carry important information:
4089 1 the first time, range or not
4090 8 the second time, if it is a range.")
4092 (defconst org-plain-time-extension-regexp
4095 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4096 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4097 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4098 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4099 groups carry important information:
4102 9 minutes of duration")
4104 (defconst org-stamp-time-of-day-regexp
4106 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4107 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4109 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4110 "Regular expression to match a timestamp time or time range.
4111 After a match, the following groups carry important information:
4113 1 date plus weekday, for back referencing to make sure both times are on the same day
4114 2 the first time, range or not
4115 4 the second time, if it is a range.")
4117 (defconst org-startup-options
4118 '(("fold" org-startup-folded t
)
4119 ("overview" org-startup-folded t
)
4120 ("nofold" org-startup-folded nil
)
4121 ("showall" org-startup-folded nil
)
4122 ("showeverything" org-startup-folded showeverything
)
4123 ("content" org-startup-folded content
)
4124 ("indent" org-startup-indented t
)
4125 ("noindent" org-startup-indented nil
)
4126 ("hidestars" org-hide-leading-stars t
)
4127 ("showstars" org-hide-leading-stars nil
)
4128 ("odd" org-odd-levels-only t
)
4129 ("oddeven" org-odd-levels-only nil
)
4130 ("align" org-startup-align-all-tables t
)
4131 ("noalign" org-startup-align-all-tables nil
)
4132 ("customtime" org-display-custom-times t
)
4133 ("logdone" org-log-done time
)
4134 ("lognotedone" org-log-done note
)
4135 ("nologdone" org-log-done nil
)
4136 ("lognoteclock-out" org-log-note-clock-out t
)
4137 ("nolognoteclock-out" org-log-note-clock-out nil
)
4138 ("logrepeat" org-log-repeat state
)
4139 ("lognoterepeat" org-log-repeat note
)
4140 ("nologrepeat" org-log-repeat nil
)
4141 ("logreschedule" org-log-reschedule time
)
4142 ("lognotereschedule" org-log-reschedule note
)
4143 ("nologreschedule" org-log-reschedule nil
)
4144 ("logredeadline" org-log-redeadline time
)
4145 ("lognoteredeadline" org-log-redeadline note
)
4146 ("nologredeadline" org-log-redeadline nil
)
4147 ("logrefile" org-log-refile time
)
4148 ("lognoterefile" org-log-refile note
)
4149 ("nologrefile" org-log-refile nil
)
4150 ("fninline" org-footnote-define-inline t
)
4151 ("nofninline" org-footnote-define-inline nil
)
4152 ("fnlocal" org-footnote-section nil
)
4153 ("fnauto" org-footnote-auto-label t
)
4154 ("fnprompt" org-footnote-auto-label nil
)
4155 ("fnconfirm" org-footnote-auto-label confirm
)
4156 ("fnplain" org-footnote-auto-label plain
)
4157 ("fnadjust" org-footnote-auto-adjust t
)
4158 ("nofnadjust" org-footnote-auto-adjust nil
)
4159 ("constcgs" constants-unit-system cgs
)
4160 ("constSI" constants-unit-system SI
)
4161 ("noptag" org-tag-persistent-alist nil
)
4162 ("hideblocks" org-hide-block-startup t
)
4163 ("nohideblocks" org-hide-block-startup nil
)
4164 ("beamer" org-startup-with-beamer-mode t
)
4165 ("entitiespretty" org-pretty-entities t
)
4166 ("entitiesplain" org-pretty-entities nil
))
4167 "Variable associated with STARTUP options for org-mode.
4168 Each element is a list of three items: The startup options as written
4169 in the #+STARTUP line, the corresponding variable, and the value to
4170 set this variable to if the option is found. An optional forth element PUSH
4171 means to push this value onto the list in the variable.")
4173 (defun org-set-regexps-and-options ()
4174 "Precompute regular expressions for current buffer."
4176 (org-set-local 'org-todo-kwd-alist nil
)
4177 (org-set-local 'org-todo-key-alist nil
)
4178 (org-set-local 'org-todo-key-trigger nil
)
4179 (org-set-local 'org-todo-keywords-1 nil
)
4180 (org-set-local 'org-done-keywords nil
)
4181 (org-set-local 'org-todo-heads nil
)
4182 (org-set-local 'org-todo-sets nil
)
4183 (org-set-local 'org-todo-log-states nil
)
4184 (org-set-local 'org-file-properties nil
)
4185 (org-set-local 'org-file-tags nil
)
4186 (let ((re (org-make-options-regexp
4187 '("CATEGORY" "TODO" "COLUMNS"
4188 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
4189 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS"
4191 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4193 (scripts org-use-sub-superscripts
)
4194 kwds kws0 kwsa key log value cat arch tags const links hw dws
4195 tail sep kws1 prio props ftags drawers beamer-p
4196 ext-setup-or-nil setup-contents
(start 0))
4200 (goto-char (point-min))
4201 (while (or (and ext-setup-or-nil
4202 (string-match re ext-setup-or-nil start
)
4203 (setq start
(match-end 0)))
4204 (and (setq ext-setup-or-nil nil start
0)
4205 (re-search-forward re nil t
)))
4206 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4207 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4208 (if (stringp value
) (setq value
(org-trim value
)))
4210 ((equal key
"CATEGORY")
4212 ((member key
'("SEQ_TODO" "TODO"))
4213 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4214 ((equal key
"TYP_TODO")
4215 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4216 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4217 ;; general TODO-like setup
4218 (push (cons (intern (downcase (match-string 1 key
)))
4219 (org-split-string value splitre
)) kwds
))
4221 (setq tags
(append tags
(if tags
'("\\n") nil
)
4222 (org-split-string value splitre
))))
4223 ((equal key
"COLUMNS")
4224 (org-set-local 'org-columns-default-format value
))
4226 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4227 (push (cons (match-string 1 value
)
4228 (org-trim (match-string 2 value
)))
4230 ((equal key
"PRIORITIES")
4231 (setq prio
(org-split-string value
" +")))
4232 ((equal key
"PROPERTY")
4233 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4234 (push (cons (match-string 1 value
) (match-string 2 value
))
4236 ((equal key
"FILETAGS")
4237 (when (string-match "\\S-" value
)
4242 (mapcar (lambda (x) (org-split-string x
":"))
4243 (org-split-string value
)))))))
4244 ((equal key
"DRAWERS")
4245 (setq drawers
(org-split-string value splitre
)))
4246 ((equal key
"CONSTANTS")
4247 (setq const
(append const
(org-split-string value splitre
))))
4248 ((equal key
"STARTUP")
4249 (let ((opts (org-split-string value splitre
))
4251 (while (setq l
(pop opts
))
4252 (when (setq l
(assoc l org-startup-options
))
4253 (setq var
(nth 1 l
) val
(nth 2 l
))
4255 (set (make-local-variable var
) val
)
4256 (if (not (listp (symbol-value var
)))
4257 (set (make-local-variable var
) nil
))
4258 (set (make-local-variable var
) (symbol-value var
))
4259 (add-to-list var val
))))))
4260 ((equal key
"ARCHIVE")
4262 (remove-text-properties 0 (length arch
)
4263 '(face t fontified t
) arch
))
4264 ((equal key
"LATEX_CLASS")
4265 (setq beamer-p
(equal value
"beamer")))
4266 ((equal key
"OPTIONS")
4267 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4268 (setq scripts
(read (match-string 2 value
)))))
4269 ((equal key
"SETUPFILE")
4270 (setq setup-contents
(org-file-contents
4272 (org-remove-double-quotes value
))
4274 (if (not ext-setup-or-nil
)
4275 (setq ext-setup-or-nil setup-contents start
0)
4276 (setq ext-setup-or-nil
4277 (concat (substring ext-setup-or-nil
0 start
)
4278 "\n" setup-contents
"\n"
4279 (substring ext-setup-or-nil start
)))))
4281 (org-set-local 'org-use-sub-superscripts scripts
)
4283 (org-set-local 'org-category
(intern cat
))
4284 (push (cons "CATEGORY" cat
) props
))
4286 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4287 (setq prio
(mapcar 'string-to-char prio
))
4288 (org-set-local 'org-highest-priority
(nth 0 prio
))
4289 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4290 (org-set-local 'org-default-priority
(nth 2 prio
)))
4291 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4292 (and ftags
(org-set-local 'org-file-tags
4293 (mapcar 'org-add-prop-inherited ftags
)))
4294 (and drawers
(org-set-local 'org-drawers drawers
))
4295 (and arch
(org-set-local 'org-archive-location arch
))
4296 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4297 ;; Process the TODO keywords
4299 ;; Use the global values as if they had been given locally.
4300 (setq kwds
(default-value 'org-todo-keywords
))
4301 (if (stringp (car kwds
))
4302 (setq kwds
(list (cons org-todo-interpretation
4303 (default-value 'org-todo-keywords
)))))
4304 (setq kwds
(reverse kwds
)))
4305 (setq kwds
(nreverse kwds
))
4307 (while (setq kws
(pop kwds
))
4309 (run-hook-with-args-until-success
4310 'org-todo-setup-filter-hook kws
)
4312 (setq inter
(pop kws
) sep
(member "|" kws
)
4313 kws0
(delete "|" (copy-sequence kws
))
4318 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4320 (setq kw
(match-string 1 x
)
4321 key
(and (match-end 2) (match-string 2 x
))
4322 log
(org-extract-log-state-settings x
))
4323 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4324 (and log
(push log org-todo-log-states
))
4326 (error "Invalid TODO keyword %s" x
)))
4328 kwsa
(if kwsa
(append '((:startgroup
))
4332 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4333 tail
(list inter hw
(car dws
) (org-last dws
))))
4334 (add-to-list 'org-todo-heads hw
'append
)
4335 (push kws1 org-todo-sets
)
4336 (setq org-done-keywords
(append org-done-keywords dws nil
))
4337 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4338 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4339 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4340 (setq org-todo-sets
(nreverse org-todo-sets
)
4341 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4342 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4343 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4344 ;; Process the constants
4347 (while (setq e
(pop const
))
4348 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4349 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4350 (setq org-table-formula-constants-local cst
)))
4352 ;; Process the tags.
4355 (while (setq e
(pop tags
))
4357 ((equal e
"{") (push '(:startgroup
) tgs
))
4358 ((equal e
"}") (push '(:endgroup
) tgs
))
4359 ((equal e
"\\n") (push '(:newline
) tgs
))
4360 ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e
)
4361 (push (cons (match-string 1 e
)
4362 (string-to-char (match-string 2 e
)))
4364 (t (push (list e
) tgs
))))
4365 (org-set-local 'org-tag-alist nil
)
4366 (while (setq e
(pop tgs
))
4367 (or (and (stringp (car e
))
4368 (assoc (car e
) org-tag-alist
))
4369 (push e org-tag-alist
)))))
4371 ;; Compute the regular expressions and other local variables
4372 (if (not org-done-keywords
)
4373 (setq org-done-keywords
(and org-todo-keywords-1
4374 (list (org-last org-todo-keywords-1
)))))
4375 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4376 (length org-scheduled-string
)
4377 (length org-clock-string
)
4378 (length org-closed-string
)))
4380 (concat "^[ \t]*:\\("
4381 (mapconcat 'regexp-quote org-drawers
"\\|")
4383 org-not-done-keywords
4384 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4386 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
4390 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4392 org-not-done-heading-regexp
4393 (concat "^\\(\\*+\\)[ \t]+\\("
4394 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4396 org-todo-line-regexp
4397 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4398 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4399 "\\)\\>\\)?[ \t]*\\(.*\\)")
4400 org-complex-heading-regexp
4401 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4402 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4403 "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
4404 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4405 org-complex-heading-regexp-format
4406 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4407 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4409 "\\(?:[ \t]*\\(\\[#.\\]\\)\\)?"
4410 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4412 "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie
4413 "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
4415 (concat "\n\\*+[ \t]+"
4416 "\\(?:" (mapconcat 'regexp-quote org-done-keywords
"\\|")
4418 org-todo-line-tags-regexp
4419 (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
4420 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4422 "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
4423 org-looking-at-done-regexp
4425 (mapconcat 'regexp-quote org-done-keywords
"\\|") "\\)"
4427 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4428 org-deadline-time-regexp
4429 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4430 org-deadline-line-regexp
4431 (concat "\\<\\(" org-deadline-string
"\\).*")
4432 org-scheduled-regexp
4433 (concat "\\<" org-scheduled-string
)
4434 org-scheduled-time-regexp
4435 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4436 org-closed-time-regexp
4437 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4438 org-keyword-time-regexp
4439 (concat "\\<\\(" org-scheduled-string
4440 "\\|" org-deadline-string
4441 "\\|" org-closed-string
4442 "\\|" org-clock-string
"\\)"
4443 " *[[<]\\([^]>]+\\)[]>]")
4444 org-keyword-time-not-clock-regexp
4445 (concat "\\<\\(" org-scheduled-string
4446 "\\|" org-deadline-string
4447 "\\|" org-closed-string
4449 " *[[<]\\([^]>]+\\)[]>]")
4450 org-maybe-keyword-time-regexp
4451 (concat "\\(\\<\\(" org-scheduled-string
4452 "\\|" org-deadline-string
4453 "\\|" org-closed-string
4454 "\\|" org-clock-string
"\\)\\)?"
4455 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4456 org-planning-or-clock-line-re
4457 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4458 "\\|" org-deadline-string
4459 "\\|" org-closed-string
"\\|" org-clock-string
4461 org-all-time-keywords
4462 (mapcar (lambda (w) (substring w
0 -
1))
4463 (list org-scheduled-string org-deadline-string
4464 org-clock-string org-closed-string
))
4466 (org-compute-latex-and-specials-regexp)
4467 (org-set-font-lock-defaults))))
4469 (defun org-file-contents (file &optional noerror
)
4470 "Return the contents of FILE, as a string."
4472 (not (file-readable-p file
)))
4475 (message "Cannot read file \"%s\"" file
)
4478 (error "Cannot read file \"%s\"" file
))
4480 (insert-file-contents file
)
4483 (defun org-extract-log-state-settings (x)
4484 "Extract the log state setting from a TODO keyword string.
4485 This will extract info from a string like \"WAIT(w@/!)\"."
4486 (let (kw key log1 log2
)
4487 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4488 (setq kw
(match-string 1 x
)
4489 key
(and (match-end 2) (match-string 2 x
))
4490 log1
(and (match-end 3) (match-string 3 x
))
4491 log2
(and (match-end 4) (match-string 4 x
)))
4494 (and log1
(if (equal log1
"!") 'time
'note
))
4495 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4497 (defun org-remove-keyword-keys (list)
4498 "Remove a pair of parenthesis at the end of each string in LIST."
4500 (if (string-match "(.*)$" x
)
4501 (substring x
0 (match-beginning 0))
4505 (defun org-assign-fast-keys (alist)
4506 "Assign fast keys to a keyword-key alist.
4507 Respect keys that are already there."
4508 (let (new e
(alt ?
0))
4509 (while (setq e
(pop alist
))
4510 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4511 (cdr e
)) ;; Key already assigned.
4513 (let ((clist (string-to-list (downcase (car e
))))
4514 (used (append new alist
)))
4515 (when (= (car clist
) ?
@)
4517 (while (and clist
(rassoc (car clist
) used
))
4520 (while (rassoc alt used
)
4522 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4525 ;;; Some variables used in various places
4527 (defvar org-window-configuration nil
4528 "Used in various places to store a window configuration.")
4529 (defvar org-selected-window nil
4530 "Used in various places to store a window configuration.")
4531 (defvar org-finish-function nil
4532 "Function to be called when `C-c C-c' is used.
4533 This is for getting out of special buffers like remember.")
4536 ;; FIXME: Occasionally check by commenting these, to make sure
4537 ;; no other functions uses these, forgetting to let-bind them.
4542 ;; Defined somewhere in this file, but used before definition.
4543 (defvar org-entities
) ;; defined in org-entities.el
4544 (defvar org-struct-menu
)
4545 (defvar org-org-menu
)
4546 (defvar org-tbl-menu
)
4548 ;;;; Define the Org-mode
4550 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4551 (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."))
4554 ;; We use a before-change function to check if a table might need
4556 (defvar org-table-may-need-update t
4557 "Indicates that a table might need an update.
4558 This variable is set by `org-before-change-function'.
4559 `org-table-align' sets it back to nil.")
4560 (defun org-before-change-function (beg end
)
4561 "Every change indicates that a table might need an update."
4562 (setq org-table-may-need-update t
))
4563 (defvar org-mode-map
)
4564 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4565 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4566 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4567 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4568 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4569 (defvar org-table-buffer-is-an nil
)
4570 (defconst org-outline-regexp
"\\*+ ")
4573 (define-derived-mode org-mode outline-mode
"Org"
4574 "Outline-based notes management and organizer, alias
4575 \"Carsten's outline-mode for keeping track of everything.\"
4577 Org-mode develops organizational tasks around a NOTES file which
4578 contains information about projects as plain text. Org-mode is
4579 implemented on top of outline-mode, which is ideal to keep the content
4580 of large files well structured. It supports ToDo items, deadlines and
4581 time stamps, which magically appear in the diary listing of the Emacs
4582 calendar. Tables are easily created with a built-in table editor.
4583 Plain text URL-like links connect to websites, emails (VM), Usenet
4584 messages (Gnus), BBDB entries, and any files related to the project.
4585 For printing and sharing of notes, an Org-mode file (or a part of it)
4586 can be exported as a structured ASCII or HTML file.
4588 The following commands are available:
4592 ;; Get rid of Outline menus, they are not needed
4593 ;; Need to do this here because define-derived-mode sets up
4594 ;; the keymap so late. Still, it is a waste to call this each time
4595 ;; we switch another buffer into org-mode.
4596 (if (featurep 'xemacs
)
4597 (when (boundp 'outline-mode-menu-heading
)
4598 ;; Assume this is Greg's port, it uses easymenu
4599 (easy-menu-remove outline-mode-menu-heading
)
4600 (easy-menu-remove outline-mode-menu-show
)
4601 (easy-menu-remove outline-mode-menu-hide
))
4602 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4603 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4604 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4606 (org-load-modules-maybe)
4607 (easy-menu-add org-org-menu
)
4608 (easy-menu-add org-tbl-menu
)
4609 (org-install-agenda-files-menu)
4610 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4611 (add-to-invisibility-spec '(org-cwidth))
4612 (add-to-invisibility-spec '(org-hide-block . t
))
4613 (when (featurep 'xemacs
)
4614 (org-set-local 'line-move-ignore-invisible t
))
4615 (org-set-local 'outline-regexp org-outline-regexp
)
4616 (org-set-local 'outline-level
'org-outline-level
)
4617 (when (and org-ellipsis
4618 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4619 (fboundp 'make-glyph-code
))
4620 (unless org-display-table
4621 (setq org-display-table
(make-display-table)))
4622 (set-display-table-slot
4625 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4627 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4628 (setq buffer-display-table org-display-table
))
4629 (org-set-regexps-and-options)
4630 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4631 ;; tag faces set outside customize.... force initialization.
4632 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4634 (org-set-local 'calc-embedded-open-mode
"# ")
4635 (modify-syntax-entry ?
@ "w")
4636 (if org-startup-truncated
(setq truncate-lines t
))
4637 (org-set-local 'font-lock-unfontify-region-function
4638 'org-unfontify-region
)
4639 ;; Activate before-change-function
4640 (org-set-local 'org-table-may-need-update t
)
4641 (org-add-hook 'before-change-functions
'org-before-change-function nil
4643 ;; Check for running clock before killing a buffer
4644 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
4645 ;; Paragraphs and auto-filling
4646 (org-set-autofill-regexps)
4647 (setq indent-line-function
'org-indent-line-function
)
4648 (org-update-radio-target-regexp)
4649 ;; Beginning/end of defun
4650 (org-set-local 'beginning-of-defun-function
'org-beginning-of-defun
)
4651 (org-set-local 'end-of-defun-function
'org-end-of-defun
)
4652 ;; Make sure dependence stuff works reliably, even for users who set it
4654 (if org-enforce-todo-dependencies
4655 (add-hook 'org-blocker-hook
4656 'org-block-todo-from-children-or-siblings-or-parent
)
4657 (remove-hook 'org-blocker-hook
4658 'org-block-todo-from-children-or-siblings-or-parent
))
4659 (if org-enforce-todo-checkbox-dependencies
4660 (add-hook 'org-blocker-hook
4661 'org-block-todo-from-checkboxes
)
4662 (remove-hook 'org-blocker-hook
4663 'org-block-todo-from-checkboxes
))
4665 ;; Comment characters
4666 (org-set-local 'comment-start
"#")
4667 (org-set-local 'comment-padding
" ")
4669 ;; Align options lines
4671 'align-mode-rules-list
4672 '((org-in-buffer-settings
4673 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
4674 (modes .
'(org-mode)))))
4677 (org-set-local 'imenu-create-index-function
4678 'org-imenu-get-tree
)
4680 ;; Make isearch reveal context
4681 (if (or (featurep 'xemacs
)
4682 (not (boundp 'outline-isearch-open-invisible-function
)))
4683 ;; Emacs 21 and XEmacs make use of the hook
4684 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
4685 ;; Emacs 22 deals with this through a special variable
4686 (org-set-local 'outline-isearch-open-invisible-function
4687 (lambda (&rest ignore
) (org-show-context 'isearch
))))
4689 ;; Turn on org-beamer-mode?
4690 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
4692 ;; If empty file that did not turn on org-mode automatically, make it to.
4693 (if (and org-insert-mode-line-in-empty-file
4695 (= (point-min) (point-max)))
4696 (insert "# -*- mode: org -*-\n\n"))
4697 (unless org-inhibit-startup
4698 (when org-startup-align-all-tables
4699 (let ((bmp (buffer-modified-p)))
4700 (org-table-map-tables 'org-table-align
'quietly
)
4701 (set-buffer-modified-p bmp
)))
4702 (when org-startup-indented
4703 (require 'org-indent
)
4704 (org-indent-mode 1))
4705 (unless org-inhibit-startup-visibility-stuff
4706 (org-set-startup-visibility))))
4708 (when (fboundp 'abbrev-table-put
)
4709 (abbrev-table-put org-mode-abbrev-table
4710 :parents
(list text-mode-abbrev-table
)))
4712 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
4714 (defun org-current-time ()
4715 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
4716 (if (> (car org-time-stamp-rounding-minutes
) 1)
4717 (let ((r (car org-time-stamp-rounding-minutes
))
4718 (time (decode-time)))
4720 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
4724 ;;;; Font-Lock stuff, including the activators
4726 (defvar org-mouse-map
(make-sparse-keymap))
4727 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
4728 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
4729 (when org-mouse-1-follows-link
4730 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
4731 (when org-tab-follows-link
4732 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
4733 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
4735 (require 'font-lock
)
4737 (defconst org-non-link-chars
"]\t\n\r<>")
4738 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
4739 "shell" "elisp" "doi"))
4740 (defvar org-link-types-re nil
4741 "Matches a link that has a url-like prefix like \"http:\"")
4742 (defvar org-link-re-with-space nil
4743 "Matches a link with spaces, optional angular brackets around it.")
4744 (defvar org-link-re-with-space2 nil
4745 "Matches a link with spaces, optional angular brackets around it.")
4746 (defvar org-link-re-with-space3 nil
4747 "Matches a link with spaces, only for internal part in bracket links.")
4748 (defvar org-angle-link-re nil
4749 "Matches link with angular brackets, spaces are allowed.")
4750 (defvar org-plain-link-re nil
4751 "Matches plain link, without spaces.")
4752 (defvar org-bracket-link-regexp nil
4753 "Matches a link in double brackets.")
4754 (defvar org-bracket-link-analytic-regexp nil
4755 "Regular expression used to analyze links.
4756 Here is what the match groups contain after a match:
4762 (defvar org-bracket-link-analytic-regexp
++ nil
4763 "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
4764 (defvar org-any-link-re nil
4765 "Regular expression matching any link.")
4767 (defcustom org-match-sexp-depth
3
4768 "Number of stacked braces for sub/superscript matching.
4769 This has to be set before loading org.el to be effective."
4770 :group
'org-export-translation
; ??????????????????????????/
4773 (defun org-create-multibrace-regexp (left right n
)
4774 "Create a regular expression which will match a balanced sexp.
4775 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4776 as single character strings.
4777 The regexp returned will match the entire expression including the
4778 delimiters. It will also define a single group which contains the
4779 match except for the outermost delimiters. The maximum depth of
4780 stacked delimiters is N. Escaping delimiters is not possible."
4781 (let* ((nothing (concat "[^" left right
"]*?"))
4784 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4787 re
(concat re or next
)
4788 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4789 (concat left
"\\(" re
"\\)" right
)))
4791 (defvar org-match-substring-regexp
4793 "\\([^\\]\\)\\([_^]\\)\\("
4794 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4796 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4798 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4799 "The regular expression matching a sub- or superscript.")
4801 (defvar org-match-substring-with-braces-regexp
4803 "\\([^\\]\\)\\([_^]\\)\\("
4804 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4806 "The regular expression matching a sub- or superscript, forcing braces.")
4808 (defun org-make-link-regexps ()
4809 "Update the link regular expressions.
4810 This should be called after the variable `org-link-types' has changed."
4811 (setq org-link-types-re
4813 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
4814 org-link-re-with-space
4816 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4817 "\\([^" org-non-link-chars
" ]"
4818 "[^" org-non-link-chars
"]*"
4819 "[^" org-non-link-chars
" ]\\)>?")
4820 org-link-re-with-space2
4822 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4823 "\\([^" org-non-link-chars
" ]"
4825 "[^" org-non-link-chars
" ]\\)>?")
4826 org-link-re-with-space3
4828 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4829 "\\([^" org-non-link-chars
" ]"
4833 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4834 "\\([^" org-non-link-chars
" ]"
4835 "[^" org-non-link-chars
"]*"
4839 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
4840 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
4841 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
4842 org-bracket-link-regexp
4843 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
4844 org-bracket-link-analytic-regexp
4847 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
4850 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4852 org-bracket-link-analytic-regexp
++
4855 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
4858 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
4861 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
4862 org-angle-link-re
"\\)\\|\\("
4863 org-plain-link-re
"\\)")))
4865 (org-make-link-regexps)
4867 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
4868 "Regular expression for fast time stamp matching.")
4869 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
4870 "Regular expression for fast time stamp matching.")
4871 (defconst org-ts-regexp0
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4872 "Regular expression matching time strings for analysis.
4873 This one does not require the space after the date, so it can be used
4874 on a string that terminates immediately after the date.")
4875 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
4876 "Regular expression matching time strings for analysis.")
4877 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
4878 "Regular expression matching time stamps, with groups.")
4879 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
4880 "Regular expression matching time stamps (also [..]), with groups.")
4881 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
4882 "Regular expression matching a time stamp range.")
4883 (defconst org-tr-regexp-both
4884 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
4885 "Regular expression matching a time stamp range.")
4886 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
4887 org-ts-regexp
"\\)?")
4888 "Regular expression matching a time stamp or time stamp range.")
4889 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
4890 org-ts-regexp-both
"\\)?")
4891 "Regular expression matching a time stamp or time stamp range.
4892 The time stamps may be either active or inactive.")
4894 (defvar org-emph-face nil
)
4896 (defun org-do-emphasis-faces (limit)
4897 "Run through the buffer and add overlays to links."
4899 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
4900 (if (not (= (char-after (match-beginning 3))
4901 (char-after (match-beginning 4))))
4904 (setq a
(assoc (match-string 3) org-emphasis-alist
))
4905 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
4909 (org-remove-flyspell-overlays-in
4910 (match-beginning 0) (match-end 0)))
4911 (add-text-properties (match-beginning 2) (match-end 2)
4912 '(font-lock-multiline t org-emphasis t
))
4913 (when org-hide-emphasis-markers
4914 (add-text-properties (match-end 4) (match-beginning 5)
4915 '(invisible org-link
))
4916 (add-text-properties (match-beginning 3) (match-end 3)
4917 '(invisible org-link
)))))
4921 (defun org-emphasize (&optional char
)
4922 "Insert or change an emphasis, i.e. a font like bold or italic.
4923 If there is an active region, change that region to a new emphasis.
4924 If there is no region, just insert the marker characters and position
4925 the cursor between them.
4926 CHAR should be either the marker character, or the first character of the
4927 HTML tag associated with that emphasis. If CHAR is a space, the means
4928 to remove the emphasis of the selected region.
4929 If char is not given (for example in an interactive call) it
4930 will be prompted for."
4932 (let ((eal org-emphasis-alist
) e det
4933 (erc org-emphasis-regexp-components
)
4935 (string "") beg end move tag c s
)
4936 (if (org-region-active-p)
4937 (setq beg
(region-beginning) end
(region-end)
4938 string
(buffer-substring beg end
))
4941 (while (setq e
(pop eal
))
4942 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
4944 (push (cons c
(string-to-char (car e
))) det
)
4945 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
4946 (substring tag
1)))))
4947 (setq det
(nreverse det
))
4949 (message "%s" (concat "Emphasis marker or tag:" prompt
))
4950 (setq char
(read-char-exclusive)))
4951 (setq char
(or (cdr (assoc char det
)) char
))
4952 (if (equal char ?\
)
4953 (setq s
"" move nil
)
4954 (unless (assoc (char-to-string char
) org-emphasis-alist
)
4955 (error "No such emphasis marker: \"%c\"" char
))
4956 (setq s
(char-to-string char
)))
4957 (while (and (> (length string
) 1)
4958 (equal (substring string
0 1) (substring string -
1))
4959 (assoc (substring string
0 1) org-emphasis-alist
))
4960 (setq string
(substring string
1 -
1)))
4961 (setq string
(concat s string s
))
4962 (if beg
(delete-region beg end
))
4964 (string-match (concat "[" (nth 0 erc
) "\n]")
4965 (char-to-string (char-before (point)))))
4968 (string-match (concat "[" (nth 1 erc
) "\n]")
4969 (char-to-string (char-after (point)))))
4970 (insert " ") (backward-char 1))
4972 (and move
(backward-char 1))))
4974 (defconst org-nonsticky-props
4975 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
4977 (defsubst org-rear-nonsticky-at
(pos)
4978 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
4980 (defun org-activate-plain-links (limit)
4981 "Run through the buffer and add overlays to links."
4984 (if (re-search-forward org-plain-link-re limit t
)
4986 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
4987 (setq f
(get-text-property (match-beginning 0) 'face
))
4988 (if (or (eq f
'org-tag
)
4989 (and (listp f
) (memq 'org-tag f
)))
4991 (add-text-properties (match-beginning 0) (match-end 0)
4992 (list 'mouse-face
'highlight
4994 'keymap org-mouse-map
))
4995 (org-rear-nonsticky-at (match-end 0)))
4998 (defun org-activate-code (limit)
4999 (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t
)
5001 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5002 (remove-text-properties (match-beginning 0) (match-end 0)
5003 '(display t invisible t intangible t
))
5006 (defun org-fontify-meta-lines-and-blocks (limit)
5007 "Fontify #+ lines and blocks, in the correct ways."
5008 (let ((case-fold-search t
))
5009 (if (re-search-forward
5010 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
5012 (let ((beg (match-beginning 0))
5013 (beg1 (line-beginning-position 2))
5014 (dc1 (downcase (match-string 2)))
5015 (dc3 (downcase (match-string 3)))
5016 end end1 quoting block-type
)
5018 ((member dc1
'("html:" "ascii:" "latex:" "docbook:"))
5019 ;; a single line of backend-specific content
5020 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5021 (remove-text-properties (match-beginning 0) (match-end 0)
5022 '(display t invisible t intangible t
))
5023 (add-text-properties (match-beginning 1) (match-end 3)
5024 '(font-lock-fontified t face org-meta-line
))
5025 (add-text-properties (match-beginning 6) (match-end 6)
5026 '(font-lock-fontified t face org-block
))
5028 ((and (match-end 4) (equal dc3
"begin"))
5030 (setq block-type
(downcase (match-string 5))
5031 quoting
(member block-type org-protecting-blocks
))
5032 (when (re-search-forward
5033 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
5034 nil t
) ;; on purpose, we look further than LIMIT
5035 (setq end
(match-end 0) end1
(1- (match-beginning 0)))
5037 (remove-text-properties beg end
5038 '(display t invisible t intangible t
)))
5039 (add-text-properties
5041 '(font-lock-fontified t font-lock-multiline t
))
5042 (add-text-properties beg beg1
'(face org-meta-line
))
5043 (add-text-properties end1 end
'(face org-meta-line
))
5046 (add-text-properties beg1 end1
'(face org-block
)))
5047 ((not org-fontify-quote-and-verse-blocks
))
5048 ((string= block-type
"quote")
5049 (add-text-properties beg1 end1
'(face org-quote
)))
5050 ((string= block-type
"verse")
5051 (add-text-properties beg1 end1
'(face org-verse
))))
5053 ((member dc1
'("title:" "author:" "email:" "date:"))
5054 (add-text-properties
5056 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
5057 '(font-lock-fontified t invisible t
)
5058 '(font-lock-fontified t face org-document-info-keyword
)))
5059 (add-text-properties
5060 (match-beginning 6) (match-end 6)
5061 (if (string-equal dc1
"title:")
5062 '(font-lock-fontified t face org-document-title
)
5063 '(font-lock-fontified t face org-document-info
))))
5064 ((not (member (char-after beg
) '(?\ ?
\t)))
5065 ;; just any other in-buffer setting, but not indented
5066 (add-text-properties
5068 '(font-lock-fontified t face org-meta-line
))
5070 ((or (member dc1
'("begin:" "end:" "caption:" "label:"
5071 "orgtbl:" "tblfm:" "tblname:" "result:"
5072 "results:" "source:" "srcname:" "call:"))
5073 (and (match-end 4) (equal dc3
"attr")))
5074 (add-text-properties
5076 '(font-lock-fontified t face org-meta-line
))
5078 ((member dc3
'(" " ""))
5079 (add-text-properties
5081 '(font-lock-fontified t face font-lock-comment-face
)))
5084 (defun org-activate-angle-links (limit)
5085 "Run through the buffer and add overlays to links."
5086 (if (re-search-forward org-angle-link-re limit t
)
5088 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5089 (add-text-properties (match-beginning 0) (match-end 0)
5090 (list 'mouse-face
'highlight
5091 'keymap org-mouse-map
))
5092 (org-rear-nonsticky-at (match-end 0))
5095 (defun org-activate-footnote-links (limit)
5096 "Run through the buffer and add overlays to links."
5097 (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
5100 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5101 (add-text-properties (match-beginning 2) (match-end 2)
5102 (list 'mouse-face
'highlight
5103 'keymap org-mouse-map
5105 (if (= (point-at-bol) (match-beginning 2))
5106 "Footnote definition"
5107 "Footnote reference")
5109 (org-rear-nonsticky-at (match-end 2))
5112 (defun org-activate-bracket-links (limit)
5113 "Run through the buffer and add overlays to bracketed links."
5114 (if (re-search-forward org-bracket-link-regexp limit t
)
5115 (let* ((help (concat "LINK: "
5116 (org-match-string-no-properties 1)))
5117 ;; FIXME: above we should remove the escapes.
5118 ;; but that requires another match, protecting match data,
5119 ;; a lot of overhead for font-lock.
5120 (ip (org-maybe-intangible
5121 (list 'invisible
'org-link
5122 'keymap org-mouse-map
'mouse-face
'highlight
5123 'font-lock-multiline t
'help-echo help
)))
5124 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5125 'font-lock-multiline t
'help-echo help
)))
5126 ;; We need to remove the invisible property here. Table narrowing
5127 ;; may have made some of this invisible.
5128 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5129 (remove-text-properties (match-beginning 0) (match-end 0)
5133 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5134 (org-rear-nonsticky-at (match-beginning 3))
5135 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5136 (org-rear-nonsticky-at (match-end 3))
5137 (add-text-properties (match-end 3) (match-end 0) ip
)
5138 (org-rear-nonsticky-at (match-end 0)))
5139 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5140 (org-rear-nonsticky-at (match-beginning 1))
5141 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5142 (org-rear-nonsticky-at (match-end 1))
5143 (add-text-properties (match-end 1) (match-end 0) ip
)
5144 (org-rear-nonsticky-at (match-end 0)))
5147 (defun org-activate-dates (limit)
5148 "Run through the buffer and add overlays to dates."
5149 (if (re-search-forward org-tsr-regexp-both limit t
)
5151 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5152 (add-text-properties (match-beginning 0) (match-end 0)
5153 (list 'mouse-face
'highlight
5154 'keymap org-mouse-map
))
5155 (org-rear-nonsticky-at (match-end 0))
5156 (when org-display-custom-times
5158 (org-display-custom-time (match-beginning 3) (match-end 3)))
5159 (org-display-custom-time (match-beginning 1) (match-end 1)))
5162 (defvar org-target-link-regexp nil
5163 "Regular expression matching radio targets in plain text.")
5164 (make-variable-buffer-local 'org-target-link-regexp
)
5165 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5166 "Regular expression matching a link target.")
5167 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5168 "Regular expression matching a radio target.")
5169 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5170 "Regular expression matching any target.")
5172 (defun org-activate-target-links (limit)
5173 "Run through the buffer and add overlays to target matches."
5174 (when org-target-link-regexp
5175 (let ((case-fold-search t
))
5176 (if (re-search-forward org-target-link-regexp limit t
)
5178 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5179 (add-text-properties (match-beginning 0) (match-end 0)
5180 (list 'mouse-face
'highlight
5181 'keymap org-mouse-map
5182 'help-echo
"Radio target link"
5183 'org-linked-text t
))
5184 (org-rear-nonsticky-at (match-end 0))
5187 (defun org-update-radio-target-regexp ()
5188 "Find all radio targets in this file and update the regular expression."
5190 (when (memq 'radio org-activate-links
)
5191 (setq org-target-link-regexp
5192 (org-make-target-link-regexp (org-all-targets 'radio
)))
5193 (org-restart-font-lock)))
5195 (defun org-hide-wide-columns (limit)
5197 (setq s
(text-property-any (point) (or limit
(point-max))
5200 (setq e
(next-single-property-change s
'org-cwidth
))
5201 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5205 (defvar org-latex-and-specials-regexp nil
5206 "Regular expression for highlighting export special stuff.")
5207 (defvar org-match-substring-regexp
)
5208 (defvar org-match-substring-with-braces-regexp
)
5210 ;; This should be with the exporter code, but we also use if for font-locking
5211 (defconst org-export-html-special-string-regexps
5212 '(("\\\\-" .
"­")
5213 ("---\\([^-]\\)" .
"—\\1")
5214 ("--\\([^-]\\)" .
"–\\1")
5215 ("\\.\\.\\." .
"…"))
5216 "Regular expressions for special string conversion.")
5219 (defun org-compute-latex-and-specials-regexp ()
5220 "Compute regular expression for stuff treated specially by exporters."
5221 (if (not org-highlight-latex-fragments-and-specials
)
5222 (org-set-local 'org-latex-and-specials-regexp nil
)
5225 ((matchers (plist-get org-format-latex-options
:matchers
))
5226 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
5227 org-latex-regexps
)))
5228 (org-export-allow-BIND nil
)
5229 (options (org-combine-plists (org-default-export-plist)
5230 (org-infile-export-plist)))
5231 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
5232 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
5233 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
5234 (org-export-html-expand (plist-get options
:expand-quoted-html
))
5235 (org-export-with-special-strings (plist-get options
:special-strings
))
5238 ((equal org-export-with-sub-superscripts
'{})
5239 (list org-match-substring-with-braces-regexp
))
5240 (org-export-with-sub-superscripts
5241 (list org-match-substring-regexp
))
5244 (if org-export-with-LaTeX-fragments
5245 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
5247 (if org-export-with-TeX-macros
5248 (list (concat "\\\\"
5254 (append org-entities-user
5256 (if (boundp 'org-latex-entities
)
5258 (or (car-safe x
) x
))
5263 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5264 (re-special (if org-export-with-special-strings
5265 (mapcar (lambda (x) (car x
))
5266 org-export-html-special-string-regexps
)))
5270 (if org-export-html-expand
"@<[^>\n]+>")
5273 'org-latex-and-specials-regexp
5274 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5277 (defun org-do-latex-and-special-faces (limit)
5278 "Run through the buffer and add overlays to links."
5279 (when org-latex-and-specials-regexp
5281 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5283 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5285 '(org-code org-verbatim underline
)))
5288 d
(cond ((member (char-after (1+ (match-beginning 0)))
5291 (font-lock-prepend-text-property
5292 (+ d
(match-beginning 0)) (match-end 0)
5293 'face
'org-latex-and-export-specials
)
5294 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5295 '(font-lock-multiline t
)))))
5298 (defun org-restart-font-lock ()
5299 "Restart font-lock-mode, to force refontification."
5300 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5302 (font-lock-mode 1)))
5304 (defun org-all-targets (&optional radio
)
5305 "Return a list of all targets in this file.
5306 With optional argument RADIO, only find radio targets."
5307 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5310 (goto-char (point-min))
5311 (while (re-search-forward re nil t
)
5312 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5315 (defun org-make-target-link-regexp (targets)
5316 "Make regular expression matching all strings in TARGETS.
5317 The regular expression finds the targets also if there is a line break
5324 (while (string-match " +" x
)
5325 (setq x
(replace-match "\\s-+" t t x
)))
5331 (defun org-activate-tags (limit)
5332 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t
)
5334 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5335 (add-text-properties (match-beginning 1) (match-end 1)
5336 (list 'mouse-face
'highlight
5337 'keymap org-mouse-map
))
5338 (org-rear-nonsticky-at (match-end 1))
5341 (defun org-outline-level ()
5342 "Compute the outline level of the heading at point.
5343 This function assumes that the cursor is at the beginning of a line matched
5344 by outline-regexp. Otherwise it returns garbage.
5345 If this is called at a normal headline, the level is the number of stars.
5346 Use `org-reduced-level' to remove the effect of `org-odd-levels'.
5347 For plain list items, if they are matched by `outline-regexp', this returns
5348 1000 plus the line indentation."
5350 (looking-at outline-regexp
)
5351 (if (match-beginning 1)
5352 (+ (org-get-string-indentation (match-string 1)) 1000)
5353 (1- (- (match-end 0) (match-beginning 0))))))
5355 (defvar org-font-lock-keywords nil
)
5357 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5358 "Regular expression matching a property line.")
5360 (defvar org-font-lock-hook nil
5361 "Functions to be called for special font lock stuff.")
5363 (defun org-font-lock-hook (limit)
5364 (run-hook-with-args 'org-font-lock-hook limit
))
5366 (defun org-set-font-lock-defaults ()
5367 (let* ((em org-fontify-emphasized-text
)
5368 (lk org-activate-links
)
5369 (org-font-lock-extra-keywords
5372 '(org-font-lock-hook)
5374 `(,(if org-fontify-whole-heading-line
5375 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5376 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5377 (1 (org-get-level-face 1))
5378 (2 (org-get-level-face 2))
5379 (3 (org-get-level-face 3)))
5381 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5384 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5385 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5386 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5387 '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t
))
5389 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5390 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5392 (list org-property-re
5393 '(1 'org-special-keyword t
)
5394 '(3 'org-property-value t
))
5396 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5397 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5398 (if (memq 'plain lk
) '(org-activate-plain-links))
5399 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5400 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5401 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5402 (if (memq 'footnote lk
) '(org-activate-footnote-links
5403 (2 'org-footnote t
)))
5404 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5405 '(org-hide-wide-columns (0 nil append
))
5407 (list (concat "^\\*+[ \t]+" org-todo-regexp
"\\([ \t]\\|$\\)")
5408 '(1 (org-get-todo-face 1) t
))
5410 (if org-fontify-done-headline
5411 (list (concat "^[*]+ +\\<\\("
5412 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5414 '(2 'org-headline-done t
))
5417 '(org-font-lock-add-priority-faces)
5419 '(org-font-lock-add-tag-faces)
5421 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5422 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5423 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5424 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5427 (if (featurep 'xemacs
)
5428 '(org-do-emphasis-faces (0 nil append
))
5429 '(org-do-emphasis-faces)))
5431 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
5432 2 'org-checkbox prepend
)
5433 (if org-provide-checkbox-statistics
5434 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5435 (0 (org-get-checkbox-statistics-face) t
)))
5436 ;; Description list items
5437 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
5439 ;; ARCHIVEd headings
5440 (list (concat "^\\*+ \\(.*:" org-archive-tag
":.*\\)")
5441 '(1 'org-archived prepend
))
5443 '(org-do-latex-and-special-faces)
5444 '(org-fontify-entities)
5445 '(org-raise-scripts)
5447 '(org-activate-code (1 'org-code t
))
5449 (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
5450 "\\|" org-quote-string
"\\)\\>")
5451 '(1 'org-special-keyword t
))
5452 '("^#.*" (0 'font-lock-comment-face t
))
5453 ;; Blocks and meta lines
5454 '(org-fontify-meta-lines-and-blocks)
5456 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5457 ;; Now set the full font-lock-keywords
5458 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5459 (org-set-local 'font-lock-defaults
5460 '(org-font-lock-keywords t nil nil backward-paragraph
))
5461 (kill-local-variable 'font-lock-keywords
) nil
))
5463 (defun org-toggle-pretty-entities ()
5464 "Toggle the compostion display of entities as UTF8 characters."
5466 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
5467 (org-restart-font-lock)
5468 (if org-pretty-entities
5469 (message "Entities are displayed as UTF8 characers")
5472 (decompose-region (point-min) (point-max))
5473 (message "Entities are displayed plain"))))
5475 (defun org-fontify-entities (limit)
5476 "Find an entity to fontify."
5478 (when org-pretty-entities
5480 (while (re-search-forward
5481 "\\\\\\([a-zA-Z][a-zA-Z0-9]*\\)\\($\\|[^[:alnum:]\n]\\)"
5483 (if (and (not (org-in-indented-comment-line))
5484 (setq ee
(org-entity-get (match-string 1)))
5485 (= (length (nth 6 ee
)) 1))
5487 (add-text-properties
5488 (match-beginning 0) (match-end 1)
5489 (list 'font-lock-fontified t
))
5490 (compose-region (match-beginning 0) (match-end 1)
5496 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
5497 "Fontify string S like in Org-mode"
5500 (let ((org-odd-levels-only odd-levels
))
5502 (font-lock-fontify-buffer)
5508 (defun org-get-level-face (n)
5509 "Get the right face for match N in font-lock matching of headlines."
5510 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
5511 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
5512 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
5514 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
5516 (t (if org-level-color-stars-only nil org-f
))))
5518 (defun org-get-todo-face (kwd)
5519 "Get the right face for a TODO keyword KWD.
5520 If KWD is a number, get the corresponding match group."
5521 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5522 (or (org-face-from-face-or-color
5523 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
5524 (and (member kwd org-done-keywords
) 'org-done
)
5527 (defun org-face-from-face-or-color (context inherit face-or-color
)
5528 "Create a face list that inherits INHERIT, but sets the foreground color.
5529 When FACE-OR-COLOR is not a string, just return it."
5530 (if (stringp face-or-color
)
5531 (list :inherit inherit
5532 (cdr (assoc context org-faces-easy-properties
))
5536 (defun org-font-lock-add-tag-faces (limit)
5537 "Add the special tag faces."
5538 (when (and org-tag-faces org-tags-special-faces-re
)
5539 (while (re-search-forward org-tags-special-faces-re limit t
)
5540 (add-text-properties (match-beginning 1) (match-end 1)
5541 (list 'face
(org-get-tag-face 1)
5542 'font-lock-fontified t
))
5543 (backward-char 1))))
5545 (defun org-font-lock-add-priority-faces (limit)
5546 "Add the special priority faces."
5547 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
5548 (add-text-properties
5549 (match-beginning 0) (match-end 0)
5550 (list 'face
(or (org-face-from-face-or-color
5551 'priority
'org-special-keyword
5552 (cdr (assoc (char-after (match-beginning 1))
5553 org-priority-faces
)))
5554 'org-special-keyword
)
5555 'font-lock-fontified t
))))
5557 (defun org-get-tag-face (kwd)
5558 "Get the right face for a TODO keyword KWD.
5559 If KWD is a number, get the corresponding match group."
5560 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5561 (or (org-face-from-face-or-color
5562 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
5565 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
5566 "Remove fontification and activation overlays from links."
5567 (font-lock-default-unfontify-region beg end
)
5568 (let* ((buffer-undo-list t
)
5569 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
5570 (inhibit-modification-hooks t
)
5571 deactivate-mark buffer-file-name buffer-file-truename
)
5572 (decompose-region beg end
)
5573 (remove-text-properties
5576 ;; also remove line-prefix and wrap-prefix properties
5577 '(mouse-face t keymap t org-linked-text t
5578 invisible t intangible t
5579 line-prefix t wrap-prefix t
5580 org-no-flyspell t org-emphasis t
)
5581 '(mouse-face t keymap t org-linked-text t
5582 invisible t intangible t
5583 org-no-flyspell t org-emphasis t
)))
5584 (org-remove-font-lock-display-properties beg end
)))
5586 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
5587 ((raise 0.3) (height 0.7))
5590 "Display properties for showing superscripts and subscripts.")
5592 (defun org-remove-font-lock-display-properties (beg end
)
5593 "Remove specific display properties that have been added by font lock.
5594 The will remove the raise properties that are used to show superscripts
5598 (setq next
(next-single-property-change beg
'display nil end
)
5599 prop
(get-text-property beg
'display
))
5600 (if (member prop org-script-display
)
5601 (put-text-property beg next
'display nil
))
5604 (defun org-raise-scripts (limit)
5605 "Add raise properties to sub/superscripts."
5606 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
5607 (if (re-search-forward
5608 (if (eq org-use-sub-superscripts t
)
5609 org-match-substring-regexp
5610 org-match-substring-with-braces-regexp
)
5612 (let* ((pos (point)) table-p comment-p
5613 (mpos (match-beginning 3))
5614 (emph-p (get-text-property mpos
'org-emphasis
))
5615 (link-p (get-text-property mpos
'mouse-face
))
5616 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
5617 (goto-char (point-at-bol))
5618 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
5619 comment-p
(org-looking-at-p "[ \t]*#"))
5621 ;; FIXME: Should we go back one character here, for a_b^c
5622 ;; (goto-char (1- pos)) ;????????????????????
5623 (if (or comment-p emph-p link-p keyw-p
)
5625 (put-text-property (match-beginning 3) (match-end 0)
5627 (if (equal (char-after (match-beginning 2)) ?^
)
5628 (nth (if table-p
3 1) org-script-display
)
5629 (nth (if table-p
2 0) org-script-display
)))
5630 (add-text-properties (match-beginning 2) (match-end 2)
5632 'org-dwidth t
'org-dwidth-n
1))
5633 (if (and (eq (char-after (match-beginning 3)) ?
{)
5634 (eq (char-before (match-end 3)) ?
}))
5636 (add-text-properties
5637 (match-beginning 3) (1+ (match-beginning 3))
5638 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
5639 (add-text-properties
5640 (1- (match-end 3)) (match-end 3)
5641 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
5644 ;;;; Visibility cycling, including org-goto and indirect buffer
5648 (defvar org-cycle-global-status nil
)
5649 (make-variable-buffer-local 'org-cycle-global-status
)
5650 (defvar org-cycle-subtree-status nil
)
5651 (make-variable-buffer-local 'org-cycle-subtree-status
)
5655 (defvar org-inlinetask-min-level
)
5657 (defun org-cycle (&optional arg
)
5658 "TAB-action and visibility cycling for Org-mode.
5660 This is the command invoked in Org-mode by the TAB key. Its main purpose
5661 is outline visibility cycling, but it also invokes other actions
5662 in special contexts.
5664 - When this function is called with a prefix argument, rotate the entire
5665 buffer through 3 states (global cycling)
5666 1. OVERVIEW: Show only top-level headlines.
5667 2. CONTENTS: Show all headlines of all levels, but no body text.
5668 3. SHOW ALL: Show everything.
5669 When called with two `C-u C-u' prefixes, switch to the startup visibility,
5670 determined by the variable `org-startup-folded', and by any VISIBILITY
5671 properties in the buffer.
5672 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
5673 including any drawers.
5675 - When inside a table, re-align the table and move to the next field.
5677 - When point is at the beginning of a headline, rotate the subtree started
5678 by this line through 3 different states (local cycling)
5679 1. FOLDED: Only the main headline is shown.
5680 2. CHILDREN: The main headline and the direct children are shown.
5681 From this state, you can move to one of the children
5682 and zoom in further.
5683 3. SUBTREE: Show the entire subtree, including body text.
5684 If there is no subtree, switch directly from CHILDREN to FOLDED.
5686 - When point is at the beginning of an empty headline and the variable
5687 `org-cycle-level-after-item/entry-creation' is set, cycle the level
5688 of the headline by demoting and promoting it to likely levels. This
5689 speeds up creation document structure by presing TAB once or several
5690 times right after creating a new headline.
5692 - When there is a numeric prefix, go up to a heading with level ARG, do
5693 a `show-subtree' and return to the previous cursor position. If ARG
5694 is negative, go up that many levels.
5696 - When point is not at the beginning of a headline, execute the global
5697 binding for TAB, which is re-indenting the line. See the option
5698 `org-cycle-emulate-tab' for details.
5700 - Special case: if point is at the beginning of the buffer and there is
5701 no headline in line 1, this function will act as if called with prefix arg.
5702 But only if also the variable `org-cycle-global-at-bob' is t."
5704 (org-load-modules-maybe)
5705 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
5706 (and org-cycle-level-after-item
/entry-creation
5707 (or (org-cycle-level)
5708 (org-cycle-item-indentation))))
5710 (or org-cycle-max-level
5711 (and (boundp 'org-inlinetask-min-level
)
5712 org-inlinetask-min-level
5713 (1- org-inlinetask-min-level
))))
5714 (nstars (and limit-level
5715 (if org-odd-levels-only
5716 (and limit-level
(1- (* limit-level
2)))
5720 ((not (org-mode-p)) outline-regexp
)
5721 ((or (eq org-cycle-include-plain-lists
'integrate
)
5722 (and org-cycle-include-plain-lists
(org-at-item-p)))
5724 (if nstars
(format "\\{1,%d\\}" nstars
) "+")
5725 " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
5726 (t (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ ")))))
5727 (bob-special (and org-cycle-global-at-bob
(bobp)
5728 (not (looking-at outline-regexp
))))
5731 (delq 'org-optimize-window-after-visibility-change
5732 (copy-sequence org-cycle-hook
))
5736 (if (or bob-special
(equal arg
'(4)))
5737 ;; special case: use global cycling
5743 (org-set-startup-visibility)
5744 (message "Startup visibility, plus VISIBILITY properties"))
5748 (message "Entire buffer visible, including drawers"))
5750 ((org-at-table-p 'any
)
5751 ;; Enter the table or move to the next field in the table
5752 (if (org-at-table.el-p
)
5753 (message "Use C-c ' to edit table.el tables")
5754 (if arg
(org-table-edit-field t
)
5755 (org-table-justify-field-maybe)
5756 (call-interactively 'org-table-next-field
))))
5758 ((run-hook-with-args-until-success
5759 'org-tab-after-check-for-table-hook
))
5761 ((eq arg t
) ;; Global cycling
5762 (org-cycle-internal-global))
5764 ((and org-drawers org-drawer-regexp
5766 (beginning-of-line 1)
5767 (looking-at org-drawer-regexp
)))
5768 ;; Toggle block visibility
5770 (not (get-char-property (match-end 0) 'invisible
))))
5773 ;; Show-subtree, ARG levels up from here.
5775 (org-back-to-heading)
5776 (outline-up-heading (if (< arg
0) (- arg
)
5777 (- (funcall outline-level
) arg
)))
5778 (org-show-subtree)))
5780 ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp
))
5781 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
5783 (org-cycle-internal-local))
5785 ;; TAB emulation and template completion
5786 (buffer-read-only (org-back-to-heading))
5788 ((run-hook-with-args-until-success
5789 'org-tab-after-check-for-cycling-hook
))
5791 ((org-try-structure-completion))
5793 ((org-try-cdlatex-tab))
5795 ((run-hook-with-args-until-success
5796 'org-tab-before-tab-emulation-hook
))
5798 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
5800 (not (looking-at outline-regexp
))))
5801 (call-interactively (global-key-binding "\t")))
5803 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
5804 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
5805 (or (and (eq org-cycle-emulate-tab
'white
)
5806 (= (match-end 0) (point-at-eol)))
5807 (and (eq org-cycle-emulate-tab
'whitestart
)
5808 (>= (match-end 0) pos
))))
5810 (eq org-cycle-emulate-tab t
))
5811 (call-interactively (global-key-binding "\t")))
5814 (org-back-to-heading)
5817 (defun org-cycle-internal-global ()
5818 "Do the global cycling action."
5820 ((and (eq last-command this-command
)
5821 (eq org-cycle-global-status
'overview
))
5822 ;; We just created the overview - now do table of contents
5823 ;; This can be slow in very large buffers, so indicate action
5824 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
5825 (message "CONTENTS...")
5827 (message "CONTENTS...done")
5828 (setq org-cycle-global-status
'contents
)
5829 (run-hook-with-args 'org-cycle-hook
'contents
))
5831 ((and (eq last-command this-command
)
5832 (eq org-cycle-global-status
'contents
))
5833 ;; We just showed the table of contents - now show everything
5834 (run-hook-with-args 'org-pre-cycle-hook
'all
)
5836 (message "SHOW ALL")
5837 (setq org-cycle-global-status
'all
)
5838 (run-hook-with-args 'org-cycle-hook
'all
))
5841 ;; Default action: go to overview
5842 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
5844 (message "OVERVIEW")
5845 (setq org-cycle-global-status
'overview
)
5846 (run-hook-with-args 'org-cycle-hook
'overview
))))
5848 (defun org-cycle-internal-local ()
5849 "Do the local cycling action."
5850 (org-back-to-heading)
5851 (let ((goal-column 0) eoh eol eos level has-children children-skipped
)
5852 ;; First, some boundaries
5854 (org-back-to-heading)
5855 (setq level
(funcall outline-level
))
5857 (beginning-of-line 2)
5858 (if (or (featurep 'xemacs
) (<= emacs-major-version
21))
5859 ; XEmacs does not have `next-single-char-property-change'
5860 ; I'm not sure about Emacs 21.
5861 (while (and (not (eobp)) ;; this is like `next-line'
5862 (get-char-property (1- (point)) 'invisible
))
5863 (beginning-of-line 2))
5864 (while (and (not (eobp)) ;; this is like `next-line'
5865 (get-char-property (1- (point)) 'invisible
))
5866 (goto-char (next-single-char-property-change (point) 'invisible
))
5867 (and (eolp) (beginning-of-line 2))))
5869 (outline-end-of-heading) (setq eoh
(point))
5871 (outline-next-heading)
5872 (setq has-children
(and (org-at-heading-p t
)
5873 (> (funcall outline-level
) level
))))
5874 (org-end-of-subtree t
)
5876 (skip-chars-forward " \t\n")
5877 (beginning-of-line 1) ; in case this is an item
5879 (setq eos
(if (eobp) (point) (1- (point)))))
5880 ;; Find out what to do next and set `this-command'
5883 ;; Nothing is hidden behind this heading
5884 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
5885 (message "EMPTY ENTRY")
5886 (setq org-cycle-subtree-status nil
)
5889 (outline-next-heading)
5890 (if (org-invisible-p) (org-flag-heading nil
))))
5891 ((and (or (>= eol eos
)
5892 (not (string-match "\\S-" (buffer-substring eol eos
))))
5894 (not (setq children-skipped
5895 org-cycle-skip-children-state-if-no-children
))))
5896 ;; Entire subtree is hidden in one line: children view
5897 (run-hook-with-args 'org-pre-cycle-hook
'children
)
5900 (message "CHILDREN")
5903 (outline-next-heading)
5904 (if (org-invisible-p) (org-flag-heading nil
)))
5905 (setq org-cycle-subtree-status
'children
)
5906 (run-hook-with-args 'org-cycle-hook
'children
))
5907 ((or children-skipped
5908 (and (eq last-command this-command
)
5909 (eq org-cycle-subtree-status
'children
)))
5910 ;; We just showed the children, or no children are there,
5911 ;; now show everything.
5912 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
5914 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
5915 (setq org-cycle-subtree-status
'subtree
)
5916 (run-hook-with-args 'org-cycle-hook
'subtree
))
5918 ;; Default action: hide the subtree.
5919 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
5922 (setq org-cycle-subtree-status
'folded
)
5923 (run-hook-with-args 'org-cycle-hook
'folded
)))))
5926 (defun org-global-cycle (&optional arg
)
5927 "Cycle the global visibility. For details see `org-cycle'.
5928 With C-u prefix arg, switch to startup visibility.
5929 With a numeric prefix, show all headlines up to that level."
5931 (let ((org-cycle-include-plain-lists
5932 (if (org-mode-p) org-cycle-include-plain-lists nil
)))
5936 (hide-sublevels arg
)
5937 (setq org-cycle-global-status
'contents
))
5939 (org-set-startup-visibility)
5940 (message "Startup visibility, plus VISIBILITY properties."))
5942 (org-cycle '(4))))))
5944 (defun org-set-startup-visibility ()
5945 "Set the visibility required by startup options and properties."
5947 ((eq org-startup-folded t
)
5949 ((eq org-startup-folded
'content
)
5950 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
5951 (org-cycle '(4)) (org-cycle '(4)))))
5952 (unless (eq org-startup-folded
'showeverything
)
5953 (if org-hide-block-startup
(org-hide-block-all))
5954 (org-set-visibility-according-to-property 'no-cleanup
)
5955 (org-cycle-hide-archived-subtrees 'all
)
5956 (org-cycle-hide-drawers 'all
)
5957 (org-cycle-show-empty-lines t
)))
5959 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
5960 "Switch subtree visibilities according to :VISIBILITY: property."
5962 (let (org-show-entry-below state
)
5964 (goto-char (point-min))
5965 (while (re-search-forward
5966 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
5968 (setq state
(match-string 1))
5970 (org-back-to-heading t
)
5974 ((equal state
'("fold" "folded"))
5976 ((equal state
"children")
5977 (org-show-hidden-entry)
5979 ((equal state
"content")
5982 (org-narrow-to-subtree)
5984 ((member state
'("all" "showall"))
5987 (org-cycle-hide-archived-subtrees 'all
)
5988 (org-cycle-hide-drawers 'all
)
5989 (org-cycle-show-empty-lines 'all
)))))
5991 (defun org-overview ()
5992 "Switch to overview mode, showing only top-level headlines.
5993 Really, this shows all headlines with level equal or greater than the level
5994 of the first headline in the buffer. This is important, because if the
5995 first headline is not level one, then (hide-sublevels 1) gives confusing
5998 (let ((level (save-excursion
5999 (goto-char (point-min))
6000 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
6002 (goto-char (match-beginning 0))
6003 (funcall outline-level
))))))
6004 (and level
(hide-sublevels level
))))
6006 (defun org-content (&optional arg
)
6007 "Show all headlines in the buffer, like a table of contents.
6008 With numerical argument N, show content up to level N."
6011 ;; Visit all headings and show their offspring
6012 (and (integerp arg
) (org-overview))
6013 (goto-char (point-max))
6015 (while (and (progn (condition-case nil
6016 (outline-previous-visible-heading 1)
6017 (error (goto-char (point-min))))
6019 (looking-at outline-regexp
))
6021 (show-children (1- arg
))
6023 (if (bobp) (throw 'exit nil
))))))
6026 (defun org-optimize-window-after-visibility-change (state)
6027 "Adjust the window after a change in outline visibility.
6028 This function is the default value of the hook `org-cycle-hook'."
6029 (when (get-buffer-window (current-buffer))
6031 ((eq state
'content
) nil
)
6032 ((eq state
'all
) nil
)
6033 ((eq state
'folded
) nil
)
6034 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
6035 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
6037 (defun org-remove-empty-overlays-at (pos)
6038 "Remove outline overlays that do not contain non-white stuff."
6041 (and (eq 'outline
(overlay-get o
'invisible
))
6042 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
6044 (delete-overlay o
)))
6047 (defun org-clean-visibility-after-subtree-move ()
6048 "Fix visibility issues after moving a subtree."
6049 ;; First, find a reasonable region to look at:
6050 ;; Start two siblings above, end three below
6051 (let* ((beg (save-excursion
6052 (and (org-get-last-sibling)
6053 (org-get-last-sibling))
6055 (end (save-excursion
6056 (and (org-get-next-sibling)
6057 (org-get-next-sibling)
6058 (org-get-next-sibling))
6059 (if (org-at-heading-p)
6062 (level (looking-at "\\*+"))
6063 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6066 (narrow-to-region beg end
)
6068 ;; Properly fold already folded siblings
6069 (goto-char (point-min))
6070 (while (re-search-forward re nil t
)
6071 (if (and (not (org-invisible-p))
6073 (goto-char (point-at-eol)) (org-invisible-p)))
6075 (org-cycle-show-empty-lines 'overview
)
6076 (org-cycle-hide-drawers 'overview
)))))
6078 (defun org-cycle-show-empty-lines (state)
6079 "Show empty lines above all visible headlines.
6080 The region to be covered depends on STATE when called through
6081 `org-cycle-hook'. Lisp program can use t for STATE to get the
6082 entire buffer covered. Note that an empty line is only shown if there
6083 are at least `org-cycle-separator-lines' empty lines before the headline."
6084 (when (not (= org-cycle-separator-lines
0))
6086 (let* ((n (abs org-cycle-separator-lines
))
6088 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6089 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6090 (t (let ((ns (number-to-string (- n
2))))
6091 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6092 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6095 ((memq state
'(overview contents t
))
6096 (setq beg
(point-min) end
(point-max)))
6097 ((memq state
'(children folded
))
6098 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6099 (beginning-of-line 2)
6103 (while (re-search-forward re end t
)
6104 (unless (get-char-property (match-end 1) 'invisible
)
6105 (setq e
(match-end 1))
6106 (if (< org-cycle-separator-lines
0)
6107 (setq b
(save-excursion
6108 (goto-char (match-beginning 0))
6109 (org-back-over-empty-lines)
6111 (goto-char (max (point-min) (1- (point))))
6115 (setq b
(match-beginning 1)))
6116 (outline-flag-region b e nil
)))))))
6117 ;; Never hide empty lines at the end of the file.
6119 (goto-char (point-max))
6120 (outline-previous-heading)
6121 (outline-end-of-heading)
6122 (if (and (looking-at "[ \t\n]+")
6123 (= (match-end 0) (point-max)))
6124 (outline-flag-region (point) (match-end 0) nil
))))
6126 (defun org-show-empty-lines-in-parent ()
6127 "Move to the parent and re-show empty lines before visible headlines."
6129 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6130 (org-cycle-show-empty-lines context
))))
6132 (defun org-files-list ()
6133 "Return `org-agenda-files' list, plus all open org-mode files.
6134 This is useful for operations that need to scan all of a user's
6135 open and agenda-wise Org files."
6136 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6137 (dolist (buf (buffer-list))
6138 (with-current-buffer buf
6139 (if (and (eq major-mode
'org-mode
) (buffer-file-name))
6140 (let ((file (expand-file-name (buffer-file-name))))
6141 (unless (member file files
)
6142 (push file files
))))))
6145 (defsubst org-entry-beginning-position
()
6146 "Return the beginning position of the current entry."
6147 (save-excursion (outline-back-to-heading t
) (point)))
6149 (defsubst org-entry-end-position
()
6150 "Return the end position of the current entry."
6151 (save-excursion (outline-next-heading) (point)))
6153 (defun org-cycle-hide-drawers (state)
6154 "Re-hide all drawers after a visibility state change."
6155 (when (and (org-mode-p)
6156 (not (memq state
'(overview folded contents
))))
6158 (let* ((globalp (memq state
'(contents all
)))
6159 (beg (if globalp
(point-min) (point)))
6160 (end (if globalp
(point-max)
6161 (if (eq state
'children
)
6162 (save-excursion (outline-next-heading) (point))
6163 (org-end-of-subtree t
)))))
6165 (while (re-search-forward org-drawer-regexp end t
)
6166 (org-flag-drawer t
))))))
6168 (defun org-flag-drawer (flag)
6170 (beginning-of-line 1)
6171 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6172 (let ((b (match-end 0))
6173 (outline-regexp org-outline-regexp
))
6174 (if (re-search-forward
6176 (save-excursion (outline-next-heading) (point)) t
)
6177 (outline-flag-region b
(point-at-eol) flag
)
6178 (error ":END: line missing at position %s" b
))))))
6180 (defun org-subtree-end-visible-p ()
6181 "Is the end of the current subtree visible?"
6182 (pos-visible-in-window-p
6183 (save-excursion (org-end-of-subtree t
) (point))))
6185 (defun org-first-headline-recenter (&optional N
)
6186 "Move cursor to the first headline and recenter the headline.
6187 Optional argument N means put the headline into the Nth line of the window."
6188 (goto-char (point-min))
6189 (when (re-search-forward (concat "^\\(" outline-regexp
"\\)") nil t
)
6191 (recenter (prefix-numeric-value N
))))
6193 ;;; Saving and restoring visibility
6195 (defun org-outline-overlay-data (&optional use-markers
)
6196 "Return a list of the locations of all outline overlays.
6197 The are overlays with the `invisible' property value `outline'.
6198 The return valus is a list of cons cells, with start and stop
6199 positions for each overlay.
6200 If USE-MARKERS is set, return the positions as markers."
6207 (when (eq (overlay-get o
'invisible
) 'outline
)
6208 (setq beg
(overlay-start o
)
6209 end
(overlay-end o
))
6210 (and beg end
(> end beg
)
6212 (cons (move-marker (make-marker) beg
)
6213 (move-marker (make-marker) end
))
6215 (overlays-in (point-min) (point-max))))))))
6217 (defun org-set-outline-overlay-data (data)
6218 "Create visibility overlays for all positions in DATA.
6219 DATA should have been made by `org-outline-overlay-data'."
6226 (setq o
(make-overlay (car c
) (cdr c
)))
6227 (overlay-put o
'invisible
'outline
))
6230 (defmacro org-save-outline-visibility
(use-markers &rest body
)
6231 "Save and restore outline visibility around BODY.
6232 If USE-MARKERS is non-nil, use markers for the positions.
6233 This means that the buffer may change while running BODY,
6234 but it also means that the buffer should stay alive
6235 during the operation, because otherwise all these markers will
6237 (declare (indent 1))
6238 `(let ((data (org-outline-overlay-data ,use-markers
)))
6242 (org-set-outline-overlay-data data
))
6245 (and (markerp (car c
)) (move-marker (car c
) nil
))
6246 (and (markerp (cdr c
)) (move-marker (cdr c
) nil
)))
6250 ;;; Folding of blocks
6252 (defconst org-block-regexp
6254 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
6255 "Regular expression for hiding blocks.")
6257 (defvar org-hide-block-overlays nil
6258 "Overlays hiding blocks.")
6259 (make-variable-buffer-local 'org-hide-block-overlays
)
6261 (defun org-block-map (function &optional start end
)
6262 "Call func at the head of all source blocks in the current
6263 buffer. Optional arguments START and END can be used to limit
6265 (let ((start (or start
(point-min)))
6266 (end (or end
(point-max))))
6269 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6272 (goto-char (match-beginning 0))
6273 (funcall function
)))))))
6275 (defun org-hide-block-toggle-all ()
6276 "Toggle the visibility of all blocks in the current buffer."
6277 (org-block-map #'org-hide-block-toggle
))
6279 (defun org-hide-block-all ()
6280 "Fold all blocks in the current buffer."
6282 (org-show-block-all)
6283 (org-block-map #'org-hide-block-toggle-maybe
))
6285 (defun org-show-block-all ()
6286 "Unfold all blocks in the current buffer."
6288 (mapc 'delete-overlay org-hide-block-overlays
)
6289 (setq org-hide-block-overlays nil
))
6291 (defun org-hide-block-toggle-maybe ()
6292 "Toggle visibility of block at point."
6294 (let ((case-fold-search t
))
6296 (beginning-of-line 1)
6297 (looking-at org-block-regexp
))
6298 (progn (org-hide-block-toggle)
6299 t
) ;; to signal that we took action
6300 nil
))) ;; to signal that we did not
6302 (defun org-hide-block-toggle (&optional force
)
6303 "Toggle the visibility of the current block."
6307 (if (re-search-forward org-block-regexp nil t
)
6308 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6309 (end (match-end 0)) ;; end of entire body
6311 (if (memq t
(mapcar (lambda (overlay)
6312 (eq (overlay-get overlay
'invisible
)
6314 (overlays-at start
)))
6315 (if (or (not force
) (eq force
'off
))
6317 (when (member ov org-hide-block-overlays
)
6318 (setq org-hide-block-overlays
6319 (delq ov org-hide-block-overlays
)))
6320 (when (eq (overlay-get ov
'invisible
)
6322 (delete-overlay ov
)))
6323 (overlays-at start
)))
6324 (setq ov
(make-overlay start end
))
6325 (overlay-put ov
'invisible
'org-hide-block
)
6326 ;; make the block accessible to isearch
6328 ov
'isearch-open-invisible
6330 (when (member ov org-hide-block-overlays
)
6331 (setq org-hide-block-overlays
6332 (delq ov org-hide-block-overlays
)))
6333 (when (eq (overlay-get ov
'invisible
)
6335 (delete-overlay ov
))))
6336 (push ov org-hide-block-overlays
)))
6337 (error "Not looking at a source block"))))
6339 ;; org-tab-after-check-for-cycling-hook
6340 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6341 ;; Remove overlays when changing major mode
6342 (add-hook 'org-mode-hook
6343 (lambda () (org-add-hook 'change-major-mode-hook
6344 'org-show-block-all
'append
'local
)))
6348 (defvar org-goto-window-configuration nil
)
6349 (defvar org-goto-marker nil
)
6350 (defvar org-goto-map
6351 (let ((map (make-sparse-keymap)))
6352 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6353 (while (setq cmd
(pop cmds
))
6354 (substitute-key-definition cmd cmd map global-map
)))
6355 (suppress-keymap map
)
6356 (org-defkey map
"\C-m" 'org-goto-ret
)
6357 (org-defkey map
[(return)] 'org-goto-ret
)
6358 (org-defkey map
[(left)] 'org-goto-left
)
6359 (org-defkey map
[(right)] 'org-goto-right
)
6360 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6361 (org-defkey map
"\C-i" 'org-cycle
)
6362 (org-defkey map
[(tab)] 'org-cycle
)
6363 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6364 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6365 (if org-goto-auto-isearch
6366 (if (fboundp 'define-key-after
)
6367 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6369 (org-defkey map "q" 'org-goto-quit)
6370 (org-defkey map "n" 'outline-next-visible-heading)
6371 (org-defkey map "p" 'outline-previous-visible-heading)
6372 (org-defkey map "f" 'outline-forward-same-level)
6373 (org-defkey map "b" 'outline-backward-same-level)
6374 (org-defkey map "u" 'outline-up-heading))
6375 (org-defkey map "/" 'org-occur)
6376 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6377 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6378 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6379 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6380 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6383 (defconst org-goto-help
6384 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6385 RET=jump to location [Q]uit and return to previous location
6386 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6388 (defvar org-goto-start-pos) ; dynamically scoped parameter
6390 ;; FIXME: Docstring does not mention both interfaces
6391 (defun org-goto (&optional alternative-interface)
6392 "Look up a different location in the current file, keeping current visibility.
6394 When you want look-up or go to a different location in a document, the
6395 fastest way is often to fold the entire buffer and then dive into the tree.
6396 This method has the disadvantage, that the previous location will be folded,
6397 which may not be what you want.
6399 This command works around this by showing a copy of the current buffer
6400 in an indirect buffer, in overview mode. You can dive into the tree in
6401 that copy, use org-occur and incremental search to find a location.
6402 When pressing RET or `Q', the command returns to the original buffer in
6403 which the visibility is still unchanged. After RET is will also jump to
6404 the location selected in the indirect buffer and expose the
6405 the headline hierarchy above."
6407 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6408 (org-refile-use-outline-path t)
6409 (org-refile-target-verify-function nil)
6411 (if (not alternative-interface)
6413 (if (eq org-goto-interface 'outline)
6414 'outline-path-completion
6416 (org-goto-start-pos (point))
6418 (if (eq interface 'outline)
6419 (car (org-get-location (current-buffer) org-goto-help))
6420 (nth 3 (org-refile-get-location "Goto: ")))))
6423 (org-mark-ring-push org-goto-start-pos)
6424 (goto-char selected-point)
6425 (if (or (org-invisible-p) (org-invisible-p2))
6426 (org-show-context 'org-goto)))
6429 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6430 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6431 (defvar org-goto-local-auto-isearch-map) ; defined below
6433 (defun org-get-location (buf help)
6434 "Let the user select a location in the Org-mode buffer BUF.
6435 This function uses a recursive edit. It returns the selected position
6437 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6438 (isearch-hide-immediately nil)
6439 (isearch-search-fun-function
6440 (lambda () 'org-goto-local-search-headings))
6441 (org-goto-selected-point org-goto-exit-command)
6443 (special-display-buffer-names nil)
6444 (special-display-regexps nil)
6445 (special-display-function nil))
6447 (save-window-excursion
6448 (delete-other-windows)
6449 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6452 (make-indirect-buffer (current-buffer) "*org-goto*")
6453 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6454 (with-output-to-temp-buffer "*Help*"
6456 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6457 (setq buffer-read-only nil)
6458 (let ((org-startup-truncated t)
6459 (org-startup-folded nil)
6460 (org-startup-align-all-tables nil))
6463 (setq buffer-read-only t)
6464 (if (and (boundp 'org-goto-start-pos)
6465 (integer-or-marker-p org-goto-start-pos))
6466 (let ((org-show-hierarchy-above t)
6467 (org-show-siblings t)
6468 (org-show-following-heading t))
6469 (goto-char org-goto-start-pos)
6470 (and (org-invisible-p) (org-show-context)))
6471 (goto-char (point-min)))
6472 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6473 (message "Select location and press RET")
6474 (use-local-map org-goto-map)
6477 (kill-buffer "*org-goto*")
6478 (cons org-goto-selected-point org-goto-exit-command)))
6480 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6481 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6482 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6483 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6485 (defun org-goto-local-search-headings (string bound noerror)
6486 "Search and make sure that any matches are in headlines."
6488 (while (if isearch-forward
6489 (search-forward string bound noerror)
6490 (search-backward string bound noerror))
6491 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6492 (and (member :headline context)
6493 (not (member :tags context))))
6494 (throw 'return (point))))))
6496 (defun org-goto-local-auto-isearch ()
6499 (goto-char (point-min))
6500 (let ((keys (this-command-keys)))
6501 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6503 (isearch-process-search-char (string-to-char keys)))))
6505 (defun org-goto-ret (&optional arg)
6506 "Finish `org-goto' by going to the new location."
6508 (setq org-goto-selected-point (point)
6509 org-goto-exit-command 'return)
6512 (defun org-goto-left ()
6513 "Finish `org-goto' by going to the new location."
6515 (if (org-on-heading-p)
6517 (beginning-of-line 1)
6518 (setq org-goto-selected-point (point)
6519 org-goto-exit-command 'left)
6521 (error "Not on a heading")))
6523 (defun org-goto-right ()
6524 "Finish `org-goto' by going to the new location."
6526 (if (org-on-heading-p)
6528 (setq org-goto-selected-point (point)
6529 org-goto-exit-command 'right)
6531 (error "Not on a heading")))
6533 (defun org-goto-quit ()
6534 "Finish `org-goto' without cursor motion."
6536 (setq org-goto-selected-point nil)
6537 (setq org-goto-exit-command 'quit)
6540 ;;; Indirect buffer display of subtrees
6542 (defvar org-indirect-dedicated-frame nil
6543 "This is the frame being used for indirect tree display.")
6544 (defvar org-last-indirect-buffer nil)
6546 (defun org-tree-to-indirect-buffer (&optional arg)
6547 "Create indirect buffer and narrow it to current subtree.
6548 With numerical prefix ARG, go up to this level and then take that tree.
6549 If ARG is negative, go up that many levels.
6550 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6551 indirect buffer previously made with this command, to avoid proliferation of
6552 indirect buffers. However, when you call the command with a `C-u' prefix, or
6553 when `org-indirect-buffer-display' is `new-frame', the last buffer
6554 is kept so that you can work with several indirect buffers at the same time.
6555 If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
6556 requests that a new frame be made for the new buffer, so that the dedicated
6557 frame is not changed."
6559 (let ((cbuf (current-buffer))
6560 (cwin (selected-window))
6562 beg end level heading ibuf)
6564 (org-back-to-heading t)
6566 (setq level (org-outline-level))
6567 (if (< arg 0) (setq arg (+ level arg)))
6568 (while (> (setq level (org-outline-level)) arg)
6569 (outline-up-heading 1 t)))
6571 heading (org-get-heading))
6572 (org-end-of-subtree t t)
6573 (if (org-on-heading-p) (backward-char 1))
6575 (if (and (buffer-live-p org-last-indirect-buffer)
6576 (not (eq org-indirect-buffer-display 'new-frame))
6578 (kill-buffer org-last-indirect-buffer))
6579 (setq ibuf (org-get-indirect-buffer cbuf)
6580 org-last-indirect-buffer ibuf)
6582 ((or (eq org-indirect-buffer-display 'new-frame)
6583 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6584 (select-frame (make-frame))
6585 (delete-other-windows)
6586 (switch-to-buffer ibuf)
6587 (org-set-frame-title heading))
6588 ((eq org-indirect-buffer-display 'dedicated-frame)
6590 (select-frame (or (and org-indirect-dedicated-frame
6591 (frame-live-p org-indirect-dedicated-frame)
6592 org-indirect-dedicated-frame)
6593 (setq org-indirect-dedicated-frame (make-frame)))))
6594 (delete-other-windows)
6595 (switch-to-buffer ibuf)
6596 (org-set-frame-title (concat "Indirect: " heading)))
6597 ((eq org-indirect-buffer-display 'current-window)
6598 (switch-to-buffer ibuf))
6599 ((eq org-indirect-buffer-display 'other-window)
6600 (pop-to-buffer ibuf))
6601 (t (error "Invalid value")))
6602 (if (featurep 'xemacs)
6603 (save-excursion (org-mode) (turn-on-font-lock)))
6604 (narrow-to-region beg end)
6607 (and (window-live-p cwin) (select-window cwin))))
6609 (defun org-get-indirect-buffer (&optional buffer)
6610 (setq buffer (or buffer (current-buffer)))
6611 (let ((n 1) (base (buffer-name buffer)) bname)
6612 (while (buffer-live-p
6613 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6616 (make-indirect-buffer buffer bname 'clone)
6617 (error (make-indirect-buffer buffer bname)))))
6619 (defun org-set-frame-title (title)
6620 "Set the title of the current frame to the string TITLE."
6621 ;; FIXME: how to name a single frame in XEmacs???
6622 (unless (featurep 'xemacs)
6623 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6625 ;;;; Structure editing
6627 ;;; Inserting headlines
6629 (defun org-previous-line-empty-p ()
6632 (or (beginning-of-line 0) t)
6634 (looking-at "[ \t]*$")))))
6636 (defun org-insert-heading (&optional force-heading invisible-ok)
6637 "Insert a new heading or item with same depth at point.
6638 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6639 If point is at the beginning of a headline, insert a sibling before the
6640 current headline. If point is not at the beginning, do not split the line,
6641 but create the new headline after the current line.
6642 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6643 This is important for non-interactive uses of the command."
6645 (if (or (= (buffer-size) 0)
6646 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6647 (org-on-heading-p))))
6648 (not (org-in-item-p))))
6650 (when (or force-heading (not (org-insert-item)))
6651 (let* ((empty-line-p nil)
6652 (head (save-excursion
6655 (org-back-to-heading invisible-ok)
6656 (setq empty-line-p (org-previous-line-empty-p))
6659 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6660 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6661 pos hide-previous previous-pos)
6663 ((and (org-on-heading-p) (bolp)
6665 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6666 ;; insert before the current line
6667 (open-line (if blank 2 1)))
6669 (not org-insert-heading-respect-content)
6672 (backward-char 1) (not (org-invisible-p)))))
6673 ;; insert right here
6676 ;; somewhere in the line
6678 (setq previous-pos (point-at-bol))
6680 (setq hide-previous (org-invisible-p)))
6681 (and org-insert-heading-respect-content (org-show-subtree))
6683 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6686 (goto-char (point-at-bol))
6687 (and (looking-at org-complex-heading-regexp)
6688 (> p (match-beginning 4)))))))
6691 (org-insert-heading-respect-content
6692 (org-end-of-subtree nil t)
6693 (or (bolp) (newline))
6694 (or (org-previous-line-empty-p)
6695 (and blank (newline)))
6701 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6702 (setq tags (and (match-end 2) (match-string 2)))
6704 (delete-region (match-beginning 1) (match-end 1)))
6705 (setq pos (point-at-bol))
6706 (or split (end-of-line 1))
6707 (delete-horizontal-space)
6708 (if (string-match "\\`\\*+\\'"
6709 (buffer-substring (point-at-bol) (point)))
6711 (newline (if blank 2 1))
6717 (org-set-tags nil 'align))))
6719 (or split (end-of-line 1))
6720 (newline (if blank 2 1)))))))
6721 (insert head) (just-one-space)
6724 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6725 (when (and org-insert-heading-respect-content hide-previous)
6727 (goto-char previous-pos)
6729 (run-hooks 'org-insert-heading-hook)))))
6731 (defun org-get-heading (&optional no-tags)
6732 "Return the heading of the current entry, without the stars."
6734 (org-back-to-heading t)
6737 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6738 "\\*+[ \t]+\\([^\r\n]*\\)"))
6739 (match-string 1) "")))
6741 (defun org-heading-components ()
6742 "Return the components of the current heading.
6743 This is a list with the following elements:
6744 - the level as an integer
6745 - the reduced level, different if `org-odd-levels-only' is set.
6746 - the TODO keyword, or nil
6747 - the priority character, like ?A, or nil if no priority is given
6748 - the headline text itself, or the tags string if no headline text
6749 - the tags string, or nil."
6751 (org-back-to-heading t)
6752 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6753 (list (length (match-string 1))
6754 (org-reduced-level (length (match-string 1)))
6755 (org-match-string-no-properties 2)
6756 (and (match-end 3) (aref (match-string 3) 2))
6757 (org-match-string-no-properties 4)
6758 (org-match-string-no-properties 5)))))
6760 (defun org-get-entry ()
6761 "Get the entry text, after heading, entire subtree."
6763 (org-back-to-heading t)
6764 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6766 (defun org-insert-heading-after-current ()
6767 "Insert a new heading with same level as current, after current subtree."
6769 (org-back-to-heading)
6770 (org-insert-heading)
6771 (org-move-subtree-down)
6774 (defun org-insert-heading-respect-content ()
6776 (let ((org-insert-heading-respect-content t))
6777 (org-insert-heading t)))
6779 (defun org-insert-todo-heading-respect-content (&optional force-state)
6781 (let ((org-insert-heading-respect-content t))
6782 (org-insert-todo-heading force-state t)))
6784 (defun org-insert-todo-heading (arg &optional force-heading)
6785 "Insert a new heading with the same level and TODO state as current heading.
6786 If the heading has no TODO state, or if the state is DONE, use the first
6787 state (TODO by default). Also with prefix arg, force first state."
6789 (when (or force-heading (not (org-insert-item 'checkbox)))
6790 (org-insert-heading force-heading)
6792 (org-back-to-heading)
6793 (outline-previous-heading)
6794 (looking-at org-todo-line-regexp))
6798 (not (match-beginning 2))
6799 (member (match-string 2) org-done-keywords))
6800 (car org-todo-keywords-1)
6804 (run-hook-with-args-until-success
6805 'org-todo-get-default-hook new-mark-x nil)
6807 (beginning-of-line 1)
6808 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6809 (if org-treat-insert-todo-heading-as-state-change
6811 (insert new-mark " "))))
6812 (when org-provide-todo-statistics
6813 (org-update-parent-todo-statistics))))
6815 (defun org-insert-subheading (arg)
6816 "Insert a new subheading and demote it.
6817 Works for outline headings and for plain lists alike."
6819 (org-insert-heading arg)
6821 ((org-on-heading-p) (org-do-demote))
6822 ((org-at-item-p) (org-indent-item 1))))
6824 (defun org-insert-todo-subheading (arg)
6825 "Insert a new subheading with TODO keyword or checkbox and demote it.
6826 Works for outline headings and for plain lists alike."
6828 (org-insert-todo-heading arg)
6830 ((org-on-heading-p) (org-do-demote))
6831 ((org-at-item-p) (org-indent-item 1))))
6833 ;;; Promotion and Demotion
6835 (defvar org-after-demote-entry-hook nil
6836 "Hook run after an entry has been demoted.
6837 The cursor will be at the beginning of the entry.
6838 When a subtree is being demoted, the hook will be called for each node.")
6840 (defvar org-after-promote-entry-hook nil
6841 "Hook run after an entry has been promoted.
6842 The cursor will be at the beginning of the entry.
6843 When a subtree is being promoted, the hook will be called for each node.")
6845 (defun org-promote-subtree ()
6846 "Promote the entire subtree.
6847 See also `org-promote'."
6850 (org-map-tree 'org-promote))
6851 (org-fix-position-after-promote))
6853 (defun org-demote-subtree ()
6854 "Demote the entire subtree. See `org-demote'.
6855 See also `org-promote'."
6858 (org-map-tree 'org-demote))
6859 (org-fix-position-after-promote))
6862 (defun org-do-promote ()
6863 "Promote the current heading higher up the tree.
6864 If the region is active in `transient-mark-mode', promote all headings
6868 (if (org-region-active-p)
6869 (org-map-region 'org-promote (region-beginning) (region-end))
6871 (org-fix-position-after-promote))
6873 (defun org-do-demote ()
6874 "Demote the current heading lower down the tree.
6875 If the region is active in `transient-mark-mode', demote all headings
6879 (if (org-region-active-p)
6880 (org-map-region 'org-demote (region-beginning) (region-end))
6882 (org-fix-position-after-promote))
6884 (defun org-fix-position-after-promote ()
6885 "Make sure that after pro/demotion cursor position is right."
6886 (let ((pos (point)))
6887 (when (save-excursion
6888 (beginning-of-line 1)
6889 (looking-at org-todo-line-regexp)
6890 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6891 (cond ((eobp) (insert " "))
6892 ((eolp) (insert " "))
6893 ((equal (char-after) ?\ ) (forward-char 1))))))
6895 (defun org-current-level ()
6896 "Return the level of the current entry, or nil if before the first headline.
6897 The level is the number of stars at the beginning of the headline."
6901 (org-back-to-heading t)
6902 (funcall outline-level))
6905 (defun org-get-previous-line-level ()
6906 "Return the outline depth of the last headline before the current line.
6907 Returns 0 for the first headline in the buffer, and nil if before the
6909 (let ((current-level (org-current-level))
6910 (prev-level (when (> (line-number-at-pos) 1)
6912 (beginning-of-line 0)
6913 (org-current-level)))))
6914 (cond ((null current-level) nil) ; Before first headline
6915 ((null prev-level) 0) ; At first headline
6918 (defun org-reduced-level (l)
6919 "Compute the effective level of a heading.
6920 This takes into account the setting of `org-odd-levels-only'."
6921 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6923 (defun org-level-increment ()
6924 "Return the number of stars that will be added or removed at a
6925 time to headlines when structure editing, based on the value of
6926 `org-odd-levels-only'."
6927 (if org-odd-levels-only 2 1))
6929 (defun org-get-valid-level (level &optional change)
6930 "Rectify a level change under the influence of `org-odd-levels-only'
6931 LEVEL is a current level, CHANGE is by how much the level should be
6932 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6933 even level numbers will become the next higher odd number."
6934 (if org-odd-levels-only
6935 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6936 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6937 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6938 (max 1 (+ level (or change 0)))))
6940 (if (boundp 'define-obsolete-function-alias)
6941 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6942 (define-obsolete-function-alias 'org-get-legal-level
6943 'org-get-valid-level)
6944 (define-obsolete-function-alias 'org-get-legal-level
6945 'org-get-valid-level "23.1")))
6947 (defun org-promote ()
6948 "Promote the current heading higher up the tree.
6949 If the region is active in `transient-mark-mode', promote all headings
6951 (org-back-to-heading t)
6952 (let* ((level (save-match-data (funcall outline-level)))
6953 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6954 (diff (abs (- level (length up-head) -1))))
6955 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6956 (replace-match up-head nil t)
6957 ;; Fixup tag positioning
6958 (and org-auto-align-tags (org-set-tags nil t))
6959 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6960 (run-hooks 'org-after-promote-entry-hook)))
6962 (defun org-demote ()
6963 "Demote the current heading lower down the tree.
6964 If the region is active in `transient-mark-mode', demote all headings
6966 (org-back-to-heading t)
6967 (let* ((level (save-match-data (funcall outline-level)))
6968 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6969 (diff (abs (- level (length down-head) -1))))
6970 (replace-match down-head nil t)
6971 ;; Fixup tag positioning
6972 (and org-auto-align-tags (org-set-tags nil t))
6973 (if org-adapt-indentation (org-fixup-indentation diff))
6974 (run-hooks 'org-after-demote-entry-hook)))
6976 (defun org-cycle-level ()
6977 "Cycle the level of an empty headline through possible states.
6978 This goes first to child, then to parent, level, then up the hierarchy.
6979 After top level, it switches back to sibling level."
6981 (let ((org-adapt-indentation nil))
6982 (when (org-point-at-end-of-empty-headline)
6983 (setq this-command 'org-cycle-level) ; Only needed for caching
6984 (let ((cur-level (org-current-level))
6985 (prev-level (org-get-previous-line-level)))
6987 ;; If first headline in file, promote to top-level.
6989 (loop repeat (/ (- cur-level 1) (org-level-increment))
6990 do (org-do-promote)))
6991 ;; If same level as prev, demote one.
6992 ((= prev-level cur-level)
6994 ;; If parent is top-level, promote to top level if not already.
6996 (loop repeat (/ (- cur-level 1) (org-level-increment))
6997 do (org-do-promote)))
6998 ;; If top-level, return to prev-level.
7000 (loop repeat (/ (- prev-level 1) (org-level-increment))
7001 do (org-do-demote)))
7002 ;; If less than prev-level, promote one.
7003 ((< cur-level prev-level)
7005 ;; If deeper than prev-level, promote until higher than
7007 ((> cur-level prev-level)
7008 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
7009 do (org-do-promote))))
7012 (defun org-map-tree (fun)
7013 "Call FUN for every heading underneath the current one."
7014 (org-back-to-heading)
7015 (let ((level (funcall outline-level)))
7019 (outline-next-heading)
7020 (> (funcall outline-level) level))
7024 (defun org-map-region (fun beg end)
7025 "Call FUN for every heading between BEG and END."
7026 (let ((org-ignore-region t))
7028 (setq end (copy-marker end))
7030 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
7034 (outline-next-heading)
7039 (defun org-fixup-indentation (diff)
7040 "Change the indentation in the current entry by DIFF
7041 However, if any line in the current entry has no indentation, or if it
7042 would end up with no indentation after the change, nothing at all is done."
7044 (let ((end (save-excursion (outline-next-heading)
7046 (prohibit (if (> diff 0)
7048 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
7050 (unless (save-excursion (end-of-line 1)
7051 (re-search-forward prohibit end t))
7052 (while (and (< (point) end)
7053 (re-search-forward "^[ \t]+" end t))
7054 (goto-char (match-end 0))
7055 (setq col (current-column))
7056 (if (< diff 0) (replace-match ""))
7057 (org-indent-to-column (+ diff col))))
7058 (move-marker end nil))))
7060 (defun org-convert-to-odd-levels ()
7061 "Convert an org-mode file with all levels allowed to one with odd levels.
7062 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7065 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7066 (let ((outline-regexp org-outline-regexp)
7067 (outline-level 'org-outline-level)
7068 (org-odd-levels-only nil) n)
7070 (goto-char (point-min))
7071 (while (re-search-forward "^\\*\\*+ " nil t)
7072 (setq n (- (length (match-string 0)) 2))
7073 (while (>= (setq n (1- n)) 0)
7075 (end-of-line 1))))))
7077 (defun org-convert-to-oddeven-levels ()
7078 "Convert an org-mode file with only odd levels to one with odd and even levels.
7079 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
7080 section with an even level, conversion would destroy the structure of the file. An error
7081 is signaled in this case."
7083 (goto-char (point-min))
7084 ;; First check if there are no even levels
7085 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7086 (org-show-context t)
7087 (error "Not all levels are odd in this file. Conversion not possible"))
7088 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7089 (let ((outline-regexp org-outline-regexp)
7090 (outline-level 'org-outline-level)
7091 (org-odd-levels-only nil) n)
7093 (goto-char (point-min))
7094 (while (re-search-forward "^\\*\\*+ " nil t)
7095 (setq n (/ (1- (length (match-string 0))) 2))
7096 (while (>= (setq n (1- n)) 0)
7098 (end-of-line 1))))))
7100 (defun org-tr-level (n)
7101 "Make N odd if required."
7102 (if org-odd-levels-only (1+ (/ n 2)) n))
7104 ;;; Vertical tree motion, cutting and pasting of subtrees
7106 (defun org-move-subtree-up (&optional arg)
7107 "Move the current subtree up past ARG headlines of the same level."
7109 (org-move-subtree-down (- (prefix-numeric-value arg))))
7111 (defun org-move-subtree-down (&optional arg)
7112 "Move the current subtree down past ARG headlines of the same level."
7114 (setq arg (prefix-numeric-value arg))
7115 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7116 'org-get-last-sibling))
7117 (ins-point (make-marker))
7119 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7121 (org-back-to-heading)
7124 (setq ne-beg (org-back-over-empty-lines))
7127 (save-excursion (outline-end-of-heading)
7128 (setq folded (org-invisible-p)))
7129 (outline-end-of-subtree))
7130 (outline-next-heading)
7131 (setq ne-end (org-back-over-empty-lines))
7134 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7135 ;; include less whitespace
7138 (forward-line (- ne-beg ne-end))
7139 (setq beg (point))))
7140 ;; Find insertion point, with error handling
7142 (or (and (funcall movfunc) (looking-at outline-regexp))
7143 (progn (goto-char beg0)
7144 (error "Cannot move past superior level or buffer limit")))
7145 (setq cnt (1- cnt)))
7147 ;; Moving forward - still need to move over subtree
7148 (progn (org-end-of-subtree t t)
7150 (org-back-over-empty-lines)
7151 (or (bolp) (newline)))))
7152 (setq ne-ins (org-back-over-empty-lines))
7153 (move-marker ins-point (point))
7154 (setq txt (buffer-substring beg end))
7155 (org-save-markers-in-region beg end)
7156 (delete-region beg end)
7157 (org-remove-empty-overlays-at beg)
7158 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7159 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7160 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7161 (let ((bbb (point)))
7162 (insert-before-markers txt)
7163 (org-reinstall-markers-in-region bbb)
7164 (move-marker ins-point bbb))
7165 (or (bolp) (insert "\n"))
7166 (setq ins-end (point))
7167 (goto-char ins-point)
7168 (org-skip-whitespace)
7169 (when (and (< arg 0)
7170 (org-first-sibling-p)
7172 ;; Move whitespace back to beginning
7175 (let ((kill-whole-line t))
7176 (kill-line (- ne-ins ne-beg)) (point)))
7177 (insert (make-string (- ne-ins ne-beg) ?\n)))
7178 (move-marker ins-point nil)
7183 (org-cycle-hide-drawers 'children))
7184 (org-clean-visibility-after-subtree-move)))
7186 (defvar org-subtree-clip ""
7187 "Clipboard for cut and paste of subtrees.
7188 This is actually only a copy of the kill, because we use the normal kill
7189 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7191 (defvar org-subtree-clip-folded nil
7192 "Was the last copied subtree folded?
7193 This is used to fold the tree back after pasting.")
7195 (defun org-cut-subtree (&optional n)
7196 "Cut the current subtree into the clipboard.
7197 With prefix arg N, cut this many sequential subtrees.
7198 This is a short-hand for marking the subtree and then cutting it."
7200 (org-copy-subtree n 'cut))
7202 (defun org-copy-subtree (&optional n cut force-store-markers)
7203 "Cut the current subtree into the clipboard.
7204 With prefix arg N, cut this many sequential subtrees.
7205 This is a short-hand for marking the subtree and then copying it.
7206 If CUT is non-nil, actually cut the subtree.
7207 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7208 of some markers in the region, even if CUT is non-nil. This is
7209 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7211 (let (beg end folded (beg0 (point)))
7213 (org-back-to-heading nil) ; take what looks like a subtree
7214 (org-back-to-heading t)) ; take what is really there
7215 (org-back-over-empty-lines)
7217 (skip-chars-forward " \t\r\n")
7219 (save-excursion (outline-end-of-heading)
7220 (setq folded (org-invisible-p)))
7222 (org-forward-same-level (1- n) t)
7224 (org-end-of-subtree t t))
7225 (org-back-over-empty-lines)
7229 (setq org-subtree-clip-folded folded)
7230 (when (or cut force-store-markers)
7231 (org-save-markers-in-region beg end))
7232 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7233 (setq org-subtree-clip (current-kill 0))
7234 (message "%s: Subtree(s) with %d characters"
7235 (if cut "Cut" "Copied")
7236 (length org-subtree-clip)))))
7238 (defun org-paste-subtree (&optional level tree for-yank)
7239 "Paste the clipboard as a subtree, with modification of headline level.
7240 The entire subtree is promoted or demoted in order to match a new headline
7243 If the cursor is at the beginning of a headline, the same level as
7244 that headline is used to paste the tree
7246 If not, the new level is derived from the *visible* headings
7247 before and after the insertion point, and taken to be the inferior headline
7248 level of the two. So if the previous visible heading is level 3 and the
7249 next is level 4 (or vice versa), level 4 will be used for insertion.
7250 This makes sure that the subtree remains an independent subtree and does
7251 not swallow low level entries.
7253 You can also force a different level, either by using a numeric prefix
7254 argument, or by inserting the heading marker by hand. For example, if the
7255 cursor is after \"*****\", then the tree will be shifted to level 5.
7257 If optional TREE is given, use this text instead of the kill ring.
7259 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7260 move back over whitespace before inserting, and move point to the end of
7261 the inserted text when done."
7263 (setq tree (or tree (and kill-ring (current-kill 0))))
7264 (unless (org-kill-is-subtree-p tree)
7266 (substitute-command-keys
7267 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7268 (let* ((visp (not (org-invisible-p)))
7270 (^re (concat "^\\(" outline-regexp "\\)"))
7271 (re (concat "\\(" outline-regexp "\\)"))
7272 (^re_ (concat "\\(\\*+\\)[ \t]*"))
7274 (old-level (if (string-match ^re txt)
7275 (- (match-end 0) (match-beginning 0) 1)
7277 (force-level (cond (level (prefix-numeric-value level))
7278 ((and (looking-at "[ \t]*$")
7280 ^re_ (buffer-substring
7281 (point-at-bol) (point))))
7282 (- (match-end 1) (match-beginning 1)))
7284 (looking-at org-outline-regexp))
7285 (- (match-end 0) (point) 1))
7287 (previous-level (save-excursion
7290 (outline-previous-visible-heading 1)
7292 (- (match-end 0) (match-beginning 0) 1)
7295 (next-level (save-excursion
7298 (or (looking-at outline-regexp)
7299 (outline-next-visible-heading 1))
7301 (- (match-end 0) (match-beginning 0) 1)
7304 (new-level (or force-level (max previous-level next-level)))
7305 (shift (if (or (= old-level -1)
7307 (= old-level new-level))
7309 (- new-level old-level)))
7310 (delta (if (> shift 0) -1 1))
7311 (func (if (> shift 0) 'org-demote 'org-promote))
7312 (org-odd-levels-only nil)
7314 ;; Remove the forced level indicator
7316 (delete-region (point-at-bol) (point)))
7318 (beginning-of-line 1)
7319 (unless for-yank (org-back-over-empty-lines))
7321 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7322 (insert-before-markers txt)
7323 (unless (string-match "\n\\'" txt) (insert "\n"))
7324 (setq newend (point))
7325 (org-reinstall-markers-in-region beg)
7328 (skip-chars-forward " \t\n\r")
7330 (if (and (org-invisible-p) visp)
7331 (save-excursion (outline-show-heading)))
7332 ;; Shift if necessary
7335 (narrow-to-region beg end)
7336 (while (not (= shift 0))
7337 (org-map-region func (point-min) (point-max))
7338 (setq shift (+ delta shift)))
7339 (goto-char (point-min))
7340 (setq newend (point-max))))
7341 (when (or (interactive-p) for-yank)
7342 (message "Clipboard pasted as level %d subtree" new-level))
7343 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7345 (eq org-subtree-clip (current-kill 0))
7346 org-subtree-clip-folded)
7347 ;; The tree was folded before it was killed/copied
7349 (and for-yank (goto-char newend))))
7351 (defun org-kill-is-subtree-p (&optional txt)
7352 "Check if the current kill is an outline subtree, or a set of trees.
7353 Returns nil if kill does not start with a headline, or if the first
7354 headline level is not the largest headline level in the tree.
7355 So this will actually accept several entries of equal levels as well,
7356 which is OK for `org-paste-subtree'.
7357 If optional TXT is given, check this string instead of the current kill."
7358 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7359 (start-level (and kill
7360 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
7361 org-outline-regexp "\\)")
7363 (- (match-end 2) (match-beginning 2) 1)))
7364 (re (concat "^" org-outline-regexp))
7365 (start (1+ (or (match-beginning 2) -1))))
7366 (if (not start-level)
7368 nil) ;; does not even start with a heading
7370 (while (setq start (string-match re kill (1+ start)))
7371 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7375 (defvar org-markers-to-move nil
7376 "Markers that should be moved with a cut-and-paste operation.
7377 Those markers are stored together with their positions relative to
7378 the start of the region.")
7380 (defun org-save-markers-in-region (beg end)
7381 "Check markers in region.
7382 If these markers are between BEG and END, record their position relative
7383 to BEG, so that after moving the block of text, we can put the markers back
7385 This function gets called just before an entry or tree gets cut from the
7386 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7387 called immediately, to move the markers with the entries."
7388 (setq org-markers-to-move nil)
7389 (when (featurep 'org-clock)
7390 (org-clock-save-markers-for-cut-and-paste beg end))
7391 (when (featurep 'org-agenda)
7392 (org-agenda-save-markers-for-cut-and-paste beg end)))
7394 (defun org-check-and-save-marker (marker beg end)
7395 "Check if MARKER is between BEG and END.
7396 If yes, remember the marker and the distance to BEG."
7397 (when (and (marker-buffer marker)
7398 (equal (marker-buffer marker) (current-buffer)))
7399 (if (and (>= marker beg) (< marker end))
7400 (push (cons marker (- marker beg)) org-markers-to-move))))
7402 (defun org-reinstall-markers-in-region (beg)
7403 "Move all remembered markers to their position relative to BEG."
7405 (move-marker (car x) (+ beg (cdr x))))
7406 org-markers-to-move)
7407 (setq org-markers-to-move nil))
7409 (defun org-narrow-to-subtree ()
7410 "Narrow buffer to the current subtree."
7415 (progn (org-back-to-heading t) (point))
7416 (progn (org-end-of-subtree t t)
7417 (if (org-on-heading-p) (backward-char 1))
7421 (defvar org-property-drawer-re))
7423 (defun org-clone-subtree-with-time-shift (n &optional shift)
7424 "Clone the task (subtree) at point N times.
7425 The clones will be inserted as siblings.
7427 In interactive use, the user will be prompted for the number of
7428 clones to be produced, and for a time SHIFT, which may be a
7429 repeater as used in time stamps, for example `+3d'.
7431 When a valid repeater is given and the entry contains any time
7432 stamps, the clones will become a sequence in time, with time
7433 stamps in the subtree shifted for each clone produced. If SHIFT
7434 is nil or the empty string, time stamps will be left alone. The
7435 ID property of the original subtree is removed.
7437 If the original subtree did contain time stamps with a repeater,
7438 the following will happen:
7439 - the repeater will be removed in each clone
7440 - an additional clone will be produced, with the current, unshifted
7441 date(s) in the entry.
7442 - the original entry will be placed *after* all the clones, with
7444 - the start days in the repeater in the original entry will be shifted
7445 to past the last clone.
7446 I this way you can spell out a number of instances of a repeating task,
7447 and still retain the repeater to cover future instances of the task."
7448 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7449 (let (beg end template task idprop
7450 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7451 (if (not (and (integerp n) (> n 0)))
7452 (error "Invalid number of replications %s" n))
7453 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7454 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7456 (error "Invalid shift specification %s" shift))
7458 (setq shift-n (string-to-number (match-string 1 shift))
7459 shift-what (cdr (assoc (match-string 2 shift)
7460 '(("d" . day) ("w" . week)
7461 ("m" . month) ("y" . year))))))
7462 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7463 (setq nmin 1 nmax n)
7464 (org-back-to-heading t)
7466 (setq idprop (org-entry-get nil "ID"))
7467 (org-end-of-subtree t t)
7468 (or (bolp) (insert "\n"))
7470 (setq template (buffer-substring beg end))
7472 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7473 (delete-region beg end)
7475 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7477 (loop for n from nmin to nmax do
7482 (goto-char (point-min))
7483 (and idprop (if org-clone-delete-id
7484 (org-entry-delete nil "ID")
7485 (org-id-get-create t)))
7486 (while (re-search-forward org-property-drawer-re nil t)
7487 (org-remove-empty-drawer-at "PROPERTIES" (point)))
7488 (goto-char (point-min))
7490 (while (re-search-forward org-ts-regexp-both nil t)
7491 (org-timestamp-change (* n shift-n) shift-what))
7492 (unless (= n n-no-remove)
7493 (goto-char (point-min))
7494 (while (re-search-forward org-ts-regexp nil t)
7496 (goto-char (match-beginning 0))
7497 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7498 (delete-region (match-beginning 1) (match-end 1)))))))
7499 (setq task (buffer-string)))
7505 (defun org-sort (with-case)
7506 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7507 Optional argument WITH-CASE means sort case-sensitively.
7508 With a double prefix argument, also remove duplicate entries."
7510 (if (org-at-table-p)
7511 (org-call-with-arg 'org-table-sort-lines with-case)
7512 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7514 (defun org-sort-remove-invisible (s)
7515 (remove-text-properties 0 (length s) org-rm-props s)
7516 (while (string-match org-bracket-link-regexp s)
7517 (setq s (replace-match (if (match-end 2)
7519 (match-string 1 s)) t t s)))
7522 (defvar org-priority-regexp) ; defined later in the file
7524 (defvar org-after-sorting-entries-or-items-hook nil
7525 "Hook that is run after a bunch of entries or items have been sorted.
7526 When children are sorted, the cursor is in the parent line when this
7527 hook gets called. When a region or a plain list is sorted, the cursor
7528 will be in the first entry of the sorted region/list.")
7530 (defun org-sort-entries-or-items
7531 (&optional with-case sorting-type getkey-func compare-func property)
7532 "Sort entries on a certain level of an outline tree, or plain list items.
7533 If there is an active region, the entries in the region are sorted.
7534 Else, if the cursor is before the first entry, sort the top-level items.
7535 Else, the children of the entry at point are sorted.
7536 If the cursor is at the first item in a plain list, the list items will be
7539 Sorting can be alphabetically, numerically, by date/time as given by
7540 a time stamp, by a property or by priority.
7542 The command prompts for the sorting type unless it has been given to the
7543 function through the SORTING-TYPE argument, which needs to be a character,
7544 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7545 precise meaning of each character:
7547 n Numerically, by converting the beginning of the entry/item to a number.
7548 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7549 t By date/time, either the first active time stamp in the entry, or, if
7550 none exist, by the first inactive one.
7551 In items, only the first line will be checked.
7552 s By the scheduled date/time.
7553 d By deadline date/time.
7554 c By creation time, which is assumed to be the first inactive time stamp
7555 at the beginning of a line.
7556 p By priority according to the cookie.
7557 r By the value of a property.
7559 Capital letters will reverse the sort order.
7561 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7562 called with point at the beginning of the record. It must return either
7563 a string or a number that should serve as the sorting key for that record.
7565 Comparing entries ignores case by default. However, with an optional argument
7566 WITH-CASE, the sorting considers case as well."
7568 (let ((case-func (if with-case 'identity 'downcase))
7569 start beg end stars re re2
7570 txt what tmp plain-list-p)
7571 ;; Find beginning and end of region to sort
7573 ((org-region-active-p)
7574 ;; we will sort the region
7575 (setq end (region-end)
7577 (goto-char (region-beginning))
7578 (if (not (org-on-heading-p)) (outline-next-heading))
7579 (setq start (point)))
7581 ;; we will sort this plain list
7582 (org-beginning-of-item-list) (setq start (point))
7583 (org-end-of-item-list)
7584 (or (bolp) (insert "\n"))
7587 (setq plain-list-p t
7589 ((or (org-on-heading-p)
7590 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7591 ;; we will sort the children of the current headline
7592 (org-back-to-heading)
7594 end (progn (org-end-of-subtree t t)
7595 (or (bolp) (insert "\n"))
7596 (org-back-over-empty-lines)
7601 (outline-next-heading))
7603 ;; we will sort the top-level entries in this file
7604 (goto-char (point-min))
7605 (or (org-on-heading-p) (outline-next-heading))
7606 (setq start (point))
7607 (goto-char (point-max))
7608 (beginning-of-line 1)
7609 (when (looking-at ".*?\\S-")
7610 ;; File ends in a non-white line
7613 (setq end (point-max))
7614 (setq what "top-level")
7619 (if (>= beg end) (error "Nothing to sort"))
7621 (unless plain-list-p
7622 (looking-at "\\(\\*+\\)")
7623 (setq stars (match-string 1)
7624 re (concat "^" (regexp-quote stars) " +")
7625 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7626 txt (buffer-substring beg end))
7627 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7628 (if (and (not (equal stars "*")) (string-match re2 txt))
7629 (error "Region to sort contains a level above the first entry")))
7631 (unless sorting-type
7634 "Sort %s: [a]lpha [n]umeric [t]ime
[f]unc A/N/T/F means reversed:"
7635 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7636 [t]ime [s]cheduled [d]eadline [c]reated
7637 A/N/T/S/D/C/P/O/F means reversed:")
7639 (setq sorting-type (read-char-exclusive))
7641 (and (= (downcase sorting-type) ?f)
7643 (org-icompleting-read "Sort using function: "
7644 obarray 'fboundp t nil nil))
7645 (setq getkey-func (intern getkey-func)))
7647 (and (= (downcase sorting-type) ?r)
7649 (org-icompleting-read "Property: "
7650 (mapcar 'list (org-buffer-property-keys t))
7653 (message "Sorting entries...")
7656 (narrow-to-region start end)
7658 (let ((dcst (downcase sorting-type))
7659 (case-fold-search nil)
7660 (now (current-time)))
7662 (/= dcst sorting-type)
7663 ;; This function moves to the beginning character of the "record" to
7667 (if (org-at-item-p) t (goto-char (point-max))))
7669 (if (re-search-forward re nil t)
7670 (goto-char (match-beginning 0))
7671 (goto-char (point-max)))))
7672 ;; This function moves to the last character of the "record" being
7679 (outline-forward-same-level 1)
7681 (goto-char (point-max)))))))
7683 ;; This function returns the value that gets sorted against.
7686 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7689 (string-to-number (buffer-substring (match-end 0)
7692 (buffer-substring (match-end 0) (point-at-eol)))
7694 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7695 (re-search-forward org-ts-regexp-both
7697 (org-time-string-to-seconds (match-string 0))
7698 (org-float-time now)))
7702 (setq tmp (funcall getkey-func))
7703 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7705 (error "Invalid key function `%s'" getkey-func)))
7706 (t (error "Invalid sorting type `%c'" sorting-type)))))
7710 (if (looking-at org-complex-heading-regexp)
7711 (string-to-number (match-string 4))
7714 (if (looking-at org-complex-heading-regexp)
7715 (funcall case-func (match-string 4))
7718 (let ((end (save-excursion (outline-next-heading) (point))))
7719 (if (or (re-search-forward org-ts-regexp end t)
7720 (re-search-forward org-ts-regexp-both end t))
7721 (org-time-string-to-seconds (match-string 0))
7722 (org-float-time now))))
7724 (let ((end (save-excursion (outline-next-heading) (point))))
7725 (if (re-search-forward
7726 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7728 (org-time-string-to-seconds (match-string 0))
7729 (org-float-time now))))
7731 (let ((end (save-excursion (outline-next-heading) (point))))
7732 (if (re-search-forward org-scheduled-time-regexp end t)
7733 (org-time-string-to-seconds (match-string 1))
7734 (org-float-time now))))
7736 (let ((end (save-excursion (outline-next-heading) (point))))
7737 (if (re-search-forward org-deadline-time-regexp end t)
7738 (org-time-string-to-seconds (match-string 1))
7739 (org-float-time now))))
7741 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7742 (string-to-char (match-string 2))
7743 org-default-priority))
7745 (or (org-entry-get nil property) ""))
7747 (if (looking-at org-complex-heading-regexp)
7748 (- 9999 (length (member (match-string 2)
7749 org-todo-keywords-1)))))
7753 (setq tmp (funcall getkey-func))
7754 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7756 (error "Invalid key function `%s'" getkey-func)))
7757 (t (error "Invalid sorting type `%c'" sorting-type)))))
7760 ((= dcst ?a) 'string<)
7761 ((= dcst ?f) compare-func)
7762 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7764 (run-hooks 'org-after-sorting-entries-or-items-hook)
7765 (message "Sorting entries...done")))
7767 (defun org-do-sort (table what &optional with-case sorting-type)
7768 "Sort TABLE of WHAT according to SORTING-TYPE.
7769 The user will be prompted for the SORTING-TYPE if the call to this
7770 function does not specify it. WHAT is only for the prompt, to indicate
7771 what is being sorted. The sorting key will be extracted from
7772 the car of the elements of the table.
7773 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7774 (unless sorting-type
7776 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A
/N
/T means reversed
:"
7778 (setq sorting-type (read-char-exclusive)))
7779 (let ((dcst (downcase sorting-type))
7780 extractfun comparefun)
7781 ;; Define the appropriate functions
7784 (setq extractfun 'string-to-number
7785 comparefun (if (= dcst sorting-type) '< '>)))
7787 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7788 (lambda(x) (downcase (org-sort-remove-invisible x))))
7789 comparefun (if (= dcst sorting-type)
7791 (lambda (a b) (and (not (string< a b))
7792 (not (string= a b)))))))
7796 (if (or (string-match org-ts-regexp x)
7797 (string-match org-ts-regexp-both x))
7799 (org-time-string-to-time (match-string 0 x)))
7801 comparefun (if (= dcst sorting-type) '< '>)))
7802 (t (error "Invalid sorting type
`%c
'" sorting-type)))
7804 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7806 (lambda (a b) (funcall comparefun (car a) (car b))))))
7809 ;;; The orgstruct minor mode
7811 ;; Define a minor mode which can be used in other modes in order to
7812 ;; integrate the org-mode structure editing commands.
7814 ;; This is really a hack, because the org-mode structure commands use
7815 ;; keys which normally belong to the major mode. Here is how it
7816 ;; works: The minor mode defines all the keys necessary to operate the
7817 ;; structure commands, but wraps the commands into a function which
7818 ;; tests if the cursor is currently at a headline or a plain list
7819 ;; item. If that is the case, the structure command is used,
7820 ;; temporarily setting many Org-mode variables like regular
7821 ;; expressions for filling etc. However, when any of those keys is
7822 ;; used at a different location, function uses `key-binding' to look
7823 ;; up if the key has an associated command in another currently active
7824 ;; keymap (minor modes, major mode, global), and executes that
7825 ;; command. There might be problems if any of the keys is otherwise
7826 ;; used as a prefix key.
7828 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7829 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7830 ;; addresses this by checking explicitly for both bindings.
7832 (defvar orgstruct-mode-map (make-sparse-keymap)
7833 "Keymap for the minor
`orgstruct-mode
'.
")
7835 (defvar org-local-vars nil
7836 "List of local variables
, for use by
`orgstruct-mode
'")
7839 (define-minor-mode orgstruct-mode
7840 "Toggle the minor mode
`orgstruct-mode
'.
7841 This mode is for using Org-mode structure commands in other
7842 modes. The following keys behave as if Org-mode were active
, if
7843 the cursor is on a headline
, or on a plain list item
(both as
7844 defined by Org-mode
).
7846 M-up Move entry
/item up
7847 M-down Move entry
/item down
7850 M-S-up Move entry
/item up
7851 M-S-down Move entry
/item down
7852 M-S-left Promote subtree
7853 M-S-right Demote subtree
7854 M-q Fill paragraph and items like in Org-mode
7856 C-c - Cycle list bullet
7857 TAB Cycle item visibility
7858 M-RET Insert new heading
/item
7859 S-M-RET Insert new TODO heading
/ Checkbox item
7860 C-c C-c Set tags
/ toggle checkbox
"
7861 nil " OrgStruct
" nil
7862 (org-load-modules-maybe)
7863 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7866 (defun turn-on-orgstruct ()
7867 "Unconditionally turn on
`orgstruct-mode
'.
"
7870 (defun orgstruct++-mode (&optional arg)
7871 "Toggle
`orgstruct-mode
', the enhanced version of it.
7872 In addition to setting orgstruct-mode
, this also exports all indentation
7873 and autofilling variables from org-mode into the buffer. It will also
7874 recognize item context in multiline items.
7875 Note that turning off orgstruct-mode will
*not
* remove the
7876 indentation
/paragraph settings. This can only be done by refreshing the
7877 major mode
, for example with
\\[normal-mode
].
"
7879 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7887 "^
\\(paragraph-\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7888 (symbol-name (car x)))
7889 (setq var (car x) val (nth 1 x))
7890 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7892 (org-set-local 'orgstruct-is-++ t))))
7894 (defvar orgstruct-is-++ nil
7895 "Is orgstruct-mode in
++ version in the current-buffer?
")
7896 (make-variable-buffer-local 'orgstruct-is-++)
7899 (defun turn-on-orgstruct++ ()
7900 "Unconditionally turn on
`orgstruct
++-mode
'.
"
7901 (orgstruct++-mode 1))
7903 (defun orgstruct-error ()
7904 "Error when there is no default binding for a structure key.
"
7906 (error "This key has no function outside structure elements
"))
7908 (defun orgstruct-setup ()
7909 "Setup orgstruct keymaps.
"
7913 '([(meta up)] org-metaup)
7914 '([(meta down)] org-metadown)
7915 '([(meta left)] org-metaleft)
7916 '([(meta right)] org-metaright)
7917 '([(meta shift up)] org-shiftmetaup)
7918 '([(meta shift down)] org-shiftmetadown)
7919 '([(meta shift left)] org-shiftmetaleft)
7920 '([(meta shift right)] org-shiftmetaright)
7921 '([?\e (up)] org-metaup)
7922 '([?\e (down)] org-metadown)
7923 '([?\e (left)] org-metaleft)
7924 '([?\e (right)] org-metaright)
7925 '([?\e (shift up)] org-shiftmetaup)
7926 '([?\e (shift down)] org-shiftmetadown)
7927 '([?\e (shift left)] org-shiftmetaleft)
7928 '([?\e (shift right)] org-shiftmetaright)
7929 '([(shift up)] org-shiftup)
7930 '([(shift down)] org-shiftdown)
7931 '([(shift left)] org-shiftleft)
7932 '([(shift right)] org-shiftright)
7933 '("\C-c\C-c
" org-ctrl-c-ctrl-c)
7934 '("\M-q
" fill-paragraph)
7936 '("\C-c-
" org-cycle-list-bullet)))
7938 (while (setq elt (pop bindings))
7939 (setq nfunc (1+ nfunc))
7940 (setq key (org-key (car elt))
7942 cmd (orgstruct-make-binding fun nfunc key))
7943 (org-defkey orgstruct-mode-map key cmd))
7945 ;; Special treatment needed for TAB and RET
7946 (org-defkey orgstruct-mode-map [(tab)]
7947 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i
"))
7948 (org-defkey orgstruct-mode-map "\C-i
"
7949 (orgstruct-make-binding 'org-cycle 103 "\C-i
" [(tab)]))
7951 (org-defkey orgstruct-mode-map "\M-\C-m
"
7952 (orgstruct-make-binding 'org-insert-heading 105
7953 "\M-\C-m
" [(meta return)]))
7954 (org-defkey orgstruct-mode-map [(meta return)]
7955 (orgstruct-make-binding 'org-insert-heading 106
7956 [(meta return)] "\M-\C-m
"))
7958 (org-defkey orgstruct-mode-map [(shift meta return)]
7959 (orgstruct-make-binding 'org-insert-todo-heading 107
7960 [(meta return)] "\M-\C-m
"))
7962 (org-defkey orgstruct-mode-map "\e\C-m
"
7963 (orgstruct-make-binding 'org-insert-heading 108
7964 "\e\C-m
" [?\e (return)]))
7965 (org-defkey orgstruct-mode-map [?\e (return)]
7966 (orgstruct-make-binding 'org-insert-heading 109
7967 [?\e (return)] "\e\C-m
"))
7968 (org-defkey orgstruct-mode-map [?\e (shift return)]
7969 (orgstruct-make-binding 'org-insert-todo-heading 110
7970 [?\e (return)] "\e\C-m
"))
7972 (unless org-local-vars
7973 (setq org-local-vars (org-get-local-variables)))
7977 (defun orgstruct-make-binding (fun n &rest keys)
7978 "Create a function for binding in the structure minor mode.
7979 FUN is the command to call inside a table. N is used to create a unique
7980 command name. KEYS are keys that should be checked in for a command
7981 to execute outside of tables.
"
7984 (intern (concat "orgstruct-hijacker-command-
" (int-to-string n)))
7986 (concat "In Structure
, run
`" (symbol-name fun) "'.
\n"
7987 "Outside of structure
, run the binding of
`"
7988 (mapconcat (lambda (x) (format "%s
" x)) keys "' or
`")
7992 `(org-context-p 'headline 'item
7993 (and orgstruct-is-++
7994 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7996 (list 'org-run-like-in-org-mode (list 'quote fun))
7997 (list 'let '(orgstruct-mode)
7998 (list 'call-interactively
8001 (list 'key-binding k))
8003 '('orgstruct-error))))))))
8005 (defun org-context-p (&rest contexts)
8006 "Check if local context is any of CONTEXTS.
8007 Possible values in the list of contexts are
`table
', `headline
', and
`item
'.
"
8008 (let ((pos (point)))
8009 (goto-char (point-at-bol))
8010 (prog1 (or (and (memq 'table contexts)
8011 (looking-at "[ \t]*|
"))
8012 (and (memq 'headline contexts)
8013 ;;????????? (looking-at "\\*+"))
8014 (looking-at outline-regexp))
8015 (and (memq 'item contexts)
8016 (looking-at "[ \t]*\\([-
+*] \\|
[0-
9]+[.
)] \\)"))
8017 (and (memq 'item-body contexts)
8021 (defun org-get-local-variables ()
8022 "Return a list of all local variables in an org-mode buffer.
"
8024 (with-current-buffer (get-buffer-create "*Org tmp
*")
8027 (setq varlist (buffer-local-variables)))
8028 (kill-buffer "*Org tmp
*")
8035 (list (car x) (list 'quote (cdr x)))))
8037 "^
\\(org-\\|orgtbl-
\\|outline-
\\|comment-
\\|paragraph-
\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
8038 (symbol-name (car x)))
8043 (defun org-run-like-in-org-mode (cmd)
8044 "Run a command
, pretending that the current buffer is in Org-mode.
8045 This will temporarily bind local variables that are typically bound in
8046 Org-mode to the values they have in Org-mode
, and then interactively
8048 (org-load-modules-maybe)
8049 (unless org-local-vars
8050 (setq org-local-vars (org-get-local-variables)))
8051 (eval (list 'let org-local-vars
8052 (list 'call-interactively (list 'quote cmd)))))
8056 (defun org-get-category (&optional pos)
8057 "Get the category applying to position POS.
"
8058 (get-text-property (or pos (point)) 'org-category))
8060 (defun org-refresh-category-properties ()
8061 "Refresh category text properties in the buffer.
"
8062 (let ((def-cat (cond
8063 ((null org-category)
8064 (if buffer-file-name
8065 (file-name-sans-extension
8066 (file-name-nondirectory buffer-file-name))
8068 ((symbolp org-category) (symbol-name org-category))
8070 beg end cat pos optionp)
8075 (goto-char (point-min))
8076 (put-text-property (point) (point-max) 'org-category def-cat)
8077 (while (re-search-forward
8078 "^
\\(#\\+CATEGORY
:\\|
[ \t]*:CATEGORY
:\\)\\(.
*\\)" nil t)
8079 (setq pos (match-end 0)
8080 optionp (equal (char-after (match-beginning 0)) ?#)
8081 cat (org-trim (match-string 2)))
8083 (setq beg (point-at-bol) end (point-max))
8084 (org-back-to-heading t)
8085 (setq beg (point) end (org-end-of-subtree t t)))
8086 (put-text-property beg end 'org-category cat)
8087 (goto-char pos)))))))
8092 ;;; Link abbreviations
8094 (defun org-link-expand-abbrev (link)
8095 "Apply replacements as defined in
`org-link-abbrev-alist.
"
8096 (if (string-match "^
\\([a-zA-Z
][-_a-zA-Z0-9
]*\\)\\(::?
\\(.
*\\)\\)?$
" link)
8097 (let* ((key (match-string 1 link))
8098 (as (or (assoc key org-link-abbrev-alist-local)
8099 (assoc key org-link-abbrev-alist)))
8100 (tag (and (match-end 2) (match-string 3 link)))
8106 ((symbolp rpl) (funcall rpl tag))
8107 ((string-match "%s
" rpl) (replace-match (or tag "") t t rpl))
8108 ((string-match "%h
" rpl)
8109 (replace-match (url-hexify-string (or tag "")) t t rpl))
8110 (t (concat rpl tag)))))
8113 ;;; Storing and inserting links
8115 (defvar org-insert-link-history nil
8116 "Minibuffer history for links inserted with
`org-insert-link
'.
")
8118 (defvar org-stored-links nil
8119 "Contains the links stored with
`org-store-link
'.
")
8121 (defvar org-store-link-plist nil
8122 "Plist with info about the most recently link created with
`org-store-link
'.
")
8124 (defvar org-link-protocols nil
8125 "Link protocols added to Org-mode using
`org-add-link-type
'.
")
8127 (defvar org-store-link-functions nil
8128 "List of functions that are called to create and store a link.
8129 Each function will be called in turn until one returns a non-nil
8130 value. Each function should check if it is responsible for creating
8131 this link
(for example by looking at the major mode
).
8132 If not
, it must exit and return nil.
8133 If yes
, it should return a non-nil value after a calling
8134 `org-store-link-props
' with a list of properties and values.
8135 Special properties are
:
8137 :type The link prefix. like
\"http
\". This must be given.
8138 :link The link
, like
\"http
://www.astro.uva.nl
/~dominik
\".
8139 This is obligatory as well.
8140 :description Optional default description for the second pair
8141 of brackets in an Org-mode link. The user can still change
8142 this when inserting this link into an Org-mode buffer.
8144 In addition to these
, any additional properties can be specified
8145 and then used in remember templates.
")
8147 (defun org-add-link-type (type &optional follow export)
8148 "Add TYPE to the list of
`org-link-types
'.
8149 Re-compute all regular expressions depending on
`org-link-types
'
8151 FOLLOW and EXPORT are two functions.
8153 FOLLOW should take the link path as the single argument and do whatever
8154 is necessary to follow the link
, for example find a file or display
8157 EXPORT should format the link path for export to one of the export formats.
8158 It should be a function accepting three arguments
:
8160 path the path of the link
, the text after the prefix
(like \"http
:\")
8161 desc the description of the link
, if any
, nil if there was no description
8162 format the export format
, a symbol like
`html
' or
`latex
'.
8164 The function may use the FORMAT information to return different values
8165 depending on the format. The return value will be put literally into
8167 Org-mode has a built-in default for exporting links. If you are happy with
8168 this default
, there is no need to define an export function for the link
8169 type. For a simple example of an export function
, see
`org-bbdb.el
'.
"
8170 (add-to-list 'org-link-types type t)
8171 (org-make-link-regexps)
8172 (if (assoc type org-link-protocols)
8173 (setcdr (assoc type org-link-protocols) (list follow export))
8174 (push (list type follow export) org-link-protocols)))
8176 (defvar org-agenda-buffer-name)
8179 (defun org-store-link (arg)
8180 "\\<org-mode-map
>Store an org-link to the current location.
8181 This link is added to
`org-stored-links
' and can later be inserted
8182 into an org-buffer with
\\[org-insert-link
].
8184 For some link types
, a prefix arg is interpreted
:
8185 For links to usenet articles
, arg negates
`org-gnus-prefer-web-links
'.
8186 For file links
, arg negates
`org-context-in-file-links
'.
"
8188 (org-load-modules-maybe)
8189 (setq org-store-link-plist nil) ; reset
8190 (let ((outline-regexp (org-get-limited-outline-regexp))
8191 link cpltxt desc description search txt custom-id)
8194 ((run-hook-with-args-until-success 'org-store-link-functions)
8195 (setq link (plist-get org-store-link-plist :link)
8196 desc (or (plist-get org-store-link-plist :description) link)))
8198 ((equal (buffer-name) "*Org Edit Src Example
*")
8200 (while (or (not label)
8204 (goto-char (point-min))
8206 (regexp-quote (format org-coderef-label-format label))
8208 (when label (message "Label exists already
") (sit-for 2))
8209 (setq label (read-string "Code line label
: " label)))
8211 (setq link (format org-coderef-label-format label))
8212 (setq gc (- 79 (length link)))
8213 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8215 (setq link (concat "(" label ")") desc nil)))
8217 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8218 ;; We are in the agenda, link to referenced location
8219 (let ((m (or (get-text-property (point) 'org-hd-marker)
8220 (get-text-property (point) 'org-marker))))
8222 (org-with-point-at m
8224 (call-interactively 'org-store-link)
8225 (org-store-link nil))))))
8227 ((eq major-mode 'calendar-mode)
8228 (let ((cd (calendar-cursor-to-date)))
8231 (car org-time-stamp-formats)
8233 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8235 (org-store-link-props :type "calendar
" :date cd)))
8237 ((eq major-mode 'w3-mode)
8238 (setq cpltxt (if (and (buffer-name)
8239 (not (string-match "Untitled
" (buffer-name))))
8242 link (org-make-link (url-view-url t)))
8243 (org-store-link-props :type "w3
" :url (url-view-url t)))
8245 ((eq major-mode 'w3m-mode)
8246 (setq cpltxt (or w3m-current-title w3m-current-url)
8247 link (org-make-link w3m-current-url))
8248 (org-store-link-props :type "w3m
" :url (url-view-url t)))
8250 ((setq search (run-hook-with-args-until-success
8251 'org-create-file-search-functions))
8252 (setq link (concat "file
:" (abbreviate-file-name buffer-file-name)
8254 (setq cpltxt (or description link)))
8256 ((eq major-mode 'image-mode)
8257 (setq cpltxt (concat "file
:"
8258 (abbreviate-file-name buffer-file-name))
8259 link (org-make-link cpltxt))
8260 (org-store-link-props :type "image
" :file buffer-file-name))
8262 ((eq major-mode 'dired-mode)
8263 ;; link to the file in the current line
8264 (let ((file (dired-get-filename nil t)))
8266 (abbreviate-file-name
8267 (expand-file-name (dired-get-filename nil t)))
8268 ;; otherwise, no file so use current directory.
8270 (setq cpltxt (concat "file
:" file)
8271 link (org-make-link cpltxt))))
8273 ((and buffer-file-name (org-mode-p))
8274 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID
")))
8276 ((org-in-regexp "<<\\(.
*?
\\)>>")
8279 (abbreviate-file-name buffer-file-name)
8280 "::" (match-string 1))
8281 link (org-make-link cpltxt)))
8282 ((and (featurep 'org-id)
8283 (or (eq org-link-to-org-use-id t)
8284 (and (eq org-link-to-org-use-id 'create-if-interactive)
8286 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
8289 (and org-link-to-org-use-id
8291 (org-entry-get nil "ID
")
8293 ;; We can make a link using the ID.
8294 (setq link (condition-case nil
8295 (prog1 (org-id-store-link)
8296 (setq desc (plist-get org-store-link-plist
8299 ;; probably before first headline, link to file only
8301 (abbreviate-file-name buffer-file-name))))))
8303 ;; Just link to current headline
8304 (setq cpltxt (concat "file
:"
8305 (abbreviate-file-name buffer-file-name)))
8306 ;; Add a context search string
8307 (when (org-xor org-context-in-file-links arg)
8309 ((org-on-heading-p) nil)
8310 ((org-region-active-p)
8311 (buffer-substring (region-beginning) (region-end)))
8313 (when (or (null txt) (string-match "\\S-
" txt))
8317 (org-make-org-heading-search-string txt)
8319 desc (or (nth 4 (ignore-errors
8320 (org-heading-components))) "NONE
"))))
8321 (if (string-match "::\\'" cpltxt)
8322 (setq cpltxt (substring cpltxt 0 -2)))
8323 (setq link (org-make-link cpltxt)))))
8325 ((buffer-file-name (buffer-base-buffer))
8326 ;; Just link to this file here.
8327 (setq cpltxt (concat "file
:"
8328 (abbreviate-file-name
8329 (buffer-file-name (buffer-base-buffer)))))
8330 ;; Add a context string
8331 (when (org-xor org-context-in-file-links arg)
8332 (setq txt (if (org-region-active-p)
8333 (buffer-substring (region-beginning) (region-end))
8334 (buffer-substring (point-at-bol) (point-at-eol))))
8335 ;; Only use search option if there is some text.
8336 (when (string-match "\\S-
" txt)
8338 (concat cpltxt "::" (org-make-org-heading-search-string txt))
8340 (setq link (org-make-link cpltxt)))
8343 (error "Cannot link to a buffer which is not visiting a file
"))
8345 (t (setq link nil)))
8347 (if (consp link) (setq cpltxt (car link) link (cdr link)))
8348 (setq link (or link cpltxt)
8349 desc (or desc cpltxt))
8350 (if (equal desc "NONE
") (setq desc nil))
8352 (if (and (or (interactive-p) executing-kbd-macro) link)
8354 (setq org-stored-links
8355 (cons (list link desc) org-stored-links))
8356 (message "Stored
: %s
" (or desc link))
8358 (setq link (concat "file
:" (abbreviate-file-name (buffer-file-name))
8360 (setq org-stored-links
8361 (cons (list link desc) org-stored-links))))
8362 (and link (org-make-link-string link desc)))))
8364 (defun org-store-link-props (&rest plist)
8365 "Store link properties
, extract names and addresses.
"
8367 (when (setq x (plist-get plist :from))
8368 (setq adr (mail-extract-address-components x))
8369 (setq plist (plist-put plist :fromname (car adr)))
8370 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8371 (when (setq x (plist-get plist :to))
8372 (setq adr (mail-extract-address-components x))
8373 (setq plist (plist-put plist :toname (car adr)))
8374 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8375 (let ((from (plist-get plist :from))
8376 (to (plist-get plist :to)))
8377 (when (and from to org-from-is-user-regexp)
8379 (plist-put plist :fromto
8380 (if (string-match org-from-is-user-regexp from)
8382 (concat "from %f
"))))))
8383 (setq org-store-link-plist plist))
8385 (defun org-add-link-props (&rest plist)
8386 "Add these properties to the link property list.
"
8389 (setq key (pop plist) value (pop plist))
8390 (setq org-store-link-plist
8391 (plist-put org-store-link-plist key value)))))
8393 (defun org-email-link-description (&optional fmt)
8394 "Return the description part of an email link.
8395 This takes information from
`org-store-link-plist
' and formats it
8396 according to FMT
(default from
`org-email-link-description-format
').
"
8397 (setq fmt (or fmt org-email-link-description-format))
8398 (let* ((p org-store-link-plist)
8399 (to (plist-get p :toaddress))
8400 (from (plist-get p :fromaddress))
8403 (cons "%c
" (plist-get p :fromto))
8404 (cons "%F
" (plist-get p :from))
8405 (cons "%f
" (or (plist-get p :fromname) (plist-get p :fromaddress) "?
"))
8406 (cons "%T
" (plist-get p :to))
8407 (cons "%t
" (or (plist-get p :toname) (plist-get p :toaddress) "?
"))
8408 (cons "%s
" (plist-get p :subject))
8409 (cons "%m
" (plist-get p :message-id)))))
8410 (when (string-match "%c
" fmt)
8411 ;; Check if the user wrote this message
8412 (if (and org-from-is-user-regexp from to
8413 (save-match-data (string-match org-from-is-user-regexp from)))
8414 (setq fmt (replace-match "to %t
" t t fmt))
8415 (setq fmt (replace-match "from %f
" t t fmt))))
8416 (org-replace-escapes fmt table)))
8418 (defun org-make-org-heading-search-string (&optional string heading)
8419 "Make search string for STRING or current headline.
"
8421 (let ((s (or string (org-get-heading))))
8422 (unless (and string (not heading))
8423 ;; We are using a headline, clean up garbage in there.
8424 (if (string-match org-todo-regexp s)
8425 (setq s (replace-match "" t t s)))
8426 (if (string-match (org-re ":[[:alnum
:]_
@:]+:[ \t]*$
") s)
8427 (setq s (replace-match "" t t s)))
8428 (setq s (org-trim s))
8429 (if (string-match (concat "^
\\(" org-quote-string "\\|
"
8430 org-comment-string "\\)") s)
8431 (setq s (replace-match "" t t s)))
8432 (while (string-match org-ts-regexp s)
8433 (setq s (replace-match "" t t s))))
8434 (while (string-match "[^a-zA-Z_0-9
\t]+" s)
8435 (setq s (replace-match " " t t s)))
8436 (or string (setq s (concat "*" s))) ; Add * for headlines
8437 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8439 (defun org-make-link (&rest strings)
8440 "Concatenate STRINGS.
"
8441 (apply 'concat strings))
8443 (defun org-make-link-string (link &optional description)
8444 "Make a link with brackets
, consisting of LINK and DESCRIPTION.
"
8445 (unless (string-match "\\S-
" link)
8446 (error "Empty link
"))
8447 (when (and description
8448 (stringp description)
8449 (not (string-match "\\S-
" description)))
8450 (setq description nil))
8451 (when (stringp description)
8452 ;; Remove brackets from the description, they are fatal.
8453 (while (string-match "\\[" description)
8454 (setq description (replace-match "{" t t description)))
8455 (while (string-match "\\]" description)
8456 (setq description (replace-match "}" t t description))))
8457 (when (equal (org-link-escape link) description)
8458 ;; No description needed, it is identical
8459 (setq description nil))
8460 (when (and (not description)
8461 (not (equal link (org-link-escape link))))
8462 (setq description (org-extract-attributes link)))
8463 (concat "[[" (org-link-escape link) "]"
8464 (if description (concat "[" description "]") "")
8467 (defconst org-link-escape-chars
8471 (?\340 . "%E0
") ; `a
8472 (?\342 . "%E2
") ; ^a
8473 (?\347 . "%E7
") ; ,c
8474 (?\350 . "%E8
") ; `e
8475 (?\351 . "%E9
") ; 'e
8476 (?\352 . "%EA
") ; ^e
8477 (?\356 . "%EE
") ; ^i
8478 (?\364 . "%F4
") ; ^o
8479 (?\371 . "%F9
") ; `u
8480 (?\373 . "%FB
") ; ^u
8486 "Association list of escapes for some characters problematic in links.
8487 This is the list that is used for internal purposes.
")
8489 (defvar org-url-encoding-use-url-hexify nil)
8491 (defconst org-link-escape-chars-browser
8492 '((?\ . "%
20")) ; 32 for the SPC char
8493 "Association list of escapes for some characters problematic in links.
8494 This is the list that is used before handing over to the browser.
")
8496 (defun org-link-escape (text &optional table)
8497 "Escape characters in TEXT that are problematic for links.
"
8498 (if (and org-url-encoding-use-url-hexify (not table))
8499 (url-hexify-string text)
8500 (setq table (or table org-link-escape-chars))
8502 (let ((re (mapconcat (lambda (x) (regexp-quote
8503 (char-to-string (car x))))
8505 (while (string-match re text)
8508 (cdr (assoc (string-to-char (match-string 0 text))
8513 (defun org-link-unescape (text &optional table)
8514 "Reverse the action of
`org-link-escape
'.
"
8515 (if (and org-url-encoding-use-url-hexify (not table))
8516 (url-unhex-string text)
8517 (setq table (or table org-link-escape-chars))
8519 (let ((case-fold-search t)
8520 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8522 (while (string-match re text)
8525 (char-to-string (car (rassoc (upcase (match-string 0 text))
8530 (defun org-xor (a b)
8534 (defun org-fixup-message-id-for-http (s)
8535 "Replace special characters in a message id
, so it can be used in an http query.
"
8536 (when (string-match "%
" s)
8537 (setq s (mapconcat (lambda (c)
8540 (char-to-string c)))
8542 (while (string-match "<" s)
8543 (setq s (replace-match "%
3C
" t t s)))
8544 (while (string-match ">" s)
8545 (setq s (replace-match "%
3E
" t t s)))
8546 (while (string-match "@" s)
8547 (setq s (replace-match "%
40" t t s)))
8551 (defun org-insert-link-global ()
8552 "Insert a link like Org-mode does.
8553 This command can be called in any mode to insert a link in Org-mode syntax.
"
8555 (org-load-modules-maybe)
8556 (org-run-like-in-org-mode 'org-insert-link))
8558 (defun org-insert-link (&optional complete-file link-location)
8559 "Insert a link. At the prompt
, enter the link.
8561 Completion can be used to insert any of the link protocol prefixes like
8564 The history can be used to select a link previously stored with
8565 `org-store-link
'. When the empty string is entered
(i.e. if you just
8566 press RET at the prompt
), the link defaults to the most recently
8567 stored link. As SPC triggers completion in the minibuffer
, you need to
8568 use M-SPC or C-q SPC to force the insertion of a space character.
8570 You will also be prompted for a description
, and if one is given
, it will
8571 be displayed in the buffer instead of the link.
8573 If there is already a link at point
, this command will allow you to edit link
8574 and description parts.
8576 With a
\\[universal-argument
] prefix
, prompts for a file to link to. The file name can
8577 be selected using completion. The path to the file will be relative to the
8578 current directory if the file is in the current directory or a subdirectory.
8579 Otherwise
, the link will be the absolute path as completed in the minibuffer
8580 \
(i.e. normally ~
/path
/to
/file
). You can configure this behavior using the
8581 option
`org-link-file-path-type
'.
8583 With two
\\[universal-argument
] prefixes
, enforce an absolute path even if the file is in
8584 the current directory or below.
8586 With three
\\[universal-argument
] prefixes
, negate the meaning of
8587 `org-keep-stored-link-after-insertion
'.
8589 If
`org-make-link-description-function
' is non-nil
, this function will be
8590 called with the link target
, and the result will be the default
8593 If the LINK-LOCATION parameter is non-nil
, this value will be
8594 used as the link location instead of reading one interactively.
"
8596 (let* ((wcf (current-window-configuration))
8597 (region (if (org-region-active-p)
8598 (buffer-substring (region-beginning) (region-end))))
8599 (remove (and region (list (region-beginning) (region-end))))
8601 tmphist ; byte-compile incorrectly complains about this
8602 (link link-location)
8603 entry file all-prefixes)
8605 (link-location) ; specified by arg, just use it.
8606 ((org-in-regexp org-bracket-link-regexp 1)
8607 ;; We do have a link at point, and we are going to edit it.
8608 (setq remove (list (match-beginning 0) (match-end 0)))
8609 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8610 (setq link (read-string "Link
: "
8612 (org-match-string-no-properties 1)))))
8613 ((or (org-in-regexp org-angle-link-re)
8614 (org-in-regexp org-plain-link-re))
8615 ;; Convert to bracket link
8616 (setq remove (list (match-beginning 0) (match-end 0))
8617 link (read-string "Link
: "
8618 (org-remove-angle-brackets (match-string 0)))))
8619 ((member complete-file '((4) (16)))
8620 ;; Completing read for file names.
8621 (setq link (org-file-complete-link complete-file)))
8623 ;; Read link, with completion for stored links.
8624 (with-output-to-temp-buffer "*Org Links
*"
8625 (princ "Insert a link.
8626 Use TAB to complete link prefixes
, then RET for type-specific completion support
\n")
8627 (when org-stored-links
8628 (princ "\nStored links are available with
<up
>/<down
> or M-p
/n
(most recent with RET
):\n\n")
8631 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8632 (reverse org-stored-links) "\n"))))
8633 (let ((cw (selected-window)))
8634 (select-window (get-buffer-window "*Org Links
*" 'visible))
8635 (setq truncate-lines t)
8636 (unless (pos-visible-in-window-p (point-max))
8637 (org-fit-window-to-buffer))
8638 (and (window-live-p cw) (select-window cw)))
8639 ;; Fake a link history, containing the stored links.
8640 (setq tmphist (append (mapcar 'car org-stored-links)
8641 org-insert-link-history))
8642 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8643 (mapcar 'car org-link-abbrev-alist)
8648 (let ((org-completion-use-ido nil)
8649 (org-completion-use-iswitchb nil))
8650 (org-completing-read
8653 (mapcar (lambda (x) (list (concat x ":")))
8655 (mapcar 'car org-stored-links))
8658 (car (car org-stored-links)))))
8659 (if (not (string-match "\\S-
" link))
8660 (error "No link selected
"))
8661 (if (or (member link all-prefixes)
8662 (and (equal ":" (substring link -1))
8663 (member (substring link 0 -1) all-prefixes)
8664 (setq link (substring link 0 -1))))
8665 (setq link (org-link-try-special-completion link))))
8666 (set-window-configuration wcf)
8667 (kill-buffer "*Org Links
*"))
8668 (setq entry (assoc link org-stored-links))
8669 (or entry (push link org-insert-link-history))
8670 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8671 (not org-keep-stored-link-after-insertion))
8672 (setq org-stored-links (delq (assoc link org-stored-links)
8674 (setq desc (or desc (nth 1 entry)))))
8676 (if (string-match org-plain-link-re link)
8677 ;; URL-like link, normalize the use of angular brackets.
8678 (setq link (org-make-link (org-remove-angle-brackets link))))
8680 ;; Check if we are linking to the current file with a search option
8681 ;; If yes, simplify the link by using only the search option.
8682 (when (and buffer-file-name
8683 (string-match "^file
:\\(.
+?
\\)::\\([^
>]+\\)" link))
8684 (let* ((path (match-string 1 link))
8685 (case-fold-search nil)
8686 (search (match-string 2 link)))
8688 (if (equal (file-truename buffer-file-name) (file-truename path))
8689 ;; We are linking to this same file, with a search option
8690 (setq link search)))))
8692 ;; Check if we can/should use a relative path. If yes, simplify the link
8693 (when (string-match "^
\\(file:\\|docview
:\\)\\(.
*\\)" link)
8694 (let* ((type (match-string 1 link))
8695 (path (match-string 2 link))
8697 (case-fold-search nil))
8699 ((or (eq org-link-file-path-type 'absolute)
8700 (equal complete-file '(16)))
8701 (setq path (abbreviate-file-name (expand-file-name path))))
8702 ((eq org-link-file-path-type 'noabbrev)
8703 (setq path (expand-file-name path)))
8704 ((eq org-link-file-path-type 'relative)
8705 (setq path (file-relative-name path)))
8708 (if (string-match (concat "^
" (regexp-quote
8710 (file-name-as-directory
8711 default-directory))))
8712 (expand-file-name path))
8713 ;; We are linking a file with relative path name.
8714 (setq path (substring (expand-file-name path)
8716 (setq path (abbreviate-file-name (expand-file-name path)))))))
8717 (setq link (concat type path))
8718 (if (equal desc origpath)
8721 (if org-make-link-description-function
8722 (setq desc (funcall org-make-link-description-function link desc)))
8724 (setq desc (read-string "Description
: " desc))
8725 (unless (string-match "\\S-
" desc) (setq desc nil))
8726 (if remove (apply 'delete-region remove))
8727 (insert (org-make-link-string link desc))))
8729 (defun org-link-try-special-completion (type)
8730 "If there is completion support for link type TYPE
, offer it.
"
8731 (let ((fun (intern (concat "org-
" type "-complete-link
"))))
8734 (read-string "Link
(no completion support
): " (concat type ":")))))
8736 (defun org-file-complete-link (&optional arg)
8737 "Create a file link using completion.
"
8739 (setq file (read-file-name "File
: "))
8740 (let ((pwd (file-name-as-directory (expand-file-name ".
")))
8741 (pwd1 (file-name-as-directory (abbreviate-file-name
8742 (expand-file-name ".
")))))
8745 (setq link (org-make-link
8747 (abbreviate-file-name (expand-file-name file)))))
8748 ((string-match (concat "^
" (regexp-quote pwd1) "\\(.
+\\)") file)
8749 (setq link (org-make-link "file
:" (match-string 1 file))))
8750 ((string-match (concat "^
" (regexp-quote pwd) "\\(.
+\\)")
8751 (expand-file-name file))
8752 (setq link (org-make-link
8753 "file
:" (match-string 1 (expand-file-name file)))))
8754 (t (setq link (org-make-link "file
:" file)))))
8757 (defun org-completing-read (&rest args)
8758 "Completing-read with SPACE being a normal character.
"
8759 (let ((minibuffer-local-completion-map
8760 (copy-keymap minibuffer-local-completion-map)))
8761 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8762 (org-defkey minibuffer-local-completion-map "?
" 'self-insert-command)
8763 (apply 'org-icompleting-read args)))
8765 (defun org-completing-read-no-i (&rest args)
8766 (let (org-completion-use-ido org-completion-use-iswitchb)
8767 (apply 'org-completing-read args)))
8769 (defun org-iswitchb-completing-read (prompt choices &rest args)
8770 "Use iswitch as a completing-read replacement to choose from choices.
8771 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8773 (let* ((iswitchb-use-virtual-buffers nil)
8774 (iswitchb-make-buflist-hook
8776 (setq iswitchb-temp-buflist choices))))
8777 (iswitchb-read-buffer prompt)))
8779 (defun org-icompleting-read (&rest args)
8780 "Completing-read using
`ido-mode
' or
`iswitchb
' speedups if available.
"
8781 (org-without-partial-completion
8782 (if (and org-completion-use-ido
8783 (fboundp 'ido-completing-read)
8784 (boundp 'ido-mode) ido-mode
8785 (listp (second args)))
8786 (let ((ido-enter-matching-directory nil))
8787 (apply 'ido-completing-read (concat (car args))
8788 (if (consp (car (nth 1 args)))
8789 (mapcar (lambda (x) (car x)) (nth 1 args))
8792 (if (and org-completion-use-iswitchb
8793 (boundp 'iswitchb-mode) iswitchb-mode
8794 (listp (second args)))
8795 (apply 'org-iswitchb-completing-read (concat (car args))
8796 (if (consp (car (nth 1 args)))
8797 (mapcar (lambda (x) (car x)) (nth 1 args))
8800 (apply 'completing-read args)))))
8802 (defun org-extract-attributes (s)
8803 "Extract the attributes cookie from a string and set as text property.
"
8804 (let (a attr (start 0) key value)
8806 (when (string-match "{{\\([^
}]+\\)}}$
" s)
8807 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8808 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"" a start)
8809 (setq key (match-string 1 a) value (match-string 2 a)
8811 attr (plist-put attr (intern key) value))))
8812 (org-add-props s nil 'org-attr attr))
8815 (defun org-extract-attributes-from-string (tag)
8816 (let (key value attr)
8817 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"\\s-?
" tag)
8818 (setq key (match-string 1 tag) value (match-string 2 tag)
8819 tag (replace-match "" t t tag)
8820 attr (plist-put attr (intern key) value)))
8823 (defun org-attributes-to-string (plist)
8824 "Format a property list into an HTML attribute list.
"
8825 (let ((s "") key value)
8827 (setq key (pop plist) value (pop plist))
8829 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8832 ;;; Opening/following a link
8834 (defvar org-link-search-failed nil)
8836 (defvar org-open-link-functions nil
8837 "Hook for functions finding a plain text link.
8838 These functions must take a single argument
, the link content.
8839 They will be called for links that look like
[[link text
][description]]
8840 when LINK TEXT does not have a protocol like \"http:\" and does not look
8841 like a filename (e.g. \"./blue.png\").
8843 These functions will be called *before* Org attempts to resolve the
8844 link by doing text searches in the current buffer - so if you want a
8845 link \"[[target]]\" to still find \"<<target>>\", your function should
8846 handle this as a special case.
8848 When the function does handle the link, it must return a non-nil value.
8849 If it decides that it is not responsible for this link, it must return
8850 nil to indicate that that Org-mode can continue with other options
8851 like exact and fuzzy text search.")
8853 (defun org-next-link ()
8854 "Move forward to the next link.
8855 If the link is in hidden text, expose it."
8857 (when (and org-link-search-failed (eq this-command last-command))
8858 (goto-char (point-min))
8859 (message "Link search wrapped back to beginning of buffer"))
8860 (setq org-link-search-failed nil)
8861 (let* ((pos (point))
8863 (a (assoc :link ct)))
8864 (if a (goto-char (nth 2 a)))
8865 (if (re-search-forward org-any-link-re nil t)
8867 (goto-char (match-beginning 0))
8868 (if (org-invisible-p) (org-show-context)))
8870 (setq org-link-search-failed t)
8871 (error "No further link found"))))
8873 (defun org-previous-link ()
8874 "Move backward to the previous link.
8875 If the link is in hidden text, expose it."
8877 (when (and org-link-search-failed (eq this-command last-command))
8878 (goto-char (point-max))
8879 (message "Link search wrapped back to end of buffer"))
8880 (setq org-link-search-failed nil)
8881 (let* ((pos (point))
8883 (a (assoc :link ct)))
8884 (if a (goto-char (nth 1 a)))
8885 (if (re-search-backward org-any-link-re nil t)
8887 (goto-char (match-beginning 0))
8888 (if (org-invisible-p) (org-show-context)))
8890 (setq org-link-search-failed t)
8891 (error "No further link found"))))
8893 (defun org-translate-link (s)
8894 "Translate a link string if a translation function has been defined."
8895 (if (and org-link-translation-function
8896 (fboundp org-link-translation-function)
8897 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8899 (setq s (funcall org-link-translation-function
8900 (match-string 1) (match-string 2)))
8901 (concat (car s) ":" (cdr s)))
8904 (defun org-translate-link-from-planner (type path)
8905 "Translate a link from Emacs Planner syntax so that Org can follow it.
8906 This is still an experimental function, your mileage may vary."
8908 ((member type '("http" "https" "news" "ftp"))
8909 ;; standard Internet links are the same.
8911 ((and (equal type "irc") (string-match "^//" path))
8912 ;; Planner has two / at the beginning of an irc link, we have 1.
8913 ;; We should have zero, actually....
8914 (setq path (substring path 1)))
8915 ((and (equal type "lisp") (string-match "^/" path))
8916 ;; Planner has a slash, we do not.
8917 (setq type "elisp" path (substring path 1)))
8918 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8919 ;; A typical message link. Planner has the id after the final slash,
8920 ;; we separate it with a hash mark
8921 (setq path (concat (match-string 1 path) "#"
8922 (org-remove-angle-brackets (match-string 2 path)))))
8926 (defun org-find-file-at-mouse (ev)
8927 "Open file link or URL at mouse."
8929 (mouse-set-point ev)
8930 (org-open-at-point 'in-emacs))
8932 (defun org-open-at-mouse (ev)
8933 "Open file link or URL at mouse."
8935 (mouse-set-point ev)
8936 (if (eq major-mode 'org-agenda-mode)
8937 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8938 (org-open-at-point))
8940 (defvar org-window-config-before-follow-link nil
8941 "The window configuration before following a link.
8942 This is saved in case the need arises to restore it.")
8944 (defvar org-open-link-marker (make-marker)
8945 "Marker pointing to the location where `org-open-at-point; was called.")
8948 (defun org-open-at-point-global ()
8949 "Follow a link like Org-mode does.
8950 This command can be called in any mode to follow a link that has
8953 (org-run-like-in-org-mode 'org-open-at-point))
8956 (defun org-open-link-from-string (s &optional arg reference-buffer)
8957 "Open a link in the string S, as if it was in Org-mode."
8958 (interactive "sLink: \nP")
8959 (let ((reference-buffer (or reference-buffer (current-buffer))))
8961 (let ((org-inhibit-startup t))
8964 (goto-char (point-min))
8965 (when reference-buffer
8966 (setq org-link-abbrev-alist-local
8967 (with-current-buffer reference-buffer
8968 org-link-abbrev-alist-local)))
8969 (org-open-at-point arg reference-buffer)))))
8971 (defun org-open-at-point (&optional in-emacs reference-buffer)
8972 "Open link at or after point.
8973 If there is no link at point, this function will search forward up to
8974 the end of the current line.
8975 Normally, files will be opened by an appropriate application. If the
8976 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8977 With a double prefix argument, try to open outside of Emacs, in the
8978 application the system uses for this file type."
8980 ;; if in a code block, then open the block's results
8981 (unless (call-interactively #'org-babel-open-src-block-result)
8982 (org-load-modules-maybe)
8983 (move-marker org-open-link-marker (point))
8984 (setq org-window-config-before-follow-link (current-window-configuration))
8985 (org-remove-occur-highlights nil nil t)
8987 ((and (org-on-heading-p)
8989 (concat org-plain-link-re "\\|"
8990 org-bracket-link-regexp "\\|"
8991 org-angle-link-re "\\|"
8992 "[ \t]:[^ \t\n]+:[ \t]*$")))
8993 (not (get-text-property (point) 'org-linked-text)))
8994 (or (org-offer-links-in-entry in-emacs)
8995 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8996 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8997 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8998 (org-footnote-action))
9000 (let (type path link line search (pos (point)))
9003 (skip-chars-forward "^]\n\r")
9004 (when (org-in-regexp org-bracket-link-regexp 1)
9005 (setq link (org-extract-attributes
9006 (org-link-unescape (org-match-string-no-properties 1))))
9007 (while (string-match " *\n *" link)
9008 (setq link (replace-match " " t t link)))
9009 (setq link (org-link-expand-abbrev link))
9011 ((or (file-name-absolute-p link)
9012 (string-match "^\\.\\.?/" link))
9013 (setq type "file" path link))
9014 ((string-match org-link-re-with-space3 link)
9015 (setq type (match-string 1 link) path (match-string 2 link)))
9016 (t (setq type "thisfile" path link)))
9019 (when (get-text-property (point) 'org-linked-text)
9020 (setq type "thisfile"
9021 pos (if (get-text-property (1+ (point)) 'org-linked-text)
9022 (1+ (point)) (point))
9023 path (buffer-substring
9024 (previous-single-property-change pos 'org-linked-text)
9025 (next-single-property-change pos 'org-linked-text)))
9029 (when (or (org-in-regexp org-angle-link-re)
9030 (org-in-regexp org-plain-link-re))
9031 (setq type (match-string 1) path (match-string 2))
9034 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
9036 path (match-string 1))
9037 (while (string-match ":" path)
9038 (setq path (replace-match "+" t t path)))
9040 (when (org-in-regexp "<\\([^><\n]+\\)>")
9041 (setq type "tree-match"
9042 path (match-string 1))
9045 (error "No link found"))
9047 ;; switch back to reference buffer
9048 ;; needed when if called in a temporary buffer through
9049 ;; org-open-link-from-string
9050 (with-current-buffer (or reference-buffer (current-buffer))
9052 ;; Remove any trailing spaces in path
9053 (if (string-match " +\\'" path)
9054 (setq path (replace-match "" t t path)))
9055 (if (and org-link-translation-function
9056 (fboundp org-link-translation-function))
9057 ;; Check if we need to translate the link
9058 (let ((tmp (funcall org-link-translation-function type path)))
9059 (setq type (car tmp) path (cdr tmp))))
9063 ((assoc type org-link-protocols)
9064 (funcall (nth 1 (assoc type org-link-protocols)) path))
9066 ((equal type "mailto")
9067 (let ((cmd (car org-link-mailto-program))
9068 (args (cdr org-link-mailto-program)) args1
9069 (address path) (subject "") a)
9070 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9071 (setq address (match-string 1 path)
9072 subject (org-link-escape (match-string 2 path))))
9075 ((not (stringp (car args))) (push (pop args) args1))
9076 (t (setq a (pop args))
9077 (if (string-match "%a" a)
9078 (setq a (replace-match address t t a)))
9079 (if (string-match "%s" a)
9080 (setq a (replace-match subject t t a)))
9082 (apply cmd (nreverse args1))))
9084 ((member type '("http" "https" "ftp" "news"))
9085 (browse-url (concat type ":" (org-link-escape
9086 path org-link-escape-chars-browser))))
9088 ((string= type "doi")
9089 (browse-url (concat "http://dx.doi.org/"
9091 path org-link-escape-chars-browser))))
9093 ((member type '("message"))
9094 (browse-url (concat type ":" path)))
9096 ((string= type "tags")
9097 (org-tags-view in-emacs path))
9099 ((string= type "tree-match")
9100 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9102 ((string= type "file")
9103 (if (string-match "::\\([0-9]+\\)\\'" path)
9104 (setq line (string-to-number (match-string 1 path))
9105 path (substring path 0 (match-beginning 0)))
9106 (if (string-match "::\\(.+\\)\\'" path)
9107 (setq search (match-string 1 path)
9108 path (substring path 0 (match-beginning 0)))))
9109 (if (string-match "[*?{]" (file-name-nondirectory path))
9111 (org-open-file path in-emacs line search)))
9113 ((string= type "news")
9115 (org-gnus-follow-link path))
9117 ((string= type "shell")
9119 (if (or (not org-confirm-shell-link-function)
9120 (funcall org-confirm-shell-link-function
9121 (format "Execute \"%s\" in shell? "
9122 (org-add-props cmd nil
9123 'face 'org-warning))))
9125 (message "Executing %s" cmd)
9126 (shell-command cmd))
9129 ((string= type "elisp")
9131 (if (or (not org-confirm-elisp-link-function)
9132 (funcall org-confirm-elisp-link-function
9133 (format "Execute \"%s\" as elisp? "
9134 (org-add-props cmd nil
9135 'face 'org-warning))))
9136 (message "%s => %s" cmd
9137 (if (equal (string-to-char cmd) ?\()
9139 (call-interactively (read cmd))))
9142 ((and (string= type "thisfile")
9143 (run-hook-with-args-until-success
9144 'org-open-link-functions path)))
9146 ((string= type "thisfile")
9148 (switch-to-buffer-other-window
9149 (org-get-buffer-for-internal-link (current-buffer)))
9150 (org-mark-ring-push))
9151 (let ((cmd `(org-link-search
9153 ,(cond ((equal in-emacs '(4)) 'occur)
9154 ((equal in-emacs '(16)) 'org-occur)
9157 (condition-case nil (eval cmd)
9158 (error (progn (widen) (eval cmd))))))
9161 (browse-url-at-point)))))))
9162 (move-marker org-open-link-marker nil)
9163 (run-hook-with-args 'org-follow-link-hook)))
9165 (defun org-offer-links-in-entry (&optional nth zero)
9166 "Offer links in the current entry and follow the selected link.
9167 If there is only one link, follow it immediately as well.
9168 If NTH is an integer, immediately pick the NTH link found.
9169 If ZERO is a string, check also this string for a link, and if
9170 there is one, offer it as link number zero."
9171 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
9172 "\\(" org-angle-link-re "\\)\\|"
9173 "\\(" org-plain-link-re "\\)"))
9175 (in-emacs (if (integerp nth) nil nth))
9176 have-zero end links link c)
9177 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
9178 (push (match-string 0 zero) links)
9179 (setq cnt (1- cnt) have-zero t))
9181 (org-back-to-heading t)
9182 (setq end (save-excursion (outline-next-heading) (point)))
9183 (while (re-search-forward re end t)
9184 (push (match-string 0) links))
9185 (setq links (org-uniquify (reverse links))))
9189 (message "No links"))
9190 ((equal (length links) 1)
9191 (setq link (list (car links))))
9192 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
9193 (setq link (nth (if have-zero nth (1- nth)) links)))
9194 (t ; we have to select a link
9196 (save-window-excursion
9197 (delete-other-windows)
9198 (with-output-to-temp-buffer "*Select Link*"
9200 (if (not (string-match org-bracket-link-regexp l))
9201 (princ (format "[%c] %s\n" (incf cnt)
9202 (org-remove-angle-brackets l)))
9204 (princ (format "[%c] %s (%s)\n" (incf cnt)
9205 (match-string 3 l) (match-string 1 l)))
9206 (princ (format "[%c] %s\n" (incf cnt)
9207 (match-string 1 l))))))
9209 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
9210 (message "Select link to open, RET to open all:")
9211 (setq c (read-char-exclusive))
9212 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
9213 (when (equal c ?q) (error "Abort"))
9217 (if have-zero (setq nth (1+ nth)))
9218 (unless (and (integerp nth) (>= (length links) nth))
9219 (error "Invalid link selection"))
9220 (setq link (list (nth (1- nth) links))))))
9222 (let ((buf (current-buffer)))
9224 (org-open-link-from-string l in-emacs buf))
9228 ;; Add special file links that specify the way of opening
9230 (org-add-link-type "file+sys" 'org-open-file-with-system)
9231 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
9232 (defun org-open-file-with-system (path)
9233 "Open file at PATH using the system way of opeing it."
9234 (org-open-file path 'system))
9235 (defun org-open-file-with-emacs (path)
9236 "Open file at PATH in emacs."
9237 (org-open-file path 'emacs))
9238 (defun org-remove-file-link-modifiers ()
9239 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
9240 (goto-char (point-min))
9241 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
9243 (replace-match "file:" t t))))
9244 (eval-after-load "org-exp"
9245 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
9246 'org-remove-file-link-modifiers))
9250 (defun org-get-effort (&optional pom)
9251 "Get the effort estimate for the current entry."
9252 (org-entry-get pom org-effort-property))
9256 (defvar org-create-file-search-functions nil
9257 "List of functions to construct the right search string for a file link.
9258 These functions are called in turn with point at the location to
9259 which the link should point.
9261 A function in the hook should first test if it would like to
9262 handle this file type, for example by checking the major-mode or
9263 the file extension. If it decides not to handle this file, it
9264 should just return nil to give other functions a chance. If it
9265 does handle the file, it must return the search string to be used
9266 when following the link. The search string will be part of the
9267 file link, given after a double colon, and `org-open-at-point'
9268 will automatically search for it. If special measures must be
9269 taken to make the search successful, another function should be
9270 added to the companion hook `org-execute-file-search-functions',
9273 A function in this hook may also use `setq' to set the variable
9274 `description' to provide a suggestion for the descriptive text to
9275 be used for this link when it gets inserted into an Org-mode
9276 buffer with \\[org-insert-link].")
9278 (defvar org-execute-file-search-functions nil
9279 "List of functions to execute a file search triggered by a link.
9281 Functions added to this hook must accept a single argument, the
9282 search string that was part of the file link, the part after the
9283 double colon. The function must first check if it would like to
9284 handle this search, for example by checking the major-mode or the
9285 file extension. If it decides not to handle this search, it
9286 should just return nil to give other functions a chance. If it
9287 does handle the search, it must return a non-nil value to keep
9288 other functions from trying.
9290 Each function can access the current prefix argument through the
9291 variable `current-prefix-argument'. Note that a single prefix is
9292 used to force opening a link in Emacs, so it may be good to only
9293 use a numeric or double prefix to guide the search function.
9295 In case this is needed, a function in this hook can also restore
9296 the window configuration before `org-open-at-point' was called using:
9298 (set-window-configuration org-window-config-before-follow-link)")
9300 (defun org-link-search (s &optional type avoid-pos)
9301 "Search for a link search option.
9302 If S is surrounded by forward slashes, it is interpreted as a
9303 regular expression. In org-mode files, this will create an `org-occur'
9304 sparse tree. In ordinary files, `occur' will be used to list matches.
9305 If the current buffer is in `dired-mode', grep will be used to search
9306 in all files. If AVOID-POS is given, ignore matches near that position."
9307 (let ((case-fold-search t)
9308 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
9309 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
9310 (append '(("") (" ") ("\t") ("\n"))
9314 (pre nil) (post nil)
9315 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
9317 ;; First check if there are any special
9318 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
9319 ;; Now try the builtin stuff
9320 ((and (equal (string-to-char s0) ?#)
9323 (goto-char (point-min))
9326 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
9327 (setq type 'dedicated
9328 pos (match-beginning 0))))
9329 ;; There is an exact target for this
9331 (org-back-to-heading t)))
9333 (goto-char (point-min))
9336 (concat "<<" (regexp-quote s0) ">>") nil t)
9337 (setq type 'dedicated
9338 pos (match-beginning 0))))
9339 ;; There is an exact target for this
9341 ((and (string-match "^(\\(.*\\))$" s0)
9343 (goto-char (point-min))
9346 (concat "[^[]" (regexp-quote
9347 (format org-coderef-label-format
9348 (match-string 1 s0))))
9350 (setq type 'dedicated
9351 pos (1+ (match-beginning 0))))))
9352 ;; There is a coderef target for this
9354 ((string-match "^/\\(.*\\)/$" s)
9355 ;; A regular expression
9358 (org-occur (match-string 1 s)))
9359 ;;((eq major-mode 'dired-mode)
9360 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9361 (t (org-do-occur (match-string 1 s)))))
9363 ;; A normal search strings
9364 (when (equal (string-to-char s) ?*)
9365 ;; Anchor on headlines, post may include tags.
9366 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
9367 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
9369 (remove-text-properties
9371 '(face nil mouse-face nil keymap nil fontified nil) s)
9372 ;; Make a series of regular expressions to find a match
9373 (setq words (org-split-string s "[ \n\r\t]+")
9375 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
9376 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9378 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9379 re2a (concat "[ \t\r\n]" re2a_)
9380 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9381 re4 (concat "[^a-zA-Z_]" re4_)
9383 re1 (concat pre re2 post)
9384 re3 (concat pre (if pre re4_ re4) post)
9385 re5 (concat pre ".*" re4)
9386 re2 (concat pre re2)
9387 re2a (concat pre (if pre re2a_ re2a))
9388 re4 (concat pre (if pre re4_ re4))
9389 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9390 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9394 ((eq type 'org-occur) (org-occur reall))
9395 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9396 (t (goto-char (point-min))
9398 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9399 (org-search-not-self 1 re1 nil t)
9400 (org-search-not-self 1 re2 nil t)
9401 (org-search-not-self 1 re2a nil t)
9402 (org-search-not-self 1 re3 nil t)
9403 (org-search-not-self 1 re4 nil t)
9404 (org-search-not-self 1 re5 nil t)
9406 (goto-char (match-beginning 1))
9408 (error "No match")))))
9410 ;; Normal string-search
9411 (goto-char (point-min))
9412 (if (search-forward s nil t)
9413 (goto-char (match-beginning 0))
9414 (error "No match"))))
9415 (and (org-mode-p) (org-show-context 'link-search))
9418 (defun org-search-not-self (group &rest args)
9419 "Execute `re-search-forward', but only accept matches that do not
9420 enclose the position of `org-open-link-marker'."
9421 (let ((m org-open-link-marker))
9423 (while (apply 're-search-forward args)
9424 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9425 (goto-char (match-end group))
9426 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9427 (> (match-beginning 0) (marker-position m))
9428 (< (match-end 0) (marker-position m)))
9430 (or (not (org-in-regexp
9431 org-bracket-link-analytic-regexp 1))
9432 (not (match-end 4)) ; no description
9433 (and (<= (match-beginning 4) (point))
9434 (>= (match-end 4) (point))))))
9435 (throw 'exit (point))))))))
9437 (defun org-get-buffer-for-internal-link (buffer)
9438 "Return a buffer to be used for displaying the link target of internal links."
9440 ((not org-display-internal-link-with-indirect-buffer)
9442 ((string-match "(Clone)$" (buffer-name buffer))
9443 (message "Buffer is already a clone, not making another one")
9444 ;; we also do not modify visibility in this case
9446 (t ; make a new indirect buffer for displaying the link
9447 (let* ((bn (buffer-name buffer))
9448 (ibn (concat bn "(Clone)"))
9449 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9450 (with-current-buffer ib (org-overview))
9453 (defun org-do-occur (regexp &optional cleanup)
9454 "Call the Emacs command `occur'.
9455 If CLEANUP is non-nil, remove the printout of the regular expression
9456 in the *Occur* buffer. This is useful if the regex is long and not useful
9460 (let ((cwin (selected-window)) win beg end)
9461 (when (setq win (get-buffer-window "*Occur*"))
9462 (select-window win))
9463 (goto-char (point-min))
9464 (when (re-search-forward "match[a-z]+" nil t)
9465 (setq beg (match-end 0))
9466 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9467 (setq end (1- (match-beginning 0)))))
9468 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9469 (goto-char (point-min))
9470 (select-window cwin))))
9472 ;;; The mark ring for links jumps
9474 (defvar org-mark-ring nil
9475 "Mark ring for positions before jumps in Org-mode.")
9476 (defvar org-mark-ring-last-goto nil
9477 "Last position in the mark ring used to go back.")
9478 ;; Fill and close the ring
9479 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9480 (loop for i from 1 to org-mark-ring-length do
9481 (push (make-marker) org-mark-ring))
9482 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9485 (defun org-mark-ring-push (&optional pos buffer)
9486 "Put the current position or POS into the mark ring and rotate it."
9488 (setq pos (or pos (point)))
9489 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9490 (move-marker (car org-mark-ring)
9492 (or buffer (current-buffer)))
9494 (substitute-command-keys
9495 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9497 (defun org-mark-ring-goto (&optional n)
9498 "Jump to the previous position in the mark ring.
9499 With prefix arg N, jump back that many stored positions. When
9500 called several times in succession, walk through the entire ring.
9501 Org-mode commands jumping to a different position in the current file,
9502 or to another Org-mode file, automatically push the old position
9506 (if (eq last-command this-command)
9507 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9508 (setq p org-mark-ring))
9509 (setq org-mark-ring-last-goto p)
9511 (switch-to-buffer (marker-buffer m))
9513 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9515 (defun org-remove-angle-brackets (s)
9516 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9517 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9519 (defun org-add-angle-brackets (s)
9520 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9521 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9523 (defun org-remove-double-quotes (s)
9524 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9525 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9528 ;;; Following specific links
9530 (defun org-follow-timestamp-link ()
9532 ((org-at-date-range-p t)
9533 (let ((org-agenda-start-on-weekday)
9534 (t1 (match-string 1))
9535 (t2 (match-string 2)))
9536 (setq t1 (time-to-days (org-time-string-to-time t1))
9537 t2 (time-to-days (org-time-string-to-time t2)))
9538 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9539 ((org-at-timestamp-p t)
9540 (org-agenda-list nil (time-to-days (org-time-string-to-time
9541 (substring (match-string 1) 0 10)))
9543 (t (error "This should not happen"))))
9546 ;;; Following file links
9547 (defvar org-wait nil)
9548 (defun org-open-file (path &optional in-emacs line search)
9549 "Open the file at PATH.
9550 First, this expands any special file name abbreviations. Then the
9551 configuration variable `org-file-apps' is checked if it contains an
9552 entry for this file type, and if yes, the corresponding command is launched.
9554 If no application is found, Emacs simply visits the file.
9556 With optional prefix argument IN-EMACS, Emacs will visit the file.
9557 With a double C-c C-u prefix arg, Org tries to avoid opening in Emacs
9558 and to use an external application to visit the file.
9560 Optional LINE specifies a line to go to, optional SEARCH a string
9561 to search for. If LINE or SEARCH is given, the file will be
9562 opened in Emacs, unless an entry from org-file-apps that makes
9563 use of groups in a regexp matches.
9564 If the file does not exist, an error is thrown."
9565 (let* ((file (if (equal path "")
9567 (substitute-in-file-name (expand-file-name path))))
9568 (file-apps (append org-file-apps (org-default-apps)))
9569 (apps (org-remove-if
9570 'org-file-apps-entry-match-against-dlink-p file-apps))
9571 (apps-dlink (org-remove-if-not
9572 'org-file-apps-entry-match-against-dlink-p file-apps))
9573 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9574 (dirp (if remp nil (file-directory-p file)))
9575 (file (if (and dirp org-open-directory-means-index-dot-org)
9576 (concat (file-name-as-directory file) "index.org")
9578 (a-m-a-p (assq 'auto-mode apps))
9579 (dfile (downcase file))
9580 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9581 (link (cond ((and (eq line nil)
9585 (concat file "::" (number-to-string line)))
9587 (concat file "::" search))))
9588 (dlink (downcase link))
9589 (old-buffer (current-buffer))
9591 (old-mode major-mode)
9592 ext cmd link-match-data)
9593 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9594 (setq ext (match-string 1 dfile))
9595 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9596 (setq ext (match-string 1 dfile))))
9598 ((member in-emacs '((16) system))
9599 (setq cmd (cdr (assoc 'system apps))))
9600 (in-emacs (setq cmd 'emacs))
9602 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9603 (and dirp (cdr (assoc 'directory apps)))
9604 ; first, try matching against apps-dlink
9605 ; if we get a match here, store the match data for later
9606 (let ((match (assoc-default dlink apps-dlink
9609 (progn (setq link-match-data (match-data))
9611 (progn (setq in-emacs (or in-emacs line search))
9612 nil))) ; if we have no match in apps-dlink,
9613 ; always open the file in emacs if line or search
9614 ; is given (for backwards compatibility)
9615 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9617 (cdr (assoc ext apps))
9618 (cdr (assoc t apps))))))
9619 (when (eq cmd 'system)
9620 (setq cmd (cdr (assoc 'system apps))))
9621 (when (eq cmd 'default)
9622 (setq cmd (cdr (assoc t apps))))
9623 (when (eq cmd 'mailcap)
9625 (mailcap-parse-mailcaps)
9626 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9627 (command (mailcap-mime-info mime-type)))
9628 (if (stringp command)
9630 (setq cmd 'emacs))))
9631 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9632 (not (file-exists-p file))
9633 (not org-open-non-existing-files))
9634 (error "No such file: %s" file))
9636 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9637 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9638 (while (string-match "['\"]%s['\"]" cmd)
9639 (setq cmd (replace-match "%s" t t cmd)))
9640 (while (string-match "%s" cmd)
9641 (setq cmd (replace-match
9643 (shell-quote-argument
9644 (convert-standard-filename file)))
9647 ;; Replace "%1", "%2" etc. in command with group matches from regex
9649 (let ((match-index 1)
9650 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9651 (set-match-data link-match-data)
9652 (while (<= match-index number-of-groups)
9653 (let ((regex (concat "%" (number-to-string match-index)))
9654 (replace-with (match-string match-index dlink)))
9655 (while (string-match regex cmd)
9656 (setq cmd (replace-match replace-with t t cmd))))
9657 (setq match-index (+ match-index 1)))))
9659 (save-window-excursion
9660 (start-process-shell-command cmd nil cmd)
9661 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9665 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9667 (if line (org-goto-line line)
9668 (if search (org-link-search search))))
9670 (let ((file (convert-standard-filename file)))
9672 (set-match-data link-match-data)
9674 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9675 (and (org-mode-p) (eq old-mode 'org-mode)
9676 (or (not (equal old-buffer (current-buffer)))
9677 (not (equal old-pos (point))))
9678 (org-mark-ring-push old-pos old-buffer))))
9680 (defun org-file-apps-entry-match-against-dlink-p (entry)
9681 "This function returns non-nil if `entry' uses a regular
9682 expression which should be matched against the whole link by
9685 It assumes that is the case when the entry uses a regular
9686 expression which has at least one grouping construct and the
9687 action is either a lisp form or a command string containing
9688 '%1', i.e. using at least one subexpression match as a
9690 (let ((selector (car entry))
9691 (action (cdr entry)))
9692 (if (stringp selector)
9693 (and (> (regexp-opt-depth selector) 0)
9694 (or (and (stringp action)
9695 (string-match "%[0-9]" action))
9699 (defun org-default-apps ()
9700 "Return the default applications for this operating system."
9702 ((eq system-type 'darwin)
9703 org-file-apps-defaults-macosx)
9704 ((eq system-type 'windows-nt)
9705 org-file-apps-defaults-windowsnt)
9706 (t org-file-apps-defaults-gnu)))
9708 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9709 "Convert extensions to regular expressions in the cars of LIST.
9710 Also, weed out any non-string entries, because the return value is used
9711 only for regexp matching.
9712 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9713 point to the symbol `emacs', indicating that the file should
9714 be opened in Emacs."
9718 (if (not (stringp (car x)))
9720 (if (string-match "\\W" (car x))
9722 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9725 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9727 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9728 (defun org-file-remote-p (file)
9729 "Test whether FILE specifies a location on a remote system.
9730 Return non-nil if the location is indeed remote.
9732 For example, the filename \"/user@host:/foo\" specifies a location
9733 on the system \"/user@host:\"."
9734 (cond ((fboundp 'file-remote-p)
9735 (file-remote-p file))
9736 ((fboundp 'tramp-handle-file-remote-p)
9737 (tramp-handle-file-remote-p file))
9738 ((and (boundp 'ange-ftp-name-format)
9739 (string-match (car ange-ftp-name-format) file))
9746 (defun org-get-org-file ()
9747 "Read a filename, with default directory `org-directory'."
9748 (let ((default (or org-default-notes-file remember-data-file)))
9749 (read-file-name (format "File name [%s]: " default)
9750 (file-name-as-directory org-directory)
9753 (defun org-notes-order-reversed-p ()
9754 "Check if the current file should receive notes in reversed order."
9756 ((not org-reverse-note-order) nil)
9757 ((eq t org-reverse-note-order) t)
9758 ((not (listp org-reverse-note-order)) nil)
9760 (let ((all org-reverse-note-order)
9762 (while (setq entry (pop all))
9763 (if (string-match (car entry) buffer-file-name)
9764 (throw 'exit (cdr entry))))
9767 (defvar org-refile-target-table nil
9768 "The list of refile targets, created by `org-refile'.")
9770 (defvar org-agenda-new-buffers nil
9771 "Buffers created to visit agenda files.")
9773 (defvar org-refile-cache nil
9774 "Cache for refile targets.")
9777 (defvar org-refile-markers nil
9778 "All the markers used for caching refile locations.")
9780 (defun org-refile-marker (pos)
9781 "Get a new refile marker, but only if caching is in use."
9782 (if (not org-refile-use-cache)
9784 (let ((m (make-marker)))
9786 (push m org-refile-markers)
9789 (defun org-refile-cache-clear ()
9790 "Clear the refile cache and disable all the markers."
9791 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
9792 (setq org-refile-markers nil)
9793 (setq org-refile-cache nil)
9794 (message "Refile cache has been cleared"))
9796 (defun org-refile-cache-check-set (set)
9797 "Check if all the markers in the cache still have live buffers."
9800 (while (and set (setq marker (nth 3 (pop set))))
9801 ;; if org-refile-use-outline-path is 'file, marker may be nil
9802 (when (and marker (null (marker-buffer marker)))
9803 (message "not found") (sit-for 3)
9807 (defun org-refile-cache-put (set &rest identifiers)
9808 "Push the refile targets SET into the cache, under IDENTIFIERS."
9809 (let* ((key (sha1 (prin1-to-string identifiers)))
9810 (entry (assoc key org-refile-cache)))
9813 (push (cons key set) org-refile-cache))))
9815 (defun org-refile-cache-get (&rest identifiers)
9816 "Retrieve the cached value for refile targets given by IDENTIFIERS."
9818 ((not org-refile-cache) nil)
9819 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
9821 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
9822 org-refile-cache))))
9823 (and set (org-refile-cache-check-set set) set)))))
9825 (defun org-get-refile-targets (&optional default-buffer)
9826 "Produce a table with refile targets."
9827 (let ((case-fold-search nil)
9828 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9829 (entries (or org-refile-targets '((nil . (:level . 1)))))
9830 targets tgs txt re files f desc descre fast-path-p level pos0)
9831 (message "Getting targets...")
9832 (with-current-buffer (or default-buffer (current-buffer))
9833 (while (setq entry (pop entries))
9834 (setq files (car entry) desc (cdr entry))
9835 (setq fast-path-p nil)
9837 ((null files) (setq files (list (current-buffer))))
9838 ((eq files 'org-agenda-files)
9839 (setq files (org-agenda-files 'unrestricted)))
9840 ((and (symbolp files) (fboundp files))
9841 (setq files (funcall files)))
9842 ((and (symbolp files) (boundp files))
9843 (setq files (symbol-value files))))
9844 (if (stringp files) (setq files (list files)))
9846 ((eq (car desc) :tag)
9847 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9848 ((eq (car desc) :todo)
9849 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9850 ((eq (car desc) :regexp)
9851 (setq descre (cdr desc)))
9852 ((eq (car desc) :level)
9853 (setq descre (concat "^\\*\\{" (number-to-string
9854 (if org-odd-levels-only
9855 (1- (* 2 (cdr desc)))
9858 ((eq (car desc) :maxlevel)
9859 (setq fast-path-p t)
9860 (setq descre (concat "^\\*\\{1," (number-to-string
9861 (if org-odd-levels-only
9862 (1- (* 2 (cdr desc)))
9865 (t (error "Bad refiling target description %s" desc)))
9866 (while (setq f (pop files))
9867 (with-current-buffer
9868 (if (bufferp f) f (org-get-agenda-file-buffer f))
9870 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
9872 (if (bufferp f) (setq f (buffer-file-name
9873 (buffer-base-buffer f))))
9874 (setq f (and f (expand-file-name f)))
9875 (if (eq org-refile-use-outline-path 'file)
9876 (push (list (file-name-nondirectory f) f nil nil) tgs))
9880 (goto-char (point-min))
9881 (while (re-search-forward descre nil t)
9882 (goto-char (setq pos0 (point-at-bol)))
9884 (when org-refile-target-verify-function
9886 (or (funcall org-refile-target-verify-function)
9888 (when (looking-at org-complex-heading-regexp)
9889 (setq level (org-reduced-level
9890 (- (match-end 1) (match-beginning 1)))
9891 txt (org-link-display-format (match-string 4))
9892 re (concat "^" (regexp-quote
9896 (if (match-end 5) (setq re (concat
9899 (match-string 5)))))
9900 (setq re (concat re "[ \t]*$"))
9901 (when org-refile-use-outline-path
9902 (setq txt (mapconcat
9905 (if (eq org-refile-use-outline-path
9907 (list (file-name-nondirectory
9909 (buffer-base-buffer))))
9910 (if (eq org-refile-use-outline-path
9912 (list (buffer-file-name
9913 (buffer-base-buffer)))))
9914 (org-get-outline-path fast-path-p
9918 (push (list txt f re (org-refile-marker (point)))
9920 (when (= (point) pos0)
9921 ;; verification function has not moved point
9922 (goto-char (point-at-eol))))))))
9923 (when org-refile-use-cache
9924 (org-refile-cache-put tgs (buffer-file-name) descre))
9925 (setq targets (append tgs targets))
9927 (message "Getting targets...done")
9928 (nreverse targets)))
9930 (defun org-protect-slash (s)
9931 (while (string-match "/" s)
9932 (setq s (replace-match "\\" t t s)))
9935 (defvar org-olpa (make-vector 20 nil))
9937 (defun org-get-outline-path (&optional fastp level heading)
9938 "Return the outline path to the current entry, as a list.
9940 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
9941 routine which makes outline path derivations for an entire file,
9942 avoiding backtracing. Refile target collection makes use of that."
9946 (error "Outline path failure, more than 19 levels."))
9947 (loop for i from level upto 19 do
9948 (aset org-olpa i nil))
9950 (delq nil (append org-olpa nil))
9951 (aset org-olpa level heading)))
9952 (let (rtn case-fold-search)
9956 (while (org-up-heading-safe)
9957 (when (looking-at org-complex-heading-regexp)
9958 (push (org-match-string-no-properties 4) rtn)))
9961 (defun org-format-outline-path (path &optional width prefix)
9962 "Format the outlie path PATH for display.
9963 Width is the maximum number of characters that is available.
9964 Prefix is a prefix to be included in the returned string,
9965 such as the file name."
9966 (setq width (or width 79))
9967 (if prefix (setq width (- width (length prefix))))
9970 (let* ((nsteps (length path))
9971 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9972 (maxwidth (if (<= total-width width)
9973 10000 ;; everything fits
9974 ;; we need to shorten the level headings
9975 (/ (- width nsteps) nsteps)))
9976 (org-odd-levels-only nil)
9978 (total (1+ (length prefix))))
9979 (setq maxwidth (max maxwidth 10))
9984 (if (and (= n nsteps) (< maxwidth 10000))
9985 (setq maxwidth (- total-width total)))
9986 (if (< (length h) maxwidth)
9987 (progn (setq total (+ total (length h) 1)) h)
9988 (setq h (substring h 0 (- maxwidth 2))
9989 total (+ total maxwidth 1))
9990 (if (string-match "[ \t]+\\'" h)
9991 (setq h (substring h 0 (match-beginning 0))))
9992 (setq h (concat h "..")))
9993 (org-add-props h nil 'face
9994 (nth (% (1- n) org-n-level-faces)
9999 (defun org-display-outline-path (&optional file current)
10000 "Display the current outline path in the echo area."
10002 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
10003 (case-fold-search nil)
10004 (path (and (org-mode-p) (org-get-outline-path))))
10005 (if current (setq path (append path
10007 (org-back-to-heading t)
10008 (if (looking-at org-complex-heading-regexp)
10009 (list (match-string 4)))))))
10011 (org-format-outline-path
10014 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
10016 (defvar org-refile-history nil
10017 "History for refiling operations.")
10019 (defvar org-after-refile-insert-hook nil
10020 "Hook run after `org-refile' has inserted its stuff at the new location.
10021 Note that this is still *before* the stuff will be removed from
10022 the *old* location.")
10024 (defvar org-capture-last-stored-marker)
10025 (defun org-refile (&optional goto default-buffer rfloc)
10026 "Move the entry at point to another heading.
10027 The list of target headings is compiled using the information in
10028 `org-refile-targets', which see. This list is created before each use
10029 and will therefore always be up-to-date.
10031 At the target location, the entry is filed as a subitem of the target heading.
10032 Depending on `org-reverse-note-order', the new subitem will either be the
10033 first or the last subitem.
10035 If there is an active region, all entries in that region will be moved.
10036 However, the region must fulfil the requirement that the first heading
10037 is the first one sets the top-level of the moved text - at most siblings
10038 below it are allowed.
10040 With prefix arg GOTO, the command will only visit the target location,
10041 not actually move anything.
10042 With a double prefix `C-u C-u', go to the location where the last refiling
10043 operation has put the subtree.
10044 With a prefix argument of `2', refile to the running clock.
10046 RFLOC can be a refile location obtained in a different way.
10048 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
10050 If you are using target caching (see `org-refile-use-cache'),
10051 You have to clear the target cache in order to find new targets.
10052 This can be done with a 0 prefix: `C-0 C-c C-w'"
10054 (if (member goto '(0 (64)))
10055 (org-refile-cache-clear)
10056 (let* ((cbuf (current-buffer))
10057 (regionp (org-region-active-p))
10058 (region-start (and regionp (region-beginning)))
10059 (region-end (and regionp (region-end)))
10060 (region-length (and regionp (- region-end region-start)))
10061 (filename (buffer-file-name (buffer-base-buffer cbuf)))
10062 pos it nbuf file re level reversed)
10063 (setq last-command nil)
10065 (goto-char region-start)
10066 (or (bolp) (goto-char (point-at-bol)))
10067 (setq region-start (point))
10068 (unless (org-kill-is-subtree-p
10069 (buffer-substring region-start region-end))
10070 (error "The region is not a (sequence of) subtree(s)")))
10071 (if (equal goto '(16))
10072 (org-refile-goto-last-stored)
10074 (and (equal goto 2)
10075 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10077 (setq it (list (or org-clock-heading "running clock")
10079 (marker-buffer org-clock-hd-marker))
10081 (marker-position org-clock-hd-marker)))
10085 (org-refile-get-location
10086 (if goto "Goto: " "Refile to: ") default-buffer
10087 org-refile-allow-creating-parent-nodes)))))
10088 (setq file (nth 1 it)
10091 (if (and (not goto)
10093 (equal (buffer-file-name) file)
10095 (and (>= pos region-start)
10096 (<= pos region-end))
10097 (and (>= pos (point))
10098 (< pos (save-excursion
10099 (org-end-of-subtree t t))))))
10100 (error "Cannot refile to position inside the tree or region"))
10102 (setq nbuf (or (find-buffer-visiting file)
10103 (find-file-noselect file)))
10106 (switch-to-buffer nbuf)
10108 (org-show-context 'org-goto))
10111 (org-kill-new (buffer-substring region-start region-end))
10112 (org-save-markers-in-region region-start region-end))
10113 (org-copy-subtree 1 nil t))
10114 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
10115 (find-file-noselect file)))
10116 (setq reversed (org-notes-order-reversed-p))
10123 (looking-at outline-regexp)
10124 (setq level (org-get-valid-level (funcall outline-level) 1))
10127 (or (outline-next-heading) (point-max))
10128 (or (save-excursion (org-get-next-sibling))
10129 (org-end-of-subtree t t)
10133 (goto-char (point-max))
10134 (goto-char (point-min))
10135 (or (outline-next-heading) (goto-char (point-max)))))
10136 (if (not (bolp)) (newline))
10137 (org-paste-subtree level)
10138 (when org-log-refile
10139 (org-add-log-setup 'refile nil nil 'findpos
10141 (unless (eq org-log-refile 'note)
10142 (save-excursion (org-add-log-note))))
10143 (and org-auto-align-tags (org-set-tags nil t))
10144 (bookmark-set "org-refile-last-stored")
10145 ;; If we are refiling for capture, make sure that the
10146 ;; last-capture pointers point here
10147 (when (org-bound-and-true-p org-refile-for-capture)
10148 (bookmark-set "org-capture-last-stored-marker")
10149 (move-marker org-capture-last-stored-marker (point)))
10150 (if (fboundp 'deactivate-mark) (deactivate-mark))
10151 (run-hooks 'org-after-refile-insert-hook))))
10153 (delete-region (point) (+ (point) region-length))
10155 (when (featurep 'org-inlinetask)
10156 (org-inlinetask-remove-END-maybe))
10157 (setq org-markers-to-move nil)
10158 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
10160 (defun org-refile-goto-last-stored ()
10161 "Go to the location where the last refile was stored."
10163 (bookmark-jump "org-refile-last-stored")
10164 (message "This is the location of the last refile"))
10166 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
10167 "Prompt the user for a refile location, using PROMPT."
10168 (let ((org-refile-targets org-refile-targets)
10169 (org-refile-use-outline-path org-refile-use-outline-path))
10170 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
10171 (unless org-refile-target-table
10172 (error "No refile targets"))
10173 (let* ((cbuf (current-buffer))
10174 (partial-completion-mode nil)
10175 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
10176 (cfunc (if (and org-refile-use-outline-path
10177 org-outline-path-complete-in-steps)
10178 'org-olpath-completing-read
10179 'org-icompleting-read))
10180 (extra (if org-refile-use-outline-path "/" ""))
10181 (filename (and cfn (expand-file-name cfn)))
10184 (if (and (not (member org-refile-use-outline-path
10185 '(file full-file-path)))
10186 (not (equal filename (nth 1 x))))
10187 (cons (concat (car x) extra " ("
10188 (file-name-nondirectory (nth 1 x)) ")")
10190 (cons (concat (car x) extra) (cdr x))))
10191 org-refile-target-table))
10192 (completion-ignore-case t)
10193 pa answ parent-target child parent old-hist)
10194 (setq old-hist org-refile-history)
10195 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
10196 nil 'org-refile-history))
10197 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
10200 (when (or (not org-refile-history)
10201 (not (eq old-hist org-refile-history))
10202 (not (equal (car pa) (car org-refile-history))))
10203 (setq org-refile-history
10204 (cons (car pa) (if (assoc (car org-refile-history) tbl)
10206 (cdr org-refile-history))))
10207 (if (equal (car org-refile-history) (nth 1 org-refile-history))
10208 (pop org-refile-history)))
10210 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
10212 (setq parent (match-string 1 answ)
10213 child (match-string 2 answ))
10214 (setq parent-target (or (assoc parent tbl)
10215 (assoc (concat parent "/") tbl)))
10216 (when (and parent-target
10217 (or (eq new-nodes t)
10218 (and (eq new-nodes 'confirm)
10219 (y-or-n-p (format "Create new node \"%s\"? "
10221 (org-refile-new-child parent-target child)))
10222 (error "Invalid target location")))))
10224 (defun org-refile-new-child (parent-target child)
10225 "Use refile target PARENT-TARGET to add new CHILD below it."
10226 (unless parent-target
10227 (error "Cannot find parent for new node"))
10228 (let ((file (nth 1 parent-target))
10229 (pos (nth 3 parent-target))
10231 (with-current-buffer (or (find-buffer-visiting file)
10232 (find-file-noselect file))
10238 (goto-char (point-max))
10239 (if (not (bolp)) (newline)))
10240 (when (looking-at outline-regexp)
10241 (setq level (funcall outline-level))
10242 (org-end-of-subtree t t))
10243 (org-back-over-empty-lines)
10244 (insert "\n" (make-string
10245 (if pos (org-get-valid-level level 1) 1) ?*)
10247 (beginning-of-line 0)
10248 (list (concat (car parent-target) "/" child) file "" (point)))))))
10250 (defun org-olpath-completing-read (prompt collection &rest args)
10251 "Read an outline path like a file name."
10252 (let ((thetable collection)
10253 (org-completion-use-ido nil) ; does not work with ido.
10254 (org-completion-use-iswitchb nil)) ; or iswitchb
10256 'org-icompleting-read prompt
10257 (lambda (string predicate &optional flag)
10258 (let (rtn r f (l (length string)))
10262 (try-completion string thetable))
10265 (setq rtn (all-completions string thetable predicate))
10268 (setq r (substring x l))
10269 (if (string-match " ([^)]*)$" x)
10270 (setq f (match-string 0 x))
10272 (if (string-match "/" r)
10273 (concat string (substring r 0 (match-end 0)) f)
10278 (assoc string thetable)))
10282 ;;;; Dynamic blocks
10284 (defun org-find-dblock (name)
10285 "Find the first dynamic block with name NAME in the buffer.
10286 If not found, stay at current position and return nil."
10289 (goto-char (point-min))
10290 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
10292 (match-beginning 0))))
10293 (if pos (goto-char pos))
10296 (defconst org-dblock-start-re
10297 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
10298 "Matches the start line of a dynamic block, with parameters.")
10300 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
10301 "Matches the end of a dynamic block.")
10303 (defun org-create-dblock (plist)
10304 "Create a dynamic block section, with parameters taken from PLIST.
10305 PLIST must contain a :name entry which is used as name of the block."
10306 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
10309 (let ((col (current-column))
10310 (name (plist-get plist :name)))
10311 (insert "#+BEGIN: " name)
10313 (if (eq (car plist) :name)
10314 (setq plist (cddr plist))
10315 (insert " " (prin1-to-string (pop plist)))))
10316 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
10317 (beginning-of-line -2)))
10319 (defun org-prepare-dblock ()
10320 "Prepare dynamic block for refresh.
10321 This empties the block, puts the cursor at the insert position and returns
10322 the property list including an extra property :name with the block name."
10323 (unless (looking-at org-dblock-start-re)
10324 (error "Not at a dynamic block"))
10325 (let* ((begdel (1+ (match-end 0)))
10326 (name (org-no-properties (match-string 1)))
10327 (params (append (list :name name)
10328 (read (concat "(" (match-string 3) ")")))))
10330 (beginning-of-line 1)
10331 (skip-chars-forward " \t")
10332 (setq params (plist-put params :indentation-column (current-column))))
10333 (unless (re-search-forward org-dblock-end-re nil t)
10334 (error "Dynamic block not terminated"))
10337 (list :content (buffer-substring
10338 begdel (match-beginning 0)))))
10339 (delete-region begdel (match-beginning 0))
10344 (defun org-map-dblocks (&optional command)
10345 "Apply COMMAND to all dynamic blocks in the current buffer.
10346 If COMMAND is not given, use `org-update-dblock'."
10347 (let ((cmd (or command 'org-update-dblock)))
10349 (goto-char (point-min))
10350 (while (re-search-forward org-dblock-start-re nil t)
10351 (goto-char (match-beginning 0))
10353 (condition-case nil
10355 (error (message "Error during update of dynamic block"))))
10356 (unless (re-search-forward org-dblock-end-re nil t)
10357 (error "Dynamic block not terminated"))))))
10359 (defun org-dblock-update (&optional arg)
10360 "User command for updating dynamic blocks.
10361 Update the dynamic block at point. With prefix ARG, update all dynamic
10362 blocks in the buffer."
10365 (org-update-all-dblocks)
10366 (or (looking-at org-dblock-start-re)
10367 (org-beginning-of-dblock))
10368 (org-update-dblock)))
10370 (defun org-update-dblock ()
10371 "Update the dynamic block at point
10372 This means to empty the block, parse for parameters and then call
10373 the correct writing function."
10374 (save-window-excursion
10375 (let* ((pos (point))
10376 (line (org-current-line))
10377 (params (org-prepare-dblock))
10378 (name (plist-get params :name))
10379 (indent (plist-get params :indentation-column))
10380 (cmd (intern (concat "org-dblock-write:" name))))
10381 (message "Updating dynamic block `%s' at line %d..." name line)
10382 (funcall cmd params)
10383 (message "Updating dynamic block `%s' at line %d...done" name line)
10385 (when (and indent (> indent 0))
10386 (setq indent (make-string indent ?\ ))
10388 (org-beginning-of-dblock)
10390 (while (not (looking-at org-dblock-end-re))
10392 (beginning-of-line 2))
10393 (when (looking-at org-dblock-end-re)
10394 (and (looking-at "[ \t]+")
10395 (replace-match ""))
10396 (insert indent)))))))
10398 (defun org-beginning-of-dblock ()
10399 "Find the beginning of the dynamic block at point.
10400 Error if there is no such block at point."
10401 (let ((pos (point))
10404 (if (and (re-search-backward org-dblock-start-re nil t)
10405 (setq beg (match-beginning 0))
10406 (re-search-forward org-dblock-end-re nil t)
10407 (> (match-end 0) pos))
10410 (error "Not in a dynamic block"))))
10412 (defun org-update-all-dblocks ()
10413 "Update all dynamic blocks in the buffer.
10414 This function can be used in a hook."
10416 (org-map-dblocks 'org-update-dblock)))
10421 (defconst org-additional-option-like-keywords
10422 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
10423 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
10424 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
10425 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
10427 "ORGTBL" "TBLFM:" "TBLNAME:"
10428 "BEGIN_EXAMPLE" "END_EXAMPLE"
10429 "BEGIN_QUOTE" "END_QUOTE"
10430 "BEGIN_VERSE" "END_VERSE"
10431 "BEGIN_CENTER" "END_CENTER"
10432 "BEGIN_SRC" "END_SRC"
10433 "CATEGORY" "COLUMNS"
10439 (defcustom org-structure-template-alist
10441 ("s" "#+begin_src ?\n\n#+end_src"
10442 "<src lang=\"?\">\n\n</src>")
10443 ("e" "#+begin_example\n?\n#+end_example"
10444 "<example>\n?\n</example>")
10445 ("q" "#+begin_quote\n?\n#+end_quote"
10446 "<quote>\n?\n</quote>")
10447 ("v" "#+begin_verse\n?\n#+end_verse"
10448 "<verse>\n?\n/verse>")
10449 ("c" "#+begin_center\n?\n#+end_center"
10450 "<center>\n?\n/center>")
10451 ("l" "#+begin_latex\n?\n#+end_latex"
10452 "<literal style=\"latex\">\n?\n</literal>")
10454 "<literal style=\"latex\">?</literal>")
10455 ("h" "#+begin_html\n?\n#+end_html"
10456 "<literal style=\"html\">\n?\n</literal>")
10458 "<literal style=\"html\">?</literal>")
10459 ("a" "#+begin_ascii\n?\n#+end_ascii")
10461 ("i" "#+include %file ?"
10462 "<include file=%file markup=\"?\">")
10464 "Structure completion elements.
10465 This is a list of abbreviation keys and values. The value gets inserted
10466 if you type `<' followed by the key and then press the completion key,
10467 usually `M-TAB'. %file will be replaced by a file name after prompting
10468 for the file using completion.
10469 There are two templates for each key, the first uses the original Org syntax,
10470 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
10471 the default when the /org-mtags.el/ module has been loaded. See also the
10472 variable `org-mtags-prefer-muse-templates'.
10473 This is an experimental feature, it is undecided if it is going to stay in."
10474 :group 'org-completion
10476 (string :tag "Key")
10477 (string :tag "Template")
10478 (string :tag "Muse Template")))
10480 (defun org-try-structure-completion ()
10481 "Try to complete a structure template before point.
10482 This looks for strings like \"<e\" on an otherwise empty line and
10484 (let ((l (buffer-substring (point-at-bol) (point)))
10486 (when (and (looking-at "[ \t]*$")
10487 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
10488 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
10489 (org-complete-expand-structure-template (+ -1 (point-at-bol)
10490 (match-beginning 1)) a)
10493 (defun org-complete-expand-structure-template (start cell)
10494 "Expand a structure template."
10495 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10496 (rpl (nth (if musep 2 1) cell))
10498 (delete-region start (point))
10499 (when (string-match "\\`#\\+" rpl)
10502 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10503 (setq ind (buffer-substring (point-at-bol) (point))))
10505 (setq start (point))
10506 (if (string-match "%file" rpl)
10507 (setq rpl (replace-match
10511 (abbreviate-file-name (read-file-name "Include file: ")))
10514 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10515 (concat "\n" ind)))
10517 (if (re-search-backward "\\?" start t) (delete-char 1))))
10520 (defun org-complete (&optional arg)
10521 "Perform completion on word at point.
10522 At the beginning of a headline, this completes TODO keywords as given in
10523 `org-todo-keywords'.
10524 If the current word is preceded by a backslash, completes the TeX symbols
10525 that are supported for HTML support.
10526 If the current word is preceded by \"#+\", completes special words for
10527 setting file options.
10528 In the line after \"#+STARTUP:, complete valid keywords.\"
10529 At all other locations, this simply calls the value of
10530 `org-completion-fallback-command'."
10532 (org-without-partial-completion
10536 (beg1 (save-excursion
10537 (skip-chars-backward (org-re "[:alnum:]_@"))
10539 (beg (save-excursion
10540 (skip-chars-backward "a-zA-Z0-9_:$")
10542 (confirm (lambda (x) (stringp (car x))))
10543 (searchhead (equal (char-before beg) ?*))
10545 (when (and (member (char-before beg1) '(?. ?<))
10546 (setq a (assoc (buffer-substring beg1 (point))
10547 org-structure-template-alist)))
10548 (org-complete-expand-structure-template (1- beg1) a)
10550 (tag (and (equal (char-before beg1) ?:)
10551 (equal (char-after (point-at-bol)) ?*)))
10552 (prop (and (equal (char-before beg1) ?:)
10553 (not (equal (char-after (point-at-bol)) ?*))))
10554 (texp (equal (char-before beg) ?\\))
10555 (link (equal (char-before beg) ?\[))
10556 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10559 (startup (string-match "^#\\+STARTUP:.*"
10560 (buffer-substring (point-at-bol) (point))))
10561 (completion-ignore-case opt)
10573 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10574 (cons (match-string 2 x)
10575 (match-string 1 x))))
10576 (org-split-string (org-get-current-options) "\n")))
10577 (mapcar 'list org-additional-option-like-keywords)))
10579 (setq type :startup)
10580 org-startup-options)
10581 (link (append org-link-abbrev-alist-local
10582 org-link-abbrev-alist))
10585 (append org-entities-user org-entities))
10586 ((string-match "\\`\\*+[ \t]+\\'"
10587 (buffer-substring (point-at-bol) beg))
10589 (mapcar 'list org-todo-keywords-1))
10591 (setq type :searchhead)
10593 (goto-char (point-min))
10594 (while (re-search-forward org-todo-line-regexp nil t)
10596 (org-make-org-heading-search-string
10597 (match-string 3) t))
10600 (tag (setq type :tag beg beg1)
10601 (or org-tag-alist (org-get-buffer-tags)))
10602 (prop (setq type :prop beg beg1)
10603 (mapcar 'list (org-buffer-property-keys nil t t)))
10605 (call-interactively org-completion-fallback-command)
10606 (throw 'exit nil)))))
10607 (pattern (buffer-substring-no-properties beg end))
10608 (completion (try-completion pattern table confirm)))
10609 (cond ((eq completion t)
10610 (if (not (assoc (upcase pattern) table))
10611 (message "Already complete")
10612 (if (and (equal type :opt)
10613 (not (member (car (assoc (upcase pattern) table))
10614 org-additional-option-like-keywords)))
10615 (insert (substring (cdr (assoc (upcase pattern) table))
10617 (if (memq type '(:tag :prop)) (insert ":")))))
10619 (message "Can't find completion for \"%s\"" pattern)
10621 ((not (string= pattern completion))
10622 (delete-region beg end)
10623 (if (string-match " +$" completion)
10624 (setq completion (replace-match "" t t completion)))
10625 (insert completion)
10626 (if (get-buffer-window "*Completions*")
10627 (delete-window (get-buffer-window "*Completions*")))
10628 (if (assoc completion table)
10629 (if (eq type :todo) (insert " ")
10630 (if (memq type '(:tag :prop)) (insert ":"))))
10631 (if (and (equal type :opt) (assoc completion table))
10632 (message "%s" (substitute-command-keys
10633 "Press \\[org-complete] again to insert example settings"))))
10635 (message "Making completion list...")
10636 (let ((list (sort (all-completions pattern table confirm)
10638 (with-output-to-temp-buffer "*Completions*"
10639 (condition-case nil
10640 ;; Protection needed for XEmacs and emacs 21
10641 (display-completion-list list pattern)
10642 (error (display-completion-list list)))))
10643 (message "Making completion list...%s" "done")))))))
10645 ;;;; TODO, DEADLINE, Comments
10647 (defun org-toggle-comment ()
10648 "Change the COMMENT state of an entry."
10651 (org-back-to-heading)
10652 (let (case-fold-search)
10653 (if (looking-at (concat outline-regexp
10654 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10655 (replace-match "" t t nil 1)
10656 (if (looking-at outline-regexp)
10658 (goto-char (match-end 0))
10659 (insert org-comment-string " ")))))))
10661 (defvar org-last-todo-state-is-todo nil
10662 "This is non-nil when the last TODO state change led to a TODO state.
10663 If the last change removed the TODO tag or switched to DONE, then
10666 (defvar org-setting-tags nil) ; dynamically skipped
10668 (defun org-parse-local-options (string var)
10669 "Parse STRING for startup setting relevant for variable VAR."
10670 (let ((rtn (symbol-value var))
10673 (if (or (not string) (not (string-match "\\S-" string)))
10675 (setq opts (delq nil (mapcar (lambda (x)
10676 (setq e (assoc x org-startup-options))
10677 (if (eq (nth 1 e) var) e nil))
10678 (org-split-string string "[ \t]+"))))
10682 (while (setq e (pop opts))
10683 (if (not (nth 3 e))
10684 (setq rtn (nth 2 e))
10685 (if (not (listp rtn)) (setq rtn nil))
10686 (push (nth 2 e) rtn)))
10689 (defvar org-todo-setup-filter-hook nil
10690 "Hook for functions that pre-filter todo specs.
10692 Each function takes a todo spec and returns either `nil' or the spec
10693 transformed into canonical form." )
10695 (defvar org-todo-get-default-hook nil
10696 "Hook for functions that get a default item for todo.
10698 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10699 `nil' or a string to be used for the todo mark." )
10701 (defvar org-agenda-headline-snapshot-before-repeat)
10703 (defun org-todo (&optional arg)
10704 "Change the TODO state of an item.
10705 The state of an item is given by a keyword at the start of the heading,
10707 *** TODO Write paper
10710 The different keywords are specified in the variable `org-todo-keywords'.
10711 By default the available states are \"TODO\" and \"DONE\".
10712 So for this example: when the item starts with TODO, it is changed to DONE.
10713 When it starts with DONE, the DONE is removed. And when neither TODO nor
10714 DONE are present, add TODO at the beginning of the heading.
10716 With C-u prefix arg, use completion to determine the new state.
10717 With numeric prefix arg, switch to that state.
10718 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
10719 With a triple C-u prefix, circumvent any state blocking.
10721 For calling through lisp, arg is also interpreted in the following way:
10722 'none -> empty state
10723 \"\"(empty string) -> switch to empty state
10724 'done -> switch to DONE
10725 'nextset -> switch to the next set of keywords
10726 'previousset -> switch to the previous set of keywords
10727 \"WAITING\" -> switch to the specified keyword, but only if it
10728 really is a member of `org-todo-keywords'."
10730 (if (equal arg '(16)) (setq arg 'nextset))
10731 (let ((org-blocker-hook org-blocker-hook)
10732 (case-fold-search nil))
10733 (when (equal arg '(64))
10734 (setq arg nil org-blocker-hook nil))
10735 (when (and org-blocker-hook
10736 (or org-inhibit-blocking
10737 (org-entry-get nil "NOBLOCKING")))
10738 (setq org-blocker-hook nil))
10741 (org-back-to-heading t)
10742 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10743 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10745 (let* ((match-data (match-data))
10746 (startpos (point-at-bol))
10747 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
10748 (org-log-done org-log-done)
10749 (org-log-repeat org-log-repeat)
10750 (org-todo-log-states org-todo-log-states)
10751 (this (match-string 1))
10752 (hl-pos (match-beginning 0))
10753 (head (org-get-todo-sequence-head this))
10754 (ass (assoc head org-todo-kwd-alist))
10755 (interpret (nth 1 ass))
10756 (done-word (nth 3 ass))
10757 (final-done-word (nth 4 ass))
10758 (last-state (or this ""))
10759 (completion-ignore-case t)
10760 (member (member this org-todo-keywords-1))
10761 (tail (cdr member))
10763 ((and org-todo-key-trigger
10764 (or (and (equal arg '(4))
10765 (eq org-use-fast-todo-selection 'prefix))
10766 (and (not arg) org-use-fast-todo-selection
10767 (not (eq org-use-fast-todo-selection
10769 ;; Use fast selection
10770 (org-fast-todo-selection))
10771 ((and (equal arg '(4))
10772 (or (not org-use-fast-todo-selection)
10773 (not org-todo-key-trigger)))
10774 ;; Read a state with completion
10775 (org-icompleting-read
10776 "State: " (mapcar (lambda(x) (list x))
10777 org-todo-keywords-1)
10781 (if tail (car tail) nil)
10782 (car org-todo-keywords-1)))
10784 (if (equal member org-todo-keywords-1)
10787 (nth (- (length org-todo-keywords-1)
10789 org-todo-keywords-1)
10790 (org-last org-todo-keywords-1))))
10791 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10792 (setq arg nil))) ; hack to fall back to cycling
10794 ;; user or caller requests a specific state
10796 ((equal arg "") nil)
10797 ((eq arg 'none) nil)
10798 ((eq arg 'done) (or done-word (car org-done-keywords)))
10800 (or (car (cdr (member head org-todo-heads)))
10801 (car org-todo-heads)))
10802 ((eq arg 'previousset)
10803 (let ((org-todo-heads (reverse org-todo-heads)))
10804 (or (car (cdr (member head org-todo-heads)))
10805 (car org-todo-heads))))
10806 ((car (member arg org-todo-keywords-1)))
10808 (error "State `%s' not valid in this file" arg))
10809 ((nth (1- (prefix-numeric-value arg))
10810 org-todo-keywords-1))))
10811 ((null member) (or head (car org-todo-keywords-1)))
10812 ((equal this final-done-word) nil) ;; -> make empty
10813 ((null tail) nil) ;; -> first entry
10814 ((memq interpret '(type priority))
10815 (if (eq this-command last-command)
10817 (if (> (length tail) 0)
10818 (or done-word (car org-done-keywords))
10823 (run-hook-with-args-until-success
10824 'org-todo-get-default-hook state last-state)
10826 (next (if state (concat " " state " ") " "))
10827 (change-plist (list :type 'todo-state-change :from this :to state
10828 :position startpos))
10830 (when org-blocker-hook
10831 (setq org-last-todo-state-is-todo
10832 (not (member this org-done-keywords)))
10833 (unless (save-excursion
10835 (run-hook-with-args-until-failure
10836 'org-blocker-hook change-plist)))
10837 (if (interactive-p)
10838 (error "TODO state change from %s to %s blocked" this state)
10840 (message "TODO state change from %s to %s blocked" this state)
10841 (throw 'exit nil))))
10842 (store-match-data match-data)
10843 (replace-match next t t)
10844 (unless (pos-visible-in-window-p hl-pos)
10845 (message "TODO state changed to %s" (org-trim next)))
10847 (setq head (org-get-todo-sequence-head state)
10848 ass (assoc head org-todo-kwd-alist)
10849 interpret (nth 1 ass)
10850 done-word (nth 3 ass)
10851 final-done-word (nth 4 ass)))
10852 (when (memq arg '(nextset previousset))
10853 (message "Keyword-Set %d/%d: %s"
10854 (- (length org-todo-sets) -1
10855 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10856 (length org-todo-sets)
10857 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10858 (setq org-last-todo-state-is-todo
10859 (not (member state org-done-keywords)))
10860 (setq now-done-p (and (member state org-done-keywords)
10861 (not (member this org-done-keywords))))
10862 (and logging (org-local-logging logging))
10863 (when (and (or org-todo-log-states org-log-done)
10864 (not (eq org-inhibit-logging t))
10865 (not (memq arg '(nextset previousset))))
10866 ;; we need to look at recording a time and note
10867 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10868 (nth 2 (assoc this org-todo-log-states))))
10869 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10870 (setq dolog 'time))
10872 (member state org-not-done-keywords)
10873 (not (member this org-not-done-keywords)))
10874 ;; This is now a todo state and was not one before
10875 ;; If there was a CLOSED time stamp, get rid of it.
10876 (org-add-planning-info nil nil 'closed))
10877 (when (and now-done-p org-log-done)
10878 ;; It is now done, and it was not done before
10879 (org-add-planning-info 'closed (org-current-time))
10880 (if (and (not dolog) (eq 'note org-log-done))
10881 (org-add-log-setup 'done state this 'findpos 'note)))
10882 (when (and state dolog)
10883 ;; This is a non-nil state, and we need to log it
10884 (org-add-log-setup 'state state this 'findpos dolog)))
10885 ;; Fixup tag positioning
10886 (org-todo-trigger-tag-changes state)
10887 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10888 (when org-provide-todo-statistics
10889 (org-update-parent-todo-statistics))
10890 (run-hooks 'org-after-todo-state-change-hook)
10891 (if (and arg (not (member state org-done-keywords)))
10892 (setq head (org-get-todo-sequence-head state)))
10893 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10894 ;; Do we need to trigger a repeat?
10896 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10897 ;; This is for the agenda, take a snapshot of the headline.
10899 (setq org-agenda-headline-snapshot-before-repeat
10900 (org-get-heading))))
10901 (org-auto-repeat-maybe state))
10902 ;; Fixup cursor location if close to the keyword
10903 (if (and (outline-on-heading-p)
10905 (save-excursion (beginning-of-line 1)
10906 (looking-at org-todo-line-regexp))
10907 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10909 (goto-char (or (match-end 2) (match-end 1)))
10910 (and (looking-at " ") (just-one-space))))
10911 (when org-trigger-hook
10913 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10915 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10916 "Block turning an entry into a TODO, using the hierarchy.
10917 This checks whether the current task should be blocked from state
10918 changes. Such blocking occurs when:
10920 1. The task has children which are not all in a completed state.
10922 2. A task has a parent with the property :ORDERED:, and there
10923 are siblings prior to the current task with incomplete
10926 3. The parent of the task is blocked because it has siblings that should
10927 be done first, or is child of a block grandparent TODO entry."
10929 (if (not org-enforce-todo-dependencies)
10930 t ; if locally turned off don't block
10932 ;; If this is not a todo state change, or if this entry is already DONE,
10934 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10935 (member (plist-get change-plist :from)
10936 (cons 'done org-done-keywords))
10937 (member (plist-get change-plist :to)
10938 (cons 'todo org-not-done-keywords))
10939 (not (plist-get change-plist :to)))
10940 (throw 'dont-block t))
10941 ;; If this task has children, and any are undone, it's blocked
10943 (org-back-to-heading t)
10944 (let ((this-level (funcall outline-level)))
10945 (outline-next-heading)
10946 (let ((child-level (funcall outline-level)))
10947 (while (and (not (eobp))
10948 (> child-level this-level))
10949 ;; this todo has children, check whether they are all
10951 (if (and (not (org-entry-is-done-p))
10952 (org-entry-is-todo-p))
10953 (throw 'dont-block nil))
10954 (outline-next-heading)
10955 (setq child-level (funcall outline-level))))))
10956 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10957 ;; any previous siblings are undone, it's blocked
10959 (org-back-to-heading t)
10960 (let* ((pos (point))
10961 (parent-pos (and (org-up-heading-safe) (point))))
10962 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10963 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10965 (re-search-forward org-not-done-heading-regexp pos t))
10966 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10967 ;; Search further up the hierarchy, to see if an anchestor is blocked
10969 (goto-char parent-pos)
10970 (if (not (looking-at org-not-done-heading-regexp))
10971 (throw 'dont-block t)) ; do not block, parent is not a TODO
10973 (setq parent-pos (and (org-up-heading-safe) (point)))
10974 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10975 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10977 (re-search-forward org-not-done-heading-regexp pos t))
10978 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10980 (defcustom org-track-ordered-property-with-tag nil
10981 "Should the ORDERED property also be shown as a tag?
10982 The ORDERED property decides if an entry should require subtasks to be
10983 completed in sequence. Since a property is not very visible, setting
10984 this option means that toggling the ORDERED property with the command
10985 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10986 not relevant for the behavior, but it makes things more visible.
10988 Note that toggling the tag with tags commands will not change the property
10989 and therefore not influence behavior!
10991 This can be t, meaning the tag ORDERED should be used, It can also be a
10992 string to select a different tag for this task."
10995 (const :tag "No tracking" nil)
10996 (const :tag "Track with ORDERED tag" t)
10997 (string :tag "Use other tag")))
10999 (defun org-toggle-ordered-property ()
11000 "Toggle the ORDERED property of the current entry.
11001 For better visibility, you can track the value of this property with a tag.
11002 See variable `org-track-ordered-property-with-tag'."
11004 (let* ((t1 org-track-ordered-property-with-tag)
11005 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
11007 (org-back-to-heading)
11008 (if (org-entry-get nil "ORDERED")
11010 (org-delete-property "ORDERED")
11011 (and tag (org-toggle-tag tag 'off))
11012 (message "Subtasks can be completed in arbitrary order"))
11013 (org-entry-put nil "ORDERED" "t")
11014 (and tag (org-toggle-tag tag 'on))
11015 (message "Subtasks must be completed in sequence")))))
11017 (defvar org-blocked-by-checkboxes) ; dynamically scoped
11018 (defun org-block-todo-from-checkboxes (change-plist)
11019 "Block turning an entry into a TODO, using checkboxes.
11020 This checks whether the current task should be blocked from state
11021 changes because there are unchecked boxes in this entry."
11022 (if (not org-enforce-todo-checkbox-dependencies)
11023 t ; if locally turned off don't block
11025 ;; If this is not a todo state change, or if this entry is already DONE,
11027 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
11028 (member (plist-get change-plist :from)
11029 (cons 'done org-done-keywords))
11030 (member (plist-get change-plist :to)
11031 (cons 'todo org-not-done-keywords))
11032 (not (plist-get change-plist :to)))
11033 (throw 'dont-block t))
11034 ;; If this task has checkboxes that are not checked, it's blocked
11036 (org-back-to-heading t)
11037 (let ((beg (point)) end)
11038 (outline-next-heading)
11041 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
11044 (if (boundp 'org-blocked-by-checkboxes)
11045 (setq org-blocked-by-checkboxes t))
11046 (throw 'dont-block nil)))))
11047 t))) ; do not block
11049 (defun org-entry-blocked-p ()
11050 "Is the current entry blocked?"
11051 (if (org-entry-get nil "NOBLOCKING")
11052 nil ;; Never block this entry
11054 (run-hook-with-args-until-failure
11056 (list :type 'todo-state-change
11061 (defun org-update-statistics-cookies (all)
11062 "Update the statistics cookie, either from TODO or from checkboxes.
11063 This should be called with the cursor in a line with a statistics cookie."
11067 (org-update-checkbox-count 'all)
11068 (org-map-entries 'org-update-parent-todo-statistics))
11069 (if (not (org-on-heading-p))
11070 (org-update-checkbox-count)
11071 (let ((pos (move-marker (make-marker) (point)))
11073 (ignore-errors (org-back-to-heading t))
11074 (if (not (org-on-heading-p))
11075 (org-update-checkbox-count)
11076 (setq l1 (org-outline-level))
11077 (setq end (save-excursion
11078 (outline-next-heading)
11079 (if (org-on-heading-p) (setq l2 (org-outline-level)))
11081 (if (and (save-excursion
11083 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11084 (not (save-excursion (re-search-forward
11085 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11086 (org-update-checkbox-count)
11087 (if (and l2 (> l2 l1))
11090 (org-update-parent-todo-statistics))
11092 (beginning-of-line 1)
11093 (while (re-search-forward
11094 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11096 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11098 (move-marker pos nil)))))
11100 (defvar org-entry-property-inherited-from) ;; defined below
11101 (defun org-update-parent-todo-statistics ()
11102 "Update any statistics cookie in the parent of the current headline.
11103 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11104 the entire subtree and this will travel up the hierarchy and update
11105 statistics everywhere."
11107 (let* ((lim 0) prop
11108 (recursive (or (not org-hierarchical-todo-statistics)
11111 (or (setq prop (org-entry-get
11112 nil "COOKIE_DATA" 'inherit)) ""))))
11113 (lim (or (and prop (marker-position
11114 org-entry-property-inherited-from))
11117 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11118 level ltoggle l1 new ndel
11119 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
11122 (beginning-of-line 1)
11123 (if (org-at-heading-p)
11124 (setq ltoggle (funcall outline-level))
11125 (error "This should not happen"))
11126 (while (and (setq level (org-up-heading-safe))
11127 (or recursive first)
11129 (setq first nil cookie-present nil)
11138 (while (re-search-forward box-re (point-at-eol) t)
11139 (setq cnt-all 0 cnt-done 0 cookie-present t)
11140 (setq is-percent (match-end 2))
11142 (unless (outline-next-heading) (throw 'exit nil))
11143 (while (and (looking-at org-complex-heading-regexp)
11144 (> (setq l1 (length (match-string 1))) level))
11145 (setq kwd (and (or recursive (= l1 ltoggle))
11147 (if (or (eq org-provide-todo-statistics 'all-headlines)
11148 (and (listp org-provide-todo-statistics)
11149 (or (member kwd org-provide-todo-statistics)
11150 (member kwd org-done-keywords))))
11151 (setq cnt-all (1+ cnt-all))
11152 (if (eq org-provide-todo-statistics t)
11153 (and kwd (setq cnt-all (1+ cnt-all)))))
11154 (and (member kwd org-done-keywords)
11155 (setq cnt-done (1+ cnt-done)))
11156 (outline-next-heading)))
11159 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
11160 (format "[%d/%d]" cnt-done cnt-all))
11161 ndel (- (match-end 0) (match-beginning 0)))
11162 (goto-char (match-beginning 0))
11164 (delete-region (point) (+ (point) ndel)))
11165 (when cookie-present
11166 (run-hook-with-args 'org-after-todo-statistics-hook
11167 cnt-done (- cnt-all cnt-done))))))
11168 (run-hooks 'org-todo-statistics-hook)))
11170 (defvar org-after-todo-statistics-hook nil
11171 "Hook that is called after a TODO statistics cookie has been updated.
11172 Each function is called with two arguments: the number of not-done entries
11173 and the number of done entries.
11175 For example, the following function, when added to this hook, will switch
11176 an entry to DONE when all children are done, and back to TODO when new
11177 entries are set to a TODO status. Note that this hook is only called
11178 when there is a statistics cookie in the headline!
11180 (defun org-summary-todo (n-done n-not-done)
11181 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
11182 (let (org-log-done org-log-states) ; turn off logging
11183 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
11186 (defvar org-todo-statistics-hook nil
11187 "Hook that is run whenever Org thinks TODO statistics should be updated.
11188 This hook runs even if there is no statistics cookie present, in which case
11189 `org-after-todo-statistics-hook' would not run.")
11191 (defun org-todo-trigger-tag-changes (state)
11192 "Apply the changes defined in `org-todo-state-tags-triggers'."
11193 (let ((l org-todo-state-tags-triggers)
11195 (when (or (not state) (equal state ""))
11196 (setq changes (append changes (cdr (assoc "" l)))))
11197 (when (and (stringp state) (> (length state) 0))
11198 (setq changes (append changes (cdr (assoc state l)))))
11199 (when (member state org-not-done-keywords)
11200 (setq changes (append changes (cdr (assoc 'todo l)))))
11201 (when (member state org-done-keywords)
11202 (setq changes (append changes (cdr (assoc 'done l)))))
11203 (dolist (c changes)
11204 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
11206 (defun org-local-logging (value)
11207 "Get logging settings from a property VALUE."
11209 ;; directly set the variables, they are already local.
11210 (setq org-log-done nil
11212 org-todo-log-states nil)
11213 (setq words (org-split-string value))
11214 (while (setq w (pop words))
11216 ((setq a (assoc w org-startup-options))
11217 (and (member (nth 1 a) '(org-log-done org-log-repeat))
11218 (set (nth 1 a) (nth 2 a))))
11219 ((setq a (org-extract-log-state-settings w))
11220 (and (member (car a) org-todo-keywords-1)
11221 (push a org-todo-log-states)))))))
11223 (defun org-get-todo-sequence-head (kwd)
11224 "Return the head of the TODO sequence to which KWD belongs.
11225 If KWD is not set, check if there is a text property remembering the
11230 (or (get-text-property (point-at-bol) 'org-todo-head)
11232 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
11233 nil (point-at-eol)))
11234 (get-text-property p 'org-todo-head))))
11235 ((not (member kwd org-todo-keywords-1))
11236 (car org-todo-keywords-1))
11237 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
11239 (defun org-fast-todo-selection ()
11240 "Fast TODO keyword selection with single keys.
11241 Returns the new TODO keyword, or nil if no state change should occur."
11242 (let* ((fulltable org-todo-key-alist)
11243 (done-keywords org-done-keywords) ;; needed for the faces.
11244 (maxlen (apply 'max (mapcar
11246 (if (stringp (car x)) (string-width (car x)) 0))
11249 (fwidth (+ maxlen 3 1 3))
11250 (ncol (/ (- (window-width) 4) fwidth))
11254 (save-window-excursion
11256 (set-buffer (get-buffer-create " *Org todo*"))
11257 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
11259 (org-set-local 'org-done-keywords done-keywords)
11260 (setq tbl fulltable cnt 0)
11261 (while (setq e (pop tbl))
11263 ((equal e '(:startgroup))
11264 (push '() groups) (setq ingroup t)
11265 (when (not (= cnt 0))
11269 ((equal e '(:endgroup))
11270 (setq ingroup nil cnt 0)
11272 ((equal e '(:newline))
11273 (when (not (= cnt 0))
11277 (while (equal (car tbl) '(:newline))
11279 (setq tbl (cdr tbl)))))
11281 (setq tg (car e) c (cdr e))
11282 (if ingroup (push tg (car groups)))
11283 (setq tg (org-add-props tg nil 'face
11284 (org-get-todo-face tg)))
11285 (if (and (= cnt 0) (not ingroup)) (insert " "))
11286 (insert "[" c "] " tg (make-string
11287 (- fwidth 4 (length tg)) ?\ ))
11288 (when (= (setq cnt (1+ cnt)) ncol)
11290 (if ingroup (insert " "))
11293 (goto-char (point-min))
11294 (if (not expert) (org-fit-window-to-buffer))
11295 (message "[a-z..]:Set [SPC]:clear")
11296 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
11299 (and (= c ?q) (not (rassoc c fulltable))))
11300 (setq quit-flag t))
11302 ((setq e (rassoc c fulltable) tg (car e))
11304 (t (setq quit-flag t)))))))
11306 (defun org-entry-is-todo-p ()
11307 (member (org-get-todo-state) org-not-done-keywords))
11309 (defun org-entry-is-done-p ()
11310 (member (org-get-todo-state) org-done-keywords))
11312 (defun org-get-todo-state ()
11314 (org-back-to-heading t)
11315 (and (looking-at org-todo-line-regexp)
11317 (match-string 2))))
11319 (defun org-at-date-range-p (&optional inactive-ok)
11320 "Is the cursor inside a date range?"
11324 (let ((pos (point)))
11325 (skip-chars-backward "^[<\r\n")
11326 (skip-chars-backward "<[")
11327 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11328 (>= (match-end 0) pos)
11330 (skip-chars-backward "^<[\r\n")
11331 (skip-chars-backward "<[")
11332 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11333 (>= (match-end 0) pos)
11337 (defun org-get-repeat (&optional tagline)
11338 "Check if there is a deadline/schedule with repeater in this entry."
11341 (org-back-to-heading t)
11342 (and (re-search-forward (if tagline
11343 (concat tagline "\\s-*" org-repeat-re)
11345 (org-entry-end-position) t)
11346 (match-string-no-properties 1)))))
11348 (defvar org-last-changed-timestamp)
11349 (defvar org-last-inserted-timestamp)
11350 (defvar org-log-post-message)
11351 (defvar org-log-note-purpose)
11352 (defvar org-log-note-how)
11353 (defvar org-log-note-extra)
11354 (defun org-auto-repeat-maybe (done-word)
11355 "Check if the current headline contains a repeated deadline/schedule.
11356 If yes, set TODO state back to what it was and change the base date
11357 of repeating deadline/scheduled time stamps to new date.
11358 This function is run automatically after each state change to a DONE state."
11359 ;; last-state is dynamically scoped into this function
11360 (let* ((repeat (org-get-repeat))
11361 (aa (assoc last-state org-todo-kwd-alist))
11362 (interpret (nth 1 aa))
11364 (whata '(("d" . day) ("m" . month) ("y" . year)))
11365 (msg "Entry repeats: ")
11367 (org-todo-log-states nil)
11368 (nshiftmax 10) (nshift 0)
11369 re type n what ts time to-state)
11371 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
11372 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
11373 org-todo-repeat-to-state))
11374 (unless (and to-state (member to-state org-todo-keywords-1))
11375 (setq to-state (if (eq interpret 'type) last-state head)))
11376 (org-todo to-state)
11377 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
11378 (org-entry-put nil "LAST_REPEAT" (format-time-string
11379 (org-time-stamp-format t t))))
11380 (when org-log-repeat
11381 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
11382 (memq 'org-add-log-note post-command-hook))
11383 ;; OK, we are already setup for some record
11384 (if (eq org-log-repeat 'note)
11385 ;; make sure we take a note, not only a time stamp
11386 (setq org-log-note-how 'note))
11387 ;; Set up for taking a record
11388 (org-add-log-setup 'state (or done-word (car org-done-keywords))
11390 'findpos org-log-repeat)))
11391 (org-back-to-heading t)
11392 (org-add-planning-info nil nil 'closed)
11393 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
11394 org-deadline-time-regexp "\\)\\|\\("
11395 org-ts-regexp "\\)"))
11396 (while (re-search-forward
11397 re (save-excursion (outline-next-heading) (point)) t)
11398 (setq type (if (match-end 1) org-scheduled-string
11399 (if (match-end 3) org-deadline-string "Plain:"))
11400 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
11401 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
11402 (setq n (string-to-number (match-string 2 ts))
11403 what (match-string 3 ts))
11404 (if (equal what "w") (setq n (* n 7) what "d"))
11405 ;; Preparation, see if we need to modify the start date for the change
11406 (when (match-end 1)
11407 (setq time (save-match-data (org-time-string-to-time ts)))
11409 ((equal (match-string 1 ts) ".")
11410 ;; Shift starting date to today
11411 (org-timestamp-change
11412 (- (time-to-days (current-time)) (time-to-days time))
11414 ((equal (match-string 1 ts) "+")
11415 (while (or (= nshift 0)
11416 (<= (time-to-days time) (time-to-days (current-time))))
11417 (when (= (incf nshift) nshiftmax)
11418 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
11420 (org-timestamp-change n (cdr (assoc what whata)))
11421 (org-at-timestamp-p t)
11422 (setq ts (match-string 1))
11423 (setq time (save-match-data (org-time-string-to-time ts))))
11424 (org-timestamp-change (- n) (cdr (assoc what whata)))
11425 ;; rematch, so that we have everything in place for the real shift
11426 (org-at-timestamp-p t)
11427 (setq ts (match-string 1))
11428 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
11429 (org-timestamp-change n (cdr (assoc what whata)))
11430 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
11431 (setq org-log-post-message msg)
11432 (message "%s" msg))))
11434 (defun org-show-todo-tree (arg)
11435 "Make a compact tree which shows all headlines marked with TODO.
11436 The tree will show the lines where the regexp matches, and all higher
11437 headlines above the match.
11438 With a \\[universal-argument] prefix, prompt for a regexp to match.
11439 With a numeric prefix N, construct a sparse tree for the Nth element
11440 of `org-todo-keywords-1'."
11442 (let ((case-fold-search nil)
11444 (cond ((null arg) org-not-done-regexp)
11446 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
11447 (mapcar 'list org-todo-keywords-1))))
11449 (mapconcat 'identity (org-split-string kwd "|") "\\|")
11451 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
11452 (regexp-quote (nth (1- (prefix-numeric-value arg))
11453 org-todo-keywords-1)))
11454 (t (error "Invalid prefix argument: %s" arg)))))
11455 (message "%d TODO entries found"
11456 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
11458 (defun org-deadline (&optional remove time)
11459 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
11460 With argument REMOVE, remove any deadline from the item.
11461 When TIME is set, it should be an internal time specification, and the
11462 scheduling will use the corresponding date."
11464 (let* ((old-date (org-entry-get nil "DEADLINE"))
11465 (repeater (and old-date
11466 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11467 (match-string 1 old-date))))
11470 (when (and old-date org-log-redeadline)
11471 (org-add-log-setup 'deldeadline nil old-date 'findpos
11472 org-log-redeadline))
11473 (org-remove-timestamp-with-keyword org-deadline-string)
11474 (message "Item no longer has a deadline."))
11475 (org-add-planning-info 'deadline time 'closed)
11476 (when (and old-date org-log-redeadline
11477 (not (equal old-date
11478 (substring org-last-inserted-timestamp 1 -1))))
11479 (org-add-log-setup 'redeadline nil old-date 'findpos
11480 org-log-redeadline))
11483 (org-back-to-heading t)
11484 (when (re-search-forward (concat org-deadline-string " "
11485 org-last-inserted-timestamp)
11487 (outline-next-heading) (point)) t)
11488 (goto-char (1- (match-end 0)))
11489 (insert " " repeater)
11490 (setq org-last-inserted-timestamp
11491 (concat (substring org-last-inserted-timestamp 0 -1)
11493 (substring org-last-inserted-timestamp -1))))))
11494 (message "Deadline on %s" org-last-inserted-timestamp))))
11496 (defun org-schedule (&optional remove time)
11497 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11498 With argument REMOVE, remove any scheduling date from the item.
11499 When TIME is set, it should be an internal time specification, and the
11500 scheduling will use the corresponding date."
11502 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11503 (repeater (and old-date
11504 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11505 (match-string 1 old-date))))
11508 (when (and old-date org-log-reschedule)
11509 (org-add-log-setup 'delschedule nil old-date 'findpos
11510 org-log-reschedule))
11511 (org-remove-timestamp-with-keyword org-scheduled-string)
11512 (message "Item is no longer scheduled."))
11513 (org-add-planning-info 'scheduled time 'closed)
11514 (when (and old-date org-log-reschedule
11515 (not (equal old-date
11516 (substring org-last-inserted-timestamp 1 -1))))
11517 (org-add-log-setup 'reschedule nil old-date 'findpos
11518 org-log-reschedule))
11521 (org-back-to-heading t)
11522 (when (re-search-forward (concat org-scheduled-string " "
11523 org-last-inserted-timestamp)
11525 (outline-next-heading) (point)) t)
11526 (goto-char (1- (match-end 0)))
11527 (insert " " repeater)
11528 (setq org-last-inserted-timestamp
11529 (concat (substring org-last-inserted-timestamp 0 -1)
11531 (substring org-last-inserted-timestamp -1))))))
11532 (message "Scheduled to %s" org-last-inserted-timestamp))))
11534 (defun org-get-scheduled-time (pom &optional inherit)
11535 "Get the scheduled time as a time tuple, of a format suitable
11536 for calling org-schedule with, or if there is no scheduling,
11538 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11540 (apply 'encode-time (org-parse-time-string time)))))
11542 (defun org-get-deadline-time (pom &optional inherit)
11543 "Get the deadine as a time tuple, of a format suitable for
11544 calling org-deadline with, or if there is no scheduling, returns
11546 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11548 (apply 'encode-time (org-parse-time-string time)))))
11550 (defun org-remove-timestamp-with-keyword (keyword)
11551 "Remove all time stamps with KEYWORD in the current entry."
11552 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11555 (org-back-to-heading t)
11557 (outline-next-heading)
11558 (while (re-search-backward re beg t)
11560 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11561 (equal (char-before) ?\ ))
11562 (backward-delete-char 1)
11563 (if (string-match "^[ \t]*$" (buffer-substring
11564 (point-at-bol) (point-at-eol)))
11565 (delete-region (point-at-bol)
11566 (min (point-max) (1+ (point-at-eol))))))))))
11568 (defun org-add-planning-info (what &optional time &rest remove)
11569 "Insert new timestamp with keyword in the line directly after the headline.
11570 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11571 If non is given, the user is prompted for a date.
11572 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11575 (let (org-time-was-given org-end-time-was-given ts
11576 end default-time default-input)
11579 (when (and (not time) (memq what '(scheduled deadline)))
11580 ;; Try to get a default date/time from existing timestamp
11582 (org-back-to-heading t)
11583 (setq end (save-excursion (outline-next-heading) (point)))
11584 (when (re-search-forward (if (eq what 'scheduled)
11585 org-scheduled-time-regexp
11586 org-deadline-time-regexp)
11588 (setq ts (match-string 1)
11590 (apply 'encode-time (org-parse-time-string ts))
11591 default-input (and ts (org-get-compact-tod ts))))))
11593 ;; If necessary, get the time from the user
11594 (setq time (or time (org-read-date nil 'to-time nil nil
11595 default-time default-input))))
11597 (when (and org-insert-labeled-timestamps-at-point
11598 (member what '(scheduled deadline)))
11600 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11601 (org-insert-time-stamp time org-time-was-given
11602 nil nil nil (list org-end-time-was-given))
11606 (let (col list elt ts buffer-invisibility-spec)
11607 (org-back-to-heading t)
11608 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11609 (goto-char (match-end 1))
11610 (setq col (current-column))
11611 (goto-char (match-end 0))
11612 (if (eobp) (insert "\n") (forward-char 1))
11613 (when (and (not what)
11616 org-keyword-time-not-clock-regexp))))
11617 ;; Nothing to add, nothing to remove...... :-)
11619 (if (and (not (looking-at outline-regexp))
11620 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11622 (not (equal (match-string 1) org-clock-string)))
11623 (narrow-to-region (match-beginning 0) (match-end 0))
11624 (insert-before-markers "\n")
11626 (narrow-to-region (point) (point))
11627 (and org-adapt-indentation (org-indent-to-column col)))
11628 ;; Check if we have to remove something.
11629 (setq list (cons what remove))
11631 (setq elt (pop list))
11632 (goto-char (point-min))
11633 (when (or (and (eq elt 'scheduled)
11634 (re-search-forward org-scheduled-time-regexp nil t))
11635 (and (eq elt 'deadline)
11636 (re-search-forward org-deadline-time-regexp nil t))
11637 (and (eq elt 'closed)
11638 (re-search-forward org-closed-time-regexp nil t)))
11640 (if (looking-at "--+<[^>]+>") (replace-match ""))
11641 (skip-chars-backward " ")
11642 (if (looking-at " +") (replace-match ""))))
11643 (goto-char (point-max))
11644 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11647 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11648 (cond ((eq what 'scheduled) org-scheduled-string)
11649 ((eq what 'deadline) org-deadline-string)
11650 ((eq what 'closed) org-closed-string))
11652 (setq ts (org-insert-time-stamp
11654 (or org-time-was-given
11655 (and (eq what 'closed) org-log-done-with-time))
11657 nil nil (list org-end-time-was-given)))
11659 (goto-char (point-min))
11661 (if (and (looking-at "[ \t]*\n")
11662 (equal (char-before) ?\n))
11663 (delete-region (1- (point)) (point-at-eol)))
11666 (defvar org-log-note-marker (make-marker))
11667 (defvar org-log-note-purpose nil)
11668 (defvar org-log-note-state nil)
11669 (defvar org-log-note-previous-state nil)
11670 (defvar org-log-note-how nil)
11671 (defvar org-log-note-extra nil)
11672 (defvar org-log-note-window-configuration nil)
11673 (defvar org-log-note-return-to (make-marker))
11674 (defvar org-log-post-message nil
11675 "Message to be displayed after a log note has been stored.
11676 The auto-repeater uses this.")
11678 (defun org-add-note ()
11679 "Add a note to the current entry.
11680 This is done in the same way as adding a state change note."
11682 (org-add-log-setup 'note nil nil 'findpos nil))
11684 (defvar org-property-end-re)
11685 (defun org-add-log-setup (&optional purpose state prev-state
11686 findpos how &optional extra)
11687 "Set up the post command hook to take a note.
11688 If this is about to TODO state change, the new state is expected in STATE.
11689 When FINDPOS is non-nil, find the correct position for the note in
11690 the current entry. If not, assume that it can be inserted at point.
11691 HOW is an indicator what kind of note should be created.
11692 EXTRA is additional text that will be inserted into the notes buffer."
11693 (let* ((org-log-into-drawer (org-log-into-drawer))
11694 (drawer (cond ((stringp org-log-into-drawer)
11695 org-log-into-drawer)
11696 (org-log-into-drawer "LOGBOOK")
11701 (org-back-to-heading t)
11702 (narrow-to-region (point) (save-excursion
11703 (outline-next-heading) (point)))
11704 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11705 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11707 (goto-char (match-end 0))
11710 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11713 (goto-char (match-end 0))
11714 (or org-log-states-order-reversed
11715 (and (re-search-forward org-property-end-re nil t)
11716 (goto-char (1- (match-beginning 0))))))
11717 (insert "\n:" drawer ":\n:END:")
11718 (beginning-of-line 0)
11719 (org-indent-line-function)
11720 (beginning-of-line 2)
11721 (org-indent-line-function)
11723 ((and org-log-state-notes-insert-after-drawers
11725 (forward-line) (looking-at org-drawer-regexp)))
11727 (while (looking-at org-drawer-regexp)
11728 (goto-char (match-end 0))
11729 (re-search-forward org-property-end-re (point-max) t)
11731 (forward-line -1)))
11732 (unless org-log-states-order-reversed
11733 (and (= (char-after) ?\n) (forward-char 1))
11734 (org-skip-over-state-notes)
11735 (skip-chars-backward " \t\n\r")))
11736 (move-marker org-log-note-marker (point))
11737 (setq org-log-note-purpose purpose
11738 org-log-note-state state
11739 org-log-note-previous-state prev-state
11740 org-log-note-how how
11741 org-log-note-extra extra)
11742 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11744 (defun org-skip-over-state-notes ()
11745 "Skip past the list of State notes in an entry."
11746 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11747 (while (looking-at "[ \t]*- State")
11748 (condition-case nil
11750 (error (org-end-of-item)))))
11752 (defun org-add-log-note (&optional purpose)
11753 "Pop up a window for taking a note, and add this note later at point."
11754 (remove-hook 'post-command-hook 'org-add-log-note)
11755 (setq org-log-note-window-configuration (current-window-configuration))
11756 (delete-other-windows)
11757 (move-marker org-log-note-return-to (point))
11758 (switch-to-buffer (marker-buffer org-log-note-marker))
11759 (goto-char org-log-note-marker)
11760 (org-switch-to-buffer-other-window "*Org Note*")
11762 (if (memq org-log-note-how '(time state))
11763 (let (current-prefix-arg) (org-store-log-note))
11764 (let ((org-inhibit-startup t)) (org-mode))
11765 (insert (format "# Insert note for %s.
11766 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11768 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11769 ((eq org-log-note-purpose 'done) "closed todo item")
11770 ((eq org-log-note-purpose 'state)
11771 (format "state change from \"%s\" to \"%s\""
11772 (or org-log-note-previous-state "")
11773 (or org-log-note-state "")))
11774 ((eq org-log-note-purpose 'reschedule)
11776 ((eq org-log-note-purpose 'delschedule)
11777 "no longer scheduled")
11778 ((eq org-log-note-purpose 'redeadline)
11779 "changing deadline")
11780 ((eq org-log-note-purpose 'deldeadline)
11781 "removing deadline")
11782 ((eq org-log-note-purpose 'refile)
11784 ((eq org-log-note-purpose 'note)
11786 (t (error "This should not happen")))))
11787 (if org-log-note-extra (insert org-log-note-extra))
11788 (org-set-local 'org-finish-function 'org-store-log-note)))
11790 (defvar org-note-abort nil) ; dynamically scoped
11791 (defun org-store-log-note ()
11792 "Finish taking a log note, and insert it to where it belongs."
11793 (let ((txt (buffer-string))
11794 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11796 (kill-buffer (current-buffer))
11797 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11798 (setq txt (replace-match "" t t txt)))
11799 (if (string-match "\\s-+\\'" txt)
11800 (setq txt (replace-match "" t t txt)))
11801 (setq lines (org-split-string txt "\n"))
11802 (when (and note (string-match "\\S-" note))
11804 (org-replace-escapes
11806 (list (cons "%u" (user-login-name))
11807 (cons "%U" user-full-name)
11808 (cons "%t" (format-time-string
11809 (org-time-stamp-format 'long 'inactive)
11811 (cons "%T" (format-time-string
11812 (org-time-stamp-format 'long nil)
11814 (cons "%s" (if org-log-note-state
11815 (concat "\"" org-log-note-state "\"")
11817 (cons "%S" (if org-log-note-previous-state
11818 (concat "\"" org-log-note-previous-state "\"")
11820 (if lines (setq note (concat note " \\\\")))
11822 (when (or current-prefix-arg org-note-abort)
11823 (when org-log-into-drawer
11824 (org-remove-empty-drawer-at
11825 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11826 org-log-note-marker))
11829 (with-current-buffer (marker-buffer org-log-note-marker)
11831 (goto-char org-log-note-marker)
11832 (move-marker org-log-note-marker nil)
11834 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11835 (insert "- " (pop lines))
11836 (org-indent-line-function)
11837 (beginning-of-line 1)
11838 (looking-at "[ \t]*")
11839 (setq ind (concat (match-string 0) " "))
11841 (while lines (insert "\n" ind (pop lines)))
11842 (message "Note stored")
11843 (org-back-to-heading t)
11844 (org-cycle-hide-drawers 'children)))))
11845 (set-window-configuration org-log-note-window-configuration)
11846 (with-current-buffer (marker-buffer org-log-note-return-to)
11847 (goto-char org-log-note-return-to))
11848 (move-marker org-log-note-return-to nil)
11849 (and org-log-post-message (message "%s" org-log-post-message)))
11851 (defun org-remove-empty-drawer-at (drawer pos)
11852 "Remove an empty drawer DRAWER at position POS.
11853 POS may also be a marker."
11854 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11860 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11861 (replace-match ""))))))
11863 (defun org-sparse-tree (&optional arg)
11864 "Create a sparse tree, prompt for the details.
11865 This command can create sparse trees. You first need to select the type
11866 of match used to create the tree:
11868 t Show all TODO entries.
11869 T Show entries with a specific TODO keyword.
11870 m Show entries selected by a tags/property match.
11871 p Enter a property name and its value (both with completion on existing
11872 names/values) and show entries with that property.
11873 / Show entries matching a regular expression (`r' can be used as well)
11874 d Show deadlines due within `org-deadline-warning-days'.
11875 b Show deadlines and scheduled items before a date.
11876 a Show deadlines and scheduled items after a date."
11878 (let (ans kwd value)
11879 (message "Sparse tree: [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty [d]eadlines\n [b]efore-date [a]fter-date")
11880 (setq ans (read-char-exclusive))
11883 (call-interactively 'org-check-deadlines))
11885 (call-interactively 'org-check-before-date))
11887 (call-interactively 'org-check-after-date))
11889 (org-show-todo-tree nil))
11891 (org-show-todo-tree '(4)))
11892 ((member ans '(?T ?m))
11893 (call-interactively 'org-match-sparse-tree))
11894 ((member ans '(?p ?P))
11895 (setq kwd (org-icompleting-read "Property: "
11896 (mapcar 'list (org-buffer-property-keys))))
11897 (setq value (org-icompleting-read "Value: "
11898 (mapcar 'list (org-property-values kwd))))
11899 (unless (string-match "\\`{.*}\\'" value)
11900 (setq value (concat "\"" value "\"")))
11901 (org-match-sparse-tree arg (concat kwd "=" value)))
11902 ((member ans '(?r ?R ?/))
11903 (call-interactively 'org-occur))
11904 (t (error "No such sparse tree command \"%c\"" ans)))))
11906 (defvar org-occur-highlights nil
11907 "List of overlays used for occur matches.")
11908 (make-variable-buffer-local 'org-occur-highlights)
11909 (defvar org-occur-parameters nil
11910 "Parameters of the active org-occur calls.
11911 This is a list, each call to org-occur pushes as cons cell,
11912 containing the regular expression and the callback, onto the list.
11913 The list can contain several entries if `org-occur' has been called
11914 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11915 will only contain one set of parameters. When the highlights are
11916 removed (for example with `C-c C-c', or with the next edit (depending
11917 on `org-remove-highlights-with-change'), this variable is emptied
11919 (make-variable-buffer-local 'org-occur-parameters)
11921 (defun org-occur (regexp &optional keep-previous callback)
11922 "Make a compact tree which shows all matches of REGEXP.
11923 The tree will show the lines where the regexp matches, and all higher
11924 headlines above the match. It will also show the heading after the match,
11925 to make sure editing the matching entry is easy.
11926 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11927 call to `org-occur' will be kept, to allow stacking of calls to this
11929 If CALLBACK is non-nil, it is a function which is called to confirm
11930 that the match should indeed be shown."
11931 (interactive "sRegexp: \nP")
11932 (when (equal regexp "")
11933 (error "Regexp cannot be empty"))
11934 (unless keep-previous
11935 (org-remove-occur-highlights nil nil t))
11936 (push (cons regexp callback) org-occur-parameters)
11939 (goto-char (point-min))
11940 (if (or (not keep-previous) ; do not want to keep
11941 (not org-occur-highlights)) ; no previous matches
11944 (while (re-search-forward regexp nil t)
11945 (when (or (not callback)
11946 (save-match-data (funcall callback)))
11947 (setq cnt (1+ cnt))
11948 (when org-highlight-sparse-tree-matches
11949 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11950 (org-show-context 'occur-tree))))
11951 (when org-remove-highlights-with-change
11952 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11954 (unless org-sparse-tree-open-archived-trees
11955 (org-hide-archived-subtrees (point-min) (point-max)))
11956 (run-hooks 'org-occur-hook)
11957 (if (interactive-p)
11958 (message "%d match(es) for regexp %s" cnt regexp))
11961 (defun org-show-context (&optional key)
11962 "Make sure point and context are visible.
11963 How much context is shown depends upon the variables
11964 `org-show-hierarchy-above', `org-show-following-heading'. and
11965 `org-show-siblings'."
11966 (let ((heading-p (org-on-heading-p t))
11967 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11968 (following-p (org-get-alist-option org-show-following-heading key))
11969 (entry-p (org-get-alist-option org-show-entry-below key))
11970 (siblings-p (org-get-alist-option org-show-siblings key)))
11972 ;; Show heading or entry text
11973 (if (and heading-p (not entry-p))
11974 (org-flag-heading nil) ; only show the heading
11975 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11976 (org-show-hidden-entry))) ; show entire entry
11978 ;; Show next sibling, or heading below text
11980 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11981 (org-flag-heading nil))))
11982 (when siblings-p (org-show-siblings))
11984 ;; show all higher headings, possibly with siblings
11986 (while (and (condition-case nil
11987 (progn (org-up-heading-all 1) t)
11990 (org-flag-heading nil)
11991 (when siblings-p (org-show-siblings))))))))
11993 (defvar org-reveal-start-hook nil
11994 "Hook run before revealing a location.")
11996 (defun org-reveal (&optional siblings)
11997 "Show current entry, hierarchy above it, and the following headline.
11998 This can be used to show a consistent set of context around locations
11999 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
12000 not t for the search context.
12002 With optional argument SIBLINGS, on each level of the hierarchy all
12003 siblings are shown. This repairs the tree structure to what it would
12004 look like when opened with hierarchical calls to `org-cycle'.
12005 With double optional argument `C-u C-u', go to the parent and show the
12008 (run-hooks 'org-reveal-start-hook)
12009 (let ((org-show-hierarchy-above t)
12010 (org-show-following-heading t)
12011 (org-show-siblings (if siblings t org-show-siblings)))
12012 (org-show-context nil))
12013 (when (equal siblings '(16))
12015 (when (org-up-heading-safe)
12017 (run-hook-with-args 'org-cycle-hook 'subtree)))))
12019 (defun org-highlight-new-match (beg end)
12020 "Highlight from BEG to END and mark the highlight is an occur headline."
12021 (let ((ov (make-overlay beg end)))
12022 (overlay-put ov 'face 'secondary-selection)
12023 (push ov org-occur-highlights)))
12025 (defun org-remove-occur-highlights (&optional beg end noremove)
12026 "Remove the occur highlights from the buffer.
12027 BEG and END are ignored. If NOREMOVE is nil, remove this function
12028 from the `before-change-functions' in the current buffer."
12030 (unless org-inhibit-highlight-removal
12031 (mapc 'delete-overlay org-occur-highlights)
12032 (setq org-occur-highlights nil)
12033 (setq org-occur-parameters nil)
12035 (remove-hook 'before-change-functions
12036 'org-remove-occur-highlights 'local))))
12040 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
12041 "Regular expression matching the priority indicator.")
12043 (defvar org-remove-priority-next-time nil)
12045 (defun org-priority-up ()
12046 "Increase the priority of the current item."
12048 (org-priority 'up))
12050 (defun org-priority-down ()
12051 "Decrease the priority of the current item."
12053 (org-priority 'down))
12055 (defun org-priority (&optional action)
12056 "Change the priority of an item by ARG.
12057 ACTION can be `set', `up', `down', or a character."
12059 (unless org-enable-priority-commands
12060 (error "Priority commands are disabled"))
12061 (setq action (or action 'set))
12062 (let (current new news have remove)
12064 (org-back-to-heading t)
12065 (if (looking-at org-priority-regexp)
12066 (setq current (string-to-char (match-string 2))
12068 (setq current org-default-priority))
12070 ((eq action 'remove)
12071 (setq remove t new ?\ ))
12072 ((or (eq action 'set)
12073 (if (featurep 'xemacs) (characterp action) (integerp action)))
12074 (if (not (eq action 'set))
12076 (message "Priority %c-%c, SPC to remove: "
12077 org-highest-priority org-lowest-priority)
12078 (setq new (read-char-exclusive)))
12079 (if (and (= (upcase org-highest-priority) org-highest-priority)
12080 (= (upcase org-lowest-priority) org-lowest-priority))
12081 (setq new (upcase new)))
12082 (cond ((equal new ?\ ) (setq remove t))
12083 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
12084 (error "Priority must be between `%c' and `%c'"
12085 org-highest-priority org-lowest-priority))))
12087 (if (and (not have) (eq last-command this-command))
12088 (setq new org-lowest-priority)
12089 (setq new (if (and org-priority-start-cycle-with-default (not have))
12090 org-default-priority (1- current)))))
12092 (if (and (not have) (eq last-command this-command))
12093 (setq new org-highest-priority)
12094 (setq new (if (and org-priority-start-cycle-with-default (not have))
12095 org-default-priority (1+ current)))))
12096 (t (error "Invalid action")))
12097 (if (or (< (upcase new) org-highest-priority)
12098 (> (upcase new) org-lowest-priority))
12100 (setq news (format "%c" new))
12103 (replace-match "" t t nil 1)
12104 (replace-match news t t nil 2))
12106 (error "No priority cookie found in line")
12107 (let ((case-fold-search nil))
12108 (looking-at org-todo-line-regexp))
12111 (goto-char (match-end 2))
12112 (insert " [#" news "]"))
12113 (goto-char (match-beginning 3))
12114 (insert "[#" news "] "))))
12115 (org-preserve-lc (org-set-tags nil 'align)))
12117 (message "Priority removed")
12118 (message "Priority of current item set to %s" news))))
12120 (defun org-get-priority (s)
12121 "Find priority cookie and return priority."
12123 (if (not (string-match org-priority-regexp s))
12124 (* 1000 (- org-lowest-priority org-default-priority))
12125 (* 1000 (- org-lowest-priority
12126 (string-to-char (match-string 2 s)))))))
12130 (defvar org-agenda-archives-mode)
12131 (defvar org-map-continue-from nil
12132 "Position from where mapping should continue.
12133 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
12135 (defvar org-scanner-tags nil
12136 "The current tag list while the tags scanner is running.")
12137 (defvar org-trust-scanner-tags nil
12138 "Should `org-get-tags-at' use the tags fro the scanner.
12139 This is for internal dynamical scoping only.
12140 When this is non-nil, the function `org-get-tags-at' will return the value
12141 of `org-scanner-tags' instead of building the list by itself. This
12142 can lead to large speed-ups when the tags scanner is used in a file with
12143 many entries, and when the list of tags is retrieved, for example to
12144 obtain a list of properties. Building the tags list for each entry in such
12145 a file becomes an N^2 operation - but with this variable set, it scales
12148 (defun org-scan-tags (action matcher &optional todo-only)
12149 "Scan headline tags with inheritance and produce output ACTION.
12151 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
12152 or `agenda' to produce an entry list for an agenda view. It can also be
12153 a Lisp form or a function that should be called at each matched headline, in
12154 this case the return value is a list of all return values from these calls.
12156 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
12157 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
12158 only lines with a TODO keyword are included in the output."
12159 (require 'org-agenda)
12160 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
12161 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
12163 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
12164 (props (list 'face 'default
12165 'done-face 'org-agenda-done
12166 'undone-face 'default
12167 'mouse-face 'highlight
12168 'org-not-done-regexp org-not-done-regexp
12169 'org-todo-regexp org-todo-regexp
12171 (format "mouse-2 or RET jump to org file %s"
12172 (abbreviate-file-name
12173 (or (buffer-file-name (buffer-base-buffer))
12174 (buffer-name (buffer-base-buffer)))))))
12175 (case-fold-search nil)
12176 (org-map-continue-from nil)
12177 lspos tags tags-list
12178 (tags-alist (list (cons 0 org-file-tags)))
12179 (llast 0) rtn rtn1 level category i txt
12180 todo marker entry priority)
12181 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
12182 (setq action (list 'lambda nil action)))
12184 (goto-char (point-min))
12185 (when (eq action 'sparse-tree)
12187 (org-remove-occur-highlights))
12188 (while (re-search-forward re nil t)
12190 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
12191 tags (if (match-end 4) (org-match-string-no-properties 4)))
12192 (goto-char (setq lspos (match-beginning 0)))
12193 (setq level (org-reduced-level (funcall outline-level))
12194 category (org-get-category))
12195 (setq i llast llast level)
12196 ;; remove tag lists from same and sublevels
12197 (while (>= i level)
12198 (when (setq entry (assoc i tags-alist))
12199 (setq tags-alist (delete entry tags-alist)))
12201 ;; add the next tags
12203 (setq tags (org-split-string tags ":")
12205 (cons (cons level tags) tags-alist)))
12206 ;; compile tags for current headline
12208 (if org-use-tag-inheritance
12209 (apply 'append (mapcar 'cdr (reverse tags-alist)))
12211 org-scanner-tags tags-list)
12212 (when org-use-tag-inheritance
12213 (setcdr (car tags-alist)
12214 (mapcar (lambda (x)
12215 (setq x (copy-sequence x))
12216 (org-add-prop-inherited x))
12217 (cdar tags-alist))))
12218 (when (and tags org-use-tag-inheritance
12219 (or (not (eq t org-use-tag-inheritance))
12220 org-tags-exclude-from-inheritance))
12221 ;; selective inheritance, remove uninherited ones
12222 (setcdr (car tags-alist)
12223 (org-remove-uniherited-tags (cdar tags-alist))))
12224 (when (and (or (not todo-only)
12225 (and (member todo org-not-done-keywords)
12226 (or (not org-agenda-tags-todo-honor-ignore-options)
12227 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
12228 (let ((case-fold-search t)) (eval matcher))
12230 (not (member org-archive-tag tags-list))
12231 ;; we have an archive tag, should we use this anyway?
12232 (or (not org-agenda-skip-archived-trees)
12233 (and (eq action 'agenda) org-agenda-archives-mode))))
12234 (unless (eq action 'sparse-tree) (org-agenda-skip))
12236 ;; select this headline
12239 ((eq action 'sparse-tree)
12240 (and org-highlight-sparse-tree-matches
12241 (org-get-heading) (match-end 0)
12242 (org-highlight-new-match
12243 (match-beginning 0) (match-beginning 1)))
12244 (org-show-context 'tags-tree))
12245 ((eq action 'agenda)
12246 (setq txt (org-format-agenda-item
12249 (if (eq org-tags-match-list-sublevels 'indented)
12250 (make-string (1- level) ?.) "")
12255 priority (org-get-priority txt))
12257 (setq marker (org-agenda-new-marker))
12258 (org-add-props txt props
12259 'org-marker marker 'org-hd-marker marker 'org-category category
12261 'priority priority 'type "tagsmatch")
12263 ((functionp action)
12264 (setq org-map-continue-from nil)
12266 (setq rtn1 (funcall action))
12268 (t (error "Invalid action")))
12270 ;; if we are to skip sublevels, jump to end of subtree
12271 (unless org-tags-match-list-sublevels
12272 (org-end-of-subtree t)
12273 (backward-char 1))))
12274 ;; Get the correct position from where to continue
12275 (if org-map-continue-from
12276 (goto-char org-map-continue-from)
12277 (and (= (point) lspos) (end-of-line 1)))))
12278 (when (and (eq action 'sparse-tree)
12279 (not org-sparse-tree-open-archived-trees))
12280 (org-hide-archived-subtrees (point-min) (point-max)))
12283 (defun org-remove-uniherited-tags (tags)
12284 "Remove all tags that are not inherited from the list TAGS."
12286 ((eq org-use-tag-inheritance t)
12287 (if org-tags-exclude-from-inheritance
12288 (org-delete-all org-tags-exclude-from-inheritance tags)
12290 ((not org-use-tag-inheritance) nil)
12291 ((stringp org-use-tag-inheritance)
12294 (if (and (string-match org-use-tag-inheritance x)
12295 (not (member x org-tags-exclude-from-inheritance)))
12298 ((listp org-use-tag-inheritance)
12301 (if (member x org-use-tag-inheritance) x nil))
12304 (defvar todo-only) ;; dynamically scoped
12306 (defun org-match-sparse-tree (&optional todo-only match)
12307 "Create a sparse tree according to tags string MATCH.
12308 MATCH can contain positive and negative selection of tags, like
12309 \"+WORK+URGENT-WITHBOSS\".
12310 If optional argument TODO-ONLY is non-nil, only select lines that are
12313 (org-prepare-agenda-buffers (list (current-buffer)))
12314 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
12316 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
12318 (defvar org-cached-props nil)
12319 (defun org-cached-entry-get (pom property)
12320 (if (or (eq t org-use-property-inheritance)
12321 (and (stringp org-use-property-inheritance)
12322 (string-match org-use-property-inheritance property))
12323 (and (listp org-use-property-inheritance)
12324 (member property org-use-property-inheritance)))
12325 ;; Caching is not possible, check it directly
12326 (org-entry-get pom property 'inherit)
12327 ;; Get all properties, so that we can do complicated checks easily
12328 (cdr (assoc property (or org-cached-props
12329 (setq org-cached-props
12330 (org-entry-properties pom)))))))
12332 (defun org-global-tags-completion-table (&optional files)
12333 "Return the list of all tags in all agenda buffer/files."
12340 (set-buffer (find-file-noselect file))
12341 (append (org-get-buffer-tags)
12342 (mapcar (lambda (x) (if (stringp (car-safe x))
12343 (list (car-safe x)) nil))
12345 (if (and files (car files))
12347 (org-agenda-files))))))))
12349 (defun org-make-tags-matcher (match)
12350 "Create the TAGS//TODO matcher form for the selection string MATCH."
12351 ;; todo-only is scoped dynamically into this function, and the function
12352 ;; may change it if the matcher asks for it.
12354 ;; Get a new match request, with completion
12355 (let ((org-last-tags-completion-table
12356 (org-global-tags-completion-table)))
12357 (setq match (org-completing-read-no-i
12358 "Match: " 'org-tags-completion-function nil nil nil
12359 'org-tags-history))))
12361 ;; Parse the string and create a lisp form
12362 (let ((match0 match)
12363 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
12365 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
12366 orterms term orlist re-p str-p level-p level-op time-p
12367 prop-p pn pv po cat-p gv rest)
12368 (if (string-match "/+" match)
12369 ;; match contains also a todo-matching request
12371 (setq tagsmatch (substring match 0 (match-beginning 0))
12372 todomatch (substring match (match-end 0)))
12373 (if (string-match "^!" todomatch)
12374 (setq todo-only t todomatch (substring todomatch 1)))
12375 (if (string-match "^\\s-*$" todomatch)
12376 (setq todomatch nil)))
12377 ;; only matching tags
12378 (setq tagsmatch match todomatch nil))
12380 ;; Make the tags matcher
12381 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
12382 (setq tagsmatcher t)
12383 (setq orterms (org-split-string tagsmatch "|") orlist nil)
12384 (while (setq term (pop orterms))
12385 (while (and (equal (substring term -1) "\\") orterms)
12386 (setq term (concat term "|" (pop orterms)))) ; repair bad split
12387 (while (string-match re term)
12388 (setq rest (substring term (match-end 0))
12389 minus (and (match-end 1)
12390 (equal (match-string 1 term) "-"))
12391 tag (match-string 2 term)
12392 re-p (equal (string-to-char tag) ?{)
12393 level-p (match-end 4)
12394 prop-p (match-end 5)
12396 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
12398 (setq level-op (org-op-to-function (match-string 3 term)))
12399 `(,level-op level ,(string-to-number
12400 (match-string 4 term))))
12402 (setq pn (match-string 5 term)
12403 po (match-string 6 term)
12404 pv (match-string 7 term)
12405 cat-p (equal pn "CATEGORY")
12406 re-p (equal (string-to-char pv) ?{)
12407 str-p (equal (string-to-char pv) ?\")
12408 time-p (save-match-data
12409 (string-match "^\"[[<].*[]>]\"$" pv))
12410 pv (if (or re-p str-p) (substring pv 1 -1) pv))
12411 (if time-p (setq pv (org-matcher-time pv)))
12412 (setq po (org-op-to-function po (if time-p 'time str-p)))
12414 ((equal pn "CATEGORY")
12415 (setq gv '(get-text-property (point) 'org-category)))
12419 (setq gv `(org-cached-entry-get nil ,pn))))
12422 `(not (string-match ,pv (or ,gv "")))
12423 `(string-match ,pv (or ,gv "")))
12425 `(,po (or ,gv "") ,pv)
12426 `(,po (string-to-number (or ,gv ""))
12427 ,(string-to-number pv) ))))
12428 (t `(member ,tag tags-list)))
12429 mm (if minus (list 'not mm) mm)
12431 (push mm tagsmatcher))
12432 (push (if (> (length tagsmatcher) 1)
12433 (cons 'and tagsmatcher)
12436 (setq tagsmatcher nil))
12437 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
12439 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
12440 ;; Make the todo matcher
12441 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
12442 (setq todomatcher t)
12443 (setq orterms (org-split-string todomatch "|") orlist nil)
12444 (while (setq term (pop orterms))
12445 (while (string-match re term)
12446 (setq minus (and (match-end 1)
12447 (equal (match-string 1 term) "-"))
12448 kwd (match-string 2 term)
12449 re-p (equal (string-to-char kwd) ?{)
12450 term (substring term (match-end 0))
12452 `(string-match ,(substring kwd 1 -1) todo)
12453 (list 'equal 'todo kwd))
12454 mm (if minus (list 'not mm) mm))
12455 (push mm todomatcher))
12456 (push (if (> (length todomatcher) 1)
12457 (cons 'and todomatcher)
12460 (setq todomatcher nil))
12461 (setq todomatcher (if (> (length orlist) 1)
12462 (cons 'or orlist) (car orlist))))
12464 ;; Return the string and lisp forms of the matcher
12465 (setq matcher (if todomatcher
12466 (list 'and tagsmatcher todomatcher)
12468 (cons match0 matcher)))
12470 (defun org-op-to-function (op &optional stringp)
12471 "Turn an operator into the appropriate function."
12474 ((equal op "<" ) '(< string< org-time<))
12475 ((equal op ">" ) '(> org-string> org-time>))
12476 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
12477 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
12478 ((member op '("=" "==")) '(= string= org-time=))
12479 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
12480 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
12482 (defun org<> (a b) (not (= a b)))
12483 (defun org-string<= (a b) (or (string= a b) (string< a b)))
12484 (defun org-string>= (a b) (not (string< a b)))
12485 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
12486 (defun org-string<> (a b) (not (string= a b)))
12487 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
12488 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
12489 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
12490 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
12491 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
12492 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
12494 "Convert S to a floating point time.
12495 If S is already a number, just return it. If it is a string, parse
12496 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12500 (condition-case nil
12501 (float-time (apply 'encode-time (org-parse-time-string s)))
12505 (defun org-time-today ()
12506 "Time in seconds today at 0:00.
12507 Returns the float number of seconds since the beginning of the
12508 epoch to the beginning of today (00:00)."
12509 (float-time (apply 'encode-time
12510 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12512 (defun org-matcher-time (s)
12513 "Interpret a time comparison value."
12516 ((string= s "<now>") (float-time))
12517 ((string= s "<today>") (org-time-today))
12518 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12519 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12520 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12521 (+ (org-time-today)
12522 (* (string-to-number (match-string 1 s))
12523 (cdr (assoc (match-string 2 s)
12524 '(("d" . 86400.0) ("w" . 604800.0)
12525 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12528 (defun org-match-any-p (re list)
12529 "Does re match any element of list?"
12530 (setq list (mapcar (lambda (x) (string-match re x)) list))
12533 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12534 (defvar org-tags-overlay (make-overlay 1 1))
12535 (org-detach-overlay org-tags-overlay)
12537 (defun org-get-local-tags-at (&optional pos)
12538 "Get a list of tags defined in the current headline."
12539 (org-get-tags-at pos 'local))
12541 (defun org-get-local-tags ()
12542 "Get a list of tags defined in the current headline."
12543 (org-get-tags-at nil 'local))
12545 (defun org-get-tags-at (&optional pos local)
12546 "Get a list of all headline tags applicable at POS.
12547 POS defaults to point. If tags are inherited, the list contains
12548 the targets in the same sequence as the headlines appear, i.e.
12549 the tags of the current headline come last.
12550 When LOCAL is non-nil, only return tags from the current headline,
12551 ignore inherited ones."
12553 (if (and org-trust-scanner-tags
12554 (or (not pos) (equal pos (point)))
12557 (let (tags ltags lastpos parent)
12561 (goto-char (or pos (point)))
12564 (condition-case nil
12566 (org-back-to-heading t)
12567 (while (not (equal lastpos (point)))
12568 (setq lastpos (point))
12570 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12571 (setq ltags (org-split-string
12572 (org-match-string-no-properties 1) ":"))
12574 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12577 (org-remove-uniherited-tags ltags)
12580 (or org-use-tag-inheritance (throw 'done t))
12581 (if local (throw 'done t))
12582 (or (org-up-heading-safe) (error nil))
12585 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12587 (defun org-add-prop-inherited (s)
12588 (add-text-properties 0 (length s) '(inherited t) s)
12591 (defun org-toggle-tag (tag &optional onoff)
12592 "Toggle the tag TAG for the current line.
12593 If ONOFF is `on' or `off', don't toggle but set to this state."
12596 (org-back-to-heading t)
12597 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12600 (setq current (match-string 1))
12601 (replace-match ""))
12603 (setq current (nreverse (org-split-string current ":")))
12607 (or (member tag current) (push tag current)))
12609 (or (not (member tag current)) (setq current (delete tag current))))
12610 (t (if (member tag current)
12611 (setq current (delete tag current))
12613 (push tag current))))
12617 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12618 (org-set-tags nil t))
12619 (delete-horizontal-space))
12620 (run-hooks 'org-after-tags-change-hook))
12623 (defun org-align-tags-here (to-col)
12624 ;; Assumes that this is a headline
12625 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12626 (beginning-of-line 1)
12627 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12628 (< pos (match-beginning 2)))
12630 (setq tags-l (- (match-end 2) (match-beginning 2)))
12631 (goto-char (match-beginning 1))
12633 (delete-region (point) (1+ (match-beginning 2)))
12634 (setq ncol (max (1+ (current-column))
12638 (- (abs to-col) tags-l))))
12640 (insert (make-string (- ncol (current-column)) ?\ ))
12641 (setq ncol (current-column))
12642 (when indent-tabs-mode (tabify p (point-at-eol)))
12643 (org-move-to-column (min ncol col) t))
12646 (defun org-set-tags-command (&optional arg just-align)
12647 "Call the set-tags command for the current entry."
12649 (if (org-on-heading-p)
12650 (org-set-tags arg just-align)
12652 (org-back-to-heading t)
12653 (org-set-tags arg just-align))))
12655 (defun org-set-tags-to (data)
12656 "Set the tags of the current entry to DATA, replacing the current tags.
12657 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12658 If DATA is nil or the empty string, any tags will be removed."
12659 (interactive "sTags: ")
12663 ((equal data "") "")
12665 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12668 (concat ":" (mapconcat 'identity data ":") ":"))
12672 (org-back-to-heading t)
12673 (when (looking-at org-complex-heading-regexp)
12676 (goto-char (match-beginning 5))
12678 (delete-region (point) (point-at-eol))
12679 (org-set-tags nil 'align))
12680 (goto-char (point-at-eol))
12682 (org-set-tags nil 'align)))
12683 (beginning-of-line 1)
12684 (if (looking-at ".*?\\([ \t]+\\)$")
12685 (delete-region (match-beginning 1) (match-end 1))))))
12687 (defun org-align-all-tags ()
12688 "Align the tags i all headings."
12691 (or (ignore-errors (org-back-to-heading t))
12692 (outline-next-heading))
12693 (if (org-on-heading-p)
12695 (message "No headings"))))
12697 (defun org-set-tags (&optional arg just-align)
12698 "Set the tags for the current headline.
12699 With prefix ARG, realign all tags in headings in the current buffer."
12701 (let* ((re (concat "^" outline-regexp))
12702 (current (org-get-tags-string))
12703 (col (current-column))
12704 (org-setting-tags t)
12705 table current-tags inherited-tags ; computed below when needed
12709 (goto-char (point-min))
12710 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12711 (while (re-search-forward re nil t)
12712 (org-set-tags nil t)
12714 (message "All tags realigned to column %d" org-tags-column))
12716 (setq tags current)
12717 ;; Get a new set of tags from the user
12719 (setq table (append org-tag-persistent-alist
12720 (or org-tag-alist (org-get-buffer-tags))
12721 (and org-complete-tags-always-offer-all-agenda-tags
12722 (org-global-tags-completion-table (org-agenda-files))))
12723 org-last-tags-completion-table table
12724 current-tags (org-split-string current ":")
12725 inherited-tags (nreverse
12726 (nthcdr (length current-tags)
12727 (nreverse (org-get-tags-at))))
12729 (if (or (eq t org-use-fast-tag-selection)
12730 (and org-use-fast-tag-selection
12731 (delq nil (mapcar 'cdr table))))
12732 (org-fast-tag-selection
12733 current-tags inherited-tags table
12734 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12735 (let ((org-add-colon-after-tag-completion t))
12737 (org-without-partial-completion
12738 (org-icompleting-read "Tags: " 'org-tags-completion-function
12739 nil nil current 'org-tags-history)))))))
12740 (while (string-match "[-+&]+" tags)
12741 ;; No boolean logic, just a list
12742 (setq tags (replace-match ":" t t tags))))
12744 (if org-tags-sort-function
12745 (setq tags (mapconcat 'identity
12746 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12747 org-tags-sort-function) ":")))
12749 (if (string-match "\\`[\t ]*\\'" tags)
12751 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12752 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12754 ;; Insert new tags at the correct column
12755 (beginning-of-line 1)
12757 ((and (equal current "") (equal tags "")))
12758 ((re-search-forward
12759 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12761 (if (equal tags "")
12763 (goto-char (match-beginning 0))
12764 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12765 (1+ (point)) (point))
12766 c1 (max (1+ c0) (if (> org-tags-column 0)
12768 (- (- org-tags-column) (length tags))))
12769 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12770 (replace-match rpl t t)
12771 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12773 (t (error "Tags alignment failed")))
12774 (org-move-to-column col)
12776 (run-hooks 'org-after-tags-change-hook)))))
12778 (defun org-change-tag-in-region (beg end tag off)
12779 "Add or remove TAG for each entry in the region.
12780 This works in the agenda, and also in an org-mode buffer."
12782 (list (region-beginning) (region-end)
12783 (let ((org-last-tags-completion-table
12785 (org-get-buffer-tags)
12786 (org-global-tags-completion-table))))
12787 (org-icompleting-read
12788 "Tag: " 'org-tags-completion-function nil nil nil
12789 'org-tags-history))
12791 (message "[s]et or [r]emove? ")
12792 (equal (read-char-exclusive) ?r))))
12793 (if (fboundp 'deactivate-mark) (deactivate-mark))
12794 (let ((agendap (equal major-mode 'org-agenda-mode))
12795 l1 l2 m buf pos newhead (cnt 0))
12797 (setq l2 (1- (org-current-line)))
12799 (setq l1 (org-current-line))
12800 (loop for l from l1 to l2 do
12802 (setq m (get-text-property (point) 'org-hd-marker))
12803 (when (or (and (org-mode-p) (org-on-heading-p))
12805 (setq buf (if agendap (marker-buffer m) (current-buffer))
12806 pos (if agendap m (point)))
12807 (with-current-buffer buf
12811 (setq cnt (1+ cnt))
12812 (org-toggle-tag tag (if off 'off 'on))
12813 (setq newhead (org-get-heading)))))
12814 (and agendap (org-agenda-change-all-lines newhead m))))
12815 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12817 (defun org-tags-completion-function (string predicate &optional flag)
12818 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12819 (confirm (lambda (x) (stringp (car x)))))
12820 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12821 (setq s1 (match-string 1 string)
12822 s2 (match-string 2 string))
12823 (setq s1 "" s2 string))
12827 (setq rtn (try-completion s2 ctable confirm))
12830 (concat s1 s2 (substring rtn (length s2))
12831 (if (and org-add-colon-after-tag-completion
12832 (assoc rtn ctable))
12837 (all-completions s2 ctable confirm)
12841 (assoc s2 ctable)))
12844 (defun org-fast-tag-insert (kwd tags face &optional end)
12845 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12846 (insert (format "%-12s" (concat kwd ":"))
12847 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12850 (defun org-fast-tag-show-exit (flag)
12853 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12854 (replace-match ""))
12857 (org-move-to-column (- (window-width) 19) t)
12858 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12860 (defun org-set-current-tags-overlay (current prefix)
12861 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12862 (if (featurep 'xemacs)
12863 (org-overlay-display org-tags-overlay (concat prefix s)
12864 'secondary-selection)
12865 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12866 (org-overlay-display org-tags-overlay (concat prefix s)))))
12868 (defvar org-last-tag-selection-key nil)
12869 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12870 "Fast tag selection with single keys.
12871 CURRENT is the current list of tags in the headline, INHERITED is the
12872 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12873 possibly with grouping information. TODO-TABLE is a similar table with
12874 TODO keywords, should these have keys assigned to them.
12875 If the keys are nil, a-z are automatically assigned.
12876 Returns the new tags string, or nil to not change the current settings."
12877 (let* ((fulltable (append table todo-table))
12878 (maxlen (apply 'max (mapcar
12880 (if (stringp (car x)) (string-width (car x)) 0))
12882 (buf (current-buffer))
12883 (expert (eq org-fast-tag-selection-single-key 'expert))
12885 (fwidth (+ maxlen 3 1 3))
12886 (ncol (/ (- (window-width) 4) fwidth))
12889 tg cnt e c char c1 c2 ntable tbl rtn
12890 ov-start ov-end ov-prefix
12891 (exit-after-next org-fast-tag-selection-single-key)
12892 (done-keywords org-done-keywords)
12895 (beginning-of-line 1)
12897 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12898 (setq ov-start (match-beginning 1)
12899 ov-end (match-end 1)
12901 (setq ov-start (1- (point-at-eol))
12902 ov-end (1+ ov-start))
12903 (skip-chars-forward "^\n\r")
12906 (buffer-substring (1- (point)) (point))
12907 (if (> (current-column) org-tags-column)
12909 (make-string (- org-tags-column (current-column)) ?\ ))))))
12910 (move-overlay org-tags-overlay ov-start ov-end)
12911 (save-window-excursion
12913 (set-buffer (get-buffer-create " *Org tags*"))
12914 (delete-other-windows)
12915 (split-window-vertically)
12916 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12918 (org-set-local 'org-done-keywords done-keywords)
12919 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12920 (org-fast-tag-insert "Current" current c-face "\n\n")
12921 (org-fast-tag-show-exit exit-after-next)
12922 (org-set-current-tags-overlay current ov-prefix)
12923 (setq tbl fulltable char ?a cnt 0)
12924 (while (setq e (pop tbl))
12926 ((equal (car e) :startgroup)
12927 (push '() groups) (setq ingroup t)
12928 (when (not (= cnt 0))
12931 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12932 ((equal (car e) :endgroup)
12933 (setq ingroup nil cnt 0)
12934 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12935 ((equal e '(:newline))
12936 (when (not (= cnt 0))
12940 (while (equal (car tbl) '(:newline))
12942 (setq tbl (cdr tbl)))))
12944 (setq tg (copy-sequence (car e)) c2 nil)
12947 ;; automatically assign a character.
12948 (setq c1 (string-to-char
12949 (downcase (substring
12950 tg (if (= (string-to-char tg) ?@) 1 0)))))
12951 (if (or (rassoc c1 ntable) (rassoc c1 table))
12952 (while (or (rassoc char ntable) (rassoc char table))
12953 (setq char (1+ char)))
12955 (setq c (or c2 char)))
12956 (if ingroup (push tg (car groups)))
12957 (setq tg (org-add-props tg nil 'face
12959 ((not (assoc tg table))
12960 (org-get-todo-face tg))
12961 ((member tg current) c-face)
12962 ((member tg inherited) i-face)
12964 (if (and (= cnt 0) (not ingroup)) (insert " "))
12965 (insert "[" c "] " tg (make-string
12966 (- fwidth 4 (length tg)) ?\ ))
12967 (push (cons tg c) ntable)
12968 (when (= (setq cnt (1+ cnt)) ncol)
12970 (if ingroup (insert " "))
12972 (setq ntable (nreverse ntable))
12974 (goto-char (point-min))
12975 (if (not expert) (org-fit-window-to-buffer))
12979 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12980 (if (not groups) "no " "")
12981 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12982 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12983 (setq org-last-tag-selection-key c)
12985 ((= c ?\r) (throw 'exit t))
12987 (setq groups (not groups))
12988 (goto-char (point-min))
12989 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12992 (org-fast-tag-show-exit
12993 (setq exit-after-next (not exit-after-next)))
12995 (delete-other-windows)
12996 (split-window-vertically)
12997 (org-switch-to-buffer-other-window " *Org tags*")
12998 (org-fit-window-to-buffer)))
13000 (and (= c ?q) (not (rassoc c ntable))))
13001 (org-detach-overlay org-tags-overlay)
13002 (setq quit-flag t))
13005 (if exit-after-next (setq exit-after-next 'now)))
13007 (condition-case nil
13008 (setq tg (org-icompleting-read
13011 (with-current-buffer buf
13012 (org-get-buffer-tags)))))
13013 (quit (setq tg "")))
13014 (when (string-match "\\S-" tg)
13015 (add-to-list 'buffer-tags (list tg))
13016 (if (member tg current)
13017 (setq current (delete tg current))
13018 (push tg current)))
13019 (if exit-after-next (setq exit-after-next 'now)))
13020 ((setq e (rassoc c todo-table) tg (car e))
13021 (with-current-buffer buf
13022 (save-excursion (org-todo tg)))
13023 (if exit-after-next (setq exit-after-next 'now)))
13024 ((setq e (rassoc c ntable) tg (car e))
13025 (if (member tg current)
13026 (setq current (delete tg current))
13027 (loop for g in groups do
13030 (setq current (delete x current)))
13033 (if exit-after-next (setq exit-after-next 'now))))
13035 ;; Create a sorted list
13039 (assoc b (cdr (memq (assoc a ntable) ntable))))))
13040 (if (eq exit-after-next 'now) (throw 'exit t))
13041 (goto-char (point-min))
13042 (beginning-of-line 2)
13043 (delete-region (point) (point-at-eol))
13044 (org-fast-tag-insert "Current" current c-face)
13045 (org-set-current-tags-overlay current ov-prefix)
13046 (while (re-search-forward
13047 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
13048 (setq tg (match-string 1))
13049 (add-text-properties
13050 (match-beginning 1) (match-end 1)
13053 ((member tg current) c-face)
13054 ((member tg inherited) i-face)
13055 (t (get-text-property (match-beginning 1) 'face))))))
13056 (goto-char (point-min)))))
13057 (org-detach-overlay org-tags-overlay)
13059 (mapconcat 'identity current ":")
13062 (defun org-get-tags-string ()
13063 "Get the TAGS string in the current headline."
13064 (unless (org-on-heading-p t)
13065 (error "Not on a heading"))
13067 (beginning-of-line 1)
13068 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
13069 (org-match-string-no-properties 1)
13072 (defun org-get-tags ()
13073 "Get the list of tags specified in the current headline."
13074 (org-split-string (org-get-tags-string) ":"))
13076 (defun org-get-buffer-tags ()
13077 "Get a table of all tags used in the buffer, for completion."
13080 (goto-char (point-min))
13081 (while (re-search-forward
13082 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
13083 (when (equal (char-after (point-at-bol 0)) ?*)
13084 (mapc (lambda (x) (add-to-list 'tags x))
13085 (org-split-string (org-match-string-no-properties 1) ":")))))
13086 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
13087 (mapcar 'list tags)))
13089 ;;;; The mapping API
13092 (defun org-map-entries (func &optional match scope &rest skip)
13093 "Call FUNC at each headline selected by MATCH in SCOPE.
13095 FUNC is a function or a lisp form. The function will be called without
13096 arguments, with the cursor positioned at the beginning of the headline.
13097 The return values of all calls to the function will be collected and
13098 returned as a list.
13100 The call to FUNC will be wrapped into a save-excursion form, so FUNC
13101 does not need to preserve point. After evaluation, the cursor will be
13102 moved to the end of the line (presumably of the headline of the
13103 processed entry) and search continues from there. Under some
13104 circumstances, this may not produce the wanted results. For example,
13105 if you have removed (e.g. archived) the current (sub)tree it could
13106 mean that the next entry will be skipped entirely. In such cases, you
13107 can specify the position from where search should continue by making
13108 FUNC set the variable `org-map-continue-from' to the desired buffer
13111 MATCH is a tags/property/todo match as it is used in the agenda tags view.
13112 Only headlines that are matched by this query will be considered during
13113 the iteration. When MATCH is nil or t, all headlines will be
13114 visited by the iteration.
13116 SCOPE determines the scope of this command. It can be any of:
13118 nil The current buffer, respecting the restriction if any
13119 tree The subtree started with the entry at point
13120 file The current buffer, without restriction
13122 The current buffer, and any archives associated with it
13123 agenda All agenda files
13124 agenda-with-archives
13125 All agenda files with any archive files associated with them
13127 If this is a list, all files in the list will be scanned
13129 The remaining args are treated as settings for the skipping facilities of
13130 the scanner. The following items can be given here:
13132 archive skip trees with the archive tag.
13133 comment skip trees with the COMMENT keyword
13134 function or Emacs Lisp form:
13135 will be used as value for `org-agenda-skip-function', so whenever
13136 the function returns t, FUNC will not be called for that
13137 entry and search will continue from the point where the
13138 function leaves it.
13140 If your function needs to retrieve the tags including inherited tags
13141 at the *current* entry, you can use the value of the variable
13142 `org-scanner-tags' which will be much faster than getting the value
13143 with `org-get-tags-at'. If your function gets properties with
13144 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
13145 to t around the call to `org-entry-properties' to get the same speedup.
13146 Note that if your function moves around to retrieve tags and properties at
13147 a *different* entry, you cannot use these techniques."
13148 (let* ((org-agenda-archives-mode nil) ; just to make sure
13149 (org-agenda-skip-archived-trees (memq 'archive skip))
13150 (org-agenda-skip-comment-trees (memq 'comment skip))
13151 (org-agenda-skip-function
13152 (car (org-delete-all '(comment archive) skip)))
13153 (org-tags-match-list-sublevels t)
13155 org-todo-keywords-for-agenda
13156 org-done-keywords-for-agenda
13157 org-todo-keyword-alist-for-agenda
13158 org-drawers-for-agenda
13159 org-tag-alist-for-agenda)
13162 ((eq match t) (setq matcher t))
13163 ((eq match nil) (setq matcher t))
13164 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
13168 (when (eq scope 'tree)
13169 (org-back-to-heading t)
13170 (org-narrow-to-subtree)
13175 (org-prepare-agenda-buffers
13176 (list (buffer-file-name (current-buffer))))
13177 (setq res (org-scan-tags func matcher)))
13178 ;; Get the right scope
13180 ((and scope (listp scope) (symbolp (car scope)))
13181 (setq scope (eval scope)))
13182 ((eq scope 'agenda)
13183 (setq scope (org-agenda-files t)))
13184 ((eq scope 'agenda-with-archives)
13185 (setq scope (org-agenda-files t))
13186 (setq scope (org-add-archive-files scope)))
13188 (setq scope (list (buffer-file-name))))
13189 ((eq scope 'file-with-archives)
13190 (setq scope (org-add-archive-files (list (buffer-file-name))))))
13191 (org-prepare-agenda-buffers scope)
13192 (while (setq file (pop scope))
13193 (with-current-buffer (org-find-base-buffer-visiting file)
13197 (goto-char (point-min))
13198 (setq res (append res (org-scan-tags func matcher))))))))))
13203 ;;; Setting and retrieving properties
13205 (defconst org-special-properties
13206 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
13207 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
13208 "The special properties valid in Org-mode.
13210 These are properties that are not defined in the property drawer,
13211 but in some other way.")
13213 (defconst org-default-properties
13214 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
13215 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
13216 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
13217 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
13218 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
13219 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
13220 "Some properties that are used by Org-mode for various purposes.
13221 Being in this list makes sure that they are offered for completion.")
13223 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
13224 "Regular expression matching the first line of a property drawer.")
13226 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
13227 "Regular expression matching the last line of a property drawer.")
13229 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
13230 "Regular expression matching the first line of a property drawer.")
13232 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
13233 "Regular expression matching the first line of a property drawer.")
13235 (defconst org-property-drawer-re
13236 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
13237 org-property-end-re "\\)\n?")
13238 "Matches an entire property drawer.")
13240 (defconst org-clock-drawer-re
13241 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
13242 org-property-end-re "\\)\n?")
13243 "Matches an entire clock drawer.")
13245 (defun org-property-action ()
13246 "Do an action on properties."
13249 (org-at-property-p)
13250 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
13251 (setq c (read-char-exclusive))
13254 (call-interactively 'org-set-property))
13256 (call-interactively 'org-delete-property))
13258 (call-interactively 'org-delete-property-globally))
13260 (call-interactively 'org-compute-property-at-point))
13261 (t (error "No such property action %c" c)))))
13263 (defun org-set-effort (&optional value)
13264 "Set the effort property of the current entry.
13265 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
13268 (if (equal value 0) (setq value 10))
13269 (let* ((completion-ignore-case t)
13270 (prop org-effort-property)
13271 (cur (org-entry-get nil prop))
13272 (allowed (org-property-get-allowed-values nil prop 'table))
13273 (existing (mapcar 'list (org-property-values prop)))
13276 ((stringp value) value)
13277 ((and allowed (integerp value))
13278 (or (car (nth (1- value) allowed))
13279 (car (org-last allowed))))
13281 (message "Select 1-9,0, [RET%s]: %s"
13282 (if cur (concat "=" cur) "")
13283 (mapconcat 'car allowed " "))
13284 (setq rpl (read-char-exclusive))
13285 (if (equal rpl ?\r)
13287 (setq rpl (- rpl ?0))
13288 (if (equal rpl 0) (setq rpl 10))
13289 (if (and (> rpl 0) (<= rpl (length allowed)))
13290 (car (nth (1- rpl) allowed))
13291 (org-completing-read "Effort: " allowed nil))))
13293 (let (org-completion-use-ido org-completion-use-iswitchb)
13294 (org-completing-read
13295 (concat "Effort " (if (and cur (string-match "\\S-" cur))
13296 (concat "[" cur "]") "")
13298 existing nil nil "" nil cur))))))
13299 (unless (equal (org-entry-get nil prop) val)
13300 (org-entry-put nil prop val))
13301 (message "%s is now %s" prop val)))
13303 (defun org-at-property-p ()
13304 "Is cursor inside a property drawer?"
13306 (beginning-of-line 1)
13307 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
13308 (save-match-data ;; Used by calling procedures
13310 (range (unless (org-before-first-heading-p)
13311 (org-get-property-block))))
13312 (and range (<= (car range) p) (< p (cdr range))))))))
13314 (defun org-get-property-block (&optional beg end force)
13315 "Return the (beg . end) range of the body of the property drawer.
13316 BEG and END can be beginning and end of subtree, if not given
13317 they will be found.
13318 If the drawer does not exist and FORCE is non-nil, create the drawer."
13321 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
13322 (end (or end (progn (outline-next-heading) (point)))))
13324 (if (re-search-forward org-property-start-re end t)
13325 (setq beg (1+ (match-end 0)))
13328 (org-insert-property-drawer)
13329 (setq end (progn (outline-next-heading) (point))))
13332 (if (re-search-forward org-property-start-re end t)
13333 (setq beg (1+ (match-end 0)))))
13334 (if (re-search-forward org-property-end-re end t)
13335 (setq end (match-beginning 0))
13336 (or force (throw 'exit nil))
13339 (org-indent-line-function)
13340 (insert ":END:\n"))
13343 (defun org-entry-properties (&optional pom which specific)
13344 "Get all properties of the entry at point-or-marker POM.
13345 This includes the TODO keyword, the tags, time strings for deadline,
13346 scheduled, and clocking, and any additional properties defined in the
13347 entry. The return value is an alist, keys may occur multiple times
13348 if the property key was used several times.
13349 POM may also be nil, in which case the current entry is used.
13350 If WHICH is nil or `all', get all properties. If WHICH is
13351 `special' or `standard', only get that subclass. If WHICH
13352 is a string only get exactly this property. Specific can be a string, the
13353 specific property we are interested in. Specifying it can speed
13354 things up because then unnecessary parsing is avoided."
13355 (setq which (or which 'all))
13356 (org-with-point-at pom
13357 (let ((clockstr (substring org-clock-string 0 -1))
13358 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
13359 (case-fold-search nil)
13360 beg end range props sum-props key key1 value string clocksum)
13362 (when (condition-case nil
13363 (and (org-mode-p) (org-back-to-heading t))
13366 (setq sum-props (get-text-property (point) 'org-summaries))
13367 (setq clocksum (get-text-property (point) :org-clock-minutes))
13368 (outline-next-heading)
13370 (when (memq which '(all special))
13371 ;; Get the special properties, like TODO and tags
13373 (when (and (or (not specific) (string= specific "TODO"))
13374 (looking-at org-todo-line-regexp) (match-end 2))
13375 (push (cons "TODO" (org-match-string-no-properties 2)) props))
13376 (when (and (or (not specific) (string= specific "PRIORITY"))
13377 (looking-at org-priority-regexp))
13378 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
13379 (when (and (or (not specific) (string= specific "TAGS"))
13380 (setq value (org-get-tags-string))
13381 (string-match "\\S-" value))
13382 (push (cons "TAGS" value) props))
13383 (when (and (or (not specific) (string= specific "ALLTAGS"))
13384 (setq value (org-get-tags-at)))
13385 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
13388 (when (or (not specific) (string= specific "BLOCKED"))
13389 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
13390 (when (or (not specific)
13392 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
13393 "TIMESTAMP" "TIMESTAMP_IA")))
13394 (while (re-search-forward org-maybe-keyword-time-regexp end t)
13395 (setq key (if (match-end 1)
13396 (substring (org-match-string-no-properties 1)
13398 string (if (equal key clockstr)
13402 (match-beginning 3) (goto-char
13404 (substring (org-match-string-no-properties 3)
13406 ;; Get the correct property name from the key. This is
13407 ;; necessary if the user has configured time keywords.
13408 (setq key1 (concat key ":"))
13412 (if (= (char-after (match-beginning 3)) ?\[)
13413 "TIMESTAMP_IA" "TIMESTAMP")))
13414 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
13415 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
13416 ((equal key1 org-closed-string) (setq key "CLOSED"))
13417 ((equal key1 org-clock-string) (setq key "CLOCK")))
13418 (when (or (equal key "CLOCK") (not (assoc key props)))
13419 (push (cons key string) props))))
13422 (when (memq which '(all standard))
13423 ;; Get the standard properties, like :PROP: ...
13424 (setq range (org-get-property-block beg end))
13426 (goto-char (car range))
13427 (while (re-search-forward
13428 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
13430 (setq key (org-match-string-no-properties 1)
13431 value (org-trim (or (org-match-string-no-properties 2) "")))
13432 (unless (member key excluded)
13433 (push (cons key (or value "")) props)))))
13435 (push (cons "CLOCKSUM"
13436 (org-columns-number-to-string (/ (float clocksum) 60.)
13439 (unless (assoc "CATEGORY" props)
13440 (setq value (or (org-get-category)
13441 (progn (org-refresh-category-properties)
13442 (org-get-category))))
13443 (push (cons "CATEGORY" value) props))
13444 (append sum-props (nreverse props)))))))
13446 (defun org-entry-get (pom property &optional inherit literal-nil)
13447 "Get value of PROPERTY for entry at point-or-marker POM.
13448 If INHERIT is non-nil and the entry does not have the property,
13449 then also check higher levels of the hierarchy.
13450 If INHERIT is the symbol `selective', use inheritance only if the setting
13451 in `org-use-property-inheritance' selects PROPERTY for inheritance.
13452 If the property is present but empty, the return value is the empty string.
13453 If the property is not present at all, nil is returned.
13455 If LITERAL-NIL is set, return the string value \"nil\" as a string,
13456 do not interpret it as the list atom nil. This is used for inheritance
13457 when a \"nil\" value can supercede a non-nil value higher up the hierarchy."
13458 (org-with-point-at pom
13459 (if (and inherit (if (eq inherit 'selective)
13460 (org-property-inherit-p property)
13462 (org-entry-get-with-inheritance property literal-nil)
13463 (if (member property org-special-properties)
13464 ;; We need a special property. Use `org-entry-properties' to
13465 ;; retrieve it, but specify the wanted property
13466 (cdr (assoc property (org-entry-properties nil 'special property)))
13467 (let ((range (org-get-property-block)))
13469 (goto-char (car range))
13471 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
13473 ;; Found the property, return it.
13476 (org-match-string-no-properties 1)
13477 (org-not-nil (org-match-string-no-properties 1)))
13480 (defun org-property-or-variable-value (var &optional inherit)
13481 "Check if there is a property fixing the value of VAR.
13482 If yes, return this value. If not, return the current value of the variable."
13483 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
13484 (if (and prop (stringp prop) (string-match "\\S-" prop))
13486 (symbol-value var))))
13488 (defun org-entry-delete (pom property)
13489 "Delete the property PROPERTY from entry at point-or-marker POM."
13490 (org-with-point-at pom
13491 (if (member property org-special-properties)
13492 nil ; cannot delete these properties.
13493 (let ((range (org-get-property-block)))
13495 (goto-char (car range))
13497 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
13500 (delete-region (match-beginning 0) (1+ (point-at-eol)))
13504 ;; Multi-values properties are properties that contain multiple values
13505 ;; These values are assumed to be single words, separated by whitespace.
13506 (defun org-entry-add-to-multivalued-property (pom property value)
13507 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
13508 (let* ((old (org-entry-get pom property))
13509 (values (and old (org-split-string old "[ \t]"))))
13510 (setq value (org-entry-protect-space value))
13511 (unless (member value values)
13512 (setq values (cons value values))
13513 (org-entry-put pom property
13514 (mapconcat 'identity values " ")))))
13516 (defun org-entry-remove-from-multivalued-property (pom property value)
13517 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
13518 (let* ((old (org-entry-get pom property))
13519 (values (and old (org-split-string old "[ \t]"))))
13520 (setq value (org-entry-protect-space value))
13521 (when (member value values)
13522 (setq values (delete value values))
13523 (org-entry-put pom property
13524 (mapconcat 'identity values " ")))))
13526 (defun org-entry-member-in-multivalued-property (pom property value)
13527 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
13528 (let* ((old (org-entry-get pom property))
13529 (values (and old (org-split-string old "[ \t]"))))
13530 (setq value (org-entry-protect-space value))
13531 (member value values)))
13533 (defun org-entry-get-multivalued-property (pom property)
13534 "Return a list of values in a multivalued property."
13535 (let* ((value (org-entry-get pom property))
13536 (values (and value (org-split-string value "[ \t]"))))
13537 (mapcar 'org-entry-restore-space values)))
13539 (defun org-entry-put-multivalued-property (pom property &rest values)
13540 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13541 VALUES should be a list of strings. Spaces will be protected."
13542 (org-entry-put pom property
13543 (mapconcat 'org-entry-protect-space values " "))
13544 (let* ((value (org-entry-get pom property))
13545 (values (and value (org-split-string value "[ \t]"))))
13546 (mapcar 'org-entry-restore-space values)))
13548 (defun org-entry-protect-space (s)
13549 "Protect spaces and newline in string S."
13550 (while (string-match " " s)
13551 (setq s (replace-match "%20" t t s)))
13552 (while (string-match "\n" s)
13553 (setq s (replace-match "%0A" t t s)))
13556 (defun org-entry-restore-space (s)
13557 "Restore spaces and newline in string S."
13558 (while (string-match "%20" s)
13559 (setq s (replace-match " " t t s)))
13560 (while (string-match "%0A" s)
13561 (setq s (replace-match "\n" t t s)))
13564 (defvar org-entry-property-inherited-from (make-marker)
13565 "Marker pointing to the entry from where a property was inherited.
13566 Each call to `org-entry-get-with-inheritance' will set this marker to the
13567 location of the entry where the inheritance search matched. If there was
13568 no match, the marker will point nowhere.
13569 Note that also `org-entry-get' calls this function, if the INHERIT flag
13572 (defun org-entry-get-with-inheritance (property &optional literal-nil)
13573 "Get entry property, and search higher levels if not present.
13574 The search will stop at the first ancestor which has the property defined.
13575 If the value found is \"nil\", return nil to show that the property
13576 should be considered as undefined (this is the meaning of nil here).
13577 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
13578 (move-marker org-entry-property-inherited-from nil)
13585 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
13586 (org-back-to-heading t)
13587 (move-marker org-entry-property-inherited-from (point))
13589 (or (org-up-heading-safe) (throw 'ex nil)))))
13591 (cdr (assoc property org-file-properties))
13592 (cdr (assoc property org-global-properties))
13593 (cdr (assoc property org-global-properties-fixed))))
13594 (if literal-nil tmp (org-not-nil tmp)))))
13596 (defvar org-property-changed-functions nil
13597 "Hook called when the value of a property has changed.
13598 Each hook function should accept two arguments, the name of the property
13599 and the new value.")
13601 (defun org-entry-put (pom property value)
13602 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13603 (org-with-point-at pom
13604 (org-back-to-heading t)
13605 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13608 ((equal property "TODO")
13609 (when (and (stringp value) (string-match "\\S-" value)
13610 (not (member value org-todo-keywords-1)))
13611 (error "\"%s\" is not a valid TODO state" value))
13612 (if (or (not value)
13613 (not (string-match "\\S-" value)))
13614 (setq value 'none))
13616 (org-set-tags nil 'align))
13617 ((equal property "PRIORITY")
13618 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13619 (string-to-char value) ?\ ))
13620 (org-set-tags nil 'align))
13621 ((equal property "SCHEDULED")
13622 (if (re-search-forward org-scheduled-time-regexp end t)
13624 ((eq value 'earlier) (org-timestamp-change -1 'day))
13625 ((eq value 'later) (org-timestamp-change 1 'day))
13626 (t (call-interactively 'org-schedule)))
13627 (call-interactively 'org-schedule)))
13628 ((equal property "DEADLINE")
13629 (if (re-search-forward org-deadline-time-regexp end t)
13631 ((eq value 'earlier) (org-timestamp-change -1 'day))
13632 ((eq value 'later) (org-timestamp-change 1 'day))
13633 (t (call-interactively 'org-deadline)))
13634 (call-interactively 'org-deadline)))
13635 ((member property org-special-properties)
13636 (error "The %s property can not yet be set with `org-entry-put'"
13638 (t ; a non-special property
13639 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13640 (setq range (org-get-property-block beg end 'force))
13641 (goto-char (car range))
13642 (if (re-search-forward
13643 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13645 (delete-region (match-beginning 1) (match-end 1))
13646 (goto-char (match-beginning 1)))
13647 (goto-char (cdr range))
13650 (org-indent-line-function)
13651 (insert ":" property ":"))
13652 (and value (insert " " value))
13653 (org-indent-line-function)))))
13654 (run-hook-with-args 'org-property-changed-functions property value)))
13656 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13657 "Get all property keys in the current buffer.
13658 With INCLUDE-SPECIALS, also list the special properties that reflect things
13659 like tags and TODO state.
13660 With INCLUDE-DEFAULTS, also include properties that has special meaning
13661 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13662 With INCLUDE-COLUMNS, also include property names given in COLUMN
13663 formats in the current buffer."
13664 (let (rtn range cfmt s p)
13668 (goto-char (point-min))
13669 (while (re-search-forward org-property-start-re nil t)
13670 (setq range (org-get-property-block))
13671 (goto-char (car range))
13672 (while (re-search-forward
13673 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13675 (add-to-list 'rtn (org-match-string-no-properties 1)))
13676 (outline-next-heading))))
13678 (when include-specials
13679 (setq rtn (append org-special-properties rtn)))
13681 (when include-defaults
13682 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13683 (add-to-list 'rtn org-effort-property))
13685 (when include-columns
13689 (goto-char (point-min))
13690 (while (re-search-forward
13691 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13693 (setq cfmt (match-string 2) s 0)
13694 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13696 (setq s (match-end 0)
13697 p (match-string 1 cfmt))
13698 (unless (or (equal p "ITEM")
13699 (member p org-special-properties))
13700 (add-to-list 'rtn (match-string 1 cfmt))))))))
13702 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13704 (defun org-property-values (key)
13705 "Return a list of all values of property KEY."
13709 (goto-char (point-min))
13710 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13712 (while (re-search-forward re nil t)
13713 (add-to-list 'values (org-trim (match-string 1))))
13714 (delete "" values)))))
13716 (defun org-insert-property-drawer ()
13717 "Insert a property drawer into the current entry."
13719 (org-back-to-heading t)
13720 (looking-at outline-regexp)
13721 (let ((indent (if org-adapt-indentation
13722 (- (match-end 0)(match-beginning 0))
13725 (re (concat "^[ \t]*" org-keyword-time-regexp))
13727 (outline-next-heading)
13730 (while (re-search-forward re end t))
13731 (setq hiddenp (org-invisible-p))
13733 (and (equal (char-after) ?\n) (forward-char 1))
13734 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13735 (if (member (match-string 1) '("CLOCK:" ":END:"))
13736 ;; just skip this line
13737 (beginning-of-line 2)
13738 ;; Drawer start, find the end
13739 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13740 (beginning-of-line 1)))
13741 (org-skip-over-state-notes)
13742 (skip-chars-backward " \t\n\r")
13743 (if (eq (char-before) ?*) (forward-char 1))
13744 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13745 (beginning-of-line 0)
13746 (org-indent-to-column indent)
13747 (beginning-of-line 2)
13748 (org-indent-to-column indent)
13749 (beginning-of-line 0)
13752 (org-back-to-heading t)
13754 (org-flag-drawer t))))
13756 (defun org-set-property (property value)
13757 "In the current entry, set PROPERTY to VALUE.
13758 When called interactively, this will prompt for a property name, offering
13759 completion on existing and default properties. And then it will prompt
13760 for a value, offering completion either on allowed values (via an inherited
13761 xxx_ALL property) or on existing values in other instances of this property
13762 in the current file."
13764 (let* ((completion-ignore-case t)
13765 (keys (org-buffer-property-keys nil t t))
13766 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13767 (prop (if (member prop0 keys)
13769 (or (cdr (assoc (downcase prop0)
13770 (mapcar (lambda (x) (cons (downcase x) x))
13773 (cur (org-entry-get nil prop))
13774 (prompt (concat prop " value"
13775 (if (and cur (string-match "\\S-" cur))
13776 (concat " [" cur "]") "") ": "))
13777 (allowed (org-property-get-allowed-values nil prop 'table))
13778 (existing (mapcar 'list (org-property-values prop)))
13780 (org-completing-read prompt allowed nil
13781 (not (get-text-property 0 'org-unrestricted
13783 (let (org-completion-use-ido org-completion-use-iswitchb)
13784 (org-completing-read prompt existing nil nil "" nil cur)))))
13785 (list prop (if (equal val "") cur val))))
13786 (unless (equal (org-entry-get nil property) value)
13787 (org-entry-put nil property value)))
13789 (defun org-delete-property (property)
13790 "In the current entry, delete PROPERTY."
13792 (let* ((completion-ignore-case t)
13793 (prop (org-icompleting-read "Property: "
13794 (org-entry-properties nil 'standard))))
13796 (message "Property %s %s" property
13797 (if (org-entry-delete nil property)
13799 "was not present in the entry")))
13801 (defun org-delete-property-globally (property)
13802 "Remove PROPERTY globally, from all entries."
13804 (let* ((completion-ignore-case t)
13805 (prop (org-icompleting-read
13806 "Globally remove property: "
13807 (mapcar 'list (org-buffer-property-keys)))))
13812 (goto-char (point-min))
13814 (while (re-search-forward
13815 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13817 (setq cnt (1+ cnt))
13818 (replace-match ""))
13819 (message "Property \"%s\" removed from %d entries" property cnt)))))
13821 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13823 (defun org-compute-property-at-point ()
13824 "Compute the property at point.
13825 This looks for an enclosing column format, extracts the operator and
13826 then applies it to the property in the column format's scope."
13828 (unless (org-at-property-p)
13829 (error "Not at a property"))
13830 (let ((prop (org-match-string-no-properties 2)))
13831 (org-columns-get-format-and-top-level)
13832 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13833 (error "No operator defined for property %s" prop))
13834 (org-columns-compute prop)))
13836 (defvar org-property-allowed-value-functions nil
13837 "Hook for functions supplying allowed values for a specific property.
13838 The functions must take a single argument, the name of the property, and
13839 return a flat list of allowed values. If \":ETC\" is one of
13840 the values, this means that these values are intended as defaults for
13841 completion, but that other values should be allowed too.
13842 The functions must return nil if they are not responsible for this
13845 (defun org-property-get-allowed-values (pom property &optional table)
13846 "Get allowed values for the property PROPERTY.
13847 When TABLE is non-nil, return an alist that can directly be used for
13851 ((equal property "TODO")
13852 (setq vals (org-with-point-at pom
13853 (append org-todo-keywords-1 '("")))))
13854 ((equal property "PRIORITY")
13855 (let ((n org-lowest-priority))
13856 (while (>= n org-highest-priority)
13857 (push (char-to-string n) vals)
13859 ((member property org-special-properties))
13860 ((setq vals (run-hook-with-args-until-success
13861 'org-property-allowed-value-functions property)))
13863 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13864 (when (and vals (string-match "\\S-" vals))
13865 (setq vals (car (read-from-string (concat "(" vals ")"))))
13866 (setq vals (mapcar (lambda (x)
13867 (cond ((stringp x) x)
13868 ((numberp x) (number-to-string x))
13869 ((symbolp x) (symbol-name x))
13872 (when (member ":ETC" vals)
13873 (setq vals (remove ":ETC" vals))
13874 (org-add-props (car vals) '(org-unrestricted t)))
13875 (if table (mapcar 'list vals) vals)))
13877 (defun org-property-previous-allowed-value (&optional previous)
13878 "Switch to the next allowed value for this property."
13880 (org-property-next-allowed-value t))
13882 (defun org-property-next-allowed-value (&optional previous)
13883 "Switch to the next allowed value for this property."
13885 (unless (org-at-property-p)
13886 (error "Not at a property"))
13887 (let* ((key (match-string 2))
13888 (value (match-string 3))
13889 (allowed (or (org-property-get-allowed-values (point) key)
13890 (and (member value '("[ ]" "[-]" "[X]"))
13894 (error "Allowed values for this property have not been defined"))
13895 (if previous (setq allowed (reverse allowed)))
13896 (if (member value allowed)
13897 (setq nval (car (cdr (member value allowed)))))
13898 (setq nval (or nval (car allowed)))
13899 (if (equal nval value)
13900 (error "Only one allowed value for this property"))
13901 (org-at-property-p)
13902 (replace-match (concat " :" key ": " nval) t t)
13903 (org-indent-line-function)
13904 (beginning-of-line 1)
13905 (skip-chars-forward " \t")
13906 (run-hook-with-args 'org-property-changed-functions key nval)))
13908 (defun org-find-olp (path &optional this-buffer)
13909 "Return a marker pointing to the entry at outline path OLP.
13910 If anything goes wrong, throw an error.
13911 You can wrap this call to cathc the error like this:
13913 (condition-case msg
13914 (org-mobile-locate-entry (match-string 4))
13915 (error (nth 1 msg)))
13917 The return value will then be either a string with the error message,
13918 or a marker if everyhing is OK.
13920 If THIS-BUFFER is set, the putline path does not contain a file,
13922 (let* ((file (if this-buffer buffer-file-name (pop path)))
13923 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
13927 limit re end found pos heading cnt)
13928 (unless buffer (error "File not found :%s" file))
13929 (with-current-buffer buffer
13933 (setq limit (point-max))
13934 (goto-char (point-min))
13935 (while (setq heading (pop path))
13936 (setq re (format org-complex-heading-regexp-format
13937 (regexp-quote heading)))
13938 (setq cnt 0 pos (point))
13939 (while (re-search-forward re end t)
13940 (setq level (- (match-end 1) (match-beginning 1)))
13941 (if (and (>= level lmin) (<= level lmax))
13942 (setq found (match-beginning 0) cnt (1+ cnt))))
13943 (when (= cnt 0) (error "Heading not found on level %d: %s"
13945 (when (> cnt 1) (error "Heading not unique on level %d: %s"
13948 (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0)))
13949 (setq end (save-excursion (org-end-of-subtree t t))))
13950 (when (org-on-heading-p)
13951 (move-marker (make-marker) (point))))))))
13953 (defun org-find-entry-with-id (ident)
13954 "Locate the entry that contains the ID property with exact value IDENT.
13955 IDENT can be a string, a symbol or a number, this function will search for
13956 the string representation of it.
13957 Return the position where this entry starts, or nil if there is no such entry."
13958 (interactive "sID: ")
13960 ((stringp ident) ident)
13961 ((symbol-name ident) (symbol-name ident))
13962 ((numberp ident) (number-to-string ident))
13963 (t (error "IDENT %s must be a string, symbol or number" ident))))
13964 (case-fold-search nil))
13968 (goto-char (point-min))
13969 (when (re-search-forward
13970 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13972 (org-back-to-heading t)
13977 (defvar org-last-changed-timestamp nil)
13978 (defvar org-last-inserted-timestamp nil
13979 "The last time stamp inserted with `org-insert-time-stamp'.")
13980 (defvar org-time-was-given) ; dynamically scoped parameter
13981 (defvar org-end-time-was-given) ; dynamically scoped parameter
13982 (defvar org-ts-what) ; dynamically scoped parameter
13984 (defun org-time-stamp (arg &optional inactive)
13985 "Prompt for a date/time and insert a time stamp.
13986 If the user specifies a time like HH:MM, or if this command is called
13987 with a prefix argument, the time stamp will contain date and time.
13988 Otherwise, only the date will be included. All parts of a date not
13989 specified by the user will be filled in from the current date/time.
13990 So if you press just return without typing anything, the time stamp
13991 will represent the current date/time. If there is already a timestamp
13992 at the cursor, it will be modified."
13996 ;; Default time is either today, or, when entering a range,
13997 ;; the range start.
13998 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
14000 (re-search-backward
14001 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
14002 (- (point) 20) t)))
14003 (apply 'encode-time (org-parse-time-string (match-string 1)))
14005 (default-input (and ts (org-get-compact-tod ts)))
14006 org-time-was-given org-end-time-was-given time)
14008 ((and (org-at-timestamp-p t)
14009 (memq last-command '(org-time-stamp org-time-stamp-inactive))
14010 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
14012 (setq time (let ((this-command this-command))
14013 (org-read-date arg 'totime nil nil
14014 default-time default-input)))
14015 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
14016 ((org-at-timestamp-p t)
14017 (setq time (let ((this-command this-command))
14018 (org-read-date arg 'totime nil nil default-time default-input)))
14019 (when (org-at-timestamp-p t) ; just to get the match data
14020 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
14022 (setq org-last-changed-timestamp
14023 (org-insert-time-stamp
14024 time (or org-time-was-given arg)
14025 inactive nil nil (list org-end-time-was-given))))
14026 (message "Timestamp updated"))
14028 (setq time (let ((this-command this-command))
14029 (org-read-date arg 'totime nil nil default-time default-input)))
14030 (org-insert-time-stamp time (or org-time-was-given arg) inactive
14031 nil nil (list org-end-time-was-given))))))
14033 ;; FIXME: can we use this for something else, like computing time differences?
14034 (defun org-get-compact-tod (s)
14035 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
14036 (let* ((t1 (match-string 1 s))
14037 (h1 (string-to-number (match-string 2 s)))
14038 (m1 (string-to-number (match-string 3 s)))
14039 (t2 (and (match-end 4) (match-string 5 s)))
14040 (h2 (and t2 (string-to-number (match-string 6 s))))
14041 (m2 (and t2 (string-to-number (match-string 7 s))))
14045 (setq dh (- h2 h1) dm (- m2 m1))
14046 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
14047 (concat t1 "+" (number-to-string dh)
14048 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
14050 (defun org-time-stamp-inactive (&optional arg)
14051 "Insert an inactive time stamp.
14052 An inactive time stamp is enclosed in square brackets instead of angle
14053 brackets. It is inactive in the sense that it does not trigger agenda entries,
14054 does not link to the calendar and cannot be changed with the S-cursor keys.
14055 So these are more for recording a certain time/date."
14057 (org-time-stamp arg 'inactive))
14059 (defvar org-date-ovl (make-overlay 1 1))
14060 (overlay-put org-date-ovl 'face 'org-warning)
14061 (org-detach-overlay org-date-ovl)
14063 (defvar org-ans1) ; dynamically scoped parameter
14064 (defvar org-ans2) ; dynamically scoped parameter
14066 (defvar org-plain-time-of-day-regexp) ; defined below
14068 (defvar org-overriding-default-time nil) ; dynamically scoped
14069 (defvar org-read-date-overlay nil)
14070 (defvar org-dcst nil) ; dynamically scoped
14071 (defvar org-read-date-history nil)
14072 (defvar org-read-date-final-answer nil)
14074 (defun org-read-date (&optional with-time to-time from-string prompt
14075 default-time default-input)
14076 "Read a date, possibly a time, and make things smooth for the user.
14077 The prompt will suggest to enter an ISO date, but you can also enter anything
14078 which will at least partially be understood by `parse-time-string'.
14079 Unrecognized parts of the date will default to the current day, month, year,
14080 hour and minute. If this command is called to replace a timestamp at point,
14081 of to enter the second timestamp of a range, the default time is taken
14082 from the existing stamp. Furthermore, the command prefers the future,
14083 so if you are giving a date where the year is not given, and the day-month
14084 combination is already past in the current year, it will assume you
14085 mean next year. For details, see the manual. A few examples:
14087 3-2-5 --> 2003-02-05
14088 feb 15 --> currentyear-02-15
14089 2/15 --> currentyear-02-15
14090 sep 12 9 --> 2009-09-12
14091 12:45 --> today 12:45
14092 22 sept 0:34 --> currentyear-09-22 0:34
14093 12 --> currentyear-currentmonth-12
14094 Fri --> nearest Friday (today or later)
14097 Furthermore you can specify a relative date by giving, as the *first* thing
14098 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
14099 change in days weeks, months, years.
14100 With a single plus or minus, the date is relative to today. With a double
14101 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
14102 +4d --> four days from today
14103 +4 --> same as above
14104 +2w --> two weeks from today
14105 ++5 --> five days from default date
14107 The function understands only English month and weekday abbreviations,
14108 but this can be configured with the variables `parse-time-months' and
14109 `parse-time-weekdays'.
14111 While prompting, a calendar is popped up - you can also select the
14112 date with the mouse (button 1). The calendar shows a period of three
14113 months. To scroll it to other months, use the keys `>' and `<'.
14114 If you don't like the calendar, turn it off with
14115 \(setq org-read-date-popup-calendar nil)
14117 With optional argument TO-TIME, the date will immediately be converted
14118 to an internal time.
14119 With an optional argument WITH-TIME, the prompt will suggest to also
14120 insert a time. Note that when WITH-TIME is not set, you can still
14121 enter a time, and this function will inform the calling routine about
14122 this change. The calling routine may then choose to change the format
14123 used to insert the time stamp into the buffer to include the time.
14124 With optional argument FROM-STRING, read from this string instead from
14125 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
14126 the time/date that is used for everything that is not specified by the
14128 (require 'parse-time)
14129 (let* ((org-time-stamp-rounding-minutes
14130 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
14131 (org-dcst org-display-custom-times)
14132 (ct (org-current-time))
14133 (def (or org-overriding-default-time default-time ct))
14134 (defdecode (decode-time def))
14136 (when (< (nth 2 defdecode) org-extend-today-until)
14137 (setcar (nthcdr 2 defdecode) -1)
14138 (setcar (nthcdr 1 defdecode) 59)
14139 (setq def (apply 'encode-time defdecode)
14140 defdecode (decode-time def)))))
14141 (calendar-frame-setup nil)
14142 (calendar-setup nil)
14143 (calendar-move-hook nil)
14144 (calendar-view-diary-initially-flag nil)
14145 (calendar-view-holidays-initially-flag nil)
14146 (timestr (format-time-string
14147 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
14148 (prompt (concat (if prompt (concat prompt " ") "")
14149 (format "Date+time [%s]: " timestr)))
14150 ans (org-ans0 "") org-ans1 org-ans2 final)
14153 (from-string (setq ans from-string))
14154 (org-read-date-popup-calendar
14156 (save-window-excursion
14158 (calendar-forward-day (- (time-to-days def)
14159 (calendar-absolute-from-gregorian
14160 (calendar-current-date))))
14161 (org-eval-in-calendar nil t)
14162 (let* ((old-map (current-local-map))
14163 (map (copy-keymap calendar-mode-map))
14164 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
14165 (org-defkey map (kbd "RET") 'org-calendar-select)
14166 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
14167 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
14168 (org-defkey minibuffer-local-map [(meta shift left)]
14169 (lambda () (interactive)
14170 (org-eval-in-calendar '(calendar-backward-month 1))))
14171 (org-defkey minibuffer-local-map [(meta shift right)]
14172 (lambda () (interactive)
14173 (org-eval-in-calendar '(calendar-forward-month 1))))
14174 (org-defkey minibuffer-local-map [(meta shift up)]
14175 (lambda () (interactive)
14176 (org-eval-in-calendar '(calendar-backward-year 1))))
14177 (org-defkey minibuffer-local-map [(meta shift down)]
14178 (lambda () (interactive)
14179 (org-eval-in-calendar '(calendar-forward-year 1))))
14180 (org-defkey minibuffer-local-map [?\e (shift left)]
14181 (lambda () (interactive)
14182 (org-eval-in-calendar '(calendar-backward-month 1))))
14183 (org-defkey minibuffer-local-map [?\e (shift right)]
14184 (lambda () (interactive)
14185 (org-eval-in-calendar '(calendar-forward-month 1))))
14186 (org-defkey minibuffer-local-map [?\e (shift up)]
14187 (lambda () (interactive)
14188 (org-eval-in-calendar '(calendar-backward-year 1))))
14189 (org-defkey minibuffer-local-map [?\e (shift down)]
14190 (lambda () (interactive)
14191 (org-eval-in-calendar '(calendar-forward-year 1))))
14192 (org-defkey minibuffer-local-map [(shift up)]
14193 (lambda () (interactive)
14194 (org-eval-in-calendar '(calendar-backward-week 1))))
14195 (org-defkey minibuffer-local-map [(shift down)]
14196 (lambda () (interactive)
14197 (org-eval-in-calendar '(calendar-forward-week 1))))
14198 (org-defkey minibuffer-local-map [(shift left)]
14199 (lambda () (interactive)
14200 (org-eval-in-calendar '(calendar-backward-day 1))))
14201 (org-defkey minibuffer-local-map [(shift right)]
14202 (lambda () (interactive)
14203 (org-eval-in-calendar '(calendar-forward-day 1))))
14204 (org-defkey minibuffer-local-map ">"
14205 (lambda () (interactive)
14206 (org-eval-in-calendar '(scroll-calendar-left 1))))
14207 (org-defkey minibuffer-local-map "<"
14208 (lambda () (interactive)
14209 (org-eval-in-calendar '(scroll-calendar-right 1))))
14210 (org-defkey minibuffer-local-map "\C-v"
14211 (lambda () (interactive)
14212 (org-eval-in-calendar
14213 '(calendar-scroll-left-three-months 1))))
14214 (org-defkey minibuffer-local-map "\M-v"
14215 (lambda () (interactive)
14216 (org-eval-in-calendar
14217 '(calendar-scroll-right-three-months 1))))
14218 (run-hooks 'org-read-date-minibuffer-setup-hook)
14221 (use-local-map map)
14222 (add-hook 'post-command-hook 'org-read-date-display)
14223 (setq org-ans0 (read-string prompt default-input
14224 'org-read-date-history nil))
14225 ;; org-ans0: from prompt
14226 ;; org-ans1: from mouse click
14227 ;; org-ans2: from calendar motion
14228 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
14229 (remove-hook 'post-command-hook 'org-read-date-display)
14230 (use-local-map old-map)
14231 (when org-read-date-overlay
14232 (delete-overlay org-read-date-overlay)
14233 (setq org-read-date-overlay nil)))))))
14235 (t ; Naked prompt only
14237 (setq ans (read-string prompt default-input
14238 'org-read-date-history timestr))
14239 (when org-read-date-overlay
14240 (delete-overlay org-read-date-overlay)
14241 (setq org-read-date-overlay nil)))))
14243 (setq final (org-read-date-analyze ans def defdecode))
14244 (setq org-read-date-final-answer ans)
14247 (apply 'encode-time final)
14248 (if (and (boundp 'org-time-was-given) org-time-was-given)
14249 (format "%04d-%02d-%02d %02d:%02d"
14250 (nth 5 final) (nth 4 final) (nth 3 final)
14251 (nth 2 final) (nth 1 final))
14252 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
14257 (defvar org-read-date-analyze-futurep nil)
14258 (defun org-read-date-display ()
14259 "Display the current date prompt interpretation in the minibuffer."
14260 (when org-read-date-display-live
14261 (when org-read-date-overlay
14262 (delete-overlay org-read-date-overlay))
14265 (while (not (equal (buffer-substring
14266 (max (point-min) (- (point) 4)) (point))
14270 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
14271 " " (or org-ans1 org-ans2)))
14272 (org-end-time-was-given nil)
14273 (f (org-read-date-analyze ans def defdecode))
14275 org-time-stamp-custom-formats
14276 org-time-stamp-formats))
14277 (fmt (if (or with-time
14278 (and (boundp 'org-time-was-given) org-time-was-given))
14281 (txt (concat "=> " (format-time-string fmt (apply 'encode-time f)))))
14282 (when (and org-end-time-was-given
14283 (string-match org-plain-time-of-day-regexp txt))
14284 (setq txt (concat (substring txt 0 (match-end 0)) "-"
14285 org-end-time-was-given
14286 (substring txt (match-end 0)))))
14287 (when org-read-date-analyze-futurep
14288 (setq txt (concat txt " (=>F)")))
14289 (setq org-read-date-overlay
14290 (make-overlay (1- (point-at-eol)) (point-at-eol)))
14291 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
14293 (defun org-read-date-analyze (ans def defdecode)
14294 "Analyse the combined answer of the date prompt."
14295 ;; FIXME: cleanup and comment
14296 (let ((nowdecode (decode-time (current-time)))
14297 delta deltan deltaw deltadef year month day
14298 hour minute second wday pm h2 m2 tl wday1
14299 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
14300 (setq org-read-date-analyze-futurep nil)
14301 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
14304 (when (setq delta (org-read-date-get-relative ans (current-time) def))
14305 (setq ans (replace-match "" t t ans)
14307 deltaw (nth 1 delta)
14308 deltadef (nth 2 delta)))
14310 ;; Check if there is an iso week date in there
14311 ;; If yes, store the info and postpone interpreting it until the rest
14312 ;; of the parsing is done
14313 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
14314 (setq iso-year (if (match-end 1)
14315 (org-small-year-to-year
14316 (string-to-number (match-string 1 ans))))
14317 iso-weekday (if (match-end 3)
14318 (string-to-number (match-string 3 ans)))
14319 iso-week (string-to-number (match-string 2 ans)))
14320 (setq ans (replace-match "" t t ans)))
14322 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
14323 (when (string-match
14324 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
14325 (setq year (if (match-end 2)
14326 (string-to-number (match-string 2 ans))
14327 (progn (setq kill-year t)
14328 (string-to-number (format-time-string "%Y"))))
14329 month (string-to-number (match-string 3 ans))
14330 day (string-to-number (match-string 4 ans)))
14331 (if (< year 100) (setq year (+ 2000 year)))
14332 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14334 ;; Help matching american dates, like 5/30 or 5/30/7
14335 (when (string-match
14336 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
14337 (setq year (if (match-end 4)
14338 (string-to-number (match-string 4 ans))
14339 (progn (setq kill-year t)
14340 (string-to-number (format-time-string "%Y"))))
14341 month (string-to-number (match-string 1 ans))
14342 day (string-to-number (match-string 2 ans)))
14343 (if (< year 100) (setq year (+ 2000 year)))
14344 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14346 ;; Help matching am/pm times, because `parse-time-string' does not do that.
14347 ;; If there is a time with am/pm, and *no* time without it, we convert
14348 ;; so that matching will be successful.
14349 (loop for i from 1 to 2 do ; twice, for end time as well
14350 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
14351 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
14352 (setq hour (string-to-number (match-string 1 ans))
14353 minute (if (match-end 3)
14354 (string-to-number (match-string 3 ans))
14357 (string-to-char (downcase (match-string 4 ans)))))
14358 (if (and (= hour 12) (not pm))
14360 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
14361 (setq ans (replace-match (format "%02d:%02d" hour minute)
14364 ;; Check if a time range is given as a duration
14365 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
14366 (setq hour (string-to-number (match-string 1 ans))
14367 h2 (+ hour (string-to-number (match-string 3 ans)))
14368 minute (string-to-number (match-string 2 ans))
14369 m2 (+ minute (if (match-end 5) (string-to-number
14370 (match-string 5 ans))0)))
14371 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
14372 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
14375 ;; Check if there is a time range
14376 (when (boundp 'org-end-time-was-given)
14377 (setq org-time-was-given nil)
14378 (when (and (string-match org-plain-time-of-day-regexp ans)
14380 (setq org-end-time-was-given (match-string 8 ans))
14381 (setq ans (concat (substring ans 0 (match-beginning 7))
14382 (substring ans (match-end 7))))))
14384 (setq tl (parse-time-string ans)
14385 day (or (nth 3 tl) (nth 3 defdecode))
14386 month (or (nth 4 tl)
14387 (if (and org-read-date-prefer-future
14388 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
14389 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
14390 (nth 4 defdecode)))
14391 year (or (and (not kill-year) (nth 5 tl))
14392 (if (and org-read-date-prefer-future
14393 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
14394 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
14395 (nth 5 defdecode)))
14396 hour (or (nth 2 tl) (nth 2 defdecode))
14397 minute (or (nth 1 tl) (nth 1 defdecode))
14398 second (or (nth 0 tl) 0)
14401 (when (and (eq org-read-date-prefer-future 'time)
14402 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
14403 (equal day (nth 3 nowdecode))
14404 (equal month (nth 4 nowdecode))
14405 (equal year (nth 5 nowdecode))
14407 (or (< (nth 2 tl) (nth 2 nowdecode))
14408 (and (= (nth 2 tl) (nth 2 nowdecode))
14410 (< (nth 1 tl) (nth 1 nowdecode)))))
14414 ;; Special date definitions below
14417 ;; There was an iso week
14420 (setq year (or iso-year year)
14421 day (or iso-weekday wday 1)
14422 wday nil ; to make sure that the trigger below does not match
14423 iso-date (calendar-gregorian-from-absolute
14424 (calendar-absolute-from-iso
14425 (list iso-week day year))))
14426 ; FIXME: Should we also push ISO weeks into the future?
14427 ; (when (and org-read-date-prefer-future
14429 ; (< (calendar-absolute-from-gregorian iso-date)
14430 ; (time-to-days (current-time))))
14431 ; (setq year (1+ year)
14432 ; iso-date (calendar-gregorian-from-absolute
14433 ; (calendar-absolute-from-iso
14434 ; (list iso-week day year)))))
14435 (setq month (car iso-date)
14436 year (nth 2 iso-date)
14437 day (nth 1 iso-date)))
14441 (let ((now (decode-time (current-time))))
14442 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
14443 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
14444 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
14445 ((equal deltaw "m") (setq month (+ month deltan)))
14446 ((equal deltaw "y") (setq year (+ year deltan)))))
14447 ((and wday (not (nth 3 tl)))
14449 ;; Weekday was given, but no day, so pick that day in the week
14450 ;; on or after the derived date.
14451 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
14452 (unless (equal wday wday1)
14453 (setq day (+ day (% (- wday wday1 -7) 7))))))
14454 (if (and (boundp 'org-time-was-given)
14456 (setq org-time-was-given t))
14457 (if (< year 100) (setq year (+ 2000 year)))
14458 (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
14459 (setq org-read-date-analyze-futurep futurep)
14460 (list second minute hour day month year)))
14462 (defvar parse-time-weekdays)
14464 (defun org-read-date-get-relative (s today default)
14465 "Check string S for special relative date string.
14466 TODAY and DEFAULT are internal times, for today and for a default.
14467 Return shift list (N what def-flag)
14468 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
14469 N is the number of WHATs to shift.
14470 DEF-FLAG is t when a double ++ or -- indicates shift relative to
14471 the DEFAULT date rather than TODAY."
14475 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
14477 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
14478 "\\([ \t]\\|$\\)") s)
14479 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
14480 (let* ((dir (if (> (match-end 1) (match-beginning 1))
14481 (string-to-char (substring (match-string 1 s) -1))
14483 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
14484 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
14485 (what (if (match-end 3) (match-string 3 s) "d"))
14486 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
14487 (date (if rel default today))
14488 (wday (nth 6 (decode-time date)))
14492 (setq delta (mod (+ 7 (- wday1 wday)) 7))
14493 (if (= dir ?-) (setq delta (- delta 7)))
14494 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
14495 (list delta "d" rel))
14496 (list (* n (if (= dir ?-) -1 1)) what rel)))))
14498 (defun org-order-calendar-date-args (arg1 arg2 arg3)
14499 "Turn a user-specified date into the internal representation.
14500 The internal representation needed by the calendar is (month day year).
14501 This is a wrapper to handle the brain-dead convention in calendar that
14502 user function argument order change dependent on argument order."
14503 (if (boundp 'calendar-date-style)
14505 ((eq calendar-date-style 'american)
14506 (list arg1 arg2 arg3))
14507 ((eq calendar-date-style 'european)
14508 (list arg2 arg1 arg3))
14509 ((eq calendar-date-style 'iso)
14510 (list arg2 arg3 arg1)))
14511 (if (org-bound-and-true-p european-calendar-style)
14512 (list arg2 arg1 arg3)
14513 (list arg1 arg2 arg3))))
14515 (defun org-eval-in-calendar (form &optional keepdate)
14516 "Eval FORM in the calendar window and return to current window.
14517 Also, store the cursor date in variable org-ans2."
14518 (let ((sf (selected-frame))
14519 (sw (selected-window)))
14520 (select-window (get-buffer-window "*Calendar*" t))
14522 (when (and (not keepdate) (calendar-cursor-to-date))
14523 (let* ((date (calendar-cursor-to-date))
14524 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14525 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
14526 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
14528 (org-select-frame-set-input-focus sf)))
14530 (defun org-calendar-select ()
14531 "Return to `org-read-date' with the date currently selected.
14532 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14534 (when (calendar-cursor-to-date)
14535 (let* ((date (calendar-cursor-to-date))
14536 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14537 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14538 (if (active-minibuffer-window) (exit-minibuffer))))
14540 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
14541 "Insert a date stamp for the date given by the internal TIME.
14542 WITH-HM means use the stamp format that includes the time of the day.
14543 INACTIVE means use square brackets instead of angular ones, so that the
14544 stamp will not contribute to the agenda.
14545 PRE and POST are optional strings to be inserted before and after the
14547 The command returns the inserted time stamp."
14548 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
14550 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
14551 (insert-before-markers (or pre ""))
14552 (insert-before-markers (setq stamp (format-time-string fmt time)))
14553 (when (listp extra)
14554 (setq extra (car extra))
14555 (if (and (stringp extra)
14556 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
14557 (setq extra (format "-%02d:%02d"
14558 (string-to-number (match-string 1 extra))
14559 (string-to-number (match-string 2 extra))))
14563 (insert-before-markers extra)
14565 (insert-before-markers (or post ""))
14566 (setq org-last-inserted-timestamp stamp)))
14568 (defun org-toggle-time-stamp-overlays ()
14569 "Toggle the use of custom time stamp formats."
14571 (setq org-display-custom-times (not org-display-custom-times))
14572 (unless org-display-custom-times
14573 (let ((p (point-min)) (bmp (buffer-modified-p)))
14574 (while (setq p (next-single-property-change p 'display))
14575 (if (and (get-text-property p 'display)
14576 (eq (get-text-property p 'face) 'org-date))
14577 (remove-text-properties
14578 p (setq p (next-single-property-change p 'display))
14580 (set-buffer-modified-p bmp)))
14581 (if (featurep 'xemacs)
14582 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
14583 (org-restart-font-lock)
14584 (setq org-table-may-need-update t)
14585 (if org-display-custom-times
14586 (message "Time stamps are overlayed with custom format")
14587 (message "Time stamp overlays removed")))
14589 (defun org-display-custom-time (beg end)
14590 "Overlay modified time stamp format over timestamp between BEG and END."
14591 (let* ((ts (buffer-substring beg end))
14592 t1 w1 with-hm tf time str w2 (off 0))
14594 (setq t1 (org-parse-time-string ts t))
14595 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
14596 (setq off (- (match-end 0) (match-beginning 0)))))
14597 (setq end (- end off))
14598 (setq w1 (- end beg)
14599 with-hm (and (nth 1 t1) (nth 2 t1))
14600 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
14601 time (org-fix-decoded-time t1)
14603 (format-time-string
14604 (substring tf 1 -1) (apply 'encode-time time))
14605 nil 'mouse-face 'highlight)
14607 (if (not (= w2 w1))
14608 (add-text-properties (1+ beg) (+ 2 beg)
14609 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
14610 (if (featurep 'xemacs)
14612 (put-text-property beg end 'invisible t)
14613 (put-text-property beg end 'end-glyph (make-glyph str)))
14614 (put-text-property beg end 'display str))))
14616 (defun org-translate-time (string)
14617 "Translate all timestamps in STRING to custom format.
14618 But do this only if the variable `org-display-custom-times' is set."
14619 (when org-display-custom-times
14622 (re org-ts-regexp-both)
14623 t1 with-hm inactive tf time str beg end)
14624 (while (setq start (string-match re string start))
14625 (setq beg (match-beginning 0)
14627 t1 (save-match-data
14628 (org-parse-time-string (substring string beg end) t))
14629 with-hm (and (nth 1 t1) (nth 2 t1))
14630 inactive (equal (substring string beg (1+ beg)) "[")
14631 tf (funcall (if with-hm 'cdr 'car)
14632 org-time-stamp-custom-formats)
14633 time (org-fix-decoded-time t1)
14634 str (format-time-string
14636 (if inactive "[" "<") (substring tf 1 -1)
14637 (if inactive "]" ">"))
14638 (apply 'encode-time time))
14639 string (replace-match str t t string)
14640 start (+ start (length str)))))))
14643 (defun org-fix-decoded-time (time)
14644 "Set 0 instead of nil for the first 6 elements of time.
14645 Don't touch the rest."
14647 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
14649 (defun org-days-to-time (timestamp-string)
14650 "Difference between TIMESTAMP-STRING and now in days."
14651 (- (time-to-days (org-time-string-to-time timestamp-string))
14652 (time-to-days (current-time))))
14654 (defun org-deadline-close (timestamp-string &optional ndays)
14655 "Is the time in TIMESTAMP-STRING close to the current date?"
14656 (setq ndays (or ndays (org-get-wdays timestamp-string)))
14657 (and (< (org-days-to-time timestamp-string) ndays)
14658 (not (org-entry-is-done-p))))
14660 (defun org-get-wdays (ts)
14661 "Get the deadline lead time appropriate for timestring TS."
14663 ((<= org-deadline-warning-days 0)
14664 ;; 0 or negative, enforce this value no matter what
14665 (- org-deadline-warning-days))
14666 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
14667 ;; lead time is specified.
14668 (floor (* (string-to-number (match-string 1 ts))
14669 (cdr (assoc (match-string 2 ts)
14670 '(("d" . 1) ("w" . 7)
14671 ("m" . 30.4) ("y" . 365.25)))))))
14672 ;; go for the default.
14673 (t org-deadline-warning-days)))
14675 (defun org-calendar-select-mouse (ev)
14676 "Return to `org-read-date' with the date currently selected.
14677 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14679 (mouse-set-point ev)
14680 (when (calendar-cursor-to-date)
14681 (let* ((date (calendar-cursor-to-date))
14682 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14683 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14684 (if (active-minibuffer-window) (exit-minibuffer))))
14686 (defun org-check-deadlines (ndays)
14687 "Check if there are any deadlines due or past due.
14688 A deadline is considered due if it happens within `org-deadline-warning-days'
14689 days from today's date. If the deadline appears in an entry marked DONE,
14690 it is not shown. The prefix arg NDAYS can be used to test that many
14691 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14693 (let* ((org-warn-days
14695 ((equal ndays '(4)) 100000)
14696 (ndays (prefix-numeric-value ndays))
14697 (t (abs org-deadline-warning-days))))
14698 (case-fold-search nil)
14699 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
14701 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
14703 (message "%d deadlines past-due or due within %d days"
14704 (org-occur regexp nil callback)
14707 (defun org-check-before-date (date)
14708 "Check if there are deadlines or scheduled entries before DATE."
14709 (interactive (list (org-read-date)))
14710 (let ((case-fold-search nil)
14711 (regexp (concat "\\<\\(" org-deadline-string
14712 "\\|" org-scheduled-string
14713 "\\) *<\\([^>]+\\)>"))
14715 (lambda () (time-less-p
14716 (org-time-string-to-time (match-string 2))
14717 (org-time-string-to-time date)))))
14718 (message "%d entries before %s"
14719 (org-occur regexp nil callback) date)))
14721 (defun org-check-after-date (date)
14722 "Check if there are deadlines or scheduled entries after DATE."
14723 (interactive (list (org-read-date)))
14724 (let ((case-fold-search nil)
14725 (regexp (concat "\\<\\(" org-deadline-string
14726 "\\|" org-scheduled-string
14727 "\\) *<\\([^>]+\\)>"))
14731 (org-time-string-to-time (match-string 2))
14732 (org-time-string-to-time date))))))
14733 (message "%d entries after %s"
14734 (org-occur regexp nil callback) date)))
14736 (defun org-evaluate-time-range (&optional to-buffer)
14737 "Evaluate a time range by computing the difference between start and end.
14738 Normally the result is just printed in the echo area, but with prefix arg
14739 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14740 If the time range is actually in a table, the result is inserted into the
14742 For time difference computation, a year is assumed to be exactly 365
14743 days in order to avoid rounding problems."
14746 (org-clock-update-time-maybe)
14748 (unless (org-at-date-range-p t)
14749 (goto-char (point-at-bol))
14750 (re-search-forward org-tr-regexp-both (point-at-eol) t))
14751 (if (not (org-at-date-range-p t))
14752 (error "Not at a time-stamp range, and none found in current line")))
14753 (let* ((ts1 (match-string 1))
14754 (ts2 (match-string 2))
14755 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
14756 (match-end (match-end 0))
14757 (time1 (org-time-string-to-time ts1))
14758 (time2 (org-time-string-to-time ts2))
14759 (t1 (org-float-time time1))
14760 (t2 (org-float-time time2))
14761 (diff (abs (- t2 t1)))
14762 (negative (< (- t2 t1) 0))
14763 ;; (ys (floor (* 365 24 60 60)))
14766 (fy "%dy %dd %02d:%02d")
14768 (fd "%dd %02d:%02d")
14773 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14775 d (floor (/ diff ds)) diff (mod diff ds)
14776 h (floor (/ diff hs)) diff (mod diff hs)
14777 m (floor (/ diff 60)))
14778 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14780 d (floor (+ (/ diff ds) 0.5))
14782 (if (not to-buffer)
14783 (message "%s" (org-make-tdiff-string y d h m))
14784 (if (org-at-table-p)
14786 (goto-char match-end)
14788 (and (looking-at " *|") (goto-char (match-end 0))))
14789 (goto-char match-end))
14791 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14792 (replace-match ""))
14793 (if negative (insert " -"))
14794 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
14795 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
14796 (insert " " (format fh h m))))
14797 (if align (org-table-align))
14798 (message "Time difference inserted")))))
14800 (defun org-make-tdiff-string (y d h m)
14803 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
14805 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
14807 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
14809 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
14811 (apply 'format fmt (nreverse l))))
14813 (defun org-time-string-to-time (s)
14814 (apply 'encode-time (org-parse-time-string s)))
14815 (defun org-time-string-to-seconds (s)
14816 (org-float-time (org-time-string-to-time s)))
14818 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
14819 "Convert a time stamp to an absolute day number.
14820 If there is a specifyer for a cyclic time stamp, get the closest date to
14822 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14823 the variable date is bound by the calendar when this is called."
14825 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
14826 (if (org-diary-sexp-entry (match-string 1 s) "" date)
14829 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
14830 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
14831 (time-to-days (current-time))) (match-string 0 s)
14833 (t (time-to-days (apply 'encode-time (org-parse-time-string s))))))
14835 (defun org-days-to-iso-week (days)
14836 "Return the iso week number."
14838 (car (calendar-iso-from-absolute days)))
14840 (defun org-small-year-to-year (year)
14841 "Convert 2-digit years into 4-digit years.
14842 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14843 The year 2000 cannot be abbreviated. Any year larger than 99
14844 is returned unchanged."
14846 (setq year (+ 2000 year))
14848 (setq year (+ 1900 year))))
14851 (defun org-time-from-absolute (d)
14852 "Return the time corresponding to date D.
14853 D may be an absolute day number, or a calendar-type list (month day year)."
14854 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
14855 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
14857 (defun org-calendar-holiday ()
14858 "List of holidays, for Diary display in Org-mode."
14859 (require 'holidays)
14861 (if (fboundp 'calendar-check-holidays)
14862 'calendar-check-holidays 'check-calendar-holidays) date)))
14863 (if hl (mapconcat 'identity hl "; "))))
14865 (defun org-diary-sexp-entry (sexp entry date)
14866 "Process a SEXP diary ENTRY for DATE."
14867 (require 'diary-lib)
14868 (let ((result (if calendar-debug-sexp
14869 (let ((stack-trace-on-error t))
14870 (eval (car (read-from-string sexp))))
14871 (condition-case nil
14872 (eval (car (read-from-string sexp)))
14875 (message "Bad sexp at line %d in %s: %s"
14877 (buffer-file-name) sexp)
14879 (cond ((stringp result) result)
14880 ((and (consp result)
14881 (stringp (cdr result))) (cdr result))
14885 (defun org-diary-to-ical-string (frombuf)
14886 "Get iCalendar entries from diary entries in buffer FROMBUF.
14887 This uses the icalendar.el library."
14888 (let* ((tmpdir (if (featurep 'xemacs)
14890 temporary-file-directory))
14891 (tmpfile (make-temp-name
14892 (expand-file-name "orgics" tmpdir)))
14894 (with-current-buffer frombuf
14895 (icalendar-export-region (point-min) (point-max) tmpfile)
14896 (setq buf (find-buffer-visiting tmpfile))
14898 (goto-char (point-min))
14899 (if (re-search-forward "^BEGIN:VEVENT" nil t)
14900 (setq b (match-beginning 0)))
14901 (goto-char (point-max))
14902 (if (re-search-backward "^END:VEVENT" nil t)
14903 (setq e (match-end 0)))
14904 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
14906 (delete-file tmpfile)
14909 (defun org-closest-date (start current change prefer show-all)
14910 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14911 When PREFER is `past' return a date that is either CURRENT or past.
14912 When PREFER is `future', return a date that is either CURRENT or future.
14913 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14914 ;; Make the proper lists from the dates
14916 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
14917 dn dw sday cday n1 n2 n0
14918 d m y y1 y2 date1 date2 nmonths nm ny m2)
14920 (setq start (org-date-to-gregorian start)
14921 current (org-date-to-gregorian
14924 (time-to-days (current-time))))
14925 sday (calendar-absolute-from-gregorian start)
14926 cday (calendar-absolute-from-gregorian current))
14928 (if (<= cday sday) (throw 'exit sday))
14930 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
14931 (setq dn (string-to-number (match-string 1 change))
14932 dw (cdr (assoc (match-string 2 change) a1)))
14933 (error "Invalid change specifyer: %s" change))
14934 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
14937 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
14940 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
14941 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
14942 (setq date1 (list m d y1)
14943 n1 (calendar-absolute-from-gregorian date1)
14944 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
14945 n2 (calendar-absolute-from-gregorian date2)))
14947 ;; approx number of month between the two dates
14948 (setq nmonths (floor (/ (- cday sday) 30.436875)))
14949 ;; How often does dn fit in there?
14950 (setq d (nth 1 start) m (car start) y (nth 2 start)
14951 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
14953 ny (floor (/ m 12))
14956 (while (> m 12) (setq m (- m 12) y (1+ y)))
14957 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
14958 (setq m2 (+ m dn) y2 y)
14959 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14960 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
14961 (while (<= n2 cday)
14962 (setq n1 n2 m m2 y y2)
14963 (setq m2 (+ m dn) y2 y)
14964 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14965 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
14966 ;; Make sure n1 is the earlier date
14967 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
14970 ((eq prefer 'past) (if (= cday n2) n2 n1))
14971 ((eq prefer 'future) (if (= cday n1) n1 n2))
14972 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
14974 ((eq prefer 'past) (if (= cday n2) n2 n1))
14975 ((eq prefer 'future) (if (= cday n1) n1 n2))
14976 (t (if (= cday n1) n1 n2)))))))
14978 (defun org-date-to-gregorian (date)
14979 "Turn any specification of DATE into a gregorian date for the calendar."
14980 (cond ((integerp date) (calendar-gregorian-from-absolute date))
14981 ((and (listp date) (= (length date) 3)) date)
14983 (setq date (org-parse-time-string date))
14984 (list (nth 4 date) (nth 3 date) (nth 5 date)))
14986 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
14988 (defun org-parse-time-string (s &optional nodefault)
14989 "Parse the standard Org-mode time string.
14990 This should be a lot faster than the normal `parse-time-string'.
14991 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14992 hour and minute fields will be nil if not given."
14993 (if (string-match org-ts-regexp0 s)
14995 (if (or (match-beginning 8) (not nodefault))
14996 (string-to-number (or (match-string 8 s) "0")))
14997 (if (or (match-beginning 7) (not nodefault))
14998 (string-to-number (or (match-string 7 s) "0")))
14999 (string-to-number (match-string 4 s))
15000 (string-to-number (match-string 3 s))
15001 (string-to-number (match-string 2 s))
15003 (error "Not a standard Org-mode time string: %s" s)))
15005 (defun org-timestamp-up (&optional arg)
15006 "Increase the date item at the cursor by one.
15007 If the cursor is on the year, change the year. If it is on the month or
15008 the day, change that.
15009 With prefix ARG, change by that many units."
15011 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
15013 (defun org-timestamp-down (&optional arg)
15014 "Decrease the date item at the cursor by one.
15015 If the cursor is on the year, change the year. If it is on the month or
15016 the day, change that.
15017 With prefix ARG, change by that many units."
15019 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
15021 (defun org-timestamp-up-day (&optional arg)
15022 "Increase the date in the time stamp by one day.
15023 With prefix ARG, change that many days."
15025 (if (and (not (org-at-timestamp-p t))
15026 (org-on-heading-p))
15028 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
15030 (defun org-timestamp-down-day (&optional arg)
15031 "Decrease the date in the time stamp by one day.
15032 With prefix ARG, change that many days."
15034 (if (and (not (org-at-timestamp-p t))
15035 (org-on-heading-p))
15037 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
15039 (defun org-at-timestamp-p (&optional inactive-ok)
15040 "Determine if the cursor is in or at a timestamp."
15042 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
15044 (ans (or (looking-at tsr)
15046 (skip-chars-backward "^[<\n\r\t")
15047 (if (> (point) (point-min)) (backward-char 1))
15048 (and (looking-at tsr)
15049 (> (- (match-end 0) pos) -1))))))
15051 (boundp 'org-ts-what)
15054 ((= pos (match-beginning 0)) 'bracket)
15055 ((= pos (1- (match-end 0))) 'bracket)
15056 ((org-pos-in-match-range pos 2) 'year)
15057 ((org-pos-in-match-range pos 3) 'month)
15058 ((org-pos-in-match-range pos 7) 'hour)
15059 ((org-pos-in-match-range pos 8) 'minute)
15060 ((or (org-pos-in-match-range pos 4)
15061 (org-pos-in-match-range pos 5)) 'day)
15062 ((and (> pos (or (match-end 8) (match-end 5)))
15063 (< pos (match-end 0)))
15064 (- pos (or (match-end 8) (match-end 5))))
15068 (defun org-toggle-timestamp-type ()
15069 "Toggle the type (<active> or [inactive]) of a time stamp."
15071 (when (org-at-timestamp-p t)
15072 (let ((beg (match-beginning 0)) (end (match-end 0))
15073 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
15076 (while (re-search-forward "[][<>]" end t)
15077 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
15079 (message "Timestamp is now %sactive"
15080 (if (equal (char-after beg) ?<) "" "in")))))
15082 (defun org-timestamp-change (n &optional what updown)
15083 "Change the date in the time stamp at point.
15084 The date will be changed by N times WHAT. WHAT can be `day', `month',
15085 `year', `minute', `second'. If WHAT is not given, the cursor position
15086 in the timestamp determines what will be changed."
15087 (let ((pos (point))
15089 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
15093 (if (not (org-at-timestamp-p t))
15094 (error "Not at a timestamp"))
15095 (if (and (not what) (eq org-ts-what 'bracket))
15096 (org-toggle-timestamp-type)
15097 (if (and (not what) (not (eq org-ts-what 'day))
15098 org-display-custom-times
15099 (get-text-property (point) 'display)
15100 (not (get-text-property (1- (point)) 'display)))
15101 (setq org-ts-what 'day))
15102 (setq org-ts-what (or what org-ts-what)
15103 inactive (= (char-after (match-beginning 0)) ?\[)
15104 ts (match-string 0))
15107 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
15109 (setq extra (match-string 1 ts)))
15110 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
15112 (setq time0 (org-parse-time-string ts))
15114 (eq org-ts-what 'minute)
15115 (not current-prefix-arg))
15116 ;; This looks like s-up and s-down. Change by one rounding step.
15117 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
15118 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
15119 (setcar (cdr time0) (+ (nth 1 time0)
15120 (if (> n 0) (- rem) (- dm rem))))))
15122 (encode-time (or (car time0) 0)
15123 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
15124 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
15125 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
15126 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
15127 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
15129 (when (and (member org-ts-what '(hour minute))
15131 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
15132 (setq extra (org-modify-ts-extra
15134 (if (eq org-ts-what 'hour) 2 5)
15136 (when (integerp org-ts-what)
15137 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
15138 (if (eq what 'calendar)
15139 (let ((cal-date (org-get-date-from-calendar)))
15140 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
15141 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
15142 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
15143 (setcar time0 (or (car time0) 0))
15144 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
15145 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
15146 (setq time (apply 'encode-time time0))))
15147 (setq org-last-changed-timestamp
15148 (org-insert-time-stamp time with-hm inactive nil nil extra))
15149 (org-clock-update-time-maybe)
15151 ;; Try to recenter the calendar window, if any
15152 (if (and org-calendar-follow-timestamp-change
15153 (get-buffer-window "*Calendar*" t)
15154 (memq org-ts-what '(day month year)))
15155 (org-recenter-calendar (time-to-days time))))))
15157 (defun org-modify-ts-extra (s pos n dm)
15158 "Change the different parts of the lead-time and repeat fields in timestamp."
15159 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
15161 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
15163 ((or (org-pos-in-match-range pos 2)
15164 (org-pos-in-match-range pos 3))
15165 (setq m (string-to-number (match-string 3 s))
15166 h (string-to-number (match-string 2 s)))
15167 (if (org-pos-in-match-range pos 2)
15169 (setq n (* dm (org-no-warnings (signum n))))
15170 (when (not (= 0 (setq rem (% m dm))))
15171 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
15173 (if (< m 0) (setq m (+ m 60) h (1- h)))
15174 (if (> m 59) (setq m (- m 60) h (1+ h)))
15175 (setq h (min 24 (max 0 h)))
15176 (setq ng 1 new (format "-%02d:%02d" h m)))
15177 ((org-pos-in-match-range pos 6)
15178 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
15179 ((org-pos-in-match-range pos 5)
15180 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
15182 ((org-pos-in-match-range pos 9)
15183 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
15184 ((org-pos-in-match-range pos 8)
15185 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
15189 (substring s 0 (match-beginning ng))
15191 (substring s (match-end ng))))))
15194 (defun org-recenter-calendar (date)
15195 "If the calendar is visible, recenter it to DATE."
15196 (let* ((win (selected-window))
15197 (cwin (get-buffer-window "*Calendar*" t))
15198 (calendar-move-hook nil))
15200 (select-window cwin)
15201 (calendar-goto-date (if (listp date) date
15202 (calendar-gregorian-from-absolute date)))
15203 (select-window win))))
15205 (defun org-goto-calendar (&optional arg)
15206 "Go to the Emacs calendar at the current date.
15207 If there is a time stamp in the current line, go to that date.
15208 A prefix ARG can be used to force the current date."
15210 (let ((tsr org-ts-regexp) diff
15211 (calendar-move-hook nil)
15212 (calendar-view-holidays-initially-flag nil)
15213 (calendar-view-diary-initially-flag nil))
15214 (if (or (org-at-timestamp-p)
15216 (beginning-of-line 1)
15217 (looking-at (concat ".*" tsr))))
15218 (let ((d1 (time-to-days (current-time)))
15220 (org-time-string-to-time (match-string 1)))))
15221 (setq diff (- d2 d1))))
15223 (calendar-goto-today)
15224 (if (and diff (not arg)) (calendar-forward-day diff))))
15226 (defun org-get-date-from-calendar ()
15227 "Return a list (month day year) of date at point in calendar."
15228 (with-current-buffer "*Calendar*"
15230 (calendar-cursor-to-date))))
15232 (defun org-date-from-calendar ()
15233 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
15234 If there is already a time stamp at the cursor position, update it."
15236 (if (org-at-timestamp-p t)
15237 (org-timestamp-change 0 'calendar)
15238 (let ((cal-date (org-get-date-from-calendar)))
15239 (org-insert-time-stamp
15240 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
15242 (defun org-minutes-to-hh:mm-string (m)
15243 "Compute H:MM from a number of minutes."
15244 (let ((h (/ m 60)))
15245 (setq m (- m (* 60 h)))
15246 (format org-time-clocksum-format h m)))
15248 (defun org-hh:mm-string-to-minutes (s)
15249 "Convert a string H:MM to a number of minutes.
15250 If the string is just a number, interpret it as minutes.
15251 In fact, the first hh:mm or number in the string will be taken,
15252 there can be extra stuff in the string.
15253 If no number is found, the return value is 0."
15255 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
15256 (+ (* (string-to-number (match-string 1 s)) 60)
15257 (string-to-number (match-string 2 s))))
15258 ((string-match "\\([0-9]+\\)" s)
15259 (string-to-number (match-string 1 s)))
15264 (defun org-save-all-org-buffers ()
15265 "Save all Org-mode buffers without user confirmation."
15267 (message "Saving all Org-mode buffers...")
15268 (save-some-buffers t 'org-mode-p)
15269 (when (featurep 'org-id) (org-id-locations-save))
15270 (message "Saving all Org-mode buffers... done"))
15272 (defun org-revert-all-org-buffers ()
15273 "Revert all Org-mode buffers.
15274 Prompt for confirmation when there are unsaved changes.
15275 Be sure you know what you are doing before letting this function
15276 overwrite your changes.
15278 This function is useful in a setup where one tracks org files
15279 with a version control system, to revert on one machine after pulling
15280 changes from another. I believe the procedure must be like this:
15282 1. M-x org-save-all-org-buffers
15283 2. Pull changes from the other machine, resolve conflicts
15284 3. M-x org-revert-all-org-buffers"
15286 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
15289 (save-window-excursion
15292 (when (and (with-current-buffer b (org-mode-p))
15293 (with-current-buffer b buffer-file-name))
15294 (switch-to-buffer b)
15295 (revert-buffer t 'no-confirm)))
15297 (when (and (featurep 'org-id) org-id-track-globally)
15298 (org-id-locations-load)))))
15303 (defun org-switchb (&optional arg)
15304 "Switch between Org buffers.
15305 With a prefix argument, restrict available to files.
15306 With two prefix arguments, restrict available buffers to agenda files.
15308 Defaults to `iswitchb' for buffer name completion.
15309 Set `org-completion-use-ido' to make it use ido instead."
15311 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
15312 ((equal arg '(16)) (org-buffer-list 'agenda))
15313 (t (org-buffer-list))))
15314 (org-completion-use-iswitchb org-completion-use-iswitchb)
15315 (org-completion-use-ido org-completion-use-ido))
15316 (unless (or org-completion-use-ido org-completion-use-iswitchb)
15317 (setq org-completion-use-iswitchb t))
15319 (org-icompleting-read "Org buffer: "
15320 (mapcar 'list (mapcar 'buffer-name blist))
15323 ;;; Define some older names previously used for this functionality
15325 (defalias 'org-ido-switchb 'org-switchb)
15327 (defalias 'org-iswitchb 'org-switchb)
15329 (defun org-buffer-list (&optional predicate exclude-tmp)
15330 "Return a list of Org buffers.
15331 PREDICATE can be `export', `files' or `agenda'.
15333 export restrict the list to Export buffers.
15334 files restrict the list to buffers visiting Org files.
15335 agenda restrict the list to buffers visiting agenda files.
15337 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
15339 (agenda-files (and (eq predicate 'agenda)
15340 (mapcar 'file-truename (org-agenda-files t))))
15343 ((eq predicate 'files)
15344 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
15345 ((eq predicate 'export)
15346 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
15347 ((eq predicate 'agenda)
15349 (with-current-buffer b
15350 (and (eq major-mode 'org-mode)
15351 (setq bfn (buffer-file-name b))
15352 (member (file-truename bfn) agenda-files)))))
15353 (t (lambda (b) (with-current-buffer b
15354 (or (eq major-mode 'org-mode)
15355 (string-match "\*Org .*Export"
15356 (buffer-name b)))))))))
15360 (if (and (funcall filter b)
15361 (or (not exclude-tmp)
15362 (not (string-match "tmp" (buffer-name b)))))
15367 (defun org-agenda-files (&optional unrestricted archives)
15368 "Get the list of agenda files.
15369 Optional UNRESTRICTED means return the full list even if a restriction
15370 is currently in place.
15371 When ARCHIVES is t, include all archive files that are really being
15372 used by the agenda files. If ARCHIVE is `ifmode', do this only if
15373 `org-agenda-archives-mode' is t."
15376 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
15377 ((stringp org-agenda-files) (org-read-agenda-file-list))
15378 ((listp org-agenda-files) org-agenda-files)
15379 (t (error "Invalid value of `org-agenda-files'")))))
15380 (setq files (apply 'append
15381 (mapcar (lambda (f)
15382 (if (file-directory-p f)
15384 f t org-agenda-file-regexp)
15387 (when org-agenda-skip-unavailable-files
15388 (setq files (delq nil
15391 (and (file-readable-p file) file)))
15393 (when (or (eq archives t)
15394 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
15395 (setq files (org-add-archive-files files)))
15398 (defun org-agenda-file-p (&optional file)
15399 "Return non-nil, if FILE is an agenda file.
15400 If FILE is omitted, use the file associated with the current
15402 (member (or file (buffer-file-name))
15403 (org-agenda-files t)))
15405 (defun org-edit-agenda-file-list ()
15406 "Edit the list of agenda files.
15407 Depending on setup, this either uses customize to edit the variable
15408 `org-agenda-files', or it visits the file that is holding the list. In the
15409 latter case, the buffer is set up in a way that saving it automatically kills
15410 the buffer and restores the previous window configuration."
15412 (if (stringp org-agenda-files)
15413 (let ((cw (current-window-configuration)))
15414 (find-file org-agenda-files)
15415 (org-set-local 'org-window-configuration cw)
15416 (org-add-hook 'after-save-hook
15418 (set-window-configuration
15419 (prog1 org-window-configuration
15420 (kill-buffer (current-buffer))))
15421 (org-install-agenda-files-menu)
15422 (message "New agenda file list installed"))
15424 (message "%s" (substitute-command-keys
15425 "Edit list and finish with \\[save-buffer]")))
15426 (customize-variable 'org-agenda-files)))
15428 (defun org-store-new-agenda-file-list (list)
15429 "Set new value for the agenda file list and save it correctly."
15430 (if (stringp org-agenda-files)
15431 (let ((fe (org-read-agenda-file-list t)) b u)
15432 (while (setq b (find-buffer-visiting org-agenda-files))
15434 (with-temp-file org-agenda-files
15437 (lambda (f) ;; Keep un-expanded entries.
15438 (if (setq u (assoc f fe))
15443 (let ((org-mode-hook nil) (org-inhibit-startup t)
15444 (org-insert-mode-line-in-empty-file nil))
15445 (setq org-agenda-files list)
15446 (customize-save-variable 'org-agenda-files org-agenda-files))))
15448 (defun org-read-agenda-file-list (&optional pair-with-expansion)
15449 "Read the list of agenda files from a file.
15450 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
15451 filenames, used by `org-store-new-agenda-file-list' to write back
15452 un-expanded file names."
15453 (when (file-directory-p org-agenda-files)
15454 (error "`org-agenda-files' cannot be a single directory"))
15455 (when (stringp org-agenda-files)
15457 (insert-file-contents org-agenda-files)
15460 (let ((e (expand-file-name (substitute-in-file-name f)
15462 (if pair-with-expansion
15465 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
15468 (defun org-cycle-agenda-files ()
15469 "Cycle through the files in `org-agenda-files'.
15470 If the current buffer visits an agenda file, find the next one in the list.
15471 If the current buffer does not, find the first agenda file."
15473 (let* ((fs (org-agenda-files t))
15474 (files (append fs (list (car fs))))
15475 (tcf (if buffer-file-name (file-truename buffer-file-name)))
15477 (unless files (error "No agenda files"))
15479 (while (setq file (pop files))
15480 (if (equal (file-truename file) tcf)
15482 (find-file (car files))
15484 (find-file (car fs)))
15485 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
15487 (defun org-agenda-file-to-front (&optional to-end)
15488 "Move/add the current file to the top of the agenda file list.
15489 If the file is not present in the list, it is added to the front. If it is
15490 present, it is moved there. With optional argument TO-END, add/move to the
15493 (let ((org-agenda-skip-unavailable-files nil)
15494 (file-alist (mapcar (lambda (x)
15495 (cons (file-truename x) x))
15496 (org-agenda-files t)))
15497 (ctf (file-truename buffer-file-name))
15499 (setq x (assoc ctf file-alist) had x)
15501 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
15503 (setq file-alist (append (delq x file-alist) (list x)))
15504 (setq file-alist (cons x (delq x file-alist))))
15505 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
15506 (org-install-agenda-files-menu)
15507 (message "File %s to %s of agenda file list"
15508 (if had "moved" "added") (if to-end "end" "front"))))
15510 (defun org-remove-file (&optional file)
15511 "Remove current file from the list of files in variable `org-agenda-files'.
15512 These are the files which are being checked for agenda entries.
15513 Optional argument FILE means use this file instead of the current."
15515 (let* ((org-agenda-skip-unavailable-files nil)
15516 (file (or file buffer-file-name))
15517 (true-file (file-truename file))
15518 (afile (abbreviate-file-name file))
15519 (files (delq nil (mapcar
15521 (if (equal true-file
15524 (org-agenda-files t)))))
15525 (if (not (= (length files) (length (org-agenda-files t))))
15527 (org-store-new-agenda-file-list files)
15528 (org-install-agenda-files-menu)
15529 (message "Removed file: %s" afile))
15530 (message "File was not in list: %s (not removed)" afile))))
15532 (defun org-file-menu-entry (file)
15533 (vector file (list 'find-file file) t))
15535 (defun org-check-agenda-file (file)
15536 "Make sure FILE exists. If not, ask user what to do."
15537 (when (not (file-exists-p file))
15538 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
15539 (abbreviate-file-name file))
15540 (let ((r (downcase (read-char-exclusive))))
15543 (org-remove-file file)
15544 (throw 'nextfile t))
15545 (t (error "Abort"))))))
15547 (defun org-get-agenda-file-buffer (file)
15548 "Get a buffer visiting FILE. If the buffer needs to be created, add
15549 it to the list of buffers which might be released later."
15550 (let ((buf (org-find-base-buffer-visiting file)))
15552 buf ; just return it
15553 ;; Make a new buffer and remember it
15554 (setq buf (find-file-noselect file))
15555 (if buf (push buf org-agenda-new-buffers))
15558 (defun org-release-buffers (blist)
15559 "Release all buffers in list, asking the user for confirmation when needed.
15560 When a buffer is unmodified, it is just killed. When modified, it is saved
15561 \(if the user agrees) and then killed."
15563 (while (setq buf (pop blist))
15564 (setq file (buffer-file-name buf))
15565 (when (and (buffer-modified-p buf)
15567 (y-or-n-p (format "Save file %s? " file)))
15568 (with-current-buffer buf (save-buffer)))
15569 (kill-buffer buf))))
15571 (defun org-prepare-agenda-buffers (files)
15572 "Create buffers for all agenda files, protect archived trees and comments."
15574 (let ((pa '(:org-archived t))
15575 (pc '(:org-comment t))
15576 (pall '(:org-archived t :org-comment t))
15577 (inhibit-read-only t)
15578 (rea (concat ":" org-archive-tag ":"))
15582 (while (setq file (pop files))
15586 (org-check-agenda-file file)
15587 (set-buffer (org-get-agenda-file-buffer file)))
15589 (setq bmp (buffer-modified-p))
15590 (org-refresh-category-properties)
15591 (setq org-todo-keywords-for-agenda
15592 (append org-todo-keywords-for-agenda org-todo-keywords-1))
15593 (setq org-done-keywords-for-agenda
15594 (append org-done-keywords-for-agenda org-done-keywords))
15595 (setq org-todo-keyword-alist-for-agenda
15596 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
15597 (setq org-drawers-for-agenda
15598 (append org-drawers-for-agenda org-drawers))
15599 (setq org-tag-alist-for-agenda
15600 (append org-tag-alist-for-agenda org-tag-alist))
15603 (remove-text-properties (point-min) (point-max) pall)
15604 (when org-agenda-skip-archived-trees
15605 (goto-char (point-min))
15606 (while (re-search-forward rea nil t)
15607 (if (org-on-heading-p t)
15608 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
15609 (goto-char (point-min))
15610 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
15611 (while (re-search-forward re nil t)
15612 (add-text-properties
15613 (match-beginning 0) (org-end-of-subtree t) pc)))
15614 (set-buffer-modified-p bmp)))))
15615 (setq org-todo-keywords-for-agenda
15616 (org-uniquify org-todo-keywords-for-agenda))
15617 (setq org-todo-keyword-alist-for-agenda
15618 (org-uniquify org-todo-keyword-alist-for-agenda)
15619 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
15621 ;;;; Embedded LaTeX
15623 (defvar org-cdlatex-mode-map (make-sparse-keymap)
15624 "Keymap for the minor `org-cdlatex-mode'.")
15626 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
15627 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
15628 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
15629 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
15630 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
15632 (defvar org-cdlatex-texmathp-advice-is-done nil
15633 "Flag remembering if we have applied the advice to texmathp already.")
15635 (define-minor-mode org-cdlatex-mode
15636 "Toggle the minor `org-cdlatex-mode'.
15637 This mode supports entering LaTeX environment and math in LaTeX fragments
15639 \\{org-cdlatex-mode-map}"
15641 (when org-cdlatex-mode (require 'cdlatex))
15642 (unless org-cdlatex-texmathp-advice-is-done
15643 (setq org-cdlatex-texmathp-advice-is-done t)
15644 (defadvice texmathp (around org-math-always-on activate)
15645 "Always return t in org-mode buffers.
15646 This is because we want to insert math symbols without dollars even outside
15647 the LaTeX math segments. If Orgmode thinks that point is actually inside
15648 an embedded LaTeX fragment, let texmathp do its job.
15649 \\[org-cdlatex-mode-map]"
15653 ((not (org-mode-p)) ad-do-it)
15654 ((eq this-command 'cdlatex-math-symbol)
15655 (setq ad-return-value t
15656 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
15658 (let ((p (org-inside-LaTeX-fragment-p)))
15659 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
15660 (setq ad-return-value t
15661 texmathp-why '("Org-mode embedded math" . 0))
15662 (if p ad-do-it)))))))))
15664 (defun turn-on-org-cdlatex ()
15665 "Unconditionally turn on `org-cdlatex-mode'."
15666 (org-cdlatex-mode 1))
15668 (defun org-inside-LaTeX-fragment-p ()
15669 "Test if point is inside a LaTeX fragment.
15670 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15671 sequence appearing also before point.
15672 Even though the matchers for math are configurable, this function assumes
15673 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15674 delimiters are skipped when they have been removed by customization.
15675 The return value is nil, or a cons cell with the delimiter and
15676 and the position of this delimiter.
15678 This function does a reasonably good job, but can locally be fooled by
15679 for example currency specifications. For example it will assume being in
15680 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15681 fragments that are properly closed, but during editing, we have to live
15682 with the uncertainty caused by missing closing delimiters. This function
15683 looks only before point, not after."
15685 (let ((pos (point))
15686 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
15688 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
15690 dd-on str (start 0) m re)
15693 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
15694 re (nth 1 (assoc "$" org-latex-regexps)))
15695 (while (string-match re str start)
15697 ((= (match-end 0) (length str))
15698 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
15699 ((= (match-end 0) (- (length str) 5))
15701 (t (setq start (match-end 0))))))
15702 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
15704 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
15705 (and (match-beginning 2) (throw 'exit nil))
15707 (while (re-search-backward "\\$\\$" lim t)
15708 (setq dd-on (not dd-on)))
15710 (if dd-on (cons "$$" m))))))
15712 (defun org-inside-latex-macro-p ()
15713 "Is point inside a LaTeX macro or its arguments?"
15716 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15718 (defun org-try-cdlatex-tab ()
15719 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15720 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15721 - inside a LaTeX fragment, or
15722 - after the first word in a line, where an abbreviation expansion could
15723 insert a LaTeX environment."
15724 (when org-cdlatex-mode
15727 (skip-chars-backward "a-zA-Z0-9*")
15728 (skip-chars-backward " \t")
15731 ((org-inside-LaTeX-fragment-p)
15735 (defun org-cdlatex-underscore-caret (&optional arg)
15736 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15737 Revert to the normal definition outside of these fragments."
15739 (if (org-inside-LaTeX-fragment-p)
15740 (call-interactively 'cdlatex-sub-superscript)
15741 (let (org-cdlatex-mode)
15742 (call-interactively (key-binding (vector last-input-event))))))
15744 (defun org-cdlatex-math-modify (&optional arg)
15745 "Execute `cdlatex-math-modify' in LaTeX fragments.
15746 Revert to the normal definition outside of these fragments."
15748 (if (org-inside-LaTeX-fragment-p)
15749 (call-interactively 'cdlatex-math-modify)
15750 (let (org-cdlatex-mode)
15751 (call-interactively (key-binding (vector last-input-event))))))
15753 (defvar org-latex-fragment-image-overlays nil
15754 "List of overlays carrying the images of latex fragments.")
15755 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
15757 (defun org-remove-latex-fragment-image-overlays ()
15758 "Remove all overlays with LaTeX fragment images in current buffer."
15759 (mapc 'delete-overlay org-latex-fragment-image-overlays)
15760 (setq org-latex-fragment-image-overlays nil))
15762 (defun org-preview-latex-fragment (&optional subtree)
15763 "Preview the LaTeX fragment at point, or all locally or globally.
15764 If the cursor is in a LaTeX fragment, create the image and overlay
15765 it over the source code. If there is no fragment at point, display
15766 all fragments in the current text, from one headline to the next. With
15767 prefix SUBTREE, display all fragments in the current subtree. With a
15768 double prefix `C-u C-u', or when the cursor is before the first headline,
15769 display all fragments in the buffer.
15770 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15772 (org-remove-latex-fragment-image-overlays)
15775 (let (beg end at msg)
15777 ((or (equal subtree '(16))
15778 (not (save-excursion
15779 (re-search-backward (concat "^" outline-regexp) nil t))))
15780 (setq beg (point-min) end (point-max)
15781 msg "Creating images for buffer...%s"))
15782 ((equal subtree '(4))
15783 (org-back-to-heading)
15784 (setq beg (point) end (org-end-of-subtree t)
15785 msg "Creating images for subtree...%s"))
15787 (if (setq at (org-inside-LaTeX-fragment-p))
15788 (goto-char (max (point-min) (- (cdr at) 2)))
15789 (org-back-to-heading))
15790 (setq beg (point) end (progn (outline-next-heading) (point))
15791 msg (if at "Creating image...%s"
15792 "Creating images for entry...%s"))))
15794 (narrow-to-region beg end)
15797 (concat "ltxpng/" (file-name-sans-extension
15798 (file-name-nondirectory
15799 buffer-file-name)))
15800 default-directory 'overlays msg at 'forbuffer)
15801 (message msg "done. Use `C-c C-c' to remove images.")))))
15803 (defvar org-latex-regexps
15804 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
15805 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15806 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15807 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15808 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15809 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
15810 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
15811 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
15812 "Regular expressions for matching embedded LaTeX.")
15814 (defun org-format-latex (prefix &optional dir overlays msg at
15815 forbuffer protect-only)
15816 "Replace LaTeX fragments with links to an image, and produce images.
15817 Some of the options can be changed using the variable
15818 `org-format-latex-options'."
15819 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
15820 (let* ((prefixnodir (file-name-nondirectory prefix))
15821 (absprefix (expand-file-name prefix dir))
15822 (todir (file-name-directory absprefix))
15823 (opt org-format-latex-options)
15824 (matchers (plist-get opt :matchers))
15825 (re-list org-latex-regexps)
15826 (org-format-latex-header-extra
15827 (plist-get (org-infile-export-plist) :latex-header-extra))
15828 (cnt 0) txt hash link beg end re e checkdir
15829 executables-checked
15830 m n block linkfile movefile ov)
15831 ;; Check the different regular expressions
15832 (while (setq e (pop re-list))
15833 (setq m (car e) re (nth 1 e) n (nth 2 e)
15834 block (if (nth 3 e) "\n\n" ""))
15835 (when (member m matchers)
15836 (goto-char (point-min))
15837 (while (re-search-forward re nil t)
15838 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
15839 (not (get-text-property (match-beginning n)
15842 (not (eq (get-char-property (match-beginning n)
15844 'org-latex-overlay))))
15846 (add-text-properties (match-beginning n) (match-end n)
15847 '(org-protected t))
15848 (setq txt (match-string n)
15849 beg (match-beginning n) end (match-end n)
15851 (let (print-length print-level) ; make sure full list is printed
15852 (setq hash (sha1 (prin1-to-string
15853 (list org-format-latex-header
15854 org-format-latex-header-extra
15855 org-export-latex-default-packages-alist
15856 org-export-latex-packages-alist
15857 org-format-latex-options
15859 linkfile (format "%s_%s.png" prefix hash)
15860 movefile (format "%s_%s.png" absprefix hash)))
15861 (setq link (concat block "[[file:" linkfile "]]" block))
15862 (if msg (message msg cnt))
15864 (unless checkdir ; make sure the directory exists
15866 (or (file-directory-p todir) (make-directory todir)))
15868 (unless executables-checked
15869 (org-check-external-command
15870 "latex" "needed to convert LaTeX fragments to images")
15871 (org-check-external-command
15872 "dvipng" "needed to convert LaTeX fragments to images")
15873 (setq executables-checked t))
15875 (unless (file-exists-p movefile)
15876 (org-create-formula-image
15877 txt movefile opt forbuffer))
15881 (if (eq (overlay-get o 'org-overlay-type)
15882 'org-latex-overlay)
15883 (delete-overlay o)))
15884 (overlays-in beg end))
15885 (setq ov (make-overlay beg end))
15886 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
15887 (if (featurep 'xemacs)
15889 (overlay-put ov 'invisible t)
15892 (make-glyph (vector 'png :file movefile))))
15895 (list 'image :type 'png :file movefile :ascent 'center)))
15896 (push ov org-latex-fragment-image-overlays)
15898 (delete-region beg end)
15899 (insert (org-add-props link
15900 (list 'org-latex-src
15901 (replace-regexp-in-string "\"" "" txt))))))))))))
15903 ;; This function borrows from Ganesh Swami's latex2png.el
15904 (defun org-create-formula-image (string tofile options buffer)
15905 "This calls dvipng."
15906 (require 'org-latex)
15907 (let* ((tmpdir (if (featurep 'xemacs)
15909 temporary-file-directory))
15910 (texfilebase (make-temp-name
15911 (expand-file-name "orgtex" tmpdir)))
15912 (texfile (concat texfilebase ".tex"))
15913 (dvifile (concat texfilebase ".dvi"))
15914 (pngfile (concat texfilebase ".png"))
15915 (fnh (if (featurep 'xemacs)
15916 (font-height (get-face-font 'default))
15917 (face-attribute 'default :height nil)))
15918 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
15919 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
15920 (fg (or (plist-get options (if buffer :foreground :html-foreground))
15922 (bg (or (plist-get options (if buffer :background :html-background))
15924 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
15925 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
15926 (with-temp-file texfile
15927 (insert (org-splice-latex-header
15928 org-format-latex-header
15929 org-export-latex-default-packages-alist
15930 org-export-latex-packages-alist t
15931 org-format-latex-header-extra))
15932 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
15933 (require 'org-latex)
15934 (org-export-latex-fix-inputenc))
15935 (let ((dir default-directory))
15936 (condition-case nil
15939 (call-process "latex" nil nil nil texfile))
15942 (if (not (file-exists-p dvifile))
15943 (progn (message "Failed to create dvi file from %s" texfile) nil)
15944 (condition-case nil
15945 (call-process "dvipng" nil nil nil
15948 ;;"-x" scale "-y" scale
15953 (if (not (file-exists-p pngfile))
15954 (if org-format-latex-signal-error
15955 (error "Failed to create png file from %s" texfile)
15956 (message "Failed to create png file from %s" texfile)
15958 ;; Use the requested file name and clean up
15959 (copy-file pngfile tofile 'replace)
15960 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
15961 (delete-file (concat texfilebase e)))
15964 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
15965 "Fill a LaTeX header template TPL.
15966 In the template, the following place holders will be recognized:
15968 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15969 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15970 [PACKAGES] \\usepackage statements for PKG
15971 [NO-PACKAGES] do not include PKG
15972 [EXTRA] the string EXTRA
15973 [NO-EXTRA] do not include EXTRA
15975 For backward compatibility, if both the positive and the negative place
15976 holder is missing, the positive one (without the \"NO-\") will be
15977 assumed to be present at the end of the template.
15978 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15980 SNIPPETS-P indicates if this is run to create snippet images for HTML."
15981 (let (rpl (end ""))
15982 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
15983 (setq rpl (if (or (match-end 1) (not def-pkg))
15984 "" (org-latex-packages-to-string def-pkg snippets-p t))
15985 tpl (replace-match rpl t t tpl))
15986 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
15988 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
15989 (setq rpl (if (or (match-end 1) (not pkg))
15990 "" (org-latex-packages-to-string pkg snippets-p t))
15991 tpl (replace-match rpl t t tpl))
15994 (org-latex-packages-to-string pkg snippets-p)))))
15996 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
15997 (setq rpl (if (or (match-end 1) (not extra))
15998 "" (concat extra "\n"))
15999 tpl (replace-match rpl t t tpl))
16000 (if (and extra (string-match "\\S-" extra))
16001 (setq end (concat end "\n" extra))))
16003 (if (string-match "\\S-" end)
16004 (concat tpl "\n" end)
16007 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
16008 "Turn an alist of packages into a string with the \\usepackage macros."
16009 (setq pkg (mapconcat (lambda(p)
16012 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
16013 (format "%% Package %s omitted" (cadr p)))
16014 ((equal "" (car p))
16015 (format "\\usepackage{%s}" (cadr p)))
16017 (format "\\usepackage[%s]{%s}"
16018 (car p) (cadr p)))))
16021 (if newline (concat pkg "\n") pkg))
16023 (defun org-dvipng-color (attr)
16024 "Return an rgb color specification for dvipng."
16025 (apply 'format "rgb %s %s %s"
16026 (mapcar 'org-normalize-color
16027 (color-values (face-attribute 'default attr nil)))))
16029 (defun org-normalize-color (value)
16030 "Return string to be used as color value for an RGB component."
16031 (format "%g" (/ value 65535.0)))
16036 (defvar org-inline-image-overlays nil)
16037 (make-variable-buffer-local 'org-inline-image-overlays)
16039 (defun org-toggle-inline-images (&optional include-linked)
16040 "Toggle the display of inline images.
16041 INCLUDE-LINKED is passed to `org-display-inline-images'."
16043 (if org-inline-image-overlays
16045 (org-remove-inline-images)
16046 (message "Inline image display turned off"))
16047 (org-display-inline-images include-linked)
16048 (if org-inline-image-overlays
16049 (message "%d images displayed inline"
16050 (length org-inline-image-overlays))
16051 (message "No images to display inline"))))
16053 (defun org-display-inline-images (&optional include-linked refresh beg end)
16054 "Display inline images.
16055 Normally only links without a description part are inlined, because this
16056 is how it will work for export. When INCLUDE-LINKED is set, also links
16057 with a description part will be inlined. This can be nice for a quick
16058 look at those images, but it does not reflect whatexported files will look
16060 When REFRESH is set, refresh existing images between BEG and END.
16061 This will create new image displays only if necessary.
16062 BEG and END default to the buffer boundaries."
16065 (org-remove-inline-images)
16066 (clear-image-cache))
16070 (setq beg (or beg (point-min)) end (or end (point-max)))
16071 (goto-char (point-min))
16072 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([-+~.:/\\_0-9a-zA-Z ]+"
16073 (substring (org-image-file-name-regexp) 0 -2)
16074 "\\)\\]" (if include-linked "" "\\]")))
16076 (while (re-search-forward re end t)
16077 (setq old (get-char-property-and-overlay (match-beginning 1)
16078 'org-image-overlay))
16079 (setq file (expand-file-name
16080 (concat (or (match-string 3) "") (match-string 4))))
16081 (when (file-exists-p file)
16082 (if (and (car-safe old) refresh)
16083 (image-refresh (overlay-get (cdr old) 'display))
16084 (setq img (create-image file))
16086 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
16087 (overlay-put ov 'display img)
16088 (overlay-put ov 'face 'default)
16089 (overlay-put ov 'org-image-overlay t)
16090 (overlay-put ov 'modification-hooks
16091 (list 'org-display-inline-modification-hook))
16092 (push ov org-inline-image-overlays)))))))))
16094 (defun org-display-inline-modification-hook (ov after beg end &optional len)
16095 "Remove inline-display overlay if a corresponding region is modified."
16096 (let ((inhibit-modification-hooks t))
16097 (when (and ov after)
16098 (delete ov org-inline-image-overlays)
16099 (delete-overlay ov))))
16101 (defun org-remove-inline-images ()
16102 "Remove inline display of images."
16104 (mapc 'delete-overlay org-inline-image-overlays)
16105 (setq org-inline-image-overlays nil))
16109 ;; Make `C-c C-x' a prefix key
16110 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
16112 ;; TAB key with modifiers
16113 (org-defkey org-mode-map "\C-i" 'org-cycle)
16114 (org-defkey org-mode-map [(tab)] 'org-cycle)
16115 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
16116 (org-defkey org-mode-map [(meta tab)] 'org-complete)
16117 (org-defkey org-mode-map "\M-\t" 'org-complete)
16118 (org-defkey org-mode-map "\M-\C-i" 'org-complete)
16119 ;; The following line is necessary under Suse GNU/Linux
16120 (unless (featurep 'xemacs)
16121 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
16122 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
16123 (define-key org-mode-map [backtab] 'org-shifttab)
16125 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
16126 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
16127 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
16129 ;; Cursor keys with modifiers
16130 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
16131 (org-defkey org-mode-map [(meta right)] 'org-metaright)
16132 (org-defkey org-mode-map [(meta up)] 'org-metaup)
16133 (org-defkey org-mode-map [(meta down)] 'org-metadown)
16135 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
16136 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
16137 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
16138 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
16140 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
16141 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
16142 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
16143 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
16145 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
16146 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
16149 (define-key org-mode-map org-babel-key-prefix org-babel-map)
16150 (mapc (lambda (pair)
16151 (define-key org-babel-map (car pair) (cdr pair)))
16152 org-babel-key-bindings)
16154 ;;; Extra keys for tty access.
16155 ;; We only set them when really needed because otherwise the
16156 ;; menus don't show the simple keys
16158 (when (or org-use-extra-keys
16159 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
16160 (not window-system))
16161 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
16162 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
16163 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
16164 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
16165 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
16166 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
16167 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
16168 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
16169 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
16170 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
16171 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
16172 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
16173 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
16174 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
16175 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
16176 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
16177 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
16178 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
16179 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
16180 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
16181 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
16182 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
16183 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
16184 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
16185 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
16186 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
16187 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
16188 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
16190 ;; All the other keys
16192 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
16193 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
16194 (if (boundp 'narrow-map)
16195 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
16196 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
16197 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
16198 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
16199 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
16200 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
16201 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
16202 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
16203 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
16204 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
16205 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
16206 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
16207 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
16208 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
16209 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
16210 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
16211 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
16212 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
16213 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
16214 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
16215 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
16216 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
16217 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
16218 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
16219 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
16220 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
16221 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
16222 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
16223 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
16224 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
16225 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
16226 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
16227 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
16228 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
16229 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
16230 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
16231 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
16232 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
16233 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
16234 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
16235 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
16236 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
16237 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
16238 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
16239 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
16240 (org-defkey org-mode-map "\C-c^" 'org-sort)
16241 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
16242 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
16243 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
16244 (org-defkey org-mode-map "\C-m" 'org-return)
16245 (org-defkey org-mode-map "\C-j" 'org-return-indent)
16246 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
16247 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
16248 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
16249 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
16250 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
16251 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
16252 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
16253 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
16254 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
16255 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
16256 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
16257 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
16258 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
16259 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
16260 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
16261 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
16262 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
16263 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
16264 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
16265 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
16267 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
16268 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
16269 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
16270 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
16272 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
16273 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
16274 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
16275 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
16276 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
16277 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
16278 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
16279 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
16280 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
16281 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
16282 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
16283 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
16284 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
16285 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
16286 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
16287 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
16288 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
16290 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
16291 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
16292 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
16293 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
16295 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
16297 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
16299 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
16300 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
16302 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
16305 (when (featurep 'xemacs)
16306 (org-defkey org-mode-map 'button3 'popup-mode-menu))
16309 (defconst org-speed-commands-default
16311 ("Outline Navigation")
16312 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
16313 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
16314 ("f" . (org-speed-move-safe 'org-forward-same-level))
16315 ("b" . (org-speed-move-safe 'org-backward-same-level))
16316 ("u" . (org-speed-move-safe 'outline-up-heading))
16318 ("g" . (org-refile t))
16319 ("Outline Visibility")
16321 ("C" . org-shifttab)
16322 (" " . org-display-outline-path)
16323 ("Outline Structure Editing")
16324 ("U" . org-shiftmetaup)
16325 ("D" . org-shiftmetadown)
16326 ("r" . org-metaright)
16327 ("l" . org-metaleft)
16328 ("R" . org-shiftmetaright)
16329 ("L" . org-shiftmetaleft)
16330 ("i" . (progn (forward-char 1) (call-interactively
16331 'org-insert-heading-respect-content)))
16334 ("a" . org-archive-subtree-default-with-confirmation)
16335 ("." . outline-mark-subtree)
16337 ("I" . org-clock-in)
16338 ("O" . org-clock-out)
16339 ("Meta Data Editing")
16341 ("0" . (org-priority ?\ ))
16342 ("1" . (org-priority ?A))
16343 ("2" . (org-priority ?B))
16344 ("3" . (org-priority ?C))
16345 (";" . org-set-tags-command)
16346 ("e" . org-set-effort)
16347 ("Agenda Views etc")
16349 ("/" . org-sparse-tree)
16351 ("o" . org-open-at-point)
16352 ("?" . org-speed-command-help)
16354 "The default speed commands.")
16356 (defun org-print-speed-command (e)
16357 (if (> (length (car e)) 1)
16362 (princ (make-string (length (car e)) ?-))
16366 (if (symbolp (cdr e))
16367 (princ (symbol-name (cdr e)))
16371 (defun org-speed-command-help ()
16372 "Show the available speed commands."
16374 (if (not org-use-speed-commands)
16375 (error "Speed commands are not activated, customize `org-use-speed-commands'.")
16376 (with-output-to-temp-buffer "*Help*"
16377 (princ "User-defined Speed commands\n===========================\n")
16378 (mapc 'org-print-speed-command org-speed-commands-user)
16380 (princ "Built-in Speed commands\n=======================\n")
16381 (mapc 'org-print-speed-command org-speed-commands-default))
16382 (with-current-buffer "*Help*"
16383 (setq truncate-lines t))))
16385 (defun org-speed-move-safe (cmd)
16386 "Execute CMD, but make sure that the cursor always ends up in a headline.
16387 If not, return to the original position and throw an error."
16389 (let ((pos (point)))
16390 (call-interactively cmd)
16391 (unless (and (bolp) (org-on-heading-p))
16393 (error "Boundary reached while executing %s" cmd))))
16395 (defvar org-self-insert-command-undo-counter 0)
16397 (defvar org-table-auto-blank-field) ; defined in org-table.el
16398 (defvar org-speed-command nil)
16399 (defun org-self-insert-command (N)
16400 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
16401 If the cursor is in a table looking at whitespace, the whitespace is
16402 overwritten, and the table is not marked as requiring realignment."
16405 ((and org-use-speed-commands
16406 (or (and (bolp) (looking-at outline-regexp))
16407 (and (functionp org-use-speed-commands)
16408 (funcall org-use-speed-commands)))
16411 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
16412 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
16414 ((commandp org-speed-command)
16415 (setq this-command org-speed-command)
16416 (call-interactively org-speed-command))
16417 ((functionp org-speed-command)
16418 (funcall org-speed-command))
16419 ((and org-speed-command (listp org-speed-command))
16420 (eval org-speed-command))
16421 (t (let (org-use-speed-commands)
16422 (call-interactively 'org-self-insert-command)))))
16426 ;; check if we blank the field, and if that triggers align
16427 (and (featurep 'org-table) org-table-auto-blank-field
16428 (member last-command
16429 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
16430 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
16431 ;; got extra space, this field does not determine column width
16432 (let (org-table-may-need-update) (org-table-blank-field))
16433 ;; no extra space, this field may determine column width
16434 (org-table-blank-field)))
16437 (looking-at "[^|\n]* |"))
16438 (let (org-table-may-need-update)
16439 (goto-char (1- (match-end 0)))
16440 (delete-backward-char 1)
16441 (goto-char (match-beginning 0))
16442 (self-insert-command N)))
16444 (setq org-table-may-need-update t)
16445 (self-insert-command N)
16446 (org-fix-tags-on-the-fly)
16447 (if org-self-insert-cluster-for-undo
16448 (if (not (eq last-command 'org-self-insert-command))
16449 (setq org-self-insert-command-undo-counter 1)
16450 (if (>= org-self-insert-command-undo-counter 20)
16451 (setq org-self-insert-command-undo-counter 1)
16452 (and (> org-self-insert-command-undo-counter 0)
16454 (not (cadr buffer-undo-list)) ; remove nil entry
16455 (setcdr buffer-undo-list (cddr buffer-undo-list)))
16456 (setq org-self-insert-command-undo-counter
16457 (1+ org-self-insert-command-undo-counter))))))))
16459 (defun org-fix-tags-on-the-fly ()
16460 (when (and (equal (char-after (point-at-bol)) ?*)
16461 (org-on-heading-p))
16462 (org-align-tags-here org-tags-column)))
16464 (defun org-delete-backward-char (N)
16465 "Like `delete-backward-char', insert whitespace at field end in tables.
16466 When deleting backwards, in tables this function will insert whitespace in
16467 front of the next \"|\" separator, to keep the table aligned. The table will
16468 still be marked for re-alignment if the field did fill the entire column,
16469 because, in this case the deletion might narrow the column."
16471 (if (and (org-table-p)
16473 (string-match "|" (buffer-substring (point-at-bol) (point)))
16474 (looking-at ".*?|"))
16475 (let ((pos (point))
16476 (noalign (looking-at "[^|\n\r]* |"))
16477 (c org-table-may-need-update))
16478 (backward-delete-char N)
16479 (skip-chars-forward "^|")
16481 (goto-char (1- pos))
16482 ;; noalign: if there were two spaces at the end, this field
16483 ;; does not determine the width of the column.
16484 (if noalign (setq org-table-may-need-update c)))
16485 (backward-delete-char N)
16486 (org-fix-tags-on-the-fly)))
16488 (defun org-delete-char (N)
16489 "Like `delete-char', but insert whitespace at field end in tables.
16490 When deleting characters, in tables this function will insert whitespace in
16491 front of the next \"|\" separator, to keep the table aligned. The table will
16492 still be marked for re-alignment if the field did fill the entire column,
16493 because, in this case the deletion might narrow the column."
16495 (if (and (org-table-p)
16497 (not (= (char-after) ?|))
16499 (if (looking-at ".*?|")
16500 (let ((pos (point))
16501 (noalign (looking-at "[^|\n\r]* |"))
16502 (c org-table-may-need-update))
16503 (replace-match (concat
16504 (substring (match-string 0) 1 -1)
16507 ;; noalign: if there were two spaces at the end, this field
16508 ;; does not determine the width of the column.
16509 (if noalign (setq org-table-may-need-update c)))
16512 (org-fix-tags-on-the-fly)))
16514 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
16515 (put 'org-self-insert-command 'delete-selection t)
16516 (put 'orgtbl-self-insert-command 'delete-selection t)
16517 (put 'org-delete-char 'delete-selection 'supersede)
16518 (put 'org-delete-backward-char 'delete-selection 'supersede)
16519 (put 'org-yank 'delete-selection 'yank)
16521 ;; Make `flyspell-mode' delay after some commands
16522 (put 'org-self-insert-command 'flyspell-delayed t)
16523 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
16524 (put 'org-delete-char 'flyspell-delayed t)
16525 (put 'org-delete-backward-char 'flyspell-delayed t)
16527 ;; Make pabbrev-mode expand after org-mode commands
16528 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
16529 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
16531 ;; How to do this: Measure non-white length of current string
16532 ;; If equal to column width, we should realign.
16534 (defun org-remap (map &rest commands)
16535 "In MAP, remap the functions given in COMMANDS.
16536 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
16539 (setq old (pop commands) new (pop commands))
16540 (if (fboundp 'command-remapping)
16541 (org-defkey map (vector 'remap old) new)
16542 (substitute-key-definition old new map global-map)))))
16544 (when (eq org-enable-table-editor 'optimized)
16545 ;; If the user wants maximum table support, we need to hijack
16546 ;; some standard editing functions
16547 (org-remap org-mode-map
16548 'self-insert-command 'org-self-insert-command
16549 'delete-char 'org-delete-char
16550 'delete-backward-char 'org-delete-backward-char)
16551 (org-defkey org-mode-map "|" 'org-force-self-insert))
16553 (defvar org-ctrl-c-ctrl-c-hook nil
16554 "Hook for functions attaching themselves to `C-c C-c'.
16555 This can be used to add additional functionality to the C-c C-c key which
16556 executes context-dependent commands.
16557 Each function will be called with no arguments. The function must check
16558 if the context is appropriate for it to act. If yes, it should do its
16559 thing and then return a non-nil value. If the context is wrong,
16560 just do nothing and return nil.")
16562 (defvar org-tab-first-hook nil
16563 "Hook for functions to attach themselves to TAB.
16564 See `org-ctrl-c-ctrl-c-hook' for more information.
16565 This hook runs as the first action when TAB is pressed, even before
16566 `org-cycle' messes around with the `outline-regexp' to cater for
16567 inline tasks and plain list item folding.
16568 If any function in this hook returns t, any other actions that
16569 would have been caused by TAB (such as table field motion or visibility
16570 cycling) will not occur.")
16572 (defvar org-tab-after-check-for-table-hook nil
16573 "Hook for functions to attach themselves to TAB.
16574 See `org-ctrl-c-ctrl-c-hook' for more information.
16575 This hook runs after it has been established that the cursor is not in a
16576 table, but before checking if the cursor is in a headline or if global cycling
16578 If any function in this hook returns t, not other actions like visibility
16579 cycling will be done.")
16581 (defvar org-tab-after-check-for-cycling-hook nil
16582 "Hook for functions to attach themselves to TAB.
16583 See `org-ctrl-c-ctrl-c-hook' for more information.
16584 This hook runs after it has been established that not table field motion and
16585 not visibility should be done because of current context. This is probably
16586 the place where a package like yasnippets can hook in.")
16588 (defvar org-tab-before-tab-emulation-hook nil
16589 "Hook for functions to attach themselves to TAB.
16590 See `org-ctrl-c-ctrl-c-hook' for more information.
16591 This hook runs after every other options for TAB have been exhausted, but
16592 before indentation and \t insertion takes place.")
16594 (defvar org-metaleft-hook nil
16595 "Hook for functions attaching themselves to `M-left'.
16596 See `org-ctrl-c-ctrl-c-hook' for more information.")
16597 (defvar org-metaright-hook nil
16598 "Hook for functions attaching themselves to `M-right'.
16599 See `org-ctrl-c-ctrl-c-hook' for more information.")
16600 (defvar org-metaup-hook nil
16601 "Hook for functions attaching themselves to `M-up'.
16602 See `org-ctrl-c-ctrl-c-hook' for more information.")
16603 (defvar org-metadown-hook nil
16604 "Hook for functions attaching themselves to `M-down'.
16605 See `org-ctrl-c-ctrl-c-hook' for more information.")
16606 (defvar org-shiftmetaleft-hook nil
16607 "Hook for functions attaching themselves to `M-S-left'.
16608 See `org-ctrl-c-ctrl-c-hook' for more information.")
16609 (defvar org-shiftmetaright-hook nil
16610 "Hook for functions attaching themselves to `M-S-right'.
16611 See `org-ctrl-c-ctrl-c-hook' for more information.")
16612 (defvar org-shiftmetaup-hook nil
16613 "Hook for functions attaching themselves to `M-S-up'.
16614 See `org-ctrl-c-ctrl-c-hook' for more information.")
16615 (defvar org-shiftmetadown-hook nil
16616 "Hook for functions attaching themselves to `M-S-down'.
16617 See `org-ctrl-c-ctrl-c-hook' for more information.")
16618 (defvar org-metareturn-hook nil
16619 "Hook for functions attaching themselves to `M-RET'.
16620 See `org-ctrl-c-ctrl-c-hook' for more information.")
16621 (defvar org-shiftup-hook nil
16622 "Hook for functions attaching themselves to `S-up'.
16623 See `org-ctrl-c-ctrl-c-hook' for more information.")
16624 (defvar org-shiftup-final-hook nil
16625 "Hook for functions attaching themselves to `S-up'.
16626 This one runs after all other options except shift-select have been excluded.
16627 See `org-ctrl-c-ctrl-c-hook' for more information.")
16628 (defvar org-shiftdown-hook nil
16629 "Hook for functions attaching themselves to `S-down'.
16630 See `org-ctrl-c-ctrl-c-hook' for more information.")
16631 (defvar org-shiftdown-final-hook nil
16632 "Hook for functions attaching themselves to `S-down'.
16633 This one runs after all other options except shift-select have been excluded.
16634 See `org-ctrl-c-ctrl-c-hook' for more information.")
16635 (defvar org-shiftleft-hook nil
16636 "Hook for functions attaching themselves to `S-left'.
16637 See `org-ctrl-c-ctrl-c-hook' for more information.")
16638 (defvar org-shiftleft-final-hook nil
16639 "Hook for functions attaching themselves to `S-left'.
16640 This one runs after all other options except shift-select have been excluded.
16641 See `org-ctrl-c-ctrl-c-hook' for more information.")
16642 (defvar org-shiftright-hook nil
16643 "Hook for functions attaching themselves to `S-right'.
16644 See `org-ctrl-c-ctrl-c-hook' for more information.")
16645 (defvar org-shiftright-final-hook nil
16646 "Hook for functions attaching themselves to `S-right'.
16647 This one runs after all other options except shift-select have been excluded.
16648 See `org-ctrl-c-ctrl-c-hook' for more information.")
16650 (defun org-modifier-cursor-error ()
16651 "Throw an error, a modified cursor command was applied in wrong context."
16652 (error "This command is active in special context like tables, headlines or items"))
16654 (defun org-shiftselect-error ()
16655 "Throw an error because Shift-Cursor command was applied in wrong context."
16656 (if (and (boundp 'shift-select-mode) shift-select-mode)
16657 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
16658 (error "This command works only in special context like headlines or timestamps")))
16660 (defun org-call-for-shift-select (cmd)
16661 (let ((this-command-keys-shift-translated t))
16662 (call-interactively cmd)))
16664 (defun org-shifttab (&optional arg)
16665 "Global visibility cycling or move to previous table field.
16666 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
16668 See the individual commands for more information."
16671 ((org-at-table-p) (call-interactively 'org-table-previous-field))
16673 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
16674 (message "Content view to level: %d" arg)
16675 (org-content (prefix-numeric-value arg2))
16676 (setq org-cycle-global-status 'overview)))
16677 (t (call-interactively 'org-global-cycle))))
16679 (defun org-shiftmetaleft ()
16680 "Promote subtree or delete table column.
16681 Calls `org-promote-subtree', `org-outdent-item',
16682 or `org-table-delete-column', depending on context.
16683 See the individual commands for more information."
16686 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
16687 ((org-at-table-p) (call-interactively 'org-table-delete-column))
16688 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
16689 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
16690 (t (org-modifier-cursor-error))))
16692 (defun org-shiftmetaright ()
16693 "Demote subtree or insert table column.
16694 Calls `org-demote-subtree', `org-indent-item',
16695 or `org-table-insert-column', depending on context.
16696 See the individual commands for more information."
16699 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
16700 ((org-at-table-p) (call-interactively 'org-table-insert-column))
16701 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
16702 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
16703 (t (org-modifier-cursor-error))))
16705 (defun org-shiftmetaup (&optional arg)
16706 "Move subtree up or kill table row.
16707 Calls `org-move-subtree-up' or `org-table-kill-row' or
16708 `org-move-item-up' depending on context. See the individual commands
16709 for more information."
16712 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16713 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16714 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16715 ((org-at-item-p) (call-interactively 'org-move-item-up))
16716 (t (org-modifier-cursor-error))))
16718 (defun org-shiftmetadown (&optional arg)
16719 "Move subtree down or insert table row.
16720 Calls `org-move-subtree-down' or `org-table-insert-row' or
16721 `org-move-item-down', depending on context. See the individual
16722 commands for more information."
16725 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16726 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16727 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16728 ((org-at-item-p) (call-interactively 'org-move-item-down))
16729 (t (org-modifier-cursor-error))))
16731 (defsubst org-hidden-tree-error ()
16733 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
16735 (defun org-metaleft (&optional arg)
16736 "Promote heading or move table column to left.
16737 Calls `org-do-promote' or `org-table-move-column', depending on context.
16738 With no specific context, calls the Emacs default `backward-word'.
16739 See the individual commands for more information."
16742 ((run-hook-with-args-until-success 'org-metaleft-hook))
16743 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16744 ((or (org-on-heading-p)
16745 (and (org-region-active-p)
16747 (goto-char (region-beginning))
16748 (org-on-heading-p))))
16749 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16750 (call-interactively 'org-do-promote))
16751 ((or (org-at-item-p)
16752 (and (org-region-active-p)
16754 (goto-char (region-beginning))
16756 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16757 (call-interactively 'org-outdent-item))
16758 (t (call-interactively 'backward-word))))
16760 (defun org-metaright (&optional arg)
16761 "Demote subtree or move table column to right.
16762 Calls `org-do-demote' or `org-table-move-column', depending on context.
16763 With no specific context, calls the Emacs default `forward-word'.
16764 See the individual commands for more information."
16767 ((run-hook-with-args-until-success 'org-metaright-hook))
16768 ((org-at-table-p) (call-interactively 'org-table-move-column))
16769 ((or (org-on-heading-p)
16770 (and (org-region-active-p)
16772 (goto-char (region-beginning))
16773 (org-on-heading-p))))
16774 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16775 (call-interactively 'org-do-demote))
16776 ((or (org-at-item-p)
16777 (and (org-region-active-p)
16779 (goto-char (region-beginning))
16781 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16782 (call-interactively 'org-indent-item))
16783 (t (call-interactively 'forward-word))))
16785 (defun org-check-for-hidden (what)
16786 "Check if there are hidden headlines/items in the current visual line.
16787 WHAT can be either `headlines' or `items'. If the current line is
16788 an outline or item heading and it has a folded subtree below it,
16789 this fucntion returns t, nil otherwise."
16791 ((eq what 'headlines) (concat "^" org-outline-regexp))
16792 ((eq what 'items) (concat "^" (org-item-re t)))
16793 (t (error "This should not happen"))))
16797 (unless (org-region-active-p)
16798 (setq beg (point-at-bol))
16799 (beginning-of-line 2)
16800 (while (and (not (eobp)) ;; this is like `next-line'
16801 (get-char-property (1- (point)) 'invisible))
16802 (beginning-of-line 2))
16805 (goto-char (point-at-eol))
16806 (setq end (max end (point)))
16807 (while (re-search-forward re end t)
16808 (if (get-char-property (match-beginning 0) 'invisible)
16812 (defun org-metaup (&optional arg)
16813 "Move subtree up or move table row up.
16814 Calls `org-move-subtree-up' or `org-table-move-row' or
16815 `org-move-item-up', depending on context. See the individual commands
16816 for more information."
16819 ((run-hook-with-args-until-success 'org-metaup-hook))
16820 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16821 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16822 ((org-at-item-p) (call-interactively 'org-move-item-up))
16823 (t (transpose-lines 1) (beginning-of-line -1))))
16825 (defun org-metadown (&optional arg)
16826 "Move subtree down or move table row down.
16827 Calls `org-move-subtree-down' or `org-table-move-row' or
16828 `org-move-item-down', depending on context. See the individual
16829 commands for more information."
16832 ((run-hook-with-args-until-success 'org-metadown-hook))
16833 ((org-at-table-p) (call-interactively 'org-table-move-row))
16834 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16835 ((org-at-item-p) (call-interactively 'org-move-item-down))
16836 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16838 (defun org-shiftup (&optional arg)
16839 "Increase item in timestamp or increase priority of current headline.
16840 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16841 depending on context. See the individual commands for more information."
16844 ((run-hook-with-args-until-success 'org-shiftup-hook))
16845 ((and org-support-shift-select (org-region-active-p))
16846 (org-call-for-shift-select 'previous-line))
16847 ((org-at-timestamp-p t)
16848 (call-interactively (if org-edit-timestamp-down-means-later
16849 'org-timestamp-down 'org-timestamp-up)))
16850 ((and (not (eq org-support-shift-select 'always))
16851 org-enable-priority-commands
16852 (org-on-heading-p))
16853 (call-interactively 'org-priority-up))
16854 ((and (not org-support-shift-select) (org-at-item-p))
16855 (call-interactively 'org-previous-item))
16856 ((org-clocktable-try-shift 'up arg))
16857 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
16858 (org-support-shift-select
16859 (org-call-for-shift-select 'previous-line))
16860 (t (org-shiftselect-error))))
16862 (defun org-shiftdown (&optional arg)
16863 "Decrease item in timestamp or decrease priority of current headline.
16864 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16865 depending on context. See the individual commands for more information."
16868 ((run-hook-with-args-until-success 'org-shiftdown-hook))
16869 ((and org-support-shift-select (org-region-active-p))
16870 (org-call-for-shift-select 'next-line))
16871 ((org-at-timestamp-p t)
16872 (call-interactively (if org-edit-timestamp-down-means-later
16873 'org-timestamp-up 'org-timestamp-down)))
16874 ((and (not (eq org-support-shift-select 'always))
16875 org-enable-priority-commands
16876 (org-on-heading-p))
16877 (call-interactively 'org-priority-down))
16878 ((and (not org-support-shift-select) (org-at-item-p))
16879 (call-interactively 'org-next-item))
16880 ((org-clocktable-try-shift 'down arg))
16881 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
16882 (org-support-shift-select
16883 (org-call-for-shift-select 'next-line))
16884 (t (org-shiftselect-error))))
16886 (defun org-shiftright (&optional arg)
16887 "Cycle the thing at point or in the current line, depending on context.
16888 Depending on context, this does one of the following:
16890 - switch a timestamp at point one day into the future
16891 - on a headline, switch to the next TODO keyword.
16892 - on an item, switch entire list to the next bullet type
16893 - on a property line, switch to the next allowed value
16894 - on a clocktable definition line, move time block into the future"
16897 ((run-hook-with-args-until-success 'org-shiftright-hook))
16898 ((and org-support-shift-select (org-region-active-p))
16899 (org-call-for-shift-select 'forward-char))
16900 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16901 ((and (not (eq org-support-shift-select 'always))
16902 (org-on-heading-p))
16903 (let ((org-inhibit-logging
16904 (not org-treat-S-cursor-todo-selection-as-state-change))
16905 (org-inhibit-blocking
16906 (not org-treat-S-cursor-todo-selection-as-state-change)))
16907 (org-call-with-arg 'org-todo 'right)))
16908 ((or (and org-support-shift-select
16909 (not (eq org-support-shift-select 'always))
16910 (org-at-item-bullet-p))
16911 (and (not org-support-shift-select) (org-at-item-p)))
16912 (org-call-with-arg 'org-cycle-list-bullet nil))
16913 ((and (not (eq org-support-shift-select 'always))
16914 (org-at-property-p))
16915 (call-interactively 'org-property-next-allowed-value))
16916 ((org-clocktable-try-shift 'right arg))
16917 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
16918 (org-support-shift-select
16919 (org-call-for-shift-select 'forward-char))
16920 (t (org-shiftselect-error))))
16922 (defun org-shiftleft (&optional arg)
16923 "Cycle the thing at point or in the current line, depending on context.
16924 Depending on context, this does one of the following:
16926 - switch a timestamp at point one day into the past
16927 - on a headline, switch to the previous TODO keyword.
16928 - on an item, switch entire list to the previous bullet type
16929 - on a property line, switch to the previous allowed value
16930 - on a clocktable definition line, move time block into the past"
16933 ((run-hook-with-args-until-success 'org-shiftleft-hook))
16934 ((and org-support-shift-select (org-region-active-p))
16935 (org-call-for-shift-select 'backward-char))
16936 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16937 ((and (not (eq org-support-shift-select 'always))
16938 (org-on-heading-p))
16939 (let ((org-inhibit-logging
16940 (not org-treat-S-cursor-todo-selection-as-state-change))
16941 (org-inhibit-blocking
16942 (not org-treat-S-cursor-todo-selection-as-state-change)))
16943 (org-call-with-arg 'org-todo 'left)))
16944 ((or (and org-support-shift-select
16945 (not (eq org-support-shift-select 'always))
16946 (org-at-item-bullet-p))
16947 (and (not org-support-shift-select) (org-at-item-p)))
16948 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16949 ((and (not (eq org-support-shift-select 'always))
16950 (org-at-property-p))
16951 (call-interactively 'org-property-previous-allowed-value))
16952 ((org-clocktable-try-shift 'left arg))
16953 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
16954 (org-support-shift-select
16955 (org-call-for-shift-select 'backward-char))
16956 (t (org-shiftselect-error))))
16958 (defun org-shiftcontrolright ()
16959 "Switch to next TODO set."
16962 ((and org-support-shift-select (org-region-active-p))
16963 (org-call-for-shift-select 'forward-word))
16964 ((and (not (eq org-support-shift-select 'always))
16965 (org-on-heading-p))
16966 (org-call-with-arg 'org-todo 'nextset))
16967 (org-support-shift-select
16968 (org-call-for-shift-select 'forward-word))
16969 (t (org-shiftselect-error))))
16971 (defun org-shiftcontrolleft ()
16972 "Switch to previous TODO set."
16975 ((and org-support-shift-select (org-region-active-p))
16976 (org-call-for-shift-select 'backward-word))
16977 ((and (not (eq org-support-shift-select 'always))
16978 (org-on-heading-p))
16979 (org-call-with-arg 'org-todo 'previousset))
16980 (org-support-shift-select
16981 (org-call-for-shift-select 'backward-word))
16982 (t (org-shiftselect-error))))
16984 (defun org-ctrl-c-ret ()
16985 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16988 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16989 (t (call-interactively 'org-insert-heading))))
16991 (defun org-copy-special ()
16992 "Copy region in table or copy current subtree.
16993 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16994 See the individual commands for more information."
16996 (call-interactively
16997 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16999 (defun org-cut-special ()
17000 "Cut region in table or cut current subtree.
17001 Calls `org-table-copy' or `org-cut-subtree', depending on context.
17002 See the individual commands for more information."
17004 (call-interactively
17005 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
17007 (defun org-paste-special (arg)
17008 "Paste rectangular region into table, or past subtree relative to level.
17009 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
17010 See the individual commands for more information."
17012 (if (org-at-table-p)
17013 (org-table-paste-rectangle)
17014 (org-paste-subtree arg)))
17016 (defun org-edit-special (&optional arg)
17017 "Call a special editor for the stuff at point.
17018 When at a table, call the formula editor with `org-table-edit-formulas'.
17019 When at the first line of an src example, call `org-edit-src-code'.
17020 When in an #+include line, visit the include file. Otherwise call
17021 `ffap' to visit the file at point."
17023 ;; possibly prep session before editing source
17025 (let* ((info (org-babel-get-src-block-info))
17026 (lang (nth 0 info))
17027 (params (nth 2 info))
17028 (session (cdr (assoc :session params))))
17029 (when (and info session) ;; we are in a source-code block with a session
17031 (intern (concat "org-babel-prep-session:" lang)) session params))))
17032 (cond ;; proceed with `org-edit-special'
17034 (beginning-of-line 1)
17035 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
17036 (find-file (org-trim (match-string 1))))
17037 ((org-edit-src-code))
17038 ((org-edit-fixed-width-region))
17039 ((org-at-table.el-p)
17040 (org-edit-src-code))
17042 (call-interactively 'org-table-edit-formulas))
17043 (t (call-interactively 'ffap))))
17046 (defun org-ctrl-c-ctrl-c (&optional arg)
17047 "Set tags in headline, or update according to changed information at point.
17049 This command does many different things, depending on context:
17051 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
17052 this is what we do.
17054 - If the cursor is on a statistics cookie, update it.
17056 - If the cursor is in a headline, prompt for tags and insert them
17057 into the current line, aligned to `org-tags-column'. When called
17058 with prefix arg, realign all tags in the current buffer.
17060 - If the cursor is in one of the special #+KEYWORD lines, this
17061 triggers scanning the buffer for these lines and updating the
17064 - If the cursor is inside a table, realign the table. This command
17065 works even if the automatic table editor has been turned off.
17067 - If the cursor is on a #+TBLFM line, re-apply the formulas to
17070 - If the cursor is at a footnote reference or definition, jump to
17071 the corresponding definition or references, respectively.
17073 - If the cursor is a the beginning of a dynamic block, update it.
17075 - If the current buffer is a remember buffer, close note and file
17076 it. A prefix argument of 1 files to the default location
17077 without further interaction. A prefix argument of 2 files to
17078 the currently clocking task.
17080 - If the cursor is on a <<<target>>>, update radio targets and corresponding
17081 links in this buffer.
17083 - If the cursor is on a numbered item in a plain list, renumber the
17086 - If the cursor is on a checkbox, toggle it.
17088 - If the cursor is on a code block, evaluate it. The variable
17089 `org-confirm-babel-evaluate' can be used to control prompting
17090 before code block evaluation, by default every code block
17091 evaluation requires confirmation. Code block evaluation can be
17092 inhibited by setting `org-babel-no-eval-on-ctrl-c-ctrl-c'."
17094 (let ((org-enable-table-editor t))
17096 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
17097 org-occur-highlights
17098 org-latex-fragment-image-overlays)
17099 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
17100 (org-remove-occur-highlights)
17101 (org-remove-latex-fragment-image-overlays)
17102 (message "Temporary highlights/overlays removed from current buffer"))
17103 ((and (local-variable-p 'org-finish-function (current-buffer))
17104 (fboundp org-finish-function))
17105 (funcall org-finish-function))
17106 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
17107 ((or (looking-at org-property-start-re)
17108 (org-at-property-p))
17109 (call-interactively 'org-property-action))
17110 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
17111 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
17112 (or (org-on-heading-p) (org-at-item-p)))
17113 (call-interactively 'org-update-statistics-cookies))
17114 ((org-on-heading-p) (call-interactively 'org-set-tags))
17115 ((org-at-table.el-p)
17116 (message "Use C-c ' to edit table.el tables"))
17118 (org-table-maybe-eval-formula)
17120 (call-interactively 'org-table-recalculate)
17121 (org-table-maybe-recalculate-line))
17122 (call-interactively 'org-table-align))
17123 ((or (org-footnote-at-reference-p)
17124 (org-footnote-at-definition-p))
17125 (call-interactively 'org-footnote-action))
17126 ((org-at-item-checkbox-p)
17127 (call-interactively 'org-toggle-checkbox)
17128 (org-list-send-list 'maybe))
17131 (call-interactively 'org-toggle-checkbox)
17132 (call-interactively 'org-maybe-renumber-ordered-list))
17133 (org-list-send-list 'maybe))
17134 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
17136 (beginning-of-line 1)
17137 (save-excursion (org-update-dblock)))
17139 (beginning-of-line 1)
17140 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
17142 ((equal (match-string 1) "TBLFM")
17143 ;; Recalculate the table before this line
17145 (beginning-of-line 1)
17146 (skip-chars-backward " \r\n\t")
17147 (if (org-at-table-p)
17148 (org-call-with-arg 'org-table-recalculate (or arg t)))))
17150 (let ((org-inhibit-startup-visibility-stuff t)
17151 (org-startup-align-all-tables nil))
17152 (org-save-outline-visibility 'use-markers (org-mode-restart)))
17153 (message "Local setup has been refreshed"))))
17154 ((org-clock-update-time-maybe))
17155 (t (error "C-c C-c can do nothing useful at this location")))))
17157 (defun org-mode-restart ()
17158 "Restart Org-mode, to scan again for special lines.
17159 Also updates the keyword regular expressions."
17162 (message "Org-mode restarted"))
17164 (defun org-kill-note-or-show-branches ()
17165 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
17167 (if (not org-finish-function)
17170 (call-interactively 'show-branches))
17171 (let ((org-note-abort t))
17172 (funcall org-finish-function))))
17174 (defun org-return (&optional indent)
17175 "Goto next table row or insert a newline.
17176 Calls `org-table-next-row' or `newline', depending on context.
17177 See the individual commands for more information."
17180 ((bobp) (if indent (newline-and-indent) (newline)))
17182 (org-table-justify-field-maybe)
17183 (call-interactively 'org-table-next-row))
17184 ((and org-return-follows-link
17185 (eq (get-text-property (point) 'face) 'org-link))
17186 (call-interactively 'org-open-at-point))
17187 ((and (org-at-heading-p)
17189 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
17193 (t (if indent (newline-and-indent) (newline)))))
17195 (defun org-return-indent ()
17196 "Goto next table row or insert a newline and indent.
17197 Calls `org-table-next-row' or `newline-and-indent', depending on
17198 context. See the individual commands for more information."
17202 (defun org-ctrl-c-star ()
17203 "Compute table, or change heading status of lines.
17204 Calls `org-table-recalculate' or `org-toggle-heading',
17205 depending on context."
17209 (call-interactively 'org-table-recalculate))
17211 ;; Convert all lines in region to list items
17212 (call-interactively 'org-toggle-heading))))
17214 (defun org-ctrl-c-minus ()
17215 "Insert separator line in table or modify bullet status of line.
17216 Also turns a plain line or a region of lines into list items.
17217 Calls `org-table-insert-hline', `org-toggle-item', or
17218 `org-cycle-list-bullet', depending on context."
17222 (call-interactively 'org-table-insert-hline))
17223 ((org-region-active-p)
17224 (call-interactively 'org-toggle-item))
17226 (call-interactively 'org-cycle-list-bullet))
17228 (call-interactively 'org-toggle-item))))
17230 (defun org-toggle-item ()
17231 "Convert headings or normal lines to items, items to normal lines.
17232 If there is no active region, only the current line is considered.
17234 If the first line in the region is a headline, convert all headlines to items.
17236 If the first line in the region is an item, convert all items to normal lines.
17238 If the first line is normal text, add an item bullet to each line."
17240 (let (l2 l beg end)
17241 (if (org-region-active-p)
17242 (setq beg (region-beginning) end (region-end))
17243 (setq beg (point-at-bol)
17244 end (min (1+ (point-at-eol)) (point-max))))
17247 (setq l2 (org-current-line))
17249 (beginning-of-line 1)
17250 (setq l (1- (org-current-line)))
17251 (if (org-at-item-p)
17252 ;; We already have items, de-itemize
17253 (while (< (setq l (1+ l)) l2)
17254 (when (org-at-item-p)
17255 (goto-char (match-beginning 2))
17256 (delete-region (match-beginning 2) (match-end 2))
17257 (and (looking-at "[ \t]+") (replace-match "")))
17258 (beginning-of-line 2))
17259 (if (org-on-heading-p)
17260 ;; Headings, convert to items
17261 (while (< (setq l (1+ l)) l2)
17262 (if (looking-at org-outline-regexp)
17263 (replace-match "- " t t))
17264 (beginning-of-line 2))
17265 ;; normal lines, turn them into items
17266 (while (< (setq l (1+ l)) l2)
17267 (unless (org-at-item-p)
17268 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17269 (replace-match "\\1- \\2")))
17270 (beginning-of-line 2)))))))
17272 (defun org-toggle-heading (&optional nstars)
17273 "Convert headings to normal text, or items or text to headings.
17274 If there is no active region, only the current line is considered.
17276 If the first line is a heading, remove the stars from all headlines
17279 If the first line is a plain list item, turn all plain list items
17282 If the first line is a normal line, turn each and every line in the
17283 region into a heading.
17285 When converting a line into a heading, the number of stars is chosen
17286 such that the lines become children of the current entry. However,
17287 when a prefix argument is given, its value determines the number of
17290 (let (l2 l itemp beg end)
17291 (if (org-region-active-p)
17292 (setq beg (region-beginning) end (region-end))
17293 (setq beg (point-at-bol)
17294 end (min (1+ (point-at-eol)) (point-max))))
17297 (setq l2 (org-current-line))
17299 (beginning-of-line 1)
17300 (setq l (1- (org-current-line)))
17301 (if (org-on-heading-p)
17302 ;; We already have headlines, de-star them
17303 (while (< (setq l (1+ l)) l2)
17304 (when (org-on-heading-p t)
17305 (and (looking-at outline-regexp) (replace-match "")))
17306 (beginning-of-line 2))
17307 (setq itemp (org-at-item-p))
17310 (make-string (prefix-numeric-value current-prefix-arg)
17313 (if (re-search-backward org-complex-heading-regexp nil t)
17314 (match-string 1) ""))))
17315 (add-stars (cond (nstars "")
17316 ((equal stars "") "*")
17317 (org-odd-levels-only "**")
17319 (rpl (concat stars add-stars " ")))
17320 (while (< (setq l (1+ l)) l2)
17322 (and (org-at-item-p) (replace-match rpl t t))
17323 (unless (org-on-heading-p)
17324 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17325 (replace-match (concat rpl (match-string 2))))))
17326 (beginning-of-line 2)))))))
17328 (defun org-meta-return (&optional arg)
17329 "Insert a new heading or wrap a region in a table.
17330 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
17331 See the individual commands for more information."
17334 ((run-hook-with-args-until-success 'org-metareturn-hook))
17336 (call-interactively 'org-table-wrap-region))
17337 (t (call-interactively 'org-insert-heading))))
17341 ;; Define the Org-mode menus
17342 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
17344 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
17345 ["Next Field" org-cycle (org-at-table-p)]
17346 ["Previous Field" org-shifttab (org-at-table-p)]
17347 ["Next Row" org-return (org-at-table-p)]
17349 ["Blank Field" org-table-blank-field (org-at-table-p)]
17350 ["Edit Field" org-table-edit-field (org-at-table-p)]
17351 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
17354 ["Move Column Left" org-metaleft (org-at-table-p)]
17355 ["Move Column Right" org-metaright (org-at-table-p)]
17356 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
17357 ["Insert Column" org-shiftmetaright (org-at-table-p)])
17359 ["Move Row Up" org-metaup (org-at-table-p)]
17360 ["Move Row Down" org-metadown (org-at-table-p)]
17361 ["Delete Row" org-shiftmetaup (org-at-table-p)]
17362 ["Insert Row" org-shiftmetadown (org-at-table-p)]
17363 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
17365 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
17367 ["Copy Rectangle" org-copy-special (org-at-table-p)]
17368 ["Cut Rectangle" org-cut-special (org-at-table-p)]
17369 ["Paste Rectangle" org-paste-special (org-at-table-p)]
17370 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
17373 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
17374 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
17375 ["Edit Formulas" org-edit-special (org-at-table-p)]
17377 ["Recalculate line" org-table-recalculate (org-at-table-p)]
17378 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
17379 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
17381 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
17383 ["Sum Column/Rectangle" org-table-sum
17384 (or (org-at-table-p) (org-region-active-p))]
17385 ["Which Column?" org-table-current-column (org-at-table-p)])
17387 org-table-toggle-formula-debugger
17388 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
17389 ["Show Col/Row Numbers"
17390 org-table-toggle-coordinate-overlays
17392 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
17394 ["Create" org-table-create (and (not (org-at-table-p))
17395 org-enable-table-editor)]
17396 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
17397 ["Import from File" org-table-import (not (org-at-table-p))]
17398 ["Export to File" org-table-export (org-at-table-p)]
17400 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
17402 (easy-menu-define org-org-menu org-mode-map "Org menu"
17405 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
17406 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
17407 ["Sparse Tree..." org-sparse-tree t]
17408 ["Reveal Context" org-reveal t]
17409 ["Show All" show-all t]
17411 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
17413 ["New Heading" org-insert-heading t]
17414 ("Navigate Headings"
17415 ["Up" outline-up-heading t]
17416 ["Next" outline-next-visible-heading t]
17417 ["Previous" outline-previous-visible-heading t]
17418 ["Next Same Level" outline-forward-same-level t]
17419 ["Previous Same Level" outline-backward-same-level t]
17421 ["Jump" org-goto t])
17423 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
17424 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
17426 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
17427 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
17428 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
17430 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
17432 ["Promote Heading" org-metaleft (not (org-at-table-p))]
17433 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
17434 ["Demote Heading" org-metaright (not (org-at-table-p))]
17435 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
17437 ["Sort Region/Children" org-sort (not (org-at-table-p))]
17439 ["Convert to odd levels" org-convert-to-odd-levels t]
17440 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
17442 ["Emphasis..." org-emphasize t]
17443 ["Edit Source Example" org-edit-special t]
17445 ["Footnote new/jump" org-footnote-action t]
17446 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
17448 ["Archive (default method)" org-archive-subtree-default t]
17450 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
17451 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
17452 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
17456 ["Store Link (Global)" org-store-link t]
17457 ["Find existing link to here" org-occur-link-in-agenda-files t]
17458 ["Insert Link" org-insert-link t]
17459 ["Follow Link" org-open-at-point t]
17461 ["Next link" org-next-link t]
17462 ["Previous link" org-previous-link t]
17464 ["Descriptive Links"
17465 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
17467 :selected (member '(org-link) buffer-invisibility-spec)]
17470 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
17472 :selected (not (member '(org-link) buffer-invisibility-spec))])
17475 ["TODO/DONE/-" org-todo t]
17477 ["Next keyword" org-shiftright (org-on-heading-p)]
17478 ["Previous keyword" org-shiftleft (org-on-heading-p)]
17479 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
17480 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
17481 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
17482 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
17483 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
17485 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
17486 :selected org-enforce-todo-dependencies :style toggle :active t]
17487 "Settings for tree at point"
17488 ["Do Children sequentially" org-toggle-ordered-property :style radio
17489 :selected (ignore-errors (org-entry-get nil "ORDERED"))
17490 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17491 ["Do Children parallel" org-toggle-ordered-property :style radio
17492 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
17493 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17495 ["Set Priority" org-priority t]
17496 ["Priority Up" org-shiftup t]
17497 ["Priority Down" org-shiftdown t]
17499 ["Get news from all feeds" org-feed-update-all t]
17500 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
17501 ["Customize feeds" (customize-variable 'org-feed-alist) t])
17502 ("TAGS and Properties"
17503 ["Set Tags" org-set-tags-command t]
17504 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
17506 ["Set property" org-set-property t]
17507 ["Column view of properties" org-columns t]
17508 ["Insert Column View DBlock" org-insert-columns-dblock t])
17509 ("Dates and Scheduling"
17510 ["Timestamp" org-time-stamp t]
17511 ["Timestamp (inactive)" org-time-stamp-inactive t]
17513 ["1 Day Later" org-shiftright t]
17514 ["1 Day Earlier" org-shiftleft t]
17515 ["1 ... Later" org-shiftup t]
17516 ["1 ... Earlier" org-shiftdown t])
17517 ["Compute Time Range" org-evaluate-time-range t]
17518 ["Schedule Item" org-schedule t]
17519 ["Deadline" org-deadline t]
17521 ["Custom time format" org-toggle-time-stamp-overlays
17522 :style radio :selected org-display-custom-times]
17524 ["Goto Calendar" org-goto-calendar t]
17525 ["Date from Calendar" org-date-from-calendar t]
17527 ["Start/Restart Timer" org-timer-start t]
17528 ["Pause/Continue Timer" org-timer-pause-or-continue t]
17529 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
17530 ["Insert Timer String" org-timer t]
17531 ["Insert Timer Item" org-timer-item t])
17533 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
17534 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
17535 ["Clock out" org-clock-out t]
17536 ["Clock cancel" org-clock-cancel t]
17538 ["Mark as default task" org-clock-mark-default-task t]
17539 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
17540 ["Goto running clock" org-clock-goto t]
17542 ["Display times" org-clock-display t]
17543 ["Create clock table" org-clock-report t]
17545 ["Record DONE time"
17546 (progn (setq org-log-done (not org-log-done))
17547 (message "Switching to %s will %s record a timestamp"
17548 (car org-done-keywords)
17549 (if org-log-done "automatically" "not")))
17550 :style toggle :selected org-log-done])
17552 ["Agenda Command..." org-agenda t]
17553 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
17554 ("File List for Agenda")
17555 ("Special views current file"
17556 ["TODO Tree" org-show-todo-tree t]
17557 ["Check Deadlines" org-check-deadlines t]
17558 ["Timeline" org-timeline t]
17559 ["Tags/Property tree" org-match-sparse-tree t])
17561 ["Export/Publish..." org-export t]
17563 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
17564 :selected org-cdlatex-mode]
17565 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
17566 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
17567 ["Modify math symbol" org-cdlatex-math-modify
17568 (org-inside-LaTeX-fragment-p)]
17569 ["Insert citation" org-reftex-citation t]
17571 ["Export LaTeX fragments as images"
17572 (if (featurep 'org-exp)
17573 (setq org-export-with-LaTeX-fragments
17574 (not org-export-with-LaTeX-fragments))
17575 (require 'org-exp))
17576 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
17577 org-export-with-LaTeX-fragments)]
17579 ["Template for BEAMER" org-insert-beamer-options-template t])
17582 ["Push Files and Views" org-mobile-push t]
17583 ["Get Captured and Flagged" org-mobile-pull t]
17584 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
17586 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
17589 ["Show Version" org-version t]
17590 ["Info Documentation" org-info t])
17592 ["Browse Org Group" org-customize t]
17594 ["Expand This Menu" org-create-customize-menu
17595 (fboundp 'customize-menu-create)])
17596 ["Send bug report" org-submit-bug-report t]
17599 ["Refresh setup current buffer" org-mode-restart t]
17600 ["Reload Org (after update)" org-reload t]
17601 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
17604 (defun org-info (&optional node)
17605 "Read documentation for Org-mode in the info system.
17606 With optional NODE, go directly to that node."
17608 (info (format "(org)%s" (or node ""))))
17611 (defun org-submit-bug-report ()
17612 "Submit a bug report on Org-mode via mail.
17614 Don't hesitate to report any problems or inaccurate documentation.
17616 If you don't have setup sending mail from (X)Emacs, please copy the
17617 output buffer into your mail program, as it gives us important
17618 information about your Org-mode version and configuration."
17620 (require 'reporter)
17621 (org-load-modules-maybe)
17622 (org-require-autoloaded-modules)
17623 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
17624 (reporter-submit-bug-report
17625 "emacs-orgmode@gnu.org"
17628 (save-window-excursion
17629 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
17630 (delete-other-windows)
17632 (insert "You are about to submit a bug report to the Org-mode mailing list.
17634 We would like to add your full Org-mode and Outline configuration to the
17635 bug report. This greatly simplifies the work of the maintainer and
17636 other experts on the mailing list.
17638 HOWEVER, some variables you have customized may contain private
17639 information. The names of customers, colleagues, or friends, might
17640 appear in the form of file names, tags, todo states, or search strings.
17641 If you answer yes to the prompt, you might want to check and remove
17642 such private information before sending the email.")
17643 (add-text-properties (point-min) (point-max) '(face org-warning))
17644 (when (yes-or-no-p "Include your Org-mode configuration ")
17648 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
17649 (or (and (symbol-value v)
17650 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
17652 (get v 'custom-type) (get v 'standard-value)
17653 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
17655 (kill-buffer (get-buffer "*Warn about privacy*"))
17658 "Remember to cover the basics, that is, what you expected to happen and
17659 what in fact did happen. You don't know how to make a good report? See
17661 http://orgmode.org/manual/Feedback.html#Feedback
17663 Your bug report will be posted to the Org-mode mailing list.
17664 ------------------------------------------------------------------------")
17666 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
17667 (replace-match "\\1Bug: \\3 [\\2]")))))
17670 (defun org-install-agenda-files-menu ()
17671 (let ((bl (buffer-list)))
17674 (set-buffer (pop bl))
17675 (if (org-mode-p) (setq bl nil)))
17678 '("Org") "File List for Agenda"
17681 ["Edit File List" (org-edit-agenda-file-list) t]
17682 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
17683 ["Remove Current File from List" org-remove-file t]
17684 ["Cycle through agenda files" org-cycle-agenda-files t]
17685 ["Occur in all agenda files" org-occur-in-agenda-files t]
17687 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
17692 (defun org-require-autoloaded-modules ()
17695 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
17696 org-docbook org-exp org-html org-icalendar
17698 org-publish org-remember org-table
17699 org-timer org-xoxo)))
17702 (defun org-reload (&optional uncompiled)
17703 "Reload all org lisp files.
17704 With prefix arg UNCOMPILED, load the uncompiled versions."
17706 (require 'find-func)
17707 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
17708 (dir-org (file-name-directory (org-find-library-name "org")))
17709 (dir-org-contrib (ignore-errors
17710 (file-name-directory
17711 (org-find-library-name "org-contribdir"))))
17713 (mapcar (lambda (el) (concat "ob" (when el (format "-%s" el)) ".el"))
17714 (append (list nil "comint" "eval" "exp" "keys"
17715 "lob" "ref" "table" "tangle")
17719 (when (cdr lang) (symbol-name (car lang))))
17720 org-babel-load-languages)))))
17722 (append (directory-files dir-org t file-re)
17724 (and dir-org-contrib
17725 (directory-files dir-org-contrib t file-re))))
17726 (remove-re (concat (if (featurep 'xemacs)
17727 "org-colview" "org-colview-xemacs")
17729 (setq files (mapcar 'file-name-sans-extension files))
17730 (setq files (mapcar
17731 (lambda (x) (if (string-match remove-re x) nil x))
17733 (setq files (delq nil files))
17736 (when (featurep (intern (file-name-nondirectory f)))
17737 (if (and (not uncompiled)
17738 (file-exists-p (concat f ".elc")))
17739 (load (concat f ".elc") nil nil t)
17740 (load (concat f ".el") nil nil t))))
17745 (defun org-customize ()
17746 "Call the customize function with org as argument."
17748 (org-load-modules-maybe)
17749 (org-require-autoloaded-modules)
17750 (customize-browse 'org))
17752 (defun org-create-customize-menu ()
17753 "Create a full customization menu for Org-mode, insert it into the menu."
17755 (org-load-modules-maybe)
17756 (org-require-autoloaded-modules)
17757 (if (fboundp 'customize-menu-create)
17760 '("Org") "Customize"
17761 `(["Browse Org group" org-customize t]
17763 ,(customize-menu-create 'org)
17764 ["Set" Custom-set t]
17765 ["Save" Custom-save t]
17766 ["Reset to Current" Custom-reset-current t]
17767 ["Reset to Saved" Custom-reset-saved t]
17768 ["Reset to Standard Settings" Custom-reset-standard t]))
17769 (message "\"Org\"-menu now contains full customization menu"))
17770 (error "Cannot expand menu (outdated version of cus-edit.el)")))
17772 ;;;; Miscellaneous stuff
17774 ;;; Generally useful functions
17776 (defun org-get-at-bol (property)
17777 "Get text property PROPERTY at beginning of line."
17778 (get-text-property (point-at-bol) property))
17780 (defun org-find-text-property-in-string (prop s)
17781 "Return the first non-nil value of property PROP in string S."
17782 (or (get-text-property 0 prop s)
17783 (get-text-property (or (next-single-property-change 0 prop s) 0)
17786 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17787 "Display the given MESSAGE as a warning."
17788 (if (fboundp 'display-warning)
17789 (display-warning 'org message
17790 (if (featurep 'xemacs) 'warning :warning))
17791 (let ((buf (get-buffer-create "*Org warnings*")))
17792 (with-current-buffer buf
17793 (goto-char (point-max))
17794 (insert "Warning (Org): " message)
17797 (display-buffer buf)
17800 (defun org-in-commented-line ()
17801 "Is point in a line starting with `#'?"
17802 (equal (char-after (point-at-bol)) ?#))
17804 (defun org-in-indented-comment-line ()
17805 "Is point in a line starting with `#' after some white space?"
17808 (goto-char (point-at-bol))
17809 (looking-at "[ \t]*#"))))
17811 (defun org-in-verbatim-emphasis ()
17813 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17815 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17816 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17817 (if (and marker (marker-buffer marker)
17818 (buffer-live-p (marker-buffer marker)))
17820 (switch-to-buffer (marker-buffer marker))
17821 (if (or (> marker (point-max)) (< marker (point-min)))
17824 (org-show-context 'org-goto))
17826 (bookmark-jump bookmark)
17827 (error "Cannot find location"))))
17829 (defun org-quote-csv-field (s)
17830 "Quote field for inclusion in CSV material."
17831 (if (string-match "[\",]" s)
17832 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17835 (defun org-plist-delete (plist property)
17836 "Delete PROPERTY from PLIST.
17837 This is in contrast to merely setting it to 0."
17840 (if (not (eq property (car plist)))
17841 (setq p (plist-put p (car plist) (nth 1 plist))))
17842 (setq plist (cddr plist)))
17845 (defun org-force-self-insert (N)
17846 "Needed to enforce self-insert under remapping."
17848 (self-insert-command N))
17850 (defun org-string-width (s)
17851 "Compute width of string, ignoring invisible characters.
17852 This ignores character with invisibility property `org-link', and also
17853 characters with property `org-cwidth', because these will become invisible
17854 upon the next fontification round."
17856 (when (or (eq t buffer-invisibility-spec)
17857 (assq 'org-link buffer-invisibility-spec))
17858 (while (setq b (text-property-any 0 (length s)
17859 'invisible 'org-link s))
17860 (setq s (concat (substring s 0 b)
17861 (substring s (or (next-single-property-change
17862 b 'invisible s) (length s)))))))
17863 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17864 (setq s (concat (substring s 0 b)
17865 (substring s (or (next-single-property-change
17866 b 'org-cwidth s) (length s))))))
17867 (setq l (string-width s) b -1)
17868 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17869 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17872 (defun org-get-indentation (&optional line)
17873 "Get the indentation of the current line, interpreting tabs.
17874 When LINE is given, assume it represents a line and compute its indentation."
17876 (if (string-match "^ *" (org-remove-tabs line))
17879 (beginning-of-line 1)
17880 (skip-chars-forward " \t")
17881 (current-column))))
17883 (defun org-remove-tabs (s &optional width)
17884 "Replace tabulators in S with spaces.
17885 Assumes that s is a single line, starting in column 0."
17886 (setq width (or width tab-width))
17887 (while (string-match "\t" s)
17888 (setq s (replace-match
17890 (- (* width (/ (+ (match-beginning 0) width) width))
17891 (match-beginning 0)) ?\ )
17895 (defun org-fix-indentation (line ind)
17896 "Fix indentation in LINE.
17897 IND is a cons cell with target and minimum indentation.
17898 If the current indentation in LINE is smaller than the minimum,
17899 leave it alone. If it is larger than ind, set it to the target."
17900 (let* ((l (org-remove-tabs line))
17901 (i (org-get-indentation l))
17902 (i1 (car ind)) (i2 (cdr ind)))
17903 (if (>= i i2) (setq l (substring line i2)))
17905 (concat (make-string i1 ?\ ) l)
17908 (defun org-remove-indentation (code &optional n)
17909 "Remove the maximum common indentation from the lines in CODE.
17910 N may optionally be the number of spaces to remove."
17913 (org-do-remove-indentation n)
17916 (defun org-do-remove-indentation (&optional n)
17917 "Remove the maximum common indentation from the buffer."
17918 (untabify (point-min) (point-max))
17919 (let ((min 10000) re)
17922 (goto-char (point-min))
17923 (while (re-search-forward "^ *[^ \n]" nil t)
17924 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17925 (unless (or (= min 0) (= min 10000))
17926 (setq re (format "^ \\{%d\\}" min))
17927 (goto-char (point-min))
17928 (while (re-search-forward re nil t)
17933 (defun org-fill-template (template alist)
17934 "Find each %key of ALIST in TEMPLATE and replace it."
17935 (let ((case-fold-search nil)
17937 (setq alist (sort (copy-sequence alist)
17938 (lambda (a b) (< (length (car a)) (length (car b))))))
17939 (while (setq entry (pop alist))
17941 (replace-regexp-in-string
17942 (concat "%" (regexp-quote (car entry)))
17943 (cdr entry) template t t)))
17946 (defun org-base-buffer (buffer)
17947 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17950 (or (buffer-base-buffer buffer)
17953 (defun org-trim (s)
17954 "Remove whitespace at beginning and end of string."
17955 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17956 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17959 (defun org-wrap (string &optional width lines)
17960 "Wrap string to either a number of lines, or a width in characters.
17961 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17962 that costs. If there is a word longer than WIDTH, the text is actually
17963 wrapped to the length of that word.
17964 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17965 many lines, whatever width that takes.
17966 The return value is a list of lines, without newlines at the end."
17967 (let* ((words (org-split-string string "[ \t\n]+"))
17968 (maxword (apply 'max (mapcar 'org-string-width words)))
17971 (org-do-wrap words (max maxword width)))
17974 (setq ll (org-do-wrap words maxword))
17975 (if (<= (length ll) lines)
17978 (while (> (length ll) lines)
17980 (setq ll (org-do-wrap words w)))
17982 (t (error "Cannot wrap this")))))
17984 (defun org-do-wrap (words width)
17985 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17988 (setq line (pop words))
17989 (while (and words (< (+ (length line) (length (car words))) width))
17990 (setq line (concat line " " (pop words))))
17991 (setq lines (push line lines)))
17994 (defun org-split-string (string &optional separators)
17995 "Splits STRING into substrings at SEPARATORS.
17996 No empty strings are returned if there are matches at the beginning
17997 and end of string."
17998 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
18002 (while (and (string-match rexp string
18004 (= start (match-beginning 0))
18005 (< start (length string)))
18007 (< (match-beginning 0) (length string)))
18009 (or (eq (match-beginning 0) 0)
18010 (and (eq (match-beginning 0) (match-end 0))
18011 (eq (match-beginning 0) start))
18013 (cons (substring string start (match-beginning 0))
18015 (setq start (match-end 0)))
18016 (or (eq start (length string))
18018 (cons (substring string start)
18022 (defun org-quote-vert (s)
18023 "Replace \"|\" with \"\\vert\"."
18024 (while (string-match "|" s)
18025 (setq s (replace-match "\\vert" t t s)))
18028 (defun org-uuidgen-p (s)
18029 "Is S an ID created by UUIDGEN?"
18030 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
18032 (defun org-context ()
18033 "Return a list of contexts of the current cursor position.
18034 If several contexts apply, all are returned.
18035 Each context entry is a list with a symbol naming the context, and
18036 two positions indicating start and end of the context. Possible
18039 :headline anywhere in a headline
18040 :headline-stars on the leading stars in a headline
18041 :todo-keyword on a TODO keyword (including DONE) in a headline
18042 :tags on the TAGS in a headline
18043 :priority on the priority cookie in a headline
18044 :item on the first line of a plain list item
18045 :item-bullet on the bullet/number of a plain list item
18046 :checkbox on the checkbox in a plain list item
18047 :table in an org-mode table
18048 :table-special on a special filed in a table
18049 :table-table in a table.el table
18050 :link on a hyperlink
18051 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
18052 :target on a <<target>>
18053 :radio-target on a <<<radio-target>>>
18054 :latex-fragment on a LaTeX fragment
18055 :latex-preview on a LaTeX fragment with overlayed preview image
18057 This function expects the position to be visible because it uses font-lock
18058 faces as a help to recognize the following contexts: :table-special, :link,
18060 (let* ((f (get-text-property (point) 'face))
18061 (faces (if (listp f) f (list f)))
18062 (p (point)) clist o)
18063 ;; First the large context
18065 ((org-on-heading-p t)
18066 (push (list :headline (point-at-bol) (point-at-eol)) clist)
18068 (beginning-of-line 1)
18069 (looking-at org-todo-line-tags-regexp))
18070 (push (org-point-in-group p 1 :headline-stars) clist)
18071 (push (org-point-in-group p 2 :todo-keyword) clist)
18072 (push (org-point-in-group p 4 :tags) clist))
18074 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
18075 (if (looking-at "\\[#[A-Z0-9]\\]")
18076 (push (org-point-in-group p 0 :priority) clist)))
18079 (push (org-point-in-group p 2 :item-bullet) clist)
18080 (push (list :item (point-at-bol)
18081 (save-excursion (org-end-of-item) (point)))
18083 (and (org-at-item-checkbox-p)
18084 (push (org-point-in-group p 0 :checkbox) clist)))
18087 (push (list :table (org-table-begin) (org-table-end)) clist)
18088 (if (memq 'org-formula faces)
18089 (push (list :table-special
18090 (previous-single-property-change p 'face)
18091 (next-single-property-change p 'face)) clist)))
18092 ((org-at-table-p 'any)
18093 (push (list :table-table) clist)))
18096 ;; Now the small context
18098 ((org-at-timestamp-p)
18099 (push (org-point-in-group p 0 :timestamp) clist))
18100 ((memq 'org-link faces)
18102 (previous-single-property-change p 'face)
18103 (next-single-property-change p 'face)) clist))
18104 ((memq 'org-special-keyword faces)
18105 (push (list :keyword
18106 (previous-single-property-change p 'face)
18107 (next-single-property-change p 'face)) clist))
18109 (push (org-point-in-group p 0 :target) clist)
18110 (goto-char (1- (match-beginning 0)))
18111 (if (looking-at org-radio-target-regexp)
18112 (push (org-point-in-group p 0 :radio-target) clist))
18114 ((setq o (car (delq nil
18117 (if (memq x org-latex-fragment-image-overlays) x))
18118 (overlays-at (point))))))
18119 (push (list :latex-fragment
18120 (overlay-start o) (overlay-end o)) clist)
18121 (push (list :latex-preview
18122 (overlay-start o) (overlay-end o)) clist))
18123 ((org-inside-LaTeX-fragment-p)
18124 ;; FIXME: positions wrong.
18125 (push (list :latex-fragment (point) (point)) clist)))
18127 (setq clist (nreverse (delq nil clist)))
18130 ;; FIXME: Compare with at-regexp-p Do we need both?
18131 (defun org-in-regexp (re &optional nlines visually)
18132 "Check if point is inside a match of regexp.
18133 Normally only the current line is checked, but you can include NLINES extra
18134 lines both before and after point into the search.
18135 If VISUALLY is set, require that the cursor is not after the match but
18136 really on, so that the block visually is on the match."
18138 (let ((pos (point))
18139 (eol (point-at-eol (+ 1 (or nlines 0))))
18140 (inc (if visually 1 0)))
18142 (beginning-of-line (- 1 (or nlines 0)))
18143 (while (re-search-forward re eol t)
18144 (if (and (<= (match-beginning 0) pos)
18145 (>= (+ inc (match-end 0)) pos))
18146 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
18148 (defun org-at-regexp-p (regexp)
18149 "Is point inside a match of REGEXP in the current line?"
18152 (let ((pos (point)) (end (point-at-eol)))
18153 (beginning-of-line 1)
18154 (while (re-search-forward regexp end t)
18155 (if (and (<= (match-beginning 0) pos)
18156 (>= (match-end 0) pos))
18160 (defun org-in-regexps-block-p (start-re end-re)
18161 "Returns t if the current point is between matches of START-RE and END-RE.
18162 This will also return to if point is on one of the two matches."
18166 (and (or (org-at-regexp-p start-re)
18167 (re-search-backward start-re nil t))
18168 (re-search-forward end-re nil t)
18171 (defun org-occur-in-agenda-files (regexp &optional nlines)
18172 "Call `multi-occur' with buffers for all agenda files."
18173 (interactive "sOrg-files matching: \np")
18174 (let* ((files (org-agenda-files))
18175 (tnames (mapcar 'file-truename files))
18176 (extra org-agenda-text-search-extra-files)
18178 (when (eq (car extra) 'agenda-archives)
18179 (setq extra (cdr extra))
18180 (setq files (org-add-archive-files files)))
18181 (while (setq f (pop extra))
18182 (unless (member (file-truename f) tnames)
18183 (add-to-list 'files f 'append)
18184 (add-to-list 'tnames (file-truename f) 'append)))
18186 (mapcar (lambda (x)
18187 (with-current-buffer
18188 (or (get-file-buffer x) (find-file-noselect x))
18194 (if (boundp 'occur-mode-find-occurrence-hook)
18196 (add-hook 'occur-mode-find-occurrence-hook
18201 (defadvice occur-mode-goto-occurrence
18202 (after org-occur-reveal activate)
18203 (and (org-mode-p) (org-reveal)))
18204 (defadvice occur-mode-goto-occurrence-other-window
18205 (after org-occur-reveal activate)
18206 (and (org-mode-p) (org-reveal)))
18207 (defadvice occur-mode-display-occurrence
18208 (after org-occur-reveal activate)
18210 (let ((pos (occur-mode-find-occurrence)))
18211 (with-current-buffer (marker-buffer pos)
18216 (defun org-occur-link-in-agenda-files ()
18217 "Create a link and search for it in the agendas.
18218 The link is not stored in `org-stored-links', it is just created
18219 for the search purpose."
18221 (let ((link (condition-case nil
18222 (org-store-link nil)
18223 (error "Unable to create a link to here"))))
18224 (org-occur-in-agenda-files (regexp-quote link))))
18226 (defun org-uniquify (list)
18227 "Remove duplicate elements from LIST."
18229 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
18232 (defun org-delete-all (elts list)
18233 "Remove all elements in ELTS from LIST."
18235 (setq list (delete (pop elts) list)))
18238 (defun org-count (cl-item cl-seq)
18239 "Count the number of occurrences of ITEM in SEQ.
18240 Taken from `count' in cl-seq.el with all keyword arguments removed."
18241 (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0) cl-x)
18242 (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
18243 (while (< cl-start cl-end)
18244 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
18245 (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
18246 (setq cl-start (1+ cl-start)))
18249 (defun org-remove-if (predicate seq)
18250 "Remove everything from SEQ that fulfills PREDICATE."
18254 (if (not (funcall predicate e)) (push e res)))
18257 (defun org-remove-if-not (predicate seq)
18258 "Remove everything from SEQ that does not fulfill PREDICATE."
18262 (if (funcall predicate e) (push e res)))
18265 (defun org-back-over-empty-lines ()
18266 "Move backwards over whitespace, to the beginning of the first empty line.
18267 Returns the number of empty lines passed."
18268 (let ((pos (point)))
18269 (skip-chars-backward " \t\n\r")
18270 (beginning-of-line 2)
18271 (goto-char (min (point) pos))
18272 (count-lines (point) pos)))
18274 (defun org-skip-whitespace ()
18275 (skip-chars-forward " \t\n\r"))
18277 (defun org-point-in-group (point group &optional context)
18278 "Check if POINT is in match-group GROUP.
18279 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
18280 match. If the match group does ot exist or point is not inside it,
18282 (and (match-beginning group)
18283 (>= point (match-beginning group))
18284 (<= point (match-end group))
18286 (list context (match-beginning group) (match-end group))
18289 (defun org-switch-to-buffer-other-window (&rest args)
18290 "Switch to buffer in a second window on the current frame.
18291 In particular, do not allow pop-up frames.
18292 Returns the newly created buffer."
18293 (let (pop-up-frames special-display-buffer-names special-display-regexps
18294 special-display-function)
18295 (apply 'switch-to-buffer-other-window args)))
18297 (defun org-combine-plists (&rest plists)
18298 "Create a single property list from all plists in PLISTS.
18299 The process starts by copying the first list, and then setting properties
18300 from the other lists. Settings in the last list are the most significant
18301 ones and overrule settings in the other lists."
18302 (let ((rtn (copy-sequence (pop plists)))
18305 (setq ls (pop plists))
18307 (setq p (pop ls) v (pop ls))
18308 (setq rtn (plist-put rtn p v))))
18311 (defun org-move-line-down (arg)
18312 "Move the current line down. With prefix argument, move it past ARG lines."
18314 (let ((col (current-column))
18316 (beginning-of-line 1) (setq beg (point))
18317 (beginning-of-line 2) (setq end (point))
18318 (beginning-of-line (+ 1 arg))
18319 (setq pos (move-marker (make-marker) (point)))
18320 (insert (delete-and-extract-region beg end))
18322 (org-move-to-column col)))
18324 (defun org-move-line-up (arg)
18325 "Move the current line up. With prefix argument, move it past ARG lines."
18327 (let ((col (current-column))
18329 (beginning-of-line 1) (setq beg (point))
18330 (beginning-of-line 2) (setq end (point))
18331 (beginning-of-line (- arg))
18332 (setq pos (move-marker (make-marker) (point)))
18333 (insert (delete-and-extract-region beg end))
18335 (org-move-to-column col)))
18337 (defun org-replace-escapes (string table)
18338 "Replace %-escapes in STRING with values in TABLE.
18339 TABLE is an association list with keys like \"%a\" and string values.
18340 The sequences in STRING may contain normal field width and padding information,
18341 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
18342 so values can contain further %-escapes if they are define later in TABLE."
18343 (let ((tbl (copy-alist table))
18344 (case-fold-search nil)
18347 (while (setq e (pop tbl))
18348 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
18349 (when (and (cdr e) (string-match re (cdr e)))
18350 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
18352 (add-text-properties 0 3 (list 'sref sref) safe)
18353 (setcdr e (replace-match safe t t (cdr e)))))
18354 (while (string-match re string)
18355 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
18357 (setq string (replace-match rpl t t string))))
18358 (while (setq pchg (next-property-change pchg string))
18359 (let ((sref (get-text-property pchg 'sref string)))
18360 (when (and sref (string-match "SREF" string pchg))
18361 (setq string (replace-match sref t t string)))))
18364 (defun org-sublist (list start end)
18365 "Return a section of LIST, from START to END.
18366 Counting starts at 1."
18367 (let (rtn (c start))
18368 (setq list (nthcdr (1- start) list))
18369 (while (and list (<= c end))
18370 (push (pop list) rtn)
18374 (defun org-find-base-buffer-visiting (file)
18375 "Like `find-buffer-visiting' but always return the base buffer and
18376 not an indirect buffer."
18377 (let ((buf (or (get-file-buffer file)
18378 (find-buffer-visiting file))))
18380 (or (buffer-base-buffer buf) buf)
18383 (defun org-image-file-name-regexp (&optional extensions)
18384 "Return regexp matching the file names of images.
18385 If EXTENSIONS is given, only match these."
18386 (if (and (not extensions) (fboundp 'image-file-name-regexp))
18387 (image-file-name-regexp)
18388 (let ((image-file-name-extensions
18390 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
18391 "xbm" "xpm" "pbm" "pgm" "ppm"))))
18393 (regexp-opt (nconc (mapcar 'upcase
18394 image-file-name-extensions)
18395 image-file-name-extensions)
18399 (defun org-file-image-p (file &optional extensions)
18400 "Return non-nil if FILE is an image."
18402 (string-match (org-image-file-name-regexp extensions) file)))
18404 (defun org-get-cursor-date ()
18405 "Return the date at cursor in as a time.
18406 This works in the calendar and in the agenda, anywhere else it just
18407 returns the current time."
18408 (let (date day defd)
18410 ((eq major-mode 'calendar-mode)
18411 (setq date (calendar-cursor-to-date)
18412 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
18413 ((eq major-mode 'org-agenda-mode)
18414 (setq day (get-text-property (point) 'day))
18416 (setq date (calendar-gregorian-from-absolute day)
18417 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
18419 (or defd (current-time))))
18421 (defvar org-agenda-action-marker (make-marker)
18422 "Marker pointing to the entry for the next agenda action.")
18424 (defun org-mark-entry-for-agenda-action ()
18425 "Mark the current entry as target of an agenda action.
18426 Agenda actions are actions executed from the agenda with the key `k',
18427 which make use of the date at the cursor."
18429 (move-marker org-agenda-action-marker
18430 (save-excursion (org-back-to-heading t) (point))
18433 "Entry marked for action; press `k' at desired date in agenda or calendar"))
18435 ;;; Paragraph filling stuff.
18436 ;; We want this to be just right, so use the full arsenal.
18438 (defun org-indent-line-function ()
18439 "Indent line like previous, but further if previous was headline or item."
18441 (let* ((pos (point))
18442 (itemp (org-at-item-p))
18443 (case-fold-search t)
18444 (org-drawer-regexp (or org-drawer-regexp "\000"))
18445 column bpos bcol tpos tcol bullet btype bullet-type)
18446 ;; Find the previous relevant line
18447 (beginning-of-line 1)
18449 ((looking-at "#") (setq column 0))
18450 ((looking-at "\\*+ ") (setq column 0))
18451 ((and (looking-at "[ \t]*:END:")
18452 (save-excursion (re-search-backward org-drawer-regexp nil t)))
18454 (goto-char (1- (match-beginning 1)))
18455 (setq column (current-column))))
18456 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
18458 (re-search-backward
18459 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
18460 (setq column (org-get-indentation (match-string 0))))
18462 (beginning-of-line 0)
18463 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
18464 (not (looking-at "[ \t]*:END:"))
18465 (not (looking-at org-drawer-regexp)))
18466 (beginning-of-line 0))
18468 ((looking-at "\\*+[ \t]+")
18469 (if (not org-adapt-indentation)
18471 (goto-char (match-end 0))
18472 (setq column (current-column))))
18473 ((looking-at org-drawer-regexp)
18474 (goto-char (1- (match-beginning 1)))
18475 (setq column (current-column)))
18476 ((looking-at "\\([ \t]*\\):END:")
18477 (goto-char (match-end 1))
18478 (setq column (current-column)))
18480 (org-beginning-of-item)
18481 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
18482 (setq bpos (match-beginning 1) tpos (match-end 0)
18483 bcol (progn (goto-char bpos) (current-column))
18484 tcol (progn (goto-char tpos) (current-column))
18485 bullet (match-string 1)
18486 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
18487 (if (> tcol (+ bcol org-description-max-indent))
18488 (setq tcol (+ bcol 5)))
18492 (beginning-of-line 1)
18493 (if (looking-at "\\S-")
18495 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
18496 (setq bullet (match-string 1)
18497 btype (if (string-match "[0-9]" bullet) "n" bullet))
18498 (setq column (if (equal btype bullet-type) bcol tcol)))
18499 (setq column (org-get-indentation)))))
18500 (t (setq column (org-get-indentation))))))
18502 (if (<= (current-column) (current-indentation))
18503 (org-indent-line-to column)
18504 (save-excursion (org-indent-line-to column)))
18505 (setq column (current-column))
18506 (beginning-of-line 1)
18508 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
18509 (replace-match (concat (match-string 1)
18510 (format org-property-format
18511 (match-string 2) (match-string 3)))
18513 (org-move-to-column column)))
18515 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
18516 "Variable to store copy of `adaptive-fill-regexp'.
18517 Since `adaptive-fill-regexp' is set to never match, we need to
18518 store a backup of its value before entering `org-mode' so that
18519 the functionality can be provided as a fall-back.")
18521 (defun org-set-autofill-regexps ()
18523 ;; In the paragraph separator we include headlines, because filling
18524 ;; text in a line directly attached to a headline would otherwise
18525 ;; fill the headline as well.
18526 (org-set-local 'comment-start-skip "^#+[ \t]*")
18527 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
18528 ;; The paragraph starter includes hand-formatted lists.
18536 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
18539 "\\\\\\(begin\\|end\\|[][]\\)"))
18540 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
18541 ;; But only if the user has not turned off tables or fixed-width regions
18543 'auto-fill-inhibit-regexp
18544 (concat "\\*+ \\|#\\+"
18545 "\\|[ \t]*" org-keyword-time-regexp
18546 (if (or org-enable-table-editor org-enable-fixed-width-editor)
18549 (if org-enable-table-editor "|" "")
18550 (if org-enable-fixed-width-editor ":" "")
18552 ;; We use our own fill-paragraph function, to make sure that tables
18553 ;; and fixed-width regions are not wrapped. That function will pass
18554 ;; through to `fill-paragraph' when appropriate.
18555 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
18556 ;; Adaptive filling: To get full control, first make sure that
18557 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
18558 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
18559 (org-set-local 'org-adaptive-fill-regexp-backup
18560 adaptive-fill-regexp))
18561 (org-set-local 'adaptive-fill-regexp "\000")
18562 (org-set-local 'adaptive-fill-function
18563 'org-adaptive-fill-function)
18565 'align-mode-rules-list
18566 '((org-in-buffer-settings
18567 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
18568 (modes . '(org-mode))))))
18570 (defun org-fill-paragraph (&optional justify)
18571 "Re-align a table, pass through to fill-paragraph if no table."
18572 (let ((table-p (org-at-table-p))
18573 (table.el-p (org-at-table.el-p)))
18574 (cond ((and (equal (char-after (point-at-bol)) ?*)
18575 (save-excursion (goto-char (point-at-bol))
18576 (looking-at outline-regexp)))
18577 t) ; skip headlines
18578 (table.el-p t) ; skip table.el tables
18579 (table-p (org-table-align) t) ; align org-mode tables
18580 (t nil)))) ; call paragraph-fill
18582 ;; For reference, this is the default value of adaptive-fill-regexp
18583 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
18585 (defun org-adaptive-fill-function ()
18586 "Return a fill prefix for org-mode files.
18587 In particular, this makes sure hanging paragraphs for hand-formatted lists
18591 ((looking-at "#[ \t]+")
18592 (match-string-no-properties 0))
18593 ;; Description list
18594 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
18596 (if (> (match-end 1) (+ (match-beginning 1)
18597 org-description-max-indent))
18598 (goto-char (+ (match-beginning 1) 5))
18599 (goto-char (match-end 0)))
18600 (make-string (current-column) ?\ )))
18601 ;; Ordered or unordered list
18602 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
18604 (goto-char (match-end 0))
18605 (make-string (current-column) ?\ )))
18607 ((looking-at org-adaptive-fill-regexp-backup)
18608 (match-string-no-properties 0))))
18612 (defun org-toggle-fixed-width-section (arg)
18613 "Toggle the fixed-width export.
18614 If there is no active region, the QUOTE keyword at the current headline is
18615 inserted or removed. When present, it causes the text between this headline
18616 and the next to be exported as fixed-width text, and unmodified.
18617 If there is an active region, this command adds or removes a colon as the
18618 first character of this line. If the first character of a line is a colon,
18619 this line is also exported in fixed-width font."
18622 (regionp (org-region-active-p))
18623 (beg (if regionp (region-beginning) (point)))
18624 (end (if regionp (region-end)))
18625 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
18626 (case-fold-search nil)
18627 (re "[ \t]*\\(: \\)")
18632 (setq cc (current-column))
18633 (beginning-of-line 1)
18634 (setq off (looking-at re))
18635 (while (> nlines 0)
18636 (setq nlines (1- nlines))
18637 (beginning-of-line 1)
18640 (org-move-to-column cc t)
18643 ((and off (looking-at re))
18644 (replace-match "" t t nil 1))
18645 ((not off) (org-move-to-column cc t) (insert ": ")))
18648 (org-back-to-heading)
18649 (if (looking-at (concat outline-regexp
18650 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
18651 (replace-match "" t t nil 1)
18652 (if (looking-at outline-regexp)
18654 (goto-char (match-end 0))
18655 (insert org-quote-string " "))))))))
18657 (defun org-reftex-citation ()
18658 "Use reftex-citation to insert a citation into the buffer.
18659 This looks for a line like
18661 #+BIBLIOGRAPHY: foo plain option:-d
18663 and derives from it that foo.bib is the bibliography file relevant
18664 for this document. It then installs the necessary environment for RefTeX
18665 to work in this buffer and calls `reftex-citation' to insert a citation
18668 Export of such citations to both LaTeX and HTML is handled by the contributed
18669 package org-exp-bibtex by Taru Karttunen."
18671 (let ((reftex-docstruct-symbol 'rds)
18672 (reftex-cite-format "\\cite{%l}")
18677 (let ((case-fold-search t)
18678 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
18679 (if (not (save-excursion
18680 (or (re-search-forward re nil t)
18681 (re-search-backward re nil t))))
18682 (error "No bibliography defined in file")
18683 (setq bib (concat (match-string 1) ".bib")
18684 rds (list (list 'bib bib)))))))
18685 (call-interactively 'reftex-citation)))
18687 ;;;; Functions extending outline functionality
18689 (defun org-beginning-of-line (&optional arg)
18690 "Go to the beginning of the current line. If that is invisible, continue
18691 to a visible line beginning. This makes the function of C-a more intuitive.
18692 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18693 first attempt, and only move to after the tags when the cursor is already
18694 beyond the end of the headline."
18696 (let ((pos (point))
18697 (special (if (consp org-special-ctrl-a/e)
18698 (car org-special-ctrl-a/e)
18699 org-special-ctrl-a/e))
18701 (if (org-bound-and-true-p line-move-visual)
18702 (beginning-of-visual-line 1)
18703 (beginning-of-line 1))
18704 (if (and arg (fboundp 'move-beginning-of-line))
18705 (call-interactively 'move-beginning-of-line)
18709 (if (org-truely-invisible-p)
18710 (while (and (not (bobp)) (org-truely-invisible-p))
18712 (beginning-of-line 1))
18713 (forward-char 1))))
18716 ((and (looking-at org-complex-heading-regexp)
18717 (= (char-after (match-end 1)) ?\ ))
18718 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
18722 (cond ((> pos refpos) refpos)
18723 ((= pos (point)) refpos)
18725 (cond ((> pos (point)) (point))
18726 ((not (eq last-command this-command)) (point))
18731 (cond ((> pos (match-end 4)) (match-end 4))
18732 ((= pos (point)) (match-end 4))
18734 (cond ((> pos (point)) (point))
18735 ((not (eq last-command this-command)) (point))
18736 (t (match-end 4))))))))
18738 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18740 (defun org-end-of-line (&optional arg)
18741 "Go to the end of the line.
18742 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18743 first attempt, and only move to after the tags when the cursor is already
18744 beyond the end of the headline."
18746 (let ((special (if (consp org-special-ctrl-a/e)
18747 (cdr org-special-ctrl-a/e)
18748 org-special-ctrl-a/e)))
18749 (if (or (not special)
18750 (not (org-on-heading-p))
18752 (call-interactively
18753 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
18754 ((fboundp 'move-end-of-line) 'move-end-of-line)
18756 (let ((pos (point)))
18757 (beginning-of-line 1)
18758 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
18760 (if (or (< pos (match-beginning 1))
18761 (= pos (match-end 0)))
18762 (goto-char (match-beginning 1))
18763 (goto-char (match-end 0)))
18764 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
18765 (goto-char (match-end 0))
18766 (goto-char (match-beginning 1))))
18767 (call-interactively (if (fboundp 'move-end-of-line)
18771 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18773 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
18774 (define-key org-mode-map "\C-e" 'org-end-of-line)
18775 (define-key org-mode-map [home] 'org-beginning-of-line)
18776 (define-key org-mode-map [end] 'org-end-of-line)
18778 (defun org-backward-sentence (&optional arg)
18779 "Go to beginning of sentence, or beginning of table field.
18780 This will call `backward-sentence' or `org-table-beginning-of-field',
18781 depending on context."
18784 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
18785 (t (call-interactively 'backward-sentence))))
18787 (defun org-forward-sentence (&optional arg)
18788 "Go to end of sentence, or end of table field.
18789 This will call `forward-sentence' or `org-table-end-of-field',
18790 depending on context."
18793 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
18794 (t (call-interactively 'forward-sentence))))
18796 (define-key org-mode-map "\M-a" 'org-backward-sentence)
18797 (define-key org-mode-map "\M-e" 'org-forward-sentence)
18799 (defun org-kill-line (&optional arg)
18800 "Kill line, to tags or end of line."
18803 ((or (not org-special-ctrl-k)
18805 (not (org-on-heading-p)))
18806 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
18807 org-ctrl-k-protect-subtree)
18808 (if (or (eq org-ctrl-k-protect-subtree 'error)
18809 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
18810 (error "C-k aborted - would kill hidden subtree")))
18811 (call-interactively 'kill-line))
18812 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
18813 (kill-region (point) (match-beginning 1))
18814 (org-set-tags nil t))
18815 (t (kill-region (point) (point-at-eol)))))
18817 (define-key org-mode-map "\C-k" 'org-kill-line)
18819 (defun org-yank (&optional arg)
18820 "Yank. If the kill is a subtree, treat it specially.
18821 This command will look at the current kill and check if is a single
18822 subtree, or a series of subtrees[1]. If it passes the test, and if the
18823 cursor is at the beginning of a line or after the stars of a currently
18824 empty headline, then the yank is handled specially. How exactly depends
18825 on the value of the following variables, both set by default.
18827 org-yank-folded-subtrees
18828 When set, the subtree(s) will be folded after insertion, but only
18829 if doing so would now swallow text after the yanked text.
18831 org-yank-adjusted-subtrees
18832 When set, the subtree will be promoted or demoted in order to
18833 fit into the local outline tree structure, which means that the level
18834 will be adjusted so that it becomes the smaller one of the two
18835 *visible* surrounding headings.
18837 Any prefix to this command will cause `yank' to be called directly with
18838 no special treatment. In particular, a simple `C-u' prefix will just
18839 plainly yank the text as it is.
18841 \[1] The test checks if the first non-white line is a heading
18842 and if there are no other headings with fewer stars."
18844 (org-yank-generic 'yank arg))
18846 (defun org-yank-generic (command arg)
18847 "Perform some yank-like command.
18849 This function implements the behavior described in the `org-yank'
18850 documentation. However, it has been generalized to work for any
18851 interactive command with similar behavior."
18853 ;; pretend to be command COMMAND
18854 (setq this-command command)
18857 (call-interactively command)
18859 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18860 (and (org-kill-is-subtree-p)
18862 (and (looking-at "[ \t]*$")
18865 (buffer-substring (point-at-bol) (point)))))))
18868 ((and subtreep org-yank-folded-subtrees)
18869 (let ((beg (point))
18871 (if (and subtreep org-yank-adjusted-subtrees)
18872 (org-paste-subtree nil nil 'for-yank)
18873 (call-interactively command))
18877 (when (and (bolp) subtreep
18878 (not (setq swallowp
18879 (org-yank-folding-would-swallow-text beg end))))
18880 (or (looking-at outline-regexp)
18881 (re-search-forward (concat "^" outline-regexp) end t))
18882 (while (and (< (point) end) (looking-at outline-regexp))
18884 (org-cycle-show-empty-lines 'folded)
18885 (condition-case nil
18886 (outline-forward-same-level 1)
18887 (error (goto-char end)))))
18890 "Inserted text not folded because that would swallow text"))
18893 (skip-chars-forward " \t\n\r")
18894 (beginning-of-line 1)
18895 (push-mark beg 'nomsg)))
18896 ((and subtreep org-yank-adjusted-subtrees)
18897 (let ((beg (point-at-bol)))
18898 (org-paste-subtree nil nil 'for-yank)
18899 (push-mark beg 'nomsg)))
18901 (call-interactively command))))))
18903 (defun org-yank-folding-would-swallow-text (beg end)
18904 "Would hide-subtree at BEG swallow any text after END?"
18908 (when (or (looking-at outline-regexp)
18909 (re-search-forward (concat "^" outline-regexp) end t))
18910 (setq level (org-outline-level)))
18912 (skip-chars-forward " \t\r\n\v\f")
18914 (and (bolp) (looking-at org-outline-regexp)
18915 (<= (org-outline-level) level)))
18916 nil ; Nothing would be swallowed
18917 t)))) ; something would swallow
18919 (define-key org-mode-map "\C-y" 'org-yank)
18921 (defun org-invisible-p ()
18922 "Check if point is at a character currently not visible."
18923 ;; Early versions of noutline don't have `outline-invisible-p'.
18924 (if (fboundp 'outline-invisible-p)
18925 (outline-invisible-p)
18926 (get-char-property (point) 'invisible)))
18928 (defun org-truely-invisible-p ()
18929 "Check if point is at a character currently not visible.
18930 This version does not only check the character property, but also
18932 ;; Early versions of noutline don't have `outline-invisible-p'.
18933 (if (org-bound-and-true-p visible-mode)
18935 (if (fboundp 'outline-invisible-p)
18936 (outline-invisible-p)
18937 (get-char-property (point) 'invisible))))
18939 (defun org-invisible-p2 ()
18940 "Check if point is at a character currently not visible."
18942 (if (and (eolp) (not (bobp))) (backward-char 1))
18943 ;; Early versions of noutline don't have `outline-invisible-p'.
18944 (if (fboundp 'outline-invisible-p)
18945 (outline-invisible-p)
18946 (get-char-property (point) 'invisible))))
18948 (defun org-back-to-heading (&optional invisible-ok)
18949 "Call `outline-back-to-heading', but provide a better error message."
18950 (condition-case nil
18951 (outline-back-to-heading invisible-ok)
18952 (error (error "Before first headline at position %d in buffer %s"
18953 (point) (current-buffer)))))
18955 (defun org-beginning-of-defun ()
18956 "Go to the beginning of the subtree, i.e. back to the heading."
18957 (org-back-to-heading))
18958 (defun org-end-of-defun ()
18959 "Go to the end of the subtree."
18960 (org-end-of-subtree nil t))
18962 (defun org-before-first-heading-p ()
18963 "Before first heading?"
18965 (null (re-search-backward "^\\*+ " nil t))))
18967 (defun org-on-heading-p (&optional ignored)
18968 (outline-on-heading-p t))
18969 (defun org-at-heading-p (&optional ignored)
18970 (outline-on-heading-p t))
18972 (defun org-point-at-end-of-empty-headline ()
18973 "If point is at the end of an empty headline, return t, else nil.
18974 If the heading only contains a TODO keyword, it is still still considered
18976 (and (looking-at "[ \t]*$")
18978 (beginning-of-line 1)
18979 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18981 (defun org-at-heading-or-item-p ()
18982 (or (org-on-heading-p) (org-at-item-p)))
18984 (defun org-on-target-p ()
18985 (or (org-in-regexp org-radio-target-regexp)
18986 (org-in-regexp org-target-regexp)))
18988 (defun org-up-heading-all (arg)
18989 "Move to the heading line of which the present line is a subheading.
18990 This function considers both visible and invisible heading lines.
18991 With argument, move up ARG levels."
18992 (if (fboundp 'outline-up-heading-all)
18993 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18994 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18996 (defun org-up-heading-safe ()
18997 "Move to the heading line of which the present line is a subheading.
18998 This version will not throw an error. It will return the level of the
18999 headline found, or nil if no higher level is found.
19001 Also, this function will be a lot faster than `outline-up-heading',
19002 because it relies on stars being the outline starters. This can really
19003 make a significant difference in outlines with very many siblings."
19004 (let (start-level re)
19005 (org-back-to-heading t)
19006 (setq start-level (funcall outline-level))
19007 (if (equal start-level 1)
19009 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
19010 (if (re-search-backward re nil t)
19011 (funcall outline-level)))))
19013 (defun org-first-sibling-p ()
19014 "Is this heading the first child of its parents?"
19016 (let ((re (concat "^" outline-regexp))
19018 (unless (org-at-heading-p t)
19019 (error "Not at a heading"))
19020 (setq level (funcall outline-level))
19022 (if (not (re-search-backward re nil t))
19024 (setq l (funcall outline-level))
19027 (defun org-goto-sibling (&optional previous)
19028 "Goto the next sibling, even if it is invisible.
19029 When PREVIOUS is set, go to the previous sibling instead. Returns t
19030 when a sibling was found. When none is found, return nil and don't
19032 (let ((fun (if previous 're-search-backward 're-search-forward))
19034 (re (concat "^" outline-regexp))
19036 (when (condition-case nil (org-back-to-heading t) (error nil))
19037 (setq level (funcall outline-level))
19039 (or previous (forward-char 1))
19040 (while (funcall fun re nil t)
19041 (setq l (funcall outline-level))
19042 (when (< l level) (goto-char pos) (throw 'exit nil))
19043 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
19047 (defun org-show-siblings ()
19048 "Show all siblings of the current headline."
19050 (while (org-goto-sibling) (org-flag-heading nil)))
19052 (while (org-goto-sibling 'previous)
19053 (org-flag-heading nil))))
19055 (defun org-show-hidden-entry ()
19056 "Show an entry where even the heading is hidden."
19060 (defun org-flag-heading (flag &optional entry)
19061 "Flag the current heading. FLAG non-nil means make invisible.
19062 When ENTRY is non-nil, show the entire entry."
19064 (org-back-to-heading t)
19065 ;; Check if we should show the entire entry
19070 (and (outline-next-heading)
19071 (org-flag-heading nil))))
19072 (outline-flag-region (max (point-min) (1- (point)))
19073 (save-excursion (outline-end-of-heading) (point))
19076 (defun org-get-next-sibling ()
19077 "Move to next heading of the same level, and return point.
19078 If there is no such heading, return nil.
19079 This is like outline-next-sibling, but invisible headings are ok."
19080 (let ((level (funcall outline-level)))
19081 (outline-next-heading)
19082 (while (and (not (eobp)) (> (funcall outline-level) level))
19083 (outline-next-heading))
19084 (if (or (eobp) (< (funcall outline-level) level))
19088 (defun org-get-last-sibling ()
19089 "Move to previous heading of the same level, and return point.
19090 If there is no such heading, return nil."
19091 (let ((opoint (point))
19092 (level (funcall outline-level)))
19093 (outline-previous-heading)
19094 (when (and (/= (point) opoint) (outline-on-heading-p t))
19095 (while (and (> (funcall outline-level) level)
19097 (outline-previous-heading))
19098 (if (< (funcall outline-level) level)
19102 (defun org-end-of-subtree (&optional invisible-OK to-heading)
19103 ;; This contains an exact copy of the original function, but it uses
19104 ;; `org-back-to-heading', to make it work also in invisible
19105 ;; trees. And is uses an invisible-OK argument.
19106 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
19107 ;; Furthermore, when used inside Org, finding the end of a large subtree
19108 ;; with many children and grandchildren etc, this can be much faster
19109 ;; than the outline version.
19110 (org-back-to-heading invisible-OK)
19112 (level (funcall outline-level)))
19113 (if (and (org-mode-p) (< level 1000))
19114 ;; A true heading (not a plain list item), in Org-mode
19115 ;; This means we can easily find the end by looking
19116 ;; only for the right number of stars. Using a regexp to do
19117 ;; this is so much faster than using a Lisp loop.
19118 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
19120 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
19121 ;; something else, do it the slow way
19122 (while (and (not (eobp))
19123 (or first (> (funcall outline-level) level)))
19125 (outline-next-heading)))
19127 (if (memq (preceding-char) '(?\n ?\^M))
19129 ;; Go to end of line before heading
19131 (if (memq (preceding-char) '(?\n ?\^M))
19132 ;; leave blank line before heading
19133 (forward-char -1))))))
19136 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
19137 "Use Org version in org-mode, for dramatic speed-up."
19138 (if (eq major-mode 'org-mode)
19140 (org-end-of-subtree nil t)
19141 (unless (eobp) (backward-char 1)))
19144 (defun org-forward-same-level (arg &optional invisible-ok)
19145 "Move forward to the arg'th subheading at same level as this one.
19146 Stop at the first and last subheadings of a superior heading."
19148 (org-back-to-heading invisible-ok)
19150 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19151 (re (format "^\\*\\{1,%d\\} " level))
19155 (while (and (re-search-forward re nil 'move)
19156 (setq l (- (match-end 0) (match-beginning 0) 1))
19159 (progn (backward-char 1) (org-invisible-p)))
19160 (if (< l level) (setq arg 1)))
19161 (setq arg (1- arg)))
19162 (beginning-of-line 1)))
19164 (defun org-backward-same-level (arg &optional invisible-ok)
19165 "Move backward to the arg'th subheading at same level as this one.
19166 Stop at the first and last subheadings of a superior heading."
19168 (org-back-to-heading)
19170 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19171 (re (format "^\\*\\{1,%d\\} " level))
19174 (while (and (re-search-backward re nil 'move)
19175 (setq l (- (match-end 0) (match-beginning 0) 1))
19179 (if (< l level) (setq arg 1)))
19180 (setq arg (1- arg)))))
19182 (defun org-show-subtree ()
19183 "Show everything after this heading at deeper levels."
19184 (outline-flag-region
19187 (org-end-of-subtree t t))
19190 (defun org-show-entry ()
19191 "Show the body directly following this heading.
19192 Show the heading too, if it is currently invisible."
19195 (condition-case nil
19197 (org-back-to-heading t)
19198 (outline-flag-region
19199 (max (point-min) (1- (point)))
19201 (if (re-search-forward
19202 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
19203 (match-beginning 1)
19206 (org-cycle-hide-drawers 'children))
19209 (defun org-make-options-regexp (kwds &optional extra)
19210 "Make a regular expression for keyword lines."
19214 (mapconcat 'regexp-quote kwds "\\|")
19215 (if extra (concat "\\|" extra))
19219 ;; Make isearch reveal the necessary context
19220 (defun org-isearch-end ()
19221 "Reveal context after isearch exits."
19222 (when isearch-success ; only if search was successful
19223 (if (featurep 'xemacs)
19224 ;; Under XEmacs, the hook is run in the correct place,
19225 ;; we directly show the context.
19226 (org-show-context 'isearch)
19227 ;; In Emacs the hook runs *before* restoring the overlays.
19228 ;; So we have to use a one-time post-command-hook to do this.
19229 ;; (Emacs 22 has a special variable, see function `org-mode')
19230 (unless (and (boundp 'isearch-mode-end-hook-quit)
19231 isearch-mode-end-hook-quit)
19232 ;; Only when the isearch was not quitted.
19233 (org-add-hook 'post-command-hook 'org-isearch-post-command
19234 'append 'local)))))
19236 (defun org-isearch-post-command ()
19237 "Remove self from hook, and show context."
19238 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
19239 (org-show-context 'isearch))
19242 ;;;; Integration with and fixes for other packages
19246 (defvar org-imenu-markers nil
19247 "All markers currently used by Imenu.")
19248 (make-variable-buffer-local 'org-imenu-markers)
19250 (defun org-imenu-new-marker (&optional pos)
19251 "Return a new marker for use by Imenu, and remember the marker."
19252 (let ((m (make-marker)))
19253 (move-marker m (or pos (point)))
19254 (push m org-imenu-markers)
19257 (defun org-imenu-get-tree ()
19258 "Produce the index for Imenu."
19259 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
19260 (setq org-imenu-markers nil)
19261 (let* ((n org-imenu-depth)
19262 (re (concat "^" outline-regexp))
19263 (subs (make-vector (1+ n) nil))
19269 (goto-char (point-max))
19270 (while (re-search-backward re nil t)
19271 (setq level (org-reduced-level (funcall outline-level)))
19273 (looking-at org-complex-heading-regexp)
19274 (setq head (org-link-display-format
19275 (org-match-string-no-properties 4))
19276 m (org-imenu-new-marker))
19277 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
19278 (if (>= level last-level)
19279 (push (cons head m) (aref subs level))
19280 (push (cons head (aref subs (1+ level))) (aref subs level))
19281 (loop for i from (1+ level) to n do (aset subs i nil)))
19282 (setq last-level level)))))
19285 (eval-after-load "imenu"
19287 (add-hook 'imenu-after-jump-hook
19289 (if (eq major-mode 'org-mode)
19290 (org-show-context 'org-goto))))))
19292 (defun org-link-display-format (link)
19293 "Replace a link with either the description, or the link target
19294 if no description is present"
19296 (if (string-match org-bracket-link-analytic-regexp link)
19297 (replace-match (if (match-end 5)
19298 (match-string 5 link)
19299 (concat (match-string 1 link)
19300 (match-string 3 link)))
19304 ;; Speedbar support
19306 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
19307 "Overlay marking the agenda restriction line in speedbar.")
19308 (overlay-put org-speedbar-restriction-lock-overlay
19309 'face 'org-agenda-restriction-lock)
19310 (overlay-put org-speedbar-restriction-lock-overlay
19311 'help-echo "Agendas are currently limited to this item.")
19312 (org-detach-overlay org-speedbar-restriction-lock-overlay)
19314 (defun org-speedbar-set-agenda-restriction ()
19315 "Restrict future agenda commands to the location at point in speedbar.
19316 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
19318 (require 'org-agenda)
19319 (let (p m tp np dir txt)
19321 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19323 (setq m (get-text-property p 'org-imenu-marker))
19324 (with-current-buffer (marker-buffer m)
19326 (org-agenda-set-restriction-lock 'subtree)))
19327 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19328 'speedbar-function 'speedbar-find-file))
19329 (setq tp (previous-single-property-change
19330 (1+ p) 'speedbar-function)
19331 np (next-single-property-change
19332 tp 'speedbar-function)
19333 dir (speedbar-line-directory)
19334 txt (buffer-substring-no-properties (or tp (point-min))
19335 (or np (point-max))))
19336 (with-current-buffer (find-file-noselect
19337 (let ((default-directory dir))
19338 (expand-file-name txt)))
19339 (unless (org-mode-p)
19340 (error "Cannot restrict to non-Org-mode file"))
19341 (org-agenda-set-restriction-lock 'file)))
19342 (t (error "Don't know how to restrict Org-mode's agenda")))
19343 (move-overlay org-speedbar-restriction-lock-overlay
19344 (point-at-bol) (point-at-eol))
19345 (setq current-prefix-arg nil)
19346 (org-agenda-maybe-redo)))
19348 (eval-after-load "speedbar"
19350 (speedbar-add-supported-extension ".org")
19351 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
19352 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
19353 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
19354 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
19355 (add-hook 'speedbar-visiting-tag-hook
19356 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
19358 ;;; Fixes and Hacks for problems with other packages
19360 ;; Make flyspell not check words in links, to not mess up our keymap
19361 (defun org-mode-flyspell-verify ()
19362 "Don't let flyspell put overlays at active buttons."
19363 (and (not (get-text-property (point) 'keymap))
19364 (not (get-text-property (point) 'org-no-flyspell))))
19366 (defun org-remove-flyspell-overlays-in (beg end)
19367 "Remove flyspell overlays in region."
19368 (and (org-bound-and-true-p flyspell-mode)
19369 (fboundp 'flyspell-delete-region-overlays)
19370 (flyspell-delete-region-overlays beg end))
19371 (add-text-properties beg end '(org-no-flyspell t)))
19373 ;; Make `bookmark-jump' shows the jump location if it was hidden.
19374 (eval-after-load "bookmark"
19375 '(if (boundp 'bookmark-after-jump-hook)
19376 ;; We can use the hook
19377 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
19378 ;; Hook not available, use advice
19379 (defadvice bookmark-jump (after org-make-visible activate)
19380 "Make the position visible."
19381 (org-bookmark-jump-unhide))))
19383 ;; Make sure saveplace shows the location if it was hidden
19384 (eval-after-load "saveplace"
19385 '(defadvice save-place-find-file-hook (after org-make-visible activate)
19386 "Make the position visible."
19387 (org-bookmark-jump-unhide)))
19389 ;; Make sure ecb shows the location if it was hidden
19390 (eval-after-load "ecb"
19391 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
19392 "Make hierarchy visible when jumping into location from ECB tree buffer."
19393 (if (eq major-mode 'org-mode)
19394 (org-show-context))))
19396 (defun org-bookmark-jump-unhide ()
19397 "Unhide the current position, to show the bookmark location."
19399 (or (org-invisible-p)
19400 (save-excursion (goto-char (max (point-min) (1- (point))))
19401 (org-invisible-p)))
19402 (org-show-context 'bookmark-jump)))
19404 ;; Make session.el ignore our circular variable
19405 (eval-after-load "session"
19406 '(add-to-list 'session-globals-exclude 'org-mark-ring))
19408 ;;;; Experimental code
19410 (defun org-closed-in-range ()
19411 "Sparse tree of items closed in a certain time range.
19412 Still experimental, may disappear in the future."
19414 ;; Get the time interval from the user.
19415 (let* ((time1 (org-float-time
19416 (org-read-date nil 'to-time nil "Starting date: ")))
19417 (time2 (org-float-time
19418 (org-read-date nil 'to-time nil "End date:")))
19419 ;; callback function
19420 (callback (lambda ()
19423 (apply 'encode-time
19424 (org-parse-time-string
19425 (match-string 1))))))
19426 ;; check if time in interval
19427 (and (>= time time1) (<= time time2))))))
19428 ;; make tree, check each match with the callback
19429 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
19435 (run-hooks 'org-load-hook)
19437 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
19439 ;;; org.el ends here