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.
137 This list can be used to load support for any of the languages
138 below, note that each language will depend on a different set of
139 system executables and/or Emacs modes. When a language is
140 \"loaded\", then code blocks in that language can be evaluated
141 with `org-babel-execute-src-block' bound by default to C-c
142 C-c (note the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can
143 be set to remove code block evaluation from the C-c C-c
144 keybinding. By default only Emacs Lisp (which has no
145 requirements) is loaded."
147 :set
'org-babel-do-load-languages
148 :type
'(alist :tag
"Babel Languages"
153 (const :tag
"Asymptote" asymptote
)
154 (const :tag
"Clojure" clojure
)
155 (const :tag
"CSS" css
)
156 (const :tag
"Ditaa" ditaa
)
157 (const :tag
"Dot" dot
)
158 (const :tag
"Emacs Lisp" emacs-lisp
)
159 (const :tag
"Gnuplot" gnuplot
)
160 (const :tag
"Haskell" haskell
)
161 (const :tag
"Latex" latex
)
162 (const :tag
"Matlab" matlab
)
163 (const :tag
"Mscgen" mscgen
)
164 (const :tag
"Ocaml" ocaml
)
165 (const :tag
"Octave" octave
)
166 (const :tag
"Perl" perl
)
167 (const :tag
"Python" python
)
168 (const :tag
"Ruby" ruby
)
169 (const :tag
"Sass" sass
)
170 (const :tag
"Screen" screen
)
171 (const :tag
"Shell Script" sh
)
172 (const :tag
"Sql" sql
)
173 (const :tag
"Sqlite" sqlite
))
174 :value-type
(boolean :tag
"Activate" :value t
)))
176 ;;;; Customization variables
177 (defcustom org-clone-delete-id nil
178 "Remove ID property of clones of a subtree.
179 When non-nil, clones of a subtree don't inherit the ID property.
180 Otherwise they inherit the ID property with a new unique
187 (defconst org-version
"7.01"
188 "The version number of the file org.el.")
190 (defun org-version (&optional here
)
191 "Show the org-mode version in the echo area.
192 With prefix arg HERE, insert it at point."
194 (let* ((origin default-directory
)
195 (version org-version
)
197 (dir (concat (file-name-directory (locate-library "org")) "../" )))
198 (when (and (file-exists-p (expand-file-name ".git" dir
))
199 (executable-find "git"))
203 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
204 (with-current-buffer "*Shell Command Output*"
205 (goto-char (point-min))
206 (setq git-version
(buffer-substring (point) (point-at-eol))))
207 (subst-char-in-string ?- ?. git-version t
)
208 (when (string-match "\\S-"
209 (shell-command-to-string
210 "git diff-index --name-only HEAD --"))
211 (setq git-version
(concat git-version
".dirty")))
212 (setq version
(concat version
" (" git-version
")"))))
214 (setq version
(format "Org-mode version %s" version
))
215 (if here
(insert version
))
218 ;;; Compatibility constants
220 ;;; The custom variables
223 "Outline-based notes management and organizer."
228 (defcustom org-mode-hook nil
229 "Mode hook for Org-mode, run after the mode was turned on."
233 (defcustom org-load-hook nil
234 "Hook that is run after org.el has been loaded."
238 (defvar org-modules
) ; defined below
239 (defvar org-modules-loaded nil
240 "Have the modules been loaded already?")
242 (defun org-load-modules-maybe (&optional force
)
243 "Load all extensions listed in `org-modules'."
244 (when (or force
(not org-modules-loaded
))
246 (condition-case nil
(require ext
)
247 (error (message "Problems while trying to load feature `%s'" ext
))))
249 (setq org-modules-loaded t
)))
251 (defun org-set-modules (var value
)
252 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
254 (when (featurep 'org
)
255 (org-load-modules-maybe 'force
)))
257 (when (org-bound-and-true-p org-modules
)
258 (let ((a (member 'org-infojs org-modules
)))
259 (and a
(setcar a
'org-jsinfo
))))
261 (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
)
262 "Modules that should always be loaded together with org.el.
263 If a description starts with <C>, the file is not part of Emacs
264 and loading it will require that you have downloaded and properly installed
265 the org-mode distribution.
267 You can also use this system to load external packages (i.e. neither Org
268 core modules, nor modules from the CONTRIB directory). Just add symbols
269 to the end of the list. If the package is called org-xyz.el, then you need
270 to add the symbol `xyz', and the package must have a call to
274 :set
'org-set-modules
277 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
278 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
279 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
280 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
281 (const :tag
" docview: Links to doc-view buffers" org-docview
)
282 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
283 (const :tag
" id: Global IDs for identifying entries" org-id
)
284 (const :tag
" info: Links to Info nodes" org-info
)
285 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
286 (const :tag
" habit: Track your consistency with habits" org-habit
)
287 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
288 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
289 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
290 (const :tag
" mew Links to Mew folders/messages" org-mew
)
291 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
292 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
293 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
294 (const :tag
" vm: Links to VM folders/messages" org-vm
)
295 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
296 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
297 (const :tag
" mouse: Additional mouse support" org-mouse
)
299 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
300 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
301 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
302 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
303 (const :tag
"C collector: Collect properties into tables" org-collector
)
304 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
305 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
306 (const :tag
"C eval: Include command output as text" org-eval
)
307 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
308 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
309 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
310 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
311 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
313 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
315 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
316 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
317 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
318 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
319 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
320 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
321 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
322 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
323 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
324 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
325 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
326 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
327 (const :tag
"C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
328 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
329 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
330 (const :tag
"C track: Keep up with Org-mode development" org-track
)
331 (const :tag
"C TaskJuggler: Export tasks to a TaskJuggler project" org-taskjuggler
)
332 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
334 (defcustom org-support-shift-select nil
335 "Non-nil means make shift-cursor commands select text when possible.
337 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
338 selecting a region, or enlarge regions started in this way.
339 In Org-mode, in special contexts, these same keys are used for other
340 purposes, important enough to compete with shift selection. Org tries
341 to balance these needs by supporting `shift-select-mode' outside these
342 special contexts, under control of this variable.
344 The default of this variable is nil, to avoid confusing behavior. Shifted
345 cursor keys will then execute Org commands in the following contexts:
346 - on a headline, changing TODO state (left/right) and priority (up/down)
347 - on a time stamp, changing the time
348 - in a plain list item, changing the bullet type
349 - in a property definition line, switching between allowed values
350 - in the BEGIN line of a clock table (changing the time block).
351 Outside these contexts, the commands will throw an error.
353 When this variable is t and the cursor is not in a special context,
354 Org-mode will support shift-selection for making and enlarging regions.
355 To make this more effective, the bullet cycling will no longer happen
356 anywhere in an item line, but only if the cursor is exactly on the bullet.
358 If you set this variable to the symbol `always', then the keys
359 will not be special in headlines, property lines, and item lines, to make
360 shift selection work there as well. If this is what you want, you can
361 use the following alternative commands: `C-c C-t' and `C-c ,' to
362 change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
363 TODO sets, `C-c -' to cycle item bullet types, and properties can be
364 edited by hand or in column view.
366 However, when the cursor is on a timestamp, shift-cursor commands
367 will still edit the time stamp - this is just too good to give up.
369 XEmacs user should have this variable set to nil, because shift-select-mode
373 (const :tag
"Never" nil
)
374 (const :tag
"When outside special context" t
)
375 (const :tag
"Everywhere except timestamps" always
)))
377 (defgroup org-startup nil
378 "Options concerning startup of Org-mode."
382 (defcustom org-startup-folded t
383 "Non-nil means entering Org-mode will switch to OVERVIEW.
384 This can also be configured on a per-file basis by adding one of
385 the following lines anywhere in the buffer:
387 #+STARTUP: fold (or `overview', this is equivalent)
388 #+STARTUP: nofold (or `showall', this is equivalent)
390 #+STARTUP: showeverything"
393 (const :tag
"nofold: show all" nil
)
394 (const :tag
"fold: overview" t
)
395 (const :tag
"content: all headlines" content
)
396 (const :tag
"show everything, even drawers" showeverything
)))
398 (defcustom org-startup-truncated t
399 "Non-nil means entering Org-mode will set `truncate-lines'.
400 This is useful since some lines containing links can be very long and
401 uninteresting. Also tables look terrible when wrapped."
405 (defcustom org-startup-indented nil
406 "Non-nil means turn on `org-indent-mode' on startup.
407 This can also be configured on a per-file basis by adding one of
408 the following lines anywhere in the buffer:
412 :group
'org-structure
414 (const :tag
"Not" nil
)
415 (const :tag
"Globally (slow on startup in large files)" t
)))
417 (defcustom org-use-sub-superscripts t
418 "Non-nil means interpret \"_\" and \"^\" for export.
419 When this option is turned on, you can use TeX-like syntax for sub- and
420 superscripts. Several characters after \"_\" or \"^\" will be
421 considered as a single item - so grouping with {} is normally not
422 needed. For example, the following things will be parsed as single
423 sub- or superscripts.
425 10^24 or 10^tau several digits will be considered 1 item.
426 10^-12 or 10^-tau a leading sign with digits or a word
427 x^2-y^3 will be read as x^2 - y^3, because items are
428 terminated by almost any nonword/nondigit char.
429 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
431 Still, ambiguity is possible - so when in doubt use {} to enclose the
432 sub/superscript. If you set this variable to the symbol `{}',
433 the braces are *required* in order to trigger interpretations as
434 sub/superscript. This can be helpful in documents that need \"_\"
435 frequently in plain text.
437 Not all export backends support this, but HTML does.
439 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
441 :group
'org-export-translation
443 (const :tag
"Always interpret" t
)
444 (const :tag
"Only with braces" {})
445 (const :tag
"Never interpret" nil
)))
447 (if (fboundp 'defvaralias
)
448 (defvaralias 'org-export-with-sub-superscripts
'org-use-sub-superscripts
))
451 (defcustom org-startup-with-beamer-mode nil
452 "Non-nil means turn on `org-beamer-mode' on startup.
453 This can also be configured on a per-file basis by adding one of
454 the following lines anywhere in the buffer:
460 (defcustom org-startup-align-all-tables nil
461 "Non-nil means align all tables when visiting a file.
462 This is useful when the column width in tables is forced with <N> cookies
463 in table fields. Such tables will look correct only after the first re-align.
464 This can also be configured on a per-file basis by adding one of
465 the following lines anywhere in the buffer:
471 (defcustom org-insert-mode-line-in-empty-file nil
472 "Non-nil means insert the first line setting Org-mode in empty files.
473 When the function `org-mode' is called interactively in an empty file, this
474 normally means that the file name does not automatically trigger Org-mode.
475 To ensure that the file will always be in Org-mode in the future, a
476 line enforcing Org-mode will be inserted into the buffer, if this option
481 (defcustom org-replace-disputed-keys nil
482 "Non-nil means use alternative key bindings for some keys.
483 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
484 These keys are also used by other packages like shift-selection-mode'
485 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
486 If you want to use Org-mode together with one of these other modes,
487 or more generally if you would like to move some Org-mode commands to
488 other keys, set this variable and configure the keys with the variable
491 This option is only relevant at load-time of Org-mode, and must be set
492 *before* org.el is loaded. Changing it requires a restart of Emacs to
497 (defcustom org-use-extra-keys nil
498 "Non-nil means use extra key sequence definitions for certain commands.
499 This happens automatically if you run XEmacs or if `window-system'
500 is nil. This variable lets you do the same manually. You must
501 set it before loading org.
503 Example: on Carbon Emacs 22 running graphically, with an external
504 keyboard on a Powerbook, the default way of setting M-left might
505 not work for either Alt or ESC. Setting this variable will make
510 (if (fboundp 'defvaralias
)
511 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
513 (defcustom org-disputed-keys
514 '(([(shift up
)] .
[(meta p
)])
515 ([(shift down
)] .
[(meta n
)])
516 ([(shift left
)] .
[(meta -
)])
517 ([(shift right
)] .
[(meta +)])
518 ([(control shift right
)] .
[(meta shift
+)])
519 ([(control shift left
)] .
[(meta shift -
)]))
520 "Keys for which Org-mode and other modes compete.
521 This is an alist, cars are the default keys, second element specifies
522 the alternative to use when `org-replace-disputed-keys' is t.
524 Keys can be specified in any syntax supported by `define-key'.
525 The value of this option takes effect only at Org-mode's startup,
526 therefore you'll have to restart Emacs to apply it after changing."
531 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
532 Or return the original if not disputed.
533 Also apply the translations defined in `org-xemacs-key-equivalents'."
534 (when org-replace-disputed-keys
535 (let* ((nkey (key-description key
))
536 (x (org-find-if (lambda (x)
537 (equal (key-description (car x
)) nkey
))
539 (setq key
(if x
(cdr x
) key
))))
540 (when (featurep 'xemacs
)
541 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
544 (defun org-find-if (predicate seq
)
547 (if (funcall predicate
(car seq
))
548 (throw 'exit
(car seq
))
551 (defun org-defkey (keymap key def
)
552 "Define a key, possibly translated, as returned by `org-key'."
553 (define-key keymap
(org-key key
) def
))
555 (defcustom org-ellipsis nil
556 "The ellipsis to use in the Org-mode outline.
557 When nil, just use the standard three dots. When a string, use that instead,
558 When a face, use the standard 3 dots, but with the specified face.
559 The change affects only Org-mode (which will then use its own display table).
560 Changing this requires executing `M-x org-mode' in a buffer to become
563 :type
'(choice (const :tag
"Default" nil
)
564 (face :tag
"Face" :value org-warning
)
565 (string :tag
"String" :value
"...#")))
567 (defvar org-display-table nil
568 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
570 (defgroup org-keywords nil
571 "Keywords in Org-mode."
575 (defcustom org-deadline-string
"DEADLINE:"
576 "String to mark deadline entries.
577 A deadline is this string, followed by a time stamp. Should be a word,
578 terminated by a colon. You can insert a schedule keyword and
579 a timestamp with \\[org-deadline].
580 Changes become only effective after restarting Emacs."
584 (defcustom org-scheduled-string
"SCHEDULED:"
585 "String to mark scheduled TODO entries.
586 A schedule is this string, followed by a time stamp. Should be a word,
587 terminated by a colon. You can insert a schedule keyword and
588 a timestamp with \\[org-schedule].
589 Changes become only effective after restarting Emacs."
593 (defcustom org-closed-string
"CLOSED:"
594 "String used as the prefix for timestamps logging closing a TODO entry."
598 (defcustom org-clock-string
"CLOCK:"
599 "String used as prefix for timestamps clocking work hours on an item."
603 (defcustom org-comment-string
"COMMENT"
604 "Entries starting with this keyword will never be exported.
605 An entry can be toggled between COMMENT and normal with
606 \\[org-toggle-comment].
607 Changes become only effective after restarting Emacs."
611 (defcustom org-quote-string
"QUOTE"
612 "Entries starting with this keyword will be exported in fixed-width font.
613 Quoting applies only to the text in the entry following the headline, and does
614 not extend beyond the next headline, even if that is lower level.
615 An entry can be toggled between QUOTE and normal with
616 \\[org-toggle-fixed-width-section]."
620 (defconst org-repeat-re
621 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
622 "Regular expression for specifying repeated events.
623 After a match, group 1 contains the repeat expression.")
625 (defgroup org-structure nil
626 "Options concerning the general structure of Org-mode files."
630 (defgroup org-reveal-location nil
631 "Options about how to make context of a location visible."
632 :tag
"Org Reveal Location"
633 :group
'org-structure
)
635 (defconst org-context-choice
637 (const :tag
"Always" t
)
638 (const :tag
"Never" nil
)
639 (repeat :greedy t
:tag
"Individual contexts"
641 (choice :tag
"Context"
648 (const bookmark-jump
)
652 "Contexts for the reveal options.")
654 (defcustom org-show-hierarchy-above
'((default . t
))
655 "Non-nil means show full hierarchy when revealing a location.
656 Org-mode often shows locations in an org-mode file which might have
657 been invisible before. When this is set, the hierarchy of headings
658 above the exposed location is shown.
659 Turning this off for example for sparse trees makes them very compact.
660 Instead of t, this can also be an alist specifying this option for different
661 contexts. Valid contexts are
662 agenda when exposing an entry from the agenda
663 org-goto when using the command `org-goto' on key C-c C-j
664 occur-tree when using the command `org-occur' on key C-c /
665 tags-tree when constructing a sparse tree based on tags matches
666 link-search when exposing search matches associated with a link
667 mark-goto when exposing the jump goal of a mark
668 bookmark-jump when exposing a bookmark location
669 isearch when exiting from an incremental search
670 default default for all contexts not set explicitly"
671 :group
'org-reveal-location
672 :type org-context-choice
)
674 (defcustom org-show-following-heading
'((default . nil
))
675 "Non-nil means show following heading when revealing a location.
676 Org-mode often shows locations in an org-mode file which might have
677 been invisible before. When this is set, the heading following the
679 Turning this off for example for sparse trees makes them very compact,
680 but makes it harder to edit the location of the match. In such a case,
681 use the command \\[org-reveal] to show more context.
682 Instead of t, this can also be an alist specifying this option for different
683 contexts. See `org-show-hierarchy-above' for valid contexts."
684 :group
'org-reveal-location
685 :type org-context-choice
)
687 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
688 "Non-nil means show all sibling heading when revealing a location.
689 Org-mode often shows locations in an org-mode file which might have
690 been invisible before. When this is set, the sibling of the current entry
691 heading are all made visible. If `org-show-hierarchy-above' is t,
692 the same happens on each level of the hierarchy above the current entry.
694 By default this is on for the isearch context, off for all other contexts.
695 Turning this off for example for sparse trees makes them very compact,
696 but makes it harder to edit the location of the match. In such a case,
697 use the command \\[org-reveal] to show more context.
698 Instead of t, this can also be an alist specifying this option for different
699 contexts. See `org-show-hierarchy-above' for valid contexts."
700 :group
'org-reveal-location
701 :type org-context-choice
)
703 (defcustom org-show-entry-below
'((default . nil
))
704 "Non-nil means show the entry below a headline when revealing a location.
705 Org-mode often shows locations in an org-mode file which might have
706 been invisible before. When this is set, the text below the headline that is
707 exposed is also shown.
709 By default this is off for all contexts.
710 Instead of t, this can also be an alist specifying this option for different
711 contexts. See `org-show-hierarchy-above' for valid contexts."
712 :group
'org-reveal-location
713 :type org-context-choice
)
715 (defcustom org-indirect-buffer-display
'other-window
716 "How should indirect tree buffers be displayed?
717 This applies to indirect buffers created with the commands
718 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
720 current-window Display in the current window
721 other-window Just display in another window.
722 dedicated-frame Create one new frame, and re-use it each time.
723 new-frame Make a new frame each time. Note that in this case
724 previously-made indirect buffers are kept, and you need to
725 kill these buffers yourself."
726 :group
'org-structure
727 :group
'org-agenda-windows
729 (const :tag
"In current window" current-window
)
730 (const :tag
"In current frame, other window" other-window
)
731 (const :tag
"Each time a new frame" new-frame
)
732 (const :tag
"One dedicated frame" dedicated-frame
)))
734 (defcustom org-use-speed-commands nil
735 "Non-nil means activate single letter commands at beginning of a headline.
736 This may also be a function to test for appropriate locations where speed
737 commands should be active."
738 :group
'org-structure
740 (const :tag
"Never" nil
)
741 (const :tag
"At beginning of headline stars" t
)
744 (defcustom org-speed-commands-user nil
745 "Alist of additional speed commands.
746 This list will be checked before `org-speed-commands-default'
747 when the variable `org-use-speed-commands' is non-nil
748 and when the cursor is at the beginning of a headline.
749 The car if each entry is a string with a single letter, which must
750 be assigned to `self-insert-command' in the global map.
751 The cdr is either a command to be called interactively, a function
752 to be called, or a form to be evaluated.
753 An entry that is just a list with a single string will be interpreted
754 as a descriptive headline that will be added when listing the speed
755 commands in the Help buffer using the `?' speed command."
756 :group
'org-structure
757 :type
'(repeat :value
("k" . ignore
)
758 (choice :value
("k" . ignore
)
759 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
760 (cons :tag
"Letter and Command"
761 (string :tag
"Command letter")
766 (defgroup org-cycle nil
767 "Options concerning visibility cycling in Org-mode."
769 :group
'org-structure
)
771 (defcustom org-cycle-skip-children-state-if-no-children t
772 "Non-nil means skip CHILDREN state in entries that don't have any."
776 (defcustom org-cycle-max-level nil
777 "Maximum level which should still be subject to visibility cycling.
778 Levels higher than this will, for cycling, be treated as text, not a headline.
779 When `org-odd-levels-only' is set, a value of N in this variable actually
780 means 2N-1 stars as the limiting headline.
781 When nil, cycle all levels.
782 Note that the limiting level of cycling is also influenced by
783 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
784 `org-inlinetask-min-level' is, cycling will be limited to levels one less
788 (const :tag
"No limit" nil
)
789 (integer :tag
"Maximum level")))
791 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK")
792 "Names of drawers. Drawers are not opened by cycling on the headline above.
793 Drawers only open with a TAB on the drawer line itself. A drawer looks like
798 The drawer \"PROPERTIES\" is special for capturing properties through
801 Drawers can be defined on the per-file basis with a line like:
803 #+DRAWERS: HIDDEN STATE PROPERTIES"
804 :group
'org-structure
806 :type
'(repeat (string :tag
"Drawer Name")))
808 (defcustom org-hide-block-startup nil
809 "Non-nil means entering Org-mode will fold all blocks.
810 This can also be set in on a per-file basis with
812 #+STARTUP: hideblocks
813 #+STARTUP: showblocks"
818 (defcustom org-cycle-global-at-bob nil
819 "Cycle globally if cursor is at beginning of buffer and not at a headline.
820 This makes it possible to do global cycling without having to use S-TAB or
821 \\[universal-argument] TAB. For this special case to work, the first line \
823 must not be a headline - it may be empty or some other text. When used in
824 this way, `org-cycle-hook' is disables temporarily, to make sure the
825 cursor stays at the beginning of the buffer.
826 When this option is nil, don't do anything special at the beginning
831 (defcustom org-cycle-level-after-item
/entry-creation t
832 "Non-nil means cycle entry level or item indentation in new empty entries.
834 When the cursor is at the end of an empty headline, i.e with only stars
835 and maybe a TODO keyword, TAB will then switch the entry to become a child,
836 and then all possible ancestor states, before returning to the original state.
837 This makes data entry extremely fast: M-RET to create a new headline,
838 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
840 When the cursor is at the end of an empty plain list item, one TAB will
841 make it a subitem, two or more tabs will back up to make this an item
842 higher up in the item hierarchy."
846 (defcustom org-cycle-emulate-tab t
847 "Where should `org-cycle' emulate TAB.
849 white Only in completely white lines
850 whitestart Only at the beginning of lines, before the first non-white char
851 t Everywhere except in headlines
852 exc-hl-bol Everywhere except at the start of a headline
853 If TAB is used in a place where it does not emulate TAB, the current subtree
854 visibility is cycled."
856 :type
'(choice (const :tag
"Never" nil
)
857 (const :tag
"Only in completely white lines" white
)
858 (const :tag
"Before first char in a line" whitestart
)
859 (const :tag
"Everywhere except in headlines" t
)
860 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
863 (defcustom org-cycle-separator-lines
2
864 "Number of empty lines needed to keep an empty line between collapsed trees.
865 If you leave an empty line between the end of a subtree and the following
866 headline, this empty line is hidden when the subtree is folded.
867 Org-mode will leave (exactly) one empty line visible if the number of
868 empty lines is equal or larger to the number given in this variable.
869 So the default 2 means at least 2 empty lines after the end of a subtree
870 are needed to produce free space between a collapsed subtree and the
873 If the number is negative, and the number of empty lines is at least -N,
874 all empty lines are shown.
876 Special case: when 0, never leave empty lines in collapsed view."
879 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
881 (defcustom org-pre-cycle-hook nil
882 "Hook that is run before visibility cycling is happening.
883 The function(s) in this hook must accept a single argument which indicates
884 the new state that will be set right after running this hook. The
885 argument is a symbol. Before a global state change, it can have the values
886 `overview', `content', or `all'. Before a local state change, it can have
887 the values `folded', `children', or `subtree'."
891 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
892 org-cycle-hide-drawers
893 org-cycle-show-empty-lines
894 org-optimize-window-after-visibility-change
)
895 "Hook that is run after `org-cycle' has changed the buffer visibility.
896 The function(s) in this hook must accept a single argument which indicates
897 the new state that was set by the most recent `org-cycle' command. The
898 argument is a symbol. After a global state change, it can have the values
899 `overview', `content', or `all'. After a local state change, it can have
900 the values `folded', `children', or `subtree'."
904 (defgroup org-edit-structure nil
905 "Options concerning structure editing in Org-mode."
906 :tag
"Org Edit Structure"
907 :group
'org-structure
)
909 (defcustom org-odd-levels-only nil
910 "Non-nil means skip even levels and only use odd levels for the outline.
911 This has the effect that two stars are being added/taken away in
912 promotion/demotion commands. It also influences how levels are
913 handled by the exporters.
914 Changing it requires restart of `font-lock-mode' to become effective
915 for fontification also in regions already fontified.
916 You may also set this on a per-file basis by adding one of the following
921 :group
'org-edit-structure
922 :group
'org-appearance
925 (defcustom org-adapt-indentation t
926 "Non-nil means adapt indentation to outline node level.
928 When this variable is set, Org assumes that you write outlines by
929 indenting text in each node to align with the headline (after the stars).
930 The following issues are influenced by this variable:
932 - When this is set and the *entire* text in an entry is indented, the
933 indentation is increased by one space in a demotion command, and
934 decreased by one in a promotion command. If any line in the entry
935 body starts with text at column 0, indentation is not changed at all.
937 - Property drawers and planning information is inserted indented when
938 this variable s set. When nil, they will not be indented.
940 - TAB indents a line relative to context. The lines below a headline
941 will be indented when this variable is set.
943 Note that this is all about true indentation, by adding and removing
944 space characters. See also `org-indent.el' which does level-dependent
945 indentation in a virtual way, i.e. at display time in Emacs."
946 :group
'org-edit-structure
949 (defcustom org-special-ctrl-a
/e nil
950 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
952 When t, `C-a' will bring back the cursor to the beginning of the
953 headline text, i.e. after the stars and after a possible TODO keyword.
954 In an item, this will be the position after the bullet.
955 When the cursor is already at that position, another `C-a' will bring
956 it to the beginning of the line.
958 `C-e' will jump to the end of the headline, ignoring the presence of tags
959 in the headline. A second `C-e' will then jump to the true end of the
960 line, after any tags. This also means that, when this variable is
961 non-nil, `C-e' also will never jump beyond the end of the heading of a
962 folded section, i.e. not after the ellipses.
964 When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
965 going to the true line boundary first. Only a directly following, identical
966 keypress will bring the cursor to the special positions.
968 This may also be a cons cell where the behavior for `C-a' and `C-e' is
970 :group
'org-edit-structure
972 (const :tag
"off" nil
)
973 (const :tag
"on: after stars/bullet and before tags first" t
)
974 (const :tag
"reversed: true line boundary first" reversed
)
975 (cons :tag
"Set C-a and C-e separately"
976 (choice :tag
"Special C-a"
977 (const :tag
"off" nil
)
978 (const :tag
"on: after stars/bullet first" t
)
979 (const :tag
"reversed: before stars/bullet first" reversed
))
980 (choice :tag
"Special C-e"
981 (const :tag
"off" nil
)
982 (const :tag
"on: before tags first" t
)
983 (const :tag
"reversed: after tags first" reversed
)))))
984 (if (fboundp 'defvaralias
)
985 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
987 (defcustom org-special-ctrl-k nil
988 "Non-nil means `C-k' will behave specially in headlines.
989 When nil, `C-k' will call the default `kill-line' command.
990 When t, the following will happen while the cursor is in the headline:
992 - When the cursor is at the beginning of a headline, kill the entire
993 line and possible the folded subtree below the line.
994 - When in the middle of the headline text, kill the headline up to the tags.
995 - When after the headline text, kill the tags."
996 :group
'org-edit-structure
999 (defcustom org-ctrl-k-protect-subtree nil
1000 "Non-nil means, do not delete a hidden subtree with C-k.
1001 When set to the symbol `error', simply throw an error when C-k is
1002 used to kill (part-of) a headline that has hidden text behind it.
1003 Any other non-nil value will result in a query to the user, if it is
1004 OK to kill that hidden subtree. When nil, kill without remorse."
1005 :group
'org-edit-structure
1007 (const :tag
"Do not protect hidden subtrees" nil
)
1008 (const :tag
"Protect hidden subtrees with a security query" t
)
1009 (const :tag
"Never kill a hidden subtree with C-k" error
)))
1011 (defcustom org-yank-folded-subtrees t
1012 "Non-nil means when yanking subtrees, fold them.
1013 If the kill is a single subtree, or a sequence of subtrees, i.e. if
1014 it starts with a heading and all other headings in it are either children
1015 or siblings, then fold all the subtrees. However, do this only if no
1016 text after the yank would be swallowed into a folded tree by this action."
1017 :group
'org-edit-structure
1020 (defcustom org-yank-adjusted-subtrees nil
1021 "Non-nil means when yanking subtrees, adjust the level.
1022 With this setting, `org-paste-subtree' is used to insert the subtree, see
1023 this function for details."
1024 :group
'org-edit-structure
1027 (defcustom org-M-RET-may-split-line
'((default . t
))
1028 "Non-nil means M-RET will split the line at the cursor position.
1029 When nil, it will go to the end of the line before making a
1031 You may also set this option in a different way for different
1032 contexts. Valid contexts are:
1034 headline when creating a new headline
1035 item when creating a new item
1036 table in a table field
1037 default the value to be used for all contexts not explicitly
1039 :group
'org-structure
1042 (const :tag
"Always" t
)
1043 (const :tag
"Never" nil
)
1044 (repeat :greedy t
:tag
"Individual contexts"
1046 (choice :tag
"Context"
1054 (defcustom org-insert-heading-respect-content nil
1055 "Non-nil means insert new headings after the current subtree.
1056 When nil, the new heading is created directly after the current line.
1057 The commands \\[org-insert-heading-respect-content] and
1058 \\[org-insert-todo-heading-respect-content] turn this variable on
1059 for the duration of the command."
1060 :group
'org-structure
1063 (defcustom org-blank-before-new-entry
'((heading . auto
)
1064 (plain-list-item . auto
))
1065 "Should `org-insert-heading' leave a blank line before new heading/item?
1066 The value is an alist, with `heading' and `plain-list-item' as car,
1067 and a boolean flag as cdr. For plain lists, if the variable
1068 `org-empty-line-terminates-plain-lists' is set, the setting here
1069 is ignored and no empty line is inserted, to keep the list in tact."
1070 :group
'org-edit-structure
1072 (cons (const heading
)
1073 (choice (const :tag
"Never" nil
)
1074 (const :tag
"Always" t
)
1075 (const :tag
"Auto" auto
)))
1076 (cons (const plain-list-item
)
1077 (choice (const :tag
"Never" nil
)
1078 (const :tag
"Always" t
)
1079 (const :tag
"Auto" auto
)))))
1081 (defcustom org-insert-heading-hook nil
1082 "Hook being run after inserting a new heading."
1083 :group
'org-edit-structure
1086 (defcustom org-enable-fixed-width-editor t
1087 "Non-nil means lines starting with \":\" are treated as fixed-width.
1088 This currently only means they are never auto-wrapped.
1089 When nil, such lines will be treated like ordinary lines.
1090 See also the QUOTE keyword."
1091 :group
'org-edit-structure
1094 (defcustom org-goto-auto-isearch t
1095 "Non-nil means typing characters in `org-goto' starts incremental search."
1096 :group
'org-edit-structure
1099 (defgroup org-sparse-trees nil
1100 "Options concerning sparse trees in Org-mode."
1101 :tag
"Org Sparse Trees"
1102 :group
'org-structure
)
1104 (defcustom org-highlight-sparse-tree-matches t
1105 "Non-nil means highlight all matches that define a sparse tree.
1106 The highlights will automatically disappear the next time the buffer is
1107 changed by an edit command."
1108 :group
'org-sparse-trees
1111 (defcustom org-remove-highlights-with-change t
1112 "Non-nil means any change to the buffer will remove temporary highlights.
1113 Such highlights are created by `org-occur' and `org-clock-display'.
1114 When nil, `C-c C-c needs to be used to get rid of the highlights.
1115 The highlights created by `org-preview-latex-fragment' always need
1116 `C-c C-c' to be removed."
1117 :group
'org-sparse-trees
1122 (defcustom org-occur-hook
'(org-first-headline-recenter)
1123 "Hook that is run after `org-occur' has constructed a sparse tree.
1124 This can be used to recenter the window to show as much of the structure
1126 :group
'org-sparse-trees
1129 (defgroup org-imenu-and-speedbar nil
1130 "Options concerning imenu and speedbar in Org-mode."
1131 :tag
"Org Imenu and Speedbar"
1132 :group
'org-structure
)
1134 (defcustom org-imenu-depth
2
1135 "The maximum level for Imenu access to Org-mode headlines.
1136 This also applied for speedbar access."
1137 :group
'org-imenu-and-speedbar
1140 (defgroup org-table nil
1141 "Options concerning tables in Org-mode."
1145 (defcustom org-enable-table-editor
'optimized
1146 "Non-nil means lines starting with \"|\" are handled by the table editor.
1147 When nil, such lines will be treated like ordinary lines.
1149 When equal to the symbol `optimized', the table editor will be optimized to
1151 - Automatic overwrite mode in front of whitespace in table fields.
1152 This makes the structure of the table stay in tact as long as the edited
1153 field does not exceed the column width.
1154 - Minimize the number of realigns. Normally, the table is aligned each time
1155 TAB or RET are pressed to move to another field. With optimization this
1156 happens only if changes to a field might have changed the column width.
1157 Optimization requires replacing the functions `self-insert-command',
1158 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1159 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1160 very good at guessing when a re-align will be necessary, but you can always
1161 force one with \\[org-ctrl-c-ctrl-c].
1163 If you would like to use the optimized version in Org-mode, but the
1164 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1166 This variable can be used to turn on and off the table editor during a session,
1167 but in order to toggle optimization, a restart is required.
1169 See also the variable `org-table-auto-blank-field'."
1172 (const :tag
"off" nil
)
1174 (const :tag
"on, optimized" optimized
)))
1176 (defcustom org-self-insert-cluster-for-undo t
1177 "Non-nil means cluster self-insert commands for undo when possible.
1178 If this is set, then, like in the Emacs command loop, 20 consecutive
1179 characters will be undone together.
1180 This is configurable, because there is some impact on typing performance."
1184 (defcustom org-table-tab-recognizes-table.el t
1185 "Non-nil means TAB will automatically notice a table.el table.
1186 When it sees such a table, it moves point into it and - if necessary -
1187 calls `table-recognize-table'."
1188 :group
'org-table-editing
1191 (defgroup org-link nil
1192 "Options concerning links in Org-mode."
1196 (defvar org-link-abbrev-alist-local nil
1197 "Buffer-local version of `org-link-abbrev-alist', which see.
1198 The value of this is taken from the #+LINK lines.")
1199 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1201 (defcustom org-link-abbrev-alist nil
1202 "Alist of link abbreviations.
1203 The car of each element is a string, to be replaced at the start of a link.
1204 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1205 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1207 [[linkkey:tag][description]]
1209 The 'linkkey' must be a word word, starting with a letter, followed
1210 by letters, numbers, '-' or '_'.
1212 If REPLACE is a string, the tag will simply be appended to create the link.
1213 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1214 the placeholder \"%h\" will cause a url-encoded version of the tag to
1215 be inserted at that point (see the function `url-hexify-string').
1217 REPLACE may also be a function that will be called with the tag as the
1218 only argument to create the link, which should be returned as a string.
1220 See the manual for examples."
1224 (string :tag
"Protocol")
1226 (string :tag
"Format")
1229 (defcustom org-descriptive-links t
1230 "Non-nil means hide link part and only show description of bracket links.
1231 Bracket links are like [[link][description]]. This variable sets the initial
1232 state in new org-mode buffers. The setting can then be toggled on a
1233 per-buffer basis from the Org->Hyperlinks menu."
1237 (defcustom org-link-file-path-type
'adaptive
1238 "How the path name in file links should be stored.
1241 relative Relative to the current directory, i.e. the directory of the file
1242 into which the link is being inserted.
1243 absolute Absolute path, if possible with ~ for home directory.
1244 noabbrev Absolute path, no abbreviation of home directory.
1245 adaptive Use relative path for files in the current directory and sub-
1246 directories of it. For other files, use an absolute path."
1254 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1255 "Types of links that should be activated in Org-mode files.
1256 This is a list of symbols, each leading to the activation of a certain link
1257 type. In principle, it does not hurt to turn on most link types - there may
1258 be a small gain when turning off unused link types. The types are:
1260 bracket The recommended [[link][description]] or [[link]] links with hiding.
1261 angular Links in angular brackets that may contain whitespace like
1262 <bbdb:Carsten Dominik>.
1263 plain Plain links in normal text, no whitespace, like http://google.com.
1264 radio Text that is matched by a radio target, see manual for details.
1265 tag Tag settings in a headline (link to tag search).
1266 date Time stamps (link to calendar).
1267 footnote Footnote labels.
1269 Changing this variable requires a restart of Emacs to become effective."
1271 :type
'(set :greedy t
1272 (const :tag
"Double bracket links (new style)" bracket
)
1273 (const :tag
"Angular bracket links (old style)" angular
)
1274 (const :tag
"Plain text links" plain
)
1275 (const :tag
"Radio target matches" radio
)
1276 (const :tag
"Tags" tag
)
1277 (const :tag
"Timestamps" date
)
1278 (const :tag
"Footnotes" footnote
)))
1280 (defcustom org-make-link-description-function nil
1281 "Function to use to generate link descriptions from links.
1282 If nil the link location will be used. This function must take
1283 two parameters; the first is the link and the second the
1284 description `org-insert-link' has generated, and should return the
1285 description to use."
1289 (defgroup org-link-store nil
1290 "Options concerning storing links in Org-mode."
1291 :tag
"Org Store Link"
1294 (defcustom org-email-link-description-format
"Email %c: %.30s"
1295 "Format of the description part of a link to an email or usenet message.
1296 The following %-escapes will be replaced by corresponding information:
1298 %F full \"From\" field
1299 %f name, taken from \"From\" field, address if no name
1300 %T full \"To\" field
1301 %t first name in \"To\" field, address if no name
1302 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1303 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1307 You may use normal field width specification between the % and the letter.
1308 This is for example useful to limit the length of the subject.
1310 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1311 :group
'org-link-store
1314 (defcustom org-from-is-user-regexp
1316 (when (and user-mail-address
(not (string= user-mail-address
"")))
1317 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1318 (when (and user-full-name
(not (string= user-full-name
"")))
1319 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1320 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1321 "Regexp matched against the \"From:\" header of an email or usenet message.
1322 It should match if the message is from the user him/herself."
1323 :group
'org-link-store
1326 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1327 "Non-nil means storing a link to an Org file will use entry IDs.
1329 Note that before this variable is even considered, org-id must be loaded,
1330 so please customize `org-modules' and turn it on.
1332 The variable can have the following values:
1334 t Create an ID if needed to make a link to the current entry.
1336 create-if-interactive
1337 If `org-store-link' is called directly (interactively, as a user
1338 command), do create an ID to support the link. But when doing the
1339 job for remember, only use the ID if it already exists. The
1340 purpose of this setting is to avoid proliferation of unwanted
1341 IDs, just because you happen to be in an Org file when you
1342 call `org-remember' that automatically and preemptively
1343 creates a link. If you do want to get an ID link in a remember
1344 template to an entry not having an ID, create it first by
1345 explicitly creating a link to it, using `C-c C-l' first.
1347 create-if-interactive-and-no-custom-id
1348 Like create-if-interactive, but do not create an ID if there is
1349 a CUSTOM_ID property defined in the entry. This is the default.
1352 Use existing ID, do not create one.
1354 nil Never use an ID to make a link, instead link using a text search for
1356 :group
'org-link-store
1358 (const :tag
"Create ID to make link" t
)
1359 (const :tag
"Create if storing link interactively"
1360 create-if-interactive
)
1361 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1362 create-if-interactive-and-no-custom-id
)
1363 (const :tag
"Only use existing" use-existing
)
1364 (const :tag
"Do not use ID to create link" nil
)))
1366 (defcustom org-context-in-file-links t
1367 "Non-nil means file links from `org-store-link' contain context.
1368 A search string will be added to the file name with :: as separator and
1369 used to find the context when the link is activated by the command
1370 `org-open-at-point'.
1371 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1372 negates this setting for the duration of the command."
1373 :group
'org-link-store
1376 (defcustom org-keep-stored-link-after-insertion nil
1377 "Non-nil means keep link in list for entire session.
1379 The command `org-store-link' adds a link pointing to the current
1380 location to an internal list. These links accumulate during a session.
1381 The command `org-insert-link' can be used to insert links into any
1382 Org-mode file (offering completion for all stored links). When this
1383 option is nil, every link which has been inserted once using \\[org-insert-link]
1384 will be removed from the list, to make completing the unused links
1386 :group
'org-link-store
1389 (defgroup org-link-follow nil
1390 "Options concerning following links in Org-mode."
1391 :tag
"Org Follow Link"
1394 (defcustom org-link-translation-function nil
1395 "Function to translate links with different syntax to Org syntax.
1396 This can be used to translate links created for example by the Planner
1397 or emacs-wiki packages to Org syntax.
1398 The function must accept two parameters, a TYPE containing the link
1399 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1400 which is everything after the link protocol. It should return a cons
1401 with possibly modified values of type and path.
1402 Org contains a function for this, so if you set this variable to
1403 `org-translate-link-from-planner', you should be able follow many
1404 links created by planner."
1405 :group
'org-link-follow
1408 (defcustom org-follow-link-hook nil
1409 "Hook that is run after a link has been followed."
1410 :group
'org-link-follow
1413 (defcustom org-tab-follows-link nil
1414 "Non-nil means on links TAB will follow the link.
1415 Needs to be set before org.el is loaded.
1416 This really should not be used, it does not make sense, and the
1417 implementation is bad."
1418 :group
'org-link-follow
1421 (defcustom org-return-follows-link nil
1422 "Non-nil means on links RET will follow the link."
1423 :group
'org-link-follow
1426 (defcustom org-mouse-1-follows-link
1427 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1428 "Non-nil means mouse-1 on a link will follow the link.
1429 A longer mouse click will still set point. Does not work on XEmacs.
1430 Needs to be set before org.el is loaded."
1431 :group
'org-link-follow
1434 (defcustom org-mark-ring-length
4
1435 "Number of different positions to be recorded in the ring.
1436 Changing this requires a restart of Emacs to work correctly."
1437 :group
'org-link-follow
1440 (defcustom org-link-frame-setup
1441 '((vm . vm-visit-folder-other-frame
)
1442 (gnus . org-gnus-no-new-news
)
1443 (file . find-file-other-window
)
1444 (wl . wl-other-frame
))
1445 "Setup the frame configuration for following links.
1446 When following a link with Emacs, it may often be useful to display
1447 this link in another window or frame. This variable can be used to
1448 set this up for the different types of links.
1451 `vm-visit-folder-other-frame'
1452 For Gnus, use any of
1455 `org-gnus-no-new-news'
1456 For FILE, use any of
1458 `find-file-other-window'
1459 `find-file-other-frame'
1460 For Wanderlust use any of
1463 For the calendar, use the variable `calendar-setup'.
1464 For BBDB, it is currently only possible to display the matches in
1466 :group
'org-link-follow
1470 (const vm-visit-folder
)
1471 (const vm-visit-folder-other-window
)
1472 (const vm-visit-folder-other-frame
)))
1476 (const gnus-other-frame
)
1477 (const org-gnus-no-new-news
)))
1481 (const find-file-other-window
)
1482 (const find-file-other-frame
)))
1486 (const wl-other-frame
)))))
1488 (defcustom org-display-internal-link-with-indirect-buffer nil
1489 "Non-nil means use indirect buffer to display infile links.
1490 Activating internal links (from one location in a file to another location
1491 in the same file) normally just jumps to the location. When the link is
1492 activated with a \\[universal-argument] prefix (or with mouse-3), the link \
1494 another window. When this option is set, the other window actually displays
1495 an indirect buffer clone of the current buffer, to avoid any visibility
1496 changes to the current buffer."
1497 :group
'org-link-follow
1500 (defcustom org-open-non-existing-files nil
1501 "Non-nil means `org-open-file' will open non-existing files.
1502 When nil, an error will be generated.
1503 This variable applies only to external applications because they
1504 might choke on non-existing files. If the link is to a file that
1505 will be opened in Emacs, the variable is ignored."
1506 :group
'org-link-follow
1509 (defcustom org-open-directory-means-index-dot-org nil
1510 "Non-nil means a link to a directory really means to index.org.
1511 When nil, following a directory link will run dired or open a finder/explorer
1512 window on that directory."
1513 :group
'org-link-follow
1516 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1517 "Function and arguments to call for following mailto links.
1518 This is a list with the first element being a Lisp function, and the
1519 remaining elements being arguments to the function. In string arguments,
1520 %a will be replaced by the address, and %s will be replaced by the subject
1521 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1522 :group
'org-link-follow
1524 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1525 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1526 (const :tag
"message-mail" (message-mail "%a" "%s"))
1527 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1529 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1530 "Non-nil means ask for confirmation before executing shell links.
1531 Shell links can be dangerous: just think about a link
1533 [[shell:rm -rf ~/*][Google Search]]
1535 This link would show up in your Org-mode document as \"Google Search\",
1536 but really it would remove your entire home directory.
1537 Therefore we advise against setting this variable to nil.
1538 Just change it to `y-or-n-p' if you want to confirm with a
1539 single keystroke rather than having to type \"yes\"."
1540 :group
'org-link-follow
1542 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1543 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1544 (const :tag
"no confirmation (dangerous)" nil
)))
1545 (put 'org-confirm-shell-link-function
1546 'safe-local-variable
1547 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1549 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1550 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1551 Elisp links can be dangerous: just think about a link
1553 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1555 This link would show up in your Org-mode document as \"Google Search\",
1556 but really it would remove your entire home directory.
1557 Therefore we advise against setting this variable to nil.
1558 Just change it to `y-or-n-p' if you want to confirm with a
1559 single keystroke rather than having to type \"yes\"."
1560 :group
'org-link-follow
1562 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1563 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1564 (const :tag
"no confirmation (dangerous)" nil
)))
1565 (put 'org-confirm-shell-link-function
1566 'safe-local-variable
1567 '(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1569 (defconst org-file-apps-defaults-gnu
1573 "Default file applications on a UNIX or GNU/Linux system.
1574 See `org-file-apps'.")
1576 (defconst org-file-apps-defaults-macosx
1579 (system .
"open %s")
1581 ("eps.gz" .
"gv %s")
1583 ("fig" .
"xfig %s"))
1584 "Default file applications on a MacOS X system.
1585 The system \"open\" is known as a default, but we use X11 applications
1586 for some files for which the OS does not have a good default.
1587 See `org-file-apps'.")
1589 (defconst org-file-apps-defaults-windowsnt
1593 (list (if (featurep 'xemacs
)
1594 'mswindows-shell-execute
1598 (list (if (featurep 'xemacs
)
1599 'mswindows-shell-execute
1602 "Default file applications on a Windows NT system.
1603 The system \"open\" is used for most files.
1604 See `org-file-apps'.")
1606 (defcustom org-file-apps
1609 ("\\.mm\\'" . default
)
1610 ("\\.x?html?\\'" . default
)
1611 ("\\.pdf\\'" . default
)
1613 "External applications for opening `file:path' items in a document.
1614 Org-mode uses system defaults for different file types, but
1615 you can use this variable to set the application for a given file
1616 extension. The entries in this list are cons cells where the car identifies
1617 files and the cdr the corresponding command. Possible values for the
1619 \"string\" A string as a file identifier can be interpreted in different
1620 ways, depending on its contents:
1622 - Alphanumeric characters only:
1623 Match links with this file extension.
1624 Example: (\"pdf\" . \"evince %s\")
1625 to open PDFs with evince.
1627 - Regular expression: Match links where the
1628 filename matches the regexp. If you want to
1629 use groups here, use shy groups.
1631 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1632 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1633 to open *.html and *.xhtml with firefox.
1635 - Regular expression which contains (non-shy) groups:
1636 Match links where the whole link, including \"::\", and
1637 anything after that, matches the regexp.
1638 In a custom command string, %1, %2, etc. are replaced with
1639 the parts of the link that were matched by the groups.
1640 For backwards compatibility, if a command string is given
1641 that does not use any of the group matches, this case is
1642 handled identically to the second one (i.e. match against
1644 In a custom lisp form, you can access the group matches with
1645 (match-string n link).
1647 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1648 to open [[file:document.pdf::5]] with evince at page 5.
1650 `directory' Matches a directory
1651 `remote' Matches a remote file, accessible through tramp or efs.
1652 Remote files most likely should be visited through Emacs
1653 because external applications cannot handle such paths.
1654 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1655 so all files Emacs knows how to handle. Using this with
1656 command `emacs' will open most files in Emacs. Beware that this
1657 will also open html files inside Emacs, unless you add
1658 (\"html\" . default) to the list as well.
1659 t Default for files not matched by any of the other options.
1660 `system' The system command to open files, like `open' on Windows
1661 and Mac OS X, and mailcap under GNU/Linux. This is the command
1662 that will be selected if you call `C-c C-o' with a double
1663 \\[universal-argument] \\[universal-argument] prefix.
1665 Possible values for the command are:
1666 `emacs' The file will be visited by the current Emacs process.
1667 `default' Use the default application for this file type, which is the
1668 association for t in the list, most likely in the system-specific
1670 This can be used to overrule an unwanted setting in the
1671 system-specific variable.
1672 `system' Use the system command for opening files, like \"open\".
1673 This command is specified by the entry whose car is `system'.
1674 Most likely, the system-specific version of this variable
1675 does define this command, but you can overrule/replace it
1677 string A command to be executed by a shell; %s will be replaced
1678 by the path to the file.
1679 sexp A Lisp form which will be evaluated. The file path will
1680 be available in the Lisp variable `file'.
1681 For more examples, see the system specific constants
1682 `org-file-apps-defaults-macosx'
1683 `org-file-apps-defaults-windowsnt'
1684 `org-file-apps-defaults-gnu'."
1685 :group
'org-link-follow
1687 (cons (choice :value
""
1688 (string :tag
"Extension")
1689 (const :tag
"System command to open files" system
)
1690 (const :tag
"Default for unrecognized files" t
)
1691 (const :tag
"Remote file" remote
)
1692 (const :tag
"Links to a directory" directory
)
1693 (const :tag
"Any files that have Emacs modes"
1696 (const :tag
"Visit with Emacs" emacs
)
1697 (const :tag
"Use default" default
)
1698 (const :tag
"Use the system command" system
)
1699 (string :tag
"Command")
1700 (sexp :tag
"Lisp form")))))
1704 (defgroup org-refile nil
1705 "Options concerning refiling entries in Org-mode."
1709 (defcustom org-directory
"~/org"
1710 "Directory with org files.
1711 This is just a default location to look for Org files. There is no need
1712 at all to put your files into this directory. It is only used in the
1713 following situations:
1715 1. When a remember template specifies a target file that is not an
1716 absolute path. The path will then be interpreted relative to
1718 2. When a remember note is filed away in an interactive way (when exiting the
1719 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1720 with `org-directory' as the default path."
1722 :group
'org-remember
1725 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1726 "Default target for storing notes.
1727 Used as a fall back file for org-remember.el and org-capture.el, for
1728 templates that do not specify a target file."
1730 :group
'org-remember
1732 (const :tag
"Default from remember-data-file" nil
)
1735 (defcustom org-goto-interface
'outline
1736 "The default interface to be used for `org-goto'.
1738 outline The interface shows an outline of the relevant file
1739 and the correct heading is found by moving through
1740 the outline or by searching with incremental search.
1741 outline-path-completion Headlines in the current buffer are offered via
1742 completion. This is the interface also used by
1743 the refile command."
1746 (const :tag
"Outline" outline
)
1747 (const :tag
"Outline-path-completion" outline-path-completion
)))
1749 (defcustom org-goto-max-level
5
1750 "Maximum target level when running `org-goto' with refile interface."
1754 (defcustom org-reverse-note-order nil
1755 "Non-nil means store new notes at the beginning of a file or entry.
1756 When nil, new notes will be filed to the end of a file or entry.
1757 This can also be a list with cons cells of regular expressions that
1758 are matched against file names, and values."
1759 :group
'org-remember
1762 (const :tag
"Reverse always" t
)
1763 (const :tag
"Reverse never" nil
)
1764 (repeat :tag
"By file name regexp"
1765 (cons regexp boolean
))))
1767 (defcustom org-log-refile nil
1768 "Information to record when a task is refiled.
1770 Possible values are:
1772 nil Don't add anything
1773 time Add a time stamp to the task
1774 note Prompt for a note and add it with template `org-log-note-headings'
1776 This option can also be set with on a per-file-basis with
1778 #+STARTUP: nologrefile
1779 #+STARTUP: logrefile
1780 #+STARTUP: lognoterefile
1782 You can have local logging settings for a subtree by setting the LOGGING
1783 property to one or more of these keywords.
1785 When bulk-refiling from the agenda, the value `note' is forbidden and
1786 will temporarily be changed to `time'."
1788 :group
'org-progress
1790 (const :tag
"No logging" nil
)
1791 (const :tag
"Record timestamp" time
)
1792 (const :tag
"Record timestamp with note." note
)))
1794 (defcustom org-refile-targets nil
1795 "Targets for refiling entries with \\[org-refile].
1796 This is list of cons cells. Each cell contains:
1797 - a specification of the files to be considered, either a list of files,
1798 or a symbol whose function or variable value will be used to retrieve
1799 a file name or a list of file names. If you use `org-agenda-files' for
1800 that, all agenda files will be scanned for targets. The value nil means
1801 consider headings in the current buffer.
1802 - A specification of how to find candidate refile targets. This may be
1804 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1805 This tag has to be present in all target headlines, inheritance will
1807 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1809 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1810 headlines that are refiling targets.
1811 - a cons cell (:level . N). Any headline of level N is considered a target.
1812 Note that, when `org-odd-levels-only' is set, level corresponds to
1813 order in hierarchy, not to the number of stars.
1814 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1815 Note that, when `org-odd-levels-only' is set, level corresponds to
1816 order in hierarchy, not to the number of stars.
1818 You can set the variable `org-refile-target-verify-function' to a function
1819 to verify each headline found by the simple criteria above.
1821 When this variable is nil, all top-level headlines in the current buffer
1822 are used, equivalent to the value `((nil . (:level . 1))'."
1826 (choice :value org-agenda-files
1827 (const :tag
"All agenda files" org-agenda-files
)
1828 (const :tag
"Current buffer" nil
)
1829 (function) (variable) (file))
1830 (choice :tag
"Identify target headline by"
1831 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1832 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1833 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1834 (cons :tag
"Level number" (const :value
:level
) (integer))
1835 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1837 (defcustom org-refile-target-verify-function nil
1838 "Function to verify if the headline at point should be a refile target.
1839 The function will be called without arguments, with point at the
1840 beginning of the headline. It should return t and leave point
1841 where it is if the headline is a valid target for refiling.
1843 If the target should not be selected, the function must return nil.
1844 In addition to this, it may move point to a place from where the search
1845 should be continued. For example, the function may decide that the entire
1846 subtree of the current entry should be excluded and move point to the end
1851 (defcustom org-refile-use-cache nil
1852 "Non-nil means cache refile targets to speed up the process.
1853 The cache for a particular file will be updated automatically when
1854 the buffer has been killed, or when any of the marker used for flagging
1855 refile targets no longer points at a live buffer.
1856 If you have added new entries to a buffer that might themselves be targets,
1857 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
1858 find that easier, `C-u C-u C-u C-c C-w'."
1862 (defcustom org-refile-use-outline-path nil
1863 "Non-nil means provide refile targets as paths.
1864 So a level 3 headline will be available as level1/level2/level3.
1866 When the value is `file', also include the file name (without directory)
1867 into the path. In this case, you can also stop the completion after
1868 the file name, to get entries inserted as top level in the file.
1870 When `full-file-path', include the full file path."
1873 (const :tag
"Not" nil
)
1874 (const :tag
"Yes" t
)
1875 (const :tag
"Start with file name" file
)
1876 (const :tag
"Start with full file path" full-file-path
)))
1878 (defcustom org-outline-path-complete-in-steps t
1879 "Non-nil means complete the outline path in hierarchical steps.
1880 When Org-mode uses the refile interface to select an outline path
1881 \(see variable `org-refile-use-outline-path'), the completion of
1882 the path can be done is a single go, or if can be done in steps down
1883 the headline hierarchy. Going in steps is probably the best if you
1884 do not use a special completion package like `ido' or `icicles'.
1885 However, when using these packages, going in one step can be very
1886 fast, while still showing the whole path to the entry."
1890 (defcustom org-refile-allow-creating-parent-nodes nil
1891 "Non-nil means allow to create new nodes as refile targets.
1892 New nodes are then created by adding \"/new node name\" to the completion
1893 of an existing node. When the value of this variable is `confirm',
1894 new node creation must be confirmed by the user (recommended)
1895 When nil, the completion must match an existing entry.
1897 Note that, if the new heading is not seen by the criteria
1898 listed in `org-refile-targets', multiple instances of the same
1899 heading would be created by trying again to file under the new
1903 (const :tag
"Never" nil
)
1904 (const :tag
"Always" t
)
1905 (const :tag
"Prompt for confirmation" confirm
)))
1907 (defgroup org-todo nil
1908 "Options concerning TODO items in Org-mode."
1912 (defgroup org-progress nil
1913 "Options concerning Progress logging in Org-mode."
1917 (defvar org-todo-interpretation-widgets
1919 (:tag
"Sequence (cycling hits every state)" sequence
)
1920 (:tag
"Type (cycling directly to DONE)" type
))
1921 "The available interpretation symbols for customizing `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 active time stamp instead the default inactive 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.
2524 This is also used when 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 "Detect an org-type or table-type table.")
3534 (defconst org-table-line-regexp
"^[ \t]*|"
3535 "Detect an org-type table line.")
3536 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3537 "Detect an org-type table line.")
3538 (defconst org-table-hline-regexp
"^[ \t]*|-"
3539 "Detect an org-type table hline.")
3540 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3541 "Detect a table-type table hline.")
3542 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3543 "Detect the first line outside a table when searching from within it.
3544 This works for both table types.")
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 preceded 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 composition 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 pressing 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 \\[universal-argument] 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
))))
6194 ;;; Folding of blocks
6196 (defconst org-block-regexp
6198 "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
6199 "Regular expression for hiding blocks.")
6201 (defvar org-hide-block-overlays nil
6202 "Overlays hiding blocks.")
6203 (make-variable-buffer-local 'org-hide-block-overlays
)
6205 (defun org-block-map (function &optional start end
)
6206 "Call FUNCTION at the head of all source blocks in the current buffer.
6207 Optional arguments START and END can be used to limit the range."
6208 (let ((start (or start
(point-min)))
6209 (end (or end
(point-max))))
6212 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6215 (goto-char (match-beginning 0))
6216 (funcall function
)))))))
6218 (defun org-hide-block-toggle-all ()
6219 "Toggle the visibility of all blocks in the current buffer."
6220 (org-block-map #'org-hide-block-toggle
))
6222 (defun org-hide-block-all ()
6223 "Fold all blocks in the current buffer."
6225 (org-show-block-all)
6226 (org-block-map #'org-hide-block-toggle-maybe
))
6228 (defun org-show-block-all ()
6229 "Unfold all blocks in the current buffer."
6231 (mapc 'delete-overlay org-hide-block-overlays
)
6232 (setq org-hide-block-overlays nil
))
6234 (defun org-hide-block-toggle-maybe ()
6235 "Toggle visibility of block at point."
6237 (let ((case-fold-search t
))
6239 (beginning-of-line 1)
6240 (looking-at org-block-regexp
))
6241 (progn (org-hide-block-toggle)
6242 t
) ;; to signal that we took action
6243 nil
))) ;; to signal that we did not
6245 (defun org-hide-block-toggle (&optional force
)
6246 "Toggle the visibility of the current block."
6250 (if (re-search-forward org-block-regexp nil t
)
6251 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6252 (end (match-end 0)) ;; end of entire body
6254 (if (memq t
(mapcar (lambda (overlay)
6255 (eq (overlay-get overlay
'invisible
)
6257 (overlays-at start
)))
6258 (if (or (not force
) (eq force
'off
))
6260 (when (member ov org-hide-block-overlays
)
6261 (setq org-hide-block-overlays
6262 (delq ov org-hide-block-overlays
)))
6263 (when (eq (overlay-get ov
'invisible
)
6265 (delete-overlay ov
)))
6266 (overlays-at start
)))
6267 (setq ov
(make-overlay start end
))
6268 (overlay-put ov
'invisible
'org-hide-block
)
6269 ;; make the block accessible to isearch
6271 ov
'isearch-open-invisible
6273 (when (member ov org-hide-block-overlays
)
6274 (setq org-hide-block-overlays
6275 (delq ov org-hide-block-overlays
)))
6276 (when (eq (overlay-get ov
'invisible
)
6278 (delete-overlay ov
))))
6279 (push ov org-hide-block-overlays
)))
6280 (error "Not looking at a source block"))))
6282 ;; org-tab-after-check-for-cycling-hook
6283 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6284 ;; Remove overlays when changing major mode
6285 (add-hook 'org-mode-hook
6286 (lambda () (org-add-hook 'change-major-mode-hook
6287 'org-show-block-all
'append
'local
)))
6291 (defvar org-goto-window-configuration nil
)
6292 (defvar org-goto-marker nil
)
6293 (defvar org-goto-map
6294 (let ((map (make-sparse-keymap)))
6295 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6296 (while (setq cmd
(pop cmds
))
6297 (substitute-key-definition cmd cmd map global-map
)))
6298 (suppress-keymap map
)
6299 (org-defkey map
"\C-m" 'org-goto-ret
)
6300 (org-defkey map
[(return)] 'org-goto-ret
)
6301 (org-defkey map
[(left)] 'org-goto-left
)
6302 (org-defkey map
[(right)] 'org-goto-right
)
6303 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6304 (org-defkey map
"\C-i" 'org-cycle
)
6305 (org-defkey map
[(tab)] 'org-cycle
)
6306 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6307 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6308 (if org-goto-auto-isearch
6309 (if (fboundp 'define-key-after
)
6310 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6312 (org-defkey map "q" 'org-goto-quit)
6313 (org-defkey map "n" 'outline-next-visible-heading)
6314 (org-defkey map "p" 'outline-previous-visible-heading)
6315 (org-defkey map "f" 'outline-forward-same-level)
6316 (org-defkey map "b" 'outline-backward-same-level)
6317 (org-defkey map "u" 'outline-up-heading))
6318 (org-defkey map "/" 'org-occur)
6319 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6320 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6321 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6322 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6323 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6326 (defconst org-goto-help
6327 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6328 RET=jump to location [Q]uit and return to previous location
6329 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6331 (defvar org-goto-start-pos) ; dynamically scoped parameter
6333 ;; FIXME: Docstring does not mention both interfaces
6334 (defun org-goto (&optional alternative-interface)
6335 "Look up a different location in the current file, keeping current visibility.
6337 When you want look-up or go to a different location in a document, the
6338 fastest way is often to fold the entire buffer and then dive into the tree.
6339 This method has the disadvantage, that the previous location will be folded,
6340 which may not be what you want.
6342 This command works around this by showing a copy of the current buffer
6343 in an indirect buffer, in overview mode. You can dive into the tree in
6344 that copy, use org-occur and incremental search to find a location.
6345 When pressing RET or `Q', the command returns to the original buffer in
6346 which the visibility is still unchanged. After RET is will also jump to
6347 the location selected in the indirect buffer and expose the
6348 the headline hierarchy above."
6350 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6351 (org-refile-use-outline-path t)
6352 (org-refile-target-verify-function nil)
6354 (if (not alternative-interface)
6356 (if (eq org-goto-interface 'outline)
6357 'outline-path-completion
6359 (org-goto-start-pos (point))
6361 (if (eq interface 'outline)
6362 (car (org-get-location (current-buffer) org-goto-help))
6363 (nth 3 (org-refile-get-location "Goto: ")))))
6366 (org-mark-ring-push org-goto-start-pos)
6367 (goto-char selected-point)
6368 (if (or (org-invisible-p) (org-invisible-p2))
6369 (org-show-context 'org-goto)))
6372 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6373 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6374 (defvar org-goto-local-auto-isearch-map) ; defined below
6376 (defun org-get-location (buf help)
6377 "Let the user select a location in the Org-mode buffer BUF.
6378 This function uses a recursive edit. It returns the selected position
6380 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6381 (isearch-hide-immediately nil)
6382 (isearch-search-fun-function
6383 (lambda () 'org-goto-local-search-headings))
6384 (org-goto-selected-point org-goto-exit-command)
6386 (special-display-buffer-names nil)
6387 (special-display-regexps nil)
6388 (special-display-function nil))
6390 (save-window-excursion
6391 (delete-other-windows)
6392 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6395 (make-indirect-buffer (current-buffer) "*org-goto*")
6396 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6397 (with-output-to-temp-buffer "*Help*"
6399 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6400 (setq buffer-read-only nil)
6401 (let ((org-startup-truncated t)
6402 (org-startup-folded nil)
6403 (org-startup-align-all-tables nil))
6406 (setq buffer-read-only t)
6407 (if (and (boundp 'org-goto-start-pos)
6408 (integer-or-marker-p org-goto-start-pos))
6409 (let ((org-show-hierarchy-above t)
6410 (org-show-siblings t)
6411 (org-show-following-heading t))
6412 (goto-char org-goto-start-pos)
6413 (and (org-invisible-p) (org-show-context)))
6414 (goto-char (point-min)))
6415 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6416 (message "Select location and press RET")
6417 (use-local-map org-goto-map)
6420 (kill-buffer "*org-goto*")
6421 (cons org-goto-selected-point org-goto-exit-command)))
6423 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6424 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6425 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6426 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6428 (defun org-goto-local-search-headings (string bound noerror)
6429 "Search and make sure that any matches are in headlines."
6431 (while (if isearch-forward
6432 (search-forward string bound noerror)
6433 (search-backward string bound noerror))
6434 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6435 (and (member :headline context)
6436 (not (member :tags context))))
6437 (throw 'return (point))))))
6439 (defun org-goto-local-auto-isearch ()
6442 (goto-char (point-min))
6443 (let ((keys (this-command-keys)))
6444 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6446 (isearch-process-search-char (string-to-char keys)))))
6448 (defun org-goto-ret (&optional arg)
6449 "Finish `org-goto' by going to the new location."
6451 (setq org-goto-selected-point (point)
6452 org-goto-exit-command 'return)
6455 (defun org-goto-left ()
6456 "Finish `org-goto' by going to the new location."
6458 (if (org-on-heading-p)
6460 (beginning-of-line 1)
6461 (setq org-goto-selected-point (point)
6462 org-goto-exit-command 'left)
6464 (error "Not on a heading")))
6466 (defun org-goto-right ()
6467 "Finish `org-goto' by going to the new location."
6469 (if (org-on-heading-p)
6471 (setq org-goto-selected-point (point)
6472 org-goto-exit-command 'right)
6474 (error "Not on a heading")))
6476 (defun org-goto-quit ()
6477 "Finish `org-goto' without cursor motion."
6479 (setq org-goto-selected-point nil)
6480 (setq org-goto-exit-command 'quit)
6483 ;;; Indirect buffer display of subtrees
6485 (defvar org-indirect-dedicated-frame nil
6486 "This is the frame being used for indirect tree display.")
6487 (defvar org-last-indirect-buffer nil)
6489 (defun org-tree-to-indirect-buffer (&optional arg)
6490 "Create indirect buffer and narrow it to current subtree.
6491 With numerical prefix ARG, go up to this level and then take that tree.
6492 If ARG is negative, go up that many levels.
6493 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6494 indirect buffer previously made with this command, to avoid proliferation of
6495 indirect buffers. However, when you call the command with a \
6496 \\[universal-argument] prefix, or
6497 when `org-indirect-buffer-display' is `new-frame', the last buffer
6498 is kept so that you can work with several indirect buffers at the same time.
6499 If `org-indirect-buffer-display' is `dedicated-frame', the \
6500 \\[universal-argument] prefix also
6501 requests that a new frame be made for the new buffer, so that the dedicated
6502 frame is not changed."
6504 (let ((cbuf (current-buffer))
6505 (cwin (selected-window))
6507 beg end level heading ibuf)
6509 (org-back-to-heading t)
6511 (setq level (org-outline-level))
6512 (if (< arg 0) (setq arg (+ level arg)))
6513 (while (> (setq level (org-outline-level)) arg)
6514 (outline-up-heading 1 t)))
6516 heading (org-get-heading))
6517 (org-end-of-subtree t t)
6518 (if (org-on-heading-p) (backward-char 1))
6520 (if (and (buffer-live-p org-last-indirect-buffer)
6521 (not (eq org-indirect-buffer-display 'new-frame))
6523 (kill-buffer org-last-indirect-buffer))
6524 (setq ibuf (org-get-indirect-buffer cbuf)
6525 org-last-indirect-buffer ibuf)
6527 ((or (eq org-indirect-buffer-display 'new-frame)
6528 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
6529 (select-frame (make-frame))
6530 (delete-other-windows)
6531 (switch-to-buffer ibuf)
6532 (org-set-frame-title heading))
6533 ((eq org-indirect-buffer-display 'dedicated-frame)
6535 (select-frame (or (and org-indirect-dedicated-frame
6536 (frame-live-p org-indirect-dedicated-frame)
6537 org-indirect-dedicated-frame)
6538 (setq org-indirect-dedicated-frame (make-frame)))))
6539 (delete-other-windows)
6540 (switch-to-buffer ibuf)
6541 (org-set-frame-title (concat "Indirect: " heading)))
6542 ((eq org-indirect-buffer-display 'current-window)
6543 (switch-to-buffer ibuf))
6544 ((eq org-indirect-buffer-display 'other-window)
6545 (pop-to-buffer ibuf))
6546 (t (error "Invalid value")))
6547 (if (featurep 'xemacs)
6548 (save-excursion (org-mode) (turn-on-font-lock)))
6549 (narrow-to-region beg end)
6552 (and (window-live-p cwin) (select-window cwin))))
6554 (defun org-get-indirect-buffer (&optional buffer)
6555 (setq buffer (or buffer (current-buffer)))
6556 (let ((n 1) (base (buffer-name buffer)) bname)
6557 (while (buffer-live-p
6558 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
6561 (make-indirect-buffer buffer bname 'clone)
6562 (error (make-indirect-buffer buffer bname)))))
6564 (defun org-set-frame-title (title)
6565 "Set the title of the current frame to the string TITLE."
6566 ;; FIXME: how to name a single frame in XEmacs???
6567 (unless (featurep 'xemacs)
6568 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
6570 ;;;; Structure editing
6572 ;;; Inserting headlines
6574 (defun org-previous-line-empty-p ()
6577 (or (beginning-of-line 0) t)
6579 (looking-at "[ \t]*$")))))
6581 (defun org-insert-heading (&optional force-heading invisible-ok)
6582 "Insert a new heading or item with same depth at point.
6583 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
6584 If point is at the beginning of a headline, insert a sibling before the
6585 current headline. If point is not at the beginning, do not split the line,
6586 but create the new headline after the current line.
6587 When INVISIBLE-OK is set, stop at invisible headlines when going back.
6588 This is important for non-interactive uses of the command."
6590 (if (or (= (buffer-size) 0)
6591 (and (not (save-excursion (and (ignore-errors (org-back-to-heading invisible-ok))
6592 (org-on-heading-p))))
6593 (not (org-in-item-p))))
6595 (when (or force-heading (not (org-insert-item)))
6596 (let* ((empty-line-p nil)
6597 (head (save-excursion
6600 (org-back-to-heading invisible-ok)
6601 (setq empty-line-p (org-previous-line-empty-p))
6604 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
6605 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
6606 pos hide-previous previous-pos)
6608 ((and (org-on-heading-p) (bolp)
6610 (save-excursion (backward-char 1) (not (org-invisible-p)))))
6611 ;; insert before the current line
6612 (open-line (if blank 2 1)))
6614 (not org-insert-heading-respect-content)
6617 (backward-char 1) (not (org-invisible-p)))))
6618 ;; insert right here
6621 ;; somewhere in the line
6623 (setq previous-pos (point-at-bol))
6625 (setq hide-previous (org-invisible-p)))
6626 (and org-insert-heading-respect-content (org-show-subtree))
6628 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
6631 (goto-char (point-at-bol))
6632 (and (looking-at org-complex-heading-regexp)
6633 (> p (match-beginning 4)))))))
6636 (org-insert-heading-respect-content
6637 (org-end-of-subtree nil t)
6638 (or (bolp) (newline))
6639 (or (org-previous-line-empty-p)
6640 (and blank (newline)))
6646 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
6647 (setq tags (and (match-end 2) (match-string 2)))
6649 (delete-region (match-beginning 1) (match-end 1)))
6650 (setq pos (point-at-bol))
6651 (or split (end-of-line 1))
6652 (delete-horizontal-space)
6653 (if (string-match "\\`\\*+\\'"
6654 (buffer-substring (point-at-bol) (point)))
6656 (newline (if blank 2 1))
6662 (org-set-tags nil 'align))))
6664 (or split (end-of-line 1))
6665 (newline (if blank 2 1)))))))
6666 (insert head) (just-one-space)
6669 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
6670 (when (and org-insert-heading-respect-content hide-previous)
6672 (goto-char previous-pos)
6674 (run-hooks 'org-insert-heading-hook)))))
6676 (defun org-get-heading (&optional no-tags)
6677 "Return the heading of the current entry, without the stars."
6679 (org-back-to-heading t)
6682 (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
6683 "\\*+[ \t]+\\([^\r\n]*\\)"))
6684 (match-string 1) "")))
6686 (defun org-heading-components ()
6687 "Return the components of the current heading.
6688 This is a list with the following elements:
6689 - the level as an integer
6690 - the reduced level, different if `org-odd-levels-only' is set.
6691 - the TODO keyword, or nil
6692 - the priority character, like ?A, or nil if no priority is given
6693 - the headline text itself, or the tags string if no headline text
6694 - the tags string, or nil."
6696 (org-back-to-heading t)
6697 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
6698 (list (length (match-string 1))
6699 (org-reduced-level (length (match-string 1)))
6700 (org-match-string-no-properties 2)
6701 (and (match-end 3) (aref (match-string 3) 2))
6702 (org-match-string-no-properties 4)
6703 (org-match-string-no-properties 5)))))
6705 (defun org-get-entry ()
6706 "Get the entry text, after heading, entire subtree."
6708 (org-back-to-heading t)
6709 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
6711 (defun org-insert-heading-after-current ()
6712 "Insert a new heading with same level as current, after current subtree."
6714 (org-back-to-heading)
6715 (org-insert-heading)
6716 (org-move-subtree-down)
6719 (defun org-insert-heading-respect-content ()
6721 (let ((org-insert-heading-respect-content t))
6722 (org-insert-heading t)))
6724 (defun org-insert-todo-heading-respect-content (&optional force-state)
6726 (let ((org-insert-heading-respect-content t))
6727 (org-insert-todo-heading force-state t)))
6729 (defun org-insert-todo-heading (arg &optional force-heading)
6730 "Insert a new heading with the same level and TODO state as current heading.
6731 If the heading has no TODO state, or if the state is DONE, use the first
6732 state (TODO by default). Also with prefix arg, force first state."
6734 (when (or force-heading (not (org-insert-item 'checkbox)))
6735 (org-insert-heading force-heading)
6737 (org-back-to-heading)
6738 (outline-previous-heading)
6739 (looking-at org-todo-line-regexp))
6743 (not (match-beginning 2))
6744 (member (match-string 2) org-done-keywords))
6745 (car org-todo-keywords-1)
6749 (run-hook-with-args-until-success
6750 'org-todo-get-default-hook new-mark-x nil)
6752 (beginning-of-line 1)
6753 (and (looking-at "\\*+ ") (goto-char (match-end 0))
6754 (if org-treat-insert-todo-heading-as-state-change
6756 (insert new-mark " "))))
6757 (when org-provide-todo-statistics
6758 (org-update-parent-todo-statistics))))
6760 (defun org-insert-subheading (arg)
6761 "Insert a new subheading and demote it.
6762 Works for outline headings and for plain lists alike."
6764 (org-insert-heading arg)
6766 ((org-on-heading-p) (org-do-demote))
6767 ((org-at-item-p) (org-indent-item 1))))
6769 (defun org-insert-todo-subheading (arg)
6770 "Insert a new subheading with TODO keyword or checkbox and demote it.
6771 Works for outline headings and for plain lists alike."
6773 (org-insert-todo-heading arg)
6775 ((org-on-heading-p) (org-do-demote))
6776 ((org-at-item-p) (org-indent-item 1))))
6778 ;;; Promotion and Demotion
6780 (defvar org-after-demote-entry-hook nil
6781 "Hook run after an entry has been demoted.
6782 The cursor will be at the beginning of the entry.
6783 When a subtree is being demoted, the hook will be called for each node.")
6785 (defvar org-after-promote-entry-hook nil
6786 "Hook run after an entry has been promoted.
6787 The cursor will be at the beginning of the entry.
6788 When a subtree is being promoted, the hook will be called for each node.")
6790 (defun org-promote-subtree ()
6791 "Promote the entire subtree.
6792 See also `org-promote'."
6795 (org-map-tree 'org-promote))
6796 (org-fix-position-after-promote))
6798 (defun org-demote-subtree ()
6799 "Demote the entire subtree. See `org-demote'.
6800 See also `org-promote'."
6803 (org-map-tree 'org-demote))
6804 (org-fix-position-after-promote))
6807 (defun org-do-promote ()
6808 "Promote the current heading higher up the tree.
6809 If the region is active in `transient-mark-mode', promote all headings
6813 (if (org-region-active-p)
6814 (org-map-region 'org-promote (region-beginning) (region-end))
6816 (org-fix-position-after-promote))
6818 (defun org-do-demote ()
6819 "Demote the current heading lower down the tree.
6820 If the region is active in `transient-mark-mode', demote all headings
6824 (if (org-region-active-p)
6825 (org-map-region 'org-demote (region-beginning) (region-end))
6827 (org-fix-position-after-promote))
6829 (defun org-fix-position-after-promote ()
6830 "Make sure that after pro/demotion cursor position is right."
6831 (let ((pos (point)))
6832 (when (save-excursion
6833 (beginning-of-line 1)
6834 (looking-at org-todo-line-regexp)
6835 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
6836 (cond ((eobp) (insert " "))
6837 ((eolp) (insert " "))
6838 ((equal (char-after) ?\ ) (forward-char 1))))))
6840 (defun org-current-level ()
6841 "Return the level of the current entry, or nil if before the first headline.
6842 The level is the number of stars at the beginning of the headline."
6846 (org-back-to-heading t)
6847 (funcall outline-level))
6850 (defun org-get-previous-line-level ()
6851 "Return the outline depth of the last headline before the current line.
6852 Returns 0 for the first headline in the buffer, and nil if before the
6854 (let ((current-level (org-current-level))
6855 (prev-level (when (> (line-number-at-pos) 1)
6857 (beginning-of-line 0)
6858 (org-current-level)))))
6859 (cond ((null current-level) nil) ; Before first headline
6860 ((null prev-level) 0) ; At first headline
6863 (defun org-reduced-level (l)
6864 "Compute the effective level of a heading.
6865 This takes into account the setting of `org-odd-levels-only'."
6866 (if org-odd-levels-only (1+ (floor (/ l 2))) l))
6868 (defun org-level-increment ()
6869 "Return the number of stars that will be added or removed at a
6870 time to headlines when structure editing, based on the value of
6871 `org-odd-levels-only'."
6872 (if org-odd-levels-only 2 1))
6874 (defun org-get-valid-level (level &optional change)
6875 "Rectify a level change under the influence of `org-odd-levels-only'
6876 LEVEL is a current level, CHANGE is by how much the level should be
6877 modified. Even if CHANGE is nil, LEVEL may be returned modified because
6878 even level numbers will become the next higher odd number."
6879 (if org-odd-levels-only
6880 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
6881 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
6882 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
6883 (max 1 (+ level (or change 0)))))
6885 (if (boundp 'define-obsolete-function-alias)
6886 (if (or (featurep 'xemacs) (< emacs-major-version 23))
6887 (define-obsolete-function-alias 'org-get-legal-level
6888 'org-get-valid-level)
6889 (define-obsolete-function-alias 'org-get-legal-level
6890 'org-get-valid-level "23.1")))
6892 (defun org-promote ()
6893 "Promote the current heading higher up the tree.
6894 If the region is active in `transient-mark-mode', promote all headings
6896 (org-back-to-heading t)
6897 (let* ((level (save-match-data (funcall outline-level)))
6898 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
6899 (diff (abs (- level (length up-head) -1))))
6900 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
6901 (replace-match up-head nil t)
6902 ;; Fixup tag positioning
6903 (and org-auto-align-tags (org-set-tags nil t))
6904 (if org-adapt-indentation (org-fixup-indentation (- diff)))
6905 (run-hooks 'org-after-promote-entry-hook)))
6907 (defun org-demote ()
6908 "Demote the current heading lower down the tree.
6909 If the region is active in `transient-mark-mode', demote all headings
6911 (org-back-to-heading t)
6912 (let* ((level (save-match-data (funcall outline-level)))
6913 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
6914 (diff (abs (- level (length down-head) -1))))
6915 (replace-match down-head nil t)
6916 ;; Fixup tag positioning
6917 (and org-auto-align-tags (org-set-tags nil t))
6918 (if org-adapt-indentation (org-fixup-indentation diff))
6919 (run-hooks 'org-after-demote-entry-hook)))
6921 (defun org-cycle-level ()
6922 "Cycle the level of an empty headline through possible states.
6923 This goes first to child, then to parent, level, then up the hierarchy.
6924 After top level, it switches back to sibling level."
6926 (let ((org-adapt-indentation nil))
6927 (when (org-point-at-end-of-empty-headline)
6928 (setq this-command 'org-cycle-level) ; Only needed for caching
6929 (let ((cur-level (org-current-level))
6930 (prev-level (org-get-previous-line-level)))
6932 ;; If first headline in file, promote to top-level.
6934 (loop repeat (/ (- cur-level 1) (org-level-increment))
6935 do (org-do-promote)))
6936 ;; If same level as prev, demote one.
6937 ((= prev-level cur-level)
6939 ;; If parent is top-level, promote to top level if not already.
6941 (loop repeat (/ (- cur-level 1) (org-level-increment))
6942 do (org-do-promote)))
6943 ;; If top-level, return to prev-level.
6945 (loop repeat (/ (- prev-level 1) (org-level-increment))
6946 do (org-do-demote)))
6947 ;; If less than prev-level, promote one.
6948 ((< cur-level prev-level)
6950 ;; If deeper than prev-level, promote until higher than
6952 ((> cur-level prev-level)
6953 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
6954 do (org-do-promote))))
6957 (defun org-map-tree (fun)
6958 "Call FUN for every heading underneath the current one."
6959 (org-back-to-heading)
6960 (let ((level (funcall outline-level)))
6964 (outline-next-heading)
6965 (> (funcall outline-level) level))
6969 (defun org-map-region (fun beg end)
6970 "Call FUN for every heading between BEG and END."
6971 (let ((org-ignore-region t))
6973 (setq end (copy-marker end))
6975 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
6979 (outline-next-heading)
6984 (defun org-fixup-indentation (diff)
6985 "Change the indentation in the current entry by DIFF.
6986 However, if any line in the current entry has no indentation, or if it
6987 would end up with no indentation after the change, nothing at all is done."
6989 (let ((end (save-excursion (outline-next-heading)
6991 (prohibit (if (> diff 0)
6993 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
6995 (unless (save-excursion (end-of-line 1)
6996 (re-search-forward prohibit end t))
6997 (while (and (< (point) end)
6998 (re-search-forward "^[ \t]+" end t))
6999 (goto-char (match-end 0))
7000 (setq col (current-column))
7001 (if (< diff 0) (replace-match ""))
7002 (org-indent-to-column (+ diff col))))
7003 (move-marker end nil))))
7005 (defun org-convert-to-odd-levels ()
7006 "Convert an org-mode file with all levels allowed to one with odd levels.
7007 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7010 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7011 (let ((outline-regexp org-outline-regexp)
7012 (outline-level 'org-outline-level)
7013 (org-odd-levels-only nil) n)
7015 (goto-char (point-min))
7016 (while (re-search-forward "^\\*\\*+ " nil t)
7017 (setq n (- (length (match-string 0)) 2))
7018 (while (>= (setq n (1- n)) 0)
7020 (end-of-line 1))))))
7022 (defun org-convert-to-oddeven-levels ()
7023 "Convert an org-mode file with only odd levels to one with odd/even levels.
7024 This promotes level 3 to level 2, level 5 to level 3 etc. If the
7025 file contains a section with an even level, conversion would
7026 destroy the structure of the file. An error is signaled in this
7029 (goto-char (point-min))
7030 ;; First check if there are no even levels
7031 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7032 (org-show-context t)
7033 (error "Not all levels are odd in this file. Conversion not possible"))
7034 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7035 (let ((outline-regexp org-outline-regexp)
7036 (outline-level 'org-outline-level)
7037 (org-odd-levels-only nil) n)
7039 (goto-char (point-min))
7040 (while (re-search-forward "^\\*\\*+ " nil t)
7041 (setq n (/ (1- (length (match-string 0))) 2))
7042 (while (>= (setq n (1- n)) 0)
7044 (end-of-line 1))))))
7046 (defun org-tr-level (n)
7047 "Make N odd if required."
7048 (if org-odd-levels-only (1+ (/ n 2)) n))
7050 ;;; Vertical tree motion, cutting and pasting of subtrees
7052 (defun org-move-subtree-up (&optional arg)
7053 "Move the current subtree up past ARG headlines of the same level."
7055 (org-move-subtree-down (- (prefix-numeric-value arg))))
7057 (defun org-move-subtree-down (&optional arg)
7058 "Move the current subtree down past ARG headlines of the same level."
7060 (setq arg (prefix-numeric-value arg))
7061 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7062 'org-get-last-sibling))
7063 (ins-point (make-marker))
7065 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7067 (org-back-to-heading)
7070 (setq ne-beg (org-back-over-empty-lines))
7073 (save-excursion (outline-end-of-heading)
7074 (setq folded (org-invisible-p)))
7075 (outline-end-of-subtree))
7076 (outline-next-heading)
7077 (setq ne-end (org-back-over-empty-lines))
7080 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7081 ;; include less whitespace
7084 (forward-line (- ne-beg ne-end))
7085 (setq beg (point))))
7086 ;; Find insertion point, with error handling
7088 (or (and (funcall movfunc) (looking-at outline-regexp))
7089 (progn (goto-char beg0)
7090 (error "Cannot move past superior level or buffer limit")))
7091 (setq cnt (1- cnt)))
7093 ;; Moving forward - still need to move over subtree
7094 (progn (org-end-of-subtree t t)
7096 (org-back-over-empty-lines)
7097 (or (bolp) (newline)))))
7098 (setq ne-ins (org-back-over-empty-lines))
7099 (move-marker ins-point (point))
7100 (setq txt (buffer-substring beg end))
7101 (org-save-markers-in-region beg end)
7102 (delete-region beg end)
7103 (org-remove-empty-overlays-at beg)
7104 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7105 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7106 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7107 (let ((bbb (point)))
7108 (insert-before-markers txt)
7109 (org-reinstall-markers-in-region bbb)
7110 (move-marker ins-point bbb))
7111 (or (bolp) (insert "\n"))
7112 (setq ins-end (point))
7113 (goto-char ins-point)
7114 (org-skip-whitespace)
7115 (when (and (< arg 0)
7116 (org-first-sibling-p)
7118 ;; Move whitespace back to beginning
7121 (let ((kill-whole-line t))
7122 (kill-line (- ne-ins ne-beg)) (point)))
7123 (insert (make-string (- ne-ins ne-beg) ?\n)))
7124 (move-marker ins-point nil)
7129 (org-cycle-hide-drawers 'children))
7130 (org-clean-visibility-after-subtree-move)))
7132 (defvar org-subtree-clip ""
7133 "Clipboard for cut and paste of subtrees.
7134 This is actually only a copy of the kill, because we use the normal kill
7135 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7137 (defvar org-subtree-clip-folded nil
7138 "Was the last copied subtree folded?
7139 This is used to fold the tree back after pasting.")
7141 (defun org-cut-subtree (&optional n)
7142 "Cut the current subtree into the clipboard.
7143 With prefix arg N, cut this many sequential subtrees.
7144 This is a short-hand for marking the subtree and then cutting it."
7146 (org-copy-subtree n 'cut))
7148 (defun org-copy-subtree (&optional n cut force-store-markers)
7149 "Cut the current subtree into the clipboard.
7150 With prefix arg N, cut this many sequential subtrees.
7151 This is a short-hand for marking the subtree and then copying it.
7152 If CUT is non-nil, actually cut the subtree.
7153 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7154 of some markers in the region, even if CUT is non-nil. This is
7155 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7157 (let (beg end folded (beg0 (point)))
7159 (org-back-to-heading nil) ; take what looks like a subtree
7160 (org-back-to-heading t)) ; take what is really there
7161 (org-back-over-empty-lines)
7163 (skip-chars-forward " \t\r\n")
7165 (save-excursion (outline-end-of-heading)
7166 (setq folded (org-invisible-p)))
7168 (org-forward-same-level (1- n) t)
7170 (org-end-of-subtree t t))
7171 (org-back-over-empty-lines)
7175 (setq org-subtree-clip-folded folded)
7176 (when (or cut force-store-markers)
7177 (org-save-markers-in-region beg end))
7178 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7179 (setq org-subtree-clip (current-kill 0))
7180 (message "%s: Subtree(s) with %d characters"
7181 (if cut "Cut" "Copied")
7182 (length org-subtree-clip)))))
7184 (defun org-paste-subtree (&optional level tree for-yank)
7185 "Paste the clipboard as a subtree, with modification of headline level.
7186 The entire subtree is promoted or demoted in order to match a new headline
7189 If the cursor is at the beginning of a headline, the same level as
7190 that headline is used to paste the tree
7192 If not, the new level is derived from the *visible* headings
7193 before and after the insertion point, and taken to be the inferior headline
7194 level of the two. So if the previous visible heading is level 3 and the
7195 next is level 4 (or vice versa), level 4 will be used for insertion.
7196 This makes sure that the subtree remains an independent subtree and does
7197 not swallow low level entries.
7199 You can also force a different level, either by using a numeric prefix
7200 argument, or by inserting the heading marker by hand. For example, if the
7201 cursor is after \"*****\", then the tree will be shifted to level 5.
7203 If optional TREE is given, use this text instead of the kill ring.
7205 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7206 move back over whitespace before inserting, and move point to the end of
7207 the inserted text when done."
7209 (setq tree (or tree (and kill-ring (current-kill 0))))
7210 (unless (org-kill-is-subtree-p tree)
7212 (substitute-command-keys
7213 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7214 (let* ((visp (not (org-invisible-p)))
7216 (^re (concat "^\\(" outline-regexp "\\)"))
7217 (re (concat "\\(" outline-regexp "\\)"))
7218 (^re_ (concat "\\(\\*+\\)[ \t]*"))
7220 (old-level (if (string-match ^re txt)
7221 (- (match-end 0) (match-beginning 0) 1)
7223 (force-level (cond (level (prefix-numeric-value level))
7224 ((and (looking-at "[ \t]*$")
7226 ^re_ (buffer-substring
7227 (point-at-bol) (point))))
7228 (- (match-end 1) (match-beginning 1)))
7230 (looking-at org-outline-regexp))
7231 (- (match-end 0) (point) 1))
7233 (previous-level (save-excursion
7236 (outline-previous-visible-heading 1)
7238 (- (match-end 0) (match-beginning 0) 1)
7241 (next-level (save-excursion
7244 (or (looking-at outline-regexp)
7245 (outline-next-visible-heading 1))
7247 (- (match-end 0) (match-beginning 0) 1)
7250 (new-level (or force-level (max previous-level next-level)))
7251 (shift (if (or (= old-level -1)
7253 (= old-level new-level))
7255 (- new-level old-level)))
7256 (delta (if (> shift 0) -1 1))
7257 (func (if (> shift 0) 'org-demote 'org-promote))
7258 (org-odd-levels-only nil)
7260 ;; Remove the forced level indicator
7262 (delete-region (point-at-bol) (point)))
7264 (beginning-of-line 1)
7265 (unless for-yank (org-back-over-empty-lines))
7267 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7268 (insert-before-markers txt)
7269 (unless (string-match "\n\\'" txt) (insert "\n"))
7270 (setq newend (point))
7271 (org-reinstall-markers-in-region beg)
7274 (skip-chars-forward " \t\n\r")
7276 (if (and (org-invisible-p) visp)
7277 (save-excursion (outline-show-heading)))
7278 ;; Shift if necessary
7281 (narrow-to-region beg end)
7282 (while (not (= shift 0))
7283 (org-map-region func (point-min) (point-max))
7284 (setq shift (+ delta shift)))
7285 (goto-char (point-min))
7286 (setq newend (point-max))))
7287 (when (or (interactive-p) for-yank)
7288 (message "Clipboard pasted as level %d subtree" new-level))
7289 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7291 (eq org-subtree-clip (current-kill 0))
7292 org-subtree-clip-folded)
7293 ;; The tree was folded before it was killed/copied
7295 (and for-yank (goto-char newend))))
7297 (defun org-kill-is-subtree-p (&optional txt)
7298 "Check if the current kill is an outline subtree, or a set of trees.
7299 Returns nil if kill does not start with a headline, or if the first
7300 headline level is not the largest headline level in the tree.
7301 So this will actually accept several entries of equal levels as well,
7302 which is OK for `org-paste-subtree'.
7303 If optional TXT is given, check this string instead of the current kill."
7304 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7305 (start-level (and kill
7306 (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
7307 org-outline-regexp "\\)")
7309 (- (match-end 2) (match-beginning 2) 1)))
7310 (re (concat "^" org-outline-regexp))
7311 (start (1+ (or (match-beginning 2) -1))))
7312 (if (not start-level)
7314 nil) ;; does not even start with a heading
7316 (while (setq start (string-match re kill (1+ start)))
7317 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7321 (defvar org-markers-to-move nil
7322 "Markers that should be moved with a cut-and-paste operation.
7323 Those markers are stored together with their positions relative to
7324 the start of the region.")
7326 (defun org-save-markers-in-region (beg end)
7327 "Check markers in region.
7328 If these markers are between BEG and END, record their position relative
7329 to BEG, so that after moving the block of text, we can put the markers back
7331 This function gets called just before an entry or tree gets cut from the
7332 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7333 called immediately, to move the markers with the entries."
7334 (setq org-markers-to-move nil)
7335 (when (featurep 'org-clock)
7336 (org-clock-save-markers-for-cut-and-paste beg end))
7337 (when (featurep 'org-agenda)
7338 (org-agenda-save-markers-for-cut-and-paste beg end)))
7340 (defun org-check-and-save-marker (marker beg end)
7341 "Check if MARKER is between BEG and END.
7342 If yes, remember the marker and the distance to BEG."
7343 (when (and (marker-buffer marker)
7344 (equal (marker-buffer marker) (current-buffer)))
7345 (if (and (>= marker beg) (< marker end))
7346 (push (cons marker (- marker beg)) org-markers-to-move))))
7348 (defun org-reinstall-markers-in-region (beg)
7349 "Move all remembered markers to their position relative to BEG."
7351 (move-marker (car x) (+ beg (cdr x))))
7352 org-markers-to-move)
7353 (setq org-markers-to-move nil))
7355 (defun org-narrow-to-subtree ()
7356 "Narrow buffer to the current subtree."
7361 (progn (org-back-to-heading t) (point))
7362 (progn (org-end-of-subtree t t)
7363 (if (org-on-heading-p) (backward-char 1))
7367 (defvar org-property-drawer-re))
7369 (defun org-clone-subtree-with-time-shift (n &optional shift)
7370 "Clone the task (subtree) at point N times.
7371 The clones will be inserted as siblings.
7373 In interactive use, the user will be prompted for the number of
7374 clones to be produced, and for a time SHIFT, which may be a
7375 repeater as used in time stamps, for example `+3d'.
7377 When a valid repeater is given and the entry contains any time
7378 stamps, the clones will become a sequence in time, with time
7379 stamps in the subtree shifted for each clone produced. If SHIFT
7380 is nil or the empty string, time stamps will be left alone. The
7381 ID property of the original subtree is removed.
7383 If the original subtree did contain time stamps with a repeater,
7384 the following will happen:
7385 - the repeater will be removed in each clone
7386 - an additional clone will be produced, with the current, unshifted
7387 date(s) in the entry.
7388 - the original entry will be placed *after* all the clones, with
7390 - the start days in the repeater in the original entry will be shifted
7391 to past the last clone.
7392 I this way you can spell out a number of instances of a repeating task,
7393 and still retain the repeater to cover future instances of the task."
7394 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7395 (let (beg end template task idprop
7396 shift-n shift-what doshift nmin nmax (n-no-remove -1))
7397 (if (not (and (integerp n) (> n 0)))
7398 (error "Invalid number of replications %s" n))
7399 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7400 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7402 (error "Invalid shift specification %s" shift))
7404 (setq shift-n (string-to-number (match-string 1 shift))
7405 shift-what (cdr (assoc (match-string 2 shift)
7406 '(("d" . day) ("w" . week)
7407 ("m" . month) ("y" . year))))))
7408 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7409 (setq nmin 1 nmax n)
7410 (org-back-to-heading t)
7412 (setq idprop (org-entry-get nil "ID"))
7413 (org-end-of-subtree t t)
7414 (or (bolp) (insert "\n"))
7416 (setq template (buffer-substring beg end))
7418 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7419 (delete-region beg end)
7421 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7423 (loop for n from nmin to nmax do
7428 (goto-char (point-min))
7429 (and idprop (if org-clone-delete-id
7430 (org-entry-delete nil "ID")
7431 (org-id-get-create t)))
7432 (while (re-search-forward org-property-drawer-re nil t)
7433 (org-remove-empty-drawer-at "PROPERTIES" (point)))
7434 (goto-char (point-min))
7436 (while (re-search-forward org-ts-regexp-both nil t)
7437 (org-timestamp-change (* n shift-n) shift-what))
7438 (unless (= n n-no-remove)
7439 (goto-char (point-min))
7440 (while (re-search-forward org-ts-regexp nil t)
7442 (goto-char (match-beginning 0))
7443 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
7444 (delete-region (match-beginning 1) (match-end 1)))))))
7445 (setq task (buffer-string)))
7451 (defun org-sort (with-case)
7452 "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
7453 Optional argument WITH-CASE means sort case-sensitively.
7454 With a double prefix argument, also remove duplicate entries."
7456 (if (org-at-table-p)
7457 (org-call-with-arg 'org-table-sort-lines with-case)
7458 (org-call-with-arg 'org-sort-entries-or-items with-case)))
7460 (defun org-sort-remove-invisible (s)
7461 (remove-text-properties 0 (length s) org-rm-props s)
7462 (while (string-match org-bracket-link-regexp s)
7463 (setq s (replace-match (if (match-end 2)
7465 (match-string 1 s)) t t s)))
7468 (defvar org-priority-regexp) ; defined later in the file
7470 (defvar org-after-sorting-entries-or-items-hook nil
7471 "Hook that is run after a bunch of entries or items have been sorted.
7472 When children are sorted, the cursor is in the parent line when this
7473 hook gets called. When a region or a plain list is sorted, the cursor
7474 will be in the first entry of the sorted region/list.")
7476 (defun org-sort-entries-or-items
7477 (&optional with-case sorting-type getkey-func compare-func property)
7478 "Sort entries on a certain level of an outline tree, or plain list items.
7479 If there is an active region, the entries in the region are sorted.
7480 Else, if the cursor is before the first entry, sort the top-level items.
7481 Else, the children of the entry at point are sorted.
7482 If the cursor is at the first item in a plain list, the list items will be
7485 Sorting can be alphabetically, numerically, by date/time as given by
7486 a time stamp, by a property or by priority.
7488 The command prompts for the sorting type unless it has been given to the
7489 function through the SORTING-TYPE argument, which needs to be a character,
7490 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
7491 precise meaning of each character:
7493 n Numerically, by converting the beginning of the entry/item to a number.
7494 a Alphabetically, ignoring the TODO keyword and the priority, if any.
7495 t By date/time, either the first active time stamp in the entry, or, if
7496 none exist, by the first inactive one.
7497 In items, only the first line will be checked.
7498 s By the scheduled date/time.
7499 d By deadline date/time.
7500 c By creation time, which is assumed to be the first inactive time stamp
7501 at the beginning of a line.
7502 p By priority according to the cookie.
7503 r By the value of a property.
7505 Capital letters will reverse the sort order.
7507 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
7508 called with point at the beginning of the record. It must return either
7509 a string or a number that should serve as the sorting key for that record.
7511 Comparing entries ignores case by default. However, with an optional argument
7512 WITH-CASE, the sorting considers case as well."
7514 (let ((case-func (if with-case 'identity 'downcase))
7515 start beg end stars re re2
7516 txt what tmp plain-list-p)
7517 ;; Find beginning and end of region to sort
7519 ((org-region-active-p)
7520 ;; we will sort the region
7521 (setq end (region-end)
7523 (goto-char (region-beginning))
7524 (if (not (org-on-heading-p)) (outline-next-heading))
7525 (setq start (point)))
7527 ;; we will sort this plain list
7528 (org-beginning-of-item-list) (setq start (point))
7529 (org-end-of-item-list)
7530 (or (bolp) (insert "\n"))
7533 (setq plain-list-p t
7535 ((or (org-on-heading-p)
7536 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
7537 ;; we will sort the children of the current headline
7538 (org-back-to-heading)
7540 end (progn (org-end-of-subtree t t)
7541 (or (bolp) (insert "\n"))
7542 (org-back-over-empty-lines)
7547 (outline-next-heading))
7549 ;; we will sort the top-level entries in this file
7550 (goto-char (point-min))
7551 (or (org-on-heading-p) (outline-next-heading))
7552 (setq start (point))
7553 (goto-char (point-max))
7554 (beginning-of-line 1)
7555 (when (looking-at ".*?\\S-")
7556 ;; File ends in a non-white line
7559 (setq end (point-max))
7560 (setq what "top-level")
7565 (if (>= beg end) (error "Nothing to sort"))
7567 (unless plain-list-p
7568 (looking-at "\\(\\*+\\)")
7569 (setq stars (match-string 1)
7570 re (concat "^" (regexp-quote stars) " +")
7571 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
7572 txt (buffer-substring beg end))
7573 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
7574 (if (and (not (equal stars "*")) (string-match re2 txt))
7575 (error "Region to sort contains a level above the first entry")))
7577 (unless sorting-type
7580 "Sort %s: [a]lpha [n]umeric [t]ime
[f]unc A/N/T/F means reversed:"
7581 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
7582 [t]ime [s]cheduled [d]eadline [c]reated
7583 A/N/T/S/D/C/P/O/F means reversed:")
7585 (setq sorting-type (read-char-exclusive))
7587 (and (= (downcase sorting-type) ?f)
7589 (org-icompleting-read "Sort using function: "
7590 obarray 'fboundp t nil nil))
7591 (setq getkey-func (intern getkey-func)))
7593 (and (= (downcase sorting-type) ?r)
7595 (org-icompleting-read "Property: "
7596 (mapcar 'list (org-buffer-property-keys t))
7599 (message "Sorting entries...")
7602 (narrow-to-region start end)
7604 (let ((dcst (downcase sorting-type))
7605 (case-fold-search nil)
7606 (now (current-time)))
7608 (/= dcst sorting-type)
7609 ;; This function moves to the beginning character of the "record" to
7613 (if (org-at-item-p) t (goto-char (point-max))))
7615 (if (re-search-forward re nil t)
7616 (goto-char (match-beginning 0))
7617 (goto-char (point-max)))))
7618 ;; This function moves to the last character of the "record" being
7625 (outline-forward-same-level 1)
7627 (goto-char (point-max)))))))
7629 ;; This function returns the value that gets sorted against.
7632 (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
7635 (string-to-number (buffer-substring (match-end 0)
7638 (buffer-substring (match-end 0) (point-at-eol)))
7640 (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
7641 (re-search-forward org-ts-regexp-both
7643 (org-time-string-to-seconds (match-string 0))
7644 (org-float-time now)))
7648 (setq tmp (funcall getkey-func))
7649 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7651 (error "Invalid key function `%s'" getkey-func)))
7652 (t (error "Invalid sorting type `%c'" sorting-type)))))
7656 (if (looking-at org-complex-heading-regexp)
7657 (string-to-number (match-string 4))
7660 (if (looking-at org-complex-heading-regexp)
7661 (funcall case-func (match-string 4))
7664 (let ((end (save-excursion (outline-next-heading) (point))))
7665 (if (or (re-search-forward org-ts-regexp end t)
7666 (re-search-forward org-ts-regexp-both end t))
7667 (org-time-string-to-seconds (match-string 0))
7668 (org-float-time now))))
7670 (let ((end (save-excursion (outline-next-heading) (point))))
7671 (if (re-search-forward
7672 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
7674 (org-time-string-to-seconds (match-string 0))
7675 (org-float-time now))))
7677 (let ((end (save-excursion (outline-next-heading) (point))))
7678 (if (re-search-forward org-scheduled-time-regexp end t)
7679 (org-time-string-to-seconds (match-string 1))
7680 (org-float-time now))))
7682 (let ((end (save-excursion (outline-next-heading) (point))))
7683 (if (re-search-forward org-deadline-time-regexp end t)
7684 (org-time-string-to-seconds (match-string 1))
7685 (org-float-time now))))
7687 (if (re-search-forward org-priority-regexp (point-at-eol) t)
7688 (string-to-char (match-string 2))
7689 org-default-priority))
7691 (or (org-entry-get nil property) ""))
7693 (if (looking-at org-complex-heading-regexp)
7694 (- 9999 (length (member (match-string 2)
7695 org-todo-keywords-1)))))
7699 (setq tmp (funcall getkey-func))
7700 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
7702 (error "Invalid key function `%s'" getkey-func)))
7703 (t (error "Invalid sorting type `%c'" sorting-type)))))
7706 ((= dcst ?a) 'string<)
7707 ((= dcst ?f) compare-func)
7708 ((member dcst '(?p ?t ?s ?d ?c)) '<)
7710 (run-hooks 'org-after-sorting-entries-or-items-hook)
7711 (message "Sorting entries...done")))
7713 (defun org-do-sort (table what &optional with-case sorting-type)
7714 "Sort TABLE of WHAT according to SORTING-TYPE.
7715 The user will be prompted for the SORTING-TYPE if the call to this
7716 function does not specify it. WHAT is only for the prompt, to indicate
7717 what is being sorted. The sorting key will be extracted from
7718 the car of the elements of the table.
7719 If WITH-CASE is non-nil, the sorting will be case-sensitive."
7720 (unless sorting-type
7722 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A
/N
/T means reversed
:"
7724 (setq sorting-type (read-char-exclusive)))
7725 (let ((dcst (downcase sorting-type))
7726 extractfun comparefun)
7727 ;; Define the appropriate functions
7730 (setq extractfun 'string-to-number
7731 comparefun (if (= dcst sorting-type) '< '>)))
7733 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
7734 (lambda(x) (downcase (org-sort-remove-invisible x))))
7735 comparefun (if (= dcst sorting-type)
7737 (lambda (a b) (and (not (string< a b))
7738 (not (string= a b)))))))
7742 (if (or (string-match org-ts-regexp x)
7743 (string-match org-ts-regexp-both x))
7745 (org-time-string-to-time (match-string 0 x)))
7747 comparefun (if (= dcst sorting-type) '< '>)))
7748 (t (error "Invalid sorting type
`%c
'" sorting-type)))
7750 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
7752 (lambda (a b) (funcall comparefun (car a) (car b))))))
7755 ;;; The orgstruct minor mode
7757 ;; Define a minor mode which can be used in other modes in order to
7758 ;; integrate the org-mode structure editing commands.
7760 ;; This is really a hack, because the org-mode structure commands use
7761 ;; keys which normally belong to the major mode. Here is how it
7762 ;; works: The minor mode defines all the keys necessary to operate the
7763 ;; structure commands, but wraps the commands into a function which
7764 ;; tests if the cursor is currently at a headline or a plain list
7765 ;; item. If that is the case, the structure command is used,
7766 ;; temporarily setting many Org-mode variables like regular
7767 ;; expressions for filling etc. However, when any of those keys is
7768 ;; used at a different location, function uses `key-binding' to look
7769 ;; up if the key has an associated command in another currently active
7770 ;; keymap (minor modes, major mode, global), and executes that
7771 ;; command. There might be problems if any of the keys is otherwise
7772 ;; used as a prefix key.
7774 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
7775 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
7776 ;; addresses this by checking explicitly for both bindings.
7778 (defvar orgstruct-mode-map (make-sparse-keymap)
7779 "Keymap for the minor
`orgstruct-mode
'.
")
7781 (defvar org-local-vars nil
7782 "List of local variables
, for use by
`orgstruct-mode
'.
")
7785 (define-minor-mode orgstruct-mode
7786 "Toggle the minor mode
`orgstruct-mode
'.
7787 This mode is for using Org-mode structure commands in other
7788 modes. The following keys behave as if Org-mode were active
, if
7789 the cursor is on a headline
, or on a plain list item
(both as
7790 defined by Org-mode
).
7792 M-up Move entry
/item up
7793 M-down Move entry
/item down
7796 M-S-up Move entry
/item up
7797 M-S-down Move entry
/item down
7798 M-S-left Promote subtree
7799 M-S-right Demote subtree
7800 M-q Fill paragraph and items like in Org-mode
7802 C-c - Cycle list bullet
7803 TAB Cycle item visibility
7804 M-RET Insert new heading
/item
7805 S-M-RET Insert new TODO heading
/ Checkbox item
7806 C-c C-c Set tags
/ toggle checkbox
"
7807 nil " OrgStruct
" nil
7808 (org-load-modules-maybe)
7809 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
7812 (defun turn-on-orgstruct ()
7813 "Unconditionally turn on
`orgstruct-mode
'.
"
7816 (defun orgstruct++-mode (&optional arg)
7817 "Toggle
`orgstruct-mode
', the enhanced version of it.
7818 In addition to setting orgstruct-mode
, this also exports all indentation
7819 and autofilling variables from org-mode into the buffer. It will also
7820 recognize item context in multiline items.
7821 Note that turning off orgstruct-mode will
*not
* remove the
7822 indentation
/paragraph settings. This can only be done by refreshing the
7823 major mode
, for example with
\\[normal-mode
].
"
7825 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
7833 "^
\\(paragraph-\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7834 (symbol-name (car x)))
7835 (setq var (car x) val (nth 1 x))
7836 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
7838 (org-set-local 'orgstruct-is-++ t))))
7840 (defvar orgstruct-is-++ nil
7841 "Is
`orgstruct-mode
' in
++ version in the current-buffer?
")
7842 (make-variable-buffer-local 'orgstruct-is-++)
7845 (defun turn-on-orgstruct++ ()
7846 "Unconditionally turn on
`orgstruct
++-mode
'.
"
7847 (orgstruct++-mode 1))
7849 (defun orgstruct-error ()
7850 "Error when there is no default binding for a structure key.
"
7852 (error "This key has no function outside structure elements
"))
7854 (defun orgstruct-setup ()
7855 "Setup orgstruct keymaps.
"
7859 '([(meta up)] org-metaup)
7860 '([(meta down)] org-metadown)
7861 '([(meta left)] org-metaleft)
7862 '([(meta right)] org-metaright)
7863 '([(meta shift up)] org-shiftmetaup)
7864 '([(meta shift down)] org-shiftmetadown)
7865 '([(meta shift left)] org-shiftmetaleft)
7866 '([(meta shift right)] org-shiftmetaright)
7867 '([?\e (up)] org-metaup)
7868 '([?\e (down)] org-metadown)
7869 '([?\e (left)] org-metaleft)
7870 '([?\e (right)] org-metaright)
7871 '([?\e (shift up)] org-shiftmetaup)
7872 '([?\e (shift down)] org-shiftmetadown)
7873 '([?\e (shift left)] org-shiftmetaleft)
7874 '([?\e (shift right)] org-shiftmetaright)
7875 '([(shift up)] org-shiftup)
7876 '([(shift down)] org-shiftdown)
7877 '([(shift left)] org-shiftleft)
7878 '([(shift right)] org-shiftright)
7879 '("\C-c\C-c
" org-ctrl-c-ctrl-c)
7880 '("\M-q
" fill-paragraph)
7882 '("\C-c-
" org-cycle-list-bullet)))
7884 (while (setq elt (pop bindings))
7885 (setq nfunc (1+ nfunc))
7886 (setq key (org-key (car elt))
7888 cmd (orgstruct-make-binding fun nfunc key))
7889 (org-defkey orgstruct-mode-map key cmd))
7891 ;; Special treatment needed for TAB and RET
7892 (org-defkey orgstruct-mode-map [(tab)]
7893 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i
"))
7894 (org-defkey orgstruct-mode-map "\C-i
"
7895 (orgstruct-make-binding 'org-cycle 103 "\C-i
" [(tab)]))
7897 (org-defkey orgstruct-mode-map "\M-\C-m
"
7898 (orgstruct-make-binding 'org-insert-heading 105
7899 "\M-\C-m
" [(meta return)]))
7900 (org-defkey orgstruct-mode-map [(meta return)]
7901 (orgstruct-make-binding 'org-insert-heading 106
7902 [(meta return)] "\M-\C-m
"))
7904 (org-defkey orgstruct-mode-map [(shift meta return)]
7905 (orgstruct-make-binding 'org-insert-todo-heading 107
7906 [(meta return)] "\M-\C-m
"))
7908 (org-defkey orgstruct-mode-map "\e\C-m
"
7909 (orgstruct-make-binding 'org-insert-heading 108
7910 "\e\C-m
" [?\e (return)]))
7911 (org-defkey orgstruct-mode-map [?\e (return)]
7912 (orgstruct-make-binding 'org-insert-heading 109
7913 [?\e (return)] "\e\C-m
"))
7914 (org-defkey orgstruct-mode-map [?\e (shift return)]
7915 (orgstruct-make-binding 'org-insert-todo-heading 110
7916 [?\e (return)] "\e\C-m
"))
7918 (unless org-local-vars
7919 (setq org-local-vars (org-get-local-variables)))
7923 (defun orgstruct-make-binding (fun n &rest keys)
7924 "Create a function for binding in the structure minor mode.
7925 FUN is the command to call inside a table. N is used to create a unique
7926 command name. KEYS are keys that should be checked in for a command
7927 to execute outside of tables.
"
7930 (intern (concat "orgstruct-hijacker-command-
" (int-to-string n)))
7932 (concat "In Structure
, run
`" (symbol-name fun) "'.
\n"
7933 "Outside of structure
, run the binding of
`"
7934 (mapconcat (lambda (x) (format "%s
" x)) keys "' or
`")
7938 `(org-context-p 'headline 'item
7939 (and orgstruct-is-++
7940 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
7942 (list 'org-run-like-in-org-mode (list 'quote fun))
7943 (list 'let '(orgstruct-mode)
7944 (list 'call-interactively
7947 (list 'key-binding k))
7949 '('orgstruct-error))))))))
7951 (defun org-context-p (&rest contexts)
7952 "Check if local context is any of CONTEXTS.
7953 Possible values in the list of contexts are
`table
', `headline
', and
`item
'.
"
7954 (let ((pos (point)))
7955 (goto-char (point-at-bol))
7956 (prog1 (or (and (memq 'table contexts)
7957 (looking-at "[ \t]*|
"))
7958 (and (memq 'headline contexts)
7959 ;;????????? (looking-at "\\*+"))
7960 (looking-at outline-regexp))
7961 (and (memq 'item contexts)
7962 (looking-at "[ \t]*\\([-
+*] \\|
[0-
9]+[.
)] \\)"))
7963 (and (memq 'item-body contexts)
7967 (defun org-get-local-variables ()
7968 "Return a list of all local variables in an org-mode buffer.
"
7970 (with-current-buffer (get-buffer-create "*Org tmp
*")
7973 (setq varlist (buffer-local-variables)))
7974 (kill-buffer "*Org tmp
*")
7981 (list (car x) (list 'quote (cdr x)))))
7983 "^
\\(org-\\|orgtbl-
\\|outline-
\\|comment-
\\|paragraph-
\\|auto-fill
\\|fill-paragraph
\\|adaptive-fill
\\|indent-
\\)"
7984 (symbol-name (car x)))
7989 (defun org-run-like-in-org-mode (cmd)
7990 "Run a command
, pretending that the current buffer is in Org-mode.
7991 This will temporarily bind local variables that are typically bound in
7992 Org-mode to the values they have in Org-mode
, and then interactively
7994 (org-load-modules-maybe)
7995 (unless org-local-vars
7996 (setq org-local-vars (org-get-local-variables)))
7997 (eval (list 'let org-local-vars
7998 (list 'call-interactively (list 'quote cmd)))))
8002 (defun org-get-category (&optional pos)
8003 "Get the category applying to position POS.
"
8004 (get-text-property (or pos (point)) 'org-category))
8006 (defun org-refresh-category-properties ()
8007 "Refresh category text properties in the buffer.
"
8008 (let ((def-cat (cond
8009 ((null org-category)
8010 (if buffer-file-name
8011 (file-name-sans-extension
8012 (file-name-nondirectory buffer-file-name))
8014 ((symbolp org-category) (symbol-name org-category))
8016 beg end cat pos optionp)
8021 (goto-char (point-min))
8022 (put-text-property (point) (point-max) 'org-category def-cat)
8023 (while (re-search-forward
8024 "^
\\(#\\+CATEGORY
:\\|
[ \t]*:CATEGORY
:\\)\\(.
*\\)" nil t)
8025 (setq pos (match-end 0)
8026 optionp (equal (char-after (match-beginning 0)) ?#)
8027 cat (org-trim (match-string 2)))
8029 (setq beg (point-at-bol) end (point-max))
8030 (org-back-to-heading t)
8031 (setq beg (point) end (org-end-of-subtree t t)))
8032 (put-text-property beg end 'org-category cat)
8033 (goto-char pos)))))))
8038 ;;; Link abbreviations
8040 (defun org-link-expand-abbrev (link)
8041 "Apply replacements as defined in
`org-link-abbrev-alist.
"
8042 (if (string-match "^
\\([a-zA-Z
][-_a-zA-Z0-9
]*\\)\\(::?
\\(.
*\\)\\)?$
" link)
8043 (let* ((key (match-string 1 link))
8044 (as (or (assoc key org-link-abbrev-alist-local)
8045 (assoc key org-link-abbrev-alist)))
8046 (tag (and (match-end 2) (match-string 3 link)))
8052 ((symbolp rpl) (funcall rpl tag))
8053 ((string-match "%s
" rpl) (replace-match (or tag "") t t rpl))
8054 ((string-match "%h
" rpl)
8055 (replace-match (url-hexify-string (or tag "")) t t rpl))
8056 (t (concat rpl tag)))))
8059 ;;; Storing and inserting links
8061 (defvar org-insert-link-history nil
8062 "Minibuffer history for links inserted with
`org-insert-link
'.
")
8064 (defvar org-stored-links nil
8065 "Contains the links stored with
`org-store-link
'.
")
8067 (defvar org-store-link-plist nil
8068 "Plist with info about the most recently link created with
`org-store-link
'.
")
8070 (defvar org-link-protocols nil
8071 "Link protocols added to Org-mode using
`org-add-link-type
'.
")
8073 (defvar org-store-link-functions nil
8074 "List of functions that are called to create and store a link.
8075 Each function will be called in turn until one returns a non-nil
8076 value. Each function should check if it is responsible for creating
8077 this link
(for example by looking at the major mode
).
8078 If not
, it must exit and return nil.
8079 If yes
, it should return a non-nil value after a calling
8080 `org-store-link-props
' with a list of properties and values.
8081 Special properties are
:
8083 :type The link prefix
, like
\"http
\". This must be given.
8084 :link The link
, like
\"http
://www.astro.uva.nl
/~dominik
\".
8085 This is obligatory as well.
8086 :description Optional default description for the second pair
8087 of brackets in an Org-mode link. The user can still change
8088 this when inserting this link into an Org-mode buffer.
8090 In addition to these
, any additional properties can be specified
8091 and then used in remember templates.
")
8093 (defun org-add-link-type (type &optional follow export)
8094 "Add TYPE to the list of
`org-link-types
'.
8095 Re-compute all regular expressions depending on
`org-link-types
'
8097 FOLLOW and EXPORT are two functions.
8099 FOLLOW should take the link path as the single argument and do whatever
8100 is necessary to follow the link
, for example find a file or display
8103 EXPORT should format the link path for export to one of the export formats.
8104 It should be a function accepting three arguments
:
8106 path the path of the link
, the text after the prefix
(like \"http
:\")
8107 desc the description of the link
, if any
, nil if there was no description
8108 format the export format
, a symbol like
`html
' or
`latex
'.
8110 The function may use the FORMAT information to return different values
8111 depending on the format. The return value will be put literally into
8113 Org-mode has a built-in default for exporting links. If you are happy with
8114 this default
, there is no need to define an export function for the link
8115 type. For a simple example of an export function
, see
`org-bbdb.el
'.
"
8116 (add-to-list 'org-link-types type t)
8117 (org-make-link-regexps)
8118 (if (assoc type org-link-protocols)
8119 (setcdr (assoc type org-link-protocols) (list follow export))
8120 (push (list type follow export) org-link-protocols)))
8122 (defvar org-agenda-buffer-name)
8125 (defun org-store-link (arg)
8126 "\\<org-mode-map
>Store an org-link to the current location.
8127 This link is added to
`org-stored-links
' and can later be inserted
8128 into an org-buffer with
\\[org-insert-link
].
8130 For some link types
, a prefix arg is interpreted
:
8131 For links to usenet articles
, arg negates
`org-gnus-prefer-web-links
'.
8132 For file links
, arg negates
`org-context-in-file-links
'.
"
8134 (org-load-modules-maybe)
8135 (setq org-store-link-plist nil) ; reset
8136 (let ((outline-regexp (org-get-limited-outline-regexp))
8137 link cpltxt desc description search txt custom-id)
8140 ((run-hook-with-args-until-success 'org-store-link-functions)
8141 (setq link (plist-get org-store-link-plist :link)
8142 desc (or (plist-get org-store-link-plist :description) link)))
8144 ((equal (buffer-name) "*Org Edit Src Example
*")
8146 (while (or (not label)
8150 (goto-char (point-min))
8152 (regexp-quote (format org-coderef-label-format label))
8154 (when label (message "Label exists already
") (sit-for 2))
8155 (setq label (read-string "Code line label
: " label)))
8157 (setq link (format org-coderef-label-format label))
8158 (setq gc (- 79 (length link)))
8159 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8161 (setq link (concat "(" label ")") desc nil)))
8163 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8164 ;; We are in the agenda, link to referenced location
8165 (let ((m (or (get-text-property (point) 'org-hd-marker)
8166 (get-text-property (point) 'org-marker))))
8168 (org-with-point-at m
8170 (call-interactively 'org-store-link)
8171 (org-store-link nil))))))
8173 ((eq major-mode 'calendar-mode)
8174 (let ((cd (calendar-cursor-to-date)))
8177 (car org-time-stamp-formats)
8179 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8181 (org-store-link-props :type "calendar
" :date cd)))
8183 ((eq major-mode 'w3-mode)
8184 (setq cpltxt (if (and (buffer-name)
8185 (not (string-match "Untitled
" (buffer-name))))
8188 link (org-make-link (url-view-url t)))
8189 (org-store-link-props :type "w3
" :url (url-view-url t)))
8191 ((eq major-mode 'w3m-mode)
8192 (setq cpltxt (or w3m-current-title w3m-current-url)
8193 link (org-make-link w3m-current-url))
8194 (org-store-link-props :type "w3m
" :url (url-view-url t)))
8196 ((setq search (run-hook-with-args-until-success
8197 'org-create-file-search-functions))
8198 (setq link (concat "file
:" (abbreviate-file-name buffer-file-name)
8200 (setq cpltxt (or description link)))
8202 ((eq major-mode 'image-mode)
8203 (setq cpltxt (concat "file
:"
8204 (abbreviate-file-name buffer-file-name))
8205 link (org-make-link cpltxt))
8206 (org-store-link-props :type "image
" :file buffer-file-name))
8208 ((eq major-mode 'dired-mode)
8209 ;; link to the file in the current line
8210 (let ((file (dired-get-filename nil t)))
8212 (abbreviate-file-name
8213 (expand-file-name (dired-get-filename nil t)))
8214 ;; otherwise, no file so use current directory.
8216 (setq cpltxt (concat "file
:" file)
8217 link (org-make-link cpltxt))))
8219 ((and buffer-file-name (org-mode-p))
8220 (setq custom-id (ignore-errors (org-entry-get nil "CUSTOM_ID
")))
8222 ((org-in-regexp "<<\\(.
*?
\\)>>")
8225 (abbreviate-file-name buffer-file-name)
8226 "::" (match-string 1))
8227 link (org-make-link cpltxt)))
8228 ((and (featurep 'org-id)
8229 (or (eq org-link-to-org-use-id t)
8230 (and (eq org-link-to-org-use-id 'create-if-interactive)
8232 (and (eq org-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
8235 (and org-link-to-org-use-id
8237 (org-entry-get nil "ID
")
8239 ;; We can make a link using the ID.
8240 (setq link (condition-case nil
8241 (prog1 (org-id-store-link)
8242 (setq desc (plist-get org-store-link-plist
8245 ;; probably before first headline, link to file only
8247 (abbreviate-file-name buffer-file-name))))))
8249 ;; Just link to current headline
8250 (setq cpltxt (concat "file
:"
8251 (abbreviate-file-name buffer-file-name)))
8252 ;; Add a context search string
8253 (when (org-xor org-context-in-file-links arg)
8255 ((org-on-heading-p) nil)
8256 ((org-region-active-p)
8257 (buffer-substring (region-beginning) (region-end)))
8259 (when (or (null txt) (string-match "\\S-
" txt))
8263 (org-make-org-heading-search-string txt)
8265 desc (or (nth 4 (ignore-errors
8266 (org-heading-components))) "NONE
"))))
8267 (if (string-match "::\\'" cpltxt)
8268 (setq cpltxt (substring cpltxt 0 -2)))
8269 (setq link (org-make-link cpltxt)))))
8271 ((buffer-file-name (buffer-base-buffer))
8272 ;; Just link to this file here.
8273 (setq cpltxt (concat "file
:"
8274 (abbreviate-file-name
8275 (buffer-file-name (buffer-base-buffer)))))
8276 ;; Add a context string
8277 (when (org-xor org-context-in-file-links arg)
8278 (setq txt (if (org-region-active-p)
8279 (buffer-substring (region-beginning) (region-end))
8280 (buffer-substring (point-at-bol) (point-at-eol))))
8281 ;; Only use search option if there is some text.
8282 (when (string-match "\\S-
" txt)
8284 (concat cpltxt "::" (org-make-org-heading-search-string txt))
8286 (setq link (org-make-link cpltxt)))
8289 (error "Cannot link to a buffer which is not visiting a file
"))
8291 (t (setq link nil)))
8293 (if (consp link) (setq cpltxt (car link) link (cdr link)))
8294 (setq link (or link cpltxt)
8295 desc (or desc cpltxt))
8296 (if (equal desc "NONE
") (setq desc nil))
8298 (if (and (or (interactive-p) executing-kbd-macro) link)
8300 (setq org-stored-links
8301 (cons (list link desc) org-stored-links))
8302 (message "Stored
: %s
" (or desc link))
8304 (setq link (concat "file
:" (abbreviate-file-name (buffer-file-name))
8306 (setq org-stored-links
8307 (cons (list link desc) org-stored-links))))
8308 (and link (org-make-link-string link desc)))))
8310 (defun org-store-link-props (&rest plist)
8311 "Store link properties
, extract names and addresses.
"
8313 (when (setq x (plist-get plist :from))
8314 (setq adr (mail-extract-address-components x))
8315 (setq plist (plist-put plist :fromname (car adr)))
8316 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8317 (when (setq x (plist-get plist :to))
8318 (setq adr (mail-extract-address-components x))
8319 (setq plist (plist-put plist :toname (car adr)))
8320 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8321 (let ((from (plist-get plist :from))
8322 (to (plist-get plist :to)))
8323 (when (and from to org-from-is-user-regexp)
8325 (plist-put plist :fromto
8326 (if (string-match org-from-is-user-regexp from)
8328 (concat "from %f
"))))))
8329 (setq org-store-link-plist plist))
8331 (defun org-add-link-props (&rest plist)
8332 "Add these properties to the link property list.
"
8335 (setq key (pop plist) value (pop plist))
8336 (setq org-store-link-plist
8337 (plist-put org-store-link-plist key value)))))
8339 (defun org-email-link-description (&optional fmt)
8340 "Return the description part of an email link.
8341 This takes information from
`org-store-link-plist
' and formats it
8342 according to FMT
(default from
`org-email-link-description-format
').
"
8343 (setq fmt (or fmt org-email-link-description-format))
8344 (let* ((p org-store-link-plist)
8345 (to (plist-get p :toaddress))
8346 (from (plist-get p :fromaddress))
8349 (cons "%c
" (plist-get p :fromto))
8350 (cons "%F
" (plist-get p :from))
8351 (cons "%f
" (or (plist-get p :fromname) (plist-get p :fromaddress) "?
"))
8352 (cons "%T
" (plist-get p :to))
8353 (cons "%t
" (or (plist-get p :toname) (plist-get p :toaddress) "?
"))
8354 (cons "%s
" (plist-get p :subject))
8355 (cons "%m
" (plist-get p :message-id)))))
8356 (when (string-match "%c
" fmt)
8357 ;; Check if the user wrote this message
8358 (if (and org-from-is-user-regexp from to
8359 (save-match-data (string-match org-from-is-user-regexp from)))
8360 (setq fmt (replace-match "to %t
" t t fmt))
8361 (setq fmt (replace-match "from %f
" t t fmt))))
8362 (org-replace-escapes fmt table)))
8364 (defun org-make-org-heading-search-string (&optional string heading)
8365 "Make search string for STRING or current headline.
"
8367 (let ((s (or string (org-get-heading))))
8368 (unless (and string (not heading))
8369 ;; We are using a headline, clean up garbage in there.
8370 (if (string-match org-todo-regexp s)
8371 (setq s (replace-match "" t t s)))
8372 (if (string-match (org-re ":[[:alnum
:]_
@:]+:[ \t]*$
") s)
8373 (setq s (replace-match "" t t s)))
8374 (setq s (org-trim s))
8375 (if (string-match (concat "^
\\(" org-quote-string "\\|
"
8376 org-comment-string "\\)") s)
8377 (setq s (replace-match "" t t s)))
8378 (while (string-match org-ts-regexp s)
8379 (setq s (replace-match "" t t s))))
8380 (while (string-match "[^a-zA-Z_0-9
\t]+" s)
8381 (setq s (replace-match " " t t s)))
8382 (or string (setq s (concat "*" s))) ; Add * for headlines
8383 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8385 (defun org-make-link (&rest strings)
8386 "Concatenate STRINGS.
"
8387 (apply 'concat strings))
8389 (defun org-make-link-string (link &optional description)
8390 "Make a link with brackets
, consisting of LINK and DESCRIPTION.
"
8391 (unless (string-match "\\S-
" link)
8392 (error "Empty link
"))
8393 (when (and description
8394 (stringp description)
8395 (not (string-match "\\S-
" description)))
8396 (setq description nil))
8397 (when (stringp description)
8398 ;; Remove brackets from the description, they are fatal.
8399 (while (string-match "\\[" description)
8400 (setq description (replace-match "{" t t description)))
8401 (while (string-match "\\]" description)
8402 (setq description (replace-match "}" t t description))))
8403 (when (equal (org-link-escape link) description)
8404 ;; No description needed, it is identical
8405 (setq description nil))
8406 (when (and (not description)
8407 (not (equal link (org-link-escape link))))
8408 (setq description (org-extract-attributes link)))
8409 (concat "[[" (org-link-escape link) "]"
8410 (if description (concat "[" description "]") "")
8413 (defconst org-link-escape-chars
8417 (?\340 . "%E0
") ; `a
8418 (?\342 . "%E2
") ; ^a
8419 (?\347 . "%E7
") ; ,c
8420 (?\350 . "%E8
") ; `e
8421 (?\351 . "%E9
") ; 'e
8422 (?\352 . "%EA
") ; ^e
8423 (?\356 . "%EE
") ; ^i
8424 (?\364 . "%F4
") ; ^o
8425 (?\371 . "%F9
") ; `u
8426 (?\373 . "%FB
") ; ^u
8432 "Association list of escapes for some characters problematic in links.
8433 This is the list that is used for internal purposes.
")
8435 (defvar org-url-encoding-use-url-hexify nil)
8437 (defconst org-link-escape-chars-browser
8438 '((?\ . "%
20")) ; 32 for the SPC char
8439 "Association list of escapes for some characters problematic in links.
8440 This is the list that is used before handing over to the browser.
")
8442 (defun org-link-escape (text &optional table)
8443 "Escape characters in TEXT that are problematic for links.
"
8444 (if (and org-url-encoding-use-url-hexify (not table))
8445 (url-hexify-string text)
8446 (setq table (or table org-link-escape-chars))
8448 (let ((re (mapconcat (lambda (x) (regexp-quote
8449 (char-to-string (car x))))
8451 (while (string-match re text)
8454 (cdr (assoc (string-to-char (match-string 0 text))
8459 (defun org-link-unescape (text &optional table)
8460 "Reverse the action of
`org-link-escape
'.
"
8461 (if (and org-url-encoding-use-url-hexify (not table))
8462 (url-unhex-string text)
8463 (setq table (or table org-link-escape-chars))
8465 (let ((case-fold-search t)
8466 (re (mapconcat (lambda (x) (regexp-quote (downcase (cdr x))))
8468 (while (string-match re text)
8471 (char-to-string (car (rassoc (upcase (match-string 0 text))
8476 (defun org-xor (a b)
8480 (defun org-fixup-message-id-for-http (s)
8481 "Replace special characters in a message id
, so it can be used in an http query.
"
8482 (when (string-match "%
" s)
8483 (setq s (mapconcat (lambda (c)
8486 (char-to-string c)))
8488 (while (string-match "<" s)
8489 (setq s (replace-match "%
3C
" t t s)))
8490 (while (string-match ">" s)
8491 (setq s (replace-match "%
3E
" t t s)))
8492 (while (string-match "@" s)
8493 (setq s (replace-match "%
40" t t s)))
8497 (defun org-insert-link-global ()
8498 "Insert a link like Org-mode does.
8499 This command can be called in any mode to insert a link in Org-mode syntax.
"
8501 (org-load-modules-maybe)
8502 (org-run-like-in-org-mode 'org-insert-link))
8504 (defun org-insert-link (&optional complete-file link-location)
8505 "Insert a link. At the prompt
, enter the link.
8507 Completion can be used to insert any of the link protocol prefixes like
8510 The history can be used to select a link previously stored with
8511 `org-store-link
'. When the empty string is entered
(i.e. if you just
8512 press RET at the prompt
), the link defaults to the most recently
8513 stored link. As SPC triggers completion in the minibuffer
, you need to
8514 use M-SPC or C-q SPC to force the insertion of a space character.
8516 You will also be prompted for a description
, and if one is given
, it will
8517 be displayed in the buffer instead of the link.
8519 If there is already a link at point
, this command will allow you to edit link
8520 and description parts.
8522 With a
\\[universal-argument
] prefix
, prompts for a file to link to. The file name can
8523 be selected using completion. The path to the file will be relative to the
8524 current directory if the file is in the current directory or a subdirectory.
8525 Otherwise
, the link will be the absolute path as completed in the minibuffer
8526 \
(i.e. normally ~
/path
/to
/file
). You can configure this behavior using the
8527 option
`org-link-file-path-type
'.
8529 With two
\\[universal-argument
] prefixes
, enforce an absolute path even if the file is in
8530 the current directory or below.
8532 With three
\\[universal-argument
] prefixes
, negate the meaning of
8533 `org-keep-stored-link-after-insertion
'.
8535 If
`org-make-link-description-function
' is non-nil
, this function will be
8536 called with the link target
, and the result will be the default
8539 If the LINK-LOCATION parameter is non-nil
, this value will be
8540 used as the link location instead of reading one interactively.
"
8542 (let* ((wcf (current-window-configuration))
8543 (region (if (org-region-active-p)
8544 (buffer-substring (region-beginning) (region-end))))
8545 (remove (and region (list (region-beginning) (region-end))))
8547 tmphist ; byte-compile incorrectly complains about this
8548 (link link-location)
8549 entry file all-prefixes)
8551 (link-location) ; specified by arg, just use it.
8552 ((org-in-regexp org-bracket-link-regexp 1)
8553 ;; We do have a link at point, and we are going to edit it.
8554 (setq remove (list (match-beginning 0) (match-end 0)))
8555 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
8556 (setq link (read-string "Link
: "
8558 (org-match-string-no-properties 1)))))
8559 ((or (org-in-regexp org-angle-link-re)
8560 (org-in-regexp org-plain-link-re))
8561 ;; Convert to bracket link
8562 (setq remove (list (match-beginning 0) (match-end 0))
8563 link (read-string "Link
: "
8564 (org-remove-angle-brackets (match-string 0)))))
8565 ((member complete-file '((4) (16)))
8566 ;; Completing read for file names.
8567 (setq link (org-file-complete-link complete-file)))
8569 ;; Read link, with completion for stored links.
8570 (with-output-to-temp-buffer "*Org Links
*"
8571 (princ "Insert a link.
8572 Use TAB to complete link prefixes
, then RET for type-specific completion support
\n")
8573 (when org-stored-links
8574 (princ "\nStored links are available with
<up
>/<down
> or M-p
/n
(most recent with RET
):\n\n")
8577 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
8578 (reverse org-stored-links) "\n"))))
8579 (let ((cw (selected-window)))
8580 (select-window (get-buffer-window "*Org Links
*" 'visible))
8581 (setq truncate-lines t)
8582 (unless (pos-visible-in-window-p (point-max))
8583 (org-fit-window-to-buffer))
8584 (and (window-live-p cw) (select-window cw)))
8585 ;; Fake a link history, containing the stored links.
8586 (setq tmphist (append (mapcar 'car org-stored-links)
8587 org-insert-link-history))
8588 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
8589 (mapcar 'car org-link-abbrev-alist)
8594 (let ((org-completion-use-ido nil)
8595 (org-completion-use-iswitchb nil))
8596 (org-completing-read
8599 (mapcar (lambda (x) (list (concat x ":")))
8601 (mapcar 'car org-stored-links))
8604 (car (car org-stored-links)))))
8605 (if (not (string-match "\\S-
" link))
8606 (error "No link selected
"))
8607 (if (or (member link all-prefixes)
8608 (and (equal ":" (substring link -1))
8609 (member (substring link 0 -1) all-prefixes)
8610 (setq link (substring link 0 -1))))
8611 (setq link (org-link-try-special-completion link))))
8612 (set-window-configuration wcf)
8613 (kill-buffer "*Org Links
*"))
8614 (setq entry (assoc link org-stored-links))
8615 (or entry (push link org-insert-link-history))
8616 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
8617 (not org-keep-stored-link-after-insertion))
8618 (setq org-stored-links (delq (assoc link org-stored-links)
8620 (setq desc (or desc (nth 1 entry)))))
8622 (if (string-match org-plain-link-re link)
8623 ;; URL-like link, normalize the use of angular brackets.
8624 (setq link (org-make-link (org-remove-angle-brackets link))))
8626 ;; Check if we are linking to the current file with a search option
8627 ;; If yes, simplify the link by using only the search option.
8628 (when (and buffer-file-name
8629 (string-match "^file
:\\(.
+?
\\)::\\([^
>]+\\)" link))
8630 (let* ((path (match-string 1 link))
8631 (case-fold-search nil)
8632 (search (match-string 2 link)))
8634 (if (equal (file-truename buffer-file-name) (file-truename path))
8635 ;; We are linking to this same file, with a search option
8636 (setq link search)))))
8638 ;; Check if we can/should use a relative path. If yes, simplify the link
8639 (when (string-match "^
\\(file:\\|docview
:\\)\\(.
*\\)" link)
8640 (let* ((type (match-string 1 link))
8641 (path (match-string 2 link))
8643 (case-fold-search nil))
8645 ((or (eq org-link-file-path-type 'absolute)
8646 (equal complete-file '(16)))
8647 (setq path (abbreviate-file-name (expand-file-name path))))
8648 ((eq org-link-file-path-type 'noabbrev)
8649 (setq path (expand-file-name path)))
8650 ((eq org-link-file-path-type 'relative)
8651 (setq path (file-relative-name path)))
8654 (if (string-match (concat "^
" (regexp-quote
8656 (file-name-as-directory
8657 default-directory))))
8658 (expand-file-name path))
8659 ;; We are linking a file with relative path name.
8660 (setq path (substring (expand-file-name path)
8662 (setq path (abbreviate-file-name (expand-file-name path)))))))
8663 (setq link (concat type path))
8664 (if (equal desc origpath)
8667 (if org-make-link-description-function
8668 (setq desc (funcall org-make-link-description-function link desc)))
8670 (setq desc (read-string "Description
: " desc))
8671 (unless (string-match "\\S-
" desc) (setq desc nil))
8672 (if remove (apply 'delete-region remove))
8673 (insert (org-make-link-string link desc))))
8675 (defun org-link-try-special-completion (type)
8676 "If there is completion support for link type TYPE
, offer it.
"
8677 (let ((fun (intern (concat "org-
" type "-complete-link
"))))
8680 (read-string "Link
(no completion support
): " (concat type ":")))))
8682 (defun org-file-complete-link (&optional arg)
8683 "Create a file link using completion.
"
8685 (setq file (read-file-name "File
: "))
8686 (let ((pwd (file-name-as-directory (expand-file-name ".
")))
8687 (pwd1 (file-name-as-directory (abbreviate-file-name
8688 (expand-file-name ".
")))))
8691 (setq link (org-make-link
8693 (abbreviate-file-name (expand-file-name file)))))
8694 ((string-match (concat "^
" (regexp-quote pwd1) "\\(.
+\\)") file)
8695 (setq link (org-make-link "file
:" (match-string 1 file))))
8696 ((string-match (concat "^
" (regexp-quote pwd) "\\(.
+\\)")
8697 (expand-file-name file))
8698 (setq link (org-make-link
8699 "file
:" (match-string 1 (expand-file-name file)))))
8700 (t (setq link (org-make-link "file
:" file)))))
8703 (defun org-completing-read (&rest args)
8704 "Completing-read with SPACE being a normal character.
"
8705 (let ((minibuffer-local-completion-map
8706 (copy-keymap minibuffer-local-completion-map)))
8707 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
8708 (org-defkey minibuffer-local-completion-map "?
" 'self-insert-command)
8709 (apply 'org-icompleting-read args)))
8711 (defun org-completing-read-no-i (&rest args)
8712 (let (org-completion-use-ido org-completion-use-iswitchb)
8713 (apply 'org-completing-read args)))
8715 (defun org-iswitchb-completing-read (prompt choices &rest args)
8716 "Use iswitch as a completing-read replacement to choose from choices.
8717 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
8719 (let* ((iswitchb-use-virtual-buffers nil)
8720 (iswitchb-make-buflist-hook
8722 (setq iswitchb-temp-buflist choices))))
8723 (iswitchb-read-buffer prompt)))
8725 (defun org-icompleting-read (&rest args)
8726 "Completing-read using
`ido-mode
' or
`iswitchb
' speedups if available.
"
8727 (org-without-partial-completion
8728 (if (and org-completion-use-ido
8729 (fboundp 'ido-completing-read)
8730 (boundp 'ido-mode) ido-mode
8731 (listp (second args)))
8732 (let ((ido-enter-matching-directory nil))
8733 (apply 'ido-completing-read (concat (car args))
8734 (if (consp (car (nth 1 args)))
8735 (mapcar (lambda (x) (car x)) (nth 1 args))
8738 (if (and org-completion-use-iswitchb
8739 (boundp 'iswitchb-mode) iswitchb-mode
8740 (listp (second args)))
8741 (apply 'org-iswitchb-completing-read (concat (car args))
8742 (if (consp (car (nth 1 args)))
8743 (mapcar (lambda (x) (car x)) (nth 1 args))
8746 (apply 'completing-read args)))))
8748 (defun org-extract-attributes (s)
8749 "Extract the attributes cookie from a string and set as text property.
"
8750 (let (a attr (start 0) key value)
8752 (when (string-match "{{\\([^
}]+\\)}}$
" s)
8753 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
8754 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"" a start)
8755 (setq key (match-string 1 a) value (match-string 2 a)
8757 attr (plist-put attr (intern key) value))))
8758 (org-add-props s nil 'org-attr attr))
8761 (defun org-extract-attributes-from-string (tag)
8762 (let (key value attr)
8763 (while (string-match "\\([a-zA-Z
]+\\)=\"\\([^
\"]*\\)\"\\s-?
" tag)
8764 (setq key (match-string 1 tag) value (match-string 2 tag)
8765 tag (replace-match "" t t tag)
8766 attr (plist-put attr (intern key) value)))
8769 (defun org-attributes-to-string (plist)
8770 "Format a property list into an HTML attribute list.
"
8771 (let ((s "") key value)
8773 (setq key (pop plist) value (pop plist))
8775 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
8778 ;;; Opening/following a link
8780 (defvar org-link-search-failed nil)
8782 (defvar org-open-link-functions nil
8783 "Hook for functions finding a plain text link.
8784 These functions must take a single argument
, the link content.
8785 They will be called for links that look like
[[link text
][description]]
8786 when LINK TEXT does not have a protocol like \"http:\" and does not look
8787 like a filename (e.g. \"./blue.png\").
8789 These functions will be called *before* Org attempts to resolve the
8790 link by doing text searches in the current buffer - so if you want a
8791 link \"[[target]]\" to still find \"<<target>>\", your function should
8792 handle this as a special case.
8794 When the function does handle the link, it must return a non-nil value.
8795 If it decides that it is not responsible for this link, it must return
8796 nil to indicate that that Org-mode can continue with other options
8797 like exact and fuzzy text search.")
8799 (defun org-next-link ()
8800 "Move forward to the next link.
8801 If the link is in hidden text, expose it."
8803 (when (and org-link-search-failed (eq this-command last-command))
8804 (goto-char (point-min))
8805 (message "Link search wrapped back to beginning of buffer"))
8806 (setq org-link-search-failed nil)
8807 (let* ((pos (point))
8809 (a (assoc :link ct)))
8810 (if a (goto-char (nth 2 a)))
8811 (if (re-search-forward org-any-link-re nil t)
8813 (goto-char (match-beginning 0))
8814 (if (org-invisible-p) (org-show-context)))
8816 (setq org-link-search-failed t)
8817 (error "No further link found"))))
8819 (defun org-previous-link ()
8820 "Move backward to the previous link.
8821 If the link is in hidden text, expose it."
8823 (when (and org-link-search-failed (eq this-command last-command))
8824 (goto-char (point-max))
8825 (message "Link search wrapped back to end of buffer"))
8826 (setq org-link-search-failed nil)
8827 (let* ((pos (point))
8829 (a (assoc :link ct)))
8830 (if a (goto-char (nth 1 a)))
8831 (if (re-search-backward org-any-link-re nil t)
8833 (goto-char (match-beginning 0))
8834 (if (org-invisible-p) (org-show-context)))
8836 (setq org-link-search-failed t)
8837 (error "No further link found"))))
8839 (defun org-translate-link (s)
8840 "Translate a link string if a translation function has been defined."
8841 (if (and org-link-translation-function
8842 (fboundp org-link-translation-function)
8843 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
8845 (setq s (funcall org-link-translation-function
8846 (match-string 1) (match-string 2)))
8847 (concat (car s) ":" (cdr s)))
8850 (defun org-translate-link-from-planner (type path)
8851 "Translate a link from Emacs Planner syntax so that Org can follow it.
8852 This is still an experimental function, your mileage may vary."
8854 ((member type '("http" "https" "news" "ftp"))
8855 ;; standard Internet links are the same.
8857 ((and (equal type "irc") (string-match "^//" path))
8858 ;; Planner has two / at the beginning of an irc link, we have 1.
8859 ;; We should have zero, actually....
8860 (setq path (substring path 1)))
8861 ((and (equal type "lisp") (string-match "^/" path))
8862 ;; Planner has a slash, we do not.
8863 (setq type "elisp" path (substring path 1)))
8864 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
8865 ;; A typical message link. Planner has the id after the final slash,
8866 ;; we separate it with a hash mark
8867 (setq path (concat (match-string 1 path) "#"
8868 (org-remove-angle-brackets (match-string 2 path)))))
8872 (defun org-find-file-at-mouse (ev)
8873 "Open file link or URL at mouse."
8875 (mouse-set-point ev)
8876 (org-open-at-point 'in-emacs))
8878 (defun org-open-at-mouse (ev)
8879 "Open file link or URL at mouse."
8881 (mouse-set-point ev)
8882 (if (eq major-mode 'org-agenda-mode)
8883 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
8884 (org-open-at-point))
8886 (defvar org-window-config-before-follow-link nil
8887 "The window configuration before following a link.
8888 This is saved in case the need arises to restore it.")
8890 (defvar org-open-link-marker (make-marker)
8891 "Marker pointing to the location where `org-open-at-point; was called.")
8894 (defun org-open-at-point-global ()
8895 "Follow a link like Org-mode does.
8896 This command can be called in any mode to follow a link that has
8899 (org-run-like-in-org-mode 'org-open-at-point))
8902 (defun org-open-link-from-string (s &optional arg reference-buffer)
8903 "Open a link in the string S, as if it was in Org-mode."
8904 (interactive "sLink: \nP")
8905 (let ((reference-buffer (or reference-buffer (current-buffer))))
8907 (let ((org-inhibit-startup t))
8910 (goto-char (point-min))
8911 (when reference-buffer
8912 (setq org-link-abbrev-alist-local
8913 (with-current-buffer reference-buffer
8914 org-link-abbrev-alist-local)))
8915 (org-open-at-point arg reference-buffer)))))
8917 (defun org-open-at-point (&optional in-emacs reference-buffer)
8918 "Open link at or after point.
8919 If there is no link at point, this function will search forward up to
8920 the end of the current line.
8921 Normally, files will be opened by an appropriate application. If the
8922 optional argument IN-EMACS is non-nil, Emacs will visit the file.
8923 With a double prefix argument, try to open outside of Emacs, in the
8924 application the system uses for this file type."
8926 ;; if in a code block, then open the block's results
8927 (unless (call-interactively #'org-babel-open-src-block-result)
8928 (org-load-modules-maybe)
8929 (move-marker org-open-link-marker (point))
8930 (setq org-window-config-before-follow-link (current-window-configuration))
8931 (org-remove-occur-highlights nil nil t)
8933 ((and (org-on-heading-p)
8935 (concat org-plain-link-re "\\|"
8936 org-bracket-link-regexp "\\|"
8937 org-angle-link-re "\\|"
8938 "[ \t]:[^ \t\n]+:[ \t]*$")))
8939 (not (get-text-property (point) 'org-linked-text)))
8940 (or (org-offer-links-in-entry in-emacs)
8941 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
8942 ((org-at-timestamp-p t) (org-follow-timestamp-link))
8943 ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
8944 (org-footnote-action))
8946 (let (type path link line search (pos (point)))
8949 (skip-chars-forward "^]\n\r")
8950 (when (org-in-regexp org-bracket-link-regexp 1)
8951 (setq link (org-extract-attributes
8952 (org-link-unescape (org-match-string-no-properties 1))))
8953 (while (string-match " *\n *" link)
8954 (setq link (replace-match " " t t link)))
8955 (setq link (org-link-expand-abbrev link))
8957 ((or (file-name-absolute-p link)
8958 (string-match "^\\.\\.?/" link))
8959 (setq type "file" path link))
8960 ((string-match org-link-re-with-space3 link)
8961 (setq type (match-string 1 link) path (match-string 2 link)))
8962 (t (setq type "thisfile" path link)))
8965 (when (get-text-property (point) 'org-linked-text)
8966 (setq type "thisfile"
8967 pos (if (get-text-property (1+ (point)) 'org-linked-text)
8968 (1+ (point)) (point))
8969 path (buffer-substring
8970 (previous-single-property-change pos 'org-linked-text)
8971 (next-single-property-change pos 'org-linked-text)))
8975 (when (or (org-in-regexp org-angle-link-re)
8976 (org-in-regexp org-plain-link-re))
8977 (setq type (match-string 1) path (match-string 2))
8980 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
8982 path (match-string 1))
8983 (while (string-match ":" path)
8984 (setq path (replace-match "+" t t path)))
8986 (when (org-in-regexp "<\\([^><\n]+\\)>")
8987 (setq type "tree-match"
8988 path (match-string 1))
8991 (error "No link found"))
8993 ;; switch back to reference buffer
8994 ;; needed when if called in a temporary buffer through
8995 ;; org-open-link-from-string
8996 (with-current-buffer (or reference-buffer (current-buffer))
8998 ;; Remove any trailing spaces in path
8999 (if (string-match " +\\'" path)
9000 (setq path (replace-match "" t t path)))
9001 (if (and org-link-translation-function
9002 (fboundp org-link-translation-function))
9003 ;; Check if we need to translate the link
9004 (let ((tmp (funcall org-link-translation-function type path)))
9005 (setq type (car tmp) path (cdr tmp))))
9009 ((assoc type org-link-protocols)
9010 (funcall (nth 1 (assoc type org-link-protocols)) path))
9012 ((equal type "mailto")
9013 (let ((cmd (car org-link-mailto-program))
9014 (args (cdr org-link-mailto-program)) args1
9015 (address path) (subject "") a)
9016 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9017 (setq address (match-string 1 path)
9018 subject (org-link-escape (match-string 2 path))))
9021 ((not (stringp (car args))) (push (pop args) args1))
9022 (t (setq a (pop args))
9023 (if (string-match "%a" a)
9024 (setq a (replace-match address t t a)))
9025 (if (string-match "%s" a)
9026 (setq a (replace-match subject t t a)))
9028 (apply cmd (nreverse args1))))
9030 ((member type '("http" "https" "ftp" "news"))
9031 (browse-url (concat type ":" (org-link-escape
9032 path org-link-escape-chars-browser))))
9034 ((string= type "doi")
9035 (browse-url (concat "http://dx.doi.org/"
9037 path org-link-escape-chars-browser))))
9039 ((member type '("message"))
9040 (browse-url (concat type ":" path)))
9042 ((string= type "tags")
9043 (org-tags-view in-emacs path))
9045 ((string= type "tree-match")
9046 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9048 ((string= type "file")
9049 (if (string-match "::\\([0-9]+\\)\\'" path)
9050 (setq line (string-to-number (match-string 1 path))
9051 path (substring path 0 (match-beginning 0)))
9052 (if (string-match "::\\(.+\\)\\'" path)
9053 (setq search (match-string 1 path)
9054 path (substring path 0 (match-beginning 0)))))
9055 (if (string-match "[*?{]" (file-name-nondirectory path))
9057 (org-open-file path in-emacs line search)))
9059 ((string= type "news")
9061 (org-gnus-follow-link path))
9063 ((string= type "shell")
9065 (if (or (not org-confirm-shell-link-function)
9066 (funcall org-confirm-shell-link-function
9067 (format "Execute \"%s\" in shell? "
9068 (org-add-props cmd nil
9069 'face 'org-warning))))
9071 (message "Executing %s" cmd)
9072 (shell-command cmd))
9075 ((string= type "elisp")
9077 (if (or (not org-confirm-elisp-link-function)
9078 (funcall org-confirm-elisp-link-function
9079 (format "Execute \"%s\" as elisp? "
9080 (org-add-props cmd nil
9081 'face 'org-warning))))
9082 (message "%s => %s" cmd
9083 (if (equal (string-to-char cmd) ?\()
9085 (call-interactively (read cmd))))
9088 ((and (string= type "thisfile")
9089 (run-hook-with-args-until-success
9090 'org-open-link-functions path)))
9092 ((string= type "thisfile")
9094 (switch-to-buffer-other-window
9095 (org-get-buffer-for-internal-link (current-buffer)))
9096 (org-mark-ring-push))
9097 (let ((cmd `(org-link-search
9099 ,(cond ((equal in-emacs '(4)) 'occur)
9100 ((equal in-emacs '(16)) 'org-occur)
9103 (condition-case nil (eval cmd)
9104 (error (progn (widen) (eval cmd))))))
9107 (browse-url-at-point)))))))
9108 (move-marker org-open-link-marker nil)
9109 (run-hook-with-args 'org-follow-link-hook)))
9111 (defun org-offer-links-in-entry (&optional nth zero)
9112 "Offer links in the current entry and follow the selected link.
9113 If there is only one link, follow it immediately as well.
9114 If NTH is an integer, immediately pick the NTH link found.
9115 If ZERO is a string, check also this string for a link, and if
9116 there is one, offer it as link number zero."
9117 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
9118 "\\(" org-angle-link-re "\\)\\|"
9119 "\\(" org-plain-link-re "\\)"))
9121 (in-emacs (if (integerp nth) nil nth))
9122 have-zero end links link c)
9123 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
9124 (push (match-string 0 zero) links)
9125 (setq cnt (1- cnt) have-zero t))
9127 (org-back-to-heading t)
9128 (setq end (save-excursion (outline-next-heading) (point)))
9129 (while (re-search-forward re end t)
9130 (push (match-string 0) links))
9131 (setq links (org-uniquify (reverse links))))
9135 (message "No links"))
9136 ((equal (length links) 1)
9137 (setq link (list (car links))))
9138 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
9139 (setq link (nth (if have-zero nth (1- nth)) links)))
9140 (t ; we have to select a link
9142 (save-window-excursion
9143 (delete-other-windows)
9144 (with-output-to-temp-buffer "*Select Link*"
9146 (if (not (string-match org-bracket-link-regexp l))
9147 (princ (format "[%c] %s\n" (incf cnt)
9148 (org-remove-angle-brackets l)))
9150 (princ (format "[%c] %s (%s)\n" (incf cnt)
9151 (match-string 3 l) (match-string 1 l)))
9152 (princ (format "[%c] %s\n" (incf cnt)
9153 (match-string 1 l))))))
9155 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
9156 (message "Select link to open, RET to open all:")
9157 (setq c (read-char-exclusive))
9158 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
9159 (when (equal c ?q) (error "Abort"))
9163 (if have-zero (setq nth (1+ nth)))
9164 (unless (and (integerp nth) (>= (length links) nth))
9165 (error "Invalid link selection"))
9166 (setq link (list (nth (1- nth) links))))))
9168 (let ((buf (current-buffer)))
9170 (org-open-link-from-string l in-emacs buf))
9174 ;; Add special file links that specify the way of opening
9176 (org-add-link-type "file+sys" 'org-open-file-with-system)
9177 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
9178 (defun org-open-file-with-system (path)
9179 "Open file at PATH using the system way of opening it."
9180 (org-open-file path 'system))
9181 (defun org-open-file-with-emacs (path)
9182 "Open file at PATH in Emacs."
9183 (org-open-file path 'emacs))
9184 (defun org-remove-file-link-modifiers ()
9185 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
9186 (goto-char (point-min))
9187 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
9189 (replace-match "file:" t t))))
9190 (eval-after-load "org-exp"
9191 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
9192 'org-remove-file-link-modifiers))
9196 (defun org-get-effort (&optional pom)
9197 "Get the effort estimate for the current entry."
9198 (org-entry-get pom org-effort-property))
9202 (defvar org-create-file-search-functions nil
9203 "List of functions to construct the right search string for a file link.
9204 These functions are called in turn with point at the location to
9205 which the link should point.
9207 A function in the hook should first test if it would like to
9208 handle this file type, for example by checking the `major-mode'
9209 or the file extension. If it decides not to handle this file, it
9210 should just return nil to give other functions a chance. If it
9211 does handle the file, it must return the search string to be used
9212 when following the link. The search string will be part of the
9213 file link, given after a double colon, and `org-open-at-point'
9214 will automatically search for it. If special measures must be
9215 taken to make the search successful, another function should be
9216 added to the companion hook `org-execute-file-search-functions',
9219 A function in this hook may also use `setq' to set the variable
9220 `description' to provide a suggestion for the descriptive text to
9221 be used for this link when it gets inserted into an Org-mode
9222 buffer with \\[org-insert-link].")
9224 (defvar org-execute-file-search-functions nil
9225 "List of functions to execute a file search triggered by a link.
9227 Functions added to this hook must accept a single argument, the
9228 search string that was part of the file link, the part after the
9229 double colon. The function must first check if it would like to
9230 handle this search, for example by checking the `major-mode' or
9231 the file extension. If it decides not to handle this search, it
9232 should just return nil to give other functions a chance. If it
9233 does handle the search, it must return a non-nil value to keep
9234 other functions from trying.
9236 Each function can access the current prefix argument through the
9237 variable `current-prefix-argument'. Note that a single prefix is
9238 used to force opening a link in Emacs, so it may be good to only
9239 use a numeric or double prefix to guide the search function.
9241 In case this is needed, a function in this hook can also restore
9242 the window configuration before `org-open-at-point' was called using:
9244 (set-window-configuration org-window-config-before-follow-link)")
9246 (defun org-link-search (s &optional type avoid-pos)
9247 "Search for a link search option.
9248 If S is surrounded by forward slashes, it is interpreted as a
9249 regular expression. In org-mode files, this will create an `org-occur'
9250 sparse tree. In ordinary files, `occur' will be used to list matches.
9251 If the current buffer is in `dired-mode', grep will be used to search
9252 in all files. If AVOID-POS is given, ignore matches near that position."
9253 (let ((case-fold-search t)
9254 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
9255 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
9256 (append '(("") (" ") ("\t") ("\n"))
9260 (pre nil) (post nil)
9261 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
9263 ;; First check if there are any special
9264 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
9265 ;; Now try the builtin stuff
9266 ((and (equal (string-to-char s0) ?#)
9269 (goto-char (point-min))
9272 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
9273 (setq type 'dedicated
9274 pos (match-beginning 0))))
9275 ;; There is an exact target for this
9277 (org-back-to-heading t)))
9279 (goto-char (point-min))
9282 (concat "<<" (regexp-quote s0) ">>") nil t)
9283 (setq type 'dedicated
9284 pos (match-beginning 0))))
9285 ;; There is an exact target for this
9287 ((and (string-match "^(\\(.*\\))$" s0)
9289 (goto-char (point-min))
9292 (concat "[^[]" (regexp-quote
9293 (format org-coderef-label-format
9294 (match-string 1 s0))))
9296 (setq type 'dedicated
9297 pos (1+ (match-beginning 0))))))
9298 ;; There is a coderef target for this
9300 ((string-match "^/\\(.*\\)/$" s)
9301 ;; A regular expression
9304 (org-occur (match-string 1 s)))
9305 ;;((eq major-mode 'dired-mode)
9306 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9307 (t (org-do-occur (match-string 1 s)))))
9309 ;; A normal search strings
9310 (when (equal (string-to-char s) ?*)
9311 ;; Anchor on headlines, post may include tags.
9312 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
9313 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
9315 (remove-text-properties
9317 '(face nil mouse-face nil keymap nil fontified nil) s)
9318 ;; Make a series of regular expressions to find a match
9319 (setq words (org-split-string s "[ \n\r\t]+")
9321 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
9322 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9324 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9325 re2a (concat "[ \t\r\n]" re2a_)
9326 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9327 re4 (concat "[^a-zA-Z_]" re4_)
9329 re1 (concat pre re2 post)
9330 re3 (concat pre (if pre re4_ re4) post)
9331 re5 (concat pre ".*" re4)
9332 re2 (concat pre re2)
9333 re2a (concat pre (if pre re2a_ re2a))
9334 re4 (concat pre (if pre re4_ re4))
9335 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9336 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9340 ((eq type 'org-occur) (org-occur reall))
9341 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9342 (t (goto-char (point-min))
9344 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9345 (org-search-not-self 1 re1 nil t)
9346 (org-search-not-self 1 re2 nil t)
9347 (org-search-not-self 1 re2a nil t)
9348 (org-search-not-self 1 re3 nil t)
9349 (org-search-not-self 1 re4 nil t)
9350 (org-search-not-self 1 re5 nil t)
9352 (goto-char (match-beginning 1))
9354 (error "No match")))))
9356 ;; Normal string-search
9357 (goto-char (point-min))
9358 (if (search-forward s nil t)
9359 (goto-char (match-beginning 0))
9360 (error "No match"))))
9361 (and (org-mode-p) (org-show-context 'link-search))
9364 (defun org-search-not-self (group &rest args)
9365 "Execute `re-search-forward', but only accept matches that do not
9366 enclose the position of `org-open-link-marker'."
9367 (let ((m org-open-link-marker))
9369 (while (apply 're-search-forward args)
9370 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
9371 (goto-char (match-end group))
9372 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
9373 (> (match-beginning 0) (marker-position m))
9374 (< (match-end 0) (marker-position m)))
9376 (or (not (org-in-regexp
9377 org-bracket-link-analytic-regexp 1))
9378 (not (match-end 4)) ; no description
9379 (and (<= (match-beginning 4) (point))
9380 (>= (match-end 4) (point))))))
9381 (throw 'exit (point))))))))
9383 (defun org-get-buffer-for-internal-link (buffer)
9384 "Return a buffer to be used for displaying the link target of internal links."
9386 ((not org-display-internal-link-with-indirect-buffer)
9388 ((string-match "(Clone)$" (buffer-name buffer))
9389 (message "Buffer is already a clone, not making another one")
9390 ;; we also do not modify visibility in this case
9392 (t ; make a new indirect buffer for displaying the link
9393 (let* ((bn (buffer-name buffer))
9394 (ibn (concat bn "(Clone)"))
9395 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
9396 (with-current-buffer ib (org-overview))
9399 (defun org-do-occur (regexp &optional cleanup)
9400 "Call the Emacs command `occur'.
9401 If CLEANUP is non-nil, remove the printout of the regular expression
9402 in the *Occur* buffer. This is useful if the regex is long and not useful
9406 (let ((cwin (selected-window)) win beg end)
9407 (when (setq win (get-buffer-window "*Occur*"))
9408 (select-window win))
9409 (goto-char (point-min))
9410 (when (re-search-forward "match[a-z]+" nil t)
9411 (setq beg (match-end 0))
9412 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
9413 (setq end (1- (match-beginning 0)))))
9414 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
9415 (goto-char (point-min))
9416 (select-window cwin))))
9418 ;;; The mark ring for links jumps
9420 (defvar org-mark-ring nil
9421 "Mark ring for positions before jumps in Org-mode.")
9422 (defvar org-mark-ring-last-goto nil
9423 "Last position in the mark ring used to go back.")
9424 ;; Fill and close the ring
9425 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
9426 (loop for i from 1 to org-mark-ring-length do
9427 (push (make-marker) org-mark-ring))
9428 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
9431 (defun org-mark-ring-push (&optional pos buffer)
9432 "Put the current position or POS into the mark ring and rotate it."
9434 (setq pos (or pos (point)))
9435 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
9436 (move-marker (car org-mark-ring)
9438 (or buffer (current-buffer)))
9440 (substitute-command-keys
9441 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9443 (defun org-mark-ring-goto (&optional n)
9444 "Jump to the previous position in the mark ring.
9445 With prefix arg N, jump back that many stored positions. When
9446 called several times in succession, walk through the entire ring.
9447 Org-mode commands jumping to a different position in the current file,
9448 or to another Org-mode file, automatically push the old position
9452 (if (eq last-command this-command)
9453 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
9454 (setq p org-mark-ring))
9455 (setq org-mark-ring-last-goto p)
9457 (switch-to-buffer (marker-buffer m))
9459 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
9461 (defun org-remove-angle-brackets (s)
9462 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
9463 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
9465 (defun org-add-angle-brackets (s)
9466 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
9467 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
9469 (defun org-remove-double-quotes (s)
9470 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
9471 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
9474 ;;; Following specific links
9476 (defun org-follow-timestamp-link ()
9478 ((org-at-date-range-p t)
9479 (let ((org-agenda-start-on-weekday)
9480 (t1 (match-string 1))
9481 (t2 (match-string 2)))
9482 (setq t1 (time-to-days (org-time-string-to-time t1))
9483 t2 (time-to-days (org-time-string-to-time t2)))
9484 (org-agenda-list nil t1 (1+ (- t2 t1)))))
9485 ((org-at-timestamp-p t)
9486 (org-agenda-list nil (time-to-days (org-time-string-to-time
9487 (substring (match-string 1) 0 10)))
9489 (t (error "This should not happen"))))
9492 ;;; Following file links
9493 (defvar org-wait nil)
9494 (defun org-open-file (path &optional in-emacs line search)
9495 "Open the file at PATH.
9496 First, this expands any special file name abbreviations. Then the
9497 configuration variable `org-file-apps' is checked if it contains an
9498 entry for this file type, and if yes, the corresponding command is launched.
9500 If no application is found, Emacs simply visits the file.
9502 With optional prefix argument IN-EMACS, Emacs will visit the file.
9503 With a double \\[universal-argument] \\[universal-argument] \
9504 prefix arg, Org tries to avoid opening in Emacs
9505 and to use an external application to visit the file.
9507 Optional LINE specifies a line to go to, optional SEARCH a string
9508 to search for. If LINE or SEARCH is given, the file will be
9509 opened in Emacs, unless an entry from org-file-apps that makes
9510 use of groups in a regexp matches.
9511 If the file does not exist, an error is thrown."
9512 (let* ((file (if (equal path "")
9514 (substitute-in-file-name (expand-file-name path))))
9515 (file-apps (append org-file-apps (org-default-apps)))
9516 (apps (org-remove-if
9517 'org-file-apps-entry-match-against-dlink-p file-apps))
9518 (apps-dlink (org-remove-if-not
9519 'org-file-apps-entry-match-against-dlink-p file-apps))
9520 (remp (and (assq 'remote apps) (org-file-remote-p file)))
9521 (dirp (if remp nil (file-directory-p file)))
9522 (file (if (and dirp org-open-directory-means-index-dot-org)
9523 (concat (file-name-as-directory file) "index.org")
9525 (a-m-a-p (assq 'auto-mode apps))
9526 (dfile (downcase file))
9527 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
9528 (link (cond ((and (eq line nil)
9532 (concat file "::" (number-to-string line)))
9534 (concat file "::" search))))
9535 (dlink (downcase link))
9536 (old-buffer (current-buffer))
9538 (old-mode major-mode)
9539 ext cmd link-match-data)
9540 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
9541 (setq ext (match-string 1 dfile))
9542 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
9543 (setq ext (match-string 1 dfile))))
9545 ((member in-emacs '((16) system))
9546 (setq cmd (cdr (assoc 'system apps))))
9547 (in-emacs (setq cmd 'emacs))
9549 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
9550 (and dirp (cdr (assoc 'directory apps)))
9551 ; first, try matching against apps-dlink
9552 ; if we get a match here, store the match data for later
9553 (let ((match (assoc-default dlink apps-dlink
9556 (progn (setq link-match-data (match-data))
9558 (progn (setq in-emacs (or in-emacs line search))
9559 nil))) ; if we have no match in apps-dlink,
9560 ; always open the file in emacs if line or search
9561 ; is given (for backwards compatibility)
9562 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
9564 (cdr (assoc ext apps))
9565 (cdr (assoc t apps))))))
9566 (when (eq cmd 'system)
9567 (setq cmd (cdr (assoc 'system apps))))
9568 (when (eq cmd 'default)
9569 (setq cmd (cdr (assoc t apps))))
9570 (when (eq cmd 'mailcap)
9572 (mailcap-parse-mailcaps)
9573 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
9574 (command (mailcap-mime-info mime-type)))
9575 (if (stringp command)
9577 (setq cmd 'emacs))))
9578 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
9579 (not (file-exists-p file))
9580 (not org-open-non-existing-files))
9581 (error "No such file: %s" file))
9583 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
9584 ;; Remove quotes around the file name - we'll use shell-quote-argument.
9585 (while (string-match "['\"]%s['\"]" cmd)
9586 (setq cmd (replace-match "%s" t t cmd)))
9587 (while (string-match "%s" cmd)
9588 (setq cmd (replace-match
9590 (shell-quote-argument
9591 (convert-standard-filename file)))
9594 ;; Replace "%1", "%2" etc. in command with group matches from regex
9596 (let ((match-index 1)
9597 (number-of-groups (- (/ (length link-match-data) 2) 1)))
9598 (set-match-data link-match-data)
9599 (while (<= match-index number-of-groups)
9600 (let ((regex (concat "%" (number-to-string match-index)))
9601 (replace-with (match-string match-index dlink)))
9602 (while (string-match regex cmd)
9603 (setq cmd (replace-match replace-with t t cmd))))
9604 (setq match-index (+ match-index 1)))))
9606 (save-window-excursion
9607 (start-process-shell-command cmd nil cmd)
9608 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
9612 (funcall (cdr (assq 'file org-link-frame-setup)) file)
9614 (if line (org-goto-line line)
9615 (if search (org-link-search search))))
9617 (let ((file (convert-standard-filename file)))
9619 (set-match-data link-match-data)
9621 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
9622 (and (org-mode-p) (eq old-mode 'org-mode)
9623 (or (not (equal old-buffer (current-buffer)))
9624 (not (equal old-pos (point))))
9625 (org-mark-ring-push old-pos old-buffer))))
9627 (defun org-file-apps-entry-match-against-dlink-p (entry)
9628 "This function returns non-nil if `entry' uses a regular
9629 expression which should be matched against the whole link by
9632 It assumes that is the case when the entry uses a regular
9633 expression which has at least one grouping construct and the
9634 action is either a lisp form or a command string containing
9635 '%1', i.e. using at least one subexpression match as a
9637 (let ((selector (car entry))
9638 (action (cdr entry)))
9639 (if (stringp selector)
9640 (and (> (regexp-opt-depth selector) 0)
9641 (or (and (stringp action)
9642 (string-match "%[0-9]" action))
9646 (defun org-default-apps ()
9647 "Return the default applications for this operating system."
9649 ((eq system-type 'darwin)
9650 org-file-apps-defaults-macosx)
9651 ((eq system-type 'windows-nt)
9652 org-file-apps-defaults-windowsnt)
9653 (t org-file-apps-defaults-gnu)))
9655 (defun org-apps-regexp-alist (list &optional add-auto-mode)
9656 "Convert extensions to regular expressions in the cars of LIST.
9657 Also, weed out any non-string entries, because the return value is used
9658 only for regexp matching.
9659 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
9660 point to the symbol `emacs', indicating that the file should
9661 be opened in Emacs."
9665 (if (not (stringp (car x)))
9667 (if (string-match "\\W" (car x))
9669 (cons (concat "\\." (car x) "\\'") (cdr x)))))
9672 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
9674 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
9675 (defun org-file-remote-p (file)
9676 "Test whether FILE specifies a location on a remote system.
9677 Return non-nil if the location is indeed remote.
9679 For example, the filename \"/user@host:/foo\" specifies a location
9680 on the system \"/user@host:\"."
9681 (cond ((fboundp 'file-remote-p)
9682 (file-remote-p file))
9683 ((fboundp 'tramp-handle-file-remote-p)
9684 (tramp-handle-file-remote-p file))
9685 ((and (boundp 'ange-ftp-name-format)
9686 (string-match (car ange-ftp-name-format) file))
9693 (defun org-get-org-file ()
9694 "Read a filename, with default directory `org-directory'."
9695 (let ((default (or org-default-notes-file remember-data-file)))
9696 (read-file-name (format "File name [%s]: " default)
9697 (file-name-as-directory org-directory)
9700 (defun org-notes-order-reversed-p ()
9701 "Check if the current file should receive notes in reversed order."
9703 ((not org-reverse-note-order) nil)
9704 ((eq t org-reverse-note-order) t)
9705 ((not (listp org-reverse-note-order)) nil)
9707 (let ((all org-reverse-note-order)
9709 (while (setq entry (pop all))
9710 (if (string-match (car entry) buffer-file-name)
9711 (throw 'exit (cdr entry))))
9714 (defvar org-refile-target-table nil
9715 "The list of refile targets, created by `org-refile'.")
9717 (defvar org-agenda-new-buffers nil
9718 "Buffers created to visit agenda files.")
9720 (defvar org-refile-cache nil
9721 "Cache for refile targets.")
9724 (defvar org-refile-markers nil
9725 "All the markers used for caching refile locations.")
9727 (defun org-refile-marker (pos)
9728 "Get a new refile marker, but only if caching is in use."
9729 (if (not org-refile-use-cache)
9731 (let ((m (make-marker)))
9733 (push m org-refile-markers)
9736 (defun org-refile-cache-clear ()
9737 "Clear the refile cache and disable all the markers."
9738 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
9739 (setq org-refile-markers nil)
9740 (setq org-refile-cache nil)
9741 (message "Refile cache has been cleared"))
9743 (defun org-refile-cache-check-set (set)
9744 "Check if all the markers in the cache still have live buffers."
9747 (while (and set (setq marker (nth 3 (pop set))))
9748 ;; if org-refile-use-outline-path is 'file, marker may be nil
9749 (when (and marker (null (marker-buffer marker)))
9750 (message "not found") (sit-for 3)
9754 (defun org-refile-cache-put (set &rest identifiers)
9755 "Push the refile targets SET into the cache, under IDENTIFIERS."
9756 (let* ((key (sha1 (prin1-to-string identifiers)))
9757 (entry (assoc key org-refile-cache)))
9760 (push (cons key set) org-refile-cache))))
9762 (defun org-refile-cache-get (&rest identifiers)
9763 "Retrieve the cached value for refile targets given by IDENTIFIERS."
9765 ((not org-refile-cache) nil)
9766 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
9768 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
9769 org-refile-cache))))
9770 (and set (org-refile-cache-check-set set) set)))))
9772 (defun org-get-refile-targets (&optional default-buffer)
9773 "Produce a table with refile targets."
9774 (let ((case-fold-search nil)
9775 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
9776 (entries (or org-refile-targets '((nil . (:level . 1)))))
9777 targets tgs txt re files f desc descre fast-path-p level pos0)
9778 (message "Getting targets...")
9779 (with-current-buffer (or default-buffer (current-buffer))
9780 (while (setq entry (pop entries))
9781 (setq files (car entry) desc (cdr entry))
9782 (setq fast-path-p nil)
9784 ((null files) (setq files (list (current-buffer))))
9785 ((eq files 'org-agenda-files)
9786 (setq files (org-agenda-files 'unrestricted)))
9787 ((and (symbolp files) (fboundp files))
9788 (setq files (funcall files)))
9789 ((and (symbolp files) (boundp files))
9790 (setq files (symbol-value files))))
9791 (if (stringp files) (setq files (list files)))
9793 ((eq (car desc) :tag)
9794 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
9795 ((eq (car desc) :todo)
9796 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
9797 ((eq (car desc) :regexp)
9798 (setq descre (cdr desc)))
9799 ((eq (car desc) :level)
9800 (setq descre (concat "^\\*\\{" (number-to-string
9801 (if org-odd-levels-only
9802 (1- (* 2 (cdr desc)))
9805 ((eq (car desc) :maxlevel)
9806 (setq fast-path-p t)
9807 (setq descre (concat "^\\*\\{1," (number-to-string
9808 (if org-odd-levels-only
9809 (1- (* 2 (cdr desc)))
9812 (t (error "Bad refiling target description %s" desc)))
9813 (while (setq f (pop files))
9814 (with-current-buffer
9815 (if (bufferp f) f (org-get-agenda-file-buffer f))
9817 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
9819 (if (bufferp f) (setq f (buffer-file-name
9820 (buffer-base-buffer f))))
9821 (setq f (and f (expand-file-name f)))
9822 (if (eq org-refile-use-outline-path 'file)
9823 (push (list (file-name-nondirectory f) f nil nil) tgs))
9827 (goto-char (point-min))
9828 (while (re-search-forward descre nil t)
9829 (goto-char (setq pos0 (point-at-bol)))
9831 (when org-refile-target-verify-function
9833 (or (funcall org-refile-target-verify-function)
9835 (when (looking-at org-complex-heading-regexp)
9836 (setq level (org-reduced-level
9837 (- (match-end 1) (match-beginning 1)))
9838 txt (org-link-display-format (match-string 4))
9839 re (concat "^" (regexp-quote
9843 (if (match-end 5) (setq re (concat
9846 (match-string 5)))))
9847 (setq re (concat re "[ \t]*$"))
9848 (when org-refile-use-outline-path
9849 (setq txt (mapconcat
9852 (if (eq org-refile-use-outline-path
9854 (list (file-name-nondirectory
9856 (buffer-base-buffer))))
9857 (if (eq org-refile-use-outline-path
9859 (list (buffer-file-name
9860 (buffer-base-buffer)))))
9861 (org-get-outline-path fast-path-p
9865 (push (list txt f re (org-refile-marker (point)))
9867 (when (= (point) pos0)
9868 ;; verification function has not moved point
9869 (goto-char (point-at-eol))))))))
9870 (when org-refile-use-cache
9871 (org-refile-cache-put tgs (buffer-file-name) descre))
9872 (setq targets (append tgs targets))
9874 (message "Getting targets...done")
9875 (nreverse targets)))
9877 (defun org-protect-slash (s)
9878 (while (string-match "/" s)
9879 (setq s (replace-match "\\" t t s)))
9882 (defvar org-olpa (make-vector 20 nil))
9884 (defun org-get-outline-path (&optional fastp level heading)
9885 "Return the outline path to the current entry, as a list.
9887 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
9888 routine which makes outline path derivations for an entire file,
9889 avoiding backtracing. Refile target collection makes use of that."
9893 (error "Outline path failure, more than 19 levels"))
9894 (loop for i from level upto 19 do
9895 (aset org-olpa i nil))
9897 (delq nil (append org-olpa nil))
9898 (aset org-olpa level heading)))
9899 (let (rtn case-fold-search)
9903 (while (org-up-heading-safe)
9904 (when (looking-at org-complex-heading-regexp)
9905 (push (org-match-string-no-properties 4) rtn)))
9908 (defun org-format-outline-path (path &optional width prefix)
9909 "Format the outline path PATH for display.
9910 Width is the maximum number of characters that is available.
9911 Prefix is a prefix to be included in the returned string,
9912 such as the file name."
9913 (setq width (or width 79))
9914 (if prefix (setq width (- width (length prefix))))
9917 (let* ((nsteps (length path))
9918 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
9919 (maxwidth (if (<= total-width width)
9920 10000 ;; everything fits
9921 ;; we need to shorten the level headings
9922 (/ (- width nsteps) nsteps)))
9923 (org-odd-levels-only nil)
9925 (total (1+ (length prefix))))
9926 (setq maxwidth (max maxwidth 10))
9931 (if (and (= n nsteps) (< maxwidth 10000))
9932 (setq maxwidth (- total-width total)))
9933 (if (< (length h) maxwidth)
9934 (progn (setq total (+ total (length h) 1)) h)
9935 (setq h (substring h 0 (- maxwidth 2))
9936 total (+ total maxwidth 1))
9937 (if (string-match "[ \t]+\\'" h)
9938 (setq h (substring h 0 (match-beginning 0))))
9939 (setq h (concat h "..")))
9940 (org-add-props h nil 'face
9941 (nth (% (1- n) org-n-level-faces)
9946 (defun org-display-outline-path (&optional file current)
9947 "Display the current outline path in the echo area."
9949 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
9950 (case-fold-search nil)
9951 (path (and (org-mode-p) (org-get-outline-path))))
9952 (if current (setq path (append path
9954 (org-back-to-heading t)
9955 (if (looking-at org-complex-heading-regexp)
9956 (list (match-string 4)))))))
9958 (org-format-outline-path
9961 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
9963 (defvar org-refile-history nil
9964 "History for refiling operations.")
9966 (defvar org-after-refile-insert-hook nil
9967 "Hook run after `org-refile' has inserted its stuff at the new location.
9968 Note that this is still *before* the stuff will be removed from
9969 the *old* location.")
9971 (defvar org-capture-last-stored-marker)
9972 (defun org-refile (&optional goto default-buffer rfloc)
9973 "Move the entry at point to another heading.
9974 The list of target headings is compiled using the information in
9975 `org-refile-targets', which see. This list is created before each use
9976 and will therefore always be up-to-date.
9978 At the target location, the entry is filed as a subitem of the target heading.
9979 Depending on `org-reverse-note-order', the new subitem will either be the
9980 first or the last subitem.
9982 If there is an active region, all entries in that region will be moved.
9983 However, the region must fulfill the requirement that the first heading
9984 is the first one sets the top-level of the moved text - at most siblings
9985 below it are allowed.
9987 With prefix arg GOTO, the command will only visit the target location,
9988 not actually move anything.
9989 With a double prefix arg \\[universal-argument] \\[universal-argument], \
9990 go to the location where the last refiling
9991 operation has put the subtree.
9992 With a prefix argument of `2', refile to the running clock.
9994 RFLOC can be a refile location obtained in a different way.
9996 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
9998 If you are using target caching (see `org-refile-use-cache'),
9999 You have to clear the target cache in order to find new targets.
10000 This can be done with a 0 prefix: `C-0 C-c C-w'"
10002 (if (member goto '(0 (64)))
10003 (org-refile-cache-clear)
10004 (let* ((cbuf (current-buffer))
10005 (regionp (org-region-active-p))
10006 (region-start (and regionp (region-beginning)))
10007 (region-end (and regionp (region-end)))
10008 (region-length (and regionp (- region-end region-start)))
10009 (filename (buffer-file-name (buffer-base-buffer cbuf)))
10010 pos it nbuf file re level reversed)
10011 (setq last-command nil)
10013 (goto-char region-start)
10014 (or (bolp) (goto-char (point-at-bol)))
10015 (setq region-start (point))
10016 (unless (org-kill-is-subtree-p
10017 (buffer-substring region-start region-end))
10018 (error "The region is not a (sequence of) subtree(s)")))
10019 (if (equal goto '(16))
10020 (org-refile-goto-last-stored)
10022 (and (equal goto 2)
10023 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10025 (setq it (list (or org-clock-heading "running clock")
10027 (marker-buffer org-clock-hd-marker))
10029 (marker-position org-clock-hd-marker)))
10033 (org-refile-get-location
10034 (if goto "Goto: " "Refile to: ") default-buffer
10035 org-refile-allow-creating-parent-nodes)))))
10036 (setq file (nth 1 it)
10039 (if (and (not goto)
10041 (equal (buffer-file-name) file)
10043 (and (>= pos region-start)
10044 (<= pos region-end))
10045 (and (>= pos (point))
10046 (< pos (save-excursion
10047 (org-end-of-subtree t t))))))
10048 (error "Cannot refile to position inside the tree or region"))
10050 (setq nbuf (or (find-buffer-visiting file)
10051 (find-file-noselect file)))
10054 (switch-to-buffer nbuf)
10056 (org-show-context 'org-goto))
10059 (org-kill-new (buffer-substring region-start region-end))
10060 (org-save-markers-in-region region-start region-end))
10061 (org-copy-subtree 1 nil t))
10062 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
10063 (find-file-noselect file)))
10064 (setq reversed (org-notes-order-reversed-p))
10071 (looking-at outline-regexp)
10072 (setq level (org-get-valid-level (funcall outline-level) 1))
10075 (or (outline-next-heading) (point-max))
10076 (or (save-excursion (org-get-next-sibling))
10077 (org-end-of-subtree t t)
10081 (goto-char (point-max))
10082 (goto-char (point-min))
10083 (or (outline-next-heading) (goto-char (point-max)))))
10084 (if (not (bolp)) (newline))
10085 (org-paste-subtree level)
10086 (when org-log-refile
10087 (org-add-log-setup 'refile nil nil 'findpos
10089 (unless (eq org-log-refile 'note)
10090 (save-excursion (org-add-log-note))))
10091 (and org-auto-align-tags (org-set-tags nil t))
10092 (bookmark-set "org-refile-last-stored")
10093 ;; If we are refiling for capture, make sure that the
10094 ;; last-capture pointers point here
10095 (when (org-bound-and-true-p org-refile-for-capture)
10096 (bookmark-set "org-capture-last-stored-marker")
10097 (move-marker org-capture-last-stored-marker (point)))
10098 (if (fboundp 'deactivate-mark) (deactivate-mark))
10099 (run-hooks 'org-after-refile-insert-hook))))
10101 (delete-region (point) (+ (point) region-length))
10103 (when (featurep 'org-inlinetask)
10104 (org-inlinetask-remove-END-maybe))
10105 (setq org-markers-to-move nil)
10106 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
10108 (defun org-refile-goto-last-stored ()
10109 "Go to the location where the last refile was stored."
10111 (bookmark-jump "org-refile-last-stored")
10112 (message "This is the location of the last refile"))
10114 (defun org-refile-get-location (&optional prompt default-buffer new-nodes)
10115 "Prompt the user for a refile location, using PROMPT."
10116 (let ((org-refile-targets org-refile-targets)
10117 (org-refile-use-outline-path org-refile-use-outline-path))
10118 (setq org-refile-target-table (org-get-refile-targets default-buffer)))
10119 (unless org-refile-target-table
10120 (error "No refile targets"))
10121 (let* ((cbuf (current-buffer))
10122 (partial-completion-mode nil)
10123 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
10124 (cfunc (if (and org-refile-use-outline-path
10125 org-outline-path-complete-in-steps)
10126 'org-olpath-completing-read
10127 'org-icompleting-read))
10128 (extra (if org-refile-use-outline-path "/" ""))
10129 (filename (and cfn (expand-file-name cfn)))
10132 (if (and (not (member org-refile-use-outline-path
10133 '(file full-file-path)))
10134 (not (equal filename (nth 1 x))))
10135 (cons (concat (car x) extra " ("
10136 (file-name-nondirectory (nth 1 x)) ")")
10138 (cons (concat (car x) extra) (cdr x))))
10139 org-refile-target-table))
10140 (completion-ignore-case t)
10141 pa answ parent-target child parent old-hist)
10142 (setq old-hist org-refile-history)
10143 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
10144 nil 'org-refile-history))
10145 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
10148 (when (or (not org-refile-history)
10149 (not (eq old-hist org-refile-history))
10150 (not (equal (car pa) (car org-refile-history))))
10151 (setq org-refile-history
10152 (cons (car pa) (if (assoc (car org-refile-history) tbl)
10154 (cdr org-refile-history))))
10155 (if (equal (car org-refile-history) (nth 1 org-refile-history))
10156 (pop org-refile-history)))
10158 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
10160 (setq parent (match-string 1 answ)
10161 child (match-string 2 answ))
10162 (setq parent-target (or (assoc parent tbl)
10163 (assoc (concat parent "/") tbl)))
10164 (when (and parent-target
10165 (or (eq new-nodes t)
10166 (and (eq new-nodes 'confirm)
10167 (y-or-n-p (format "Create new node \"%s\"? "
10169 (org-refile-new-child parent-target child)))
10170 (error "Invalid target location")))))
10172 (defun org-refile-new-child (parent-target child)
10173 "Use refile target PARENT-TARGET to add new CHILD below it."
10174 (unless parent-target
10175 (error "Cannot find parent for new node"))
10176 (let ((file (nth 1 parent-target))
10177 (pos (nth 3 parent-target))
10179 (with-current-buffer (or (find-buffer-visiting file)
10180 (find-file-noselect file))
10186 (goto-char (point-max))
10187 (if (not (bolp)) (newline)))
10188 (when (looking-at outline-regexp)
10189 (setq level (funcall outline-level))
10190 (org-end-of-subtree t t))
10191 (org-back-over-empty-lines)
10192 (insert "\n" (make-string
10193 (if pos (org-get-valid-level level 1) 1) ?*)
10195 (beginning-of-line 0)
10196 (list (concat (car parent-target) "/" child) file "" (point)))))))
10198 (defun org-olpath-completing-read (prompt collection &rest args)
10199 "Read an outline path like a file name."
10200 (let ((thetable collection)
10201 (org-completion-use-ido nil) ; does not work with ido.
10202 (org-completion-use-iswitchb nil)) ; or iswitchb
10204 'org-icompleting-read prompt
10205 (lambda (string predicate &optional flag)
10206 (let (rtn r f (l (length string)))
10210 (try-completion string thetable))
10213 (setq rtn (all-completions string thetable predicate))
10216 (setq r (substring x l))
10217 (if (string-match " ([^)]*)$" x)
10218 (setq f (match-string 0 x))
10220 (if (string-match "/" r)
10221 (concat string (substring r 0 (match-end 0)) f)
10226 (assoc string thetable)))
10230 ;;;; Dynamic blocks
10232 (defun org-find-dblock (name)
10233 "Find the first dynamic block with name NAME in the buffer.
10234 If not found, stay at current position and return nil."
10237 (goto-char (point-min))
10238 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
10240 (match-beginning 0))))
10241 (if pos (goto-char pos))
10244 (defconst org-dblock-start-re
10245 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
10246 "Matches the start line of a dynamic block, with parameters.")
10248 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
10249 "Matches the end of a dynamic block.")
10251 (defun org-create-dblock (plist)
10252 "Create a dynamic block section, with parameters taken from PLIST.
10253 PLIST must contain a :name entry which is used as name of the block."
10254 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
10257 (let ((col (current-column))
10258 (name (plist-get plist :name)))
10259 (insert "#+BEGIN: " name)
10261 (if (eq (car plist) :name)
10262 (setq plist (cddr plist))
10263 (insert " " (prin1-to-string (pop plist)))))
10264 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
10265 (beginning-of-line -2)))
10267 (defun org-prepare-dblock ()
10268 "Prepare dynamic block for refresh.
10269 This empties the block, puts the cursor at the insert position and returns
10270 the property list including an extra property :name with the block name."
10271 (unless (looking-at org-dblock-start-re)
10272 (error "Not at a dynamic block"))
10273 (let* ((begdel (1+ (match-end 0)))
10274 (name (org-no-properties (match-string 1)))
10275 (params (append (list :name name)
10276 (read (concat "(" (match-string 3) ")")))))
10278 (beginning-of-line 1)
10279 (skip-chars-forward " \t")
10280 (setq params (plist-put params :indentation-column (current-column))))
10281 (unless (re-search-forward org-dblock-end-re nil t)
10282 (error "Dynamic block not terminated"))
10285 (list :content (buffer-substring
10286 begdel (match-beginning 0)))))
10287 (delete-region begdel (match-beginning 0))
10292 (defun org-map-dblocks (&optional command)
10293 "Apply COMMAND to all dynamic blocks in the current buffer.
10294 If COMMAND is not given, use `org-update-dblock'."
10295 (let ((cmd (or command 'org-update-dblock)))
10297 (goto-char (point-min))
10298 (while (re-search-forward org-dblock-start-re nil t)
10299 (goto-char (match-beginning 0))
10301 (condition-case nil
10303 (error (message "Error during update of dynamic block"))))
10304 (unless (re-search-forward org-dblock-end-re nil t)
10305 (error "Dynamic block not terminated"))))))
10307 (defun org-dblock-update (&optional arg)
10308 "User command for updating dynamic blocks.
10309 Update the dynamic block at point. With prefix ARG, update all dynamic
10310 blocks in the buffer."
10313 (org-update-all-dblocks)
10314 (or (looking-at org-dblock-start-re)
10315 (org-beginning-of-dblock))
10316 (org-update-dblock)))
10318 (defun org-update-dblock ()
10319 "Update the dynamic block at point.
10320 This means to empty the block, parse for parameters and then call
10321 the correct writing function."
10322 (save-window-excursion
10323 (let* ((pos (point))
10324 (line (org-current-line))
10325 (params (org-prepare-dblock))
10326 (name (plist-get params :name))
10327 (indent (plist-get params :indentation-column))
10328 (cmd (intern (concat "org-dblock-write:" name))))
10329 (message "Updating dynamic block `%s' at line %d..." name line)
10330 (funcall cmd params)
10331 (message "Updating dynamic block `%s' at line %d...done" name line)
10333 (when (and indent (> indent 0))
10334 (setq indent (make-string indent ?\ ))
10336 (org-beginning-of-dblock)
10338 (while (not (looking-at org-dblock-end-re))
10340 (beginning-of-line 2))
10341 (when (looking-at org-dblock-end-re)
10342 (and (looking-at "[ \t]+")
10343 (replace-match ""))
10344 (insert indent)))))))
10346 (defun org-beginning-of-dblock ()
10347 "Find the beginning of the dynamic block at point.
10348 Error if there is no such block at point."
10349 (let ((pos (point))
10352 (if (and (re-search-backward org-dblock-start-re nil t)
10353 (setq beg (match-beginning 0))
10354 (re-search-forward org-dblock-end-re nil t)
10355 (> (match-end 0) pos))
10358 (error "Not in a dynamic block"))))
10360 (defun org-update-all-dblocks ()
10361 "Update all dynamic blocks in the buffer.
10362 This function can be used in a hook."
10364 (org-map-dblocks 'org-update-dblock)))
10369 (defconst org-additional-option-like-keywords
10370 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML"
10371 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook"
10372 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
10373 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX"
10375 "ORGTBL" "TBLFM:" "TBLNAME:"
10376 "BEGIN_EXAMPLE" "END_EXAMPLE"
10377 "BEGIN_QUOTE" "END_QUOTE"
10378 "BEGIN_VERSE" "END_VERSE"
10379 "BEGIN_CENTER" "END_CENTER"
10380 "BEGIN_SRC" "END_SRC"
10381 "CATEGORY" "COLUMNS"
10387 (defcustom org-structure-template-alist
10389 ("s" "#+begin_src ?\n\n#+end_src"
10390 "<src lang=\"?\">\n\n</src>")
10391 ("e" "#+begin_example\n?\n#+end_example"
10392 "<example>\n?\n</example>")
10393 ("q" "#+begin_quote\n?\n#+end_quote"
10394 "<quote>\n?\n</quote>")
10395 ("v" "#+begin_verse\n?\n#+end_verse"
10396 "<verse>\n?\n/verse>")
10397 ("c" "#+begin_center\n?\n#+end_center"
10398 "<center>\n?\n/center>")
10399 ("l" "#+begin_latex\n?\n#+end_latex"
10400 "<literal style=\"latex\">\n?\n</literal>")
10402 "<literal style=\"latex\">?</literal>")
10403 ("h" "#+begin_html\n?\n#+end_html"
10404 "<literal style=\"html\">\n?\n</literal>")
10406 "<literal style=\"html\">?</literal>")
10407 ("a" "#+begin_ascii\n?\n#+end_ascii")
10409 ("i" "#+include %file ?"
10410 "<include file=%file markup=\"?\">")
10412 "Structure completion elements.
10413 This is a list of abbreviation keys and values. The value gets inserted
10414 if you type `<' followed by the key and then press the completion key,
10415 usually `M-TAB'. %file will be replaced by a file name after prompting
10416 for the file using completion.
10417 There are two templates for each key, the first uses the original Org syntax,
10418 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
10419 the default when the /org-mtags.el/ module has been loaded. See also the
10420 variable `org-mtags-prefer-muse-templates'.
10421 This is an experimental feature, it is undecided if it is going to stay in."
10422 :group 'org-completion
10424 (string :tag "Key")
10425 (string :tag "Template")
10426 (string :tag "Muse Template")))
10428 (defun org-try-structure-completion ()
10429 "Try to complete a structure template before point.
10430 This looks for strings like \"<e\" on an otherwise empty line and
10432 (let ((l (buffer-substring (point-at-bol) (point)))
10434 (when (and (looking-at "[ \t]*$")
10435 (string-match "^[ \t]*<\\([a-z]+\\)$"l)
10436 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
10437 (org-complete-expand-structure-template (+ -1 (point-at-bol)
10438 (match-beginning 1)) a)
10441 (defun org-complete-expand-structure-template (start cell)
10442 "Expand a structure template."
10443 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
10444 (rpl (nth (if musep 2 1) cell))
10446 (delete-region start (point))
10447 (when (string-match "\\`#\\+" rpl)
10450 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
10451 (setq ind (buffer-substring (point-at-bol) (point))))
10453 (setq start (point))
10454 (if (string-match "%file" rpl)
10455 (setq rpl (replace-match
10459 (abbreviate-file-name (read-file-name "Include file: ")))
10462 (setq rpl (mapconcat 'identity (split-string rpl "\n")
10463 (concat "\n" ind)))
10465 (if (re-search-backward "\\?" start t) (delete-char 1))))
10468 (defun org-complete (&optional arg)
10469 "Perform completion on word at point.
10470 At the beginning of a headline, this completes TODO keywords as given in
10471 `org-todo-keywords'.
10472 If the current word is preceded by a backslash, completes the TeX symbols
10473 that are supported for HTML support.
10474 If the current word is preceded by \"#+\", completes special words for
10475 setting file options.
10476 In the line after \"#+STARTUP:, complete valid keywords.\"
10477 At all other locations, this simply calls the value of
10478 `org-completion-fallback-command'."
10480 (org-without-partial-completion
10484 (beg1 (save-excursion
10485 (skip-chars-backward (org-re "[:alnum:]_@"))
10487 (beg (save-excursion
10488 (skip-chars-backward "a-zA-Z0-9_:$")
10490 (confirm (lambda (x) (stringp (car x))))
10491 (searchhead (equal (char-before beg) ?*))
10493 (when (and (member (char-before beg1) '(?. ?<))
10494 (setq a (assoc (buffer-substring beg1 (point))
10495 org-structure-template-alist)))
10496 (org-complete-expand-structure-template (1- beg1) a)
10498 (tag (and (equal (char-before beg1) ?:)
10499 (equal (char-after (point-at-bol)) ?*)))
10500 (prop (and (equal (char-before beg1) ?:)
10501 (not (equal (char-after (point-at-bol)) ?*))))
10502 (texp (equal (char-before beg) ?\\))
10503 (link (equal (char-before beg) ?\[))
10504 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
10507 (startup (string-match "^#\\+STARTUP:.*"
10508 (buffer-substring (point-at-bol) (point))))
10509 (completion-ignore-case opt)
10521 "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
10522 (cons (match-string 2 x)
10523 (match-string 1 x))))
10524 (org-split-string (org-get-current-options) "\n")))
10525 (mapcar 'list org-additional-option-like-keywords)))
10527 (setq type :startup)
10528 org-startup-options)
10529 (link (append org-link-abbrev-alist-local
10530 org-link-abbrev-alist))
10533 (append org-entities-user org-entities))
10534 ((string-match "\\`\\*+[ \t]+\\'"
10535 (buffer-substring (point-at-bol) beg))
10537 (mapcar 'list org-todo-keywords-1))
10539 (setq type :searchhead)
10541 (goto-char (point-min))
10542 (while (re-search-forward org-todo-line-regexp nil t)
10544 (org-make-org-heading-search-string
10545 (match-string 3) t))
10548 (tag (setq type :tag beg beg1)
10549 (or org-tag-alist (org-get-buffer-tags)))
10550 (prop (setq type :prop beg beg1)
10551 (mapcar 'list (org-buffer-property-keys nil t t)))
10553 (call-interactively org-completion-fallback-command)
10554 (throw 'exit nil)))))
10555 (pattern (buffer-substring-no-properties beg end))
10556 (completion (try-completion pattern table confirm)))
10557 (cond ((eq completion t)
10558 (if (not (assoc (upcase pattern) table))
10559 (message "Already complete")
10560 (if (and (equal type :opt)
10561 (not (member (car (assoc (upcase pattern) table))
10562 org-additional-option-like-keywords)))
10563 (insert (substring (cdr (assoc (upcase pattern) table))
10565 (if (memq type '(:tag :prop)) (insert ":")))))
10567 (message "Can't find completion for \"%s\"" pattern)
10569 ((not (string= pattern completion))
10570 (delete-region beg end)
10571 (if (string-match " +$" completion)
10572 (setq completion (replace-match "" t t completion)))
10573 (insert completion)
10574 (if (get-buffer-window "*Completions*")
10575 (delete-window (get-buffer-window "*Completions*")))
10576 (if (assoc completion table)
10577 (if (eq type :todo) (insert " ")
10578 (if (memq type '(:tag :prop)) (insert ":"))))
10579 (if (and (equal type :opt) (assoc completion table))
10580 (message "%s" (substitute-command-keys
10581 "Press \\[org-complete] again to insert example settings"))))
10583 (message "Making completion list...")
10584 (let ((list (sort (all-completions pattern table confirm)
10586 (with-output-to-temp-buffer "*Completions*"
10587 (condition-case nil
10588 ;; Protection needed for XEmacs and emacs 21
10589 (display-completion-list list pattern)
10590 (error (display-completion-list list)))))
10591 (message "Making completion list...%s" "done")))))))
10593 ;;;; TODO, DEADLINE, Comments
10595 (defun org-toggle-comment ()
10596 "Change the COMMENT state of an entry."
10599 (org-back-to-heading)
10600 (let (case-fold-search)
10601 (if (looking-at (concat outline-regexp
10602 "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
10603 (replace-match "" t t nil 1)
10604 (if (looking-at outline-regexp)
10606 (goto-char (match-end 0))
10607 (insert org-comment-string " ")))))))
10609 (defvar org-last-todo-state-is-todo nil
10610 "This is non-nil when the last TODO state change led to a TODO state.
10611 If the last change removed the TODO tag or switched to DONE, then
10614 (defvar org-setting-tags nil) ; dynamically skipped
10616 (defun org-parse-local-options (string var)
10617 "Parse STRING for startup setting relevant for variable VAR."
10618 (let ((rtn (symbol-value var))
10621 (if (or (not string) (not (string-match "\\S-" string)))
10623 (setq opts (delq nil (mapcar (lambda (x)
10624 (setq e (assoc x org-startup-options))
10625 (if (eq (nth 1 e) var) e nil))
10626 (org-split-string string "[ \t]+"))))
10630 (while (setq e (pop opts))
10631 (if (not (nth 3 e))
10632 (setq rtn (nth 2 e))
10633 (if (not (listp rtn)) (setq rtn nil))
10634 (push (nth 2 e) rtn)))
10637 (defvar org-todo-setup-filter-hook nil
10638 "Hook for functions that pre-filter todo specs.
10639 Each function takes a todo spec and returns either nil or the spec
10640 transformed into canonical form." )
10642 (defvar org-todo-get-default-hook nil
10643 "Hook for functions that get a default item for todo.
10644 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
10645 nil or a string to be used for the todo mark." )
10647 (defvar org-agenda-headline-snapshot-before-repeat)
10649 (defun org-todo (&optional arg)
10650 "Change the TODO state of an item.
10651 The state of an item is given by a keyword at the start of the heading,
10653 *** TODO Write paper
10656 The different keywords are specified in the variable `org-todo-keywords'.
10657 By default the available states are \"TODO\" and \"DONE\".
10658 So for this example: when the item starts with TODO, it is changed to DONE.
10659 When it starts with DONE, the DONE is removed. And when neither TODO nor
10660 DONE are present, add TODO at the beginning of the heading.
10662 With \\[universal-argument] prefix arg, use completion to determine the new \
10664 With numeric prefix arg, switch to that state.
10665 With a double \\[universal-argument] prefix, switch to the next set of TODO \
10666 keywords (nextset).
10667 With a triple \\[universal-argument] prefix, circumvent any state blocking.
10669 For calling through lisp, arg is also interpreted in the following way:
10670 'none -> empty state
10671 \"\"(empty string) -> switch to empty state
10672 'done -> switch to DONE
10673 'nextset -> switch to the next set of keywords
10674 'previousset -> switch to the previous set of keywords
10675 \"WAITING\" -> switch to the specified keyword, but only if it
10676 really is a member of `org-todo-keywords'."
10678 (if (equal arg '(16)) (setq arg 'nextset))
10679 (let ((org-blocker-hook org-blocker-hook)
10680 (case-fold-search nil))
10681 (when (equal arg '(64))
10682 (setq arg nil org-blocker-hook nil))
10683 (when (and org-blocker-hook
10684 (or org-inhibit-blocking
10685 (org-entry-get nil "NOBLOCKING")))
10686 (setq org-blocker-hook nil))
10689 (org-back-to-heading t)
10690 (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
10691 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|$\\)"))
10693 (let* ((match-data (match-data))
10694 (startpos (point-at-bol))
10695 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
10696 (org-log-done org-log-done)
10697 (org-log-repeat org-log-repeat)
10698 (org-todo-log-states org-todo-log-states)
10699 (this (match-string 1))
10700 (hl-pos (match-beginning 0))
10701 (head (org-get-todo-sequence-head this))
10702 (ass (assoc head org-todo-kwd-alist))
10703 (interpret (nth 1 ass))
10704 (done-word (nth 3 ass))
10705 (final-done-word (nth 4 ass))
10706 (last-state (or this ""))
10707 (completion-ignore-case t)
10708 (member (member this org-todo-keywords-1))
10709 (tail (cdr member))
10711 ((and org-todo-key-trigger
10712 (or (and (equal arg '(4))
10713 (eq org-use-fast-todo-selection 'prefix))
10714 (and (not arg) org-use-fast-todo-selection
10715 (not (eq org-use-fast-todo-selection
10717 ;; Use fast selection
10718 (org-fast-todo-selection))
10719 ((and (equal arg '(4))
10720 (or (not org-use-fast-todo-selection)
10721 (not org-todo-key-trigger)))
10722 ;; Read a state with completion
10723 (org-icompleting-read
10724 "State: " (mapcar (lambda(x) (list x))
10725 org-todo-keywords-1)
10729 (if tail (car tail) nil)
10730 (car org-todo-keywords-1)))
10732 (if (equal member org-todo-keywords-1)
10735 (nth (- (length org-todo-keywords-1)
10737 org-todo-keywords-1)
10738 (org-last org-todo-keywords-1))))
10739 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
10740 (setq arg nil))) ; hack to fall back to cycling
10742 ;; user or caller requests a specific state
10744 ((equal arg "") nil)
10745 ((eq arg 'none) nil)
10746 ((eq arg 'done) (or done-word (car org-done-keywords)))
10748 (or (car (cdr (member head org-todo-heads)))
10749 (car org-todo-heads)))
10750 ((eq arg 'previousset)
10751 (let ((org-todo-heads (reverse org-todo-heads)))
10752 (or (car (cdr (member head org-todo-heads)))
10753 (car org-todo-heads))))
10754 ((car (member arg org-todo-keywords-1)))
10756 (error "State `%s' not valid in this file" arg))
10757 ((nth (1- (prefix-numeric-value arg))
10758 org-todo-keywords-1))))
10759 ((null member) (or head (car org-todo-keywords-1)))
10760 ((equal this final-done-word) nil) ;; -> make empty
10761 ((null tail) nil) ;; -> first entry
10762 ((memq interpret '(type priority))
10763 (if (eq this-command last-command)
10765 (if (> (length tail) 0)
10766 (or done-word (car org-done-keywords))
10771 (run-hook-with-args-until-success
10772 'org-todo-get-default-hook state last-state)
10774 (next (if state (concat " " state " ") " "))
10775 (change-plist (list :type 'todo-state-change :from this :to state
10776 :position startpos))
10778 (when org-blocker-hook
10779 (setq org-last-todo-state-is-todo
10780 (not (member this org-done-keywords)))
10781 (unless (save-excursion
10783 (run-hook-with-args-until-failure
10784 'org-blocker-hook change-plist)))
10785 (if (interactive-p)
10786 (error "TODO state change from %s to %s blocked" this state)
10788 (message "TODO state change from %s to %s blocked" this state)
10789 (throw 'exit nil))))
10790 (store-match-data match-data)
10791 (replace-match next t t)
10792 (unless (pos-visible-in-window-p hl-pos)
10793 (message "TODO state changed to %s" (org-trim next)))
10795 (setq head (org-get-todo-sequence-head state)
10796 ass (assoc head org-todo-kwd-alist)
10797 interpret (nth 1 ass)
10798 done-word (nth 3 ass)
10799 final-done-word (nth 4 ass)))
10800 (when (memq arg '(nextset previousset))
10801 (message "Keyword-Set %d/%d: %s"
10802 (- (length org-todo-sets) -1
10803 (length (memq (assoc state org-todo-sets) org-todo-sets)))
10804 (length org-todo-sets)
10805 (mapconcat 'identity (assoc state org-todo-sets) " ")))
10806 (setq org-last-todo-state-is-todo
10807 (not (member state org-done-keywords)))
10808 (setq now-done-p (and (member state org-done-keywords)
10809 (not (member this org-done-keywords))))
10810 (and logging (org-local-logging logging))
10811 (when (and (or org-todo-log-states org-log-done)
10812 (not (eq org-inhibit-logging t))
10813 (not (memq arg '(nextset previousset))))
10814 ;; we need to look at recording a time and note
10815 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
10816 (nth 2 (assoc this org-todo-log-states))))
10817 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
10818 (setq dolog 'time))
10820 (member state org-not-done-keywords)
10821 (not (member this org-not-done-keywords)))
10822 ;; This is now a todo state and was not one before
10823 ;; If there was a CLOSED time stamp, get rid of it.
10824 (org-add-planning-info nil nil 'closed))
10825 (when (and now-done-p org-log-done)
10826 ;; It is now done, and it was not done before
10827 (org-add-planning-info 'closed (org-current-time))
10828 (if (and (not dolog) (eq 'note org-log-done))
10829 (org-add-log-setup 'done state this 'findpos 'note)))
10830 (when (and state dolog)
10831 ;; This is a non-nil state, and we need to log it
10832 (org-add-log-setup 'state state this 'findpos dolog)))
10833 ;; Fixup tag positioning
10834 (org-todo-trigger-tag-changes state)
10835 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
10836 (when org-provide-todo-statistics
10837 (org-update-parent-todo-statistics))
10838 (run-hooks 'org-after-todo-state-change-hook)
10839 (if (and arg (not (member state org-done-keywords)))
10840 (setq head (org-get-todo-sequence-head state)))
10841 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
10842 ;; Do we need to trigger a repeat?
10844 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
10845 ;; This is for the agenda, take a snapshot of the headline.
10847 (setq org-agenda-headline-snapshot-before-repeat
10848 (org-get-heading))))
10849 (org-auto-repeat-maybe state))
10850 ;; Fixup cursor location if close to the keyword
10851 (if (and (outline-on-heading-p)
10853 (save-excursion (beginning-of-line 1)
10854 (looking-at org-todo-line-regexp))
10855 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
10857 (goto-char (or (match-end 2) (match-end 1)))
10858 (and (looking-at " ") (just-one-space))))
10859 (when org-trigger-hook
10861 (run-hook-with-args 'org-trigger-hook change-plist))))))))
10863 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
10864 "Block turning an entry into a TODO, using the hierarchy.
10865 This checks whether the current task should be blocked from state
10866 changes. Such blocking occurs when:
10868 1. The task has children which are not all in a completed state.
10870 2. A task has a parent with the property :ORDERED:, and there
10871 are siblings prior to the current task with incomplete
10874 3. The parent of the task is blocked because it has siblings that should
10875 be done first, or is child of a block grandparent TODO entry."
10877 (if (not org-enforce-todo-dependencies)
10878 t ; if locally turned off don't block
10880 ;; If this is not a todo state change, or if this entry is already DONE,
10882 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10883 (member (plist-get change-plist :from)
10884 (cons 'done org-done-keywords))
10885 (member (plist-get change-plist :to)
10886 (cons 'todo org-not-done-keywords))
10887 (not (plist-get change-plist :to)))
10888 (throw 'dont-block t))
10889 ;; If this task has children, and any are undone, it's blocked
10891 (org-back-to-heading t)
10892 (let ((this-level (funcall outline-level)))
10893 (outline-next-heading)
10894 (let ((child-level (funcall outline-level)))
10895 (while (and (not (eobp))
10896 (> child-level this-level))
10897 ;; this todo has children, check whether they are all
10899 (if (and (not (org-entry-is-done-p))
10900 (org-entry-is-todo-p))
10901 (throw 'dont-block nil))
10902 (outline-next-heading)
10903 (setq child-level (funcall outline-level))))))
10904 ;; Otherwise, if the task's parent has the :ORDERED: property, and
10905 ;; any previous siblings are undone, it's blocked
10907 (org-back-to-heading t)
10908 (let* ((pos (point))
10909 (parent-pos (and (org-up-heading-safe) (point))))
10910 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10911 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10913 (re-search-forward org-not-done-heading-regexp pos t))
10914 (throw 'dont-block nil)) ; block, there is an older sibling not done.
10915 ;; Search further up the hierarchy, to see if an anchestor is blocked
10917 (goto-char parent-pos)
10918 (if (not (looking-at org-not-done-heading-regexp))
10919 (throw 'dont-block t)) ; do not block, parent is not a TODO
10921 (setq parent-pos (and (org-up-heading-safe) (point)))
10922 (if (not parent-pos) (throw 'dont-block t)) ; no parent
10923 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
10925 (re-search-forward org-not-done-heading-regexp pos t))
10926 (throw 'dont-block nil)))))))) ; block, older sibling not done.
10928 (defcustom org-track-ordered-property-with-tag nil
10929 "Should the ORDERED property also be shown as a tag?
10930 The ORDERED property decides if an entry should require subtasks to be
10931 completed in sequence. Since a property is not very visible, setting
10932 this option means that toggling the ORDERED property with the command
10933 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
10934 not relevant for the behavior, but it makes things more visible.
10936 Note that toggling the tag with tags commands will not change the property
10937 and therefore not influence behavior!
10939 This can be t, meaning the tag ORDERED should be used, It can also be a
10940 string to select a different tag for this task."
10943 (const :tag "No tracking" nil)
10944 (const :tag "Track with ORDERED tag" t)
10945 (string :tag "Use other tag")))
10947 (defun org-toggle-ordered-property ()
10948 "Toggle the ORDERED property of the current entry.
10949 For better visibility, you can track the value of this property with a tag.
10950 See variable `org-track-ordered-property-with-tag'."
10952 (let* ((t1 org-track-ordered-property-with-tag)
10953 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
10955 (org-back-to-heading)
10956 (if (org-entry-get nil "ORDERED")
10958 (org-delete-property "ORDERED")
10959 (and tag (org-toggle-tag tag 'off))
10960 (message "Subtasks can be completed in arbitrary order"))
10961 (org-entry-put nil "ORDERED" "t")
10962 (and tag (org-toggle-tag tag 'on))
10963 (message "Subtasks must be completed in sequence")))))
10965 (defvar org-blocked-by-checkboxes) ; dynamically scoped
10966 (defun org-block-todo-from-checkboxes (change-plist)
10967 "Block turning an entry into a TODO, using checkboxes.
10968 This checks whether the current task should be blocked from state
10969 changes because there are unchecked boxes in this entry."
10970 (if (not org-enforce-todo-checkbox-dependencies)
10971 t ; if locally turned off don't block
10973 ;; If this is not a todo state change, or if this entry is already DONE,
10975 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
10976 (member (plist-get change-plist :from)
10977 (cons 'done org-done-keywords))
10978 (member (plist-get change-plist :to)
10979 (cons 'todo org-not-done-keywords))
10980 (not (plist-get change-plist :to)))
10981 (throw 'dont-block t))
10982 ;; If this task has checkboxes that are not checked, it's blocked
10984 (org-back-to-heading t)
10985 (let ((beg (point)) end)
10986 (outline-next-heading)
10989 (if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
10992 (if (boundp 'org-blocked-by-checkboxes)
10993 (setq org-blocked-by-checkboxes t))
10994 (throw 'dont-block nil)))))
10995 t))) ; do not block
10997 (defun org-entry-blocked-p ()
10998 "Is the current entry blocked?"
10999 (if (org-entry-get nil "NOBLOCKING")
11000 nil ;; Never block this entry
11002 (run-hook-with-args-until-failure
11004 (list :type 'todo-state-change
11009 (defun org-update-statistics-cookies (all)
11010 "Update the statistics cookie, either from TODO or from checkboxes.
11011 This should be called with the cursor in a line with a statistics cookie."
11015 (org-update-checkbox-count 'all)
11016 (org-map-entries 'org-update-parent-todo-statistics))
11017 (if (not (org-on-heading-p))
11018 (org-update-checkbox-count)
11019 (let ((pos (move-marker (make-marker) (point)))
11021 (ignore-errors (org-back-to-heading t))
11022 (if (not (org-on-heading-p))
11023 (org-update-checkbox-count)
11024 (setq l1 (org-outline-level))
11025 (setq end (save-excursion
11026 (outline-next-heading)
11027 (if (org-on-heading-p) (setq l2 (org-outline-level)))
11029 (if (and (save-excursion
11031 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11032 (not (save-excursion (re-search-forward
11033 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11034 (org-update-checkbox-count)
11035 (if (and l2 (> l2 l1))
11038 (org-update-parent-todo-statistics))
11040 (beginning-of-line 1)
11041 (while (re-search-forward
11042 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11044 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11046 (move-marker pos nil)))))
11048 (defvar org-entry-property-inherited-from) ;; defined below
11049 (defun org-update-parent-todo-statistics ()
11050 "Update any statistics cookie in the parent of the current headline.
11051 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11052 the entire subtree and this will travel up the hierarchy and update
11053 statistics everywhere."
11055 (let* ((lim 0) prop
11056 (recursive (or (not org-hierarchical-todo-statistics)
11059 (or (setq prop (org-entry-get
11060 nil "COOKIE_DATA" 'inherit)) ""))))
11061 (lim (or (and prop (marker-position
11062 org-entry-property-inherited-from))
11065 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11066 level ltoggle l1 new ndel
11067 (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
11070 (beginning-of-line 1)
11071 (if (org-at-heading-p)
11072 (setq ltoggle (funcall outline-level))
11073 (error "This should not happen"))
11074 (while (and (setq level (org-up-heading-safe))
11075 (or recursive first)
11077 (setq first nil cookie-present nil)
11086 (while (re-search-forward box-re (point-at-eol) t)
11087 (setq cnt-all 0 cnt-done 0 cookie-present t)
11088 (setq is-percent (match-end 2))
11090 (unless (outline-next-heading) (throw 'exit nil))
11091 (while (and (looking-at org-complex-heading-regexp)
11092 (> (setq l1 (length (match-string 1))) level))
11093 (setq kwd (and (or recursive (= l1 ltoggle))
11095 (if (or (eq org-provide-todo-statistics 'all-headlines)
11096 (and (listp org-provide-todo-statistics)
11097 (or (member kwd org-provide-todo-statistics)
11098 (member kwd org-done-keywords))))
11099 (setq cnt-all (1+ cnt-all))
11100 (if (eq org-provide-todo-statistics t)
11101 (and kwd (setq cnt-all (1+ cnt-all)))))
11102 (and (member kwd org-done-keywords)
11103 (setq cnt-done (1+ cnt-done)))
11104 (outline-next-heading)))
11107 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
11108 (format "[%d/%d]" cnt-done cnt-all))
11109 ndel (- (match-end 0) (match-beginning 0)))
11110 (goto-char (match-beginning 0))
11112 (delete-region (point) (+ (point) ndel)))
11113 (when cookie-present
11114 (run-hook-with-args 'org-after-todo-statistics-hook
11115 cnt-done (- cnt-all cnt-done))))))
11116 (run-hooks 'org-todo-statistics-hook)))
11118 (defvar org-after-todo-statistics-hook nil
11119 "Hook that is called after a TODO statistics cookie has been updated.
11120 Each function is called with two arguments: the number of not-done entries
11121 and the number of done entries.
11123 For example, the following function, when added to this hook, will switch
11124 an entry to DONE when all children are done, and back to TODO when new
11125 entries are set to a TODO status. Note that this hook is only called
11126 when there is a statistics cookie in the headline!
11128 (defun org-summary-todo (n-done n-not-done)
11129 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
11130 (let (org-log-done org-log-states) ; turn off logging
11131 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
11134 (defvar org-todo-statistics-hook nil
11135 "Hook that is run whenever Org thinks TODO statistics should be updated.
11136 This hook runs even if there is no statistics cookie present, in which case
11137 `org-after-todo-statistics-hook' would not run.")
11139 (defun org-todo-trigger-tag-changes (state)
11140 "Apply the changes defined in `org-todo-state-tags-triggers'."
11141 (let ((l org-todo-state-tags-triggers)
11143 (when (or (not state) (equal state ""))
11144 (setq changes (append changes (cdr (assoc "" l)))))
11145 (when (and (stringp state) (> (length state) 0))
11146 (setq changes (append changes (cdr (assoc state l)))))
11147 (when (member state org-not-done-keywords)
11148 (setq changes (append changes (cdr (assoc 'todo l)))))
11149 (when (member state org-done-keywords)
11150 (setq changes (append changes (cdr (assoc 'done l)))))
11151 (dolist (c changes)
11152 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
11154 (defun org-local-logging (value)
11155 "Get logging settings from a property VALUE."
11157 ;; directly set the variables, they are already local.
11158 (setq org-log-done nil
11160 org-todo-log-states nil)
11161 (setq words (org-split-string value))
11162 (while (setq w (pop words))
11164 ((setq a (assoc w org-startup-options))
11165 (and (member (nth 1 a) '(org-log-done org-log-repeat))
11166 (set (nth 1 a) (nth 2 a))))
11167 ((setq a (org-extract-log-state-settings w))
11168 (and (member (car a) org-todo-keywords-1)
11169 (push a org-todo-log-states)))))))
11171 (defun org-get-todo-sequence-head (kwd)
11172 "Return the head of the TODO sequence to which KWD belongs.
11173 If KWD is not set, check if there is a text property remembering the
11178 (or (get-text-property (point-at-bol) 'org-todo-head)
11180 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
11181 nil (point-at-eol)))
11182 (get-text-property p 'org-todo-head))))
11183 ((not (member kwd org-todo-keywords-1))
11184 (car org-todo-keywords-1))
11185 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
11187 (defun org-fast-todo-selection ()
11188 "Fast TODO keyword selection with single keys.
11189 Returns the new TODO keyword, or nil if no state change should occur."
11190 (let* ((fulltable org-todo-key-alist)
11191 (done-keywords org-done-keywords) ;; needed for the faces.
11192 (maxlen (apply 'max (mapcar
11194 (if (stringp (car x)) (string-width (car x)) 0))
11197 (fwidth (+ maxlen 3 1 3))
11198 (ncol (/ (- (window-width) 4) fwidth))
11202 (save-window-excursion
11204 (set-buffer (get-buffer-create " *Org todo*"))
11205 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
11207 (org-set-local 'org-done-keywords done-keywords)
11208 (setq tbl fulltable cnt 0)
11209 (while (setq e (pop tbl))
11211 ((equal e '(:startgroup))
11212 (push '() groups) (setq ingroup t)
11213 (when (not (= cnt 0))
11217 ((equal e '(:endgroup))
11218 (setq ingroup nil cnt 0)
11220 ((equal e '(:newline))
11221 (when (not (= cnt 0))
11225 (while (equal (car tbl) '(:newline))
11227 (setq tbl (cdr tbl)))))
11229 (setq tg (car e) c (cdr e))
11230 (if ingroup (push tg (car groups)))
11231 (setq tg (org-add-props tg nil 'face
11232 (org-get-todo-face tg)))
11233 (if (and (= cnt 0) (not ingroup)) (insert " "))
11234 (insert "[" c "] " tg (make-string
11235 (- fwidth 4 (length tg)) ?\ ))
11236 (when (= (setq cnt (1+ cnt)) ncol)
11238 (if ingroup (insert " "))
11241 (goto-char (point-min))
11242 (if (not expert) (org-fit-window-to-buffer))
11243 (message "[a-z..]:Set [SPC]:clear")
11244 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
11247 (and (= c ?q) (not (rassoc c fulltable))))
11248 (setq quit-flag t))
11250 ((setq e (rassoc c fulltable) tg (car e))
11252 (t (setq quit-flag t)))))))
11254 (defun org-entry-is-todo-p ()
11255 (member (org-get-todo-state) org-not-done-keywords))
11257 (defun org-entry-is-done-p ()
11258 (member (org-get-todo-state) org-done-keywords))
11260 (defun org-get-todo-state ()
11262 (org-back-to-heading t)
11263 (and (looking-at org-todo-line-regexp)
11265 (match-string 2))))
11267 (defun org-at-date-range-p (&optional inactive-ok)
11268 "Is the cursor inside a date range?"
11272 (let ((pos (point)))
11273 (skip-chars-backward "^[<\r\n")
11274 (skip-chars-backward "<[")
11275 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11276 (>= (match-end 0) pos)
11278 (skip-chars-backward "^<[\r\n")
11279 (skip-chars-backward "<[")
11280 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11281 (>= (match-end 0) pos)
11285 (defun org-get-repeat (&optional tagline)
11286 "Check if there is a deadline/schedule with repeater in this entry."
11289 (org-back-to-heading t)
11290 (and (re-search-forward (if tagline
11291 (concat tagline "\\s-*" org-repeat-re)
11293 (org-entry-end-position) t)
11294 (match-string-no-properties 1)))))
11296 (defvar org-last-changed-timestamp)
11297 (defvar org-last-inserted-timestamp)
11298 (defvar org-log-post-message)
11299 (defvar org-log-note-purpose)
11300 (defvar org-log-note-how)
11301 (defvar org-log-note-extra)
11302 (defun org-auto-repeat-maybe (done-word)
11303 "Check if the current headline contains a repeated deadline/schedule.
11304 If yes, set TODO state back to what it was and change the base date
11305 of repeating deadline/scheduled time stamps to new date.
11306 This function is run automatically after each state change to a DONE state."
11307 ;; last-state is dynamically scoped into this function
11308 (let* ((repeat (org-get-repeat))
11309 (aa (assoc last-state org-todo-kwd-alist))
11310 (interpret (nth 1 aa))
11312 (whata '(("d" . day) ("m" . month) ("y" . year)))
11313 (msg "Entry repeats: ")
11315 (org-todo-log-states nil)
11316 (nshiftmax 10) (nshift 0)
11317 re type n what ts time to-state)
11319 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
11320 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
11321 org-todo-repeat-to-state))
11322 (unless (and to-state (member to-state org-todo-keywords-1))
11323 (setq to-state (if (eq interpret 'type) last-state head)))
11324 (org-todo to-state)
11325 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
11326 (org-entry-put nil "LAST_REPEAT" (format-time-string
11327 (org-time-stamp-format t t))))
11328 (when org-log-repeat
11329 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
11330 (memq 'org-add-log-note post-command-hook))
11331 ;; OK, we are already setup for some record
11332 (if (eq org-log-repeat 'note)
11333 ;; make sure we take a note, not only a time stamp
11334 (setq org-log-note-how 'note))
11335 ;; Set up for taking a record
11336 (org-add-log-setup 'state (or done-word (car org-done-keywords))
11338 'findpos org-log-repeat)))
11339 (org-back-to-heading t)
11340 (org-add-planning-info nil nil 'closed)
11341 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
11342 org-deadline-time-regexp "\\)\\|\\("
11343 org-ts-regexp "\\)"))
11344 (while (re-search-forward
11345 re (save-excursion (outline-next-heading) (point)) t)
11346 (setq type (if (match-end 1) org-scheduled-string
11347 (if (match-end 3) org-deadline-string "Plain:"))
11348 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
11349 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
11350 (setq n (string-to-number (match-string 2 ts))
11351 what (match-string 3 ts))
11352 (if (equal what "w") (setq n (* n 7) what "d"))
11353 ;; Preparation, see if we need to modify the start date for the change
11354 (when (match-end 1)
11355 (setq time (save-match-data (org-time-string-to-time ts)))
11357 ((equal (match-string 1 ts) ".")
11358 ;; Shift starting date to today
11359 (org-timestamp-change
11360 (- (time-to-days (current-time)) (time-to-days time))
11362 ((equal (match-string 1 ts) "+")
11363 (while (or (= nshift 0)
11364 (<= (time-to-days time) (time-to-days (current-time))))
11365 (when (= (incf nshift) nshiftmax)
11366 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
11368 (org-timestamp-change n (cdr (assoc what whata)))
11369 (org-at-timestamp-p t)
11370 (setq ts (match-string 1))
11371 (setq time (save-match-data (org-time-string-to-time ts))))
11372 (org-timestamp-change (- n) (cdr (assoc what whata)))
11373 ;; rematch, so that we have everything in place for the real shift
11374 (org-at-timestamp-p t)
11375 (setq ts (match-string 1))
11376 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
11377 (org-timestamp-change n (cdr (assoc what whata)))
11378 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
11379 (setq org-log-post-message msg)
11380 (message "%s" msg))))
11382 (defun org-show-todo-tree (arg)
11383 "Make a compact tree which shows all headlines marked with TODO.
11384 The tree will show the lines where the regexp matches, and all higher
11385 headlines above the match.
11386 With a \\[universal-argument] prefix, prompt for a regexp to match.
11387 With a numeric prefix N, construct a sparse tree for the Nth element
11388 of `org-todo-keywords-1'."
11390 (let ((case-fold-search nil)
11392 (cond ((null arg) org-not-done-regexp)
11394 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
11395 (mapcar 'list org-todo-keywords-1))))
11397 (mapconcat 'identity (org-split-string kwd "|") "\\|")
11399 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
11400 (regexp-quote (nth (1- (prefix-numeric-value arg))
11401 org-todo-keywords-1)))
11402 (t (error "Invalid prefix argument: %s" arg)))))
11403 (message "%d TODO entries found"
11404 (org-occur (concat "^" outline-regexp " *" kwd-re )))))
11406 (defun org-deadline (&optional remove time)
11407 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
11408 With argument REMOVE, remove any deadline from the item.
11409 When TIME is set, it should be an internal time specification, and the
11410 scheduling will use the corresponding date."
11412 (let* ((old-date (org-entry-get nil "DEADLINE"))
11413 (repeater (and old-date
11414 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11415 (match-string 1 old-date))))
11418 (when (and old-date org-log-redeadline)
11419 (org-add-log-setup 'deldeadline nil old-date 'findpos
11420 org-log-redeadline))
11421 (org-remove-timestamp-with-keyword org-deadline-string)
11422 (message "Item no longer has a deadline."))
11423 (org-add-planning-info 'deadline time 'closed)
11424 (when (and old-date org-log-redeadline
11425 (not (equal old-date
11426 (substring org-last-inserted-timestamp 1 -1))))
11427 (org-add-log-setup 'redeadline nil old-date 'findpos
11428 org-log-redeadline))
11431 (org-back-to-heading t)
11432 (when (re-search-forward (concat org-deadline-string " "
11433 org-last-inserted-timestamp)
11435 (outline-next-heading) (point)) t)
11436 (goto-char (1- (match-end 0)))
11437 (insert " " repeater)
11438 (setq org-last-inserted-timestamp
11439 (concat (substring org-last-inserted-timestamp 0 -1)
11441 (substring org-last-inserted-timestamp -1))))))
11442 (message "Deadline on %s" org-last-inserted-timestamp))))
11444 (defun org-schedule (&optional remove time)
11445 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
11446 With argument REMOVE, remove any scheduling date from the item.
11447 When TIME is set, it should be an internal time specification, and the
11448 scheduling will use the corresponding date."
11450 (let* ((old-date (org-entry-get nil "SCHEDULED"))
11451 (repeater (and old-date
11452 (string-match "\\([.+]+[0-9]+[dwmy]\\) ?" old-date)
11453 (match-string 1 old-date))))
11456 (when (and old-date org-log-reschedule)
11457 (org-add-log-setup 'delschedule nil old-date 'findpos
11458 org-log-reschedule))
11459 (org-remove-timestamp-with-keyword org-scheduled-string)
11460 (message "Item is no longer scheduled."))
11461 (org-add-planning-info 'scheduled time 'closed)
11462 (when (and old-date org-log-reschedule
11463 (not (equal old-date
11464 (substring org-last-inserted-timestamp 1 -1))))
11465 (org-add-log-setup 'reschedule nil old-date 'findpos
11466 org-log-reschedule))
11469 (org-back-to-heading t)
11470 (when (re-search-forward (concat org-scheduled-string " "
11471 org-last-inserted-timestamp)
11473 (outline-next-heading) (point)) t)
11474 (goto-char (1- (match-end 0)))
11475 (insert " " repeater)
11476 (setq org-last-inserted-timestamp
11477 (concat (substring org-last-inserted-timestamp 0 -1)
11479 (substring org-last-inserted-timestamp -1))))))
11480 (message "Scheduled to %s" org-last-inserted-timestamp))))
11482 (defun org-get-scheduled-time (pom &optional inherit)
11483 "Get the scheduled time as a time tuple, of a format suitable
11484 for calling org-schedule with, or if there is no scheduling,
11486 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
11488 (apply 'encode-time (org-parse-time-string time)))))
11490 (defun org-get-deadline-time (pom &optional inherit)
11491 "Get the deadline as a time tuple, of a format suitable for
11492 calling org-deadline with, or if there is no scheduling, returns
11494 (let ((time (org-entry-get pom "DEADLINE" inherit)))
11496 (apply 'encode-time (org-parse-time-string time)))))
11498 (defun org-remove-timestamp-with-keyword (keyword)
11499 "Remove all time stamps with KEYWORD in the current entry."
11500 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
11503 (org-back-to-heading t)
11505 (outline-next-heading)
11506 (while (re-search-backward re beg t)
11508 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
11509 (equal (char-before) ?\ ))
11510 (backward-delete-char 1)
11511 (if (string-match "^[ \t]*$" (buffer-substring
11512 (point-at-bol) (point-at-eol)))
11513 (delete-region (point-at-bol)
11514 (min (point-max) (1+ (point-at-eol))))))))))
11516 (defun org-add-planning-info (what &optional time &rest remove)
11517 "Insert new timestamp with keyword in the line directly after the headline.
11518 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
11519 If non is given, the user is prompted for a date.
11520 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
11523 (let (org-time-was-given org-end-time-was-given ts
11524 end default-time default-input)
11527 (when (and (not time) (memq what '(scheduled deadline)))
11528 ;; Try to get a default date/time from existing timestamp
11530 (org-back-to-heading t)
11531 (setq end (save-excursion (outline-next-heading) (point)))
11532 (when (re-search-forward (if (eq what 'scheduled)
11533 org-scheduled-time-regexp
11534 org-deadline-time-regexp)
11536 (setq ts (match-string 1)
11538 (apply 'encode-time (org-parse-time-string ts))
11539 default-input (and ts (org-get-compact-tod ts))))))
11541 ;; If necessary, get the time from the user
11542 (setq time (or time (org-read-date nil 'to-time nil nil
11543 default-time default-input))))
11545 (when (and org-insert-labeled-timestamps-at-point
11546 (member what '(scheduled deadline)))
11548 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
11549 (org-insert-time-stamp time org-time-was-given
11550 nil nil nil (list org-end-time-was-given))
11554 (let (col list elt ts buffer-invisibility-spec)
11555 (org-back-to-heading t)
11556 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
11557 (goto-char (match-end 1))
11558 (setq col (current-column))
11559 (goto-char (match-end 0))
11560 (if (eobp) (insert "\n") (forward-char 1))
11561 (when (and (not what)
11564 org-keyword-time-not-clock-regexp))))
11565 ;; Nothing to add, nothing to remove...... :-)
11567 (if (and (not (looking-at outline-regexp))
11568 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
11570 (not (equal (match-string 1) org-clock-string)))
11571 (narrow-to-region (match-beginning 0) (match-end 0))
11572 (insert-before-markers "\n")
11574 (narrow-to-region (point) (point))
11575 (and org-adapt-indentation (org-indent-to-column col)))
11576 ;; Check if we have to remove something.
11577 (setq list (cons what remove))
11579 (setq elt (pop list))
11580 (goto-char (point-min))
11581 (when (or (and (eq elt 'scheduled)
11582 (re-search-forward org-scheduled-time-regexp nil t))
11583 (and (eq elt 'deadline)
11584 (re-search-forward org-deadline-time-regexp nil t))
11585 (and (eq elt 'closed)
11586 (re-search-forward org-closed-time-regexp nil t)))
11588 (if (looking-at "--+<[^>]+>") (replace-match ""))
11589 (skip-chars-backward " ")
11590 (if (looking-at " +") (replace-match ""))))
11591 (goto-char (point-max))
11592 (and org-adapt-indentation (bolp) (org-indent-to-column col))
11595 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
11596 (cond ((eq what 'scheduled) org-scheduled-string)
11597 ((eq what 'deadline) org-deadline-string)
11598 ((eq what 'closed) org-closed-string))
11600 (setq ts (org-insert-time-stamp
11602 (or org-time-was-given
11603 (and (eq what 'closed) org-log-done-with-time))
11605 nil nil (list org-end-time-was-given)))
11607 (goto-char (point-min))
11609 (if (and (looking-at "[ \t]*\n")
11610 (equal (char-before) ?\n))
11611 (delete-region (1- (point)) (point-at-eol)))
11614 (defvar org-log-note-marker (make-marker))
11615 (defvar org-log-note-purpose nil)
11616 (defvar org-log-note-state nil)
11617 (defvar org-log-note-previous-state nil)
11618 (defvar org-log-note-how nil)
11619 (defvar org-log-note-extra nil)
11620 (defvar org-log-note-window-configuration nil)
11621 (defvar org-log-note-return-to (make-marker))
11622 (defvar org-log-post-message nil
11623 "Message to be displayed after a log note has been stored.
11624 The auto-repeater uses this.")
11626 (defun org-add-note ()
11627 "Add a note to the current entry.
11628 This is done in the same way as adding a state change note."
11630 (org-add-log-setup 'note nil nil 'findpos nil))
11632 (defvar org-property-end-re)
11633 (defun org-add-log-setup (&optional purpose state prev-state
11634 findpos how &optional extra)
11635 "Set up the post command hook to take a note.
11636 If this is about to TODO state change, the new state is expected in STATE.
11637 When FINDPOS is non-nil, find the correct position for the note in
11638 the current entry. If not, assume that it can be inserted at point.
11639 HOW is an indicator what kind of note should be created.
11640 EXTRA is additional text that will be inserted into the notes buffer."
11641 (let* ((org-log-into-drawer (org-log-into-drawer))
11642 (drawer (cond ((stringp org-log-into-drawer)
11643 org-log-into-drawer)
11644 (org-log-into-drawer "LOGBOOK")
11649 (org-back-to-heading t)
11650 (narrow-to-region (point) (save-excursion
11651 (outline-next-heading) (point)))
11652 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
11653 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
11655 (goto-char (match-end 0))
11658 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
11661 (goto-char (match-end 0))
11662 (or org-log-states-order-reversed
11663 (and (re-search-forward org-property-end-re nil t)
11664 (goto-char (1- (match-beginning 0))))))
11665 (insert "\n:" drawer ":\n:END:")
11666 (beginning-of-line 0)
11667 (org-indent-line-function)
11668 (beginning-of-line 2)
11669 (org-indent-line-function)
11671 ((and org-log-state-notes-insert-after-drawers
11673 (forward-line) (looking-at org-drawer-regexp)))
11675 (while (looking-at org-drawer-regexp)
11676 (goto-char (match-end 0))
11677 (re-search-forward org-property-end-re (point-max) t)
11679 (forward-line -1)))
11680 (unless org-log-states-order-reversed
11681 (and (= (char-after) ?\n) (forward-char 1))
11682 (org-skip-over-state-notes)
11683 (skip-chars-backward " \t\n\r")))
11684 (move-marker org-log-note-marker (point))
11685 (setq org-log-note-purpose purpose
11686 org-log-note-state state
11687 org-log-note-previous-state prev-state
11688 org-log-note-how how
11689 org-log-note-extra extra)
11690 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
11692 (defun org-skip-over-state-notes ()
11693 "Skip past the list of State notes in an entry."
11694 (if (looking-at "\n[ \t]*- State") (forward-char 1))
11695 (while (looking-at "[ \t]*- State")
11696 (condition-case nil
11698 (error (org-end-of-item)))))
11700 (defun org-add-log-note (&optional purpose)
11701 "Pop up a window for taking a note, and add this note later at point."
11702 (remove-hook 'post-command-hook 'org-add-log-note)
11703 (setq org-log-note-window-configuration (current-window-configuration))
11704 (delete-other-windows)
11705 (move-marker org-log-note-return-to (point))
11706 (switch-to-buffer (marker-buffer org-log-note-marker))
11707 (goto-char org-log-note-marker)
11708 (org-switch-to-buffer-other-window "*Org Note*")
11710 (if (memq org-log-note-how '(time state))
11711 (let (current-prefix-arg) (org-store-log-note))
11712 (let ((org-inhibit-startup t)) (org-mode))
11713 (insert (format "# Insert note for %s.
11714 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
11716 ((eq org-log-note-purpose 'clock-out) "stopped clock")
11717 ((eq org-log-note-purpose 'done) "closed todo item")
11718 ((eq org-log-note-purpose 'state)
11719 (format "state change from \"%s\" to \"%s\""
11720 (or org-log-note-previous-state "")
11721 (or org-log-note-state "")))
11722 ((eq org-log-note-purpose 'reschedule)
11724 ((eq org-log-note-purpose 'delschedule)
11725 "no longer scheduled")
11726 ((eq org-log-note-purpose 'redeadline)
11727 "changing deadline")
11728 ((eq org-log-note-purpose 'deldeadline)
11729 "removing deadline")
11730 ((eq org-log-note-purpose 'refile)
11732 ((eq org-log-note-purpose 'note)
11734 (t (error "This should not happen")))))
11735 (if org-log-note-extra (insert org-log-note-extra))
11736 (org-set-local 'org-finish-function 'org-store-log-note)))
11738 (defvar org-note-abort nil) ; dynamically scoped
11739 (defun org-store-log-note ()
11740 "Finish taking a log note, and insert it to where it belongs."
11741 (let ((txt (buffer-string))
11742 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
11744 (kill-buffer (current-buffer))
11745 (while (string-match "\\`#.*\n[ \t\n]*" txt)
11746 (setq txt (replace-match "" t t txt)))
11747 (if (string-match "\\s-+\\'" txt)
11748 (setq txt (replace-match "" t t txt)))
11749 (setq lines (org-split-string txt "\n"))
11750 (when (and note (string-match "\\S-" note))
11752 (org-replace-escapes
11754 (list (cons "%u" (user-login-name))
11755 (cons "%U" user-full-name)
11756 (cons "%t" (format-time-string
11757 (org-time-stamp-format 'long 'inactive)
11759 (cons "%T" (format-time-string
11760 (org-time-stamp-format 'long nil)
11762 (cons "%s" (if org-log-note-state
11763 (concat "\"" org-log-note-state "\"")
11765 (cons "%S" (if org-log-note-previous-state
11766 (concat "\"" org-log-note-previous-state "\"")
11768 (if lines (setq note (concat note " \\\\")))
11770 (when (or current-prefix-arg org-note-abort)
11771 (when org-log-into-drawer
11772 (org-remove-empty-drawer-at
11773 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
11774 org-log-note-marker))
11777 (with-current-buffer (marker-buffer org-log-note-marker)
11779 (goto-char org-log-note-marker)
11780 (move-marker org-log-note-marker nil)
11782 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
11783 (insert "- " (pop lines))
11784 (org-indent-line-function)
11785 (beginning-of-line 1)
11786 (looking-at "[ \t]*")
11787 (setq ind (concat (match-string 0) " "))
11789 (while lines (insert "\n" ind (pop lines)))
11790 (message "Note stored")
11791 (org-back-to-heading t)
11792 (org-cycle-hide-drawers 'children)))))
11793 (set-window-configuration org-log-note-window-configuration)
11794 (with-current-buffer (marker-buffer org-log-note-return-to)
11795 (goto-char org-log-note-return-to))
11796 (move-marker org-log-note-return-to nil)
11797 (and org-log-post-message (message "%s" org-log-post-message)))
11799 (defun org-remove-empty-drawer-at (drawer pos)
11800 "Remove an empty drawer DRAWER at position POS.
11801 POS may also be a marker."
11802 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
11808 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
11809 (replace-match ""))))))
11811 (defun org-sparse-tree (&optional arg)
11812 "Create a sparse tree, prompt for the details.
11813 This command can create sparse trees. You first need to select the type
11814 of match used to create the tree:
11816 t Show all TODO entries.
11817 T Show entries with a specific TODO keyword.
11818 m Show entries selected by a tags/property match.
11819 p Enter a property name and its value (both with completion on existing
11820 names/values) and show entries with that property.
11821 / Show entries matching a regular expression (`r' can be used as well)
11822 d Show deadlines due within `org-deadline-warning-days'.
11823 b Show deadlines and scheduled items before a date.
11824 a Show deadlines and scheduled items after a date."
11826 (let (ans kwd value)
11827 (message "Sparse tree: [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty [d]eadlines\n [b]efore-date [a]fter-date")
11828 (setq ans (read-char-exclusive))
11831 (call-interactively 'org-check-deadlines))
11833 (call-interactively 'org-check-before-date))
11835 (call-interactively 'org-check-after-date))
11837 (org-show-todo-tree nil))
11839 (org-show-todo-tree '(4)))
11840 ((member ans '(?T ?m))
11841 (call-interactively 'org-match-sparse-tree))
11842 ((member ans '(?p ?P))
11843 (setq kwd (org-icompleting-read "Property: "
11844 (mapcar 'list (org-buffer-property-keys))))
11845 (setq value (org-icompleting-read "Value: "
11846 (mapcar 'list (org-property-values kwd))))
11847 (unless (string-match "\\`{.*}\\'" value)
11848 (setq value (concat "\"" value "\"")))
11849 (org-match-sparse-tree arg (concat kwd "=" value)))
11850 ((member ans '(?r ?R ?/))
11851 (call-interactively 'org-occur))
11852 (t (error "No such sparse tree command \"%c\"" ans)))))
11854 (defvar org-occur-highlights nil
11855 "List of overlays used for occur matches.")
11856 (make-variable-buffer-local 'org-occur-highlights)
11857 (defvar org-occur-parameters nil
11858 "Parameters of the active org-occur calls.
11859 This is a list, each call to org-occur pushes as cons cell,
11860 containing the regular expression and the callback, onto the list.
11861 The list can contain several entries if `org-occur' has been called
11862 several time with the KEEP-PREVIOUS argument. Otherwise, this list
11863 will only contain one set of parameters. When the highlights are
11864 removed (for example with `C-c C-c', or with the next edit (depending
11865 on `org-remove-highlights-with-change'), this variable is emptied
11867 (make-variable-buffer-local 'org-occur-parameters)
11869 (defun org-occur (regexp &optional keep-previous callback)
11870 "Make a compact tree which shows all matches of REGEXP.
11871 The tree will show the lines where the regexp matches, and all higher
11872 headlines above the match. It will also show the heading after the match,
11873 to make sure editing the matching entry is easy.
11874 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
11875 call to `org-occur' will be kept, to allow stacking of calls to this
11877 If CALLBACK is non-nil, it is a function which is called to confirm
11878 that the match should indeed be shown."
11879 (interactive "sRegexp: \nP")
11880 (when (equal regexp "")
11881 (error "Regexp cannot be empty"))
11882 (unless keep-previous
11883 (org-remove-occur-highlights nil nil t))
11884 (push (cons regexp callback) org-occur-parameters)
11887 (goto-char (point-min))
11888 (if (or (not keep-previous) ; do not want to keep
11889 (not org-occur-highlights)) ; no previous matches
11892 (while (re-search-forward regexp nil t)
11893 (when (or (not callback)
11894 (save-match-data (funcall callback)))
11895 (setq cnt (1+ cnt))
11896 (when org-highlight-sparse-tree-matches
11897 (org-highlight-new-match (match-beginning 0) (match-end 0)))
11898 (org-show-context 'occur-tree))))
11899 (when org-remove-highlights-with-change
11900 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
11902 (unless org-sparse-tree-open-archived-trees
11903 (org-hide-archived-subtrees (point-min) (point-max)))
11904 (run-hooks 'org-occur-hook)
11905 (if (interactive-p)
11906 (message "%d match(es) for regexp %s" cnt regexp))
11909 (defun org-show-context (&optional key)
11910 "Make sure point and context are visible.
11911 How much context is shown depends upon the variables
11912 `org-show-hierarchy-above', `org-show-following-heading'. and
11913 `org-show-siblings'."
11914 (let ((heading-p (org-on-heading-p t))
11915 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
11916 (following-p (org-get-alist-option org-show-following-heading key))
11917 (entry-p (org-get-alist-option org-show-entry-below key))
11918 (siblings-p (org-get-alist-option org-show-siblings key)))
11920 ;; Show heading or entry text
11921 (if (and heading-p (not entry-p))
11922 (org-flag-heading nil) ; only show the heading
11923 (and (or entry-p (org-invisible-p) (org-invisible-p2))
11924 (org-show-hidden-entry))) ; show entire entry
11926 ;; Show next sibling, or heading below text
11928 (and (if heading-p (org-goto-sibling) (outline-next-heading))
11929 (org-flag-heading nil))))
11930 (when siblings-p (org-show-siblings))
11932 ;; show all higher headings, possibly with siblings
11934 (while (and (condition-case nil
11935 (progn (org-up-heading-all 1) t)
11938 (org-flag-heading nil)
11939 (when siblings-p (org-show-siblings))))))))
11941 (defvar org-reveal-start-hook nil
11942 "Hook run before revealing a location.")
11944 (defun org-reveal (&optional siblings)
11945 "Show current entry, hierarchy above it, and the following headline.
11946 This can be used to show a consistent set of context around locations
11947 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
11948 not t for the search context.
11950 With optional argument SIBLINGS, on each level of the hierarchy all
11951 siblings are shown. This repairs the tree structure to what it would
11952 look like when opened with hierarchical calls to `org-cycle'.
11953 With double optional argument \\[universal-argument] \\[universal-argument], \
11954 go to the parent and show the
11957 (run-hooks 'org-reveal-start-hook)
11958 (let ((org-show-hierarchy-above t)
11959 (org-show-following-heading t)
11960 (org-show-siblings (if siblings t org-show-siblings)))
11961 (org-show-context nil))
11962 (when (equal siblings '(16))
11964 (when (org-up-heading-safe)
11966 (run-hook-with-args 'org-cycle-hook 'subtree)))))
11968 (defun org-highlight-new-match (beg end)
11969 "Highlight from BEG to END and mark the highlight is an occur headline."
11970 (let ((ov (make-overlay beg end)))
11971 (overlay-put ov 'face 'secondary-selection)
11972 (push ov org-occur-highlights)))
11974 (defun org-remove-occur-highlights (&optional beg end noremove)
11975 "Remove the occur highlights from the buffer.
11976 BEG and END are ignored. If NOREMOVE is nil, remove this function
11977 from the `before-change-functions' in the current buffer."
11979 (unless org-inhibit-highlight-removal
11980 (mapc 'delete-overlay org-occur-highlights)
11981 (setq org-occur-highlights nil)
11982 (setq org-occur-parameters nil)
11984 (remove-hook 'before-change-functions
11985 'org-remove-occur-highlights 'local))))
11989 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
11990 "Regular expression matching the priority indicator.")
11992 (defvar org-remove-priority-next-time nil)
11994 (defun org-priority-up ()
11995 "Increase the priority of the current item."
11997 (org-priority 'up))
11999 (defun org-priority-down ()
12000 "Decrease the priority of the current item."
12002 (org-priority 'down))
12004 (defun org-priority (&optional action)
12005 "Change the priority of an item by ARG.
12006 ACTION can be `set', `up', `down', or a character."
12008 (unless org-enable-priority-commands
12009 (error "Priority commands are disabled"))
12010 (setq action (or action 'set))
12011 (let (current new news have remove)
12013 (org-back-to-heading t)
12014 (if (looking-at org-priority-regexp)
12015 (setq current (string-to-char (match-string 2))
12017 (setq current org-default-priority))
12019 ((eq action 'remove)
12020 (setq remove t new ?\ ))
12021 ((or (eq action 'set)
12022 (if (featurep 'xemacs) (characterp action) (integerp action)))
12023 (if (not (eq action 'set))
12025 (message "Priority %c-%c, SPC to remove: "
12026 org-highest-priority org-lowest-priority)
12027 (setq new (read-char-exclusive)))
12028 (if (and (= (upcase org-highest-priority) org-highest-priority)
12029 (= (upcase org-lowest-priority) org-lowest-priority))
12030 (setq new (upcase new)))
12031 (cond ((equal new ?\ ) (setq remove t))
12032 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
12033 (error "Priority must be between `%c' and `%c'"
12034 org-highest-priority org-lowest-priority))))
12036 (if (and (not have) (eq last-command this-command))
12037 (setq new org-lowest-priority)
12038 (setq new (if (and org-priority-start-cycle-with-default (not have))
12039 org-default-priority (1- current)))))
12041 (if (and (not have) (eq last-command this-command))
12042 (setq new org-highest-priority)
12043 (setq new (if (and org-priority-start-cycle-with-default (not have))
12044 org-default-priority (1+ current)))))
12045 (t (error "Invalid action")))
12046 (if (or (< (upcase new) org-highest-priority)
12047 (> (upcase new) org-lowest-priority))
12049 (setq news (format "%c" new))
12052 (replace-match "" t t nil 1)
12053 (replace-match news t t nil 2))
12055 (error "No priority cookie found in line")
12056 (let ((case-fold-search nil))
12057 (looking-at org-todo-line-regexp))
12060 (goto-char (match-end 2))
12061 (insert " [#" news "]"))
12062 (goto-char (match-beginning 3))
12063 (insert "[#" news "] "))))
12064 (org-preserve-lc (org-set-tags nil 'align)))
12066 (message "Priority removed")
12067 (message "Priority of current item set to %s" news))))
12069 (defun org-get-priority (s)
12070 "Find priority cookie and return priority."
12072 (if (not (string-match org-priority-regexp s))
12073 (* 1000 (- org-lowest-priority org-default-priority))
12074 (* 1000 (- org-lowest-priority
12075 (string-to-char (match-string 2 s)))))))
12079 (defvar org-agenda-archives-mode)
12080 (defvar org-map-continue-from nil
12081 "Position from where mapping should continue.
12082 Can be set by the action argument to `org-scan-tag's and `org-map-entries'.")
12084 (defvar org-scanner-tags nil
12085 "The current tag list while the tags scanner is running.")
12086 (defvar org-trust-scanner-tags nil
12087 "Should `org-get-tags-at' use the tags fro the scanner.
12088 This is for internal dynamical scoping only.
12089 When this is non-nil, the function `org-get-tags-at' will return the value
12090 of `org-scanner-tags' instead of building the list by itself. This
12091 can lead to large speed-ups when the tags scanner is used in a file with
12092 many entries, and when the list of tags is retrieved, for example to
12093 obtain a list of properties. Building the tags list for each entry in such
12094 a file becomes an N^2 operation - but with this variable set, it scales
12097 (defun org-scan-tags (action matcher &optional todo-only)
12098 "Scan headline tags with inheritance and produce output ACTION.
12100 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
12101 or `agenda' to produce an entry list for an agenda view. It can also be
12102 a Lisp form or a function that should be called at each matched headline, in
12103 this case the return value is a list of all return values from these calls.
12105 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
12106 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
12107 only lines with a TODO keyword are included in the output."
12108 (require 'org-agenda)
12109 (let* ((re (concat "^" outline-regexp " *\\(\\<\\("
12110 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
12112 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
12113 (props (list 'face 'default
12114 'done-face 'org-agenda-done
12115 'undone-face 'default
12116 'mouse-face 'highlight
12117 'org-not-done-regexp org-not-done-regexp
12118 'org-todo-regexp org-todo-regexp
12120 (format "mouse-2 or RET jump to org file %s"
12121 (abbreviate-file-name
12122 (or (buffer-file-name (buffer-base-buffer))
12123 (buffer-name (buffer-base-buffer)))))))
12124 (case-fold-search nil)
12125 (org-map-continue-from nil)
12126 lspos tags tags-list
12127 (tags-alist (list (cons 0 org-file-tags)))
12128 (llast 0) rtn rtn1 level category i txt
12129 todo marker entry priority)
12130 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
12131 (setq action (list 'lambda nil action)))
12133 (goto-char (point-min))
12134 (when (eq action 'sparse-tree)
12136 (org-remove-occur-highlights))
12137 (while (re-search-forward re nil t)
12139 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
12140 tags (if (match-end 4) (org-match-string-no-properties 4)))
12141 (goto-char (setq lspos (match-beginning 0)))
12142 (setq level (org-reduced-level (funcall outline-level))
12143 category (org-get-category))
12144 (setq i llast llast level)
12145 ;; remove tag lists from same and sublevels
12146 (while (>= i level)
12147 (when (setq entry (assoc i tags-alist))
12148 (setq tags-alist (delete entry tags-alist)))
12150 ;; add the next tags
12152 (setq tags (org-split-string tags ":")
12154 (cons (cons level tags) tags-alist)))
12155 ;; compile tags for current headline
12157 (if org-use-tag-inheritance
12158 (apply 'append (mapcar 'cdr (reverse tags-alist)))
12160 org-scanner-tags tags-list)
12161 (when org-use-tag-inheritance
12162 (setcdr (car tags-alist)
12163 (mapcar (lambda (x)
12164 (setq x (copy-sequence x))
12165 (org-add-prop-inherited x))
12166 (cdar tags-alist))))
12167 (when (and tags org-use-tag-inheritance
12168 (or (not (eq t org-use-tag-inheritance))
12169 org-tags-exclude-from-inheritance))
12170 ;; selective inheritance, remove uninherited ones
12171 (setcdr (car tags-alist)
12172 (org-remove-uniherited-tags (cdar tags-alist))))
12173 (when (and (or (not todo-only)
12174 (and (member todo org-not-done-keywords)
12175 (or (not org-agenda-tags-todo-honor-ignore-options)
12176 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
12177 (let ((case-fold-search t)) (eval matcher))
12179 (not (member org-archive-tag tags-list))
12180 ;; we have an archive tag, should we use this anyway?
12181 (or (not org-agenda-skip-archived-trees)
12182 (and (eq action 'agenda) org-agenda-archives-mode))))
12183 (unless (eq action 'sparse-tree) (org-agenda-skip))
12185 ;; select this headline
12188 ((eq action 'sparse-tree)
12189 (and org-highlight-sparse-tree-matches
12190 (org-get-heading) (match-end 0)
12191 (org-highlight-new-match
12192 (match-beginning 0) (match-beginning 1)))
12193 (org-show-context 'tags-tree))
12194 ((eq action 'agenda)
12195 (setq txt (org-format-agenda-item
12198 (if (eq org-tags-match-list-sublevels 'indented)
12199 (make-string (1- level) ?.) "")
12204 priority (org-get-priority txt))
12206 (setq marker (org-agenda-new-marker))
12207 (org-add-props txt props
12208 'org-marker marker 'org-hd-marker marker 'org-category category
12210 'priority priority 'type "tagsmatch")
12212 ((functionp action)
12213 (setq org-map-continue-from nil)
12215 (setq rtn1 (funcall action))
12217 (t (error "Invalid action")))
12219 ;; if we are to skip sublevels, jump to end of subtree
12220 (unless org-tags-match-list-sublevels
12221 (org-end-of-subtree t)
12222 (backward-char 1))))
12223 ;; Get the correct position from where to continue
12224 (if org-map-continue-from
12225 (goto-char org-map-continue-from)
12226 (and (= (point) lspos) (end-of-line 1)))))
12227 (when (and (eq action 'sparse-tree)
12228 (not org-sparse-tree-open-archived-trees))
12229 (org-hide-archived-subtrees (point-min) (point-max)))
12232 (defun org-remove-uniherited-tags (tags)
12233 "Remove all tags that are not inherited from the list TAGS."
12235 ((eq org-use-tag-inheritance t)
12236 (if org-tags-exclude-from-inheritance
12237 (org-delete-all org-tags-exclude-from-inheritance tags)
12239 ((not org-use-tag-inheritance) nil)
12240 ((stringp org-use-tag-inheritance)
12243 (if (and (string-match org-use-tag-inheritance x)
12244 (not (member x org-tags-exclude-from-inheritance)))
12247 ((listp org-use-tag-inheritance)
12250 (if (member x org-use-tag-inheritance) x nil))
12253 (defvar todo-only) ;; dynamically scoped
12255 (defun org-match-sparse-tree (&optional todo-only match)
12256 "Create a sparse tree according to tags string MATCH.
12257 MATCH can contain positive and negative selection of tags, like
12258 \"+WORK+URGENT-WITHBOSS\".
12259 If optional argument TODO-ONLY is non-nil, only select lines that are
12262 (org-prepare-agenda-buffers (list (current-buffer)))
12263 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
12265 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
12267 (defvar org-cached-props nil)
12268 (defun org-cached-entry-get (pom property)
12269 (if (or (eq t org-use-property-inheritance)
12270 (and (stringp org-use-property-inheritance)
12271 (string-match org-use-property-inheritance property))
12272 (and (listp org-use-property-inheritance)
12273 (member property org-use-property-inheritance)))
12274 ;; Caching is not possible, check it directly
12275 (org-entry-get pom property 'inherit)
12276 ;; Get all properties, so that we can do complicated checks easily
12277 (cdr (assoc property (or org-cached-props
12278 (setq org-cached-props
12279 (org-entry-properties pom)))))))
12281 (defun org-global-tags-completion-table (&optional files)
12282 "Return the list of all tags in all agenda buffer/files."
12289 (set-buffer (find-file-noselect file))
12290 (append (org-get-buffer-tags)
12291 (mapcar (lambda (x) (if (stringp (car-safe x))
12292 (list (car-safe x)) nil))
12294 (if (and files (car files))
12296 (org-agenda-files))))))))
12298 (defun org-make-tags-matcher (match)
12299 "Create the TAGS//TODO matcher form for the selection string MATCH."
12300 ;; todo-only is scoped dynamically into this function, and the function
12301 ;; may change it if the matcher asks for it.
12303 ;; Get a new match request, with completion
12304 (let ((org-last-tags-completion-table
12305 (org-global-tags-completion-table)))
12306 (setq match (org-completing-read-no-i
12307 "Match: " 'org-tags-completion-function nil nil nil
12308 'org-tags-history))))
12310 ;; Parse the string and create a lisp form
12311 (let ((match0 match)
12312 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\([[:alnum:]_]+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@]+\\)"))
12314 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
12315 orterms term orlist re-p str-p level-p level-op time-p
12316 prop-p pn pv po cat-p gv rest)
12317 (if (string-match "/+" match)
12318 ;; match contains also a todo-matching request
12320 (setq tagsmatch (substring match 0 (match-beginning 0))
12321 todomatch (substring match (match-end 0)))
12322 (if (string-match "^!" todomatch)
12323 (setq todo-only t todomatch (substring todomatch 1)))
12324 (if (string-match "^\\s-*$" todomatch)
12325 (setq todomatch nil)))
12326 ;; only matching tags
12327 (setq tagsmatch match todomatch nil))
12329 ;; Make the tags matcher
12330 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
12331 (setq tagsmatcher t)
12332 (setq orterms (org-split-string tagsmatch "|") orlist nil)
12333 (while (setq term (pop orterms))
12334 (while (and (equal (substring term -1) "\\") orterms)
12335 (setq term (concat term "|" (pop orterms)))) ; repair bad split
12336 (while (string-match re term)
12337 (setq rest (substring term (match-end 0))
12338 minus (and (match-end 1)
12339 (equal (match-string 1 term) "-"))
12340 tag (match-string 2 term)
12341 re-p (equal (string-to-char tag) ?{)
12342 level-p (match-end 4)
12343 prop-p (match-end 5)
12345 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
12347 (setq level-op (org-op-to-function (match-string 3 term)))
12348 `(,level-op level ,(string-to-number
12349 (match-string 4 term))))
12351 (setq pn (match-string 5 term)
12352 po (match-string 6 term)
12353 pv (match-string 7 term)
12354 cat-p (equal pn "CATEGORY")
12355 re-p (equal (string-to-char pv) ?{)
12356 str-p (equal (string-to-char pv) ?\")
12357 time-p (save-match-data
12358 (string-match "^\"[[<].*[]>]\"$" pv))
12359 pv (if (or re-p str-p) (substring pv 1 -1) pv))
12360 (if time-p (setq pv (org-matcher-time pv)))
12361 (setq po (org-op-to-function po (if time-p 'time str-p)))
12363 ((equal pn "CATEGORY")
12364 (setq gv '(get-text-property (point) 'org-category)))
12368 (setq gv `(org-cached-entry-get nil ,pn))))
12371 `(not (string-match ,pv (or ,gv "")))
12372 `(string-match ,pv (or ,gv "")))
12374 `(,po (or ,gv "") ,pv)
12375 `(,po (string-to-number (or ,gv ""))
12376 ,(string-to-number pv) ))))
12377 (t `(member ,tag tags-list)))
12378 mm (if minus (list 'not mm) mm)
12380 (push mm tagsmatcher))
12381 (push (if (> (length tagsmatcher) 1)
12382 (cons 'and tagsmatcher)
12385 (setq tagsmatcher nil))
12386 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
12388 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
12389 ;; Make the todo matcher
12390 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
12391 (setq todomatcher t)
12392 (setq orterms (org-split-string todomatch "|") orlist nil)
12393 (while (setq term (pop orterms))
12394 (while (string-match re term)
12395 (setq minus (and (match-end 1)
12396 (equal (match-string 1 term) "-"))
12397 kwd (match-string 2 term)
12398 re-p (equal (string-to-char kwd) ?{)
12399 term (substring term (match-end 0))
12401 `(string-match ,(substring kwd 1 -1) todo)
12402 (list 'equal 'todo kwd))
12403 mm (if minus (list 'not mm) mm))
12404 (push mm todomatcher))
12405 (push (if (> (length todomatcher) 1)
12406 (cons 'and todomatcher)
12409 (setq todomatcher nil))
12410 (setq todomatcher (if (> (length orlist) 1)
12411 (cons 'or orlist) (car orlist))))
12413 ;; Return the string and lisp forms of the matcher
12414 (setq matcher (if todomatcher
12415 (list 'and tagsmatcher todomatcher)
12417 (cons match0 matcher)))
12419 (defun org-op-to-function (op &optional stringp)
12420 "Turn an operator into the appropriate function."
12423 ((equal op "<" ) '(< string< org-time<))
12424 ((equal op ">" ) '(> org-string> org-time>))
12425 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
12426 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
12427 ((member op '("=" "==")) '(= string= org-time=))
12428 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
12429 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
12431 (defun org<> (a b) (not (= a b)))
12432 (defun org-string<= (a b) (or (string= a b) (string< a b)))
12433 (defun org-string>= (a b) (not (string< a b)))
12434 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
12435 (defun org-string<> (a b) (not (string= a b)))
12436 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
12437 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
12438 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
12439 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
12440 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
12441 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
12443 "Convert S to a floating point time.
12444 If S is already a number, just return it. If it is a string, parse
12445 it as a time string and apply `float-time' to it. If S is nil, just return 0."
12449 (condition-case nil
12450 (float-time (apply 'encode-time (org-parse-time-string s)))
12454 (defun org-time-today ()
12455 "Time in seconds today at 0:00.
12456 Returns the float number of seconds since the beginning of the
12457 epoch to the beginning of today (00:00)."
12458 (float-time (apply 'encode-time
12459 (append '(0 0 0) (nthcdr 3 (decode-time))))))
12461 (defun org-matcher-time (s)
12462 "Interpret a time comparison value."
12465 ((string= s "<now>") (float-time))
12466 ((string= s "<today>") (org-time-today))
12467 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
12468 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
12469 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
12470 (+ (org-time-today)
12471 (* (string-to-number (match-string 1 s))
12472 (cdr (assoc (match-string 2 s)
12473 '(("d" . 86400.0) ("w" . 604800.0)
12474 ("m" . 2678400.0) ("y" . 31557600.0)))))))
12477 (defun org-match-any-p (re list)
12478 "Does re match any element of list?"
12479 (setq list (mapcar (lambda (x) (string-match re x)) list))
12482 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
12483 (defvar org-tags-overlay (make-overlay 1 1))
12484 (org-detach-overlay org-tags-overlay)
12486 (defun org-get-local-tags-at (&optional pos)
12487 "Get a list of tags defined in the current headline."
12488 (org-get-tags-at pos 'local))
12490 (defun org-get-local-tags ()
12491 "Get a list of tags defined in the current headline."
12492 (org-get-tags-at nil 'local))
12494 (defun org-get-tags-at (&optional pos local)
12495 "Get a list of all headline tags applicable at POS.
12496 POS defaults to point. If tags are inherited, the list contains
12497 the targets in the same sequence as the headlines appear, i.e.
12498 the tags of the current headline come last.
12499 When LOCAL is non-nil, only return tags from the current headline,
12500 ignore inherited ones."
12502 (if (and org-trust-scanner-tags
12503 (or (not pos) (equal pos (point)))
12506 (let (tags ltags lastpos parent)
12510 (goto-char (or pos (point)))
12513 (condition-case nil
12515 (org-back-to-heading t)
12516 (while (not (equal lastpos (point)))
12517 (setq lastpos (point))
12519 (org-re "[^\r\n]+?:\\([[:alnum:]_@:]+\\):[ \t]*$"))
12520 (setq ltags (org-split-string
12521 (org-match-string-no-properties 1) ":"))
12523 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
12526 (org-remove-uniherited-tags ltags)
12529 (or org-use-tag-inheritance (throw 'done t))
12530 (if local (throw 'done t))
12531 (or (org-up-heading-safe) (error nil))
12534 (append (org-remove-uniherited-tags org-file-tags) tags)))))
12536 (defun org-add-prop-inherited (s)
12537 (add-text-properties 0 (length s) '(inherited t) s)
12540 (defun org-toggle-tag (tag &optional onoff)
12541 "Toggle the tag TAG for the current line.
12542 If ONOFF is `on' or `off', don't toggle but set to this state."
12545 (org-back-to-heading t)
12546 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
12549 (setq current (match-string 1))
12550 (replace-match ""))
12552 (setq current (nreverse (org-split-string current ":")))
12556 (or (member tag current) (push tag current)))
12558 (or (not (member tag current)) (setq current (delete tag current))))
12559 (t (if (member tag current)
12560 (setq current (delete tag current))
12562 (push tag current))))
12566 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
12567 (org-set-tags nil t))
12568 (delete-horizontal-space))
12569 (run-hooks 'org-after-tags-change-hook))
12572 (defun org-align-tags-here (to-col)
12573 ;; Assumes that this is a headline
12574 (let ((pos (point)) (col (current-column)) ncol tags-l p)
12575 (beginning-of-line 1)
12576 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12577 (< pos (match-beginning 2)))
12579 (setq tags-l (- (match-end 2) (match-beginning 2)))
12580 (goto-char (match-beginning 1))
12582 (delete-region (point) (1+ (match-beginning 2)))
12583 (setq ncol (max (1+ (current-column))
12587 (- (abs to-col) tags-l))))
12589 (insert (make-string (- ncol (current-column)) ?\ ))
12590 (setq ncol (current-column))
12591 (when indent-tabs-mode (tabify p (point-at-eol)))
12592 (org-move-to-column (min ncol col) t))
12595 (defun org-set-tags-command (&optional arg just-align)
12596 "Call the set-tags command for the current entry."
12598 (if (org-on-heading-p)
12599 (org-set-tags arg just-align)
12601 (org-back-to-heading t)
12602 (org-set-tags arg just-align))))
12604 (defun org-set-tags-to (data)
12605 "Set the tags of the current entry to DATA, replacing the current tags.
12606 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
12607 If DATA is nil or the empty string, any tags will be removed."
12608 (interactive "sTags: ")
12612 ((equal data "") "")
12614 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
12617 (concat ":" (mapconcat 'identity data ":") ":"))
12621 (org-back-to-heading t)
12622 (when (looking-at org-complex-heading-regexp)
12625 (goto-char (match-beginning 5))
12627 (delete-region (point) (point-at-eol))
12628 (org-set-tags nil 'align))
12629 (goto-char (point-at-eol))
12631 (org-set-tags nil 'align)))
12632 (beginning-of-line 1)
12633 (if (looking-at ".*?\\([ \t]+\\)$")
12634 (delete-region (match-beginning 1) (match-end 1))))))
12636 (defun org-align-all-tags ()
12637 "Align the tags i all headings."
12640 (or (ignore-errors (org-back-to-heading t))
12641 (outline-next-heading))
12642 (if (org-on-heading-p)
12644 (message "No headings"))))
12646 (defun org-set-tags (&optional arg just-align)
12647 "Set the tags for the current headline.
12648 With prefix ARG, realign all tags in headings in the current buffer."
12650 (let* ((re (concat "^" outline-regexp))
12651 (current (org-get-tags-string))
12652 (col (current-column))
12653 (org-setting-tags t)
12654 table current-tags inherited-tags ; computed below when needed
12658 (goto-char (point-min))
12659 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
12660 (while (re-search-forward re nil t)
12661 (org-set-tags nil t)
12663 (message "All tags realigned to column %d" org-tags-column))
12665 (setq tags current)
12666 ;; Get a new set of tags from the user
12668 (setq table (append org-tag-persistent-alist
12669 (or org-tag-alist (org-get-buffer-tags))
12670 (and org-complete-tags-always-offer-all-agenda-tags
12671 (org-global-tags-completion-table (org-agenda-files))))
12672 org-last-tags-completion-table table
12673 current-tags (org-split-string current ":")
12674 inherited-tags (nreverse
12675 (nthcdr (length current-tags)
12676 (nreverse (org-get-tags-at))))
12678 (if (or (eq t org-use-fast-tag-selection)
12679 (and org-use-fast-tag-selection
12680 (delq nil (mapcar 'cdr table))))
12681 (org-fast-tag-selection
12682 current-tags inherited-tags table
12683 (if org-fast-tag-selection-include-todo org-todo-key-alist))
12684 (let ((org-add-colon-after-tag-completion t))
12686 (org-without-partial-completion
12687 (org-icompleting-read "Tags: " 'org-tags-completion-function
12688 nil nil current 'org-tags-history)))))))
12689 (while (string-match "[-+&]+" tags)
12690 ;; No boolean logic, just a list
12691 (setq tags (replace-match ":" t t tags))))
12693 (if org-tags-sort-function
12694 (setq tags (mapconcat 'identity
12695 (sort (org-split-string tags (org-re "[^[:alnum:]_@]+"))
12696 org-tags-sort-function) ":")))
12698 (if (string-match "\\`[\t ]*\\'" tags)
12700 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
12701 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
12703 ;; Insert new tags at the correct column
12704 (beginning-of-line 1)
12706 ((and (equal current "") (equal tags "")))
12707 ((re-search-forward
12708 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
12710 (if (equal tags "")
12712 (goto-char (match-beginning 0))
12713 (setq c0 (current-column) p0 (if (equal (char-before) ?*)
12714 (1+ (point)) (point))
12715 c1 (max (1+ c0) (if (> org-tags-column 0)
12717 (- (- org-tags-column) (length tags))))
12718 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
12719 (replace-match rpl t t)
12720 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
12722 (t (error "Tags alignment failed")))
12723 (org-move-to-column col)
12725 (run-hooks 'org-after-tags-change-hook)))))
12727 (defun org-change-tag-in-region (beg end tag off)
12728 "Add or remove TAG for each entry in the region.
12729 This works in the agenda, and also in an org-mode buffer."
12731 (list (region-beginning) (region-end)
12732 (let ((org-last-tags-completion-table
12734 (org-get-buffer-tags)
12735 (org-global-tags-completion-table))))
12736 (org-icompleting-read
12737 "Tag: " 'org-tags-completion-function nil nil nil
12738 'org-tags-history))
12740 (message "[s]et or [r]emove? ")
12741 (equal (read-char-exclusive) ?r))))
12742 (if (fboundp 'deactivate-mark) (deactivate-mark))
12743 (let ((agendap (equal major-mode 'org-agenda-mode))
12744 l1 l2 m buf pos newhead (cnt 0))
12746 (setq l2 (1- (org-current-line)))
12748 (setq l1 (org-current-line))
12749 (loop for l from l1 to l2 do
12751 (setq m (get-text-property (point) 'org-hd-marker))
12752 (when (or (and (org-mode-p) (org-on-heading-p))
12754 (setq buf (if agendap (marker-buffer m) (current-buffer))
12755 pos (if agendap m (point)))
12756 (with-current-buffer buf
12760 (setq cnt (1+ cnt))
12761 (org-toggle-tag tag (if off 'off 'on))
12762 (setq newhead (org-get-heading)))))
12763 (and agendap (org-agenda-change-all-lines newhead m))))
12764 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
12766 (defun org-tags-completion-function (string predicate &optional flag)
12767 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
12768 (confirm (lambda (x) (stringp (car x)))))
12769 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string)
12770 (setq s1 (match-string 1 string)
12771 s2 (match-string 2 string))
12772 (setq s1 "" s2 string))
12776 (setq rtn (try-completion s2 ctable confirm))
12779 (concat s1 s2 (substring rtn (length s2))
12780 (if (and org-add-colon-after-tag-completion
12781 (assoc rtn ctable))
12786 (all-completions s2 ctable confirm)
12790 (assoc s2 ctable)))
12793 (defun org-fast-tag-insert (kwd tags face &optional end)
12794 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
12795 (insert (format "%-12s" (concat kwd ":"))
12796 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
12799 (defun org-fast-tag-show-exit (flag)
12802 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
12803 (replace-match ""))
12806 (org-move-to-column (- (window-width) 19) t)
12807 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
12809 (defun org-set-current-tags-overlay (current prefix)
12810 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
12811 (if (featurep 'xemacs)
12812 (org-overlay-display org-tags-overlay (concat prefix s)
12813 'secondary-selection)
12814 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
12815 (org-overlay-display org-tags-overlay (concat prefix s)))))
12817 (defvar org-last-tag-selection-key nil)
12818 (defun org-fast-tag-selection (current inherited table &optional todo-table)
12819 "Fast tag selection with single keys.
12820 CURRENT is the current list of tags in the headline, INHERITED is the
12821 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
12822 possibly with grouping information. TODO-TABLE is a similar table with
12823 TODO keywords, should these have keys assigned to them.
12824 If the keys are nil, a-z are automatically assigned.
12825 Returns the new tags string, or nil to not change the current settings."
12826 (let* ((fulltable (append table todo-table))
12827 (maxlen (apply 'max (mapcar
12829 (if (stringp (car x)) (string-width (car x)) 0))
12831 (buf (current-buffer))
12832 (expert (eq org-fast-tag-selection-single-key 'expert))
12834 (fwidth (+ maxlen 3 1 3))
12835 (ncol (/ (- (window-width) 4) fwidth))
12838 tg cnt e c char c1 c2 ntable tbl rtn
12839 ov-start ov-end ov-prefix
12840 (exit-after-next org-fast-tag-selection-single-key)
12841 (done-keywords org-done-keywords)
12844 (beginning-of-line 1)
12846 (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
12847 (setq ov-start (match-beginning 1)
12848 ov-end (match-end 1)
12850 (setq ov-start (1- (point-at-eol))
12851 ov-end (1+ ov-start))
12852 (skip-chars-forward "^\n\r")
12855 (buffer-substring (1- (point)) (point))
12856 (if (> (current-column) org-tags-column)
12858 (make-string (- org-tags-column (current-column)) ?\ ))))))
12859 (move-overlay org-tags-overlay ov-start ov-end)
12860 (save-window-excursion
12862 (set-buffer (get-buffer-create " *Org tags*"))
12863 (delete-other-windows)
12864 (split-window-vertically)
12865 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
12867 (org-set-local 'org-done-keywords done-keywords)
12868 (org-fast-tag-insert "Inherited" inherited i-face "\n")
12869 (org-fast-tag-insert "Current" current c-face "\n\n")
12870 (org-fast-tag-show-exit exit-after-next)
12871 (org-set-current-tags-overlay current ov-prefix)
12872 (setq tbl fulltable char ?a cnt 0)
12873 (while (setq e (pop tbl))
12875 ((equal (car e) :startgroup)
12876 (push '() groups) (setq ingroup t)
12877 (when (not (= cnt 0))
12880 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
12881 ((equal (car e) :endgroup)
12882 (setq ingroup nil cnt 0)
12883 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
12884 ((equal e '(:newline))
12885 (when (not (= cnt 0))
12889 (while (equal (car tbl) '(:newline))
12891 (setq tbl (cdr tbl)))))
12893 (setq tg (copy-sequence (car e)) c2 nil)
12896 ;; automatically assign a character.
12897 (setq c1 (string-to-char
12898 (downcase (substring
12899 tg (if (= (string-to-char tg) ?@) 1 0)))))
12900 (if (or (rassoc c1 ntable) (rassoc c1 table))
12901 (while (or (rassoc char ntable) (rassoc char table))
12902 (setq char (1+ char)))
12904 (setq c (or c2 char)))
12905 (if ingroup (push tg (car groups)))
12906 (setq tg (org-add-props tg nil 'face
12908 ((not (assoc tg table))
12909 (org-get-todo-face tg))
12910 ((member tg current) c-face)
12911 ((member tg inherited) i-face)
12913 (if (and (= cnt 0) (not ingroup)) (insert " "))
12914 (insert "[" c "] " tg (make-string
12915 (- fwidth 4 (length tg)) ?\ ))
12916 (push (cons tg c) ntable)
12917 (when (= (setq cnt (1+ cnt)) ncol)
12919 (if ingroup (insert " "))
12921 (setq ntable (nreverse ntable))
12923 (goto-char (point-min))
12924 (if (not expert) (org-fit-window-to-buffer))
12928 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
12929 (if (not groups) "no " "")
12930 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
12931 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12932 (setq org-last-tag-selection-key c)
12934 ((= c ?\r) (throw 'exit t))
12936 (setq groups (not groups))
12937 (goto-char (point-min))
12938 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
12941 (org-fast-tag-show-exit
12942 (setq exit-after-next (not exit-after-next)))
12944 (delete-other-windows)
12945 (split-window-vertically)
12946 (org-switch-to-buffer-other-window " *Org tags*")
12947 (org-fit-window-to-buffer)))
12949 (and (= c ?q) (not (rassoc c ntable))))
12950 (org-detach-overlay org-tags-overlay)
12951 (setq quit-flag t))
12954 (if exit-after-next (setq exit-after-next 'now)))
12956 (condition-case nil
12957 (setq tg (org-icompleting-read
12960 (with-current-buffer buf
12961 (org-get-buffer-tags)))))
12962 (quit (setq tg "")))
12963 (when (string-match "\\S-" tg)
12964 (add-to-list 'buffer-tags (list tg))
12965 (if (member tg current)
12966 (setq current (delete tg current))
12967 (push tg current)))
12968 (if exit-after-next (setq exit-after-next 'now)))
12969 ((setq e (rassoc c todo-table) tg (car e))
12970 (with-current-buffer buf
12971 (save-excursion (org-todo tg)))
12972 (if exit-after-next (setq exit-after-next 'now)))
12973 ((setq e (rassoc c ntable) tg (car e))
12974 (if (member tg current)
12975 (setq current (delete tg current))
12976 (loop for g in groups do
12979 (setq current (delete x current)))
12982 (if exit-after-next (setq exit-after-next 'now))))
12984 ;; Create a sorted list
12988 (assoc b (cdr (memq (assoc a ntable) ntable))))))
12989 (if (eq exit-after-next 'now) (throw 'exit t))
12990 (goto-char (point-min))
12991 (beginning-of-line 2)
12992 (delete-region (point) (point-at-eol))
12993 (org-fast-tag-insert "Current" current c-face)
12994 (org-set-current-tags-overlay current ov-prefix)
12995 (while (re-search-forward
12996 (org-re "\\[.\\] \\([[:alnum:]_@]+\\)") nil t)
12997 (setq tg (match-string 1))
12998 (add-text-properties
12999 (match-beginning 1) (match-end 1)
13002 ((member tg current) c-face)
13003 ((member tg inherited) i-face)
13004 (t (get-text-property (match-beginning 1) 'face))))))
13005 (goto-char (point-min)))))
13006 (org-detach-overlay org-tags-overlay)
13008 (mapconcat 'identity current ":")
13011 (defun org-get-tags-string ()
13012 "Get the TAGS string in the current headline."
13013 (unless (org-on-heading-p t)
13014 (error "Not on a heading"))
13016 (beginning-of-line 1)
13017 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \t]*$"))
13018 (org-match-string-no-properties 1)
13021 (defun org-get-tags ()
13022 "Get the list of tags specified in the current headline."
13023 (org-split-string (org-get-tags-string) ":"))
13025 (defun org-get-buffer-tags ()
13026 "Get a table of all tags used in the buffer, for completion."
13029 (goto-char (point-min))
13030 (while (re-search-forward
13031 (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t\r\n]") nil t)
13032 (when (equal (char-after (point-at-bol 0)) ?*)
13033 (mapc (lambda (x) (add-to-list 'tags x))
13034 (org-split-string (org-match-string-no-properties 1) ":")))))
13035 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
13036 (mapcar 'list tags)))
13038 ;;;; The mapping API
13041 (defun org-map-entries (func &optional match scope &rest skip)
13042 "Call FUNC at each headline selected by MATCH in SCOPE.
13044 FUNC is a function or a lisp form. The function will be called without
13045 arguments, with the cursor positioned at the beginning of the headline.
13046 The return values of all calls to the function will be collected and
13047 returned as a list.
13049 The call to FUNC will be wrapped into a save-excursion form, so FUNC
13050 does not need to preserve point. After evaluation, the cursor will be
13051 moved to the end of the line (presumably of the headline of the
13052 processed entry) and search continues from there. Under some
13053 circumstances, this may not produce the wanted results. For example,
13054 if you have removed (e.g. archived) the current (sub)tree it could
13055 mean that the next entry will be skipped entirely. In such cases, you
13056 can specify the position from where search should continue by making
13057 FUNC set the variable `org-map-continue-from' to the desired buffer
13060 MATCH is a tags/property/todo match as it is used in the agenda tags view.
13061 Only headlines that are matched by this query will be considered during
13062 the iteration. When MATCH is nil or t, all headlines will be
13063 visited by the iteration.
13065 SCOPE determines the scope of this command. It can be any of:
13067 nil The current buffer, respecting the restriction if any
13068 tree The subtree started with the entry at point
13069 file The current buffer, without restriction
13071 The current buffer, and any archives associated with it
13072 agenda All agenda files
13073 agenda-with-archives
13074 All agenda files with any archive files associated with them
13076 If this is a list, all files in the list will be scanned
13078 The remaining args are treated as settings for the skipping facilities of
13079 the scanner. The following items can be given here:
13081 archive skip trees with the archive tag.
13082 comment skip trees with the COMMENT keyword
13083 function or Emacs Lisp form:
13084 will be used as value for `org-agenda-skip-function', so whenever
13085 the function returns t, FUNC will not be called for that
13086 entry and search will continue from the point where the
13087 function leaves it.
13089 If your function needs to retrieve the tags including inherited tags
13090 at the *current* entry, you can use the value of the variable
13091 `org-scanner-tags' which will be much faster than getting the value
13092 with `org-get-tags-at'. If your function gets properties with
13093 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
13094 to t around the call to `org-entry-properties' to get the same speedup.
13095 Note that if your function moves around to retrieve tags and properties at
13096 a *different* entry, you cannot use these techniques."
13097 (let* ((org-agenda-archives-mode nil) ; just to make sure
13098 (org-agenda-skip-archived-trees (memq 'archive skip))
13099 (org-agenda-skip-comment-trees (memq 'comment skip))
13100 (org-agenda-skip-function
13101 (car (org-delete-all '(comment archive) skip)))
13102 (org-tags-match-list-sublevels t)
13104 org-todo-keywords-for-agenda
13105 org-done-keywords-for-agenda
13106 org-todo-keyword-alist-for-agenda
13107 org-drawers-for-agenda
13108 org-tag-alist-for-agenda)
13111 ((eq match t) (setq matcher t))
13112 ((eq match nil) (setq matcher t))
13113 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
13117 (when (eq scope 'tree)
13118 (org-back-to-heading t)
13119 (org-narrow-to-subtree)
13124 (org-prepare-agenda-buffers
13125 (list (buffer-file-name (current-buffer))))
13126 (setq res (org-scan-tags func matcher)))
13127 ;; Get the right scope
13129 ((and scope (listp scope) (symbolp (car scope)))
13130 (setq scope (eval scope)))
13131 ((eq scope 'agenda)
13132 (setq scope (org-agenda-files t)))
13133 ((eq scope 'agenda-with-archives)
13134 (setq scope (org-agenda-files t))
13135 (setq scope (org-add-archive-files scope)))
13137 (setq scope (list (buffer-file-name))))
13138 ((eq scope 'file-with-archives)
13139 (setq scope (org-add-archive-files (list (buffer-file-name))))))
13140 (org-prepare-agenda-buffers scope)
13141 (while (setq file (pop scope))
13142 (with-current-buffer (org-find-base-buffer-visiting file)
13146 (goto-char (point-min))
13147 (setq res (append res (org-scan-tags func matcher))))))))))
13152 ;;; Setting and retrieving properties
13154 (defconst org-special-properties
13155 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
13156 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED")
13157 "The special properties valid in Org-mode.
13159 These are properties that are not defined in the property drawer,
13160 but in some other way.")
13162 (defconst org-default-properties
13163 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
13164 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
13165 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
13166 "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
13167 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
13168 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
13169 "Some properties that are used by Org-mode for various purposes.
13170 Being in this list makes sure that they are offered for completion.")
13172 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
13173 "Regular expression matching the first line of a property drawer.")
13175 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
13176 "Regular expression matching the last line of a property drawer.")
13178 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
13179 "Regular expression matching the first line of a property drawer.")
13181 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
13182 "Regular expression matching the first line of a property drawer.")
13184 (defconst org-property-drawer-re
13185 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
13186 org-property-end-re "\\)\n?")
13187 "Matches an entire property drawer.")
13189 (defconst org-clock-drawer-re
13190 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
13191 org-property-end-re "\\)\n?")
13192 "Matches an entire clock drawer.")
13194 (defun org-property-action ()
13195 "Do an action on properties."
13198 (org-at-property-p)
13199 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
13200 (setq c (read-char-exclusive))
13203 (call-interactively 'org-set-property))
13205 (call-interactively 'org-delete-property))
13207 (call-interactively 'org-delete-property-globally))
13209 (call-interactively 'org-compute-property-at-point))
13210 (t (error "No such property action %c" c)))))
13212 (defun org-set-effort (&optional value)
13213 "Set the effort property of the current entry.
13214 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
13217 (if (equal value 0) (setq value 10))
13218 (let* ((completion-ignore-case t)
13219 (prop org-effort-property)
13220 (cur (org-entry-get nil prop))
13221 (allowed (org-property-get-allowed-values nil prop 'table))
13222 (existing (mapcar 'list (org-property-values prop)))
13225 ((stringp value) value)
13226 ((and allowed (integerp value))
13227 (or (car (nth (1- value) allowed))
13228 (car (org-last allowed))))
13230 (message "Select 1-9,0, [RET%s]: %s"
13231 (if cur (concat "=" cur) "")
13232 (mapconcat 'car allowed " "))
13233 (setq rpl (read-char-exclusive))
13234 (if (equal rpl ?\r)
13236 (setq rpl (- rpl ?0))
13237 (if (equal rpl 0) (setq rpl 10))
13238 (if (and (> rpl 0) (<= rpl (length allowed)))
13239 (car (nth (1- rpl) allowed))
13240 (org-completing-read "Effort: " allowed nil))))
13242 (let (org-completion-use-ido org-completion-use-iswitchb)
13243 (org-completing-read
13244 (concat "Effort " (if (and cur (string-match "\\S-" cur))
13245 (concat "[" cur "]") "")
13247 existing nil nil "" nil cur))))))
13248 (unless (equal (org-entry-get nil prop) val)
13249 (org-entry-put nil prop val))
13250 (message "%s is now %s" prop val)))
13252 (defun org-at-property-p ()
13253 "Is cursor inside a property drawer?"
13255 (beginning-of-line 1)
13256 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
13257 (save-match-data ;; Used by calling procedures
13259 (range (unless (org-before-first-heading-p)
13260 (org-get-property-block))))
13261 (and range (<= (car range) p) (< p (cdr range))))))))
13263 (defun org-get-property-block (&optional beg end force)
13264 "Return the (beg . end) range of the body of the property drawer.
13265 BEG and END can be beginning and end of subtree, if not given
13266 they will be found.
13267 If the drawer does not exist and FORCE is non-nil, create the drawer."
13270 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
13271 (end (or end (progn (outline-next-heading) (point)))))
13273 (if (re-search-forward org-property-start-re end t)
13274 (setq beg (1+ (match-end 0)))
13277 (org-insert-property-drawer)
13278 (setq end (progn (outline-next-heading) (point))))
13281 (if (re-search-forward org-property-start-re end t)
13282 (setq beg (1+ (match-end 0)))))
13283 (if (re-search-forward org-property-end-re end t)
13284 (setq end (match-beginning 0))
13285 (or force (throw 'exit nil))
13288 (org-indent-line-function)
13289 (insert ":END:\n"))
13292 (defun org-entry-properties (&optional pom which specific)
13293 "Get all properties of the entry at point-or-marker POM.
13294 This includes the TODO keyword, the tags, time strings for deadline,
13295 scheduled, and clocking, and any additional properties defined in the
13296 entry. The return value is an alist, keys may occur multiple times
13297 if the property key was used several times.
13298 POM may also be nil, in which case the current entry is used.
13299 If WHICH is nil or `all', get all properties. If WHICH is
13300 `special' or `standard', only get that subclass. If WHICH
13301 is a string only get exactly this property. Specific can be a string, the
13302 specific property we are interested in. Specifying it can speed
13303 things up because then unnecessary parsing is avoided."
13304 (setq which (or which 'all))
13305 (org-with-point-at pom
13306 (let ((clockstr (substring org-clock-string 0 -1))
13307 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
13308 (case-fold-search nil)
13309 beg end range props sum-props key key1 value string clocksum)
13311 (when (condition-case nil
13312 (and (org-mode-p) (org-back-to-heading t))
13315 (setq sum-props (get-text-property (point) 'org-summaries))
13316 (setq clocksum (get-text-property (point) :org-clock-minutes))
13317 (outline-next-heading)
13319 (when (memq which '(all special))
13320 ;; Get the special properties, like TODO and tags
13322 (when (and (or (not specific) (string= specific "TODO"))
13323 (looking-at org-todo-line-regexp) (match-end 2))
13324 (push (cons "TODO" (org-match-string-no-properties 2)) props))
13325 (when (and (or (not specific) (string= specific "PRIORITY"))
13326 (looking-at org-priority-regexp))
13327 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
13328 (when (and (or (not specific) (string= specific "TAGS"))
13329 (setq value (org-get-tags-string))
13330 (string-match "\\S-" value))
13331 (push (cons "TAGS" value) props))
13332 (when (and (or (not specific) (string= specific "ALLTAGS"))
13333 (setq value (org-get-tags-at)))
13334 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
13337 (when (or (not specific) (string= specific "BLOCKED"))
13338 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
13339 (when (or (not specific)
13341 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
13342 "TIMESTAMP" "TIMESTAMP_IA")))
13343 (while (re-search-forward org-maybe-keyword-time-regexp end t)
13344 (setq key (if (match-end 1)
13345 (substring (org-match-string-no-properties 1)
13347 string (if (equal key clockstr)
13351 (match-beginning 3) (goto-char
13353 (substring (org-match-string-no-properties 3)
13355 ;; Get the correct property name from the key. This is
13356 ;; necessary if the user has configured time keywords.
13357 (setq key1 (concat key ":"))
13361 (if (= (char-after (match-beginning 3)) ?\[)
13362 "TIMESTAMP_IA" "TIMESTAMP")))
13363 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
13364 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
13365 ((equal key1 org-closed-string) (setq key "CLOSED"))
13366 ((equal key1 org-clock-string) (setq key "CLOCK")))
13367 (when (or (equal key "CLOCK") (not (assoc key props)))
13368 (push (cons key string) props))))
13371 (when (memq which '(all standard))
13372 ;; Get the standard properties, like :PROP: ...
13373 (setq range (org-get-property-block beg end))
13375 (goto-char (car range))
13376 (while (re-search-forward
13377 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
13379 (setq key (org-match-string-no-properties 1)
13380 value (org-trim (or (org-match-string-no-properties 2) "")))
13381 (unless (member key excluded)
13382 (push (cons key (or value "")) props)))))
13384 (push (cons "CLOCKSUM"
13385 (org-columns-number-to-string (/ (float clocksum) 60.)
13388 (unless (assoc "CATEGORY" props)
13389 (setq value (or (org-get-category)
13390 (progn (org-refresh-category-properties)
13391 (org-get-category))))
13392 (push (cons "CATEGORY" value) props))
13393 (append sum-props (nreverse props)))))))
13395 (defun org-entry-get (pom property &optional inherit literal-nil)
13396 "Get value of PROPERTY for entry at point-or-marker POM.
13397 If INHERIT is non-nil and the entry does not have the property,
13398 then also check higher levels of the hierarchy.
13399 If INHERIT is the symbol `selective', use inheritance only if the setting
13400 in `org-use-property-inheritance' selects PROPERTY for inheritance.
13401 If the property is present but empty, the return value is the empty string.
13402 If the property is not present at all, nil is returned.
13404 If LITERAL-NIL is set, return the string value \"nil\" as a string,
13405 do not interpret it as the list atom nil. This is used for inheritance
13406 when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
13407 (org-with-point-at pom
13408 (if (and inherit (if (eq inherit 'selective)
13409 (org-property-inherit-p property)
13411 (org-entry-get-with-inheritance property literal-nil)
13412 (if (member property org-special-properties)
13413 ;; We need a special property. Use `org-entry-properties' to
13414 ;; retrieve it, but specify the wanted property
13415 (cdr (assoc property (org-entry-properties nil 'special property)))
13416 (let ((range (org-get-property-block)))
13418 (goto-char (car range))
13420 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)?")
13422 ;; Found the property, return it.
13425 (org-match-string-no-properties 1)
13426 (org-not-nil (org-match-string-no-properties 1)))
13429 (defun org-property-or-variable-value (var &optional inherit)
13430 "Check if there is a property fixing the value of VAR.
13431 If yes, return this value. If not, return the current value of the variable."
13432 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
13433 (if (and prop (stringp prop) (string-match "\\S-" prop))
13435 (symbol-value var))))
13437 (defun org-entry-delete (pom property)
13438 "Delete the property PROPERTY from entry at point-or-marker POM."
13439 (org-with-point-at pom
13440 (if (member property org-special-properties)
13441 nil ; cannot delete these properties.
13442 (let ((range (org-get-property-block)))
13444 (goto-char (car range))
13446 (concat "^[ \t]*:" property ":[ \t]*\\(.*[^ \t\r\n\f\v]\\)")
13449 (delete-region (match-beginning 0) (1+ (point-at-eol)))
13453 ;; Multi-values properties are properties that contain multiple values
13454 ;; These values are assumed to be single words, separated by whitespace.
13455 (defun org-entry-add-to-multivalued-property (pom property value)
13456 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
13457 (let* ((old (org-entry-get pom property))
13458 (values (and old (org-split-string old "[ \t]"))))
13459 (setq value (org-entry-protect-space value))
13460 (unless (member value values)
13461 (setq values (cons value values))
13462 (org-entry-put pom property
13463 (mapconcat 'identity values " ")))))
13465 (defun org-entry-remove-from-multivalued-property (pom property value)
13466 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
13467 (let* ((old (org-entry-get pom property))
13468 (values (and old (org-split-string old "[ \t]"))))
13469 (setq value (org-entry-protect-space value))
13470 (when (member value values)
13471 (setq values (delete value values))
13472 (org-entry-put pom property
13473 (mapconcat 'identity values " ")))))
13475 (defun org-entry-member-in-multivalued-property (pom property value)
13476 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
13477 (let* ((old (org-entry-get pom property))
13478 (values (and old (org-split-string old "[ \t]"))))
13479 (setq value (org-entry-protect-space value))
13480 (member value values)))
13482 (defun org-entry-get-multivalued-property (pom property)
13483 "Return a list of values in a multivalued property."
13484 (let* ((value (org-entry-get pom property))
13485 (values (and value (org-split-string value "[ \t]"))))
13486 (mapcar 'org-entry-restore-space values)))
13488 (defun org-entry-put-multivalued-property (pom property &rest values)
13489 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
13490 VALUES should be a list of strings. Spaces will be protected."
13491 (org-entry-put pom property
13492 (mapconcat 'org-entry-protect-space values " "))
13493 (let* ((value (org-entry-get pom property))
13494 (values (and value (org-split-string value "[ \t]"))))
13495 (mapcar 'org-entry-restore-space values)))
13497 (defun org-entry-protect-space (s)
13498 "Protect spaces and newline in string S."
13499 (while (string-match " " s)
13500 (setq s (replace-match "%20" t t s)))
13501 (while (string-match "\n" s)
13502 (setq s (replace-match "%0A" t t s)))
13505 (defun org-entry-restore-space (s)
13506 "Restore spaces and newline in string S."
13507 (while (string-match "%20" s)
13508 (setq s (replace-match " " t t s)))
13509 (while (string-match "%0A" s)
13510 (setq s (replace-match "\n" t t s)))
13513 (defvar org-entry-property-inherited-from (make-marker)
13514 "Marker pointing to the entry from where a property was inherited.
13515 Each call to `org-entry-get-with-inheritance' will set this marker to the
13516 location of the entry where the inheritance search matched. If there was
13517 no match, the marker will point nowhere.
13518 Note that also `org-entry-get' calls this function, if the INHERIT flag
13521 (defun org-entry-get-with-inheritance (property &optional literal-nil)
13522 "Get entry property, and search higher levels if not present.
13523 The search will stop at the first ancestor which has the property defined.
13524 If the value found is \"nil\", return nil to show that the property
13525 should be considered as undefined (this is the meaning of nil here).
13526 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
13527 (move-marker org-entry-property-inherited-from nil)
13534 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
13535 (org-back-to-heading t)
13536 (move-marker org-entry-property-inherited-from (point))
13538 (or (org-up-heading-safe) (throw 'ex nil)))))
13540 (cdr (assoc property org-file-properties))
13541 (cdr (assoc property org-global-properties))
13542 (cdr (assoc property org-global-properties-fixed))))
13543 (if literal-nil tmp (org-not-nil tmp)))))
13545 (defvar org-property-changed-functions nil
13546 "Hook called when the value of a property has changed.
13547 Each hook function should accept two arguments, the name of the property
13548 and the new value.")
13550 (defun org-entry-put (pom property value)
13551 "Set PROPERTY to VALUE for entry at point-or-marker POM."
13552 (org-with-point-at pom
13553 (org-back-to-heading t)
13554 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
13557 ((equal property "TODO")
13558 (when (and (stringp value) (string-match "\\S-" value)
13559 (not (member value org-todo-keywords-1)))
13560 (error "\"%s\" is not a valid TODO state" value))
13561 (if (or (not value)
13562 (not (string-match "\\S-" value)))
13563 (setq value 'none))
13565 (org-set-tags nil 'align))
13566 ((equal property "PRIORITY")
13567 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
13568 (string-to-char value) ?\ ))
13569 (org-set-tags nil 'align))
13570 ((equal property "SCHEDULED")
13571 (if (re-search-forward org-scheduled-time-regexp end t)
13573 ((eq value 'earlier) (org-timestamp-change -1 'day))
13574 ((eq value 'later) (org-timestamp-change 1 'day))
13575 (t (call-interactively 'org-schedule)))
13576 (call-interactively 'org-schedule)))
13577 ((equal property "DEADLINE")
13578 (if (re-search-forward org-deadline-time-regexp end t)
13580 ((eq value 'earlier) (org-timestamp-change -1 'day))
13581 ((eq value 'later) (org-timestamp-change 1 'day))
13582 (t (call-interactively 'org-deadline)))
13583 (call-interactively 'org-deadline)))
13584 ((member property org-special-properties)
13585 (error "The %s property can not yet be set with `org-entry-put'"
13587 (t ; a non-special property
13588 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
13589 (setq range (org-get-property-block beg end 'force))
13590 (goto-char (car range))
13591 (if (re-search-forward
13592 (concat "^[ \t]*:" property ":\\(.*\\)") (cdr range) t)
13594 (delete-region (match-beginning 1) (match-end 1))
13595 (goto-char (match-beginning 1)))
13596 (goto-char (cdr range))
13599 (org-indent-line-function)
13600 (insert ":" property ":"))
13601 (and value (insert " " value))
13602 (org-indent-line-function)))))
13603 (run-hook-with-args 'org-property-changed-functions property value)))
13605 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
13606 "Get all property keys in the current buffer.
13607 With INCLUDE-SPECIALS, also list the special properties that reflect things
13608 like tags and TODO state.
13609 With INCLUDE-DEFAULTS, also include properties that has special meaning
13610 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING.
13611 With INCLUDE-COLUMNS, also include property names given in COLUMN
13612 formats in the current buffer."
13613 (let (rtn range cfmt s p)
13617 (goto-char (point-min))
13618 (while (re-search-forward org-property-start-re nil t)
13619 (setq range (org-get-property-block))
13620 (goto-char (car range))
13621 (while (re-search-forward
13622 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
13624 (add-to-list 'rtn (org-match-string-no-properties 1)))
13625 (outline-next-heading))))
13627 (when include-specials
13628 (setq rtn (append org-special-properties rtn)))
13630 (when include-defaults
13631 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
13632 (add-to-list 'rtn org-effort-property))
13634 (when include-columns
13638 (goto-char (point-min))
13639 (while (re-search-forward
13640 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
13642 (setq cfmt (match-string 2) s 0)
13643 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
13645 (setq s (match-end 0)
13646 p (match-string 1 cfmt))
13647 (unless (or (equal p "ITEM")
13648 (member p org-special-properties))
13649 (add-to-list 'rtn (match-string 1 cfmt))))))))
13651 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
13653 (defun org-property-values (key)
13654 "Return a list of all values of property KEY."
13658 (goto-char (point-min))
13659 (let ((re (concat "^[ \t]*:" key ":[ \t]*\\(\\S-.*\\)"))
13661 (while (re-search-forward re nil t)
13662 (add-to-list 'values (org-trim (match-string 1))))
13663 (delete "" values)))))
13665 (defun org-insert-property-drawer ()
13666 "Insert a property drawer into the current entry."
13668 (org-back-to-heading t)
13669 (looking-at outline-regexp)
13670 (let ((indent (if org-adapt-indentation
13671 (- (match-end 0)(match-beginning 0))
13674 (re (concat "^[ \t]*" org-keyword-time-regexp))
13676 (outline-next-heading)
13679 (while (re-search-forward re end t))
13680 (setq hiddenp (org-invisible-p))
13682 (and (equal (char-after) ?\n) (forward-char 1))
13683 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
13684 (if (member (match-string 1) '("CLOCK:" ":END:"))
13685 ;; just skip this line
13686 (beginning-of-line 2)
13687 ;; Drawer start, find the end
13688 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
13689 (beginning-of-line 1)))
13690 (org-skip-over-state-notes)
13691 (skip-chars-backward " \t\n\r")
13692 (if (eq (char-before) ?*) (forward-char 1))
13693 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
13694 (beginning-of-line 0)
13695 (org-indent-to-column indent)
13696 (beginning-of-line 2)
13697 (org-indent-to-column indent)
13698 (beginning-of-line 0)
13701 (org-back-to-heading t)
13703 (org-flag-drawer t))))
13705 (defun org-set-property (property value)
13706 "In the current entry, set PROPERTY to VALUE.
13707 When called interactively, this will prompt for a property name, offering
13708 completion on existing and default properties. And then it will prompt
13709 for a value, offering completion either on allowed values (via an inherited
13710 xxx_ALL property) or on existing values in other instances of this property
13711 in the current file."
13713 (let* ((completion-ignore-case t)
13714 (keys (org-buffer-property-keys nil t t))
13715 (prop0 (org-icompleting-read "Property: " (mapcar 'list keys)))
13716 (prop (if (member prop0 keys)
13718 (or (cdr (assoc (downcase prop0)
13719 (mapcar (lambda (x) (cons (downcase x) x))
13722 (cur (org-entry-get nil prop))
13723 (prompt (concat prop " value"
13724 (if (and cur (string-match "\\S-" cur))
13725 (concat " [" cur "]") "") ": "))
13726 (allowed (org-property-get-allowed-values nil prop 'table))
13727 (existing (mapcar 'list (org-property-values prop)))
13729 (org-completing-read prompt allowed nil
13730 (not (get-text-property 0 'org-unrestricted
13732 (let (org-completion-use-ido org-completion-use-iswitchb)
13733 (org-completing-read prompt existing nil nil "" nil cur)))))
13734 (list prop (if (equal val "") cur val))))
13735 (unless (equal (org-entry-get nil property) value)
13736 (org-entry-put nil property value)))
13738 (defun org-delete-property (property)
13739 "In the current entry, delete PROPERTY."
13741 (let* ((completion-ignore-case t)
13742 (prop (org-icompleting-read "Property: "
13743 (org-entry-properties nil 'standard))))
13745 (message "Property %s %s" property
13746 (if (org-entry-delete nil property)
13748 "was not present in the entry")))
13750 (defun org-delete-property-globally (property)
13751 "Remove PROPERTY globally, from all entries."
13753 (let* ((completion-ignore-case t)
13754 (prop (org-icompleting-read
13755 "Globally remove property: "
13756 (mapcar 'list (org-buffer-property-keys)))))
13761 (goto-char (point-min))
13763 (while (re-search-forward
13764 (concat "^[ \t]*:" (regexp-quote property) ":.*\n?")
13766 (setq cnt (1+ cnt))
13767 (replace-match ""))
13768 (message "Property \"%s\" removed from %d entries" property cnt)))))
13770 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
13772 (defun org-compute-property-at-point ()
13773 "Compute the property at point.
13774 This looks for an enclosing column format, extracts the operator and
13775 then applies it to the property in the column format's scope."
13777 (unless (org-at-property-p)
13778 (error "Not at a property"))
13779 (let ((prop (org-match-string-no-properties 2)))
13780 (org-columns-get-format-and-top-level)
13781 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
13782 (error "No operator defined for property %s" prop))
13783 (org-columns-compute prop)))
13785 (defvar org-property-allowed-value-functions nil
13786 "Hook for functions supplying allowed values for a specific property.
13787 The functions must take a single argument, the name of the property, and
13788 return a flat list of allowed values. If \":ETC\" is one of
13789 the values, this means that these values are intended as defaults for
13790 completion, but that other values should be allowed too.
13791 The functions must return nil if they are not responsible for this
13794 (defun org-property-get-allowed-values (pom property &optional table)
13795 "Get allowed values for the property PROPERTY.
13796 When TABLE is non-nil, return an alist that can directly be used for
13800 ((equal property "TODO")
13801 (setq vals (org-with-point-at pom
13802 (append org-todo-keywords-1 '("")))))
13803 ((equal property "PRIORITY")
13804 (let ((n org-lowest-priority))
13805 (while (>= n org-highest-priority)
13806 (push (char-to-string n) vals)
13808 ((member property org-special-properties))
13809 ((setq vals (run-hook-with-args-until-success
13810 'org-property-allowed-value-functions property)))
13812 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
13813 (when (and vals (string-match "\\S-" vals))
13814 (setq vals (car (read-from-string (concat "(" vals ")"))))
13815 (setq vals (mapcar (lambda (x)
13816 (cond ((stringp x) x)
13817 ((numberp x) (number-to-string x))
13818 ((symbolp x) (symbol-name x))
13821 (when (member ":ETC" vals)
13822 (setq vals (remove ":ETC" vals))
13823 (org-add-props (car vals) '(org-unrestricted t)))
13824 (if table (mapcar 'list vals) vals)))
13826 (defun org-property-previous-allowed-value (&optional previous)
13827 "Switch to the next allowed value for this property."
13829 (org-property-next-allowed-value t))
13831 (defun org-property-next-allowed-value (&optional previous)
13832 "Switch to the next allowed value for this property."
13834 (unless (org-at-property-p)
13835 (error "Not at a property"))
13836 (let* ((key (match-string 2))
13837 (value (match-string 3))
13838 (allowed (or (org-property-get-allowed-values (point) key)
13839 (and (member value '("[ ]" "[-]" "[X]"))
13843 (error "Allowed values for this property have not been defined"))
13844 (if previous (setq allowed (reverse allowed)))
13845 (if (member value allowed)
13846 (setq nval (car (cdr (member value allowed)))))
13847 (setq nval (or nval (car allowed)))
13848 (if (equal nval value)
13849 (error "Only one allowed value for this property"))
13850 (org-at-property-p)
13851 (replace-match (concat " :" key ": " nval) t t)
13852 (org-indent-line-function)
13853 (beginning-of-line 1)
13854 (skip-chars-forward " \t")
13855 (run-hook-with-args 'org-property-changed-functions key nval)))
13857 (defun org-find-olp (path &optional this-buffer)
13858 "Return a marker pointing to the entry at outline path OLP.
13859 If anything goes wrong, throw an error.
13860 You can wrap this call to catch the error like this:
13862 (condition-case msg
13863 (org-mobile-locate-entry (match-string 4))
13864 (error (nth 1 msg)))
13866 The return value will then be either a string with the error message,
13867 or a marker if everything is OK.
13869 If THIS-BUFFER is set, the outline path does not contain a file,
13871 (let* ((file (if this-buffer buffer-file-name (pop path)))
13872 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
13876 limit re end found pos heading cnt)
13877 (unless buffer (error "File not found :%s" file))
13878 (with-current-buffer buffer
13882 (setq limit (point-max))
13883 (goto-char (point-min))
13884 (while (setq heading (pop path))
13885 (setq re (format org-complex-heading-regexp-format
13886 (regexp-quote heading)))
13887 (setq cnt 0 pos (point))
13888 (while (re-search-forward re end t)
13889 (setq level (- (match-end 1) (match-beginning 1)))
13890 (if (and (>= level lmin) (<= level lmax))
13891 (setq found (match-beginning 0) cnt (1+ cnt))))
13892 (when (= cnt 0) (error "Heading not found on level %d: %s"
13894 (when (> cnt 1) (error "Heading not unique on level %d: %s"
13897 (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0)))
13898 (setq end (save-excursion (org-end-of-subtree t t))))
13899 (when (org-on-heading-p)
13900 (move-marker (make-marker) (point))))))))
13902 (defun org-find-entry-with-id (ident)
13903 "Locate the entry that contains the ID property with exact value IDENT.
13904 IDENT can be a string, a symbol or a number, this function will search for
13905 the string representation of it.
13906 Return the position where this entry starts, or nil if there is no such entry."
13907 (interactive "sID: ")
13909 ((stringp ident) ident)
13910 ((symbol-name ident) (symbol-name ident))
13911 ((numberp ident) (number-to-string ident))
13912 (t (error "IDENT %s must be a string, symbol or number" ident))))
13913 (case-fold-search nil))
13917 (goto-char (point-min))
13918 (when (re-search-forward
13919 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
13921 (org-back-to-heading t)
13926 (defvar org-last-changed-timestamp nil)
13927 (defvar org-last-inserted-timestamp nil
13928 "The last time stamp inserted with `org-insert-time-stamp'.")
13929 (defvar org-time-was-given) ; dynamically scoped parameter
13930 (defvar org-end-time-was-given) ; dynamically scoped parameter
13931 (defvar org-ts-what) ; dynamically scoped parameter
13933 (defun org-time-stamp (arg &optional inactive)
13934 "Prompt for a date/time and insert a time stamp.
13935 If the user specifies a time like HH:MM, or if this command is called
13936 with a prefix argument, the time stamp will contain date and time.
13937 Otherwise, only the date will be included. All parts of a date not
13938 specified by the user will be filled in from the current date/time.
13939 So if you press just return without typing anything, the time stamp
13940 will represent the current date/time. If there is already a timestamp
13941 at the cursor, it will be modified."
13945 ;; Default time is either today, or, when entering a range,
13946 ;; the range start.
13947 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
13949 (re-search-backward
13950 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
13951 (- (point) 20) t)))
13952 (apply 'encode-time (org-parse-time-string (match-string 1)))
13954 (default-input (and ts (org-get-compact-tod ts)))
13955 org-time-was-given org-end-time-was-given time)
13957 ((and (org-at-timestamp-p t)
13958 (memq last-command '(org-time-stamp org-time-stamp-inactive))
13959 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
13961 (setq time (let ((this-command this-command))
13962 (org-read-date arg 'totime nil nil
13963 default-time default-input)))
13964 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
13965 ((org-at-timestamp-p t)
13966 (setq time (let ((this-command this-command))
13967 (org-read-date arg 'totime nil nil default-time default-input)))
13968 (when (org-at-timestamp-p t) ; just to get the match data
13969 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
13971 (setq org-last-changed-timestamp
13972 (org-insert-time-stamp
13973 time (or org-time-was-given arg)
13974 inactive nil nil (list org-end-time-was-given))))
13975 (message "Timestamp updated"))
13977 (setq time (let ((this-command this-command))
13978 (org-read-date arg 'totime nil nil default-time default-input)))
13979 (org-insert-time-stamp time (or org-time-was-given arg) inactive
13980 nil nil (list org-end-time-was-given))))))
13982 ;; FIXME: can we use this for something else, like computing time differences?
13983 (defun org-get-compact-tod (s)
13984 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
13985 (let* ((t1 (match-string 1 s))
13986 (h1 (string-to-number (match-string 2 s)))
13987 (m1 (string-to-number (match-string 3 s)))
13988 (t2 (and (match-end 4) (match-string 5 s)))
13989 (h2 (and t2 (string-to-number (match-string 6 s))))
13990 (m2 (and t2 (string-to-number (match-string 7 s))))
13994 (setq dh (- h2 h1) dm (- m2 m1))
13995 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
13996 (concat t1 "+" (number-to-string dh)
13997 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
13999 (defun org-time-stamp-inactive (&optional arg)
14000 "Insert an inactive time stamp.
14001 An inactive time stamp is enclosed in square brackets instead of angle
14002 brackets. It is inactive in the sense that it does not trigger agenda entries,
14003 does not link to the calendar and cannot be changed with the S-cursor keys.
14004 So these are more for recording a certain time/date."
14006 (org-time-stamp arg 'inactive))
14008 (defvar org-date-ovl (make-overlay 1 1))
14009 (overlay-put org-date-ovl 'face 'org-warning)
14010 (org-detach-overlay org-date-ovl)
14012 (defvar org-ans1) ; dynamically scoped parameter
14013 (defvar org-ans2) ; dynamically scoped parameter
14015 (defvar org-plain-time-of-day-regexp) ; defined below
14017 (defvar org-overriding-default-time nil) ; dynamically scoped
14018 (defvar org-read-date-overlay nil)
14019 (defvar org-dcst nil) ; dynamically scoped
14020 (defvar org-read-date-history nil)
14021 (defvar org-read-date-final-answer nil)
14023 (defun org-read-date (&optional with-time to-time from-string prompt
14024 default-time default-input)
14025 "Read a date, possibly a time, and make things smooth for the user.
14026 The prompt will suggest to enter an ISO date, but you can also enter anything
14027 which will at least partially be understood by `parse-time-string'.
14028 Unrecognized parts of the date will default to the current day, month, year,
14029 hour and minute. If this command is called to replace a timestamp at point,
14030 of to enter the second timestamp of a range, the default time is taken
14031 from the existing stamp. Furthermore, the command prefers the future,
14032 so if you are giving a date where the year is not given, and the day-month
14033 combination is already past in the current year, it will assume you
14034 mean next year. For details, see the manual. A few examples:
14036 3-2-5 --> 2003-02-05
14037 feb 15 --> currentyear-02-15
14038 2/15 --> currentyear-02-15
14039 sep 12 9 --> 2009-09-12
14040 12:45 --> today 12:45
14041 22 sept 0:34 --> currentyear-09-22 0:34
14042 12 --> currentyear-currentmonth-12
14043 Fri --> nearest Friday (today or later)
14046 Furthermore you can specify a relative date by giving, as the *first* thing
14047 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
14048 change in days weeks, months, years.
14049 With a single plus or minus, the date is relative to today. With a double
14050 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
14051 +4d --> four days from today
14052 +4 --> same as above
14053 +2w --> two weeks from today
14054 ++5 --> five days from default date
14056 The function understands only English month and weekday abbreviations,
14057 but this can be configured with the variables `parse-time-months' and
14058 `parse-time-weekdays'.
14060 While prompting, a calendar is popped up - you can also select the
14061 date with the mouse (button 1). The calendar shows a period of three
14062 months. To scroll it to other months, use the keys `>' and `<'.
14063 If you don't like the calendar, turn it off with
14064 \(setq org-read-date-popup-calendar nil)
14066 With optional argument TO-TIME, the date will immediately be converted
14067 to an internal time.
14068 With an optional argument WITH-TIME, the prompt will suggest to also
14069 insert a time. Note that when WITH-TIME is not set, you can still
14070 enter a time, and this function will inform the calling routine about
14071 this change. The calling routine may then choose to change the format
14072 used to insert the time stamp into the buffer to include the time.
14073 With optional argument FROM-STRING, read from this string instead from
14074 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
14075 the time/date that is used for everything that is not specified by the
14077 (require 'parse-time)
14078 (let* ((org-time-stamp-rounding-minutes
14079 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
14080 (org-dcst org-display-custom-times)
14081 (ct (org-current-time))
14082 (def (or org-overriding-default-time default-time ct))
14083 (defdecode (decode-time def))
14085 (when (< (nth 2 defdecode) org-extend-today-until)
14086 (setcar (nthcdr 2 defdecode) -1)
14087 (setcar (nthcdr 1 defdecode) 59)
14088 (setq def (apply 'encode-time defdecode)
14089 defdecode (decode-time def)))))
14090 (calendar-frame-setup nil)
14091 (calendar-setup nil)
14092 (calendar-move-hook nil)
14093 (calendar-view-diary-initially-flag nil)
14094 (calendar-view-holidays-initially-flag nil)
14095 (timestr (format-time-string
14096 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
14097 (prompt (concat (if prompt (concat prompt " ") "")
14098 (format "Date+time [%s]: " timestr)))
14099 ans (org-ans0 "") org-ans1 org-ans2 final)
14102 (from-string (setq ans from-string))
14103 (org-read-date-popup-calendar
14105 (save-window-excursion
14107 (calendar-forward-day (- (time-to-days def)
14108 (calendar-absolute-from-gregorian
14109 (calendar-current-date))))
14110 (org-eval-in-calendar nil t)
14111 (let* ((old-map (current-local-map))
14112 (map (copy-keymap calendar-mode-map))
14113 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
14114 (org-defkey map (kbd "RET") 'org-calendar-select)
14115 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
14116 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
14117 (org-defkey minibuffer-local-map [(meta shift left)]
14118 (lambda () (interactive)
14119 (org-eval-in-calendar '(calendar-backward-month 1))))
14120 (org-defkey minibuffer-local-map [(meta shift right)]
14121 (lambda () (interactive)
14122 (org-eval-in-calendar '(calendar-forward-month 1))))
14123 (org-defkey minibuffer-local-map [(meta shift up)]
14124 (lambda () (interactive)
14125 (org-eval-in-calendar '(calendar-backward-year 1))))
14126 (org-defkey minibuffer-local-map [(meta shift down)]
14127 (lambda () (interactive)
14128 (org-eval-in-calendar '(calendar-forward-year 1))))
14129 (org-defkey minibuffer-local-map [?\e (shift left)]
14130 (lambda () (interactive)
14131 (org-eval-in-calendar '(calendar-backward-month 1))))
14132 (org-defkey minibuffer-local-map [?\e (shift right)]
14133 (lambda () (interactive)
14134 (org-eval-in-calendar '(calendar-forward-month 1))))
14135 (org-defkey minibuffer-local-map [?\e (shift up)]
14136 (lambda () (interactive)
14137 (org-eval-in-calendar '(calendar-backward-year 1))))
14138 (org-defkey minibuffer-local-map [?\e (shift down)]
14139 (lambda () (interactive)
14140 (org-eval-in-calendar '(calendar-forward-year 1))))
14141 (org-defkey minibuffer-local-map [(shift up)]
14142 (lambda () (interactive)
14143 (org-eval-in-calendar '(calendar-backward-week 1))))
14144 (org-defkey minibuffer-local-map [(shift down)]
14145 (lambda () (interactive)
14146 (org-eval-in-calendar '(calendar-forward-week 1))))
14147 (org-defkey minibuffer-local-map [(shift left)]
14148 (lambda () (interactive)
14149 (org-eval-in-calendar '(calendar-backward-day 1))))
14150 (org-defkey minibuffer-local-map [(shift right)]
14151 (lambda () (interactive)
14152 (org-eval-in-calendar '(calendar-forward-day 1))))
14153 (org-defkey minibuffer-local-map ">"
14154 (lambda () (interactive)
14155 (org-eval-in-calendar '(scroll-calendar-left 1))))
14156 (org-defkey minibuffer-local-map "<"
14157 (lambda () (interactive)
14158 (org-eval-in-calendar '(scroll-calendar-right 1))))
14159 (org-defkey minibuffer-local-map "\C-v"
14160 (lambda () (interactive)
14161 (org-eval-in-calendar
14162 '(calendar-scroll-left-three-months 1))))
14163 (org-defkey minibuffer-local-map "\M-v"
14164 (lambda () (interactive)
14165 (org-eval-in-calendar
14166 '(calendar-scroll-right-three-months 1))))
14167 (run-hooks 'org-read-date-minibuffer-setup-hook)
14170 (use-local-map map)
14171 (add-hook 'post-command-hook 'org-read-date-display)
14172 (setq org-ans0 (read-string prompt default-input
14173 'org-read-date-history nil))
14174 ;; org-ans0: from prompt
14175 ;; org-ans1: from mouse click
14176 ;; org-ans2: from calendar motion
14177 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
14178 (remove-hook 'post-command-hook 'org-read-date-display)
14179 (use-local-map old-map)
14180 (when org-read-date-overlay
14181 (delete-overlay org-read-date-overlay)
14182 (setq org-read-date-overlay nil)))))))
14184 (t ; Naked prompt only
14186 (setq ans (read-string prompt default-input
14187 'org-read-date-history timestr))
14188 (when org-read-date-overlay
14189 (delete-overlay org-read-date-overlay)
14190 (setq org-read-date-overlay nil)))))
14192 (setq final (org-read-date-analyze ans def defdecode))
14193 (setq org-read-date-final-answer ans)
14196 (apply 'encode-time final)
14197 (if (and (boundp 'org-time-was-given) org-time-was-given)
14198 (format "%04d-%02d-%02d %02d:%02d"
14199 (nth 5 final) (nth 4 final) (nth 3 final)
14200 (nth 2 final) (nth 1 final))
14201 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
14206 (defvar org-read-date-analyze-futurep nil)
14207 (defun org-read-date-display ()
14208 "Display the current date prompt interpretation in the minibuffer."
14209 (when org-read-date-display-live
14210 (when org-read-date-overlay
14211 (delete-overlay org-read-date-overlay))
14214 (while (not (equal (buffer-substring
14215 (max (point-min) (- (point) 4)) (point))
14219 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
14220 " " (or org-ans1 org-ans2)))
14221 (org-end-time-was-given nil)
14222 (f (org-read-date-analyze ans def defdecode))
14224 org-time-stamp-custom-formats
14225 org-time-stamp-formats))
14226 (fmt (if (or with-time
14227 (and (boundp 'org-time-was-given) org-time-was-given))
14230 (txt (concat "=> " (format-time-string fmt (apply 'encode-time f)))))
14231 (when (and org-end-time-was-given
14232 (string-match org-plain-time-of-day-regexp txt))
14233 (setq txt (concat (substring txt 0 (match-end 0)) "-"
14234 org-end-time-was-given
14235 (substring txt (match-end 0)))))
14236 (when org-read-date-analyze-futurep
14237 (setq txt (concat txt " (=>F)")))
14238 (setq org-read-date-overlay
14239 (make-overlay (1- (point-at-eol)) (point-at-eol)))
14240 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
14242 (defun org-read-date-analyze (ans def defdecode)
14243 "Analyze the combined answer of the date prompt."
14244 ;; FIXME: cleanup and comment
14245 (let ((nowdecode (decode-time (current-time)))
14246 delta deltan deltaw deltadef year month day
14247 hour minute second wday pm h2 m2 tl wday1
14248 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
14249 (setq org-read-date-analyze-futurep nil)
14250 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
14253 (when (setq delta (org-read-date-get-relative ans (current-time) def))
14254 (setq ans (replace-match "" t t ans)
14256 deltaw (nth 1 delta)
14257 deltadef (nth 2 delta)))
14259 ;; Check if there is an iso week date in there
14260 ;; If yes, store the info and postpone interpreting it until the rest
14261 ;; of the parsing is done
14262 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
14263 (setq iso-year (if (match-end 1)
14264 (org-small-year-to-year
14265 (string-to-number (match-string 1 ans))))
14266 iso-weekday (if (match-end 3)
14267 (string-to-number (match-string 3 ans)))
14268 iso-week (string-to-number (match-string 2 ans)))
14269 (setq ans (replace-match "" t t ans)))
14271 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
14272 (when (string-match
14273 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
14274 (setq year (if (match-end 2)
14275 (string-to-number (match-string 2 ans))
14276 (progn (setq kill-year t)
14277 (string-to-number (format-time-string "%Y"))))
14278 month (string-to-number (match-string 3 ans))
14279 day (string-to-number (match-string 4 ans)))
14280 (if (< year 100) (setq year (+ 2000 year)))
14281 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14283 ;; Help matching american dates, like 5/30 or 5/30/7
14284 (when (string-match
14285 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
14286 (setq year (if (match-end 4)
14287 (string-to-number (match-string 4 ans))
14288 (progn (setq kill-year t)
14289 (string-to-number (format-time-string "%Y"))))
14290 month (string-to-number (match-string 1 ans))
14291 day (string-to-number (match-string 2 ans)))
14292 (if (< year 100) (setq year (+ 2000 year)))
14293 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
14295 ;; Help matching am/pm times, because `parse-time-string' does not do that.
14296 ;; If there is a time with am/pm, and *no* time without it, we convert
14297 ;; so that matching will be successful.
14298 (loop for i from 1 to 2 do ; twice, for end time as well
14299 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
14300 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
14301 (setq hour (string-to-number (match-string 1 ans))
14302 minute (if (match-end 3)
14303 (string-to-number (match-string 3 ans))
14306 (string-to-char (downcase (match-string 4 ans)))))
14307 (if (and (= hour 12) (not pm))
14309 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
14310 (setq ans (replace-match (format "%02d:%02d" hour minute)
14313 ;; Check if a time range is given as a duration
14314 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
14315 (setq hour (string-to-number (match-string 1 ans))
14316 h2 (+ hour (string-to-number (match-string 3 ans)))
14317 minute (string-to-number (match-string 2 ans))
14318 m2 (+ minute (if (match-end 5) (string-to-number
14319 (match-string 5 ans))0)))
14320 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
14321 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
14324 ;; Check if there is a time range
14325 (when (boundp 'org-end-time-was-given)
14326 (setq org-time-was-given nil)
14327 (when (and (string-match org-plain-time-of-day-regexp ans)
14329 (setq org-end-time-was-given (match-string 8 ans))
14330 (setq ans (concat (substring ans 0 (match-beginning 7))
14331 (substring ans (match-end 7))))))
14333 (setq tl (parse-time-string ans)
14334 day (or (nth 3 tl) (nth 3 defdecode))
14335 month (or (nth 4 tl)
14336 (if (and org-read-date-prefer-future
14337 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
14338 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
14339 (nth 4 defdecode)))
14340 year (or (and (not kill-year) (nth 5 tl))
14341 (if (and org-read-date-prefer-future
14342 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
14343 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
14344 (nth 5 defdecode)))
14345 hour (or (nth 2 tl) (nth 2 defdecode))
14346 minute (or (nth 1 tl) (nth 1 defdecode))
14347 second (or (nth 0 tl) 0)
14350 (when (and (eq org-read-date-prefer-future 'time)
14351 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
14352 (equal day (nth 3 nowdecode))
14353 (equal month (nth 4 nowdecode))
14354 (equal year (nth 5 nowdecode))
14356 (or (< (nth 2 tl) (nth 2 nowdecode))
14357 (and (= (nth 2 tl) (nth 2 nowdecode))
14359 (< (nth 1 tl) (nth 1 nowdecode)))))
14363 ;; Special date definitions below
14366 ;; There was an iso week
14369 (setq year (or iso-year year)
14370 day (or iso-weekday wday 1)
14371 wday nil ; to make sure that the trigger below does not match
14372 iso-date (calendar-gregorian-from-absolute
14373 (calendar-absolute-from-iso
14374 (list iso-week day year))))
14375 ; FIXME: Should we also push ISO weeks into the future?
14376 ; (when (and org-read-date-prefer-future
14378 ; (< (calendar-absolute-from-gregorian iso-date)
14379 ; (time-to-days (current-time))))
14380 ; (setq year (1+ year)
14381 ; iso-date (calendar-gregorian-from-absolute
14382 ; (calendar-absolute-from-iso
14383 ; (list iso-week day year)))))
14384 (setq month (car iso-date)
14385 year (nth 2 iso-date)
14386 day (nth 1 iso-date)))
14390 (let ((now (decode-time (current-time))))
14391 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
14392 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
14393 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
14394 ((equal deltaw "m") (setq month (+ month deltan)))
14395 ((equal deltaw "y") (setq year (+ year deltan)))))
14396 ((and wday (not (nth 3 tl)))
14398 ;; Weekday was given, but no day, so pick that day in the week
14399 ;; on or after the derived date.
14400 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
14401 (unless (equal wday wday1)
14402 (setq day (+ day (% (- wday wday1 -7) 7))))))
14403 (if (and (boundp 'org-time-was-given)
14405 (setq org-time-was-given t))
14406 (if (< year 100) (setq year (+ 2000 year)))
14407 (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
14408 (setq org-read-date-analyze-futurep futurep)
14409 (list second minute hour day month year)))
14411 (defvar parse-time-weekdays)
14413 (defun org-read-date-get-relative (s today default)
14414 "Check string S for special relative date string.
14415 TODAY and DEFAULT are internal times, for today and for a default.
14416 Return shift list (N what def-flag)
14417 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
14418 N is the number of WHATs to shift.
14419 DEF-FLAG is t when a double ++ or -- indicates shift relative to
14420 the DEFAULT date rather than TODAY."
14424 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
14426 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
14427 "\\([ \t]\\|$\\)") s)
14428 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
14429 (let* ((dir (if (> (match-end 1) (match-beginning 1))
14430 (string-to-char (substring (match-string 1 s) -1))
14432 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
14433 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
14434 (what (if (match-end 3) (match-string 3 s) "d"))
14435 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
14436 (date (if rel default today))
14437 (wday (nth 6 (decode-time date)))
14441 (setq delta (mod (+ 7 (- wday1 wday)) 7))
14442 (if (= dir ?-) (setq delta (- delta 7)))
14443 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
14444 (list delta "d" rel))
14445 (list (* n (if (= dir ?-) -1 1)) what rel)))))
14447 (defun org-order-calendar-date-args (arg1 arg2 arg3)
14448 "Turn a user-specified date into the internal representation.
14449 The internal representation needed by the calendar is (month day year).
14450 This is a wrapper to handle the brain-dead convention in calendar that
14451 user function argument order change dependent on argument order."
14452 (if (boundp 'calendar-date-style)
14454 ((eq calendar-date-style 'american)
14455 (list arg1 arg2 arg3))
14456 ((eq calendar-date-style 'european)
14457 (list arg2 arg1 arg3))
14458 ((eq calendar-date-style 'iso)
14459 (list arg2 arg3 arg1)))
14460 (if (org-bound-and-true-p european-calendar-style)
14461 (list arg2 arg1 arg3)
14462 (list arg1 arg2 arg3))))
14464 (defun org-eval-in-calendar (form &optional keepdate)
14465 "Eval FORM in the calendar window and return to current window.
14466 Also, store the cursor date in variable org-ans2."
14467 (let ((sf (selected-frame))
14468 (sw (selected-window)))
14469 (select-window (get-buffer-window "*Calendar*" t))
14471 (when (and (not keepdate) (calendar-cursor-to-date))
14472 (let* ((date (calendar-cursor-to-date))
14473 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14474 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
14475 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
14477 (org-select-frame-set-input-focus sf)))
14479 (defun org-calendar-select ()
14480 "Return to `org-read-date' with the date currently selected.
14481 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14483 (when (calendar-cursor-to-date)
14484 (let* ((date (calendar-cursor-to-date))
14485 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14486 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14487 (if (active-minibuffer-window) (exit-minibuffer))))
14489 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
14490 "Insert a date stamp for the date given by the internal TIME.
14491 WITH-HM means use the stamp format that includes the time of the day.
14492 INACTIVE means use square brackets instead of angular ones, so that the
14493 stamp will not contribute to the agenda.
14494 PRE and POST are optional strings to be inserted before and after the
14496 The command returns the inserted time stamp."
14497 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
14499 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
14500 (insert-before-markers (or pre ""))
14501 (insert-before-markers (setq stamp (format-time-string fmt time)))
14502 (when (listp extra)
14503 (setq extra (car extra))
14504 (if (and (stringp extra)
14505 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
14506 (setq extra (format "-%02d:%02d"
14507 (string-to-number (match-string 1 extra))
14508 (string-to-number (match-string 2 extra))))
14512 (insert-before-markers extra)
14514 (insert-before-markers (or post ""))
14515 (setq org-last-inserted-timestamp stamp)))
14517 (defun org-toggle-time-stamp-overlays ()
14518 "Toggle the use of custom time stamp formats."
14520 (setq org-display-custom-times (not org-display-custom-times))
14521 (unless org-display-custom-times
14522 (let ((p (point-min)) (bmp (buffer-modified-p)))
14523 (while (setq p (next-single-property-change p 'display))
14524 (if (and (get-text-property p 'display)
14525 (eq (get-text-property p 'face) 'org-date))
14526 (remove-text-properties
14527 p (setq p (next-single-property-change p 'display))
14529 (set-buffer-modified-p bmp)))
14530 (if (featurep 'xemacs)
14531 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
14532 (org-restart-font-lock)
14533 (setq org-table-may-need-update t)
14534 (if org-display-custom-times
14535 (message "Time stamps are overlayed with custom format")
14536 (message "Time stamp overlays removed")))
14538 (defun org-display-custom-time (beg end)
14539 "Overlay modified time stamp format over timestamp between BEG and END."
14540 (let* ((ts (buffer-substring beg end))
14541 t1 w1 with-hm tf time str w2 (off 0))
14543 (setq t1 (org-parse-time-string ts t))
14544 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
14545 (setq off (- (match-end 0) (match-beginning 0)))))
14546 (setq end (- end off))
14547 (setq w1 (- end beg)
14548 with-hm (and (nth 1 t1) (nth 2 t1))
14549 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
14550 time (org-fix-decoded-time t1)
14552 (format-time-string
14553 (substring tf 1 -1) (apply 'encode-time time))
14554 nil 'mouse-face 'highlight)
14556 (if (not (= w2 w1))
14557 (add-text-properties (1+ beg) (+ 2 beg)
14558 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
14559 (if (featurep 'xemacs)
14561 (put-text-property beg end 'invisible t)
14562 (put-text-property beg end 'end-glyph (make-glyph str)))
14563 (put-text-property beg end 'display str))))
14565 (defun org-translate-time (string)
14566 "Translate all timestamps in STRING to custom format.
14567 But do this only if the variable `org-display-custom-times' is set."
14568 (when org-display-custom-times
14571 (re org-ts-regexp-both)
14572 t1 with-hm inactive tf time str beg end)
14573 (while (setq start (string-match re string start))
14574 (setq beg (match-beginning 0)
14576 t1 (save-match-data
14577 (org-parse-time-string (substring string beg end) t))
14578 with-hm (and (nth 1 t1) (nth 2 t1))
14579 inactive (equal (substring string beg (1+ beg)) "[")
14580 tf (funcall (if with-hm 'cdr 'car)
14581 org-time-stamp-custom-formats)
14582 time (org-fix-decoded-time t1)
14583 str (format-time-string
14585 (if inactive "[" "<") (substring tf 1 -1)
14586 (if inactive "]" ">"))
14587 (apply 'encode-time time))
14588 string (replace-match str t t string)
14589 start (+ start (length str)))))))
14592 (defun org-fix-decoded-time (time)
14593 "Set 0 instead of nil for the first 6 elements of time.
14594 Don't touch the rest."
14596 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
14598 (defun org-days-to-time (timestamp-string)
14599 "Difference between TIMESTAMP-STRING and now in days."
14600 (- (time-to-days (org-time-string-to-time timestamp-string))
14601 (time-to-days (current-time))))
14603 (defun org-deadline-close (timestamp-string &optional ndays)
14604 "Is the time in TIMESTAMP-STRING close to the current date?"
14605 (setq ndays (or ndays (org-get-wdays timestamp-string)))
14606 (and (< (org-days-to-time timestamp-string) ndays)
14607 (not (org-entry-is-done-p))))
14609 (defun org-get-wdays (ts)
14610 "Get the deadline lead time appropriate for timestring TS."
14612 ((<= org-deadline-warning-days 0)
14613 ;; 0 or negative, enforce this value no matter what
14614 (- org-deadline-warning-days))
14615 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
14616 ;; lead time is specified.
14617 (floor (* (string-to-number (match-string 1 ts))
14618 (cdr (assoc (match-string 2 ts)
14619 '(("d" . 1) ("w" . 7)
14620 ("m" . 30.4) ("y" . 365.25)))))))
14621 ;; go for the default.
14622 (t org-deadline-warning-days)))
14624 (defun org-calendar-select-mouse (ev)
14625 "Return to `org-read-date' with the date currently selected.
14626 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
14628 (mouse-set-point ev)
14629 (when (calendar-cursor-to-date)
14630 (let* ((date (calendar-cursor-to-date))
14631 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
14632 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
14633 (if (active-minibuffer-window) (exit-minibuffer))))
14635 (defun org-check-deadlines (ndays)
14636 "Check if there are any deadlines due or past due.
14637 A deadline is considered due if it happens within `org-deadline-warning-days'
14638 days from today's date. If the deadline appears in an entry marked DONE,
14639 it is not shown. The prefix arg NDAYS can be used to test that many
14640 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
14642 (let* ((org-warn-days
14644 ((equal ndays '(4)) 100000)
14645 (ndays (prefix-numeric-value ndays))
14646 (t (abs org-deadline-warning-days))))
14647 (case-fold-search nil)
14648 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
14650 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
14652 (message "%d deadlines past-due or due within %d days"
14653 (org-occur regexp nil callback)
14656 (defun org-check-before-date (date)
14657 "Check if there are deadlines or scheduled entries before DATE."
14658 (interactive (list (org-read-date)))
14659 (let ((case-fold-search nil)
14660 (regexp (concat "\\<\\(" org-deadline-string
14661 "\\|" org-scheduled-string
14662 "\\) *<\\([^>]+\\)>"))
14664 (lambda () (time-less-p
14665 (org-time-string-to-time (match-string 2))
14666 (org-time-string-to-time date)))))
14667 (message "%d entries before %s"
14668 (org-occur regexp nil callback) date)))
14670 (defun org-check-after-date (date)
14671 "Check if there are deadlines or scheduled entries after DATE."
14672 (interactive (list (org-read-date)))
14673 (let ((case-fold-search nil)
14674 (regexp (concat "\\<\\(" org-deadline-string
14675 "\\|" org-scheduled-string
14676 "\\) *<\\([^>]+\\)>"))
14680 (org-time-string-to-time (match-string 2))
14681 (org-time-string-to-time date))))))
14682 (message "%d entries after %s"
14683 (org-occur regexp nil callback) date)))
14685 (defun org-evaluate-time-range (&optional to-buffer)
14686 "Evaluate a time range by computing the difference between start and end.
14687 Normally the result is just printed in the echo area, but with prefix arg
14688 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
14689 If the time range is actually in a table, the result is inserted into the
14691 For time difference computation, a year is assumed to be exactly 365
14692 days in order to avoid rounding problems."
14695 (org-clock-update-time-maybe)
14697 (unless (org-at-date-range-p t)
14698 (goto-char (point-at-bol))
14699 (re-search-forward org-tr-regexp-both (point-at-eol) t))
14700 (if (not (org-at-date-range-p t))
14701 (error "Not at a time-stamp range, and none found in current line")))
14702 (let* ((ts1 (match-string 1))
14703 (ts2 (match-string 2))
14704 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
14705 (match-end (match-end 0))
14706 (time1 (org-time-string-to-time ts1))
14707 (time2 (org-time-string-to-time ts2))
14708 (t1 (org-float-time time1))
14709 (t2 (org-float-time time2))
14710 (diff (abs (- t2 t1)))
14711 (negative (< (- t2 t1) 0))
14712 ;; (ys (floor (* 365 24 60 60)))
14715 (fy "%dy %dd %02d:%02d")
14717 (fd "%dd %02d:%02d")
14722 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14724 d (floor (/ diff ds)) diff (mod diff ds)
14725 h (floor (/ diff hs)) diff (mod diff hs)
14726 m (floor (/ diff 60)))
14727 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
14729 d (floor (+ (/ diff ds) 0.5))
14731 (if (not to-buffer)
14732 (message "%s" (org-make-tdiff-string y d h m))
14733 (if (org-at-table-p)
14735 (goto-char match-end)
14737 (and (looking-at " *|") (goto-char (match-end 0))))
14738 (goto-char match-end))
14740 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
14741 (replace-match ""))
14742 (if negative (insert " -"))
14743 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
14744 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
14745 (insert " " (format fh h m))))
14746 (if align (org-table-align))
14747 (message "Time difference inserted")))))
14749 (defun org-make-tdiff-string (y d h m)
14752 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
14754 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
14756 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
14758 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
14760 (apply 'format fmt (nreverse l))))
14762 (defun org-time-string-to-time (s)
14763 (apply 'encode-time (org-parse-time-string s)))
14764 (defun org-time-string-to-seconds (s)
14765 (org-float-time (org-time-string-to-time s)))
14767 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
14768 "Convert a time stamp to an absolute day number.
14769 If there is a specifier for a cyclic time stamp, get the closest date to
14771 PREFER and SHOW-ALL are passed through to `org-closest-date'.
14772 the variable date is bound by the calendar when this is called."
14774 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
14775 (if (org-diary-sexp-entry (match-string 1 s) "" date)
14778 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
14779 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
14780 (time-to-days (current-time))) (match-string 0 s)
14782 (t (time-to-days (apply 'encode-time (org-parse-time-string s))))))
14784 (defun org-days-to-iso-week (days)
14785 "Return the iso week number."
14787 (car (calendar-iso-from-absolute days)))
14789 (defun org-small-year-to-year (year)
14790 "Convert 2-digit years into 4-digit years.
14791 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
14792 The year 2000 cannot be abbreviated. Any year larger than 99
14793 is returned unchanged."
14795 (setq year (+ 2000 year))
14797 (setq year (+ 1900 year))))
14800 (defun org-time-from-absolute (d)
14801 "Return the time corresponding to date D.
14802 D may be an absolute day number, or a calendar-type list (month day year)."
14803 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
14804 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
14806 (defun org-calendar-holiday ()
14807 "List of holidays, for Diary display in Org-mode."
14808 (require 'holidays)
14810 (if (fboundp 'calendar-check-holidays)
14811 'calendar-check-holidays 'check-calendar-holidays) date)))
14812 (if hl (mapconcat 'identity hl "; "))))
14814 (defun org-diary-sexp-entry (sexp entry date)
14815 "Process a SEXP diary ENTRY for DATE."
14816 (require 'diary-lib)
14817 (let ((result (if calendar-debug-sexp
14818 (let ((stack-trace-on-error t))
14819 (eval (car (read-from-string sexp))))
14820 (condition-case nil
14821 (eval (car (read-from-string sexp)))
14824 (message "Bad sexp at line %d in %s: %s"
14826 (buffer-file-name) sexp)
14828 (cond ((stringp result) result)
14829 ((and (consp result)
14830 (stringp (cdr result))) (cdr result))
14834 (defun org-diary-to-ical-string (frombuf)
14835 "Get iCalendar entries from diary entries in buffer FROMBUF.
14836 This uses the icalendar.el library."
14837 (let* ((tmpdir (if (featurep 'xemacs)
14839 temporary-file-directory))
14840 (tmpfile (make-temp-name
14841 (expand-file-name "orgics" tmpdir)))
14843 (with-current-buffer frombuf
14844 (icalendar-export-region (point-min) (point-max) tmpfile)
14845 (setq buf (find-buffer-visiting tmpfile))
14847 (goto-char (point-min))
14848 (if (re-search-forward "^BEGIN:VEVENT" nil t)
14849 (setq b (match-beginning 0)))
14850 (goto-char (point-max))
14851 (if (re-search-backward "^END:VEVENT" nil t)
14852 (setq e (match-end 0)))
14853 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
14855 (delete-file tmpfile)
14858 (defun org-closest-date (start current change prefer show-all)
14859 "Find the date closest to CURRENT that is consistent with START and CHANGE.
14860 When PREFER is `past' return a date that is either CURRENT or past.
14861 When PREFER is `future', return a date that is either CURRENT or future.
14862 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
14863 ;; Make the proper lists from the dates
14865 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
14866 dn dw sday cday n1 n2 n0
14867 d m y y1 y2 date1 date2 nmonths nm ny m2)
14869 (setq start (org-date-to-gregorian start)
14870 current (org-date-to-gregorian
14873 (time-to-days (current-time))))
14874 sday (calendar-absolute-from-gregorian start)
14875 cday (calendar-absolute-from-gregorian current))
14877 (if (<= cday sday) (throw 'exit sday))
14879 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
14880 (setq dn (string-to-number (match-string 1 change))
14881 dw (cdr (assoc (match-string 2 change) a1)))
14882 (error "Invalid change specifier: %s" change))
14883 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
14886 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
14889 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
14890 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
14891 (setq date1 (list m d y1)
14892 n1 (calendar-absolute-from-gregorian date1)
14893 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
14894 n2 (calendar-absolute-from-gregorian date2)))
14896 ;; approx number of month between the two dates
14897 (setq nmonths (floor (/ (- cday sday) 30.436875)))
14898 ;; How often does dn fit in there?
14899 (setq d (nth 1 start) m (car start) y (nth 2 start)
14900 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
14902 ny (floor (/ m 12))
14905 (while (> m 12) (setq m (- m 12) y (1+ y)))
14906 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
14907 (setq m2 (+ m dn) y2 y)
14908 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14909 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
14910 (while (<= n2 cday)
14911 (setq n1 n2 m m2 y y2)
14912 (setq m2 (+ m dn) y2 y)
14913 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
14914 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
14915 ;; Make sure n1 is the earlier date
14916 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
14919 ((eq prefer 'past) (if (= cday n2) n2 n1))
14920 ((eq prefer 'future) (if (= cday n1) n1 n2))
14921 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
14923 ((eq prefer 'past) (if (= cday n2) n2 n1))
14924 ((eq prefer 'future) (if (= cday n1) n1 n2))
14925 (t (if (= cday n1) n1 n2)))))))
14927 (defun org-date-to-gregorian (date)
14928 "Turn any specification of DATE into a Gregorian date for the calendar."
14929 (cond ((integerp date) (calendar-gregorian-from-absolute date))
14930 ((and (listp date) (= (length date) 3)) date)
14932 (setq date (org-parse-time-string date))
14933 (list (nth 4 date) (nth 3 date) (nth 5 date)))
14935 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
14937 (defun org-parse-time-string (s &optional nodefault)
14938 "Parse the standard Org-mode time string.
14939 This should be a lot faster than the normal `parse-time-string'.
14940 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
14941 hour and minute fields will be nil if not given."
14942 (if (string-match org-ts-regexp0 s)
14944 (if (or (match-beginning 8) (not nodefault))
14945 (string-to-number (or (match-string 8 s) "0")))
14946 (if (or (match-beginning 7) (not nodefault))
14947 (string-to-number (or (match-string 7 s) "0")))
14948 (string-to-number (match-string 4 s))
14949 (string-to-number (match-string 3 s))
14950 (string-to-number (match-string 2 s))
14952 (error "Not a standard Org-mode time string: %s" s)))
14954 (defun org-timestamp-up (&optional arg)
14955 "Increase the date item at the cursor by one.
14956 If the cursor is on the year, change the year. If it is on the month or
14957 the day, change that.
14958 With prefix ARG, change by that many units."
14960 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
14962 (defun org-timestamp-down (&optional arg)
14963 "Decrease the date item at the cursor by one.
14964 If the cursor is on the year, change the year. If it is on the month or
14965 the day, change that.
14966 With prefix ARG, change by that many units."
14968 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
14970 (defun org-timestamp-up-day (&optional arg)
14971 "Increase the date in the time stamp by one day.
14972 With prefix ARG, change that many days."
14974 (if (and (not (org-at-timestamp-p t))
14975 (org-on-heading-p))
14977 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
14979 (defun org-timestamp-down-day (&optional arg)
14980 "Decrease the date in the time stamp by one day.
14981 With prefix ARG, change that many days."
14983 (if (and (not (org-at-timestamp-p t))
14984 (org-on-heading-p))
14986 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
14988 (defun org-at-timestamp-p (&optional inactive-ok)
14989 "Determine if the cursor is in or at a timestamp."
14991 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
14993 (ans (or (looking-at tsr)
14995 (skip-chars-backward "^[<\n\r\t")
14996 (if (> (point) (point-min)) (backward-char 1))
14997 (and (looking-at tsr)
14998 (> (- (match-end 0) pos) -1))))))
15000 (boundp 'org-ts-what)
15003 ((= pos (match-beginning 0)) 'bracket)
15004 ((= pos (1- (match-end 0))) 'bracket)
15005 ((org-pos-in-match-range pos 2) 'year)
15006 ((org-pos-in-match-range pos 3) 'month)
15007 ((org-pos-in-match-range pos 7) 'hour)
15008 ((org-pos-in-match-range pos 8) 'minute)
15009 ((or (org-pos-in-match-range pos 4)
15010 (org-pos-in-match-range pos 5)) 'day)
15011 ((and (> pos (or (match-end 8) (match-end 5)))
15012 (< pos (match-end 0)))
15013 (- pos (or (match-end 8) (match-end 5))))
15017 (defun org-toggle-timestamp-type ()
15018 "Toggle the type (<active> or [inactive]) of a time stamp."
15020 (when (org-at-timestamp-p t)
15021 (let ((beg (match-beginning 0)) (end (match-end 0))
15022 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
15025 (while (re-search-forward "[][<>]" end t)
15026 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
15028 (message "Timestamp is now %sactive"
15029 (if (equal (char-after beg) ?<) "" "in")))))
15031 (defun org-timestamp-change (n &optional what updown)
15032 "Change the date in the time stamp at point.
15033 The date will be changed by N times WHAT. WHAT can be `day', `month',
15034 `year', `minute', `second'. If WHAT is not given, the cursor position
15035 in the timestamp determines what will be changed."
15036 (let ((pos (point))
15038 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
15042 (if (not (org-at-timestamp-p t))
15043 (error "Not at a timestamp"))
15044 (if (and (not what) (eq org-ts-what 'bracket))
15045 (org-toggle-timestamp-type)
15046 (if (and (not what) (not (eq org-ts-what 'day))
15047 org-display-custom-times
15048 (get-text-property (point) 'display)
15049 (not (get-text-property (1- (point)) 'display)))
15050 (setq org-ts-what 'day))
15051 (setq org-ts-what (or what org-ts-what)
15052 inactive (= (char-after (match-beginning 0)) ?\[)
15053 ts (match-string 0))
15056 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
15058 (setq extra (match-string 1 ts)))
15059 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
15061 (setq time0 (org-parse-time-string ts))
15063 (eq org-ts-what 'minute)
15064 (not current-prefix-arg))
15065 ;; This looks like s-up and s-down. Change by one rounding step.
15066 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
15067 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
15068 (setcar (cdr time0) (+ (nth 1 time0)
15069 (if (> n 0) (- rem) (- dm rem))))))
15071 (encode-time (or (car time0) 0)
15072 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
15073 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
15074 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
15075 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
15076 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
15078 (when (and (member org-ts-what '(hour minute))
15080 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
15081 (setq extra (org-modify-ts-extra
15083 (if (eq org-ts-what 'hour) 2 5)
15085 (when (integerp org-ts-what)
15086 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
15087 (if (eq what 'calendar)
15088 (let ((cal-date (org-get-date-from-calendar)))
15089 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
15090 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
15091 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
15092 (setcar time0 (or (car time0) 0))
15093 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
15094 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
15095 (setq time (apply 'encode-time time0))))
15096 (setq org-last-changed-timestamp
15097 (org-insert-time-stamp time with-hm inactive nil nil extra))
15098 (org-clock-update-time-maybe)
15100 ;; Try to recenter the calendar window, if any
15101 (if (and org-calendar-follow-timestamp-change
15102 (get-buffer-window "*Calendar*" t)
15103 (memq org-ts-what '(day month year)))
15104 (org-recenter-calendar (time-to-days time))))))
15106 (defun org-modify-ts-extra (s pos n dm)
15107 "Change the different parts of the lead-time and repeat fields in timestamp."
15108 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
15110 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
15112 ((or (org-pos-in-match-range pos 2)
15113 (org-pos-in-match-range pos 3))
15114 (setq m (string-to-number (match-string 3 s))
15115 h (string-to-number (match-string 2 s)))
15116 (if (org-pos-in-match-range pos 2)
15118 (setq n (* dm (org-no-warnings (signum n))))
15119 (when (not (= 0 (setq rem (% m dm))))
15120 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
15122 (if (< m 0) (setq m (+ m 60) h (1- h)))
15123 (if (> m 59) (setq m (- m 60) h (1+ h)))
15124 (setq h (min 24 (max 0 h)))
15125 (setq ng 1 new (format "-%02d:%02d" h m)))
15126 ((org-pos-in-match-range pos 6)
15127 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
15128 ((org-pos-in-match-range pos 5)
15129 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
15131 ((org-pos-in-match-range pos 9)
15132 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
15133 ((org-pos-in-match-range pos 8)
15134 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
15138 (substring s 0 (match-beginning ng))
15140 (substring s (match-end ng))))))
15143 (defun org-recenter-calendar (date)
15144 "If the calendar is visible, recenter it to DATE."
15145 (let* ((win (selected-window))
15146 (cwin (get-buffer-window "*Calendar*" t))
15147 (calendar-move-hook nil))
15149 (select-window cwin)
15150 (calendar-goto-date (if (listp date) date
15151 (calendar-gregorian-from-absolute date)))
15152 (select-window win))))
15154 (defun org-goto-calendar (&optional arg)
15155 "Go to the Emacs calendar at the current date.
15156 If there is a time stamp in the current line, go to that date.
15157 A prefix ARG can be used to force the current date."
15159 (let ((tsr org-ts-regexp) diff
15160 (calendar-move-hook nil)
15161 (calendar-view-holidays-initially-flag nil)
15162 (calendar-view-diary-initially-flag nil))
15163 (if (or (org-at-timestamp-p)
15165 (beginning-of-line 1)
15166 (looking-at (concat ".*" tsr))))
15167 (let ((d1 (time-to-days (current-time)))
15169 (org-time-string-to-time (match-string 1)))))
15170 (setq diff (- d2 d1))))
15172 (calendar-goto-today)
15173 (if (and diff (not arg)) (calendar-forward-day diff))))
15175 (defun org-get-date-from-calendar ()
15176 "Return a list (month day year) of date at point in calendar."
15177 (with-current-buffer "*Calendar*"
15179 (calendar-cursor-to-date))))
15181 (defun org-date-from-calendar ()
15182 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
15183 If there is already a time stamp at the cursor position, update it."
15185 (if (org-at-timestamp-p t)
15186 (org-timestamp-change 0 'calendar)
15187 (let ((cal-date (org-get-date-from-calendar)))
15188 (org-insert-time-stamp
15189 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
15191 (defun org-minutes-to-hh:mm-string (m)
15192 "Compute H:MM from a number of minutes."
15193 (let ((h (/ m 60)))
15194 (setq m (- m (* 60 h)))
15195 (format org-time-clocksum-format h m)))
15197 (defun org-hh:mm-string-to-minutes (s)
15198 "Convert a string H:MM to a number of minutes.
15199 If the string is just a number, interpret it as minutes.
15200 In fact, the first hh:mm or number in the string will be taken,
15201 there can be extra stuff in the string.
15202 If no number is found, the return value is 0."
15204 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
15205 (+ (* (string-to-number (match-string 1 s)) 60)
15206 (string-to-number (match-string 2 s))))
15207 ((string-match "\\([0-9]+\\)" s)
15208 (string-to-number (match-string 1 s)))
15213 (defun org-save-all-org-buffers ()
15214 "Save all Org-mode buffers without user confirmation."
15216 (message "Saving all Org-mode buffers...")
15217 (save-some-buffers t 'org-mode-p)
15218 (when (featurep 'org-id) (org-id-locations-save))
15219 (message "Saving all Org-mode buffers... done"))
15221 (defun org-revert-all-org-buffers ()
15222 "Revert all Org-mode buffers.
15223 Prompt for confirmation when there are unsaved changes.
15224 Be sure you know what you are doing before letting this function
15225 overwrite your changes.
15227 This function is useful in a setup where one tracks org files
15228 with a version control system, to revert on one machine after pulling
15229 changes from another. I believe the procedure must be like this:
15231 1. M-x org-save-all-org-buffers
15232 2. Pull changes from the other machine, resolve conflicts
15233 3. M-x org-revert-all-org-buffers"
15235 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
15238 (save-window-excursion
15241 (when (and (with-current-buffer b (org-mode-p))
15242 (with-current-buffer b buffer-file-name))
15243 (switch-to-buffer b)
15244 (revert-buffer t 'no-confirm)))
15246 (when (and (featurep 'org-id) org-id-track-globally)
15247 (org-id-locations-load)))))
15252 (defun org-switchb (&optional arg)
15253 "Switch between Org buffers.
15254 With a prefix argument, restrict available to files.
15255 With two prefix arguments, restrict available buffers to agenda files.
15257 Defaults to `iswitchb' for buffer name completion.
15258 Set `org-completion-use-ido' to make it use ido instead."
15260 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
15261 ((equal arg '(16)) (org-buffer-list 'agenda))
15262 (t (org-buffer-list))))
15263 (org-completion-use-iswitchb org-completion-use-iswitchb)
15264 (org-completion-use-ido org-completion-use-ido))
15265 (unless (or org-completion-use-ido org-completion-use-iswitchb)
15266 (setq org-completion-use-iswitchb t))
15268 (org-icompleting-read "Org buffer: "
15269 (mapcar 'list (mapcar 'buffer-name blist))
15272 ;;; Define some older names previously used for this functionality
15274 (defalias 'org-ido-switchb 'org-switchb)
15276 (defalias 'org-iswitchb 'org-switchb)
15278 (defun org-buffer-list (&optional predicate exclude-tmp)
15279 "Return a list of Org buffers.
15280 PREDICATE can be `export', `files' or `agenda'.
15282 export restrict the list to Export buffers.
15283 files restrict the list to buffers visiting Org files.
15284 agenda restrict the list to buffers visiting agenda files.
15286 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
15288 (agenda-files (and (eq predicate 'agenda)
15289 (mapcar 'file-truename (org-agenda-files t))))
15292 ((eq predicate 'files)
15293 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
15294 ((eq predicate 'export)
15295 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
15296 ((eq predicate 'agenda)
15298 (with-current-buffer b
15299 (and (eq major-mode 'org-mode)
15300 (setq bfn (buffer-file-name b))
15301 (member (file-truename bfn) agenda-files)))))
15302 (t (lambda (b) (with-current-buffer b
15303 (or (eq major-mode 'org-mode)
15304 (string-match "\*Org .*Export"
15305 (buffer-name b)))))))))
15309 (if (and (funcall filter b)
15310 (or (not exclude-tmp)
15311 (not (string-match "tmp" (buffer-name b)))))
15316 (defun org-agenda-files (&optional unrestricted archives)
15317 "Get the list of agenda files.
15318 Optional UNRESTRICTED means return the full list even if a restriction
15319 is currently in place.
15320 When ARCHIVES is t, include all archive files that are really being
15321 used by the agenda files. If ARCHIVE is `ifmode', do this only if
15322 `org-agenda-archives-mode' is t."
15325 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
15326 ((stringp org-agenda-files) (org-read-agenda-file-list))
15327 ((listp org-agenda-files) org-agenda-files)
15328 (t (error "Invalid value of `org-agenda-files'")))))
15329 (setq files (apply 'append
15330 (mapcar (lambda (f)
15331 (if (file-directory-p f)
15333 f t org-agenda-file-regexp)
15336 (when org-agenda-skip-unavailable-files
15337 (setq files (delq nil
15340 (and (file-readable-p file) file)))
15342 (when (or (eq archives t)
15343 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
15344 (setq files (org-add-archive-files files)))
15347 (defun org-agenda-file-p (&optional file)
15348 "Return non-nil, if FILE is an agenda file.
15349 If FILE is omitted, use the file associated with the current
15351 (member (or file (buffer-file-name))
15352 (org-agenda-files t)))
15354 (defun org-edit-agenda-file-list ()
15355 "Edit the list of agenda files.
15356 Depending on setup, this either uses customize to edit the variable
15357 `org-agenda-files', or it visits the file that is holding the list. In the
15358 latter case, the buffer is set up in a way that saving it automatically kills
15359 the buffer and restores the previous window configuration."
15361 (if (stringp org-agenda-files)
15362 (let ((cw (current-window-configuration)))
15363 (find-file org-agenda-files)
15364 (org-set-local 'org-window-configuration cw)
15365 (org-add-hook 'after-save-hook
15367 (set-window-configuration
15368 (prog1 org-window-configuration
15369 (kill-buffer (current-buffer))))
15370 (org-install-agenda-files-menu)
15371 (message "New agenda file list installed"))
15373 (message "%s" (substitute-command-keys
15374 "Edit list and finish with \\[save-buffer]")))
15375 (customize-variable 'org-agenda-files)))
15377 (defun org-store-new-agenda-file-list (list)
15378 "Set new value for the agenda file list and save it correctly."
15379 (if (stringp org-agenda-files)
15380 (let ((fe (org-read-agenda-file-list t)) b u)
15381 (while (setq b (find-buffer-visiting org-agenda-files))
15383 (with-temp-file org-agenda-files
15386 (lambda (f) ;; Keep un-expanded entries.
15387 (if (setq u (assoc f fe))
15392 (let ((org-mode-hook nil) (org-inhibit-startup t)
15393 (org-insert-mode-line-in-empty-file nil))
15394 (setq org-agenda-files list)
15395 (customize-save-variable 'org-agenda-files org-agenda-files))))
15397 (defun org-read-agenda-file-list (&optional pair-with-expansion)
15398 "Read the list of agenda files from a file.
15399 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
15400 filenames, used by `org-store-new-agenda-file-list' to write back
15401 un-expanded file names."
15402 (when (file-directory-p org-agenda-files)
15403 (error "`org-agenda-files' cannot be a single directory"))
15404 (when (stringp org-agenda-files)
15406 (insert-file-contents org-agenda-files)
15409 (let ((e (expand-file-name (substitute-in-file-name f)
15411 (if pair-with-expansion
15414 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
15417 (defun org-cycle-agenda-files ()
15418 "Cycle through the files in `org-agenda-files'.
15419 If the current buffer visits an agenda file, find the next one in the list.
15420 If the current buffer does not, find the first agenda file."
15422 (let* ((fs (org-agenda-files t))
15423 (files (append fs (list (car fs))))
15424 (tcf (if buffer-file-name (file-truename buffer-file-name)))
15426 (unless files (error "No agenda files"))
15428 (while (setq file (pop files))
15429 (if (equal (file-truename file) tcf)
15431 (find-file (car files))
15433 (find-file (car fs)))
15434 (if (buffer-base-buffer) (switch-to-buffer (buffer-base-buffer)))))
15436 (defun org-agenda-file-to-front (&optional to-end)
15437 "Move/add the current file to the top of the agenda file list.
15438 If the file is not present in the list, it is added to the front. If it is
15439 present, it is moved there. With optional argument TO-END, add/move to the
15442 (let ((org-agenda-skip-unavailable-files nil)
15443 (file-alist (mapcar (lambda (x)
15444 (cons (file-truename x) x))
15445 (org-agenda-files t)))
15446 (ctf (file-truename buffer-file-name))
15448 (setq x (assoc ctf file-alist) had x)
15450 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
15452 (setq file-alist (append (delq x file-alist) (list x)))
15453 (setq file-alist (cons x (delq x file-alist))))
15454 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
15455 (org-install-agenda-files-menu)
15456 (message "File %s to %s of agenda file list"
15457 (if had "moved" "added") (if to-end "end" "front"))))
15459 (defun org-remove-file (&optional file)
15460 "Remove current file from the list of files in variable `org-agenda-files'.
15461 These are the files which are being checked for agenda entries.
15462 Optional argument FILE means use this file instead of the current."
15464 (let* ((org-agenda-skip-unavailable-files nil)
15465 (file (or file buffer-file-name))
15466 (true-file (file-truename file))
15467 (afile (abbreviate-file-name file))
15468 (files (delq nil (mapcar
15470 (if (equal true-file
15473 (org-agenda-files t)))))
15474 (if (not (= (length files) (length (org-agenda-files t))))
15476 (org-store-new-agenda-file-list files)
15477 (org-install-agenda-files-menu)
15478 (message "Removed file: %s" afile))
15479 (message "File was not in list: %s (not removed)" afile))))
15481 (defun org-file-menu-entry (file)
15482 (vector file (list 'find-file file) t))
15484 (defun org-check-agenda-file (file)
15485 "Make sure FILE exists. If not, ask user what to do."
15486 (when (not (file-exists-p file))
15487 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
15488 (abbreviate-file-name file))
15489 (let ((r (downcase (read-char-exclusive))))
15492 (org-remove-file file)
15493 (throw 'nextfile t))
15494 (t (error "Abort"))))))
15496 (defun org-get-agenda-file-buffer (file)
15497 "Get a buffer visiting FILE. If the buffer needs to be created, add
15498 it to the list of buffers which might be released later."
15499 (let ((buf (org-find-base-buffer-visiting file)))
15501 buf ; just return it
15502 ;; Make a new buffer and remember it
15503 (setq buf (find-file-noselect file))
15504 (if buf (push buf org-agenda-new-buffers))
15507 (defun org-release-buffers (blist)
15508 "Release all buffers in list, asking the user for confirmation when needed.
15509 When a buffer is unmodified, it is just killed. When modified, it is saved
15510 \(if the user agrees) and then killed."
15512 (while (setq buf (pop blist))
15513 (setq file (buffer-file-name buf))
15514 (when (and (buffer-modified-p buf)
15516 (y-or-n-p (format "Save file %s? " file)))
15517 (with-current-buffer buf (save-buffer)))
15518 (kill-buffer buf))))
15520 (defun org-prepare-agenda-buffers (files)
15521 "Create buffers for all agenda files, protect archived trees and comments."
15523 (let ((pa '(:org-archived t))
15524 (pc '(:org-comment t))
15525 (pall '(:org-archived t :org-comment t))
15526 (inhibit-read-only t)
15527 (rea (concat ":" org-archive-tag ":"))
15531 (while (setq file (pop files))
15535 (org-check-agenda-file file)
15536 (set-buffer (org-get-agenda-file-buffer file)))
15538 (setq bmp (buffer-modified-p))
15539 (org-refresh-category-properties)
15540 (setq org-todo-keywords-for-agenda
15541 (append org-todo-keywords-for-agenda org-todo-keywords-1))
15542 (setq org-done-keywords-for-agenda
15543 (append org-done-keywords-for-agenda org-done-keywords))
15544 (setq org-todo-keyword-alist-for-agenda
15545 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
15546 (setq org-drawers-for-agenda
15547 (append org-drawers-for-agenda org-drawers))
15548 (setq org-tag-alist-for-agenda
15549 (append org-tag-alist-for-agenda org-tag-alist))
15552 (remove-text-properties (point-min) (point-max) pall)
15553 (when org-agenda-skip-archived-trees
15554 (goto-char (point-min))
15555 (while (re-search-forward rea nil t)
15556 (if (org-on-heading-p t)
15557 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
15558 (goto-char (point-min))
15559 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
15560 (while (re-search-forward re nil t)
15561 (add-text-properties
15562 (match-beginning 0) (org-end-of-subtree t) pc)))
15563 (set-buffer-modified-p bmp)))))
15564 (setq org-todo-keywords-for-agenda
15565 (org-uniquify org-todo-keywords-for-agenda))
15566 (setq org-todo-keyword-alist-for-agenda
15567 (org-uniquify org-todo-keyword-alist-for-agenda)
15568 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
15570 ;;;; Embedded LaTeX
15572 (defvar org-cdlatex-mode-map (make-sparse-keymap)
15573 "Keymap for the minor `org-cdlatex-mode'.")
15575 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
15576 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
15577 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
15578 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
15579 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
15581 (defvar org-cdlatex-texmathp-advice-is-done nil
15582 "Flag remembering if we have applied the advice to texmathp already.")
15584 (define-minor-mode org-cdlatex-mode
15585 "Toggle the minor `org-cdlatex-mode'.
15586 This mode supports entering LaTeX environment and math in LaTeX fragments
15588 \\{org-cdlatex-mode-map}"
15590 (when org-cdlatex-mode (require 'cdlatex))
15591 (unless org-cdlatex-texmathp-advice-is-done
15592 (setq org-cdlatex-texmathp-advice-is-done t)
15593 (defadvice texmathp (around org-math-always-on activate)
15594 "Always return t in org-mode buffers.
15595 This is because we want to insert math symbols without dollars even outside
15596 the LaTeX math segments. If Orgmode thinks that point is actually inside
15597 an embedded LaTeX fragment, let texmathp do its job.
15598 \\[org-cdlatex-mode-map]"
15602 ((not (org-mode-p)) ad-do-it)
15603 ((eq this-command 'cdlatex-math-symbol)
15604 (setq ad-return-value t
15605 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
15607 (let ((p (org-inside-LaTeX-fragment-p)))
15608 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
15609 (setq ad-return-value t
15610 texmathp-why '("Org-mode embedded math" . 0))
15611 (if p ad-do-it)))))))))
15613 (defun turn-on-org-cdlatex ()
15614 "Unconditionally turn on `org-cdlatex-mode'."
15615 (org-cdlatex-mode 1))
15617 (defun org-inside-LaTeX-fragment-p ()
15618 "Test if point is inside a LaTeX fragment.
15619 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
15620 sequence appearing also before point.
15621 Even though the matchers for math are configurable, this function assumes
15622 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
15623 delimiters are skipped when they have been removed by customization.
15624 The return value is nil, or a cons cell with the delimiter and
15625 and the position of this delimiter.
15627 This function does a reasonably good job, but can locally be fooled by
15628 for example currency specifications. For example it will assume being in
15629 inline math after \"$22.34\". The LaTeX fragment formatter will only format
15630 fragments that are properly closed, but during editing, we have to live
15631 with the uncertainty caused by missing closing delimiters. This function
15632 looks only before point, not after."
15634 (let ((pos (point))
15635 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
15637 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
15639 dd-on str (start 0) m re)
15642 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
15643 re (nth 1 (assoc "$" org-latex-regexps)))
15644 (while (string-match re str start)
15646 ((= (match-end 0) (length str))
15647 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
15648 ((= (match-end 0) (- (length str) 5))
15650 (t (setq start (match-end 0))))))
15651 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
15653 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
15654 (and (match-beginning 2) (throw 'exit nil))
15656 (while (re-search-backward "\\$\\$" lim t)
15657 (setq dd-on (not dd-on)))
15659 (if dd-on (cons "$$" m))))))
15661 (defun org-inside-latex-macro-p ()
15662 "Is point inside a LaTeX macro or its arguments?"
15665 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
15667 (defun org-try-cdlatex-tab ()
15668 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
15669 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
15670 - inside a LaTeX fragment, or
15671 - after the first word in a line, where an abbreviation expansion could
15672 insert a LaTeX environment."
15673 (when org-cdlatex-mode
15676 (skip-chars-backward "a-zA-Z0-9*")
15677 (skip-chars-backward " \t")
15680 ((org-inside-LaTeX-fragment-p)
15684 (defun org-cdlatex-underscore-caret (&optional arg)
15685 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
15686 Revert to the normal definition outside of these fragments."
15688 (if (org-inside-LaTeX-fragment-p)
15689 (call-interactively 'cdlatex-sub-superscript)
15690 (let (org-cdlatex-mode)
15691 (call-interactively (key-binding (vector last-input-event))))))
15693 (defun org-cdlatex-math-modify (&optional arg)
15694 "Execute `cdlatex-math-modify' in LaTeX fragments.
15695 Revert to the normal definition outside of these fragments."
15697 (if (org-inside-LaTeX-fragment-p)
15698 (call-interactively 'cdlatex-math-modify)
15699 (let (org-cdlatex-mode)
15700 (call-interactively (key-binding (vector last-input-event))))))
15702 (defvar org-latex-fragment-image-overlays nil
15703 "List of overlays carrying the images of latex fragments.")
15704 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
15706 (defun org-remove-latex-fragment-image-overlays ()
15707 "Remove all overlays with LaTeX fragment images in current buffer."
15708 (mapc 'delete-overlay org-latex-fragment-image-overlays)
15709 (setq org-latex-fragment-image-overlays nil))
15711 (defun org-preview-latex-fragment (&optional subtree)
15712 "Preview the LaTeX fragment at point, or all locally or globally.
15713 If the cursor is in a LaTeX fragment, create the image and overlay
15714 it over the source code. If there is no fragment at point, display
15715 all fragments in the current text, from one headline to the next. With
15716 prefix SUBTREE, display all fragments in the current subtree. With a
15717 double prefix arg \\[universal-argument] \\[universal-argument], or when \
15718 the cursor is before the first headline,
15719 display all fragments in the buffer.
15720 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15722 (org-remove-latex-fragment-image-overlays)
15725 (let (beg end at msg)
15727 ((or (equal subtree '(16))
15728 (not (save-excursion
15729 (re-search-backward (concat "^" outline-regexp) nil t))))
15730 (setq beg (point-min) end (point-max)
15731 msg "Creating images for buffer...%s"))
15732 ((equal subtree '(4))
15733 (org-back-to-heading)
15734 (setq beg (point) end (org-end-of-subtree t)
15735 msg "Creating images for subtree...%s"))
15737 (if (setq at (org-inside-LaTeX-fragment-p))
15738 (goto-char (max (point-min) (- (cdr at) 2)))
15739 (org-back-to-heading))
15740 (setq beg (point) end (progn (outline-next-heading) (point))
15741 msg (if at "Creating image...%s"
15742 "Creating images for entry...%s"))))
15744 (narrow-to-region beg end)
15747 (concat "ltxpng/" (file-name-sans-extension
15748 (file-name-nondirectory
15749 buffer-file-name)))
15750 default-directory 'overlays msg at 'forbuffer)
15751 (message msg "done. Use `C-c C-c' to remove images.")))))
15753 (defvar org-latex-regexps
15754 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
15755 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15756 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15757 ("$1" "\\([^$]\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15758 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
15759 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
15760 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
15761 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
15762 "Regular expressions for matching embedded LaTeX.")
15764 (defun org-format-latex (prefix &optional dir overlays msg at
15765 forbuffer protect-only)
15766 "Replace LaTeX fragments with links to an image, and produce images.
15767 Some of the options can be changed using the variable
15768 `org-format-latex-options'."
15769 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
15770 (let* ((prefixnodir (file-name-nondirectory prefix))
15771 (absprefix (expand-file-name prefix dir))
15772 (todir (file-name-directory absprefix))
15773 (opt org-format-latex-options)
15774 (matchers (plist-get opt :matchers))
15775 (re-list org-latex-regexps)
15776 (org-format-latex-header-extra
15777 (plist-get (org-infile-export-plist) :latex-header-extra))
15778 (cnt 0) txt hash link beg end re e checkdir
15779 executables-checked
15780 m n block linkfile movefile ov)
15781 ;; Check the different regular expressions
15782 (while (setq e (pop re-list))
15783 (setq m (car e) re (nth 1 e) n (nth 2 e)
15784 block (if (nth 3 e) "\n\n" ""))
15785 (when (member m matchers)
15786 (goto-char (point-min))
15787 (while (re-search-forward re nil t)
15788 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
15789 (not (get-text-property (match-beginning n)
15792 (not (eq (get-char-property (match-beginning n)
15794 'org-latex-overlay))))
15796 (add-text-properties (match-beginning n) (match-end n)
15797 '(org-protected t))
15798 (setq txt (match-string n)
15799 beg (match-beginning n) end (match-end n)
15801 (let (print-length print-level) ; make sure full list is printed
15802 (setq hash (sha1 (prin1-to-string
15803 (list org-format-latex-header
15804 org-format-latex-header-extra
15805 org-export-latex-default-packages-alist
15806 org-export-latex-packages-alist
15807 org-format-latex-options
15809 linkfile (format "%s_%s.png" prefix hash)
15810 movefile (format "%s_%s.png" absprefix hash)))
15811 (setq link (concat block "[[file:" linkfile "]]" block))
15812 (if msg (message msg cnt))
15814 (unless checkdir ; make sure the directory exists
15816 (or (file-directory-p todir) (make-directory todir)))
15818 (unless executables-checked
15819 (org-check-external-command
15820 "latex" "needed to convert LaTeX fragments to images")
15821 (org-check-external-command
15822 "dvipng" "needed to convert LaTeX fragments to images")
15823 (setq executables-checked t))
15825 (unless (file-exists-p movefile)
15826 (org-create-formula-image
15827 txt movefile opt forbuffer))
15831 (if (eq (overlay-get o 'org-overlay-type)
15832 'org-latex-overlay)
15833 (delete-overlay o)))
15834 (overlays-in beg end))
15835 (setq ov (make-overlay beg end))
15836 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
15837 (if (featurep 'xemacs)
15839 (overlay-put ov 'invisible t)
15842 (make-glyph (vector 'png :file movefile))))
15845 (list 'image :type 'png :file movefile :ascent 'center)))
15846 (push ov org-latex-fragment-image-overlays)
15848 (delete-region beg end)
15849 (insert (org-add-props link
15850 (list 'org-latex-src
15851 (replace-regexp-in-string "\"" "" txt))))))))))))
15853 ;; This function borrows from Ganesh Swami's latex2png.el
15854 (defun org-create-formula-image (string tofile options buffer)
15855 "This calls dvipng."
15856 (require 'org-latex)
15857 (let* ((tmpdir (if (featurep 'xemacs)
15859 temporary-file-directory))
15860 (texfilebase (make-temp-name
15861 (expand-file-name "orgtex" tmpdir)))
15862 (texfile (concat texfilebase ".tex"))
15863 (dvifile (concat texfilebase ".dvi"))
15864 (pngfile (concat texfilebase ".png"))
15865 (fnh (if (featurep 'xemacs)
15866 (font-height (get-face-font 'default))
15867 (face-attribute 'default :height nil)))
15868 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
15869 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
15870 (fg (or (plist-get options (if buffer :foreground :html-foreground))
15872 (bg (or (plist-get options (if buffer :background :html-background))
15874 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
15875 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
15876 (with-temp-file texfile
15877 (insert (org-splice-latex-header
15878 org-format-latex-header
15879 org-export-latex-default-packages-alist
15880 org-export-latex-packages-alist t
15881 org-format-latex-header-extra))
15882 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
15883 (require 'org-latex)
15884 (org-export-latex-fix-inputenc))
15885 (let ((dir default-directory))
15886 (condition-case nil
15889 (call-process "latex" nil nil nil texfile))
15892 (if (not (file-exists-p dvifile))
15893 (progn (message "Failed to create dvi file from %s" texfile) nil)
15894 (condition-case nil
15895 (call-process "dvipng" nil nil nil
15898 ;;"-x" scale "-y" scale
15903 (if (not (file-exists-p pngfile))
15904 (if org-format-latex-signal-error
15905 (error "Failed to create png file from %s" texfile)
15906 (message "Failed to create png file from %s" texfile)
15908 ;; Use the requested file name and clean up
15909 (copy-file pngfile tofile 'replace)
15910 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
15911 (delete-file (concat texfilebase e)))
15914 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
15915 "Fill a LaTeX header template TPL.
15916 In the template, the following place holders will be recognized:
15918 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
15919 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
15920 [PACKAGES] \\usepackage statements for PKG
15921 [NO-PACKAGES] do not include PKG
15922 [EXTRA] the string EXTRA
15923 [NO-EXTRA] do not include EXTRA
15925 For backward compatibility, if both the positive and the negative place
15926 holder is missing, the positive one (without the \"NO-\") will be
15927 assumed to be present at the end of the template.
15928 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
15930 SNIPPETS-P indicates if this is run to create snippet images for HTML."
15931 (let (rpl (end ""))
15932 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
15933 (setq rpl (if (or (match-end 1) (not def-pkg))
15934 "" (org-latex-packages-to-string def-pkg snippets-p t))
15935 tpl (replace-match rpl t t tpl))
15936 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
15938 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
15939 (setq rpl (if (or (match-end 1) (not pkg))
15940 "" (org-latex-packages-to-string pkg snippets-p t))
15941 tpl (replace-match rpl t t tpl))
15944 (org-latex-packages-to-string pkg snippets-p)))))
15946 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
15947 (setq rpl (if (or (match-end 1) (not extra))
15948 "" (concat extra "\n"))
15949 tpl (replace-match rpl t t tpl))
15950 (if (and extra (string-match "\\S-" extra))
15951 (setq end (concat end "\n" extra))))
15953 (if (string-match "\\S-" end)
15954 (concat tpl "\n" end)
15957 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
15958 "Turn an alist of packages into a string with the \\usepackage macros."
15959 (setq pkg (mapconcat (lambda(p)
15962 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
15963 (format "%% Package %s omitted" (cadr p)))
15964 ((equal "" (car p))
15965 (format "\\usepackage{%s}" (cadr p)))
15967 (format "\\usepackage[%s]{%s}"
15968 (car p) (cadr p)))))
15971 (if newline (concat pkg "\n") pkg))
15973 (defun org-dvipng-color (attr)
15974 "Return an rgb color specification for dvipng."
15975 (apply 'format "rgb %s %s %s"
15976 (mapcar 'org-normalize-color
15977 (color-values (face-attribute 'default attr nil)))))
15979 (defun org-normalize-color (value)
15980 "Return string to be used as color value for an RGB component."
15981 (format "%g" (/ value 65535.0)))
15986 (defvar org-inline-image-overlays nil)
15987 (make-variable-buffer-local 'org-inline-image-overlays)
15989 (defun org-toggle-inline-images (&optional include-linked)
15990 "Toggle the display of inline images.
15991 INCLUDE-LINKED is passed to `org-display-inline-images'."
15993 (if org-inline-image-overlays
15995 (org-remove-inline-images)
15996 (message "Inline image display turned off"))
15997 (org-display-inline-images include-linked)
15998 (if org-inline-image-overlays
15999 (message "%d images displayed inline"
16000 (length org-inline-image-overlays))
16001 (message "No images to display inline"))))
16003 (defun org-display-inline-images (&optional include-linked refresh beg end)
16004 "Display inline images.
16005 Normally only links without a description part are inlined, because this
16006 is how it will work for export. When INCLUDE-LINKED is set, also links
16007 with a description part will be inlined. This can be nice for a quick
16008 look at those images, but it does not reflect what exported files will look
16010 When REFRESH is set, refresh existing images between BEG and END.
16011 This will create new image displays only if necessary.
16012 BEG and END default to the buffer boundaries."
16015 (org-remove-inline-images)
16016 (clear-image-cache))
16020 (setq beg (or beg (point-min)) end (or end (point-max)))
16021 (goto-char (point-min))
16022 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([-+~.:/\\_0-9a-zA-Z ]+"
16023 (substring (org-image-file-name-regexp) 0 -2)
16024 "\\)\\]" (if include-linked "" "\\]")))
16026 (while (re-search-forward re end t)
16027 (setq old (get-char-property-and-overlay (match-beginning 1)
16028 'org-image-overlay))
16029 (setq file (expand-file-name
16030 (concat (or (match-string 3) "") (match-string 4))))
16031 (when (file-exists-p file)
16032 (if (and (car-safe old) refresh)
16033 (image-refresh (overlay-get (cdr old) 'display))
16034 (setq img (create-image file))
16036 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
16037 (overlay-put ov 'display img)
16038 (overlay-put ov 'face 'default)
16039 (overlay-put ov 'org-image-overlay t)
16040 (overlay-put ov 'modification-hooks
16041 (list 'org-display-inline-modification-hook))
16042 (push ov org-inline-image-overlays)))))))))
16044 (defun org-display-inline-modification-hook (ov after beg end &optional len)
16045 "Remove inline-display overlay if a corresponding region is modified."
16046 (let ((inhibit-modification-hooks t))
16047 (when (and ov after)
16048 (delete ov org-inline-image-overlays)
16049 (delete-overlay ov))))
16051 (defun org-remove-inline-images ()
16052 "Remove inline display of images."
16054 (mapc 'delete-overlay org-inline-image-overlays)
16055 (setq org-inline-image-overlays nil))
16059 ;; Make `C-c C-x' a prefix key
16060 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
16062 ;; TAB key with modifiers
16063 (org-defkey org-mode-map "\C-i" 'org-cycle)
16064 (org-defkey org-mode-map [(tab)] 'org-cycle)
16065 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
16066 (org-defkey org-mode-map [(meta tab)] 'org-complete)
16067 (org-defkey org-mode-map "\M-\t" 'org-complete)
16068 (org-defkey org-mode-map "\M-\C-i" 'org-complete)
16069 ;; The following line is necessary under Suse GNU/Linux
16070 (unless (featurep 'xemacs)
16071 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
16072 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
16073 (define-key org-mode-map [backtab] 'org-shifttab)
16075 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
16076 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
16077 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
16079 ;; Cursor keys with modifiers
16080 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
16081 (org-defkey org-mode-map [(meta right)] 'org-metaright)
16082 (org-defkey org-mode-map [(meta up)] 'org-metaup)
16083 (org-defkey org-mode-map [(meta down)] 'org-metadown)
16085 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
16086 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
16087 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
16088 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
16090 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
16091 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
16092 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
16093 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
16095 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
16096 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
16099 (define-key org-mode-map org-babel-key-prefix org-babel-map)
16100 (mapc (lambda (pair)
16101 (define-key org-babel-map (car pair) (cdr pair)))
16102 org-babel-key-bindings)
16104 ;;; Extra keys for tty access.
16105 ;; We only set them when really needed because otherwise the
16106 ;; menus don't show the simple keys
16108 (when (or org-use-extra-keys
16109 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
16110 (not window-system))
16111 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
16112 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
16113 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
16114 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
16115 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
16116 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
16117 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
16118 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
16119 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
16120 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
16121 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
16122 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
16123 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
16124 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
16125 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
16126 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
16127 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
16128 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
16129 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
16130 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
16131 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
16132 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
16133 (org-defkey org-mode-map [?\e (tab)] 'org-complete)
16134 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
16135 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
16136 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
16137 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
16138 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
16140 ;; All the other keys
16142 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
16143 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
16144 (if (boundp 'narrow-map)
16145 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
16146 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
16147 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
16148 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
16149 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
16150 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
16151 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
16152 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
16153 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
16154 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
16155 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
16156 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
16157 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
16158 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
16159 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
16160 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
16161 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
16162 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
16163 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
16164 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
16165 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
16166 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
16167 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
16168 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
16169 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
16170 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
16171 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
16172 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
16173 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
16174 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
16175 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
16176 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
16177 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
16178 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
16179 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
16180 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
16181 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
16182 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
16183 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
16184 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
16185 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
16186 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
16187 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
16188 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
16189 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
16190 (org-defkey org-mode-map "\C-c^" 'org-sort)
16191 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
16192 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
16193 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
16194 (org-defkey org-mode-map "\C-m" 'org-return)
16195 (org-defkey org-mode-map "\C-j" 'org-return-indent)
16196 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
16197 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
16198 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
16199 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
16200 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
16201 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
16202 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
16203 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
16204 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
16205 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
16206 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
16207 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
16208 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
16209 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
16210 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
16211 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
16212 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
16213 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
16214 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
16215 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
16217 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
16218 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
16219 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
16220 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
16222 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
16223 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
16224 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
16225 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
16226 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
16227 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
16228 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
16229 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
16230 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
16231 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
16232 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
16233 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
16234 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
16235 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
16236 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
16237 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
16238 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
16240 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
16241 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
16242 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
16243 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
16245 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
16247 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
16249 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
16250 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
16252 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
16255 (when (featurep 'xemacs)
16256 (org-defkey org-mode-map 'button3 'popup-mode-menu))
16259 (defconst org-speed-commands-default
16261 ("Outline Navigation")
16262 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
16263 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
16264 ("f" . (org-speed-move-safe 'org-forward-same-level))
16265 ("b" . (org-speed-move-safe 'org-backward-same-level))
16266 ("u" . (org-speed-move-safe 'outline-up-heading))
16268 ("g" . (org-refile t))
16269 ("Outline Visibility")
16271 ("C" . org-shifttab)
16272 (" " . org-display-outline-path)
16273 ("Outline Structure Editing")
16274 ("U" . org-shiftmetaup)
16275 ("D" . org-shiftmetadown)
16276 ("r" . org-metaright)
16277 ("l" . org-metaleft)
16278 ("R" . org-shiftmetaright)
16279 ("L" . org-shiftmetaleft)
16280 ("i" . (progn (forward-char 1) (call-interactively
16281 'org-insert-heading-respect-content)))
16284 ("a" . org-archive-subtree-default-with-confirmation)
16285 ("." . outline-mark-subtree)
16287 ("I" . org-clock-in)
16288 ("O" . org-clock-out)
16289 ("Meta Data Editing")
16291 ("0" . (org-priority ?\ ))
16292 ("1" . (org-priority ?A))
16293 ("2" . (org-priority ?B))
16294 ("3" . (org-priority ?C))
16295 (";" . org-set-tags-command)
16296 ("e" . org-set-effort)
16297 ("Agenda Views etc")
16299 ("/" . org-sparse-tree)
16301 ("o" . org-open-at-point)
16302 ("?" . org-speed-command-help)
16304 "The default speed commands.")
16306 (defun org-print-speed-command (e)
16307 (if (> (length (car e)) 1)
16312 (princ (make-string (length (car e)) ?-))
16316 (if (symbolp (cdr e))
16317 (princ (symbol-name (cdr e)))
16321 (defun org-speed-command-help ()
16322 "Show the available speed commands."
16324 (if (not org-use-speed-commands)
16325 (error "Speed commands are not activated, customize `org-use-speed-commands'")
16326 (with-output-to-temp-buffer "*Help*"
16327 (princ "User-defined Speed commands\n===========================\n")
16328 (mapc 'org-print-speed-command org-speed-commands-user)
16330 (princ "Built-in Speed commands\n=======================\n")
16331 (mapc 'org-print-speed-command org-speed-commands-default))
16332 (with-current-buffer "*Help*"
16333 (setq truncate-lines t))))
16335 (defun org-speed-move-safe (cmd)
16336 "Execute CMD, but make sure that the cursor always ends up in a headline.
16337 If not, return to the original position and throw an error."
16339 (let ((pos (point)))
16340 (call-interactively cmd)
16341 (unless (and (bolp) (org-on-heading-p))
16343 (error "Boundary reached while executing %s" cmd))))
16345 (defvar org-self-insert-command-undo-counter 0)
16347 (defvar org-table-auto-blank-field) ; defined in org-table.el
16348 (defvar org-speed-command nil)
16349 (defun org-self-insert-command (N)
16350 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
16351 If the cursor is in a table looking at whitespace, the whitespace is
16352 overwritten, and the table is not marked as requiring realignment."
16355 ((and org-use-speed-commands
16356 (or (and (bolp) (looking-at outline-regexp))
16357 (and (functionp org-use-speed-commands)
16358 (funcall org-use-speed-commands)))
16361 (or (cdr (assoc (this-command-keys) org-speed-commands-user))
16362 (cdr (assoc (this-command-keys) org-speed-commands-default)))))
16364 ((commandp org-speed-command)
16365 (setq this-command org-speed-command)
16366 (call-interactively org-speed-command))
16367 ((functionp org-speed-command)
16368 (funcall org-speed-command))
16369 ((and org-speed-command (listp org-speed-command))
16370 (eval org-speed-command))
16371 (t (let (org-use-speed-commands)
16372 (call-interactively 'org-self-insert-command)))))
16376 ;; check if we blank the field, and if that triggers align
16377 (and (featurep 'org-table) org-table-auto-blank-field
16378 (member last-command
16379 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
16380 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
16381 ;; got extra space, this field does not determine column width
16382 (let (org-table-may-need-update) (org-table-blank-field))
16383 ;; no extra space, this field may determine column width
16384 (org-table-blank-field)))
16387 (looking-at "[^|\n]* |"))
16388 (let (org-table-may-need-update)
16389 (goto-char (1- (match-end 0)))
16390 (delete-backward-char 1)
16391 (goto-char (match-beginning 0))
16392 (self-insert-command N)))
16394 (setq org-table-may-need-update t)
16395 (self-insert-command N)
16396 (org-fix-tags-on-the-fly)
16397 (if org-self-insert-cluster-for-undo
16398 (if (not (eq last-command 'org-self-insert-command))
16399 (setq org-self-insert-command-undo-counter 1)
16400 (if (>= org-self-insert-command-undo-counter 20)
16401 (setq org-self-insert-command-undo-counter 1)
16402 (and (> org-self-insert-command-undo-counter 0)
16404 (not (cadr buffer-undo-list)) ; remove nil entry
16405 (setcdr buffer-undo-list (cddr buffer-undo-list)))
16406 (setq org-self-insert-command-undo-counter
16407 (1+ org-self-insert-command-undo-counter))))))))
16409 (defun org-fix-tags-on-the-fly ()
16410 (when (and (equal (char-after (point-at-bol)) ?*)
16411 (org-on-heading-p))
16412 (org-align-tags-here org-tags-column)))
16414 (defun org-delete-backward-char (N)
16415 "Like `delete-backward-char', insert whitespace at field end in tables.
16416 When deleting backwards, in tables this function will insert whitespace in
16417 front of the next \"|\" separator, to keep the table aligned. The table will
16418 still be marked for re-alignment if the field did fill the entire column,
16419 because, in this case the deletion might narrow the column."
16421 (if (and (org-table-p)
16423 (string-match "|" (buffer-substring (point-at-bol) (point)))
16424 (looking-at ".*?|"))
16425 (let ((pos (point))
16426 (noalign (looking-at "[^|\n\r]* |"))
16427 (c org-table-may-need-update))
16428 (backward-delete-char N)
16429 (skip-chars-forward "^|")
16431 (goto-char (1- pos))
16432 ;; noalign: if there were two spaces at the end, this field
16433 ;; does not determine the width of the column.
16434 (if noalign (setq org-table-may-need-update c)))
16435 (backward-delete-char N)
16436 (org-fix-tags-on-the-fly)))
16438 (defun org-delete-char (N)
16439 "Like `delete-char', but insert whitespace at field end in tables.
16440 When deleting characters, in tables this function will insert whitespace in
16441 front of the next \"|\" separator, to keep the table aligned. The table will
16442 still be marked for re-alignment if the field did fill the entire column,
16443 because, in this case the deletion might narrow the column."
16445 (if (and (org-table-p)
16447 (not (= (char-after) ?|))
16449 (if (looking-at ".*?|")
16450 (let ((pos (point))
16451 (noalign (looking-at "[^|\n\r]* |"))
16452 (c org-table-may-need-update))
16453 (replace-match (concat
16454 (substring (match-string 0) 1 -1)
16457 ;; noalign: if there were two spaces at the end, this field
16458 ;; does not determine the width of the column.
16459 (if noalign (setq org-table-may-need-update c)))
16462 (org-fix-tags-on-the-fly)))
16464 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
16465 (put 'org-self-insert-command 'delete-selection t)
16466 (put 'orgtbl-self-insert-command 'delete-selection t)
16467 (put 'org-delete-char 'delete-selection 'supersede)
16468 (put 'org-delete-backward-char 'delete-selection 'supersede)
16469 (put 'org-yank 'delete-selection 'yank)
16471 ;; Make `flyspell-mode' delay after some commands
16472 (put 'org-self-insert-command 'flyspell-delayed t)
16473 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
16474 (put 'org-delete-char 'flyspell-delayed t)
16475 (put 'org-delete-backward-char 'flyspell-delayed t)
16477 ;; Make pabbrev-mode expand after org-mode commands
16478 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
16479 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
16481 ;; How to do this: Measure non-white length of current string
16482 ;; If equal to column width, we should realign.
16484 (defun org-remap (map &rest commands)
16485 "In MAP, remap the functions given in COMMANDS.
16486 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
16489 (setq old (pop commands) new (pop commands))
16490 (if (fboundp 'command-remapping)
16491 (org-defkey map (vector 'remap old) new)
16492 (substitute-key-definition old new map global-map)))))
16494 (when (eq org-enable-table-editor 'optimized)
16495 ;; If the user wants maximum table support, we need to hijack
16496 ;; some standard editing functions
16497 (org-remap org-mode-map
16498 'self-insert-command 'org-self-insert-command
16499 'delete-char 'org-delete-char
16500 'delete-backward-char 'org-delete-backward-char)
16501 (org-defkey org-mode-map "|" 'org-force-self-insert))
16503 (defvar org-ctrl-c-ctrl-c-hook nil
16504 "Hook for functions attaching themselves to `C-c C-c'.
16505 This can be used to add additional functionality to the C-c C-c key which
16506 executes context-dependent commands.
16507 Each function will be called with no arguments. The function must check
16508 if the context is appropriate for it to act. If yes, it should do its
16509 thing and then return a non-nil value. If the context is wrong,
16510 just do nothing and return nil.")
16512 (defvar org-tab-first-hook nil
16513 "Hook for functions to attach themselves to TAB.
16514 See `org-ctrl-c-ctrl-c-hook' for more information.
16515 This hook runs as the first action when TAB is pressed, even before
16516 `org-cycle' messes around with the `outline-regexp' to cater for
16517 inline tasks and plain list item folding.
16518 If any function in this hook returns t, any other actions that
16519 would have been caused by TAB (such as table field motion or visibility
16520 cycling) will not occur.")
16522 (defvar org-tab-after-check-for-table-hook nil
16523 "Hook for functions to attach themselves to TAB.
16524 See `org-ctrl-c-ctrl-c-hook' for more information.
16525 This hook runs after it has been established that the cursor is not in a
16526 table, but before checking if the cursor is in a headline or if global cycling
16528 If any function in this hook returns t, not other actions like visibility
16529 cycling will be done.")
16531 (defvar org-tab-after-check-for-cycling-hook nil
16532 "Hook for functions to attach themselves to TAB.
16533 See `org-ctrl-c-ctrl-c-hook' for more information.
16534 This hook runs after it has been established that not table field motion and
16535 not visibility should be done because of current context. This is probably
16536 the place where a package like yasnippets can hook in.")
16538 (defvar org-tab-before-tab-emulation-hook nil
16539 "Hook for functions to attach themselves to TAB.
16540 See `org-ctrl-c-ctrl-c-hook' for more information.
16541 This hook runs after every other options for TAB have been exhausted, but
16542 before indentation and \t insertion takes place.")
16544 (defvar org-metaleft-hook nil
16545 "Hook for functions attaching themselves to `M-left'.
16546 See `org-ctrl-c-ctrl-c-hook' for more information.")
16547 (defvar org-metaright-hook nil
16548 "Hook for functions attaching themselves to `M-right'.
16549 See `org-ctrl-c-ctrl-c-hook' for more information.")
16550 (defvar org-metaup-hook nil
16551 "Hook for functions attaching themselves to `M-up'.
16552 See `org-ctrl-c-ctrl-c-hook' for more information.")
16553 (defvar org-metadown-hook nil
16554 "Hook for functions attaching themselves to `M-down'.
16555 See `org-ctrl-c-ctrl-c-hook' for more information.")
16556 (defvar org-shiftmetaleft-hook nil
16557 "Hook for functions attaching themselves to `M-S-left'.
16558 See `org-ctrl-c-ctrl-c-hook' for more information.")
16559 (defvar org-shiftmetaright-hook nil
16560 "Hook for functions attaching themselves to `M-S-right'.
16561 See `org-ctrl-c-ctrl-c-hook' for more information.")
16562 (defvar org-shiftmetaup-hook nil
16563 "Hook for functions attaching themselves to `M-S-up'.
16564 See `org-ctrl-c-ctrl-c-hook' for more information.")
16565 (defvar org-shiftmetadown-hook nil
16566 "Hook for functions attaching themselves to `M-S-down'.
16567 See `org-ctrl-c-ctrl-c-hook' for more information.")
16568 (defvar org-metareturn-hook nil
16569 "Hook for functions attaching themselves to `M-RET'.
16570 See `org-ctrl-c-ctrl-c-hook' for more information.")
16571 (defvar org-shiftup-hook nil
16572 "Hook for functions attaching themselves to `S-up'.
16573 See `org-ctrl-c-ctrl-c-hook' for more information.")
16574 (defvar org-shiftup-final-hook nil
16575 "Hook for functions attaching themselves to `S-up'.
16576 This one runs after all other options except shift-select have been excluded.
16577 See `org-ctrl-c-ctrl-c-hook' for more information.")
16578 (defvar org-shiftdown-hook nil
16579 "Hook for functions attaching themselves to `S-down'.
16580 See `org-ctrl-c-ctrl-c-hook' for more information.")
16581 (defvar org-shiftdown-final-hook nil
16582 "Hook for functions attaching themselves to `S-down'.
16583 This one runs after all other options except shift-select have been excluded.
16584 See `org-ctrl-c-ctrl-c-hook' for more information.")
16585 (defvar org-shiftleft-hook nil
16586 "Hook for functions attaching themselves to `S-left'.
16587 See `org-ctrl-c-ctrl-c-hook' for more information.")
16588 (defvar org-shiftleft-final-hook nil
16589 "Hook for functions attaching themselves to `S-left'.
16590 This one runs after all other options except shift-select have been excluded.
16591 See `org-ctrl-c-ctrl-c-hook' for more information.")
16592 (defvar org-shiftright-hook nil
16593 "Hook for functions attaching themselves to `S-right'.
16594 See `org-ctrl-c-ctrl-c-hook' for more information.")
16595 (defvar org-shiftright-final-hook nil
16596 "Hook for functions attaching themselves to `S-right'.
16597 This one runs after all other options except shift-select have been excluded.
16598 See `org-ctrl-c-ctrl-c-hook' for more information.")
16600 (defun org-modifier-cursor-error ()
16601 "Throw an error, a modified cursor command was applied in wrong context."
16602 (error "This command is active in special context like tables, headlines or items"))
16604 (defun org-shiftselect-error ()
16605 "Throw an error because Shift-Cursor command was applied in wrong context."
16606 (if (and (boundp 'shift-select-mode) shift-select-mode)
16607 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
16608 (error "This command works only in special context like headlines or timestamps")))
16610 (defun org-call-for-shift-select (cmd)
16611 (let ((this-command-keys-shift-translated t))
16612 (call-interactively cmd)))
16614 (defun org-shifttab (&optional arg)
16615 "Global visibility cycling or move to previous table field.
16616 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
16618 See the individual commands for more information."
16621 ((org-at-table-p) (call-interactively 'org-table-previous-field))
16623 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
16624 (message "Content view to level: %d" arg)
16625 (org-content (prefix-numeric-value arg2))
16626 (setq org-cycle-global-status 'overview)))
16627 (t (call-interactively 'org-global-cycle))))
16629 (defun org-shiftmetaleft ()
16630 "Promote subtree or delete table column.
16631 Calls `org-promote-subtree', `org-outdent-item',
16632 or `org-table-delete-column', depending on context.
16633 See the individual commands for more information."
16636 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
16637 ((org-at-table-p) (call-interactively 'org-table-delete-column))
16638 ((org-on-heading-p) (call-interactively 'org-promote-subtree))
16639 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
16640 (t (org-modifier-cursor-error))))
16642 (defun org-shiftmetaright ()
16643 "Demote subtree or insert table column.
16644 Calls `org-demote-subtree', `org-indent-item',
16645 or `org-table-insert-column', depending on context.
16646 See the individual commands for more information."
16649 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
16650 ((org-at-table-p) (call-interactively 'org-table-insert-column))
16651 ((org-on-heading-p) (call-interactively 'org-demote-subtree))
16652 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
16653 (t (org-modifier-cursor-error))))
16655 (defun org-shiftmetaup (&optional arg)
16656 "Move subtree up or kill table row.
16657 Calls `org-move-subtree-up' or `org-table-kill-row' or
16658 `org-move-item-up' depending on context. See the individual commands
16659 for more information."
16662 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
16663 ((org-at-table-p) (call-interactively 'org-table-kill-row))
16664 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16665 ((org-at-item-p) (call-interactively 'org-move-item-up))
16666 (t (org-modifier-cursor-error))))
16668 (defun org-shiftmetadown (&optional arg)
16669 "Move subtree down or insert table row.
16670 Calls `org-move-subtree-down' or `org-table-insert-row' or
16671 `org-move-item-down', depending on context. See the individual
16672 commands for more information."
16675 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
16676 ((org-at-table-p) (call-interactively 'org-table-insert-row))
16677 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16678 ((org-at-item-p) (call-interactively 'org-move-item-down))
16679 (t (org-modifier-cursor-error))))
16681 (defsubst org-hidden-tree-error ()
16683 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
16685 (defun org-metaleft (&optional arg)
16686 "Promote heading or move table column to left.
16687 Calls `org-do-promote' or `org-table-move-column', depending on context.
16688 With no specific context, calls the Emacs default `backward-word'.
16689 See the individual commands for more information."
16692 ((run-hook-with-args-until-success 'org-metaleft-hook))
16693 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
16694 ((or (org-on-heading-p)
16695 (and (org-region-active-p)
16697 (goto-char (region-beginning))
16698 (org-on-heading-p))))
16699 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16700 (call-interactively 'org-do-promote))
16701 ((or (org-at-item-p)
16702 (and (org-region-active-p)
16704 (goto-char (region-beginning))
16706 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16707 (call-interactively 'org-outdent-item))
16708 (t (call-interactively 'backward-word))))
16710 (defun org-metaright (&optional arg)
16711 "Demote subtree or move table column to right.
16712 Calls `org-do-demote' or `org-table-move-column', depending on context.
16713 With no specific context, calls the Emacs default `forward-word'.
16714 See the individual commands for more information."
16717 ((run-hook-with-args-until-success 'org-metaright-hook))
16718 ((org-at-table-p) (call-interactively 'org-table-move-column))
16719 ((or (org-on-heading-p)
16720 (and (org-region-active-p)
16722 (goto-char (region-beginning))
16723 (org-on-heading-p))))
16724 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
16725 (call-interactively 'org-do-demote))
16726 ((or (org-at-item-p)
16727 (and (org-region-active-p)
16729 (goto-char (region-beginning))
16731 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
16732 (call-interactively 'org-indent-item))
16733 (t (call-interactively 'forward-word))))
16735 (defun org-check-for-hidden (what)
16736 "Check if there are hidden headlines/items in the current visual line.
16737 WHAT can be either `headlines' or `items'. If the current line is
16738 an outline or item heading and it has a folded subtree below it,
16739 this function returns t, nil otherwise."
16741 ((eq what 'headlines) (concat "^" org-outline-regexp))
16742 ((eq what 'items) (concat "^" (org-item-re t)))
16743 (t (error "This should not happen"))))
16747 (unless (org-region-active-p)
16748 (setq beg (point-at-bol))
16749 (beginning-of-line 2)
16750 (while (and (not (eobp)) ;; this is like `next-line'
16751 (get-char-property (1- (point)) 'invisible))
16752 (beginning-of-line 2))
16755 (goto-char (point-at-eol))
16756 (setq end (max end (point)))
16757 (while (re-search-forward re end t)
16758 (if (get-char-property (match-beginning 0) 'invisible)
16762 (defun org-metaup (&optional arg)
16763 "Move subtree up or move table row up.
16764 Calls `org-move-subtree-up' or `org-table-move-row' or
16765 `org-move-item-up', depending on context. See the individual commands
16766 for more information."
16769 ((run-hook-with-args-until-success 'org-metaup-hook))
16770 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
16771 ((org-on-heading-p) (call-interactively 'org-move-subtree-up))
16772 ((org-at-item-p) (call-interactively 'org-move-item-up))
16773 (t (transpose-lines 1) (beginning-of-line -1))))
16775 (defun org-metadown (&optional arg)
16776 "Move subtree down or move table row down.
16777 Calls `org-move-subtree-down' or `org-table-move-row' or
16778 `org-move-item-down', depending on context. See the individual
16779 commands for more information."
16782 ((run-hook-with-args-until-success 'org-metadown-hook))
16783 ((org-at-table-p) (call-interactively 'org-table-move-row))
16784 ((org-on-heading-p) (call-interactively 'org-move-subtree-down))
16785 ((org-at-item-p) (call-interactively 'org-move-item-down))
16786 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
16788 (defun org-shiftup (&optional arg)
16789 "Increase item in timestamp or increase priority of current headline.
16790 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
16791 depending on context. See the individual commands for more information."
16794 ((run-hook-with-args-until-success 'org-shiftup-hook))
16795 ((and org-support-shift-select (org-region-active-p))
16796 (org-call-for-shift-select 'previous-line))
16797 ((org-at-timestamp-p t)
16798 (call-interactively (if org-edit-timestamp-down-means-later
16799 'org-timestamp-down 'org-timestamp-up)))
16800 ((and (not (eq org-support-shift-select 'always))
16801 org-enable-priority-commands
16802 (org-on-heading-p))
16803 (call-interactively 'org-priority-up))
16804 ((and (not org-support-shift-select) (org-at-item-p))
16805 (call-interactively 'org-previous-item))
16806 ((org-clocktable-try-shift 'up arg))
16807 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
16808 (org-support-shift-select
16809 (org-call-for-shift-select 'previous-line))
16810 (t (org-shiftselect-error))))
16812 (defun org-shiftdown (&optional arg)
16813 "Decrease item in timestamp or decrease priority of current headline.
16814 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
16815 depending on context. See the individual commands for more information."
16818 ((run-hook-with-args-until-success 'org-shiftdown-hook))
16819 ((and org-support-shift-select (org-region-active-p))
16820 (org-call-for-shift-select 'next-line))
16821 ((org-at-timestamp-p t)
16822 (call-interactively (if org-edit-timestamp-down-means-later
16823 'org-timestamp-up 'org-timestamp-down)))
16824 ((and (not (eq org-support-shift-select 'always))
16825 org-enable-priority-commands
16826 (org-on-heading-p))
16827 (call-interactively 'org-priority-down))
16828 ((and (not org-support-shift-select) (org-at-item-p))
16829 (call-interactively 'org-next-item))
16830 ((org-clocktable-try-shift 'down arg))
16831 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
16832 (org-support-shift-select
16833 (org-call-for-shift-select 'next-line))
16834 (t (org-shiftselect-error))))
16836 (defun org-shiftright (&optional arg)
16837 "Cycle the thing at point or in the current line, depending on context.
16838 Depending on context, this does one of the following:
16840 - switch a timestamp at point one day into the future
16841 - on a headline, switch to the next TODO keyword.
16842 - on an item, switch entire list to the next bullet type
16843 - on a property line, switch to the next allowed value
16844 - on a clocktable definition line, move time block into the future"
16847 ((run-hook-with-args-until-success 'org-shiftright-hook))
16848 ((and org-support-shift-select (org-region-active-p))
16849 (org-call-for-shift-select 'forward-char))
16850 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
16851 ((and (not (eq org-support-shift-select 'always))
16852 (org-on-heading-p))
16853 (let ((org-inhibit-logging
16854 (not org-treat-S-cursor-todo-selection-as-state-change))
16855 (org-inhibit-blocking
16856 (not org-treat-S-cursor-todo-selection-as-state-change)))
16857 (org-call-with-arg 'org-todo 'right)))
16858 ((or (and org-support-shift-select
16859 (not (eq org-support-shift-select 'always))
16860 (org-at-item-bullet-p))
16861 (and (not org-support-shift-select) (org-at-item-p)))
16862 (org-call-with-arg 'org-cycle-list-bullet nil))
16863 ((and (not (eq org-support-shift-select 'always))
16864 (org-at-property-p))
16865 (call-interactively 'org-property-next-allowed-value))
16866 ((org-clocktable-try-shift 'right arg))
16867 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
16868 (org-support-shift-select
16869 (org-call-for-shift-select 'forward-char))
16870 (t (org-shiftselect-error))))
16872 (defun org-shiftleft (&optional arg)
16873 "Cycle the thing at point or in the current line, depending on context.
16874 Depending on context, this does one of the following:
16876 - switch a timestamp at point one day into the past
16877 - on a headline, switch to the previous TODO keyword.
16878 - on an item, switch entire list to the previous bullet type
16879 - on a property line, switch to the previous allowed value
16880 - on a clocktable definition line, move time block into the past"
16883 ((run-hook-with-args-until-success 'org-shiftleft-hook))
16884 ((and org-support-shift-select (org-region-active-p))
16885 (org-call-for-shift-select 'backward-char))
16886 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
16887 ((and (not (eq org-support-shift-select 'always))
16888 (org-on-heading-p))
16889 (let ((org-inhibit-logging
16890 (not org-treat-S-cursor-todo-selection-as-state-change))
16891 (org-inhibit-blocking
16892 (not org-treat-S-cursor-todo-selection-as-state-change)))
16893 (org-call-with-arg 'org-todo 'left)))
16894 ((or (and org-support-shift-select
16895 (not (eq org-support-shift-select 'always))
16896 (org-at-item-bullet-p))
16897 (and (not org-support-shift-select) (org-at-item-p)))
16898 (org-call-with-arg 'org-cycle-list-bullet 'previous))
16899 ((and (not (eq org-support-shift-select 'always))
16900 (org-at-property-p))
16901 (call-interactively 'org-property-previous-allowed-value))
16902 ((org-clocktable-try-shift 'left arg))
16903 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
16904 (org-support-shift-select
16905 (org-call-for-shift-select 'backward-char))
16906 (t (org-shiftselect-error))))
16908 (defun org-shiftcontrolright ()
16909 "Switch to next TODO set."
16912 ((and org-support-shift-select (org-region-active-p))
16913 (org-call-for-shift-select 'forward-word))
16914 ((and (not (eq org-support-shift-select 'always))
16915 (org-on-heading-p))
16916 (org-call-with-arg 'org-todo 'nextset))
16917 (org-support-shift-select
16918 (org-call-for-shift-select 'forward-word))
16919 (t (org-shiftselect-error))))
16921 (defun org-shiftcontrolleft ()
16922 "Switch to previous TODO set."
16925 ((and org-support-shift-select (org-region-active-p))
16926 (org-call-for-shift-select 'backward-word))
16927 ((and (not (eq org-support-shift-select 'always))
16928 (org-on-heading-p))
16929 (org-call-with-arg 'org-todo 'previousset))
16930 (org-support-shift-select
16931 (org-call-for-shift-select 'backward-word))
16932 (t (org-shiftselect-error))))
16934 (defun org-ctrl-c-ret ()
16935 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
16938 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
16939 (t (call-interactively 'org-insert-heading))))
16941 (defun org-copy-special ()
16942 "Copy region in table or copy current subtree.
16943 Calls `org-table-copy' or `org-copy-subtree', depending on context.
16944 See the individual commands for more information."
16946 (call-interactively
16947 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
16949 (defun org-cut-special ()
16950 "Cut region in table or cut current subtree.
16951 Calls `org-table-copy' or `org-cut-subtree', depending on context.
16952 See the individual commands for more information."
16954 (call-interactively
16955 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
16957 (defun org-paste-special (arg)
16958 "Paste rectangular region into table, or past subtree relative to level.
16959 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
16960 See the individual commands for more information."
16962 (if (org-at-table-p)
16963 (org-table-paste-rectangle)
16964 (org-paste-subtree arg)))
16966 (defun org-edit-special (&optional arg)
16967 "Call a special editor for the stuff at point.
16968 When at a table, call the formula editor with `org-table-edit-formulas'.
16969 When at the first line of an src example, call `org-edit-src-code'.
16970 When in an #+include line, visit the include file. Otherwise call
16971 `ffap' to visit the file at point."
16973 ;; possibly prep session before editing source
16975 (let* ((info (org-babel-get-src-block-info))
16976 (lang (nth 0 info))
16977 (params (nth 2 info))
16978 (session (cdr (assoc :session params))))
16979 (when (and info session) ;; we are in a source-code block with a session
16981 (intern (concat "org-babel-prep-session:" lang)) session params))))
16982 (cond ;; proceed with `org-edit-special'
16984 (beginning-of-line 1)
16985 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
16986 (find-file (org-trim (match-string 1))))
16987 ((org-edit-src-code))
16988 ((org-edit-fixed-width-region))
16989 ((org-at-table.el-p)
16990 (org-edit-src-code))
16992 (call-interactively 'org-table-edit-formulas))
16993 (t (call-interactively 'ffap))))
16996 (defun org-ctrl-c-ctrl-c (&optional arg)
16997 "Set tags in headline, or update according to changed information at point.
16999 This command does many different things, depending on context:
17001 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
17002 this is what we do.
17004 - If the cursor is on a statistics cookie, update it.
17006 - If the cursor is in a headline, prompt for tags and insert them
17007 into the current line, aligned to `org-tags-column'. When called
17008 with prefix arg, realign all tags in the current buffer.
17010 - If the cursor is in one of the special #+KEYWORD lines, this
17011 triggers scanning the buffer for these lines and updating the
17014 - If the cursor is inside a table, realign the table. This command
17015 works even if the automatic table editor has been turned off.
17017 - If the cursor is on a #+TBLFM line, re-apply the formulas to
17020 - If the cursor is at a footnote reference or definition, jump to
17021 the corresponding definition or references, respectively.
17023 - If the cursor is a the beginning of a dynamic block, update it.
17025 - If the current buffer is a remember buffer, close note and file
17026 it. A prefix argument of 1 files to the default location
17027 without further interaction. A prefix argument of 2 files to
17028 the currently clocking task.
17030 - If the cursor is on a <<<target>>>, update radio targets and corresponding
17031 links in this buffer.
17033 - If the cursor is on a numbered item in a plain list, renumber the
17036 - If the cursor is on a checkbox, toggle it.
17038 - If the cursor is on a code block, evaluate it. The variable
17039 `org-confirm-babel-evaluate' can be used to control prompting
17040 before code block evaluation, by default every code block
17041 evaluation requires confirmation. Code block evaluation can be
17042 inhibited by setting `org-babel-no-eval-on-ctrl-c-ctrl-c'."
17044 (let ((org-enable-table-editor t))
17046 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
17047 org-occur-highlights
17048 org-latex-fragment-image-overlays)
17049 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
17050 (org-remove-occur-highlights)
17051 (org-remove-latex-fragment-image-overlays)
17052 (message "Temporary highlights/overlays removed from current buffer"))
17053 ((and (local-variable-p 'org-finish-function (current-buffer))
17054 (fboundp org-finish-function))
17055 (funcall org-finish-function))
17056 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
17057 ((or (looking-at org-property-start-re)
17058 (org-at-property-p))
17059 (call-interactively 'org-property-action))
17060 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp))
17061 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
17062 (or (org-on-heading-p) (org-at-item-p)))
17063 (call-interactively 'org-update-statistics-cookies))
17064 ((org-on-heading-p) (call-interactively 'org-set-tags))
17065 ((org-at-table.el-p)
17066 (message "Use C-c ' to edit table.el tables"))
17068 (org-table-maybe-eval-formula)
17070 (call-interactively 'org-table-recalculate)
17071 (org-table-maybe-recalculate-line))
17072 (call-interactively 'org-table-align))
17073 ((or (org-footnote-at-reference-p)
17074 (org-footnote-at-definition-p))
17075 (call-interactively 'org-footnote-action))
17076 ((org-at-item-checkbox-p)
17077 (call-interactively 'org-toggle-checkbox)
17078 (org-list-send-list 'maybe))
17081 (call-interactively 'org-toggle-checkbox)
17082 (call-interactively 'org-maybe-renumber-ordered-list))
17083 (org-list-send-list 'maybe))
17084 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
17086 (beginning-of-line 1)
17087 (save-excursion (org-update-dblock)))
17089 (beginning-of-line 1)
17090 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
17092 ((equal (match-string 1) "TBLFM")
17093 ;; Recalculate the table before this line
17095 (beginning-of-line 1)
17096 (skip-chars-backward " \r\n\t")
17097 (if (org-at-table-p)
17098 (org-call-with-arg 'org-table-recalculate (or arg t)))))
17100 (let ((org-inhibit-startup-visibility-stuff t)
17101 (org-startup-align-all-tables nil))
17102 (org-save-outline-visibility 'use-markers (org-mode-restart)))
17103 (message "Local setup has been refreshed"))))
17104 ((org-clock-update-time-maybe))
17105 (t (error "C-c C-c can do nothing useful at this location")))))
17107 (defun org-mode-restart ()
17108 "Restart Org-mode, to scan again for special lines.
17109 Also updates the keyword regular expressions."
17112 (message "Org-mode restarted"))
17114 (defun org-kill-note-or-show-branches ()
17115 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
17117 (if (not org-finish-function)
17120 (call-interactively 'show-branches))
17121 (let ((org-note-abort t))
17122 (funcall org-finish-function))))
17124 (defun org-return (&optional indent)
17125 "Goto next table row or insert a newline.
17126 Calls `org-table-next-row' or `newline', depending on context.
17127 See the individual commands for more information."
17130 ((bobp) (if indent (newline-and-indent) (newline)))
17132 (org-table-justify-field-maybe)
17133 (call-interactively 'org-table-next-row))
17134 ((and org-return-follows-link
17135 (eq (get-text-property (point) 'face) 'org-link))
17136 (call-interactively 'org-open-at-point))
17137 ((and (org-at-heading-p)
17139 (org-re "\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")))
17143 (t (if indent (newline-and-indent) (newline)))))
17145 (defun org-return-indent ()
17146 "Goto next table row or insert a newline and indent.
17147 Calls `org-table-next-row' or `newline-and-indent', depending on
17148 context. See the individual commands for more information."
17152 (defun org-ctrl-c-star ()
17153 "Compute table, or change heading status of lines.
17154 Calls `org-table-recalculate' or `org-toggle-heading',
17155 depending on context."
17159 (call-interactively 'org-table-recalculate))
17161 ;; Convert all lines in region to list items
17162 (call-interactively 'org-toggle-heading))))
17164 (defun org-ctrl-c-minus ()
17165 "Insert separator line in table or modify bullet status of line.
17166 Also turns a plain line or a region of lines into list items.
17167 Calls `org-table-insert-hline', `org-toggle-item', or
17168 `org-cycle-list-bullet', depending on context."
17172 (call-interactively 'org-table-insert-hline))
17173 ((org-region-active-p)
17174 (call-interactively 'org-toggle-item))
17176 (call-interactively 'org-cycle-list-bullet))
17178 (call-interactively 'org-toggle-item))))
17180 (defun org-toggle-item ()
17181 "Convert headings or normal lines to items, items to normal lines.
17182 If there is no active region, only the current line is considered.
17184 If the first line in the region is a headline, convert all headlines to items.
17186 If the first line in the region is an item, convert all items to normal lines.
17188 If the first line is normal text, add an item bullet to each line."
17190 (let (l2 l beg end)
17191 (if (org-region-active-p)
17192 (setq beg (region-beginning) end (region-end))
17193 (setq beg (point-at-bol)
17194 end (min (1+ (point-at-eol)) (point-max))))
17197 (setq l2 (org-current-line))
17199 (beginning-of-line 1)
17200 (setq l (1- (org-current-line)))
17201 (if (org-at-item-p)
17202 ;; We already have items, de-itemize
17203 (while (< (setq l (1+ l)) l2)
17204 (when (org-at-item-p)
17205 (goto-char (match-beginning 2))
17206 (delete-region (match-beginning 2) (match-end 2))
17207 (and (looking-at "[ \t]+") (replace-match "")))
17208 (beginning-of-line 2))
17209 (if (org-on-heading-p)
17210 ;; Headings, convert to items
17211 (while (< (setq l (1+ l)) l2)
17212 (if (looking-at org-outline-regexp)
17213 (replace-match "- " t t))
17214 (beginning-of-line 2))
17215 ;; normal lines, turn them into items
17216 (while (< (setq l (1+ l)) l2)
17217 (unless (org-at-item-p)
17218 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17219 (replace-match "\\1- \\2")))
17220 (beginning-of-line 2)))))))
17222 (defun org-toggle-heading (&optional nstars)
17223 "Convert headings to normal text, or items or text to headings.
17224 If there is no active region, only the current line is considered.
17226 If the first line is a heading, remove the stars from all headlines
17229 If the first line is a plain list item, turn all plain list items
17232 If the first line is a normal line, turn each and every line in the
17233 region into a heading.
17235 When converting a line into a heading, the number of stars is chosen
17236 such that the lines become children of the current entry. However,
17237 when a prefix argument is given, its value determines the number of
17240 (let (l2 l itemp 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-on-heading-p)
17252 ;; We already have headlines, de-star them
17253 (while (< (setq l (1+ l)) l2)
17254 (when (org-on-heading-p t)
17255 (and (looking-at outline-regexp) (replace-match "")))
17256 (beginning-of-line 2))
17257 (setq itemp (org-at-item-p))
17260 (make-string (prefix-numeric-value current-prefix-arg)
17263 (if (re-search-backward org-complex-heading-regexp nil t)
17264 (match-string 1) ""))))
17265 (add-stars (cond (nstars "")
17266 ((equal stars "") "*")
17267 (org-odd-levels-only "**")
17269 (rpl (concat stars add-stars " ")))
17270 (while (< (setq l (1+ l)) l2)
17272 (and (org-at-item-p) (replace-match rpl t t))
17273 (unless (org-on-heading-p)
17274 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
17275 (replace-match (concat rpl (match-string 2))))))
17276 (beginning-of-line 2)))))))
17278 (defun org-meta-return (&optional arg)
17279 "Insert a new heading or wrap a region in a table.
17280 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
17281 See the individual commands for more information."
17284 ((run-hook-with-args-until-success 'org-metareturn-hook))
17286 (call-interactively 'org-table-wrap-region))
17287 (t (call-interactively 'org-insert-heading))))
17291 ;; Define the Org-mode menus
17292 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
17294 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
17295 ["Next Field" org-cycle (org-at-table-p)]
17296 ["Previous Field" org-shifttab (org-at-table-p)]
17297 ["Next Row" org-return (org-at-table-p)]
17299 ["Blank Field" org-table-blank-field (org-at-table-p)]
17300 ["Edit Field" org-table-edit-field (org-at-table-p)]
17301 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
17304 ["Move Column Left" org-metaleft (org-at-table-p)]
17305 ["Move Column Right" org-metaright (org-at-table-p)]
17306 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
17307 ["Insert Column" org-shiftmetaright (org-at-table-p)])
17309 ["Move Row Up" org-metaup (org-at-table-p)]
17310 ["Move Row Down" org-metadown (org-at-table-p)]
17311 ["Delete Row" org-shiftmetaup (org-at-table-p)]
17312 ["Insert Row" org-shiftmetadown (org-at-table-p)]
17313 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
17315 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
17317 ["Copy Rectangle" org-copy-special (org-at-table-p)]
17318 ["Cut Rectangle" org-cut-special (org-at-table-p)]
17319 ["Paste Rectangle" org-paste-special (org-at-table-p)]
17320 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
17323 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
17324 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
17325 ["Edit Formulas" org-edit-special (org-at-table-p)]
17327 ["Recalculate line" org-table-recalculate (org-at-table-p)]
17328 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
17329 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
17331 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
17333 ["Sum Column/Rectangle" org-table-sum
17334 (or (org-at-table-p) (org-region-active-p))]
17335 ["Which Column?" org-table-current-column (org-at-table-p)])
17337 org-table-toggle-formula-debugger
17338 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
17339 ["Show Col/Row Numbers"
17340 org-table-toggle-coordinate-overlays
17342 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
17344 ["Create" org-table-create (and (not (org-at-table-p))
17345 org-enable-table-editor)]
17346 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
17347 ["Import from File" org-table-import (not (org-at-table-p))]
17348 ["Export to File" org-table-export (org-at-table-p)]
17350 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
17352 (easy-menu-define org-org-menu org-mode-map "Org menu"
17355 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
17356 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
17357 ["Sparse Tree..." org-sparse-tree t]
17358 ["Reveal Context" org-reveal t]
17359 ["Show All" show-all t]
17361 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
17363 ["New Heading" org-insert-heading t]
17364 ("Navigate Headings"
17365 ["Up" outline-up-heading t]
17366 ["Next" outline-next-visible-heading t]
17367 ["Previous" outline-previous-visible-heading t]
17368 ["Next Same Level" outline-forward-same-level t]
17369 ["Previous Same Level" outline-backward-same-level t]
17371 ["Jump" org-goto t])
17373 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
17374 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
17376 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
17377 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
17378 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
17380 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
17382 ["Promote Heading" org-metaleft (not (org-at-table-p))]
17383 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
17384 ["Demote Heading" org-metaright (not (org-at-table-p))]
17385 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
17387 ["Sort Region/Children" org-sort (not (org-at-table-p))]
17389 ["Convert to odd levels" org-convert-to-odd-levels t]
17390 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
17392 ["Emphasis..." org-emphasize t]
17393 ["Edit Source Example" org-edit-special t]
17395 ["Footnote new/jump" org-footnote-action t]
17396 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
17398 ["Archive (default method)" org-archive-subtree-default t]
17400 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
17401 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
17402 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
17406 ["Store Link (Global)" org-store-link t]
17407 ["Find existing link to here" org-occur-link-in-agenda-files t]
17408 ["Insert Link" org-insert-link t]
17409 ["Follow Link" org-open-at-point t]
17411 ["Next link" org-next-link t]
17412 ["Previous link" org-previous-link t]
17414 ["Descriptive Links"
17415 (progn (add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
17417 :selected (member '(org-link) buffer-invisibility-spec)]
17420 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
17422 :selected (not (member '(org-link) buffer-invisibility-spec))])
17425 ["TODO/DONE/-" org-todo t]
17427 ["Next keyword" org-shiftright (org-on-heading-p)]
17428 ["Previous keyword" org-shiftleft (org-on-heading-p)]
17429 ["Complete Keyword" org-complete (assq :todo-keyword (org-context))]
17430 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))]
17431 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-on-heading-p))])
17432 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
17433 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
17435 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
17436 :selected org-enforce-todo-dependencies :style toggle :active t]
17437 "Settings for tree at point"
17438 ["Do Children sequentially" org-toggle-ordered-property :style radio
17439 :selected (ignore-errors (org-entry-get nil "ORDERED"))
17440 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17441 ["Do Children parallel" org-toggle-ordered-property :style radio
17442 :selected (ignore-errors (not (org-entry-get nil "ORDERED")))
17443 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
17445 ["Set Priority" org-priority t]
17446 ["Priority Up" org-shiftup t]
17447 ["Priority Down" org-shiftdown t]
17449 ["Get news from all feeds" org-feed-update-all t]
17450 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
17451 ["Customize feeds" (customize-variable 'org-feed-alist) t])
17452 ("TAGS and Properties"
17453 ["Set Tags" org-set-tags-command t]
17454 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
17456 ["Set property" org-set-property t]
17457 ["Column view of properties" org-columns t]
17458 ["Insert Column View DBlock" org-insert-columns-dblock t])
17459 ("Dates and Scheduling"
17460 ["Timestamp" org-time-stamp t]
17461 ["Timestamp (inactive)" org-time-stamp-inactive t]
17463 ["1 Day Later" org-shiftright t]
17464 ["1 Day Earlier" org-shiftleft t]
17465 ["1 ... Later" org-shiftup t]
17466 ["1 ... Earlier" org-shiftdown t])
17467 ["Compute Time Range" org-evaluate-time-range t]
17468 ["Schedule Item" org-schedule t]
17469 ["Deadline" org-deadline t]
17471 ["Custom time format" org-toggle-time-stamp-overlays
17472 :style radio :selected org-display-custom-times]
17474 ["Goto Calendar" org-goto-calendar t]
17475 ["Date from Calendar" org-date-from-calendar t]
17477 ["Start/Restart Timer" org-timer-start t]
17478 ["Pause/Continue Timer" org-timer-pause-or-continue t]
17479 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
17480 ["Insert Timer String" org-timer t]
17481 ["Insert Timer Item" org-timer-item t])
17483 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
17484 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
17485 ["Clock out" org-clock-out t]
17486 ["Clock cancel" org-clock-cancel t]
17488 ["Mark as default task" org-clock-mark-default-task t]
17489 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
17490 ["Goto running clock" org-clock-goto t]
17492 ["Display times" org-clock-display t]
17493 ["Create clock table" org-clock-report t]
17495 ["Record DONE time"
17496 (progn (setq org-log-done (not org-log-done))
17497 (message "Switching to %s will %s record a timestamp"
17498 (car org-done-keywords)
17499 (if org-log-done "automatically" "not")))
17500 :style toggle :selected org-log-done])
17502 ["Agenda Command..." org-agenda t]
17503 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
17504 ("File List for Agenda")
17505 ("Special views current file"
17506 ["TODO Tree" org-show-todo-tree t]
17507 ["Check Deadlines" org-check-deadlines t]
17508 ["Timeline" org-timeline t]
17509 ["Tags/Property tree" org-match-sparse-tree t])
17511 ["Export/Publish..." org-export t]
17513 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
17514 :selected org-cdlatex-mode]
17515 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
17516 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
17517 ["Modify math symbol" org-cdlatex-math-modify
17518 (org-inside-LaTeX-fragment-p)]
17519 ["Insert citation" org-reftex-citation t]
17521 ["Export LaTeX fragments as images"
17522 (if (featurep 'org-exp)
17523 (setq org-export-with-LaTeX-fragments
17524 (not org-export-with-LaTeX-fragments))
17525 (require 'org-exp))
17526 :style toggle :selected (and (boundp 'org-export-with-LaTeX-fragments)
17527 org-export-with-LaTeX-fragments)]
17529 ["Template for BEAMER" org-insert-beamer-options-template t])
17532 ["Push Files and Views" org-mobile-push t]
17533 ["Get Captured and Flagged" org-mobile-pull t]
17534 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
17536 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
17539 ["Show Version" org-version t]
17540 ["Info Documentation" org-info t])
17542 ["Browse Org Group" org-customize t]
17544 ["Expand This Menu" org-create-customize-menu
17545 (fboundp 'customize-menu-create)])
17546 ["Send bug report" org-submit-bug-report t]
17549 ["Refresh setup current buffer" org-mode-restart t]
17550 ["Reload Org (after update)" org-reload t]
17551 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
17554 (defun org-info (&optional node)
17555 "Read documentation for Org-mode in the info system.
17556 With optional NODE, go directly to that node."
17558 (info (format "(org)%s" (or node ""))))
17561 (defun org-submit-bug-report ()
17562 "Submit a bug report on Org-mode via mail.
17564 Don't hesitate to report any problems or inaccurate documentation.
17566 If you don't have setup sending mail from (X)Emacs, please copy the
17567 output buffer into your mail program, as it gives us important
17568 information about your Org-mode version and configuration."
17570 (require 'reporter)
17571 (org-load-modules-maybe)
17572 (org-require-autoloaded-modules)
17573 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
17574 (reporter-submit-bug-report
17575 "emacs-orgmode@gnu.org"
17578 (save-window-excursion
17579 (switch-to-buffer (get-buffer-create "*Warn about privacy*"))
17580 (delete-other-windows)
17582 (insert "You are about to submit a bug report to the Org-mode mailing list.
17584 We would like to add your full Org-mode and Outline configuration to the
17585 bug report. This greatly simplifies the work of the maintainer and
17586 other experts on the mailing list.
17588 HOWEVER, some variables you have customized may contain private
17589 information. The names of customers, colleagues, or friends, might
17590 appear in the form of file names, tags, todo states, or search strings.
17591 If you answer yes to the prompt, you might want to check and remove
17592 such private information before sending the email.")
17593 (add-text-properties (point-min) (point-max) '(face org-warning))
17594 (when (yes-or-no-p "Include your Org-mode configuration ")
17598 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
17599 (or (and (symbol-value v)
17600 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
17602 (get v 'custom-type) (get v 'standard-value)
17603 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
17605 (kill-buffer (get-buffer "*Warn about privacy*"))
17608 "Remember to cover the basics, that is, what you expected to happen and
17609 what in fact did happen. You don't know how to make a good report? See
17611 http://orgmode.org/manual/Feedback.html#Feedback
17613 Your bug report will be posted to the Org-mode mailing list.
17614 ------------------------------------------------------------------------")
17616 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
17617 (replace-match "\\1Bug: \\3 [\\2]")))))
17620 (defun org-install-agenda-files-menu ()
17621 (let ((bl (buffer-list)))
17624 (set-buffer (pop bl))
17625 (if (org-mode-p) (setq bl nil)))
17628 '("Org") "File List for Agenda"
17631 ["Edit File List" (org-edit-agenda-file-list) t]
17632 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
17633 ["Remove Current File from List" org-remove-file t]
17634 ["Cycle through agenda files" org-cycle-agenda-files t]
17635 ["Occur in all agenda files" org-occur-in-agenda-files t]
17637 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
17642 (defun org-require-autoloaded-modules ()
17645 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
17646 org-docbook org-exp org-html org-icalendar
17648 org-publish org-remember org-table
17649 org-timer org-xoxo)))
17652 (defun org-reload (&optional uncompiled)
17653 "Reload all org lisp files.
17654 With prefix arg UNCOMPILED, load the uncompiled versions."
17656 (require 'find-func)
17657 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
17658 (dir-org (file-name-directory (org-find-library-name "org")))
17659 (dir-org-contrib (ignore-errors
17660 (file-name-directory
17661 (org-find-library-name "org-contribdir"))))
17663 (mapcar (lambda (el) (concat "ob" (when el (format "-%s" el)) ".el"))
17664 (append (list nil "comint" "eval" "exp" "keys"
17665 "lob" "ref" "table" "tangle")
17669 (when (cdr lang) (symbol-name (car lang))))
17670 org-babel-load-languages)))))
17672 (append (directory-files dir-org t file-re)
17674 (and dir-org-contrib
17675 (directory-files dir-org-contrib t file-re))))
17676 (remove-re (concat (if (featurep 'xemacs)
17677 "org-colview" "org-colview-xemacs")
17679 (setq files (mapcar 'file-name-sans-extension files))
17680 (setq files (mapcar
17681 (lambda (x) (if (string-match remove-re x) nil x))
17683 (setq files (delq nil files))
17686 (when (featurep (intern (file-name-nondirectory f)))
17687 (if (and (not uncompiled)
17688 (file-exists-p (concat f ".elc")))
17689 (load (concat f ".elc") nil nil t)
17690 (load (concat f ".el") nil nil t))))
17695 (defun org-customize ()
17696 "Call the customize function with org as argument."
17698 (org-load-modules-maybe)
17699 (org-require-autoloaded-modules)
17700 (customize-browse 'org))
17702 (defun org-create-customize-menu ()
17703 "Create a full customization menu for Org-mode, insert it into the menu."
17705 (org-load-modules-maybe)
17706 (org-require-autoloaded-modules)
17707 (if (fboundp 'customize-menu-create)
17710 '("Org") "Customize"
17711 `(["Browse Org group" org-customize t]
17713 ,(customize-menu-create 'org)
17714 ["Set" Custom-set t]
17715 ["Save" Custom-save t]
17716 ["Reset to Current" Custom-reset-current t]
17717 ["Reset to Saved" Custom-reset-saved t]
17718 ["Reset to Standard Settings" Custom-reset-standard t]))
17719 (message "\"Org\"-menu now contains full customization menu"))
17720 (error "Cannot expand menu (outdated version of cus-edit.el)")))
17722 ;;;; Miscellaneous stuff
17724 ;;; Generally useful functions
17726 (defun org-get-at-bol (property)
17727 "Get text property PROPERTY at beginning of line."
17728 (get-text-property (point-at-bol) property))
17730 (defun org-find-text-property-in-string (prop s)
17731 "Return the first non-nil value of property PROP in string S."
17732 (or (get-text-property 0 prop s)
17733 (get-text-property (or (next-single-property-change 0 prop s) 0)
17736 (defun org-display-warning (message) ;; Copied from Emacs-Muse
17737 "Display the given MESSAGE as a warning."
17738 (if (fboundp 'display-warning)
17739 (display-warning 'org message
17740 (if (featurep 'xemacs) 'warning :warning))
17741 (let ((buf (get-buffer-create "*Org warnings*")))
17742 (with-current-buffer buf
17743 (goto-char (point-max))
17744 (insert "Warning (Org): " message)
17747 (display-buffer buf)
17750 (defun org-in-commented-line ()
17751 "Is point in a line starting with `#'?"
17752 (equal (char-after (point-at-bol)) ?#))
17754 (defun org-in-indented-comment-line ()
17755 "Is point in a line starting with `#' after some white space?"
17758 (goto-char (point-at-bol))
17759 (looking-at "[ \t]*#"))))
17761 (defun org-in-verbatim-emphasis ()
17763 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
17765 (defun org-goto-marker-or-bmk (marker &optional bookmark)
17766 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
17767 (if (and marker (marker-buffer marker)
17768 (buffer-live-p (marker-buffer marker)))
17770 (switch-to-buffer (marker-buffer marker))
17771 (if (or (> marker (point-max)) (< marker (point-min)))
17774 (org-show-context 'org-goto))
17776 (bookmark-jump bookmark)
17777 (error "Cannot find location"))))
17779 (defun org-quote-csv-field (s)
17780 "Quote field for inclusion in CSV material."
17781 (if (string-match "[\",]" s)
17782 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
17785 (defun org-plist-delete (plist property)
17786 "Delete PROPERTY from PLIST.
17787 This is in contrast to merely setting it to 0."
17790 (if (not (eq property (car plist)))
17791 (setq p (plist-put p (car plist) (nth 1 plist))))
17792 (setq plist (cddr plist)))
17795 (defun org-force-self-insert (N)
17796 "Needed to enforce self-insert under remapping."
17798 (self-insert-command N))
17800 (defun org-string-width (s)
17801 "Compute width of string, ignoring invisible characters.
17802 This ignores character with invisibility property `org-link', and also
17803 characters with property `org-cwidth', because these will become invisible
17804 upon the next fontification round."
17806 (when (or (eq t buffer-invisibility-spec)
17807 (assq 'org-link buffer-invisibility-spec))
17808 (while (setq b (text-property-any 0 (length s)
17809 'invisible 'org-link s))
17810 (setq s (concat (substring s 0 b)
17811 (substring s (or (next-single-property-change
17812 b 'invisible s) (length s)))))))
17813 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
17814 (setq s (concat (substring s 0 b)
17815 (substring s (or (next-single-property-change
17816 b 'org-cwidth s) (length s))))))
17817 (setq l (string-width s) b -1)
17818 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
17819 (setq l (- l (get-text-property b 'org-dwidth-n s))))
17822 (defun org-get-indentation (&optional line)
17823 "Get the indentation of the current line, interpreting tabs.
17824 When LINE is given, assume it represents a line and compute its indentation."
17826 (if (string-match "^ *" (org-remove-tabs line))
17829 (beginning-of-line 1)
17830 (skip-chars-forward " \t")
17831 (current-column))))
17833 (defun org-remove-tabs (s &optional width)
17834 "Replace tabulators in S with spaces.
17835 Assumes that s is a single line, starting in column 0."
17836 (setq width (or width tab-width))
17837 (while (string-match "\t" s)
17838 (setq s (replace-match
17840 (- (* width (/ (+ (match-beginning 0) width) width))
17841 (match-beginning 0)) ?\ )
17845 (defun org-fix-indentation (line ind)
17846 "Fix indentation in LINE.
17847 IND is a cons cell with target and minimum indentation.
17848 If the current indentation in LINE is smaller than the minimum,
17849 leave it alone. If it is larger than ind, set it to the target."
17850 (let* ((l (org-remove-tabs line))
17851 (i (org-get-indentation l))
17852 (i1 (car ind)) (i2 (cdr ind)))
17853 (if (>= i i2) (setq l (substring line i2)))
17855 (concat (make-string i1 ?\ ) l)
17858 (defun org-remove-indentation (code &optional n)
17859 "Remove the maximum common indentation from the lines in CODE.
17860 N may optionally be the number of spaces to remove."
17863 (org-do-remove-indentation n)
17866 (defun org-do-remove-indentation (&optional n)
17867 "Remove the maximum common indentation from the buffer."
17868 (untabify (point-min) (point-max))
17869 (let ((min 10000) re)
17872 (goto-char (point-min))
17873 (while (re-search-forward "^ *[^ \n]" nil t)
17874 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
17875 (unless (or (= min 0) (= min 10000))
17876 (setq re (format "^ \\{%d\\}" min))
17877 (goto-char (point-min))
17878 (while (re-search-forward re nil t)
17883 (defun org-fill-template (template alist)
17884 "Find each %key of ALIST in TEMPLATE and replace it."
17885 (let ((case-fold-search nil)
17887 (setq alist (sort (copy-sequence alist)
17888 (lambda (a b) (< (length (car a)) (length (car b))))))
17889 (while (setq entry (pop alist))
17891 (replace-regexp-in-string
17892 (concat "%" (regexp-quote (car entry)))
17893 (cdr entry) template t t)))
17896 (defun org-base-buffer (buffer)
17897 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
17900 (or (buffer-base-buffer buffer)
17903 (defun org-trim (s)
17904 "Remove whitespace at beginning and end of string."
17905 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
17906 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
17909 (defun org-wrap (string &optional width lines)
17910 "Wrap string to either a number of lines, or a width in characters.
17911 If WIDTH is non-nil, the string is wrapped to that width, however many lines
17912 that costs. If there is a word longer than WIDTH, the text is actually
17913 wrapped to the length of that word.
17914 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
17915 many lines, whatever width that takes.
17916 The return value is a list of lines, without newlines at the end."
17917 (let* ((words (org-split-string string "[ \t\n]+"))
17918 (maxword (apply 'max (mapcar 'org-string-width words)))
17921 (org-do-wrap words (max maxword width)))
17924 (setq ll (org-do-wrap words maxword))
17925 (if (<= (length ll) lines)
17928 (while (> (length ll) lines)
17930 (setq ll (org-do-wrap words w)))
17932 (t (error "Cannot wrap this")))))
17934 (defun org-do-wrap (words width)
17935 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
17938 (setq line (pop words))
17939 (while (and words (< (+ (length line) (length (car words))) width))
17940 (setq line (concat line " " (pop words))))
17941 (setq lines (push line lines)))
17944 (defun org-split-string (string &optional separators)
17945 "Splits STRING into substrings at SEPARATORS.
17946 No empty strings are returned if there are matches at the beginning
17947 and end of string."
17948 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
17952 (while (and (string-match rexp string
17954 (= start (match-beginning 0))
17955 (< start (length string)))
17957 (< (match-beginning 0) (length string)))
17959 (or (eq (match-beginning 0) 0)
17960 (and (eq (match-beginning 0) (match-end 0))
17961 (eq (match-beginning 0) start))
17963 (cons (substring string start (match-beginning 0))
17965 (setq start (match-end 0)))
17966 (or (eq start (length string))
17968 (cons (substring string start)
17972 (defun org-quote-vert (s)
17973 "Replace \"|\" with \"\\vert\"."
17974 (while (string-match "|" s)
17975 (setq s (replace-match "\\vert" t t s)))
17978 (defun org-uuidgen-p (s)
17979 "Is S an ID created by UUIDGEN?"
17980 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
17982 (defun org-context ()
17983 "Return a list of contexts of the current cursor position.
17984 If several contexts apply, all are returned.
17985 Each context entry is a list with a symbol naming the context, and
17986 two positions indicating start and end of the context. Possible
17989 :headline anywhere in a headline
17990 :headline-stars on the leading stars in a headline
17991 :todo-keyword on a TODO keyword (including DONE) in a headline
17992 :tags on the TAGS in a headline
17993 :priority on the priority cookie in a headline
17994 :item on the first line of a plain list item
17995 :item-bullet on the bullet/number of a plain list item
17996 :checkbox on the checkbox in a plain list item
17997 :table in an org-mode table
17998 :table-special on a special filed in a table
17999 :table-table in a table.el table
18000 :link on a hyperlink
18001 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
18002 :target on a <<target>>
18003 :radio-target on a <<<radio-target>>>
18004 :latex-fragment on a LaTeX fragment
18005 :latex-preview on a LaTeX fragment with overlayed preview image
18007 This function expects the position to be visible because it uses font-lock
18008 faces as a help to recognize the following contexts: :table-special, :link,
18010 (let* ((f (get-text-property (point) 'face))
18011 (faces (if (listp f) f (list f)))
18012 (p (point)) clist o)
18013 ;; First the large context
18015 ((org-on-heading-p t)
18016 (push (list :headline (point-at-bol) (point-at-eol)) clist)
18018 (beginning-of-line 1)
18019 (looking-at org-todo-line-tags-regexp))
18020 (push (org-point-in-group p 1 :headline-stars) clist)
18021 (push (org-point-in-group p 2 :todo-keyword) clist)
18022 (push (org-point-in-group p 4 :tags) clist))
18024 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
18025 (if (looking-at "\\[#[A-Z0-9]\\]")
18026 (push (org-point-in-group p 0 :priority) clist)))
18029 (push (org-point-in-group p 2 :item-bullet) clist)
18030 (push (list :item (point-at-bol)
18031 (save-excursion (org-end-of-item) (point)))
18033 (and (org-at-item-checkbox-p)
18034 (push (org-point-in-group p 0 :checkbox) clist)))
18037 (push (list :table (org-table-begin) (org-table-end)) clist)
18038 (if (memq 'org-formula faces)
18039 (push (list :table-special
18040 (previous-single-property-change p 'face)
18041 (next-single-property-change p 'face)) clist)))
18042 ((org-at-table-p 'any)
18043 (push (list :table-table) clist)))
18046 ;; Now the small context
18048 ((org-at-timestamp-p)
18049 (push (org-point-in-group p 0 :timestamp) clist))
18050 ((memq 'org-link faces)
18052 (previous-single-property-change p 'face)
18053 (next-single-property-change p 'face)) clist))
18054 ((memq 'org-special-keyword faces)
18055 (push (list :keyword
18056 (previous-single-property-change p 'face)
18057 (next-single-property-change p 'face)) clist))
18059 (push (org-point-in-group p 0 :target) clist)
18060 (goto-char (1- (match-beginning 0)))
18061 (if (looking-at org-radio-target-regexp)
18062 (push (org-point-in-group p 0 :radio-target) clist))
18064 ((setq o (car (delq nil
18067 (if (memq x org-latex-fragment-image-overlays) x))
18068 (overlays-at (point))))))
18069 (push (list :latex-fragment
18070 (overlay-start o) (overlay-end o)) clist)
18071 (push (list :latex-preview
18072 (overlay-start o) (overlay-end o)) clist))
18073 ((org-inside-LaTeX-fragment-p)
18074 ;; FIXME: positions wrong.
18075 (push (list :latex-fragment (point) (point)) clist)))
18077 (setq clist (nreverse (delq nil clist)))
18080 ;; FIXME: Compare with at-regexp-p Do we need both?
18081 (defun org-in-regexp (re &optional nlines visually)
18082 "Check if point is inside a match of regexp.
18083 Normally only the current line is checked, but you can include NLINES extra
18084 lines both before and after point into the search.
18085 If VISUALLY is set, require that the cursor is not after the match but
18086 really on, so that the block visually is on the match."
18088 (let ((pos (point))
18089 (eol (point-at-eol (+ 1 (or nlines 0))))
18090 (inc (if visually 1 0)))
18092 (beginning-of-line (- 1 (or nlines 0)))
18093 (while (re-search-forward re eol t)
18094 (if (and (<= (match-beginning 0) pos)
18095 (>= (+ inc (match-end 0)) pos))
18096 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
18098 (defun org-at-regexp-p (regexp)
18099 "Is point inside a match of REGEXP in the current line?"
18102 (let ((pos (point)) (end (point-at-eol)))
18103 (beginning-of-line 1)
18104 (while (re-search-forward regexp end t)
18105 (if (and (<= (match-beginning 0) pos)
18106 (>= (match-end 0) pos))
18110 (defun org-in-regexps-block-p (start-re end-re)
18111 "Return t if the current point is between matches of START-RE and END-RE.
18112 This will also return to if point is on one of the two matches."
18116 (and (or (org-at-regexp-p start-re)
18117 (re-search-backward start-re nil t))
18118 (re-search-forward end-re nil t)
18121 (defun org-occur-in-agenda-files (regexp &optional nlines)
18122 "Call `multi-occur' with buffers for all agenda files."
18123 (interactive "sOrg-files matching: \np")
18124 (let* ((files (org-agenda-files))
18125 (tnames (mapcar 'file-truename files))
18126 (extra org-agenda-text-search-extra-files)
18128 (when (eq (car extra) 'agenda-archives)
18129 (setq extra (cdr extra))
18130 (setq files (org-add-archive-files files)))
18131 (while (setq f (pop extra))
18132 (unless (member (file-truename f) tnames)
18133 (add-to-list 'files f 'append)
18134 (add-to-list 'tnames (file-truename f) 'append)))
18136 (mapcar (lambda (x)
18137 (with-current-buffer
18138 (or (get-file-buffer x) (find-file-noselect x))
18144 (if (boundp 'occur-mode-find-occurrence-hook)
18146 (add-hook 'occur-mode-find-occurrence-hook
18151 (defadvice occur-mode-goto-occurrence
18152 (after org-occur-reveal activate)
18153 (and (org-mode-p) (org-reveal)))
18154 (defadvice occur-mode-goto-occurrence-other-window
18155 (after org-occur-reveal activate)
18156 (and (org-mode-p) (org-reveal)))
18157 (defadvice occur-mode-display-occurrence
18158 (after org-occur-reveal activate)
18160 (let ((pos (occur-mode-find-occurrence)))
18161 (with-current-buffer (marker-buffer pos)
18166 (defun org-occur-link-in-agenda-files ()
18167 "Create a link and search for it in the agendas.
18168 The link is not stored in `org-stored-links', it is just created
18169 for the search purpose."
18171 (let ((link (condition-case nil
18172 (org-store-link nil)
18173 (error "Unable to create a link to here"))))
18174 (org-occur-in-agenda-files (regexp-quote link))))
18176 (defun org-uniquify (list)
18177 "Remove duplicate elements from LIST."
18179 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
18182 (defun org-delete-all (elts list)
18183 "Remove all elements in ELTS from LIST."
18185 (setq list (delete (pop elts) list)))
18188 (defun org-count (cl-item cl-seq)
18189 "Count the number of occurrences of ITEM in SEQ.
18190 Taken from `count' in cl-seq.el with all keyword arguments removed."
18191 (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0) cl-x)
18192 (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
18193 (while (< cl-start cl-end)
18194 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
18195 (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
18196 (setq cl-start (1+ cl-start)))
18199 (defun org-remove-if (predicate seq)
18200 "Remove everything from SEQ that fulfills PREDICATE."
18204 (if (not (funcall predicate e)) (push e res)))
18207 (defun org-remove-if-not (predicate seq)
18208 "Remove everything from SEQ that does not fulfill PREDICATE."
18212 (if (funcall predicate e) (push e res)))
18215 (defun org-back-over-empty-lines ()
18216 "Move backwards over whitespace, to the beginning of the first empty line.
18217 Returns the number of empty lines passed."
18218 (let ((pos (point)))
18219 (skip-chars-backward " \t\n\r")
18220 (beginning-of-line 2)
18221 (goto-char (min (point) pos))
18222 (count-lines (point) pos)))
18224 (defun org-skip-whitespace ()
18225 (skip-chars-forward " \t\n\r"))
18227 (defun org-point-in-group (point group &optional context)
18228 "Check if POINT is in match-group GROUP.
18229 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
18230 match. If the match group does not exist or point is not inside it,
18232 (and (match-beginning group)
18233 (>= point (match-beginning group))
18234 (<= point (match-end group))
18236 (list context (match-beginning group) (match-end group))
18239 (defun org-switch-to-buffer-other-window (&rest args)
18240 "Switch to buffer in a second window on the current frame.
18241 In particular, do not allow pop-up frames.
18242 Returns the newly created buffer."
18243 (let (pop-up-frames special-display-buffer-names special-display-regexps
18244 special-display-function)
18245 (apply 'switch-to-buffer-other-window args)))
18247 (defun org-combine-plists (&rest plists)
18248 "Create a single property list from all plists in PLISTS.
18249 The process starts by copying the first list, and then setting properties
18250 from the other lists. Settings in the last list are the most significant
18251 ones and overrule settings in the other lists."
18252 (let ((rtn (copy-sequence (pop plists)))
18255 (setq ls (pop plists))
18257 (setq p (pop ls) v (pop ls))
18258 (setq rtn (plist-put rtn p v))))
18261 (defun org-move-line-down (arg)
18262 "Move the current line down. With prefix argument, move it past ARG lines."
18264 (let ((col (current-column))
18266 (beginning-of-line 1) (setq beg (point))
18267 (beginning-of-line 2) (setq end (point))
18268 (beginning-of-line (+ 1 arg))
18269 (setq pos (move-marker (make-marker) (point)))
18270 (insert (delete-and-extract-region beg end))
18272 (org-move-to-column col)))
18274 (defun org-move-line-up (arg)
18275 "Move the current line up. With prefix argument, move it past ARG lines."
18277 (let ((col (current-column))
18279 (beginning-of-line 1) (setq beg (point))
18280 (beginning-of-line 2) (setq end (point))
18281 (beginning-of-line (- arg))
18282 (setq pos (move-marker (make-marker) (point)))
18283 (insert (delete-and-extract-region beg end))
18285 (org-move-to-column col)))
18287 (defun org-replace-escapes (string table)
18288 "Replace %-escapes in STRING with values in TABLE.
18289 TABLE is an association list with keys like \"%a\" and string values.
18290 The sequences in STRING may contain normal field width and padding information,
18291 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
18292 so values can contain further %-escapes if they are define later in TABLE."
18293 (let ((tbl (copy-alist table))
18294 (case-fold-search nil)
18297 (while (setq e (pop tbl))
18298 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
18299 (when (and (cdr e) (string-match re (cdr e)))
18300 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
18302 (add-text-properties 0 3 (list 'sref sref) safe)
18303 (setcdr e (replace-match safe t t (cdr e)))))
18304 (while (string-match re string)
18305 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
18307 (setq string (replace-match rpl t t string))))
18308 (while (setq pchg (next-property-change pchg string))
18309 (let ((sref (get-text-property pchg 'sref string)))
18310 (when (and sref (string-match "SREF" string pchg))
18311 (setq string (replace-match sref t t string)))))
18314 (defun org-sublist (list start end)
18315 "Return a section of LIST, from START to END.
18316 Counting starts at 1."
18317 (let (rtn (c start))
18318 (setq list (nthcdr (1- start) list))
18319 (while (and list (<= c end))
18320 (push (pop list) rtn)
18324 (defun org-find-base-buffer-visiting (file)
18325 "Like `find-buffer-visiting' but always return the base buffer and
18326 not an indirect buffer."
18327 (let ((buf (or (get-file-buffer file)
18328 (find-buffer-visiting file))))
18330 (or (buffer-base-buffer buf) buf)
18333 (defun org-image-file-name-regexp (&optional extensions)
18334 "Return regexp matching the file names of images.
18335 If EXTENSIONS is given, only match these."
18336 (if (and (not extensions) (fboundp 'image-file-name-regexp))
18337 (image-file-name-regexp)
18338 (let ((image-file-name-extensions
18340 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
18341 "xbm" "xpm" "pbm" "pgm" "ppm"))))
18343 (regexp-opt (nconc (mapcar 'upcase
18344 image-file-name-extensions)
18345 image-file-name-extensions)
18349 (defun org-file-image-p (file &optional extensions)
18350 "Return non-nil if FILE is an image."
18352 (string-match (org-image-file-name-regexp extensions) file)))
18354 (defun org-get-cursor-date ()
18355 "Return the date at cursor in as a time.
18356 This works in the calendar and in the agenda, anywhere else it just
18357 returns the current time."
18358 (let (date day defd)
18360 ((eq major-mode 'calendar-mode)
18361 (setq date (calendar-cursor-to-date)
18362 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
18363 ((eq major-mode 'org-agenda-mode)
18364 (setq day (get-text-property (point) 'day))
18366 (setq date (calendar-gregorian-from-absolute day)
18367 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
18369 (or defd (current-time))))
18371 (defvar org-agenda-action-marker (make-marker)
18372 "Marker pointing to the entry for the next agenda action.")
18374 (defun org-mark-entry-for-agenda-action ()
18375 "Mark the current entry as target of an agenda action.
18376 Agenda actions are actions executed from the agenda with the key `k',
18377 which make use of the date at the cursor."
18379 (move-marker org-agenda-action-marker
18380 (save-excursion (org-back-to-heading t) (point))
18383 "Entry marked for action; press `k' at desired date in agenda or calendar"))
18385 ;;; Paragraph filling stuff.
18386 ;; We want this to be just right, so use the full arsenal.
18388 (defun org-indent-line-function ()
18389 "Indent line like previous, but further if previous was headline or item."
18391 (let* ((pos (point))
18392 (itemp (org-at-item-p))
18393 (case-fold-search t)
18394 (org-drawer-regexp (or org-drawer-regexp "\000"))
18395 column bpos bcol tpos tcol bullet btype bullet-type)
18396 ;; Find the previous relevant line
18397 (beginning-of-line 1)
18399 ((looking-at "#") (setq column 0))
18400 ((looking-at "\\*+ ") (setq column 0))
18401 ((and (looking-at "[ \t]*:END:")
18402 (save-excursion (re-search-backward org-drawer-regexp nil t)))
18404 (goto-char (1- (match-beginning 1)))
18405 (setq column (current-column))))
18406 ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
18408 (re-search-backward
18409 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
18410 (setq column (org-get-indentation (match-string 0))))
18412 (beginning-of-line 0)
18413 (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
18414 (not (looking-at "[ \t]*:END:"))
18415 (not (looking-at org-drawer-regexp)))
18416 (beginning-of-line 0))
18418 ((looking-at "\\*+[ \t]+")
18419 (if (not org-adapt-indentation)
18421 (goto-char (match-end 0))
18422 (setq column (current-column))))
18423 ((looking-at org-drawer-regexp)
18424 (goto-char (1- (match-beginning 1)))
18425 (setq column (current-column)))
18426 ((looking-at "\\([ \t]*\\):END:")
18427 (goto-char (match-end 1))
18428 (setq column (current-column)))
18430 (org-beginning-of-item)
18431 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
18432 (setq bpos (match-beginning 1) tpos (match-end 0)
18433 bcol (progn (goto-char bpos) (current-column))
18434 tcol (progn (goto-char tpos) (current-column))
18435 bullet (match-string 1)
18436 bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
18437 (if (> tcol (+ bcol org-description-max-indent))
18438 (setq tcol (+ bcol 5)))
18442 (beginning-of-line 1)
18443 (if (looking-at "\\S-")
18445 (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
18446 (setq bullet (match-string 1)
18447 btype (if (string-match "[0-9]" bullet) "n" bullet))
18448 (setq column (if (equal btype bullet-type) bcol tcol)))
18449 (setq column (org-get-indentation)))))
18450 (t (setq column (org-get-indentation))))))
18452 (if (<= (current-column) (current-indentation))
18453 (org-indent-line-to column)
18454 (save-excursion (org-indent-line-to column)))
18455 (setq column (current-column))
18456 (beginning-of-line 1)
18458 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
18459 (replace-match (concat (match-string 1)
18460 (format org-property-format
18461 (match-string 2) (match-string 3)))
18463 (org-move-to-column column)))
18465 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
18466 "Variable to store copy of `adaptive-fill-regexp'.
18467 Since `adaptive-fill-regexp' is set to never match, we need to
18468 store a backup of its value before entering `org-mode' so that
18469 the functionality can be provided as a fall-back.")
18471 (defun org-set-autofill-regexps ()
18473 ;; In the paragraph separator we include headlines, because filling
18474 ;; text in a line directly attached to a headline would otherwise
18475 ;; fill the headline as well.
18476 (org-set-local 'comment-start-skip "^#+[ \t]*")
18477 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
18478 ;; The paragraph starter includes hand-formatted lists.
18486 "[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)" "\\|"
18489 "\\\\\\(begin\\|end\\|[][]\\)"))
18490 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
18491 ;; But only if the user has not turned off tables or fixed-width regions
18493 'auto-fill-inhibit-regexp
18494 (concat "\\*+ \\|#\\+"
18495 "\\|[ \t]*" org-keyword-time-regexp
18496 (if (or org-enable-table-editor org-enable-fixed-width-editor)
18499 (if org-enable-table-editor "|" "")
18500 (if org-enable-fixed-width-editor ":" "")
18502 ;; We use our own fill-paragraph function, to make sure that tables
18503 ;; and fixed-width regions are not wrapped. That function will pass
18504 ;; through to `fill-paragraph' when appropriate.
18505 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
18506 ;; Adaptive filling: To get full control, first make sure that
18507 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
18508 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
18509 (org-set-local 'org-adaptive-fill-regexp-backup
18510 adaptive-fill-regexp))
18511 (org-set-local 'adaptive-fill-regexp "\000")
18512 (org-set-local 'adaptive-fill-function
18513 'org-adaptive-fill-function)
18515 'align-mode-rules-list
18516 '((org-in-buffer-settings
18517 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
18518 (modes . '(org-mode))))))
18520 (defun org-fill-paragraph (&optional justify)
18521 "Re-align a table, pass through to fill-paragraph if no table."
18522 (let ((table-p (org-at-table-p))
18523 (table.el-p (org-at-table.el-p)))
18524 (cond ((and (equal (char-after (point-at-bol)) ?*)
18525 (save-excursion (goto-char (point-at-bol))
18526 (looking-at outline-regexp)))
18527 t) ; skip headlines
18528 (table.el-p t) ; skip table.el tables
18529 (table-p (org-table-align) t) ; align org-mode tables
18530 (t nil)))) ; call paragraph-fill
18532 ;; For reference, this is the default value of adaptive-fill-regexp
18533 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
18535 (defun org-adaptive-fill-function ()
18536 "Return a fill prefix for org-mode files.
18537 In particular, this makes sure hanging paragraphs for hand-formatted lists
18541 ((looking-at "#[ \t]+")
18542 (match-string-no-properties 0))
18543 ;; Description list
18544 ((looking-at "[ \t]*\\([-*+] .*? :: \\)")
18546 (if (> (match-end 1) (+ (match-beginning 1)
18547 org-description-max-indent))
18548 (goto-char (+ (match-beginning 1) 5))
18549 (goto-char (match-end 0)))
18550 (make-string (current-column) ?\ )))
18551 ;; Ordered or unordered list
18552 ((looking-at "[ \t]*\\([-*+] \\|[0-9]+[.)] ?\\)")
18554 (goto-char (match-end 0))
18555 (make-string (current-column) ?\ )))
18557 ((looking-at org-adaptive-fill-regexp-backup)
18558 (match-string-no-properties 0))))
18562 (defun org-toggle-fixed-width-section (arg)
18563 "Toggle the fixed-width export.
18564 If there is no active region, the QUOTE keyword at the current headline is
18565 inserted or removed. When present, it causes the text between this headline
18566 and the next to be exported as fixed-width text, and unmodified.
18567 If there is an active region, this command adds or removes a colon as the
18568 first character of this line. If the first character of a line is a colon,
18569 this line is also exported in fixed-width font."
18572 (regionp (org-region-active-p))
18573 (beg (if regionp (region-beginning) (point)))
18574 (end (if regionp (region-end)))
18575 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
18576 (case-fold-search nil)
18577 (re "[ \t]*\\(: \\)")
18582 (setq cc (current-column))
18583 (beginning-of-line 1)
18584 (setq off (looking-at re))
18585 (while (> nlines 0)
18586 (setq nlines (1- nlines))
18587 (beginning-of-line 1)
18590 (org-move-to-column cc t)
18593 ((and off (looking-at re))
18594 (replace-match "" t t nil 1))
18595 ((not off) (org-move-to-column cc t) (insert ": ")))
18598 (org-back-to-heading)
18599 (if (looking-at (concat outline-regexp
18600 "\\( *\\<" org-quote-string "\\>[ \t]*\\)"))
18601 (replace-match "" t t nil 1)
18602 (if (looking-at outline-regexp)
18604 (goto-char (match-end 0))
18605 (insert org-quote-string " "))))))))
18607 (defun org-reftex-citation ()
18608 "Use reftex-citation to insert a citation into the buffer.
18609 This looks for a line like
18611 #+BIBLIOGRAPHY: foo plain option:-d
18613 and derives from it that foo.bib is the bibliography file relevant
18614 for this document. It then installs the necessary environment for RefTeX
18615 to work in this buffer and calls `reftex-citation' to insert a citation
18618 Export of such citations to both LaTeX and HTML is handled by the contributed
18619 package org-exp-bibtex by Taru Karttunen."
18621 (let ((reftex-docstruct-symbol 'rds)
18622 (reftex-cite-format "\\cite{%l}")
18627 (let ((case-fold-search t)
18628 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
18629 (if (not (save-excursion
18630 (or (re-search-forward re nil t)
18631 (re-search-backward re nil t))))
18632 (error "No bibliography defined in file")
18633 (setq bib (concat (match-string 1) ".bib")
18634 rds (list (list 'bib bib)))))))
18635 (call-interactively 'reftex-citation)))
18637 ;;;; Functions extending outline functionality
18639 (defun org-beginning-of-line (&optional arg)
18640 "Go to the beginning of the current line. If that is invisible, continue
18641 to a visible line beginning. This makes the function of C-a more intuitive.
18642 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
18643 first attempt, and only move to after the tags when the cursor is already
18644 beyond the end of the headline."
18646 (let ((pos (point))
18647 (special (if (consp org-special-ctrl-a/e)
18648 (car org-special-ctrl-a/e)
18649 org-special-ctrl-a/e))
18651 (if (org-bound-and-true-p line-move-visual)
18652 (beginning-of-visual-line 1)
18653 (beginning-of-line 1))
18654 (if (and arg (fboundp 'move-beginning-of-line))
18655 (call-interactively 'move-beginning-of-line)
18659 (if (org-truely-invisible-p)
18660 (while (and (not (bobp)) (org-truely-invisible-p))
18662 (beginning-of-line 1))
18663 (forward-char 1))))
18666 ((and (looking-at org-complex-heading-regexp)
18667 (= (char-after (match-end 1)) ?\ ))
18668 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
18672 (cond ((> pos refpos) refpos)
18673 ((= pos (point)) refpos)
18675 (cond ((> pos (point)) (point))
18676 ((not (eq last-command this-command)) (point))
18681 (cond ((> pos (match-end 4)) (match-end 4))
18682 ((= pos (point)) (match-end 4))
18684 (cond ((> pos (point)) (point))
18685 ((not (eq last-command this-command)) (point))
18686 (t (match-end 4))))))))
18688 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18690 (defun org-end-of-line (&optional arg)
18691 "Go to the end of the line.
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 ((special (if (consp org-special-ctrl-a/e)
18697 (cdr org-special-ctrl-a/e)
18698 org-special-ctrl-a/e)))
18699 (if (or (not special)
18700 (not (org-on-heading-p))
18702 (call-interactively
18703 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
18704 ((fboundp 'move-end-of-line) 'move-end-of-line)
18706 (let ((pos (point)))
18707 (beginning-of-line 1)
18708 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\)?$"))
18710 (if (or (< pos (match-beginning 1))
18711 (= pos (match-end 0)))
18712 (goto-char (match-beginning 1))
18713 (goto-char (match-end 0)))
18714 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
18715 (goto-char (match-end 0))
18716 (goto-char (match-beginning 1))))
18717 (call-interactively (if (fboundp 'move-end-of-line)
18721 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
18723 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
18724 (define-key org-mode-map "\C-e" 'org-end-of-line)
18725 (define-key org-mode-map [home] 'org-beginning-of-line)
18726 (define-key org-mode-map [end] 'org-end-of-line)
18728 (defun org-backward-sentence (&optional arg)
18729 "Go to beginning of sentence, or beginning of table field.
18730 This will call `backward-sentence' or `org-table-beginning-of-field',
18731 depending on context."
18734 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
18735 (t (call-interactively 'backward-sentence))))
18737 (defun org-forward-sentence (&optional arg)
18738 "Go to end of sentence, or end of table field.
18739 This will call `forward-sentence' or `org-table-end-of-field',
18740 depending on context."
18743 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
18744 (t (call-interactively 'forward-sentence))))
18746 (define-key org-mode-map "\M-a" 'org-backward-sentence)
18747 (define-key org-mode-map "\M-e" 'org-forward-sentence)
18749 (defun org-kill-line (&optional arg)
18750 "Kill line, to tags or end of line."
18753 ((or (not org-special-ctrl-k)
18755 (not (org-on-heading-p)))
18756 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
18757 org-ctrl-k-protect-subtree)
18758 (if (or (eq org-ctrl-k-protect-subtree 'error)
18759 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
18760 (error "C-k aborted - would kill hidden subtree")))
18761 (call-interactively 'kill-line))
18762 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$"))
18763 (kill-region (point) (match-beginning 1))
18764 (org-set-tags nil t))
18765 (t (kill-region (point) (point-at-eol)))))
18767 (define-key org-mode-map "\C-k" 'org-kill-line)
18769 (defun org-yank (&optional arg)
18770 "Yank. If the kill is a subtree, treat it specially.
18771 This command will look at the current kill and check if is a single
18772 subtree, or a series of subtrees[1]. If it passes the test, and if the
18773 cursor is at the beginning of a line or after the stars of a currently
18774 empty headline, then the yank is handled specially. How exactly depends
18775 on the value of the following variables, both set by default.
18777 org-yank-folded-subtrees
18778 When set, the subtree(s) will be folded after insertion, but only
18779 if doing so would now swallow text after the yanked text.
18781 org-yank-adjusted-subtrees
18782 When set, the subtree will be promoted or demoted in order to
18783 fit into the local outline tree structure, which means that the level
18784 will be adjusted so that it becomes the smaller one of the two
18785 *visible* surrounding headings.
18787 Any prefix to this command will cause `yank' to be called directly with
18788 no special treatment. In particular, a simple \\[universal-argument] prefix \
18790 plainly yank the text as it is.
18792 \[1] The test checks if the first non-white line is a heading
18793 and if there are no other headings with fewer stars."
18795 (org-yank-generic 'yank arg))
18797 (defun org-yank-generic (command arg)
18798 "Perform some yank-like command.
18800 This function implements the behavior described in the `org-yank'
18801 documentation. However, it has been generalized to work for any
18802 interactive command with similar behavior."
18804 ;; pretend to be command COMMAND
18805 (setq this-command command)
18808 (call-interactively command)
18810 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
18811 (and (org-kill-is-subtree-p)
18813 (and (looking-at "[ \t]*$")
18816 (buffer-substring (point-at-bol) (point)))))))
18819 ((and subtreep org-yank-folded-subtrees)
18820 (let ((beg (point))
18822 (if (and subtreep org-yank-adjusted-subtrees)
18823 (org-paste-subtree nil nil 'for-yank)
18824 (call-interactively command))
18828 (when (and (bolp) subtreep
18829 (not (setq swallowp
18830 (org-yank-folding-would-swallow-text beg end))))
18831 (or (looking-at outline-regexp)
18832 (re-search-forward (concat "^" outline-regexp) end t))
18833 (while (and (< (point) end) (looking-at outline-regexp))
18835 (org-cycle-show-empty-lines 'folded)
18836 (condition-case nil
18837 (outline-forward-same-level 1)
18838 (error (goto-char end)))))
18841 "Inserted text not folded because that would swallow text"))
18844 (skip-chars-forward " \t\n\r")
18845 (beginning-of-line 1)
18846 (push-mark beg 'nomsg)))
18847 ((and subtreep org-yank-adjusted-subtrees)
18848 (let ((beg (point-at-bol)))
18849 (org-paste-subtree nil nil 'for-yank)
18850 (push-mark beg 'nomsg)))
18852 (call-interactively command))))))
18854 (defun org-yank-folding-would-swallow-text (beg end)
18855 "Would hide-subtree at BEG swallow any text after END?"
18859 (when (or (looking-at outline-regexp)
18860 (re-search-forward (concat "^" outline-regexp) end t))
18861 (setq level (org-outline-level)))
18863 (skip-chars-forward " \t\r\n\v\f")
18865 (and (bolp) (looking-at org-outline-regexp)
18866 (<= (org-outline-level) level)))
18867 nil ; Nothing would be swallowed
18868 t)))) ; something would swallow
18870 (define-key org-mode-map "\C-y" 'org-yank)
18872 (defun org-invisible-p ()
18873 "Check if point is at a character currently not visible."
18874 ;; Early versions of noutline don't have `outline-invisible-p'.
18875 (if (fboundp 'outline-invisible-p)
18876 (outline-invisible-p)
18877 (get-char-property (point) 'invisible)))
18879 (defun org-truely-invisible-p ()
18880 "Check if point is at a character currently not visible.
18881 This version does not only check the character property, but also
18883 ;; Early versions of noutline don't have `outline-invisible-p'.
18884 (if (org-bound-and-true-p visible-mode)
18886 (if (fboundp 'outline-invisible-p)
18887 (outline-invisible-p)
18888 (get-char-property (point) 'invisible))))
18890 (defun org-invisible-p2 ()
18891 "Check if point is at a character currently not visible."
18893 (if (and (eolp) (not (bobp))) (backward-char 1))
18894 ;; Early versions of noutline don't have `outline-invisible-p'.
18895 (if (fboundp 'outline-invisible-p)
18896 (outline-invisible-p)
18897 (get-char-property (point) 'invisible))))
18899 (defun org-back-to-heading (&optional invisible-ok)
18900 "Call `outline-back-to-heading', but provide a better error message."
18901 (condition-case nil
18902 (outline-back-to-heading invisible-ok)
18903 (error (error "Before first headline at position %d in buffer %s"
18904 (point) (current-buffer)))))
18906 (defun org-beginning-of-defun ()
18907 "Go to the beginning of the subtree, i.e. back to the heading."
18908 (org-back-to-heading))
18909 (defun org-end-of-defun ()
18910 "Go to the end of the subtree."
18911 (org-end-of-subtree nil t))
18913 (defun org-before-first-heading-p ()
18914 "Before first heading?"
18916 (null (re-search-backward "^\\*+ " nil t))))
18918 (defun org-on-heading-p (&optional ignored)
18919 (outline-on-heading-p t))
18920 (defun org-at-heading-p (&optional ignored)
18921 (outline-on-heading-p t))
18923 (defun org-point-at-end-of-empty-headline ()
18924 "If point is at the end of an empty headline, return t, else nil.
18925 If the heading only contains a TODO keyword, it is still still considered
18927 (and (looking-at "[ \t]*$")
18929 (beginning-of-line 1)
18930 (looking-at (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp
18932 (defun org-at-heading-or-item-p ()
18933 (or (org-on-heading-p) (org-at-item-p)))
18935 (defun org-on-target-p ()
18936 (or (org-in-regexp org-radio-target-regexp)
18937 (org-in-regexp org-target-regexp)))
18939 (defun org-up-heading-all (arg)
18940 "Move to the heading line of which the present line is a subheading.
18941 This function considers both visible and invisible heading lines.
18942 With argument, move up ARG levels."
18943 (if (fboundp 'outline-up-heading-all)
18944 (outline-up-heading-all arg) ; emacs 21 version of outline.el
18945 (outline-up-heading arg t))) ; emacs 22 version of outline.el
18947 (defun org-up-heading-safe ()
18948 "Move to the heading line of which the present line is a subheading.
18949 This version will not throw an error. It will return the level of the
18950 headline found, or nil if no higher level is found.
18952 Also, this function will be a lot faster than `outline-up-heading',
18953 because it relies on stars being the outline starters. This can really
18954 make a significant difference in outlines with very many siblings."
18955 (let (start-level re)
18956 (org-back-to-heading t)
18957 (setq start-level (funcall outline-level))
18958 (if (equal start-level 1)
18960 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
18961 (if (re-search-backward re nil t)
18962 (funcall outline-level)))))
18964 (defun org-first-sibling-p ()
18965 "Is this heading the first child of its parents?"
18967 (let ((re (concat "^" outline-regexp))
18969 (unless (org-at-heading-p t)
18970 (error "Not at a heading"))
18971 (setq level (funcall outline-level))
18973 (if (not (re-search-backward re nil t))
18975 (setq l (funcall outline-level))
18978 (defun org-goto-sibling (&optional previous)
18979 "Goto the next sibling, even if it is invisible.
18980 When PREVIOUS is set, go to the previous sibling instead. Returns t
18981 when a sibling was found. When none is found, return nil and don't
18983 (let ((fun (if previous 're-search-backward 're-search-forward))
18985 (re (concat "^" outline-regexp))
18987 (when (condition-case nil (org-back-to-heading t) (error nil))
18988 (setq level (funcall outline-level))
18990 (or previous (forward-char 1))
18991 (while (funcall fun re nil t)
18992 (setq l (funcall outline-level))
18993 (when (< l level) (goto-char pos) (throw 'exit nil))
18994 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
18998 (defun org-show-siblings ()
18999 "Show all siblings of the current headline."
19001 (while (org-goto-sibling) (org-flag-heading nil)))
19003 (while (org-goto-sibling 'previous)
19004 (org-flag-heading nil))))
19006 (defun org-show-hidden-entry ()
19007 "Show an entry where even the heading is hidden."
19011 (defun org-flag-heading (flag &optional entry)
19012 "Flag the current heading. FLAG non-nil means make invisible.
19013 When ENTRY is non-nil, show the entire entry."
19015 (org-back-to-heading t)
19016 ;; Check if we should show the entire entry
19021 (and (outline-next-heading)
19022 (org-flag-heading nil))))
19023 (outline-flag-region (max (point-min) (1- (point)))
19024 (save-excursion (outline-end-of-heading) (point))
19027 (defun org-get-next-sibling ()
19028 "Move to next heading of the same level, and return point.
19029 If there is no such heading, return nil.
19030 This is like outline-next-sibling, but invisible headings are ok."
19031 (let ((level (funcall outline-level)))
19032 (outline-next-heading)
19033 (while (and (not (eobp)) (> (funcall outline-level) level))
19034 (outline-next-heading))
19035 (if (or (eobp) (< (funcall outline-level) level))
19039 (defun org-get-last-sibling ()
19040 "Move to previous heading of the same level, and return point.
19041 If there is no such heading, return nil."
19042 (let ((opoint (point))
19043 (level (funcall outline-level)))
19044 (outline-previous-heading)
19045 (when (and (/= (point) opoint) (outline-on-heading-p t))
19046 (while (and (> (funcall outline-level) level)
19048 (outline-previous-heading))
19049 (if (< (funcall outline-level) level)
19053 (defun org-end-of-subtree (&optional invisible-OK to-heading)
19054 ;; This contains an exact copy of the original function, but it uses
19055 ;; `org-back-to-heading', to make it work also in invisible
19056 ;; trees. And is uses an invisible-OK argument.
19057 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
19058 ;; Furthermore, when used inside Org, finding the end of a large subtree
19059 ;; with many children and grandchildren etc, this can be much faster
19060 ;; than the outline version.
19061 (org-back-to-heading invisible-OK)
19063 (level (funcall outline-level)))
19064 (if (and (org-mode-p) (< level 1000))
19065 ;; A true heading (not a plain list item), in Org-mode
19066 ;; This means we can easily find the end by looking
19067 ;; only for the right number of stars. Using a regexp to do
19068 ;; this is so much faster than using a Lisp loop.
19069 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
19071 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
19072 ;; something else, do it the slow way
19073 (while (and (not (eobp))
19074 (or first (> (funcall outline-level) level)))
19076 (outline-next-heading)))
19078 (if (memq (preceding-char) '(?\n ?\^M))
19080 ;; Go to end of line before heading
19082 (if (memq (preceding-char) '(?\n ?\^M))
19083 ;; leave blank line before heading
19084 (forward-char -1))))))
19087 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
19088 "Use Org version in org-mode, for dramatic speed-up."
19089 (if (eq major-mode 'org-mode)
19091 (org-end-of-subtree nil t)
19092 (unless (eobp) (backward-char 1)))
19095 (defun org-forward-same-level (arg &optional invisible-ok)
19096 "Move forward to the arg'th subheading at same level as this one.
19097 Stop at the first and last subheadings of a superior heading."
19099 (org-back-to-heading invisible-ok)
19101 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19102 (re (format "^\\*\\{1,%d\\} " level))
19106 (while (and (re-search-forward re nil 'move)
19107 (setq l (- (match-end 0) (match-beginning 0) 1))
19110 (progn (backward-char 1) (org-invisible-p)))
19111 (if (< l level) (setq arg 1)))
19112 (setq arg (1- arg)))
19113 (beginning-of-line 1)))
19115 (defun org-backward-same-level (arg &optional invisible-ok)
19116 "Move backward to the arg'th subheading at same level as this one.
19117 Stop at the first and last subheadings of a superior heading."
19119 (org-back-to-heading)
19121 (let* ((level (- (match-end 0) (match-beginning 0) 1))
19122 (re (format "^\\*\\{1,%d\\} " level))
19125 (while (and (re-search-backward re nil 'move)
19126 (setq l (- (match-end 0) (match-beginning 0) 1))
19130 (if (< l level) (setq arg 1)))
19131 (setq arg (1- arg)))))
19133 (defun org-show-subtree ()
19134 "Show everything after this heading at deeper levels."
19135 (outline-flag-region
19138 (org-end-of-subtree t t))
19141 (defun org-show-entry ()
19142 "Show the body directly following this heading.
19143 Show the heading too, if it is currently invisible."
19146 (condition-case nil
19148 (org-back-to-heading t)
19149 (outline-flag-region
19150 (max (point-min) (1- (point)))
19152 (if (re-search-forward
19153 (concat "[\r\n]\\(" outline-regexp "\\)") nil t)
19154 (match-beginning 1)
19157 (org-cycle-hide-drawers 'children))
19160 (defun org-make-options-regexp (kwds &optional extra)
19161 "Make a regular expression for keyword lines."
19165 (mapconcat 'regexp-quote kwds "\\|")
19166 (if extra (concat "\\|" extra))
19170 ;; Make isearch reveal the necessary context
19171 (defun org-isearch-end ()
19172 "Reveal context after isearch exits."
19173 (when isearch-success ; only if search was successful
19174 (if (featurep 'xemacs)
19175 ;; Under XEmacs, the hook is run in the correct place,
19176 ;; we directly show the context.
19177 (org-show-context 'isearch)
19178 ;; In Emacs the hook runs *before* restoring the overlays.
19179 ;; So we have to use a one-time post-command-hook to do this.
19180 ;; (Emacs 22 has a special variable, see function `org-mode')
19181 (unless (and (boundp 'isearch-mode-end-hook-quit)
19182 isearch-mode-end-hook-quit)
19183 ;; Only when the isearch was not quitted.
19184 (org-add-hook 'post-command-hook 'org-isearch-post-command
19185 'append 'local)))))
19187 (defun org-isearch-post-command ()
19188 "Remove self from hook, and show context."
19189 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
19190 (org-show-context 'isearch))
19193 ;;;; Integration with and fixes for other packages
19197 (defvar org-imenu-markers nil
19198 "All markers currently used by Imenu.")
19199 (make-variable-buffer-local 'org-imenu-markers)
19201 (defun org-imenu-new-marker (&optional pos)
19202 "Return a new marker for use by Imenu, and remember the marker."
19203 (let ((m (make-marker)))
19204 (move-marker m (or pos (point)))
19205 (push m org-imenu-markers)
19208 (defun org-imenu-get-tree ()
19209 "Produce the index for Imenu."
19210 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
19211 (setq org-imenu-markers nil)
19212 (let* ((n org-imenu-depth)
19213 (re (concat "^" outline-regexp))
19214 (subs (make-vector (1+ n) nil))
19220 (goto-char (point-max))
19221 (while (re-search-backward re nil t)
19222 (setq level (org-reduced-level (funcall outline-level)))
19224 (looking-at org-complex-heading-regexp)
19225 (setq head (org-link-display-format
19226 (org-match-string-no-properties 4))
19227 m (org-imenu-new-marker))
19228 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
19229 (if (>= level last-level)
19230 (push (cons head m) (aref subs level))
19231 (push (cons head (aref subs (1+ level))) (aref subs level))
19232 (loop for i from (1+ level) to n do (aset subs i nil)))
19233 (setq last-level level)))))
19236 (eval-after-load "imenu"
19238 (add-hook 'imenu-after-jump-hook
19240 (if (eq major-mode 'org-mode)
19241 (org-show-context 'org-goto))))))
19243 (defun org-link-display-format (link)
19244 "Replace a link with either the description, or the link target
19245 if no description is present"
19247 (if (string-match org-bracket-link-analytic-regexp link)
19248 (replace-match (if (match-end 5)
19249 (match-string 5 link)
19250 (concat (match-string 1 link)
19251 (match-string 3 link)))
19255 ;; Speedbar support
19257 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
19258 "Overlay marking the agenda restriction line in speedbar.")
19259 (overlay-put org-speedbar-restriction-lock-overlay
19260 'face 'org-agenda-restriction-lock)
19261 (overlay-put org-speedbar-restriction-lock-overlay
19262 'help-echo "Agendas are currently limited to this item.")
19263 (org-detach-overlay org-speedbar-restriction-lock-overlay)
19265 (defun org-speedbar-set-agenda-restriction ()
19266 "Restrict future agenda commands to the location at point in speedbar.
19267 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
19269 (require 'org-agenda)
19270 (let (p m tp np dir txt)
19272 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19274 (setq m (get-text-property p 'org-imenu-marker))
19275 (with-current-buffer (marker-buffer m)
19277 (org-agenda-set-restriction-lock 'subtree)))
19278 ((setq p (text-property-any (point-at-bol) (point-at-eol)
19279 'speedbar-function 'speedbar-find-file))
19280 (setq tp (previous-single-property-change
19281 (1+ p) 'speedbar-function)
19282 np (next-single-property-change
19283 tp 'speedbar-function)
19284 dir (speedbar-line-directory)
19285 txt (buffer-substring-no-properties (or tp (point-min))
19286 (or np (point-max))))
19287 (with-current-buffer (find-file-noselect
19288 (let ((default-directory dir))
19289 (expand-file-name txt)))
19290 (unless (org-mode-p)
19291 (error "Cannot restrict to non-Org-mode file"))
19292 (org-agenda-set-restriction-lock 'file)))
19293 (t (error "Don't know how to restrict Org-mode's agenda")))
19294 (move-overlay org-speedbar-restriction-lock-overlay
19295 (point-at-bol) (point-at-eol))
19296 (setq current-prefix-arg nil)
19297 (org-agenda-maybe-redo)))
19299 (eval-after-load "speedbar"
19301 (speedbar-add-supported-extension ".org")
19302 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
19303 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
19304 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
19305 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
19306 (add-hook 'speedbar-visiting-tag-hook
19307 (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
19309 ;;; Fixes and Hacks for problems with other packages
19311 ;; Make flyspell not check words in links, to not mess up our keymap
19312 (defun org-mode-flyspell-verify ()
19313 "Don't let flyspell put overlays at active buttons."
19314 (and (not (get-text-property (point) 'keymap))
19315 (not (get-text-property (point) 'org-no-flyspell))))
19317 (defun org-remove-flyspell-overlays-in (beg end)
19318 "Remove flyspell overlays in region."
19319 (and (org-bound-and-true-p flyspell-mode)
19320 (fboundp 'flyspell-delete-region-overlays)
19321 (flyspell-delete-region-overlays beg end))
19322 (add-text-properties beg end '(org-no-flyspell t)))
19324 ;; Make `bookmark-jump' shows the jump location if it was hidden.
19325 (eval-after-load "bookmark"
19326 '(if (boundp 'bookmark-after-jump-hook)
19327 ;; We can use the hook
19328 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
19329 ;; Hook not available, use advice
19330 (defadvice bookmark-jump (after org-make-visible activate)
19331 "Make the position visible."
19332 (org-bookmark-jump-unhide))))
19334 ;; Make sure saveplace shows the location if it was hidden
19335 (eval-after-load "saveplace"
19336 '(defadvice save-place-find-file-hook (after org-make-visible activate)
19337 "Make the position visible."
19338 (org-bookmark-jump-unhide)))
19340 ;; Make sure ecb shows the location if it was hidden
19341 (eval-after-load "ecb"
19342 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
19343 "Make hierarchy visible when jumping into location from ECB tree buffer."
19344 (if (eq major-mode 'org-mode)
19345 (org-show-context))))
19347 (defun org-bookmark-jump-unhide ()
19348 "Unhide the current position, to show the bookmark location."
19350 (or (org-invisible-p)
19351 (save-excursion (goto-char (max (point-min) (1- (point))))
19352 (org-invisible-p)))
19353 (org-show-context 'bookmark-jump)))
19355 ;; Make session.el ignore our circular variable
19356 (eval-after-load "session"
19357 '(add-to-list 'session-globals-exclude 'org-mark-ring))
19359 ;;;; Experimental code
19361 (defun org-closed-in-range ()
19362 "Sparse tree of items closed in a certain time range.
19363 Still experimental, may disappear in the future."
19365 ;; Get the time interval from the user.
19366 (let* ((time1 (org-float-time
19367 (org-read-date nil 'to-time nil "Starting date: ")))
19368 (time2 (org-float-time
19369 (org-read-date nil 'to-time nil "End date:")))
19370 ;; callback function
19371 (callback (lambda ()
19374 (apply 'encode-time
19375 (org-parse-time-string
19376 (match-string 1))))))
19377 ;; check if time in interval
19378 (and (>= time time1) (<= time time2))))))
19379 ;; make tree, check each match with the callback
19380 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
19386 (run-hooks 'org-load-hook)
19388 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
19390 ;;; org.el ends here